I am trying to debug a C++ program in Eclipse using gdb. I think it works fine in my main()
function, but elsewhere it gives me a warning when I try to look at the
It's because the name mangling. Names are mangled same with GCC and Clang (they often share similar mechanisms). Name mangling makes it available to have C/C++ method and Assembly procedure with the same name. See what happens to a C definition:
void myfunc() {}
We use nm
to view binary names of symbols. Use nm --demangle
to view unmangled names. Nm output for compiled file is:
...
0000000000000000 T _myfunc
...
Number of other symbols depends on debugging level, see GCC manpage for -O and -g options. As we see, there is a number. It's hexadecimal. It has eight digits on 32bit machines and sixteen digits on 64bit machines (it's because n-bit CPU means that n-bits represent a pointer, the symbol is really a pointer inside the binary file). Then we have symbol type. Only two values are interesting now: T
is a C/C++/... method, t
is an assembler procedure. See what goes on if we compile following assembly code:
myproc:
GCC and Clang shouldn't push debugging symbols when compiling Assembly, so nm
output will probably look like:
0000000000000000 t myproc
Assembly procedure names are not mangled. C++ is mangled, very strangely. Some characters, like :
or ,
are not allowed in symbol name. Compile this C++ source:
namespace myspace { void myfunc() {} }
We see output:
...
0000000000000000 T __ZN7myspace6myfuncEv
...
And main method name is never mangled. If we have like this:
int main(int argc, char** argv) {}
int main(std::vector<std::string> args) {}
only the second name is mangled. I think this may be the problem. And, these warnings mean NOTHING. They mean that system was recompiled with low debugging symbol count.