笔者来聊聊断点以及断点的调试
断电的原理一般分为两种,插入断点指令或者利用硬件调试寄存器进行断点。
Cortex-M3/4,利用Flash补丁或者断点单元(FPB)中的地址比较器进行设置断点,还有多个调试寄存器辅助调试,例如暂停、获取寄存器数据以及传递数据等。例如一个调试控制寄存器如下:
接着来看一下SWD和Jtag链接时,扫描出的DP和AP端口。
SWD 链接时扫描DP和AP端口
- Found SW-DP with ID 0x1BA01477
- DPIDR: 0x1BA01477
- Scanning AP map to find all available APs
- AP[1]: Stopped AP scan as end of AP map has been reached
- AP[0]: AHB-AP (IDR: 0x14770011)
- Iterating through AP map to find AHB-AP to use
- AP[0]: Core found
- AP[0]: AHB-AP ROM base: 0xE00FF000
- CPUID register: 0x411FC231. Implementer code: 0x41 (ARM)
- Found Cortex-M3 r1p1, Little endian.
JTAG 链接时扫描DP和AP端口,支持菊花链,多个被调试主控串联起来。
- TotalIRLen = 9, IRPrint = 0x0011
- JTAG chain detection found 2 devices:
- #0 Id: 0x3BA00477, IRLen: 04, CoreSight JTAG-DP
- #1 Id: 0x06414041, IRLen: 05, STM32 Boundary Scan
- DPv0 detected
- Scanning AP map to find all available APs
- AP[1]: Stopped AP scan as end of AP map has been reached
- AP[0]: AHB-AP (IDR: 0x14770011)
- Iterating through AP map to find AHB-AP to use
- AP[0]: Core found
- AP[0]: AHB-AP ROM base: 0xE00FF000
- CPUID register: 0x411FC231. Implementer code: 0x41 (ARM)
- Found Cortex-M3 r1p1, Little endian.
软件断点:
ETM断点:
程序断点
读写断点
数据断点
高级断点
方法一:双击程序所在行即可设置对应的行断点
命令行设置:b.set addr/addr-range/name /options 后面可以跟地址、地址范、symbol名字以及选项
Trace32 官方文档:5 断点.pdf
SWD 链接的打印完整log。
Connecting ...
- Connecting via USB to probe/ programmer device 0
- Probe/ Programmer firmware: J-Link V9 compiled May 7 2021 16:26:12
- Device "STM32F105RC" selected.
- Target interface speed: 4000 kHz (Fixed)
- VTarget = 3.372V
- InitTarget() start
- InitTarget() end
- Found SW-DP with ID 0x1BA01477
- DPIDR: 0x1BA01477
- Scanning AP map to find all available APs
- AP[1]: Stopped AP scan as end of AP map has been reached
- AP[0]: AHB-AP (IDR: 0x14770011)
- Iterating through AP map to find AHB-AP to use
- AP[0]: Core found
- AP[0]: AHB-AP ROM base: 0xE00FF000
- CPUID register: 0x411FC231. Implementer code: 0x41 (ARM)
- Found Cortex-M3 r1p1, Little endian.
- FPUnit: 6 code (BP) slots and 2 literal slots
- CoreSight components:
- ROMTbl[0] @ E00FF000
- ROMTbl[0][0]: E000E000, CID: B105E00D, PID: 001BB000 SCS
- ROMTbl[0][1]: E0001000, CID: B105E00D, PID: 001BB002 DWT
- ROMTbl[0][2]: E0002000, CID: B105E00D, PID: 000BB003 FPB
- ROMTbl[0][3]: E0000000, CID: B105E00D, PID: 001BB001 ITM
- ROMTbl[0][4]: E0040000, CID: B105900D, PID: 001BB923 TPIU-Lite
- ROMTbl[0][5]: E0041000, CID: B105900D, PID: 101BB924 ETM-M3
- Executing init sequence ...
- Initialized successfully
- Target interface speed: 4000 kHz (Fixed)
- Found 1 JTAG device. Core ID: 0x1BA01477 (None)
- Connected successfully
JTag 链接的打印完整log。
Connecting ...
- Connecting via USB to probe/ programmer device 0
- Probe/ Programmer firmware: J-Link ARM V8 compiled Nov 28 2014 13:44:46
- Device "STM32F103RC" selected.
- Target interface speed: 4000 kHz (Fixed)
- VTarget = 3.338V
- InitTarget() start
- TotalIRLen = 9, IRPrint = 0x0011
- JTAG chain detection found 2 devices:
- #0 Id: 0x3BA00477, IRLen: 04, CoreSight JTAG-DP
- #1 Id: 0x06414041, IRLen: 05, STM32 Boundary Scan
- InitTarget() end
- TotalIRLen = 9, IRPrint = 0x0011
- JTAG chain detection found 2 devices:
- #0 Id: 0x3BA00477, IRLen: 04, CoreSight JTAG-DP
- #1 Id: 0x06414041, IRLen: 05, STM32 Boundary Scan
- DPv0 detected
- Scanning AP map to find all available APs
- AP[1]: Stopped AP scan as end of AP map has been reached
- AP[0]: AHB-AP (IDR: 0x14770011)
- Iterating through AP map to find AHB-AP to use
- AP[0]: Core found
- AP[0]: AHB-AP ROM base: 0xE00FF000
- CPUID register: 0x411FC231. Implementer code: 0x41 (ARM)
- Found Cortex-M3 r1p1, Little endian.
- FPUnit: 6 code (BP) slots and 2 literal slots
- CoreSight components:
- ROMTbl[0] @ E00FF000
- ROMTbl[0][0]: E000E000, CID: B105E00D, PID: 001BB000 SCS
- ROMTbl[0][1]: E0001000, CID: B105E00D, PID: 001BB002 DWT
- ROMTbl[0][2]: E0002000, CID: B105E00D, PID: 000BB003 FPB
- ROMTbl[0][3]: E0000000, CID: B105E00D, PID: 001BB001 ITM
- ROMTbl[0][4]: E0040000, CID: B105900D, PID: 001BB923 TPIU-Lite
- ROMTbl[0][5]: E0041000, CID: B105900D, PID: 101BB924 ETM-M3
- Executing init sequence ...
- Initialized successfully
- Target interface speed: 4000 kHz (Fixed)
- Found 2 JTAG devices. Core ID: 0x3BA00477 (None)
- Connected successfully