我使用gdb test core并得到:

Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x0000557ce64b63f8 in _create (str=str@entry=0x557ce80a8820 "SEND")
    at system.c:708
708         data->res = command->data->res;
(gdb) bt
#0  0x0000557ce64b63f8 in _create (str=str@entry=0x557ce80a8820 "SEND")
    at system.c:708
#1  0x0000557ce64b2ef1 in make_command (s=<optimized out>, cmd=0x557ce809cb70) at command.c:121
#2  0x0000557ce63aefdf in main (argc=<optimized out>, argv=0x7fff19053278) at main.c:394
(gdb) p *command
$1 = {status = 1, data = 0x7f21027e9a80, sum = 1543465568, time = 0, msg = { str = 0x7f20fd19f080 "GOOD", len = 4}, id = 2}
(gdb) p *command->data
$2 = {status = 1, item = 0x7f21027eb780, res = 0x7f2100990b00, sum = 1133793665}
(gdb) p *command->data->res
$3 = {msg = { str = 0x7f21010a5500 "Hi, test, test"..., len = 14}, status = 1}
(gdb) p *data
$4 = {status = 1, type = 5, res = 0x0, id = 2}


如您所见,指针commandcommand->datadata都有效,为什么发生了SIGSEGV?

最佳答案

为什么SIGSEGV发生了?


我们不能说。

一个可能的原因:其他一些代码实际上正在执行并崩溃。

如果system.c已被编辑或更新,但是该程序尚未使用新的源进行重建,则可能发生这种情况。或者,如果程序计数器到文件/行的编译器映射不正确(这种情况通常发生在优化代码中)。

如果您编辑问题以显示list _createdisas $pcinfo registers的输出,我们可能会告诉您更多信息。

关于c - SIGSEGV在某处不应该存在,没有NULL指针,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53532200/

10-11 18:44