GDB找不到源文件 [英] GDB can't find source file

查看:325
本文介绍了GDB找不到源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试调试OpenCV代码,但是 gdb 无法加载OpenCV源文件.

I am trying to debug into OpenCV code but gdb fails to load the OpenCV 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

与OpenCV调试模式库链接后,我启动 dbg 并将其添加到源目录的列表中:

After linking with OpenCV Debug mode libraries I start dbg and add this 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.

即使在启动会话后,gdb仍然找不到源文件:

Even after starting the session gdb still does not find the source 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 can be causing this (to me) unexpected behavior?

根据iksajotien的建议,据我所知可执行文件具有调试信息...

Following up on the suggestion by iksajotien, as far as I 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 opened by it...

$ 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

共享的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---

查看 gdb源代码,solib.c在第1053行具有以下内容:

Looking at gdb source code solib.c has the following 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");

因此,我假设符号已加载并且调试信息存在,否则库将以是(*)

I therefore assume symbols are loaded and debug info exists otherwise libraries would be listed with Yes (*) or No

推荐答案

我遇到了完全相同的问题,并通过将rpath附加到我的makefile中来解决了这个问题.

I faced the exact same issue and fixed it by appending an rpath to my makefile.

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

这篇关于GDB找不到源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