GDB断点失效(2)

编程入门 行业动态 更新时间:2024-10-24 18:18:54

上一篇说过,GDB使用的时候表现很奇怪,

线程都看不到,只能看到主线程,打其他线程的断点,都失效。

刚刚把源码也放到目录下,断点是打到了,但是同时程序也退出了。

提示信息如下:

Program terminated with signal SIGTRAP, Trace/breakpoint trap.

百度之后,发现GDB WIKI里有一个问题描述很类似。

http://sourceware/gdb/wiki/FAQ#GDB_does_not_see_any_threads_besides_the_one_in_which_crash_occurred.3B_or_SIGTRAP_kills_my_program_when_I_set_a_breakpoint.

<span style="font-size:18px;">GDB does not see any threads besides the one in which crash occurred; 
or SIGTRAP kills my program when I set a breakpoint.</span>

    This frequently happen on Linux, especially on embedded targets. There are two common causes:

     (1)   you are using glibc, and you have stripped libpthread.so.0

     (2)   mismatch between libpthread.so.0 and libthread_db.so.1 

    GDB itself does not know how to decode "thread control blocks" maintained by glibc and considered to be glibc private implementation detail.
    It uses libthread_db.so.1 (part of glibc) to help it do so. Therefore, libthread_db.so.1 and libpthread.so.0 must match in version and compilation flags. In addition, libthread_db.so.1 requires certain non-global symbols to be present in libpthread.so.0. Solution: use strip --strip-debug libpthread.so.0 instead of strip libpthread.so.0. 

既然是库的问题,就查一下GDB加载时的一堆提示(loading .....so)

在/lib目录下只看到libpthread.so.0,板子上没有libthread_db.so.1。

果然,在启动提示中有一段:

Reading symbols from /lib/libpthread.so.0...(no debugging symbols found)...done.                                                    
      
warning: File "/lib/libthread_db.so.1" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-
load".   
To enable execution of this file add    
        add-auto-load-safe-path /lib/libthread_db.so.1  
line to your configuration file "/home/root/.gdbinit".  
To completely disable this security protection add  
        set auto-load safe-path /    
line to your configuration file "/home/root/.gdbinit".    
For more information about this security protection see the    
"Auto-loading safe path" section in the GDB manual.  E.g., run from the shell:   
        info "(gdb)Auto-loading safe path"     
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.      
Loaded symbols for /lib/libpthread.so.0

也就是说,"/lib/libthread_db.so.1"没找到,应该符合第二条原因。


把这些库和配置按文档说明做好之后。

依然还是不行。

最后定位出来,原来是同事给错了GDB....拿之前不知道什么板子编译出来的。


另一篇文章里,介绍了GDB的编译。替换以后,就OK了。

真是一篇无耻的文章。

更多推荐

GDB断点失效(2)

本文发布于:2023-06-14 07:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1451568.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:断点   GDB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!