我的应用程序使用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,
    recv_data=@0x25d83780) at ../../../src/server/ActionHandler.cpp:862
    pAction = (Action *) 0x0
    ActionId = 1079
    GoGuid = <value optimized out>

在第1帧中,从Action::DisplayInfo上的Session::HandleAction调用了pAction。但是,第1帧显示this=0x0,而第2帧显示pAction = (Action *) 0x0

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

任何帮助是最感激的。

谢谢

最佳答案

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

如果那是崩溃的位置,那么您很有可能索引到不存在的数据中。如果m_tmap是std::map没关系-但是您是否确认slist[sId]是有效的下标?

或者-您在NULL(否则为无效)指针上调用了成员函数,并且在您第一次直接访问该对象的成员时会崩溃,即使该对象距框架只有几帧之遥。您确定pAction不能为NULL吗?

堆栈跟踪不一定有效。首先,您可以在应用程序中破坏它们。其次,优化编译器可以最大程度地优化所产生的堆栈跟踪信息。尝试在禁用编译器优化的情况下进行构建,并使用assert验证数组下标是否正确。

关于c++ - 此堆栈跟踪可能意味着什么?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2123163/

10-13 07:04