2010-01-23 100 views
1

我在使用C++编写的应用程序中使用GCC 4.3.2编译了段错误问题。它在Debian 5 x64下运行。这个堆栈跟踪可能意味着什么?

方法坠毁在下面的代码行:

#0 0x00000000007c720f in Action::LoadInfoFromDB (this=0x7fae10d38d90) 
    at ../../../src/server/Action.cpp:1233 
1233   m_tmap[tId]->slist[sId] = pItem; 

,我从核心转储得到堆栈跟踪如下:

#0 0x00000000007c720f in Action::LoadInfoFromDB (this=0x7fae10d38d90) 
    at ../../../src/server/Action.cpp:1233 
    ItemGuid = <value optimized out> 
    ItemEntry = <value optimized out> 
    pItem = (class Item *) 0x2b52bae0 
    fields = <value optimized out> 
    tId = 1 '\001' 
    sId = 0 '\0' 
    result = (QueryResult *) 0x7fadcae3d8e0 
#1 0x00000000007c7584 in Action::DisplayInfo (this=0x0, session=0x7fadbdd44a20) 
    at ../../../src/server/Action.cpp:1090 
    data = {<ByteBuffer> = {static DEFAULT_SIZE = 4096, _rpos = 220043248, _wpos = 5469086, 
    _storage = {<std::_Vector_base<unsigned char, std::allocator<unsigned char> >> = { 
     _M_impl = {<std::allocator<unsigned char>> = {<__gnu_cxx::new_allocator<unsigned char>> = {<No data fields>}, <No data fields>}, _M_start = 0x41200000 <Address 0x41200000 out of bounds>, 
      _M_finish = 0x0, 
      _M_end_of_storage = 0x7fad00000000 <Address 0x7fad00000000 out of bounds>}}, <No data fields>}}, m_code = 51152} 
#2 0x00000000007d01a3 in Session::HandleAction (this=0x7fadbdd44a20, 
    [email protected]) at ../../../src/server/ActionHandler.cpp:862 
    pAction = (Action *) 0x0 
    ActionId = 1079 
    GoGuid = <value optimized out> 

在帧#1,Action::DisplayInfo被称为从Session::HandleActionpAction。但帧#1显示this=0x0,帧#2显示pAction = (Action *) 0x0

我不明白为什么这会导致崩溃。这可能意味着什么? DisplayInfo无法在空引用上调用!

任何帮助最受赞赏。

感谢

+2

为什么不呢?很明显,你确实把它称为空引用。你自己说,pAction =(Action *)0x0。 了解有关的代码可能会有所帮助。 – oefe 2010-01-23 12:49:38

+0

@oefe:DisplayInfo似乎在空引用上调用,但看到帧#0。 DisplayInfo在同一个对象上调用它。这意味着DisplayInfo工作得很好。帧#0和帧#1应该在同一个对象上。 – 2010-01-23 12:52:23

+0

如果您调用NULL对象指针的方法,C++不会生成任何类型的异常。它只会盲目地去做。 – 2010-01-23 13:03:17

回答

2
m_tmap[tId]->slist[sId] = pItem; 

如果是这样的碰撞位置,你最有可能置入到不存在的数据。如果m_tmap是std::map这没关系 - 但是您确认slist[sId]是否是有效的下标?

或者 - 当您在第一次直接访问对象成员时(即使距离它几帧),您在NULL(或其他无效)指针上调用成员函数并崩溃。你确定pAction不能为NULL吗?

堆栈跟踪无需有效。首先,你可以在你的应用程序中破坏它们。其次,优化编译器可以优化那么多,结果堆栈跟踪不可靠。尝试使用禁用编译器优化的构建,并使用assert来验证您的数组下标是否正常。

+0

pAction可以为NULL。所以你建议可能是因为在pAction上调用DisplayInfo而导致崩溃,这是NULL?如果是这种情况,帧#0是什么意思? – 2010-01-23 12:57:29

+0

没有代码,这是不可能告诉的,但我的猜测是pAction为空,它称为pAction-> DisplayInfo,而DisplayInfo称为LoadInfoFromDB。 – 2010-01-23 13:00:15

2

这很明显,pAction为null,并且你调用了pAction-> DisplayInfo。看看Action中的地址如何在第一帧中都是无效的。除此之外,很难说明为什么没有看到一些代码,但我猜DisplayInfo直接或间接调用LoadInfoFromDB。