2

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.

3
  • What do you mean by 'get'? Obtain in a script? Via an API? Tied to the leg of a carrier pigeon? Commented Sep 29, 2013 at 21:16
  • Access it for comparison in a define block. Get something that I can compare to either an address or a name string in the gdb script. Commented Sep 29, 2013 at 21:19
  • recent gdb has Python support. I don't know the exact api to get the frame name but you could start with the python support... Commented Sep 29, 2013 at 23:53

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.