简体   繁体   中英

Gdb get frame's function name

I'm looking for a way to get the current function's name from the frame information in GDB. Is that possible? If yes, how can I find the other variables set for a specific frame?

Basically I'm after the same name that's displayed at the beginning of each line when running the bt command.

Using the ordinary gdb CLI this can only be done with great difficulty. You have to use logging to write the output of "frame" to a file; then do processing on the file to extract the name and turn it into a gdb script; then "source" the resulting script.

If you have a Python-enabled gdb, then it is easy. Use gdb.selected_frame() to get the selected frame. Then the name is in the frame's function symbol:

name = gdb.selected_frame().name()

If need be you can expose this to the CLI in various ways; but the simplest is probably to wrap it in a convenience function. See the docs for information on that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM