Handling debug exception

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
User avatar
Robert
Member
Member
Posts: 25
Joined: Wed Jan 13, 2021 8:49 am

Handling debug exception

Post by Robert »

Hi!

How could I handle Exc1 (fired when EIP equals to DRn and debug feature is enabled in DR7)?
I mean the cs:eip in the stack is the one pointed by DRn. So if I'd like to continue the execution, I should disable DRn. But I don't want to. Any ideas?

Thanks,
quirck
Member
Member
Posts: 42
Joined: Sun Nov 23, 2008 5:56 am
Location: Russia, Saint-Petersburg

Re: Handling debug exception

Post by quirck »

Take a look at this flag in EFLAGS.
RF Resume (bit 16) — Controls the processor’s response to instruction-breakpoint conditions. When set, this flag temporarily disables debug exceptions (#DB) from being generated for instruction breakpoints (although other exception conditions can cause an exception to be generated). When clear, instruction breakpoints will generate debug exceptions.

The primary function of the RF flag is to allow the restarting of an instruction following a debug exception that was caused by an instruction breakpoint condition. Here, debug software must set this flag in the EFLAGS image on the stack just prior to returning to the interrupted program with IRETD (to prevent the instruction breakpoint from causing another debug exception). The processor then automatically clears this flag after the instruction returned to has been successfully executed, enabling instruction breakpoint faults again.

See also: Section 17.3.1.1, “Instruction-Breakpoint Exception Condition.”
User avatar
Robert
Member
Member
Posts: 25
Joined: Wed Jan 13, 2021 8:49 am

Re: Handling debug exception

Post by Robert »

quirck wrote:Take a look at this flag in EFLAGS.
RF Resume (bit 16) — Controls the ...

See also: Section 17.3.1.1
A couple of ywars ago I've read about this, but totally forgot it. Thanks for the answer, it was a huge help.
Post Reply