I am trying to use addr2line command in Unix but everytime it is giving the same output as ??:0. I am giving command as addr2line -e a.out 0x4005BDC
. I got this address while running this a.out executable with valgrind
tool to find the memory leakage. I also compiled the source code with -g
option.
相关问题
- Multiple sockets for clients to connect to
- Is shmid returned by shmget() unique across proces
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- how to get running process information in java?
You need to specify an offset to addr2line, not a virtual address (VA). Presumably if you had address space randomization turned off, you could use a full VA, but in most modern OSes, address spaces are randomized for a new process.
Given the VA
0x4005BDC
by valgrind, find the base address of your process or library in memory. Do this by examining the/proc/<PID>/maps
file while your program is running. The line of interest is thetext
segment of your process, which is identifiable by the permissionsr-xp
and the name of your program or library.Let's say that the base VA is
0x0x4005000
. Then you would find the difference between the valgrind supplied VA and the base VA:0xbdc
. Then, supply that to add2line:And see if that gets you your line number.
Try adding the
-f
option to show the function names :You can also use gdb instead of addr2line to examine memory address. Load executable file in gdb and print the name of a symbol which is stored at the address. 16 Examining the Symbol Table.
Please check:
-g
,addr2line
only support functions has debug information, that is compiled with-g
.text
section. In the.text
section means the address should point to an instruction in the binaryaddr2line usage
Following is the message from
man addr2line
.The
addresses
should be the address in an executable or an offset in a section of a relocatable object.The output is something like
FILENAME:LINENO
, the source file name, and the line number in the fileExample.
Take the
helloworld
as an example.After compile it with
gcc -g hello.c
, we could firstly useobjdump
to get an idea about the offset information in the generateda.out
file.Following is part of the dumped dis-assembly:
The most left column of the code is the offset in the binary file.
__start
function comes from the standard C library and is precompiled without debug information.main
function comes from our helloworld code which has debug information since we compile the file with-g
.Following is output of
addr2line
:We could make some conclusions from the above output:
-g
flag (which means the segment have debug information) could successfully generate filename and linenumber information.-g
flag will successfully output filename and linenumber. The offset0x40054b
is the last instruction afterret
instruction of themain
function, but we could not get the information.That's exactly how you use it. There is a possibility that the address you have does not correspond to something directly in your source code though.
For example:
0x400534
is the address ofmain
in my case.0x400408
is also a valid function address ina.out
, but it's a piece of code generated/imported by GCC, that has no debug info. (In this case,__libc_csu_init
. You can see the layout of your executable withreadelf -a your_exe
.)Other times when
addr2line
will fail is if you're including a library that has no debug information.