问题
在Mojave 10.14.6 上自行编译 gdb 8.3.1 (后升级为10.1),在签名后,运行 file file_name 命令报错:
inferior.c:287: internal-error: struct inferior *find_inferior_pid(int): Assertion `pid != 0' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
gdb 版本8.3.1,网上有不少类似错误,比如最近的:
GDB not working on OSX Mojave #5256
都说是gdb的问题,可是为什么 gdb 始终不改,看 gdb 官网,最新的 10.1已放出,直接编译升级到 10.1,结果错误如下:
thread.c:95: internal-error: struct thread_info *inferior_thread(): Assertion `current_thread_ != nullptr' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
看来问题依旧。
测试和结论
看源代码解决问题,理论上最可靠,不过需要足够的经验和时间,这两样现在都不具备。换个思路,看看如何不出问题,也就是如何规避问题。
首先,直接用 gdb file_name 看看是否有问题,结果一切正常,但在进入 gdb shell 后用 file 同样报错。
其次 在 batch 模式下运行 file 命令,如下:
gdb -batch -ex 'file f_add'
错误依旧。
使用下列命令,开启了coredump:
ulimit -c unlimit
看了下日志:
20 System Integrity Protection: enabled
21
22 Crashed Thread: 0 Dispatch queue: com.apple.main-thread
23
24 Exception Type: EXC_CRASH (SIGABRT)
25 Exception Codes: 0x0000000000000000, 0x0000000000000000
26 Exception Note: EXC_CORPSE_NOTIFY
27
28 Application Specific Information:
29 abort() called
30
31 Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
32 0 libsystem_kernel.dylib 0x00007fff7c6fa2c2 __pthread_kill + 10
33 1 libsystem_pthread.dylib 0x00007fff7c7b5bf1 pthread_kill + 284
34 2 libsystem_c.dylib 0x00007fff7c6646a6 abort + 127
35 3 gdb 0x0000000100362319 internal_vproblem(internal_problem*, char const*, in 35 t, char const*, __va_list_tag*) + 1209
36 4 gdb 0x0000000100361e3b internal_verror(char const*, int, char const*, __va_ 36 list_tag*) + 27 (utils.c:440)
37 5 gdb 0x000000010041ecc4 internal_error(char const*, int, char const*, ...) + 37 116
38 6 gdb 0x000000010032a901 inferior_thread() + 65
39 7 gdb 0x0000000100288899 get_current_regcache() + 9 (regcache.c:410)
40 8 gdb 0x00000001002c725c darwin_solib_create_inferior_hook(int) + 252 (solib- 40 darwin.c:463)
41 9 gdb 0x00000001002e577a symbol_file_command(char const*, int) + 426 (symfile 41 .c:1665)
42 10 gdb 0x000000010015efdd file_command(char const*, int) + 29 (exec.c:585)
43 11 gdb 0x0000000100098d62 cmd_func(cmd_list_element*, char const*, int) + 50 ( 43 gdb_optional.h:188)
44 12 gdb 0x0000000100332fc3 execute_command(char const*, int) + 1027 (top.c:584)
45 13 gdb 0x00000001001fa861 captured_main_1(captured_main_args*) + 5633 (main.c: 45 455)
46 14 gdb 0x00000001001f910f gdb_main(captured_main_args*) + 15
47 15 gdb 0x000000010000144b main + 43 (gdb.c:32)
48 16 libdyld.dylib 0x00007fff7c5bf3d5 start + 1
嗯,比较复杂,自己改难度大,网上搜索了下,没有明确结果。有个类似的bug :
https://sourceware.org/pipermail/gdb-testers/2019q4/151973.html
算了,要花太多时间,毕竟mac用gdb调试的程序很少,影响也不是很大,等gdb的开发者去解决吧。