I try to profile my program myprog using perf, and here's what I get:

#
# Overhead                                                               Symbol                          Shared Object
# ........  ...................................................................  .....................................
#
     7.71%  0x743a             l [.] list_iter_next                            myprog

I use objdump -D to see which instruction the IP refers to. The thing is, the 0x743a IP shown here is in a .debug section of the myprog.

$ grep -ne ' 743a' dump  
418233:    743a:    65                      gs 
429445:    743a:    40 00 00                add    %al,(%rax)

The hex value provided by perf could match several places in the dump, as shown by:

$ grep -ne 743a dump 
7973:  40743a:  48 8b 00                mov    (%rax),%rax
72861:  44743a: 66 0f f8 c8             psubb  %xmm0,%xmm1
87650:  45743a: 41 d3 e9                shr    %cl,%r9d

The correct IP is 0x40743a, as shown here:

$ grep -n4 40743a dump 
7969-0000000000407430 <list_iter_next>:
7970-  407430:  48 8b 07                mov    (%rdi),%rax
7971-  407433:  48 8b 40 08             mov    0x8(%rax),%rax
7972-  407437:  48 89 07                mov    %rax,(%rdi)
7973:  40743a:  48 8b 00                mov    (%rax),%rax
7974-  40743d:  c3                      retq   
7975-  40743e:  66 90                   xchg   %ax,%ax
7976-

Does anybody know what's going on?

有帮助吗?

解决方案

Have you compiled your program with debug options (-g with gcc)? It seems that debug information is missing, as explained in the perf tutorial at : https://perf.wiki.kernel.org/index.php/Tutorial

When the symbol is printed as an hexadecimal address, this is because the ELF image does not have a symbol table. This happens when binaries are stripped.

About the symbol value you get, I don't know where it comes from and if we can interpret it like you did.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top