Home > database >  if i set breakpoints on certain assembly register operations, can this potentially block other threa
if i set breakpoints on certain assembly register operations, can this potentially block other threa

Time:11-30

Hi so from my understanding the assembly registers (rax, rdx, etc.. for 64bit architecture)

are mapped to cpu registers when beeing called as there are more registers in modern cpus than there is in the assembly register.

what i ve been wondering is, when i set breakpoints on some assembly operations for debug purpose.. for example something like

mov rax, rdx 

does this actually "block" the associated register in the cpu and hence can potentially slow down or even block other processes/threads?

i m relatively new to assembly and just trying to grasp the idea how logical registers from assembly translate to physical registers from the cpu

CodePudding user response:

No such thing happens.

When a breakpoint is reached, the same thing that happens on every context switch happens: The process is interrupted. The operating system takes control and saves the contents of all registers into memory. Then it transfers control to another process (in this case likely the debugger), restoring the register to the values it saved for that process.

While there is only one set of registers visible to the programmer, the operating system swaps them out such that each process can pretend to have access to all registers. The same applies to memory; this is called virtual memory.

CodePudding user response:

Breakpoints are achieved by two mechanisms in x64 architectures. The legacy method is to replace the first byte of an instruction, such as mov rax, rdx with a breakpoint instruction 0xcc or int 3h.

This will cause the execution to go debug handler, which typically needs to replace the 0xcc instruction with the original byte in order to actually execute that instruction.

The other mechanism is to use debug registers (DB0 to DB3) to place addresses, which will cause the CPU to trap when either a memory read, memory write, execution, or I/O occurs on that address.

The debug registers are configurable per thread, while modifying the code to get soft breakpoints affects all the threads. (So they'll hit the breakpoint, too, if they try to actually execute the same instruction. But otherwise still no effect.)

  • Related