Bug 12918 - Can not get symtab_and_line object given an arbitrary program counter
Summary: Can not get symtab_and_line object given an arbitrary program counter
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: python (show other bugs)
Version: 7.2
: P2 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-21 21:48 UTC by er_31337
Modified: 2018-09-15 05:56 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description er_31337 2011-06-21 21:48:02 UTC
There is no (obvious) documented way to get a symtab_and_line object given an arbitrary address.  
A function gdb.sal_for_pc() similar to gdb.block_for_pc() would be nice.
Comment 1 matt rice 2011-07-04 07:06:56 UTC
you can get a symtab_and_line object for an arbitrary address by using the decode_line function (see the Basic Python section of the manual) and passing in "*0xaddr" as the argument.

e.g. 
(gdb) python print gdb.decode_line("*" + str(gdb.selected_frame().find_sal().pc))
(None, (<gdb.Symtab_and_line object at 0x7f55269cbe10>,))
(gdb)

I've suggested adding a reference to decode_line from the gdb.symtab_and_line section.
If you have any recommendations how to further clarify the manual please let us know.
Comment 2 Tom Tromey 2018-09-15 03:46:09 UTC
I think a direct API would be good to have.
Comment 3 Tom Tromey 2018-09-15 05:56:04 UTC
I was looking and found gdb.find_pc_line, which is exactly this.