On MinGW's GDB (7.6.1) I sometimes run into the problem that a SegFault does not leave much useful information on the stacks (see transcript below).
For the error in the transcript I know why it occured: I called fseeki64 with a bad value as file-pointer. The fseeki64 does appear in the stack-trace but I cant see which part of my program indirectly called it.
I dont want to see the Microsoft symbols, I want to see the part of the stack that belongs to my program (which was compiled with -g).
Since I dont run into SegFaults often, my current workaround is some manual labor: 'next' through main (spamming enter) to find out which top-level function was responsible, restart, 'step' (spamming enter) through that function until the segfault.
GNU gdb (GDB) 7.6.1
Copyright (C) 2013 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 "mingw32".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from A:\prj\lib\fileBuffer\test.exe...done.
(gdb) r
Starting program: A:\prj\lib\fileBuffer/test.exe
[New Thread 3408.0x4094]
[New Thread 3408.0x3e40]
[New Thread 3408.0x4c14]
[New Thread 3408.0x5754]
Program received signal SIGSEGV, Segmentation fault.
0x77e2b2e3 in ?? ()
(gdb) info thr
Id Target Id Frame
4 Thread 3408.0x5754 0x77e5396c in ?? ()
3 Thread 3408.0x4c14 0x77e5396c in ?? ()
2 Thread 3408.0x3e40 0x77e5396c in ?? ()
* 1 Thread 3408.0x4094 0x77e2b2e3 in ?? ()
(gdb) where
#0 0x77e2b2e3 in ?? ()
#1 0x74d38384 in msvcrt!__p__iob () from C:\WINDOWS\SysWOW64\msvcrt.dll
#2 0x000000f4 in ?? ()
#3 0x000000d4 in ?? ()
#4 0x0063fd88 in ?? ()
#5 0x74d43175 in msvcrt!_fseeki64 () from C:\WINDOWS\SysWOW64\msvcrt.dll
#6 0x000000d4 in ?? ()
#7 0x0ab2d946 in ?? ()
#8 0x00000000 in ?? ()
(gdb) thr 2
[Switching to thread 2 (Thread 3408.0x3e40)]
#0 0x77e5396c in ?? ()
(gdb) where
#0 0x77e5396c in ?? ()
#1 0x75588744 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\SysWOW64\kernel32.dll
#2 0x77e4582d in ?? ()
#3 0x77e457fd in ?? ()
#4 0x00000000 in ?? ()
(gdb) thr 3
[Switching to thread 3 (Thread 3408.0x4c14)]
#0 0x77e5396c in ?? ()
(gdb) where
#0 0x77e5396c in ?? ()
#1 0x75588744 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\SysWOW64\kernel32.dll
#2 0x77e4582d in ?? ()
#3 0x77e457fd in ?? ()
#4 0x00000000 in ?? ()
(gdb) thr 4
[Switching to thread 4 (Thread 3408.0x5754)]
#0 0x77e5396c in ?? ()
(gdb) where
#0 0x77e5396c in ?? ()
#1 0x75588744 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\SysWOW64\kernel32.dll
#2 0x77e4582d in ?? ()
#3 0x77e457fd in ?? ()
#4 0x00000000 in ?? ()
(gdb)
Related
I simply try to open a file through a dialog using Gtk3. This is the code I am using, no modifications at all:
https://docs.gtk.org/gtk3/class.FileChooserNative.html#typical-usage-gtkfilechoosernative-typical-usage
The window opens fine but when I try to open the file, it segfaults. According to gdb:
Thread 1 "a.out" received signal SIGSEGV, Segmentation fault.
__strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:76
76 VPCMPEQ (%rdi), %ymm0, %ymm1
Using debuginfod of course. What am I doing wrong?
EDIT: Some backtrace from gdb:
(gdb) bt
#0 __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:76
#1 0x00007ffff7e1b948 in __GI__IO_puts (str=0x0) at ioputs.c:35
#2 0x00005555555551d6 in main (argc=1, argv=0x7fffffffdb28) at main.c:6
I experience problems analyzing a core dump for an ELF executable accompanied by symbol-file.
Without symbols file I see just function name symbols in back trace:
Core was generated by `./DSWP.out'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x00005614b4dc58fd in ntl_avl3_find ()
[Current thread is 1 (LWP 1344)]
(gdb) bt
#0 0x00005614b4dc58fd in ntl_avl3_find ()
#1 0x00005614b3ed4c03 in qbra_aro_find_route ()
#2 0x00005614b3ed5c70 in qbra_is_aro_lu_route_found ()
#3 0x00005614b3ed71ba in qbra_aro_add_route ()
#4 0x00005614b3f33c9b in qbum_cont_aro_announced ()
#5 0x00005614b3e4fe4f in qbdc_sub_stage_aro_announce ()
#6 0x00005614b3e4e23b in qbdc_do_work_part_3 ()
#7 0x00005614b3e4f4a0 in qbdc_do_work ()
#8 0x00005614b3ef20d3 in qbrm_conn_fsm ()
#9 0x00005614b3f0c282 in qbrm_process_established ()
#10 0x00005614b3df1a60 in qbrm_receive_proc ()
#11 0x00005614b4dfa78d in nbb_dispatch_process ()
#12 0x00005614b4dfc0f5 in nbb_schedule_one ()
#13 0x00005614b4e0effe in nbb_mp_scheduler ()
#14 0x00005614b4e0f0cb in nbb_sched_thread_main_fn ()
#15 0x00007f6284399ed4 in ?? () from /lib64/libpthread.so.0
#16 0x00007f6283bf5e4f in clone () from /lib64/libc.so.6
And when I load symbol-file, the stack gets shorter and some symbols disappear:
(gdb) symbol-file DSWP.symbols
Reading symbols from DSWP.symbols...
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
(gdb) bt
#0 0x00005614b4dc58fd in ntl_avl3_find (tree=0x4c026e90, key=key#entry=0x7f61717f9ae8, tree_info=0x4c026ea8) at code/comn/ntlavll.c:510
#1 0x00005614b3ed4c03 in qbra_aro_find_route (aro_cb=<optimized out>, dest_prefix=<optimized out>) at code/bgp/qbraaro1.c:1538
#2 0x00007f616001b7c0 in ?? ()
#3 0x00007f61717f9b20 in ?? ()
#4 0x00005614b3ed5c70 in qbra_is_aro_lu_route_found (nlri=0x7f616001b7c0, route_aro_cb=0x7f614c026c78) at code/bgp/qbraaro1.c:2233
Is there a way to verify executable and symbol-file are compatible with each other? or to understand what went wrong while creating the symbols file?
I'm using gdb-7.11.1 and I get this message on my embedded powerpc system. Some more background, the libpthread I use has been stripped off all the non-dynamic symbols, including nptl_version, which libthread_db uses to make sure it is compatible with libpthread.
Coming to my problem, gdb says it won't be able to debug threads, but it seemingly can as evidenced below. Am I simply misunderstanding what 'thread debugging' means? (The ?? you see are naturally due to the missing symbol table in libpthread)
(gdb) break fn2
Breakpoint 1 at 0x1000052c: file test.c, line 7.
(gdb) run
Starting program: /tmp/test
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
[New LWP 21312]
[New LWP 21313]
[New LWP 21314]
[New LWP 21315]
[New LWP 21316]
[New LWP 21317]
[Switching to LWP 21315]
Thread 5 hit Breakpoint 1, fn2 () at test.c:7
7 test.c: No such file or directory.
(gdb) thread apply all bt
Thread 7 (LWP 21317):
#0 0x0fdcf030 in ?? () from /lib/libpthread.so.0
#1 0x0fdc892c in pthread_mutex_lock () from /lib/libpthread.so.0
#2 0x00000000 in ?? ()
Thread 6 (LWP 21316):
#0 0x0fdcf030 in ?? () from /lib/libpthread.so.0
#1 0x0fdc892c in pthread_mutex_lock () from /lib/libpthread.so.0
#2 0x00000000 in ?? ()
Thread 5 (LWP 21315):
#0 fn2 () at test.c:7
#1 0x0fdc6d8c in ?? () from /lib/libpthread.so.0
#2 0x0fd26074 in clone () from /lib/libc.so.6
Thread 4 (LWP 21314):
#0 0x0fdcf030 in ?? () from /lib/libpthread.so.0
#1 0x0fdc892c in pthread_mutex_lock () from /lib/libpthread.so.0
#2 0x00000000 in ?? ()
Thread 3 (LWP 21313):
#0 0x0fdcf030 in ?? () from /lib/libpthread.so.0
#1 0x0fdc892c in pthread_mutex_lock () from /lib/libpthread.so.0
#2 0x00000000 in ?? ()
Thread 2 (LWP 21312):
#0 0x0fdcefdc in ?? () from /lib/libpthread.so.0
#1 0x0fdc892c in pthread_mutex_lock () from /lib/libpthread.so.0
#2 0x00000000 in ?? ()
Thread 1 (LWP 21309):
#0 0x0fd26038 in clone () from /lib/libc.so.6
#1 0x0fdc5f2c in ?? () from /lib/libpthread.so.0
#2 0x0fde6150 in ?? () from /lib/libpthread.so.0
#3 0x0fdc6424 in pthread_create () from /lib/libpthread.so.0
#4 0x100006a4 in main () at test.c:23
(gdb)
On Linux (at least, and others), an important part of the threading library is implemented in the kernel: that the "kernel-thread", called LWPs (for light-weight process).
GDB doesn't need libthread_db help to track them, as the OS itself can give the information the key information about them: their CPU registers (mainly IP, SP, FP).
I'm not sure what libthread_db provides in that context. The only thing I can think of is the LWP <-> Thread id mapping:
* 3 Thread 0x7ffff6d19700 (LWP 21571) "erato" primes_computer_runner2 (param=0x7fffffffca50) at erato.c:46
1 Thread 0x7ffff7fad700 (LWP 21565) "erato" 0x00007ffff7bc568d in pthread_join () from /usr/lib/libpthread.so.0
(gdb) print/x thread_handle
$1 = 0x7ffff6d19700
See, Thread 0x7ffff7fad700 maps to LWP 21565.
In comparison, without libthread_db it just gives the LWP id (in another run):
* 3 LWP 22060 "erato" primes_computer_runner2 (param=0x7fffffffca50) at erato.c:46
1 LWP 22058 "erato" 0x00007ffff76037b1 in clone () from /usr/lib/libc.so.6
If you want further details about pthread_db purpose, and why it's mandatory (or something equivalent) for user and hybrid threading libraries, you can take a look at this article I wrote several years ago:
User Level DB: a Debugging API for User-Level Thread Libraries
The common cause for this error message:
Unable to find libthread_db matching inferior's thread library, ...
is having libpthread.so.0 that is fully stripped. Don't do that.
In particular, libthread_db.so needs nptl_version (local) symbol. You can verify whether your libpthread.so.0 has it with:
nm /path/to/libpthread.so.0 | grep version
which should produce something like:
0000000000012cc6 r nptl_version
I'm trying to make skeleton SDL2 application on Xubuntu 14.04 (every packages are up to date).
Here is the my init function source code:
int map_x = 50;
int map_y = 20;
//The window we'll be rendering to
SDL_Window *gWindow = NULL;
//The window renderer
SDL_Renderer* gRenderer = NULL;
void
init() {
if (SDL_Init(SDL_INIT_VIDEO) < 0)
eprintf("SDL could not initialize: %s\n", SDL_GetError());
gWindow = SDL_CreateWindow( "SDL Tutorial",\
SDL_WINDOWPOS_UNDEFINED,\
SDL_WINDOWPOS_UNDEFINED,\
map_x, map_y,\
SDL_WINDOW_SHOWN);
if (gWindow == NULL)
eprintf( "window could not be created: %s\n", SDL_GetError());
gRenderer = SDL_CreateRenderer( gWindow, -1,\
SDL_RENDERER_ACCELERATED);
if (gRenderer == NULL)
eprintf("renderer could not be created: %s\n", SDL_GetError());
//Initialize renderer color
SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
}
But it seg faults inside SDL_CreateRenderer function. Here is gdb output:
(gdb) run
Starting program: /home/ghi/Desktop/tron/client
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault.
0x0000000000005885 in ?? ()
(gdb) up
#1 0x00007ffff67dce02 in XCloseIM ()
from /usr/lib/x86_64-linux-gnu/libX11.so.6
(gdb)
#2 0x00007ffff7b8d4fb in ?? () from /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0
(gdb)
#3 0x00007ffff7b81cce in ?? () from /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0
(gdb)
#4 0x00007ffff7aed785 in ?? () from /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0
(gdb)
#5 0x00007ffff7aed8c8 in ?? () from /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0
(gdb)
#6 0x0000000000400cc5 in close () at client.c:56
56 SDL_Quit();
(gdb)
#7 0x00007ffff464d723 in ?? () from /lib/x86_64-linux-gnu/libdbus-1.so.3
(gdb)
#8 0x00007ffff4645a46 in ?? () from /lib/x86_64-linux-gnu/libdbus-1.so.3
(gdb)
#9 0x00007ffff4644ea7 in ?? () from /lib/x86_64-linux-gnu/libdbus-1.so.3
(gdb)
#10 0x00007ffff4630e72 in ?? () from /lib/x86_64-linux-gnu/libdbus-1.so.3
(gdb)
#11 0x00007ffff7b8d534 in ?? () from /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0
(gdb)
#12 0x00007ffff7b81cce in ?? () from /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0
(gdb)
#13 0x00007ffff7aed785 in ?? () from /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0
(gdb)
#14 0x00007ffff7aed8c8 in ?? () from /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0
(gdb)
#15 0x0000000000400cc5 in close () at client.c:56
56 SDL_Quit();
(gdb)
#16 0x00007ffff217ab35 in ?? () from /usr/lib/nvidia-331/libGL.so.1
(gdb)
#17 0x00007ffff0bbda41 in ?? ()
from /usr/lib/nvidia-331/libnvidia-glcore.so.331.113
(gdb)
#18 0x00007ffff0ef1814 in ?? ()
from /usr/lib/nvidia-331/libnvidia-glcore.so.331.113
(gdb)
#19 0x00007ffff0efd869 in ?? ()
from /usr/lib/nvidia-331/libnvidia-glcore.so.331.113
(gdb)
#20 0x00007ffff0db2238 in ?? ()
from /usr/lib/nvidia-331/libnvidia-glcore.so.331.113
(gdb)
#21 0x00007ffff0dbd8a7 in ?? ()
from /usr/lib/nvidia-331/libnvidia-glcore.so.331.113
(gdb)
#22 0x00007ffff0ba34b3 in ?? ()
from /usr/lib/nvidia-331/libnvidia-glcore.so.331.113
(gdb)
#23 0x00007ffff0b8665c in ?? ()
from /usr/lib/nvidia-331/libnvidia-glcore.so.331.113
(gdb)
#24 0x00007ffff2122b30 in ?? () from /usr/lib/nvidia-331/libGL.so.1
(gdb)
#25 0x00007ffff2122cdc in ?? () from /usr/lib/nvidia-331/libGL.so.1
(gdb)
#26 0x00007ffff2153f59 in ?? () from /usr/lib/nvidia-331/libGL.so.1
(gdb)
#27 0x00007ffff7b8c0ad in ?? () from /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0
(gdb)
#28 0x00007ffff7b80be6 in ?? () from /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0
(gdb)
#29 0x00007ffff7b80e95 in ?? () from /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0
(gdb)
#30 0x00007ffff7b2ea44 in ?? () from /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0
(gdb)
#31 0x00007ffff7b284c0 in ?? () from /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0
(gdb)
#32 0x0000000000400c38 in init () at client.c:38
38 gRenderer = SDL_CreateRenderer( gWindow, -1,\
(gdb)
#33 0x0000000000400cef in main (argc=1, argv=0x7fffffffdf48) at client.c:61
61 init();
And Makefile:
client : client.o
gcc client.o -Wall -lm -o client `sdl2-config --cflags --libs`
client.o : client.c
gcc -ggdb3 -lm -Wall -c client.c `sdl2-config --cflags --libs`
I'm using libsdl2-dev from official repositories. Do anyone know what is wrong here?
Entire source can be found here: https://github.com/hafron/tron/blob/master/client.c
(posted previously as a comment, turned out to be an answer; some typos fixed)
I know nothing about SDL using, but the stack dump shows your close() function was called from inside the nvidia library. I suspect you superseded some other close identifier with your function. Try making your close strictly local by prepending a static keyword to the declaration: static void close() {...} or renaming the function to some my_close() or whatever...
We have some unit tests that often deadlock. Closer inspection with GDB reveals the following:
Thread 1:
(gdb) bt
#0 0x00110424 in __kernel_vsyscall ()
#1 0x00c681a3 in __lll_lock_wait_private () from /lib/libc.so.6
#2 0x00bf09fb in _L_lock_515 () from /lib/libc.so.6
#3 0x00bf068c in tr_mallochook () from /lib/libc.so.6
#4 0x00bece22 in calloc () from /lib/libc.so.6
#5 0x00b5ed93 in _dl_new_object () from /lib/ld-linux.so.2
#6 0x00b5b287 in _dl_map_object_from_fd () from /lib/ld-linux.so.2
#7 0x00b5c521 in _dl_map_object () from /lib/ld-linux.so.2
#8 0x00b66f43 in dl_open_worker () from /lib/ld-linux.so.2
#9 0x00b629a6 in _dl_catch_error () from /lib/ld-linux.so.2
#10 0x00b66a06 in _dl_open () from /lib/ld-linux.so.2
#11 0x00d38c3b in dlopen_doit () from /lib/libdl.so.2
#12 0x00b629a6 in _dl_catch_error () from /lib/ld-linux.so.2
#13 0x00d3903c in _dlerror_run () from /lib/libdl.so.2
#14 0x00d38b71 in dlopen##GLIBC_2.1 () from /lib/libdl.so.2
...
Thread 2:
#0 0x00110424 in __kernel_vsyscall ()
#1 0x00d4c059 in __lll_lock_wait () from /lib/libpthread.so.0
#2 0x00d4740e in _L_lock_752 () from /lib/libpthread.so.0
#3 0x00d4731a in pthread_mutex_lock () from /lib/libpthread.so.0
#4 0x00c95dd2 in _dl_addr () from /lib/libc.so.6
#5 0x00bf0425 in tr_where () from /lib/libc.so.6
#6 0x00bf06bd in tr_mallochook () from /lib/libc.so.6
#7 0x00bed01b in malloc () from /lib/libc.so.6
....
I did a lot of searches on the Internet but I can't really find out whether I am doing something wrong, or whether I have found a bug in the libraries.
glibc's dlopen() code doesn't seem to be thread safe.
It looks like your code calls malloc() and dlopen() concurrently from two threads. It also looks like malloc() call hits an unresolved dynamic symbol and tries to resolve it using _dl_addr(), which implies that the binary you are executing was linked with lazy binding (default ld behaviour) and this is why the runtime linker resolves symbols on demand on the first call. Try linking it with -Wl,-z,now gcc linker option to cause the runtime linker resolve all symbols prior to starting your application.
This bug looks similar to the one I filed a bug report against.