GDB cannot find source file

I'm trying to debug my OpenCV code , but gdb won't load the OpenCV source file.

Checking for the presence of a source file:

$ls -l /home/rui/DriveSo/opencv/modules/core/src/matrix.cpp
-rw-r--r-- 1 rui rui 156046 May 11 21:46 /home/rui/DriveSo/opencv/modules/core/src/matrix.cpp

      

After linking with the OpenGV Debug mode libraries, I start dbg and add it to the list of source directories :

$gdb DriveSo
GNU gdb (Debian 7.7.1+dfsg-5) 7.7.1
....
Reading symbols from DriveSo...done.
(gdb) directory /home/rui/DriveSo/opencv/modules/core/src
Source directories searched: /home/rui/DriveSo/opencv/modules/core/src:$cdir:$cwd
(gdb) break matrix.cpp:2349
No source file named matrix.cpp.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (matrix.cpp:2349) pending.

      

Even after starting a session, gdb still doesn't find the original file:

(gdb) start
Temporary breakpoint 2 at 0x41d2cf: file ../../DriveSo.dkt/main.cpp, line 11.
Starting program: /home/rui/DriveSo/repositories/trunk/builds/build-DriveSo-Desktop_Qt_5_5_0_GCC_64bit-Debug/DriveSo
....
Temporary breakpoint 2, main (argc=1, argv=0x7fffffffe5a8) at ../../DriveSo.dkt/main.cpp:11
11 QCoreApplication::setApplicationName(QString("DriveSo"));
(gdb)

      

What could be causing this (for me) unexpected behavior?

Following on from iksajotien's suggestion, as far as I can see the executable has debug information ...

$ objdump --syms DriveSo | grep debug
0000000000000000 l    d  .debug_aranges 0000000000000000              .debug_aranges
0000000000000000 l    d  .debug_info    0000000000000000              .debug_info
0000000000000000 l    d  .debug_abbrev  0000000000000000              .debug_abbrev
0000000000000000 l    d  .debug_line    0000000000000000              .debug_line
0000000000000000 l    d  .debug_str 0000000000000000              .debug_str
0000000000000000 l    d  .debug_ranges  0000000000000000              .debug_ranges

      

... and the shared libraries it opened ...

$ lsof -p 12159 
COMMAND   PID USER   FD      TYPE             DEVICE   SIZE/OFF      NODE NAME
...
DriveSo 12159  rui  mem       REG                8,6   20289800  26740265 /usr/local/lib/libopencv_core.so.3.1.0
...

      

... also have debug information.

$ objdump --syms /usr/local/lib/libopencv_core.so.3.1.0 | grep debug
0000000000000000 l    d  .debug_aranges 0000000000000000              .debug_aranges
0000000000000000 l    d  .debug_info    0000000000000000              .debug_info
0000000000000000 l    d  .debug_abbrev  0000000000000000              .debug_abbrev
0000000000000000 l    d  .debug_line    0000000000000000              .debug_line
0000000000000000 l    d  .debug_str 0000000000000000              .debug_str
0000000000000000 l    d  .debug_ranges  0000000000000000              .debug_ranges

      

General information about gdb:

$gdb DriveSo
GNU gdb (Debian 7.7.1+dfsg-5) 7.7.1
...
Reading symbols from DriveSo...done.
(gdb) run
Starting program: /home/rui/DriveSo/repositories/trunk/builds/build-DriveSo-Desktop_Qt_5_5_0_GCC_64bit-Debug/DriveSo 
...
^C
Program received signal SIGINT, Interrupt.
...
(gdb) info shared
From                To                  Syms Read   Shared Object Library
0x00007ffff7ddcae0  0x00007ffff7df5130  Yes         /lib64/ld-linux-x86-64.so.2
                                        No          linux-vdso.so.1
0x00007ffff7158860  0x00007ffff794a910  Yes         /usr/local/lib/libopencv_core.so.3.1
0x00007ffff6e5d880  0x00007ffff6e63a0b  Yes         /usr/local/lib/libopencv_highgui.so.3.1
0x00007ffff5493840  0x00007ffff690ce00  Yes         /usr/local/lib/libopencv_imgproc.so.3.1
0x00007ffff50aa6f0  0x00007ffff5158bd1  Yes         /usr/local/lib/libopencv_features2d.so.3.1
0x00007ffff4db8640  0x00007ffff4e3de75  Yes         /usr/local/lib/libopencv_imgcodecs.so.3.1
0x00007ffff4b72a80  0x00007ffff4b931b0  Yes         /usr/local/lib/libopencv_videoio.so.3.1
0x00007ffff47b7d40  0x00007ffff4920f80  Yes         /usr/local/lib/libopencv_calib3d.so.3.1
...
---Type <return> to continue, or q <return> to quit---

      

Looking at the gdb source code , solib.c has a line at line 1053:

   if (! ui_out_is_mi_like_p (interp_ui_out (top_level_interpreter ()))
          && so->symbols_loaded
          && !objfile_has_symbols (so->objfile))
        {
          so_missing_debug_info = 1;
          ui_out_field_string (uiout, "syms-read", "Yes (*)");
        }
      else
        ui_out_field_string (uiout, "syms-read",
                             so->symbols_loaded ? "Yes" : "No");

      

So I assume the symbols are loaded and the debug information exists, otherwise the libraries will be listed with Yes (*) or No

+1


source to share


1 answer


I faced exactly the same problem and fixed it by adding rpath to my makefile.



g++ -o $@ $< -L$(LIBS) -lmylib -Wl,-rpath,$(LIBS)

      

0


source







All Articles