1. Use gdb to debug the program on qemu
1.1. Step one: Run the program on qemu and start the gdb server
- qemu-system-riscv64 -nographic -machine virt -m 128M -smp 1 -kernel …/bin/test.elf -s -S
1.2. Step 2: Use gdb client to connect to gdb server
-x: Specify the gdb configuration file, this is not required. Using the configuration file can improve debugging efficiency. Write the commands that need to be entered every time you start gdb debugging into the configuration file in advance.
The effect achieved by the configuration file is the same as manually typing commands on the command line.
2. Use TUI mode to debug
Order | Function |
---|---|
layout src | Show source window |
layout asm | Show assembly window |
layout regs | Display the register window again on the previous window |
layout split | Display source code and assembly windows at the same time |
layout next | Show next layout |
layout prev | Show previous layout |
3. Shortcut
-
ctrl key + n: next command (function and use the "down key" on the Linux command line to view previously entered commands)
-
ctrl key + p: previous command (function and use the "up key" on the Linux command line to view previously entered commands)
-
Switch focus:
- focus next: switch to the next display window (switch the focus, that is, you can use the "up and down keys" to browse the window code)
- focus prev: switch to the previous display window (switch the focus, that is, you can use the "up and down keys" to browse the window code)
- Summary: focus next and focus prev are used when two windows are displayed at the same time.
-
Shortcut keys for viewing window source code:
- PGUP key: page up
- PGDN key: page down
- Up and down keys: slide up and down to view the source code
-
shell + linux command: use linux commands on the gdb command line
4. Commonly used commands of gdb
5. Breakpoint setting instructions
break:设置断点,简写b
b func 断点函数
b file:linenum 断点文件行号
b *address 断点地址
enable/disable:使能/去使能断点
en/dis 1 使能/去使能断点1
en/dis 使能/去使能所有断点
delete:删除断点
delete 1 删除断点1
delete 删除所有断点
info breakpoints:显示所有断点信息
checkpoint:记录断点状态,用于恢复断点。不可用于多线程
checkpoint
restart 1
Info checkpoint:显示checkpoint信息
watch:跟踪变量值,当变量值发生变化时,暂停
watch a 局部变量,在跳出当前函数时会失败
watch *0x600af0
Info watchpoint:显示watchpoint信息
6. Solve the problem that SecureCRT software displays garbled characters
- The reason why garbled characters are displayed is that the character encoding format does not match. The default character encoding of SecureCRT software is "Default" mode.