You need to sign in or sign up before continuing.
  • Martin Liška's avatar
    perf annotate: Fix jump parsing for C++ code. · 1f0e6edc
    Martin Liška authored
    Considering the following testcase:
    
      int
      foo(int a, int b)
      {
         for (unsigned i = 0; i < 1000000000; i++)
           a += b;
         return a;
      }
    
      int main()
      {
         foo (3, 4);
         return 0;
      }
    
    'perf annotate' displays:
    
      86.52 │40055e: → ja   40056c <foo(int, int)+0x26>
      13.37 │400560:   mov  -0x18(%rbp),%eax
            │400563:   add  %eax,-0x14(%rbp)
            │400566:   addl $0x1,-0x4(%rbp)
       0.11 │40056a: → jmp  400557 <foo(int, int)+0x11>
            │40056c:   mov  -0x14(%rbp),%eax
            │40056f:   pop  %rbp
    
    and the 'ja 40056c' does not link to the location in the function.  It's
    caused by fact that comma is wrongly parsed, it's part of function
    signature.
    
    With my patch I see:
    
      86.52 │   ┌──ja   26
      13.37 │   │  mov  -0x18(%rbp),%eax
            │   │  add  %eax,-0x14(%rbp)
            │   │  addl $0x1,-0x4(%rbp)
       0.11 │   │↑ jmp  11
            │26:└─→mov  -0x14(%rbp),%eax
    
    and 'o' output prints:
    
      8...
    1f0e6edc
annotate.c 78.5 KB