GDB 7.3.1 on OSX Lion - c++

I'm trying to use GDB (v 7.3.1) from macports to debug an executable compiled with
g++ 4.7 (also from macports). However, I start the debugger, I get the following output:
GNU gdb (GDB) 7.3.1 Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
http://gnu.org/licenses/gpl.html This is free software: you are free
to change and redistribute it. There is NO WARRANTY, to the extent
permitted by law. Type "show copying" and "show warranty" for
details. This GDB was configured as "x86_64-apple-darwin11.2.0". For
bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/... BFD: unable to read unknown
load command 0x24 BFD: unable to read unknown load command 0x26 BFD:
unable to read unknown load command 0x24 BFD: unable to read unknown
load command 0x26
Then, whenever I attempt to backtrace, the debugger is unable to provide any
information about the stack; I get output like:
> #0 0x00000001085106d5 in ?? ()
> #1 0x000000010833d9b6 in ?? ()
> #2 0x0000000107e23000 in ?? ()
> #3 0x00007f828341f630 in ?? ()
> #4 0x00007f828341bc10 in ?? ()
> #5 0x00007f8283421950 in ?? ()
> #6 0x00007f8283427020 in ?? ()
> #7 0x00007f8283425510 in ?? ()
> #8 0x00007f82834195e0 in ?? ()
> #9 0x0000000100000001 in ?? ()
> #10 0x0000000100000000 in ?? ()
I've built with debug symbols, and I'm able to debug the executable fine on
linux. Does anyone know what's going on here or how I might fix it. It's
really difficult to fix certain problems without a debugger!

I don't know much about OSX or usage of gdb on it, but this appears to have been fixed shorly
after the release of gdb 7.3.1, I seem to recall something about the release of OSX and the release of gdb or binutils being around the same time, with the developer not having any early access to OS X. You could try a later version of gdb.
I'm guessing that the following patch committed shortly after 7.3.1 fixes it:
http://permalink.gmane.org/gmane.comp.gnu.binutils/54607

GDB 7.4.1 had fixed this issue, you could get and build it.
http://sourceware.org/gdb/wiki/BuildingOnDarwin

Related

Why is CrashDump.exe hanging? How to go about debugging?

