Bugzilla – Bug 1222342
gdb history seems almost entirely broken
Last modified: 2024-05-22 11:25:28 UTC
For some reason, the gdb history seems almost entirely broken. This might be a user error, but then maybe it would be worth poking upstream about making this somehow more obvious. EXPECTED BEHAVIOR: I do whatever in gdb for whatever amount of time. Then I use "quit". Then I relaunch it. All the commands I used before should show up when I press up arrow. I don't really care if the order is messed up or if there are duplicates or not, as long as the commands come back in full. ACTUAL BEHAVIOR: Whenever I use set history save on, I get one of these random things when I launch gdb later: 1. suddenly, the history only has half the commands I used in the previous session, or 2. it works (kind of rare), or 3. the entire history is nuked. What I get seems entirely random, but it's almost impossible to just get the history to work. AFFECTED VERSION: GNU gdb (GDB; openSUSE Slowroll) 13.2 ADDITIONAL INFO: I'm also using the mozilla symbols.py gdb script ( https://gist.github.com/luser/193572147c401c8a965c#file-symbols-py ) in case that somehow interferes with history. If it does and this is a mozilla problem let me know, I really wouldn't know. I usually use gdb UIs that don't really rely on gdb's own history saving.
In the cases that stuff works unexpectedly, what does (gdb) show history filename say, and does the file in question there contain the expected things or not? Do note that the default filename for saving history is ".gdb_history" in the _current directory_. So, when you do your gdb session in various directories and don't overwrite the history filename you will be given the history from whatever happened to be the history the last time you were in that very directory. (You may want to do a global search for that filename and see if you indeed have various random incarnations of it) (Also, assigning to gdb maintainer).
Saving history is a feature I haven't used before, but I've read the docs now to understand what it's supposed to do. I agree with Michael that it looks like at least part of the problems reported in comment 0 can be caused by using the default history file which resides in the current directory. Anyway, I've now enabled it in my .gdbinit, like so: ... $ cat ~/.gdbinit set history filename ~/.gdb_history set history save on ... and I'll test-drive it for a while. I've tried out the use case of opening two gdb sessions at the same time, and the resulting history file looks sane, so at first glance there doesn't seem to any truncating going on there. The reported "the history only has half the commands I used in the previous session" may just be the history size parameter, defaulting to 256 taking effect.