Is it possible to use executables having no debug symbols with valgrind?

Vinie :

I have been trying to debug a piece of code using valgrind and gdb.

   #include <stdio.h>
   #include <stdlib.h>
   int main()
   {
           int *p = malloc(sizeof(int));
           free(p);
           return 0;
   }
  • I have compiled it using command gcc prog.c -o prog -g. When I run it with gdb and valgrind, it works fine.

  • Then I removed the debugging symbols by command strip --strip-all prog.

  • Then I run the same with gdb and valgrind. So gdb shows "no debugging information is available" where as in valgrind run successfully and shows no such warnings.

Also I tried to check the size using command size for both the cases. But I could not find any difference.

How to find whether debugging information has added? How is it possible to find the leakcheck using valgrind without having debugging symbols along with the executable?

John Bollinger :

How to find whether debugging information has added?

The easiest way is probably to use the file utility. Example:

file my_executable

Among the information it provides is whether debug symbols are present or have been stripped.

There are various other tools that can do this, too, among them GNU readelf (for ELF executables). Debug information will appear in one or more of its own sections of an ELF binary, and you will see those in a list of the sections.

How is it possible to find the leakcheck using valgrind without having debugging symbols along with the executable?

The same way it is possible to run the program at all without debugging symbols. Valgrind does not need the debugging information to monitor program behavior. Its main hook is to provide its own special malloc() and free() implementations. Having debug information available just allows it to emit more human-interpretable diagnostic messages, which is, after all, the whole point of debug symbols in the first place.

To a limited extent, you can debug a program with gdb without debugging symbols, too, but it's painful because so much of what you ordinarily want to do with a debugger depends on mapping details of the executable back to the source. Very little such mapping is possible without the debug symbols.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=345935&siteId=1