[0] https://bithavoc.io/blog/2020/01/01/go-binary-size-descision...
what do you mean ? in which case don't you get a backtrace in C++ ?
If you're taking first year programming and they give you a compiler incantation that doesn't include -g that will be your experience.
[profile.release]
debug = true
to make this work? $ cat test.c
int g() {
int *p = 0;
*p = 5;
}
int f() {
g();
}
int main() {
f();
}
$ cc test.c
$ ./a.out
[1] 3377 segmentation fault (core dumped) ./a.out
$ gdb -q a.out core
Reading symbols from a.out...
(No debugging symbols found in a.out)
[New LWP 3377]
Core was generated by `./a.out'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x0000557379b7613d in g ()
(gdb) bt
#0 0x0000557379b7613d in g ()
#1 0x0000557379b76158 in f ()
#2 0x0000557379b7616d in main ()Another wrinkle is that the symbol names of extern functions need to be in the binary regardless of debug level, though the main binary is a special case, unlike shared libraries. So you'll get different results again if you add -fPIC -rdynamic (or possibly just -fPIC) to -O3, similar results as-if you compiled a library with -O3 -fPIC -shared. But then if you define f and g as statically scoped -fPIC -rdynamic won't change the behavior.
It follows that there's a potential conflict between code optimization and the ability to determine function names and line numbers for a trace. To preserve the ability to associate the programer counter (PC) to distinct function names and line numbers a compiler might need to abstain from completely inlining, merging, eliding, or otherwise optimizing some functions and code blocks (though that doesn't mean it needs to preserve actual function call behavior). People will endlessly debate the cost+benefit, but it's something to keep in mind for performance critical code blocks.
uh... no. given
volatile char* foo = 0x0;
struct crasher
{
void crash()
{
*foo = 1;
}
};
int main()
{
crasher c;
c.crash();
}
and $ g++ foo.cpp
$ ./a.out
then $ coredumpctl gdb
gives me (gdb) bt
#0 0x000055cea1ff6187 in crasher::crash() ()
#1 0x000055cea1ff615c in main ()
The only case when you wouldn't get function names is if your binary has been stripped manually (or as part of a build system step)Gdb beyond what the learning person can comfortably handle at the time and that's what matters.
New programmers would be using IDEs, press the green arrow "play" button and launch the app with the debugger enabled without them knowing, which would cause the editor to jump directly to where the issue is
If they were teaching you rust be sure that they wouldn't have told you about cargo either.
I'm a self taught C/C++ programmer, learning and becoming comfortable with gdb was one of the first few things I taught myself after learning how to compile code into a binary back in the 1990's.
The Visual Studio Debugger is simply the best. Okay, it's not a powerhouse like WinDBG, or have the knowledge of IDAPro, and various other cool debuggers (OllyDbg, others..), but it's the easiest one to learn (IMHO), and teach. Few bits and tricks, press F5 and you are done :)