using libtool e gdb

末鹿安然 提交于 2020-07-05 10:22:34

问题


I'm working on a project that uses GNU autotools, so in order to debug the code using gdb, I'm running gdb from within libtool:

libtool --mode=execute gdbtui foobar

Is it possible to reload a modified version of the project without the annoyance of having to quit gdb/libtool and restart?


回答1:


libtool --mode=execute creates a temporary executable which is passed to gdb. This executable is removed upon rebuild. The trick is to recreate it with something like

libtool --mode=execute echo ./hello

(Libtool will recreate the temporary executable and pass its name to echo command. You can use any other command instead of echo, e.g. true to suppress output, or even non-existing one.)

To reload the executable use gdb filefilename command file. Executable real name is displayed by gdb upon start:

$ libtool --mode=execute gdb --args ./hello
...
Reading symbols from /path/to/.libs/lt-hello...done.
(gdb)

It is also displayed by gdb info inferiors command:

(gdb) info inferiors 
  Num  Description       Executable        
* 1    <null>            /path/to/.libs/lt-hello

and, of course, by the above echo command.




回答2:


It is a bit difficult to discern what exactly you are asking, but I hope I understood you correctly.

Yes, you can normally run the debugged command again from within gdb as long as it was started with gdb in the first place. In fact this is the common workflow for gdb. Use it in one window/tab/pane to debug your stuff and fix the code in another, rebuild in a third etc.

One way gdb gets started is this one:

# gdb --args command arg1 arg2 ...

another is:

# gdb command

in the latter case you would anyway only start the program from the gdb prompt like this.

(gdb) run arg1 arg2 ...

in the former the arguments are implied (and remembered by gdb). In either case you can retrieve the arguments after the fact using:

(gdb) show args

It is common to rebuild the program once you hit, analyzed and fixed a bug re-run it using only run (which reuses the previous arguments) and verify the fix or continue debugging another problem.




回答3:


Based on @Ilia's answer (and this answer on how to parse the executable name to a gdb variable) a solution is to define the following custom make command in ~/.gdbinit:

define lmake
  python gdb.execute('set $f = "' + str(gdb.selected_inferior().progspace.filename) + '"')
  make
  eval "file %s", $f
end



来源:https://stackoverflow.com/questions/15143739/using-libtool-e-gdb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!