I'm using the CrashCatcher/CrashDebug code from https://github.com/adamgreen/CrashDebug.
My platform is an STM32H753 running freertos. I've been able to generate a dump file based on the HexDump.c example in CrashCatcher. So far so good. The problem arises when I try to run arm-none-eabi-gdb.exe and connect it to CrashDebug.exe. I'm running on windows 10 and using the stm32 tool chain. I built CrashDebug.exe locally using mingw. I run the following command line:
C:\ST\STM32CubeIDE_1.6.1\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_2.0.0.202105311346\tools\bin\arm-none-eabi-gdb.exe "fw-10143-sensor-hub-stm32-firmware\Debug\THOR_1.5_Sensor_Hub_FW.elf" -ex "set target-charset ASCII" -ex "target remote | /Users/felix/source/Thor/CrashDebug.exe --elf C:\Users\felix\source\Thor\fw-10143-sensor-hub-stm32-firmware\Debug\THOR_1.5_Sensor_Hub_FW.elf --dump C:\Users\felix\source\Thor\crash.dmp"
This runs gdb but the command interpreter becomes unresponsive and never returns to the gdb prompt. I can not even ctrl-c to break. I have to kill the process. Here is what gdb outputs before the hang.
C:\ST\STM32CubeIDE_1.6.1\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_2.0.0.202105311346\tools\bin\arm-none-eabi-gdb.exe: warning: Couldn't determine a path for the index cache directory.
GNU gdb (GNU Tools for STM32 9-2020-q2-update.20201001-1621) 8.3.1.20191211-git
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-w64-mingw32 --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from fw-10143-sensor-hub-stm32-firmware\Debug\THOR_1.5_Sensor_Hub_FW.elf...
Remote debugging using | /Users/felix/source/Thor/CrashDebug.exe --elf C:\Users\felix\source\Thor\fw-10143-sensor-hub-stm32-firmware\Debug\THOR_1.5_Sensor_Hub_FW.elf --dump C:\Users\felix\source\Thor\crash.dmp
I'd expect the gdb prompt to come back so I can get a stack trace out.
I tried running an instance of the mingw gdb and connecting to the running CrashDebug.exe process and halting it. When I do this I get the following stack trace.
(gdb) symbol-file c:/users/felix/source/Thor/CrashDebug/bins/win32/CrashDebug.exe
Load new symbol table from "c:\users\felix\source\Thor\CrashDebug\bins\win32\CrashDebug.exe"? (y or n) y
Reading symbols from c:\users\felix\source\Thor\CrashDebug\bins\win32\CrashDebug.exe...done.
(gdb) thread apply all bt
Thread 2 (Thread 3240.0x2804):
#0 0x77154d11 in ntdll!DbgBreakPoint () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1 0x7718dca9 in ntdll!DbgUiRemoteBreakin () from C:\WINDOWS\SYSTEM32\ntdll.dll
#2 0xaa43fb20 in ?? ()
#3 0x7718dc70 in ntdll!DbgUiIssueRemoteBreakin () from C:\WINDOWS\SYSTEM32\ntdll.dll
#4 0x7556fa29 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\System32\kernel32.dll
#5 0x77147a7e in ntdll!RtlGetAppContainerNamedObjectPath () from C:\WINDOWS\SYSTEM32\ntdll.dll
#6 0x77147a4e in ntdll!RtlGetAppContainerNamedObjectPath () from C:\WINDOWS\SYSTEM32\ntdll.dll
#7 0x00000000 in ?? ()
Thread 1 (Thread 3240.0xfc4):
#0 0x77152a1c in ntdll!ZwWriteFile () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1 0x7509f32c in WriteFile () from C:\WINDOWS\System32\KernelBase.dll
#2 0x00000134 in ?? ()
#3 0x00000000 in ?? ()
(gdb)
Not very helpful. I'm at a loss as to what to do next. Because of the way CrashDebug is launched I can not breakpoint and step through the code to see what is going wrong. Can anyone advise me as to how to get this working?
This issue has been resolved (very quickly) by the awesome author.
https://github.com/adamgreen/CrashDebug/issues/18

Opening core dump file with different executable but the same sources

