15

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.

Piotr Lopusiewicz
  • 2,514
  • 2
  • 27
  • 38
  • 7
    Compiling with -gdwarf-2 solved big part of the problem; apparently the default for gcc 4.8 is newer version of dwarf which Sleepy can't read; There are still some unrecognized functions but all most expensive ones are now recognized. – Piotr Lopusiewicz Sep 23 '13 at 22:31
  • 1
    I run into the same problem but can't solve it. I use `-g -fno-omit-frame-pointer -gdwarf-2` or any combination of them without success together with `g++ 4.8.3`. Am I missing somehting obvious? – magu_ Aug 06 '14 at 13:02
  • 1
    It was some time since I've used Sleepy but try compiling with -gdwarf-2 without -g. I think -g implies the format of debugging info and then -gdwrf-2 doesn't override it. – Piotr Lopusiewicz Aug 09 '14 at 18:49
  • None of the mentioned ideas worked for me (using gcc version 4.9.1 (i686-posix-dwarf-rev2, Built by MinGW-W64 project)) – SebastianK Jun 21 '16 at 13:46

1 Answers1

7

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

Community
  • 1
  • 1
Alexis Clarembeau
  • 2,776
  • 14
  • 27
  • Thank you! Can also the ordering of the parameters be relevant? In particular that of `-gdwarf-2` and `-g`, e.g. because `-g` might trigger a different default format? – SebastianK Jun 24 '16 at 09:49
  • Will try to test that soon, so far used `-O2`. Also, I am using CMake, so, the binaries end up in a directory that is parallel to the source code. Perhaps there is a need to provide very sleepy with some directories? (Tried a lot for symbol search path without success) – SebastianK Jun 24 '16 at 09:52
  • @SebastianK: have you found a solution to our problem ? I am running into smiliar issues. – user3722440 Feb 15 '19 at 14:45
  • compiling with "-gstabs+" seems to help: symbols are resolved in my exe (I have still some issues in my custom DLLs that are QT plugins loaded dynamically by the application). – user3722440 Feb 19 '19 at 15:49