Use Addr2line to resolve the function address to the function name

Source: Internet
Author: User
Use Addr2line to resolve the function address to the function name www. ibm. the comdeveloperworkscnlinuxl-graphvisAddr2line tool, which is part of the standard GNUBinutils, is a tool that converts the address and executable image of a command to a file name, function name, and number of lines of source code. This feature is applicable

Resolve the function address with Addr2line to the function name http://www.ibm.com/developerworks/cn/linux/l-graphvis/ Addr2line tool (which is part of the standard GNU Binutils) is a tool that converts the instruction address and executable image into a file name, function name, and source code line. This feature is applicable

Use Addr2line to resolve the function address to the function name

Http://www.ibm.com/developerworks/cn/linux/l-graphvis/

The Addr2line tool (which is part of the standard GNU Binutils) is a tool that converts the instruction address and executable image into a file name, function name, and number of lines of source code. This feature is great for converting tracking addresses into more meaningful content.

To understand how this process works, we can test a simple interactive example. (I operate directly from shell, because this is the easiest way to demonstrate this process, as shown in Listing 4 .) In this example, the C file (test. c) usescatImplemented by a simple application (that is, the standard output text is redirected to a file ). Then use gcc to compile the file. It will pass some special options. First, you must-WlOption) notifies the linker to generate an image file and-gOption) notifies the compiler to generate debugging symbols. Generate an executable fileTest. After obtaining a new executable application, you can usegrepFind the tool in the Image FilemainTo find its address. Use this address and the Addr2line tool to determine the function name (main), The source file (/home/mtj/test. c), and its row number in the source file (4 ).

Use the Addr2line Tool-eOption to specify whether the executable image istest. Use-fIndicates the name of the output function.

$ cat >> test.c#include 
 
  int main(){  printf("Hello World\n");  return 0;}
  
   $ gcc -Wl,-Map=test.map -g -o test test.c$ grep main test.map0x08048258__libc_start_main@@GLIBC_2.00x08048258main$ addr2line 0x08048258 -e test -fmain/home/mtj/test/test.c:4$
  
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.