Using gdb to convert addresses to lines

后端 未结 2 1327
你的背包
你的背包 2021-01-30 04:35

I have a stack trace generated by a stripped application which looks like this:

 *** Check failure stack trace: ***
    @     0x7f0e442d392d  (unknown)
    @             


        
相关标签:
2条回答
  • 2021-01-30 04:50

    Per the OP, the command in GDB to find the source line of code from an address is:

    info line *0x10045740
    

    Edit: Replaced "info symbol 0x10045740" which won't work under certain conditions (thanks @Thomasa88).

    0 讨论(0)
  • 2021-01-30 04:52

    But how can I translate the address into files and line numbers?

    For the main executable (addresses like 0x4e8765) do this:

    addr2line -e /path/to/non-stripped/.../my-buggy-app \
        0x4a6889 0x4a8b43 0x4e8765
    

    Actually, you might want to subtract 5 (usual length of the CALL instruction) from all of the above addresses.

    For the addresses in shared libraries, you have to know the load address of the library.

    If your application produced a core file, then (gdb) info shared will tell you where libraries were loaded.

    If you did not get a core file, and the application did not print the required mapping, then

    • you should fix the application so it does print that info (the stack trace is mostly useless without it), and
    • you could still guess: look at the code in the executable at 0x4e8760 -- it should be a CALL instruction to some function. Now find out which library that function is in, and find its address in the library (via nm). If you are lucky, that address is near 0xNc56NN. You can now guess the load address of whatever library is at 0x7f0e457NNNNNN. Repeat for 0x7f0e457c55e1, and you can find out the load address of library at 0x7f0e442dNNNN.
    0 讨论(0)
提交回复
热议问题