C++ backtrace with this = 0x0 in various frames

问题描述:

我在一个mips多核系统中有一个程序,我从内核得到的回溯真的很难弄清楚(至少对我来说),我想也许其中一个内核写到mem,但并不是所有的堆栈都被损坏了,这让我对它更加困惑。C++ backtrace with this = 0x0 in various frames

在帧#2中,它是NULL,并且在帧#0中也是NULL(核心转储的原因)。

这是(部分)回溯:

 
#0 E::m (this=0x0, string=0x562f148 "", size=202) at E.cc:315 
#1 0x00000000105c773c in P::e (this=0x361ecd00, string=0x562f148 "", size=202, offset=28) at P.cc:137 
#2 0x00000000105c8c5c in M::e (this=0x0, id=7 '\a', r=2, string=0x562f148 "", size=202, oneClass=0x562f148 "", secondClass=0x14eff439 "", 
offset=28) at M.cc:75           
#3 0x0000000010596354 in m::find (this=0x4431fd70, string=0x562f148 "", size=202, oneClass=0x14eff438 "", secondClass=0x14eff439 "", 
        up=false) at A.cc:458      
#4 0x0000000010597364 in A::trigger (this=0x4431fd70, triggerType=ONE, string=0x562f148 "", size=0, up=true) at A.cc:2084 
#5 0x000000001059bcf0 in A::findOne (this=0x4431fd70, index=2, budget=0x562f148 "", size=202, up=true) at A.cc:1155 
#6 0x000000001059c934 in A::shouldpathNow (this=0x4431fd70, index=2, budget=0x562f148 "", size=202, up=false, startAt=0x0, short=) 
    at A.cc:783  
#7 0x00000000105a385c in A::shouldpath (this=0x4431fd70, index=2, rbudget=, rsize=, up=false, 
        direct=) at A.cc:1104 

相对于M ::发现功能

 

    442 m_t m::find(unsigned char const *string, unsigned int size, 
    443           hClass_t *hClass, h_t *fHClass, 
    444           bool isUp) { 
    445 
    446                    
    447 const Iterator &it=arr_[getIndex()]->getSearchIterator((char const*)value, len); 
    448                
    449 unsigned int const offset = value - engine_->getData(); 
    450                      451 int ret=UNKNOWN;    
    452 M *p;      
    453 for(const void* match=it.next(); 
    454  ret == UNKNOWN && match != NULL;             
    455  match = it.next()){ 
    456  p = (M*)match; 
    457 if(p->needMore()){    
    458  ret = p->e(id_, getIndex(), value, len, hClass, fHClass, offset); 

+0

你可以包含'E :: m'的代码吗? – user7116 2012-04-25 14:33:19

+0

这段代码很简单,只是在初始化时,一个成员正试图进行检查: int i; bool评估= true; 如果(member_){ .... } – ramp 2012-04-25 14:46:07

+0

芯发生在

 'if(member_)' 
ramp 2012-04-25 14:53:44

this=0x0实际上可以很容易地发生。例如:

E *instance = NULL; 
instance->method(); 

this将内method是NULL。

有没有必要假设内存已损坏或堆栈已被覆盖。事实上,如果堆栈内容的其余部分似乎有意义(并且您似乎认为它们的确如此),那么堆栈可能没问题。

而不一定寻找内存损坏,检查你的逻辑,看看你是否有一个未初始化(NULL)的指针或引用。

+0

是的,如果只有一帧backtrace有this = 0x0,但在这种情况下两个'this'指针有一个NULL值,所以这不是将'this'赋值为NULL的问题。 – ramp 2012-05-03 08:29:59

+0

@ramp - 根据M :: e的实现,它可能能够在触发自己的this指针为NULL的核心转储之前成功调用其他函数。然而,从看你的'm :: find'实现,我认为你可能是正确的,它不是通过NULL指针调用方法的简单情况。不过,我不确定是什么问题。 – 2012-05-03 12:59:45

无法看到所有代码,它的类型 - 很难想象发生了什么。你还可以添加M :: e()和P :: e()的代码或者至少是重要的部分。

东西可能只是解决一切问题是添加一个空检查,比如M如下:: find()方法:

456  p = (M*)match; 
     if(!p) { return; /* or do whatever */ } 
457  if(p->needMore()){    
458  ret = p->e(id_, getIndex(), value, len, hClass, fHClass, offset); 

如果p为NULL,我本来期望它坠毁调用p->needMore(),但取决于该方法的功能,它可能不会崩溃。

+0

嗨布雷迪, 这里的问题是指针已经在for循环中检查,甚至是一个局部变量,所以没有其他线程可能的副作用,... – ramp 2012-05-07 09:24:43

+0

@ramp,啊对,我没有捕捉到。 – Brady 2012-05-07 09:27:20