I have a coredump file from a colleague's machine.
We both have the same sources for the program and the same third party *.so files (like libmysqlclient18 and several in-house ones).
The problem is that we both compile the software (from the same sources) independently and I want to use his core dump files for inspection with GDB on my machine.
When I try to load the core file and my executable into gdb I get:
user#ubuntu:/mnt/hgfs/share/dir$ gdb prog core
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /mnt/hgfs/share/dir/prog...done.
warning: exec file is newer than core file.
[New LWP 4465]
[New LWP 4462]
[New LWP 4464]
warning: Can't read pathname for load map: Input/output error.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/i386-linux-gnu/libthread_db.so.1".
Core was generated by `./prog'.
Program terminated with signal 11, Segmentation fault.
#0 0x002d3706 in ?? () from /lib/i386-linux-gnu/libc.so.6
(gdb) bt full
#0 0x002d3706 in ?? () from /lib/i386-linux-gnu/libc.so.6
No symbol table info available.
#1 0x00000000 in ?? ()
No symbol table info available.
(gdb)
Is this possible for this scenario to work? (I compile the software with debugging symbols enabled, of course)
If not, what are the technical details I'm missing?
I know for sure that it wouldn't be possible if he or I would make modifications to the source, since then the executable would be different, but this is not the case, the third party *.so files and the sources, they all match.
UPDATE:
After installing libc6-dbg as user mkfs suggested in the comments, I get this in gdb:
user#ubuntu:/mnt/hgfs/share/dir$ gdb prog core
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /mnt/hgfs/share/dir/prog...done.
warning: exec file is newer than core file.
[New LWP 4465]
[New LWP 4462]
[New LWP 4464]
warning: Can't read pathname for load map: Input/output error.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/i386-linux-gnu/libthread_db.so.1".
Core was generated by `./prog'.
Program terminated with signal 11, Segmentation fault.
#0 0x002d3706 in _IO_helper_overflow (s=0x0, c=0) at vfprintf.c:2188
2188 vfprintf.c: No such file or directory.
(gdb) bt
#0 0x002d3706 in _IO_helper_overflow (s=0x0, c=0) at vfprintf.c:2188
#1 0x00000000 in ?? ()
(gdb) bt full
#0 0x002d3706 in _IO_helper_overflow (s=0x0, c=0) at vfprintf.c:2188
written = 47
target = <optimized out>
used = -1226838776
#1 0x00000000 in ?? ()
No symbol table info available.
(gdb)
Is this possible for this scenario to work?
Yes, but you need to ensure that the symbol layout of the binary you build on both machines is identical (or at least close enough). This isn't necessarily trivial: things like local username, pathname for sources or installation directory, and hostname sometimes leak into the built object files, and may cause symbol mismatch.
To check whether the binaries are close, run diff <(nm a.out) <(nm b.out) -- there should only be few differences. If you see a lot of differences, your binaries aren't close enough.
I compile the software with debugging symbols enabled, of course
This may be your first mistake: if your coworker builds with -O2, and you build with -g (and implied -O0), the binary is guaranteed to not match.
You need to build with exactly the flags your coworker builds with (but you may add debugging symbols; e.g. if your coworker builds with -O2, you should build with -O2 -g together).
P.S. Note that you also need identical versions of system libraries on the two machines.

Compiling a Qt application in order to get better debuginfos (Linux)

