我有一个程序,我正在崩溃。
通常读取堆栈跟踪不是问题,但在这种情况下我无法理解问题所在。这是我无法知道我的代码的哪一部分导致崩溃。
我正在附加gdb调试器stacktrace:
(gdb) r
Starting program: /home/r/l33t/kepler/build-SuperGUI-5_2_1-Debug/SuperGUI
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/i386-linux-gnu/libthread_db.so.1".
[New Thread 0xb4762b40 (LWP 6612)]
[New Thread 0xb327cb40 (LWP 6613)]
[New Thread 0xb28ffb40 (LWP 6615)]
[New Thread 0xb1ea3b40 (LWP 6616)]
[New Thread 0xb16a2b40 (LWP 6617)]
[New Thread 0xb0ea1b40 (LWP 6618)]
[Thread 0xb16a2b40 (LWP 6617) exited]
connecting...
connected...
[Thread 0xb0ea1b40 (LWP 6618) exited]
SYMBOL --BANKNIFTY
Program received signal SIGSEGV, Segmentation fault.
__memcpy_ssse3 () at ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S:2590
2590 ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S: No such file or directory.
(gdb) bt
#0 __memcpy_ssse3 () at ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S:2590
#1 0x081ca9b0 in ?? ()
#2 0x3143041a in ?? ()
#3 0x03223930 in ?? ()
#4 0x2a363530 in ?? ()
#5 0x4e414209 in ?? ()
#6 0x46494e4b in ?? ()
#7 0xb2305954 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
是否可以帮助我了解如何阅读本文以及如何在我的代码中找到导致此信息崩溃的重点?
qt调试器更加无益:
消费者对qt的看法同样无益(让我理解)
0xb711fe8d <+0x1cfd> sub $0x80,%ecx
2588 in ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S
0xb711fe93 <+0x1d03> movntdq %xmm0,(%edx)
2589 in ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S
0xb711fe97 <+0x1d07> movntdq %xmm1,0x10(%edx)
2590 in ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S
0xb711fe9c <+0x1d0c> movntdq %xmm2,0x20(%edx)
2591 in ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S
它说该程序在dissambler输出中的2589
行崩溃了。
有什么问题?
以下是我认为可能导致崩溃的代码部分(这就是我现在正在处理的事情)
void tradeView::readyRead()
{
std::cout << "line 70" << "\n";
char delimiter_buffer[sizeof(google::protobuf::uint32)]; // read the max size that protobuf might write.
memset(delimiter_buffer, '\0', sizeof(google::protobuf::uint32));
char* proto_data_buffer; // buffer should have been of type google::protobuf::uint8
//memset(proto_data_buffer, '\0', sizeof(google::protobuf::uint32));
google::protobuf::uint32 payload_size = 0;
int space_takenby_delimiter = 0;
size_t startof_extra_read, extra_read;
std::cout << "line 79" << "\n";
if ( socket->read(delimiter_buffer, sizeof(google::protobuf::uint32)) != -1)
{
google::protobuf::io::ArrayInputStream ais(delimiter_buffer,sizeof(google::protobuf::uint32));
google::protobuf::io::CodedInputStream coded_input(&ais);
coded_input.ReadVarint32(&payload_size);
proto_data_buffer = new char[payload_size]; // buffer should have been of type google::protobuf::uint8
space_takenby_delimiter = coded_input.CurrentPosition();
if (space_takenby_delimiter < 1)
{
std::cout << "Could not read delimiter";
return;
}
if ( space_takenby_delimiter < sizeof(google::protobuf::uint32) )
{
startof_extra_read = ( sizeof(google::protobuf::uint32) - (sizeof(google::protobuf::uint32) - space_takenby_delimiter) );
extra_read = (sizeof(google::protobuf::uint32) - space_takenby_delimiter);
std::cout << "line 99" << "\n";
memcpy(proto_data_buffer, delimiter_buffer + startof_extra_read , extra_read);
std::cout << "line 101" << "\n";
}
}
size_t bytes_stilltoberead = payload_size - extra_read;
char payload_buffer[bytes_stilltoberead];
if ( socket->read(payload_buffer, bytes_stilltoberead) != -1)
{
std::cout << "line 110" << "\n";
memcpy(proto_data_buffer + extra_read, payload_buffer, bytes_stilltoberead);
std::cout << "line 112" << "\n";
google::protobuf::io::ArrayInputStream array_input(proto_data_buffer, payload_size);
google::protobuf::io::CodedInputStream coded_input(&array_input);
data_model::terminal_data* tData = new data_model::terminal_data();
if (!tData->ParseFromCodedStream(&coded_input))
std::cout << "COuld not fetch PARSE " << std::endl;
else
std::cout <<" SYMBOL --" << tData->symbol_name() << std::endl;
}
delete proto_data_buffer;
}
上述功能是Qt中的一个插槽。每次插槽中有一些数据时都会调用IT。它执行一次(正确)然后崩溃。我在函数的第一行有一个调试语句(如你所见)。由于它没有打印,我猜这个功能本身没有错?但可能是因为这个功能在某个地方被搞砸了,这表现为崩溃?这对我来说太过亲了。能帮帮我吗?
答案 0 :(得分:1)
proto_data_buffer
和extra_read
未被引用。
如果不满足以下条件:
if ( socket->read(delimiter_buffer, sizeof(google::protobuf::uint32)) != -1)
然后proto_data_buffer
会指出任何地址。与extra_read
一样。
这将导致此行中的地址操作错误:
memcpy(proto_data_buffer + extra_read, payload_buffer, bytes_stilltoberead);