(Preface: I'm pretty new to C/C++ and I don't really know how debugging in native code actually works.)
Some sources say that gdb and lldb can debug any program compiled to machine code. Others say that to debug with gdb you must compile in gcc with the -g
flag. The documentation for gcc itself suggests this is optional, and that in fact if you use it, it can cause problems for debuggers other than gdb. Clang also has a -g
flag and the documentation basically just says "Generate debug information."
So are these debuggers restricted to their own toolchains (GNU and LLVM), or are they somehow independent of the compiler used?
-gdwarf-2
- this tells gcc to emit debug info that conforms to an older version of the DWARF debug format specification. The current version is 4. Sometimes consumers (debuggers) won't understand all the newest features in the later DWARF standards so it's necessary to have the producer (compilers) not emit all the fanciest/newest constructs. But these problems are usually short-lived as the new features are supported in the consumers soon enough and everybody can live with plain old-g
and get along. – Millwright