oceanbase / miniob

MiniOB is a compact database that assists developers in understanding the fundamental workings of a database.
https://oceanbase.github.io/miniob/
Mulan Permissive Software License, Version 2
2.86k stars 1.01k forks source link

[BUG]日志文件中打印出来的栈信息不能使用addr2line识别 #381

Open hnwyllmm opened 3 weeks ago

hnwyllmm commented 3 weeks ago

Describe the bug A clear and concise description of what the bug is.

为了方便调试,日志中可以增加 lbt() 来打印调用栈,日志中会将栈的各个Frame地址打印出来。我们期望可以直接使用addr2line工具查看调用栈信息。但是当前的栈信息不能使用addr2line查看,得到的结果中文件名和行号是问号和0。

导致无法查看符号的原因是程序在运行时会动态调整程序基址,导致每次程序运行的得到的栈信息地址会变化,也不能使用addr2line识别。

解决方法:

  1. 在编译时增加 -no-pie,让程序不做重定位(不推荐)
  2. 在输出栈信息时,自动减去起始偏移信息

Environment Environment Details sometimes important

Additional context Add any other context about the problem here.

日志示例:

[2024-04-18 15:26:42.993921 pid:1577569 tid:7f62c9dac7c0 ctx:0 DEBUG: unlock@mutex.cpp:272] >> debug unlock 0x7f62c4a44b70, lbt=0x7f62ca352c0e 0x44a9af 0x77c6d1 0x58fb34 0x58c16f 0x51fecd 0x51fd0b 0x5293eb 0x66a6d0 0x6742a6 0x673fce 0x673c39 0x674b3f 0x66abdd 0x66a7e3 0x65b064 0x6596bb 0x65f97c 0x5a339a 0x596a37 0x5a0c5d 0x5a0ae3 0x5a092a 0x5be359 0x5b0524 0x599d65 0x596d50 0x420807 0x4afe1f 0x4a8c0b 0x484416 0x484f31 0x48586f 0x495d51 0x4b0de6 0x4a9d4d 0x494373 0x42b73a 0x427e9a 0x7f62c9ddad90 0x7f62c9ddae40 0x4125d5

addr2line工具使用:

addr2line -pCfe observer 0x44a9af 0x77c6d1 0x58fb34 0x58c16f

参考资料:https://stackoverflow.com/questions/47778099/what-is-no-pie-used-for