I downloaded FabariaGest source code then to compile it you have to run:
on qt 4 systems:
cmake -DMAKE_INSTALL_PREFIX=directory -DWANT_QT4=ON -DWANT_QWT=ON
on qt5 systems:
cmake -DMAKE_INSTALL_PREFIX=directory -DWANT_QT5=ON -DWANT_QWTQT5=ON
When it finishes, you run
# make install
Since I get a segmentation fault when I start the software, I tried to run
cd /opt/fabaria_gest
gdb fabaria_gest
run
backtrace
but I only get
[user#localhost fabaria_gest]$ gdb fabaria_gest
GNU gdb (GDB) Fedora 7.9.1-19.fc22
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from fabaria_gest...(no debugging symbols found)...done.
(gdb) run
Starting program: /opt/fabaria_gest/fabaria_gest
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Detaching after fork from child process 7246.
[New Thread 0x7fffe0798700 (LWP 7244)]
Program received signal SIGSEGV, Segmentation fault.
0x00000000004f568c in QBasicAtomicInteger<int>::load() const ()
(gdb) backtrace
#0 0x00000000004f568c in QBasicAtomicInteger<int>::load() const ()
#1 0x0000000000502a92 in QtPrivate::RefCount::ref() ()
#2 0x0000000000502e37 in QString::QString(QString const&) ()
#3 0x00000000006b9709 in _ZL13getSystemInfov ()
#4 0x00000000006bc29f in main ()
(gdb)
#0 0x00
What can I do to recompile the software in order to get better debuginfos? Setting set follow-fork-mode in GDB did not help
Using
cmake -DCMAKE_BUILD_TYPE=Debug ...
will instruct cmake to generate debug information, which should make the backtrace easier to read.

Debugging PIN tool add-symbol-file doesn't work

To debug a simulator which uses PIN tool, by using 2 different terminal windows, I do the following:
/home/agy/mcsim/pin/intel64/bin/pinbin -pause_tool 5 -t /home/agy/mcsim/Pthread/mypthreadtool -port 47145 -skip_first 10000 -- McSim/JacNoBoost/JACCARD
Pausing to attach to pid 5465
To load the tool's debug info to gdb use:
add-symbol-file /home/agy/mcsim/Pthread/mypthreadtool 0x7f86e6c06ee0 -s .data 0x7f86e709f620 -s .bss 0x7f86e70aaac0
On the other window I do the following:
gdb /home/agy/mcsim/Pthread/mypthreadtool
GNU gdb (Ubuntu 7.7-0ubuntu3.1) 7.7
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /home/agy/mcsim/Pthread/mypthreadtool...done.
(gdb) attach 5465
Attaching to program: /home/agy/mcsim/Pthread/mypthreadtool, process 5465
0x0000000030592c70 in ?? ()
(gdb) add-symbol-file /home/agy/mcsim/Pthread/mypthreadtool 0x7f86e6c06ee0 -s .data 0x7f86e709f620 -s .bss 0x7f86e70aaac0
add symbol table from file "/home/agy/mcsim/Pthread/mypthreadtool" at
.text_addr = 0x7f86e6c06ee0
.data_addr = 0x7f86e709f620
.bss_addr = 0x7f86e70aaac0
(y or n) y
Reading symbols from /home/agy/mcsim/Pthread/mypthreadtool...done.
(gdb) c
Continuing.
At some point, pin tool freezes and i manually send interrupt signal to pin tool and try to debug it on the attached window. To understand at which line pin implementation stucks, I tried backtrace command but it returns with question marks even though the symbol file is added.
Program received signal SIGINT, Interrupt.
0x000000003052c474 in ?? ()
(gdb) backtrace
#0 0x000000003052c474 in ?? ()
#1 0x00007f86e5570850 in ?? ()
#2 0x000000003070c290 in ?? ()
#3 0x0000000001dda880 in ?? ()
#4 0x0000000001dda880 in ?? ()
#5 0x000000000040e03a in ?? ()
#6 0x0000000030643de0 in ?? ()
#7 0x00007f86d5ada0c0 in ?? ()
#8 0x0000000000000012 in ?? ()
#9 0x00007f86e5571350 in ?? ()
#10 0x0000000030aade20 in ?? ()
#11 0x0000000000000000 in ?? ()
I couldn't find the wrong approach here. Could you please help me?
I couldn't find the wrong approach here.
You are telling GDB that mypthreadtool is your main executable, but it is not: /home/agy/mcsim/pin/intel64/bin/pinbin is.
Try this:
gdb /home/agy/mcsim/pin/intel64/bin/pinbin 5465
(gdb) add-symbol-file /home/agy/mcsim/Pthread/mypthreadtool \
0x7f86e6c06ee0 -s .data 0x7f86e709f620 -s .bss 0x7f86e70aaac0

Debugging problems with MacPorts GCC on OS X

I can't seem to get readable debugging output for programs compiled with GCC 4.7 MacPorts build.
I've tried with both GDB 6.3 and GDB 7.3 and each have their own problems.
Try with GDB 7.3 (MacPorts)
With GDB 7.3 I get the following output on startup:
$ ggdb ./test
GNU gdb (GDB) 7.3
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin11.4.0".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
BFD: unable to read unknown load command 0x24
BFD: unable to read unknown load command 0x26
BFD: unable to read unknown load command 0x24
BFD: unable to read unknown load command 0x26
Reading symbols from /Users/StackedCrooked/programming/projects/stacked-crooked/Playground/LockOrderChecker/test...Reading symbols from /Users/StackedCrooked/programming/projects/stacked-crooked/Playground/LockOrderChecker/test.dSYM/Contents/Resources/DWARF/test...done.
done.
Running and triggering an assertion results in an unreadable stack trace:
(gdb) r
Starting program: /Users/StackedCrooked/programming/projects/stacked-crooked/Playground/LockOrderChecker/test
BFD: unable to read unknown load command 0x24
BFD: unable to read unknown load command 0x26
main
Assertion failed: (false), function lock, file main.cpp, line 168.
Program received signal SIGABRT, Aborted.
0x00007fff8ede282a in ?? ()
(gdb) bt
#0 0x00007fff8ede282a in ?? ()
#1 0x00007fff9a273a9c in ?? ()
#2 0x00007fff6af00690 in ?? ()
#3 0x0000003000000030 in ?? ()
#4 0x00007fffffffffdf in ?? ()
#5 0x000000010b305840 in ?? ()
#6 0x00007fff6af006d0 in ?? ()
#7 0x00007fff9a2a65de in ?? ()
#8 0x0000000000000000 in ?? ()
Try with GDB 6.3 (built-in)
According to this answer I should use GDB 6.3. However that leads to a different set of problems. During startup I get a bunch of errors:
GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Thu Nov 3 21:59:02 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries .
warning: Could not find object file "/Volumes/work/macports/var/macports/build/_Volumes_work_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libstdc++-v3/src/.libs/compatibility.o" - no debug information available for "../../../../gcc-4.7.1/libstdc++-v3/src/c++98/compatibility.cc".
warning: Could not find object file "/Volumes/work/macports/var/macports/build/_Volumes_work_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libstdc++-v3/src/.libs/compatibility-debug_list.o" - no debug information available for "../../../../gcc-4.7.1/libstdc++-v3/src/c++98/compatibility-debug_list.cc".
warning: Could not find object file "/Volumes/work/macports/var/macports/build/_Volumes_work_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libstdc++-v3/src/.libs/compatibility-debug_list-2.o" - no debug information available for "../../../../gcc-4.7.1/libstdc++-v3/src/c++98/compatibility-debug_list-2.cc".
This is what I see if an assertion is triggered and I try to get a backtrace:
Assertion failed: (false), function lock, file main.cpp, line 168.
Program received signal SIGABRT, Aborted.
0x00007fff8ede282a in __kill ()
(gdb) bt
#0 0x00007fff8ede282a in __kill ()
#1 0x00007fff9a273a9c in abort ()
#2 0x00007fff9a2a65de in __assert_rtn ()
Die: DW_TAG_unspecified_type (abbrev = 19, offset = 423)
has children: FALSE
attributes:
DW_AT_name (DW_FORM_strp) string: "decltype(nullptr)"
Die: DW_TAG_unspecified_type (abbrev = 19, offset = 423)
has children: FALSE
attributes:
DW_AT_name (DW_FORM_strp) string: "decltype(nullptr)"
Dwarf Error: Cannot find type of die [in module /Users/StackedCrooked/programming/projects/stacked-crooked/Playground/LockOrderChecker/test.dSYM/Contents/Resources/DWARF/test]
According to this answer (which quotes the GCC 4.5 manual) I should use the -gdwarf-2 -gstrict-dwarf options.
I followed this advice. My build command looks like this:
g++ -o run-test -std=c++0x -Wall -Wextra -Werror -gdwarf-2 -gstrict-dwarf -g2 -O0 -I/opt/local/include main.cpp
However, it doesn't fix any of the aforementioned problems.
For the record: I'm on OS X Lion.
Does anyone know how to fix this?
According to the g++ man pages you should use -ggdb to generate debug symbols for gdb. BTW, just using -g always generated good symbols for gdb in my experience (on linux, windows (mingw) and mac).
The warnings from your MacPorts gdb 7.3 session are for load commands 0x24 (LC_VERSION_MIN_MACOSX) and 0x26 (LC_FUNCTION_STARTS). These are new load commands but are not essential for debugging - the warnings are harmless. The fact that your session lacks any symbolic information is maybe because of ASLR? It's been years since that was introduced into the system for user land debugging but that's what the debugger output can look like if it doesn't know that everything slid around in memory at runtime.
Have you tried using lldb? The version provided in Xcode 4.5 is really quite nice. It is the debugger that Apple is currently supporting and developing actively, and it should work with the DWARF output by more recent compilers correctly. The command syntax is a little different than gdb (although there are many command shortcuts provided that make it familiar to gdb users), there's a table of gdb/lldb command equivalences provided over at http://lldb.llvm.org/lldb-gdb.html. Give it a try, you might like it.