【发布时间】: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