On Thursday 30 October 2008, Jonny Taylor wrote:
> I have a program written in C++, which is normally compiled with gcc  
> to object files and then linked (with gcc). I can get cachegrind/ 
> cg_annotate to display source-level output like this:
> 
> . . .  . . .  . . .  void init_hash_table(char *file_name, Word_Node  
> *table[])
> 3 1 1  . . .  1 0 0  {
> . . .  . . .  . . .      FILE *file_ptr;
> . . .  . . .  . . .      Word_Info *data;
> 1 0 0  . . .  1 1 1      int line = 1, i;
> . . .  . . .  . . .
> 5 0 0  . . .  3 0 0      data = (Word_Info *) create(sizeof(Word_Info));
> 
> but I would like to see instruction-level output something like this
> 
>                       init_hash_table:
> 1 0 0  . . .  . . .    leal -12(%ebp),%eax
> 1 0 0  . . .  1 0 0    movl %eax,84(%ebx)
> 1 0 0  0 0 0  1 0 0    movl $1,-20(%ebp)
> 1 0 0  . . .  . . .    movl $.LnrB,%eax
> 1 0 0  . . .  1 0 0    movl %eax,-16(%ebp)

Hmm... if your C++ code is in foo.cpp, you get the assembler file with

        g++ -S foo.cpp -o foo.s

then, the binary with

        gcc -g foo.s -o foo

For me, running

        valgrind --tool=cachegrind ./foo

and cg_annotate, I get annotated disassembly like

 .    .    .  .    .    .  .    .    .  .globl main
 .    .    .  .    .    .  .    .    .          .type   main, @function
 .    .    .  .    .    .  .    .    .  main:
 1    0    0  0    0    0  0    0    0          leal    4(%esp), %ecx
 1    0    0  0    0    0  0    0    0          andl    $-16, %esp
 1    0    0  1    0    0  1    0    0          pushl   -4(%ecx)
 1    0    0  0    0    0  1    0    0          pushl   %ebp

I assume this is what you want. As Nick said, you have to map instructions to 
C++ lines
yourself. For this, you also can compare the annotation with foo-g.s from

        g++ -g -S foo.cpp -o foo-g.s

as here, foo-g.s contains ".file"/".loc" macros providing the source lines for 
instructions.

However, if you are comfortable with KDE GUIs, you can get at disassembly 
annotation by
using

        g++ -g foo.cpp -o foo
        valgrind --tool=callgrind --simulate-cache=yes --dump-instr=yes ./foo

and visualizing the result in KCachegrind, more especially look at the 
disassembly view.

Josef


> 
> Any advice on how to achieve that would be very helpful!
> Cheers
> Jonny



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Valgrind-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to