有什么方法可以找到从哪个类抛出段错误吗?

问题描述 投票:0回答:1

段错误是由于对

std::mutex::lock
si_addr = 0x278
si_code = SEGV_MAPERR
的读取访问造成的。

程序中内联函数过多,堆栈仅提供有限的信息,不够充分。段错误是由某个部署引发的,我们不知道如何重现该错误。

IMO,

0x278
偏移量太小,所以它一定是某个类中的偏移量。比如应该是像下面这样的情况

struct Dummy
{
    char c[0x278];
    std::mutex mtx;
};

std::lock_guard lock (reinterpret_cast<Dummy*>(nullptr)->mtx);

然而,在检查了一些候选类别后,我们发现没有

std::mutex
0x278
有偏移。

所以我想知道是否有一些魔法可以让我们扫描某个命名空间内的所有类,并找到在偏移量 0x278 处定义了 std::mutex 的所有类?

编辑

下面是我见过的堆栈。我删除了一些额外的消息,例如位置,以使其更具可读性。

faultSignalHandler(int, siginfo_t*, void*)
<unknown symbol>
___pthread_mutex_lock
std::__1::mutex::lock()
tDB::LearnerReadWorker::waitUntilDataAvailable(std::__1::unordered_map<unsigned long, DB::RegionLearnerReadSnapshot, std::__1::hash<unsigned long>, std::__1::equal_to<unsigned long>, std::__1::allocator<std::__1::pair<unsigned long const, DB::RegionLearnerReadSnapshot> > > const&, unsigned long, unsigned long)
c++ gcc clang elf
1个回答
0
投票

然而,在检查了一些候选类后,我们发现没有 std::mutex 具有 0x278 的偏移量

您是正确的,因为可能存在一些

NULL
指针取消引用,导致访问地址
0x278

然而,这并不意味着在你的一个类中应该有一个具有这样的偏移量的

std::mutex

例如,在 Linux / x86_64 上使用 GLIBC 时,反汇编如下所示(在我的系统上):

Dump of assembler code for function ___pthread_mutex_lock:
   0x0008b570 <+0>:     mov    0x10(%edi),%eax
...

如果传递了

0x10
NULL
,此函数将在地址
pthread_mutex_t
处崩溃。

它看起来像

pthread_mutex_t
is 使用 Clang / libc++ 的
std::mutex
的第一个数据成员,所以可能你应该寻找一个在偏移量
std::mutex
处具有
0x268
的类(如果你的
pthread_mutex_lock
匹配)我的;如果没有,您需要相应地调整偏移)。

附注假设您找到一个类

C
,其
std::mutex
位于所需的偏移量处。利用这些知识,您“并没有更接近”找出错误,因此这个练习毫无意义。

© www.soinside.com 2019 - 2024. All rights reserved.