This is a script that will take an object file and a source file assosciated with it and display some statistics about the source file code transposed into assembly language commands. It uses the program objdump behind the scenes to get the source code to assembly code mapping (it basically just prettifies objdump’s output)
The perl file should be usable out of the box; just run
chmod +x analyzer.pl
to add execution permissions to the analyzer.pl script, and then you should be able to invoke it: “‘analyzer.pl [options] <object file> <source file>“`
**IMPORTANT: You must generate the object file passing the -g (debug flag) to gcc/g++, otherwise this program will not work**
analyzer.pl [options] <object file> <source file>
-l, --line activates line mode: -l 42 to get information about line 42 -h, --help (or no parameters) brings up this message
g++ -c -g hello.cpp -o hello.o perl analyzer.pl hello.o hello.cpp
Line | ASM |JMP |CALL | Source Code
---------------------------------------------------------------
1 | 0 | 0 | 0 | #include <iostream>
2 | 0 | 0 | 0 |
3 | 5 | 0 | 0 | int main(int argc, char* argv[]){
4 | 3 | 0 | 1 | std::cout << "Hello World!";
5 | 1 | 0 | 0 | return 0;
6 | 4 | 0 | 0 | }
Command: ./analyzer.pl hello.o --line 3 0: 55 push %rbp 1: 48 89 e5 mov %rsp,%rbp 4: 48 83 ec 10 sub $0x10,%rsp 8: 89 7d fc mov %edi,-0x4(%rbp) b: 48 89 75 f0 mov %rsi,-0x10(%rbp)
To get a list of these options on the command line, simply run:
./analyzer.pl --help
The BASH script, install.sh is provided for convenience; all is does is append the contents of the lisp file onto your .emacs configuration file and copy the analyzer script into your ~/bin directory.
The emacs default key combination to view assembly source of a particular line of code is “‘C-x C-a“` (Control + x then Control + a).
I hope you enjoy the little utility,
Pasha Muravyev