0
votes

I'm currently running a file manager program that abruptly crashed with a segmentation fault and dumped a core file. So I used gdb to debug the core file as:

gdb /path/to/executable /path/to/core

The program which I was running is written in C++. When I ran GDB and tried to print the source lines using "list", I got the following error:

(gdb) bt
#0  0x0000000000554286 in 
MyFSEventManager::AddEvent(wxFileSystemWatcherEvent&) ()
#1  0x00000000005ab2e8 in 
MyGenericDirCtrl::OnFileWatcherEvent(wxFileSystemWatcherEvent&) ()

(gdb) f 0
#0  0x0000000000554286 in 
MyFSEventManager::AddEvent(wxFileSystemWatcherEvent&) ()
(gdb) l
1    /build/glib2.0-prJhLS/glib2.0-2.48.2/./glib/gmain.c: No such file or directory.

Why does gdb say this "/build/glib2.0-prJhLS/glib2.0-2.48.2/./glib/gmain.c: No such file or directory." I do not hit this issue with some other programs that I've debugged using gdb.

The operating system used is Ubuntu 16.04 running on Oracle virtual box. I think may be the gdb symbols were not loaded. I'm not sure why since I compiled the program using the "-g" option. I really need to know the source lines where the code crashes via gdb.

Any suggestions?

EDIT: changes after suggestions from Employed Russian

I was compiling my main using "-g" option and linking it to "existing" object files which were obviously not compiled using "-g" so when the core dumped, I could not see the source for these files. So I went ahead and recompiled those files with "-g" option and reproduced the core dump. It's able to show me the source lines now.

1

1 Answers

1
votes

Why does gdb say this "/build/glib2.0-prJhLS/glib2.0-2.48.2/./glib/gmain.c: No such file or directory."

Because you really don't have that file on your system.

I think may be the gdb symbols were not loaded

GDB did load debug symbols for glib, but not for your main executable.

I'm not sure why since I compiled the program using the "-g" option.

Since we don't have your compile and link lines, we can't tell exactly what's wrong, but some of the common issues are:

  1. You have a "stray" -s or -Wl,-s on your link line (this strips debug info from the resulting binary).
  2. You have -g when compiling your main.c, but not when compiling the source in which MyFSEventManager::AddEvent() is defined

P.S.

(gdb) bt

This doesn't seem to be the complete output from bt command. Always try to paste complete outputs as it makes helping easier :)