我遇到了分段错误,我发现了gdb:
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0xb771ca28 in frame_dummy () from /home/Dev/.libs/coap-1.so.0
和:
(gdb) i r
eax 0x0 0
ecx 0x81477bc 135559100
edx 0x378845d4 931677652
ebx 0xb772a000 -1217224704
esp 0xbfddbcd0 0xbfddbcd0
ebp 0x81477bc 0x81477bc
esi 0x0 0
edi 0xbfddbd88 -1075987064
eip 0xb771ca28 0xb771ca28 <frame_dummy+8>
eflags 0x10246 [ PF ZF IF RF ]
cs 0x73 115
ss 0x7b 123
ds 0x7b 123
es 0x7b 123
fs 0x0 0
gs 0x33 51
究竟是什么导致了这个我没有得到的错误。
编辑:
编译器优化设置为O0 得到了:
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0xb7792a90 in coap_address_equals (a=0xac6745d4, b=0x922b814) at src/address.c:20
20 if (a->size != b->size || a->addr.sa.sa_family != b->addr.sa.sa_family)
和bt我得到了:
(gdb) bt
#0 0xb7792a90 in coap_address_equals (a=0xac6745d4, b=0x922b814) at src/address.c:20
'#1 0xb779bd8c in coap_find_observer (resource=0x922b530, peer=0x922b814, token=0xbfd8d7a8) at src/resource.c:530
#2 0x0804c55b in hnd_get_cpufreq (ctx=0x92260c0, resource=0x922b530, local_interface=0x922b784, peer=0x922b814, request=0x0, token=0xbfd8d7a8,
response=0x9227ea0) at leshan_test.c:1413
#3 0xb779c2c1 in coap_notify_observers (context=0x92260c0, r=0x922b530) at src/resource.c:656
#4 0xb779c439 in coap_check_notify (context=0x92260c0) at src/resource.c:690
#5 0x08051cba in main (argc=1, argv=0xbfd8e304) at leshan_test.c:3571
(gdb) r i
我找到了:
/home/libcoap/examples/.libs/leshan_test: relocation error: /home/libcoap/examples/.libs/leshan_test: symbol coap_set_send_handler, version VER_1 not defined in file libcoap-1.so.0 with link time reference
[Inferior 1 (process 16434) exited with code 0177]
编辑: 反汇编转储:http://pastebin.com/6r3CuELd
编辑:
(gdb) p *a
Cannot access memory at address 0xac6745d4
(gdb) p *b
$4 = {size = 0, addr = {sa = {sa_family = 0, sa_data = '\000' <repeats 13 times>}, st = {ss_family = 0, __ss_align = 0,
__ss_padding = '\000' <repeats 119 times>}, sin = {sin_family = 0, sin_port = 0, sin_addr = {s_addr = 0},
sin_zero = "\000\000\000\000\000\000\000"}, sin6 = {sin6_family = 0, sin6_port = 0, sin6_flowinfo = 0, sin6_addr = {__in6_u = {
__u6_addr8 = '\000' <repeats 15 times>, __u6_addr16 = {0, 0, 0, 0, 0, 0, 0, 0}, __u6_addr32 = {0, 0, 0, 0}}}, sin6_scope_id = 0}}}
(gdb)