introduction
- watchpoint,也可被称为 data breakpoint,是由data address产生的一个debug event
- debugger配置watchpoint在一个data address或者一个data address range
- 可配置为read access only, write access only, or both
- 可以lint to a Linked Context breakpoint,即必须在特定的context下match才会触发watchpint event
- watchpint会产生一个watchpoint debug event
- 指令fetch是不会产生watchpint event
- debugger配置watchpoint在一个data address或者一个data address range
regs
- ID_AA64DFR0_EL1.WRPs 查询实现了多少个watchpoint
- watchpoint reg pairs
- DBGWCR_EL1: Watchpoint Control Register: controls of watchpoint。32位寄存器,n=0-15
- see ARM v8 doc D7.3.11
- DGBWVR.EL1: Watchpoint Value Register: data address value。64位寄存器,n=0-15
- see ARM v8 doc D7.3.12
- DBGWCR_EL1: Watchpoint Control Register: controls of watchpoint。32位寄存器,n=0-15
配置
基本配置
一个watchpoint可以配置match1个或者多个bytes。当其中任意一个byte match,就会产生一个watchpoint event。byte的数目可以有以下两种配置方式
- 1~8个bytes:通过设置DBGWCR_EL1.BAS Byte Address Selected filed实现,要求这些byte必须是连续的,并且都要在alliened doubleword中
- 8 bytes~2GB: 通过设置DBGWCR_EL1.MASK MASK field实现。要求必须是2的幂次方,并且地址需要range align
- debugger 只能选择其中一种配置,否则unpredictable
配置1~8个bytes的watchpoint
通过设置DBGWCR_EL1.BAS Byte Address Selected Field,可以配置1~8bytes的address match。有以下两种配置方式
- Doubleword-Aligned: 使用BAS[7:0]
- Word-Aligned: 使用BAS[3:0],BAS[7:4] res0
BAS设置必须是连续的byte。如果将BAS配置为非全1,则DBGWCR_EL1.MASK必须配置为全0.
配置8bytes~2GB的watchpoint
通过设置DBGWCR_EL1.MASK,可以将watchpoint配置到最多2GB的match range
MASK定义了addr LSB bits被mask的个数,MASK包含5 bits,最多可以mask掉低31 bits。注意0b00000表示未mask任何bits,而0b00001和0b00010保留为Reserved data
当使用MASK配置时,debugger必须保证下列全部条件
- DBGWCR_EL1.BAS必须为全1
- DBGWVR_EL1, 被mask掉的address bits设为0
Linked watchpoint
watchpoint通过设置type field in DBGWCR_EL1.WT,可以配置为以下任意一种
- Unlinked watchpint: used in isolation
- Linked watchpint: link to Linked Context breakpoint。该配置下,watchpoint event只有在同时满足address match和context match才会产生
Linked watchpoint constraints
- 只有Linked watchpoint才能被link
- linked watchpoint可以link任意类型的Linked Context Breakpoint。DBGWCR_EL1.LBN Linked Breakpoint Number field,设置了对应的Linked Context Breakpoint;DBGWCR_EL1.WT.{SSC, HMC, PAC}定义了产生watchpoint event的execution conditions;DBGBCR_EL1.{SSC, HMC, PMC}则被忽略
- 一个Linked watchpoint 不能 link到另一个watchpoint。因此DBGWCR_EL1.LBN只能配置Breakpoint
- 如果Linked Context Breakpoint 不是 context-aware的,则该行为unpredictable
- 如果linked watchpoint link到一个Unlinked Context breakpoint,则watchpoint event永远不会发生
- 多个linked watchpoint可以link到一个linked Context Breakpoint;同样的,多个address breakpoint也可以link到一个Linked Context Breakpoint。
execute conditions
watchpoint可以配置为在某个execute condition下才发生。由DBGWCR_EL1.WT.{SSC, HMC, PAC}定义
- SCC:Security State Control。可配置为仅在在secure state下、仅在non-secure state下发生,或两者都可以。注意是和对应PE的secure state比,而不是指令fetch地址的NS属性比
- HMC:Higher Mode Control;PAC:privilege Access Control。两者决定了发生watchpint event的exception level
- 注意PAC决定的是access privilege。因此unprivilege load/store 在EL1或者更高level产生的watchppoint event可能是设置在EL0级的addr match(unprivilege load/store在EL1或者更高level执行时,会把访问当做还在EL0级时进行check)
Usage Constraints
see ARM v8 doc D2.10.7
产生
watchpoint debug event产生需要满足以下所有条件
- watchpoint enable。通过设置DBGWCR_EL1.E watchpoint enable control bit实现
- conditions in DBGWCR_EL1 meets
- DBGWVR_EL1地址compare成功:
- 如果watchpoint lint to Linked Context Breakpoint,则context comparison也要成功
- 产生watchpoint的指令commit
- 产生watchpoint的指令pass condition code check
taking watchpoint exception
- PE在Fault Address Register中记录trigger watchpoint的地址,使用其中一个地址寄存器:
- FAR_EL1:若exception在EL1中响应
- FAR_EL2:若exception在EL2中响应
- PE在Exception Syndrome Register(ESR)总记录响应exception的Exception level
- ESR_EL1:若exception在EL1中响应
- ESR_EL2:若exception在EL2中响应
- Table D2-19 in D2.10.8 给出了ESR个bit的值
- watchpoint不能在AArch64 EL3中响应,为什么?
- 如果一条指令trigger多个watchpoint exception,只记录其中一个address(哪一个?)
- prefered return address为产生watchpoint的指令address
- 由非Dcache instruction引起的watchpoint记录的address,需要同时满足
- inclusive range between
- memory访问的最低地址(The lowest address accessed by the memory access that triggered the watchpoint.)
- 产生watchpoint的memory访问的最高地址(The highest watchpointed address accessed by the memory access. A watchpointed address is an address that the watchpoint is watching.)
- 在naturally-aligned block访问中,同时满足
- size为2的幂次方
- 不大于DC ZVA block size
- 包含产生watchpoint的memory access
- inclusive range between
这段描述不容易理解,我们采用ARM文档上的一个例子做以详述
一个multiple load从0x8004开始向上取数据,在0x8019产生了watchpoint。如果DC ZVA block为32Bytes,则block块的地址应为32的整数
倍(0x8000,0x8020...)。最低位应为memory access最低地址0x8004,而最高位则为产生watchpoint的地址。因此地址范围[0x8004:0x8019];
0x8010为最低地址,因此地址范围为[0x8010:0x8019]
- 由Dcache instruction引起的watchpoint event,地址记录
- 记录传给指令的地址。因此该地址可能比引起watchpoint的地址位置要高。
entering Debug State
- PE在EDWAR中记录trigger watchpoint的地址
- 进入debug mode记录的地址和exception有相同的限制,见taking watchpoint exception
halting
- 如果允许halting (设置EDSCR.HDE),则watchpint event会进入Debug State
- 如果禁止halting,并且enable watchpint, watchpoint event会产生watchpint exceptions;如果没有enable watchpoint,则watchpoint event ignores
addr match
addr[48:2] match DBGWVR_EL1[48:2],同时满足
- access size match(见后节详述)。如果EL0是AArch32,EL1是AArch64,则EL0指令可以使用AArch64 stage 1 translation regime,此时地址使用0扩展与watchpoint比较
- DBGWVR_EL1.BAS设置的 Byte selection,或者
- DBGWVR_EL1.MASK设置的addr range
acess size match
注意watchpoint是data address访问的任意byte match都会产生。因此需要注意访问size对match的影响。如一个doubleword的地址访问0x1003,会覆盖0x1003~0x100a共8个bytes。一些特殊指令的地址定义如下:
- DC ZVA instruction:access size定义为DC ZVA block size,在DCZID_EL0.BS中定义
- DC IVAC instruction: access size为implementation defiend,需要同时满足以下条件:
- 为2KB可CTR_EL0_DminLine定义的size之间(inclusive range)
- 2的幂次方
- 上述两类指令,
- The lowest address accessed by the instruction is the address supplied to the instruction, rounded down to the nearest multiple of the access size initiated by that instruction.(??);
- 最高地址为(size-1)的位置
watchpoint的一些特殊行为
- 以下指令从不产生watchpoint exception
- ICache maintenance instruction
- address translation instruction
- TLB mainttenance instruction
- prefetch memory instruction
- Store-Exclusive instruction match watchpoint
- 如果store-exclusive fails,是否产生watchpoint exception由implementation defiend
- 如果store-exclusive succeed,产生watchpoint exception
- cache maintenance instruction match watchpoint
- 只有DC IVAC和DC ZVA instruction可以产生watchpoint exception。
- DBGWCR_EL1.LSC必须配置为一下任意一种
- 10: match on data stores
- 11: match on data stores and data loads