Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Very Sleepy doesn't see function names when capturing MinGW compiled file

I am new to this so probably missing something basic. I compile my C program with gcc 4.8 (MinGW) and -g option.

I then run it and capture it with Very Sleepy. It all works but the output of Sleepy looks like this:

memcpy             0.98 0.98 7.65 7.65  msvcrt unknown 0
[00000000004038FE] 0.77 0.77 6.02 6.02  a              0
memset             0.63 0.63 4.92 4.93  msvcrt unknown 0
[0000000000404549] 0.42 0.42 3.29 3.29  a              0
[000000000040282A] 0.35 0.35 2.73 2.73  a              0
[0000000000404600] 0.25 0.25 1.99 1.99  a              0
....
etc.

(my application is called a.exe)
So Sleepy doesn't see function names, how do I need to compile/run to make it work ? Sleepy website gives:

Support for GCC/mingw. You can now profile executables with embedded DWARF2 data and it should work. No special options are required for this, just compile with “-g” to make sure you have symbols present. You may also wish to use “-fno-omit-frame-pointer” to ensure correct callstacks, although Sleepy will generally work either way. You don’t need to use “-pg” or any rubbish. It can even walk correct stacks between a Microsoft DLL into a GCC one, which was harder than you’d think.

But it's not enough in my case.

like image 375
Piotr Lopusiewicz Avatar asked Sep 23 '13 21:09

Piotr Lopusiewicz


1 Answers

Usually we call the very sleepy command (or any other debugging tool) with the arguments:

  • -O0: sets default code optimization (more optimized code used to reduce time or space can hide some functions)
  • -g: it's used to retain the name of the functions and the variable, that are mangled by default in order to optimize the executable, but it makes it less debuggable: gcc -g :what will happen
  • -fno-omit-frame-pointer : it's also used to improve debugging by ommiting frame pointers (a feature used to improve performance but that makes the debug less readable), according to When should I omit the frame pointer?. With that option, the output assembly code is more simple. That helps the debugger
  • -gdwarf-2: https://gcc.gnu.org/onlinedocs/gcc-3.4.5/gcc/Debugging-Options.html specifies that it's set to force the output debugging format to "dwarf2". In fact, the -g option just tells the compiler to "retain some information". gdwarf will specify the output format (if possible).

You can also add a -glevel to indicate the precision of the output information. The default one is 2. It does not retain macros and some definitions. Maybe you can set it to 3.

If it's not enough maybe you can give a minimal working sample to see the exact problem (which function should appear in the log)?

I hope it will help

like image 127
Alexis Clarembeau Avatar answered Oct 23 '22 11:10

Alexis Clarembeau