【发布时间】:2010-01-23 12:44:50
【问题描述】:
我在使用 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 在 pAction 上从 Session::HandleAction 调用。但是帧#1 显示this=0x0,帧#2 显示pAction = (Action *) 0x0。
我不明白为什么这会导致崩溃。这可能意味着什么? DisplayInfo 不能在空引用上调用!
非常感谢任何帮助。
谢谢
【问题讨论】:
-
为什么不呢?很明显,您确实在空引用上调用了它。你自己说 pAction = (Action *) 0x0。了解相关代码可能会有所帮助。
-
@oefe:DisplayInfo 似乎在空引用上被调用,但请参见第 0 帧。 DisplayInfo 在同一个对象上调用它。这意味着 DisplayInfo 工作得很好。帧#0 和帧#1 应该在同一个对象上。
-
如果您在 NULL 对象指针上调用方法,C++ 不会生成任何类型的异常。它只会盲目地这样做。
-
@Mike DeSimone:非常感谢。我不知道。您可以将其发布为答案。我想这里的每个人都给了我正确的答案,而我是一个没有足够知识去理解的人。谢谢大家。
标签: c++ debugging segmentation-fault stack-trace