1.查看coredump
- coredump的保存地址
cat /proc/sys/kernel/core_pattern
/var/log/coredump/core-%t-%u-%e-%p
- 查看coredump文件的内容
cd /var/log/coredump
ll
-rw------- 1 root root 92G Mar 29 17:01 'core-1711702889-0-Executor task l-866955'
-rw------- 1 root root 87G Mar 29 17:23 'core-1711704230-0-Executor task l-2208190'
-rw------- 1 root root 86G Mar 30 16:26 'core-1711787213-0-Executor task l-3955961'
-rw-r--r-- 1 root root 405K Mar 23 14:55 hs_err_pid1391445.log
$lldb -d core-1711787213-0-Executor task l-3955961
(lldb) target create --core "core-1711787213-0-Executor task l-3955961"
Core file '/var/log/coredump/core-1711787213-0-Executor task l-3955961' (aarch64) was loaded.
(lldb)
Core file '/var/log/coredump/core-1711787213-0-Executor task l-3955961' (aarch64) was loaded.
(lldb) bt
* thread #1, name = 'java', stop reason = signal SIGSEGV
* frame #0: 0x0000fff7aca2f88c libxxx-xxx-operator-1.4.0-aarch64.so`int xxx::op::OperatorUtil::CompareFlatTemplate<long, true, false, true>(leftVector=0x0000fff8402804e0, leftPosition=59372, rightVector=0x0000fff8402804e0, rightPosition=59405) + 264
frame #1: 0x0000fff7aca308b4 libxxx-xxx-operator-1.4.0-aarch64.so`xxx::op::SortMergeJoinScanner::CompareStreamedRowKeys(this=0x0000fff84001a4a0, leftRowIndex=34359797740, rightRowIndex=34359797773) + 444
frame #2: 0x0000fff7aca2d928 libxxx-xxx-operator-1.4.0-aarch64.so`xxx::op::SortMergeJoinScanner::PreKeyMatched(this=0x0000fff84001a4a0) + 148
2.断点调试
2.1 编译选项添加调试信息
编译程序时需要添加调试信息,可以使用 -g
参数来生成调试符号。例如:
clang++ -g -o program program.cpp
2.2 attach到目标进程并设置断点调试
- 1.使用 LLDB 调试程序时,可以通过以下命令启动 LLDB 并附加到目标进程
lldb attach -p <PID>
- 2.在 LLDB 中设置断点有多种方式
#查看全部断点
(lldb) breakpoint list
#删除全部断点
(lldb) breakpoint delete
#删除指定断点
(lldb) breakpoint delete <断点编号>
#跳过系统断点:
(lldb) process handle SIGSEGV SIGILL -n false
(lldb) process handle SIGSEGV SIGILL -s false
#设置条件断点(將会非常耗时,将会使得进程运行速度被拖慢至少一倍)
(lldb) breakpoint set --address 0xfff51302d3c4 -c "rowIndex == 2154222"
#设置断点
(lldb) breakpoint set --file functionA.cpp --line 10
(lldb) breakpoint set --name <函数名>
(lldb) breakpoint set --address 0xfff51302d3c4
(lldb) breakpoint set --file functionA.cpp --name <函数名>
#忽略断点(1000次):
(lldb) breakpoint set --name <函数名> -i 1000
#进阶:
#(1)设置值
(lldb) expr dynamic_cast<xxx::type::DecimalDataType*>(inputDataTypes[i].get())
#(2)获取指针的内容
(lldb) p streamedPagesIndex->columnsDeque
(std:: 1::vector<xxx::vec::BaseVector **, std:: 1::allocator<xxx::vec::BaseVe
ctor **> >) $1 = size=1 {
= [0] 0x0000fff744447f50
}
(lldb) x/a 0x0000fff744447f50
0xfff744447f50: 0x0000fff744416f00
#(3)设置硬件断点
(lldb) watchpoint set expression 0x0000fff884022598
2.3 查看目标函数的符号详情
#image lookup -n <函数名>
(lldb) image lookup -n CompareStreamedRowKeys
1 match found in /home/omni/static_lib_0326_debug_bak/lib/libxxx-xxx-operator-1.4.0-aarch64.so:
Address: libxxx-xxx-operator-1.4.0-aarch64.so[0x00000000005006f8] (libxxx-xxx-operator-1.4.0-aarch64.so.PT_LOAD[0]..text + 3772168)
Summary: libxxx-xxx-operator-1.4.0-aarch64.so`xxx::op::SortMergeJoinScanner::CompareStreamedRowKeys(long, long)
2.4 反编译目标函数
#disassemble -n <函数名>
(lldb) disassemble -n CompareStreamedRowKeys
libxxx-xxx-operator-1.4.0-aarch64.so`xxx::op::SortMergeJoinScanner::CompareStreamedRowKeys:
0xfff7aca306f8 <+0>: sub sp, sp, #0xb0 ; =0xb0
...忽略
0xfff7aca307bc <+196>: ldr x8, [x8]
0xfff7aca307c0 <+200>: add x0, x8, #0x28 ; =0x28
0xfff7aca307c4 <+204>: ldursw x1, [x29, #-0xc]
0xfff7aca307c8 <+208>: bl 0xfff7aca26e84 ; std::__1::vector<xxx::vec::BaseVector**, std::__1::allocator<xxx::vec::BaseVector**> >::operator[][abi:v15000](unsigned long) const
0xfff7aca307cc <+212>: ldr x8, [sp, #0x8]
...忽略
0xfff7aca307fc <+260>: add x0, x8, #0x28 ; =0x28
0xfff7aca30800 <+264>: ldursw x1, [x29, #-0x1c]
0xfff7aca30804 <+268>: bl 0xfff7aca26e84 ; std::__1::vector<xxx::vec::BaseVector**, std::__1::allocator<xxx::vec::BaseVector**> >::operator[][abi:v15000](unsigned long) const