【问题标题】:Segmentation fault only during GDB debugging仅在 GDB 调试期间出现分段错误
【发布时间】:2017-07-04 12:38:35
【问题描述】:

我交叉编译了使用 boost::asio 库的应用程序,并在我的目标系统上对其进行了测试。它工作正常。但是当我尝试使用 gdb 调试我的应用程序时,我在 gdb-console 中收到此消息:

Program received signal SIGSEGV, Segmentation fault.
_dl_debug_initialize (ldbase=4294967292, ns=1996288212) at dl-debug.c:55
55           if (r->r_map == NULL || ldbase != 0)

远程和本机调试以及其他几个 boost 库(但不是全部)的结果是相同的。在搜索任何可能有帮助的信息后,我在此文档(第 63 页)中发现了类似的问题:http://support.garz-fricke.com/products/Santaro/Linux-Yocto/Releases/Yocto-jethro-5.1-r6859-0/GUF-Yocto-jethro-5.1-r6859-0-IMX6GUF-Manual.pdf 如文档中所述,问题可能是由“隐式实现的 C++ 方法中的静态实例化”引起的,并且与 glibc 相关。所以我尝试通过这种方法用代码重现这个错误:

#include <iostream> 
using namespace std; 
class AClass 
{ 
public:   
  void foo()   
  {
    static int NmbOfInvokes = 0;
    NmbOfInvokes++;
    cout << NmbOfInvokes << endl;   
  } 
};
int main(void) 
{
  cout << "Hello World" << endl;

  AClass anInstance;
  anInstance.foo();
  anInstance.foo();
  return 0;
}

这个程序可以正常运行,但是在调试中失败并出现同样的 SIGSEGV 错误。

要修复它足以以这种方式重写 AClass 类:

class AClass
{
public:
  void foo();
};

void AClass::foo()
{
  static int NmbOfInvokes = 0;
  NmbOfInvokes++;
  cout << NmbOfInvokes << endl;
}

编译标志:

arm-poky-linux-gnueabi-g++  -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a7 --sysroot=/opt/fsl-imx-x11/4.1.15-1.2.0/sysroots/cortexa7hf-vfp-neon-poky-linux-gnueabi -DHAVE_CONFIG_H -I. -I..   --sysroot=/opt/fsl-imx-x11/4.1.15-1.2.0/sysroots/cortexa7hf-vfp-neon-poky-linux-gnueabi  -g -O0  --sysroot=/opt/fsl-imx-x11/4.1.15-1.2.0/sysroots/cortexa7hf-vfp-neon-poky-linux-gnueabi -MT SegFault_Reproduce.o -MD -MP -MF .deps/SegFault_Reproduce.Tpo -c -o SegFault_Reproduce.o SegFault_Reproduce.cpp mv -f .deps/SegFault_Reproduce.Tpo .deps/SegFault_Reproduce.Po
../arm-poky-linux-gnueabi-libtool  --tag=CXX   --mode=link arm-poky-linux-gnueabi-g++  -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a7 --sysroot=/opt/fsl-imx-x11/4.1.15-1.2.0/sysroots/cortexa7hf-vfp-neon-poky-linux-gnueabi  -g -O0  --sysroot=/opt/fsl-imx-x11/4.1.15-1.2.0/sysroots/cortexa7hf-vfp-neon-poky-linux-gnueabi  --sysroot=/opt/fsl-imx-x11/4.1.15-1.2.0/sysroots/cortexa7hf-vfp-neon-poky-linux-gnueabi -o SegFault_Reproduce SegFault_Reproduce.o  
arm-poky-linux-gnueabi-libtool: link: arm-poky-linux-gnueabi-g++ -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a7 --sysroot=/opt/fsl-imx-x11/4.1.15-1.2.0/sysroots/cortexa7hf-vfp-neon-poky-linux-gnueabi -g -O0 --sysroot=/opt/fsl-imx-x11/4.1.15-1.2.0/sysroots/cortexa7hf-vfp-neon-poky-linux-gnueabi --sysroot=/opt/fsl-imx-x11/4.1.15-1.2.0/sysroots/cortexa7hf-vfp-neon-poky-linux-gnueabi -o SegFault_Reproduce SegFault_Reproduce.o

我想在某些 boost 库中使用了类似的静态实例化,因为症状完全一样。

我可以做些什么来获得调试 boost 应用程序的可能性?

我使用的软件包版本:yocto 2.0.1、gcc 5.2.0、gdb 7.9.1、boost 1.58。

【问题讨论】:

    标签: boost gdb embedded-linux glibc yocto


    【解决方案1】:

    但是当我尝试使用 gdb 调试我的应用程序时,我收到了这条消息

    这表明 GDB 中存在错误。您的版本:7.9.1 已经快 2 年了。您的第一步应该是尝试更新的 GDB 版本。

    “在 GDB 下”和“本机”执行之间的一个区别是 GDB 禁用了 ASLR。

    您可以在运行程序之前尝试(gdb) set disable-randomization off。但鉴于您描述的症状,我怀疑这与问题有关。

    【讨论】:

    • @Employed_Russian,感谢您的回复! set disable-randomization off 没有帮助我,所以我会尝试更新版本的 GDB 并报告结果。
    • @Employed_Russian,你说的非常对!将 GDB 更新到 7.11.1 后,我的问题消失了。非常感谢!
    猜你喜欢
    • 2012-10-24
    • 2015-09-15
    • 2018-03-26
    • 2015-12-23
    • 2019-03-25
    • 1970-01-01
    • 2013-12-28
    • 2011-06-05
    相关资源
    最近更新 更多