Skip to content

Commit

Permalink
Remove windbg breakpoint workaround & improvements (#25)
Browse files Browse the repository at this point in the history
## Description

1. Remove workaround where windbgx wasn't able to step when broken on
debug breakpoints for #10. This is fixed in windbgx version
1.2405.3001.0
2. Minor improvements to the info monitor command.

- [x] Impacts functionality?
- [ ] Impacts security?
- [ ] Breaking change?
- [ ] Includes tests?
- [ ] Includes documentation?

## How This Was Tested

Tested locally with Q35

## Integration Instructions

N/A
  • Loading branch information
cfernald committed May 6, 2024
1 parent d86d50e commit 6f04dea
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 31 deletions.
15 changes: 2 additions & 13 deletions DebuggerFeaturePkg/Library/DebugAgent/AARCH64/DebugAarch64.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ DebuggerExceptionHandler (
case 0x21: // Current EL instruction abort
case 0x24: // Lower EL data abort
case 0x25: // Current EL data abort
ExceptionInfo.ExceptionType = ExceptionGenericFault;
ExceptionInfo.ExceptionType = ExceptionAccessViolation;
ExceptionInfo.ExceptionAddress = Context->ELR;
break;

Expand Down Expand Up @@ -158,18 +158,7 @@ DebuggerExceptionHandler (

ExceptionInfo.ArchExceptionCode = ExceptionType;

if (PcdGetBool (PcdEnableWindbgWorkarounds) &&
(ExceptionType == 0x3c) &&
(DebuggerBreakpointReason != BreakpointReasonNone) &&
(CompareMem ((UINT8 *)Context->ELR, &ArchBreakpointInstruction[0], ArchBreakpointInstructionSize) == 0))
{
//
// Windbg will act oddly when broken in on a actual debug breakpoint instruction,
// so preemptively step past this.
//
Context->ELR += ArchBreakpointInstructionSize;
}

// Call into the core debugger module.
ReportEntryToDebugger (&ExceptionInfo, SystemContext);

//
Expand Down
3 changes: 2 additions & 1 deletion DebuggerFeaturePkg/Library/DebugAgent/DebugAgent.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ typedef enum _EXCEPTION_TYPE {
ExceptionBreakpoint,
ExceptionGenericFault,
ExceptionInvalidOp,
ExceptionAlignment
ExceptionAlignment,
ExceptionAccessViolation
} EXCEPTION_TYPE;

typedef struct _EXCEPTION_INFO {
Expand Down
16 changes: 13 additions & 3 deletions DebuggerFeaturePkg/Library/DebugAgent/GdbStub/GdbStub.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ STATIC CONST CHAR8 *EXCEPTION_TYPE_STRINGS[] = {
"ExceptionBreakpoint",
"ExceptionGenericFault",
"ExceptionInvalidOp",
"ExceptionAlignment"
"ExceptionAlignment",
"ExceptionAccessViolation"
};

STATIC CONST CHAR8 *BREAK_REASON_STRINGS[] = {
"N/A",
"Initial Breakpoint",
"Module Load",
"Debugger Break"
};

//
Expand Down Expand Up @@ -483,12 +491,14 @@ ProcessMonitorCmd (
"%a\n\r"
"Exception Type: %a (%d)\n\r"
"Exception Address: %llx\n\r"
"Architecture Exception Code: 0x%llx\n\r",
"Architecture Exception Code: 0x%llx\n\r"
"Break Reason: %a\n\r",
gDebuggerInfo,
EXCEPTION_TYPE_STRINGS[gExceptionInfo->ExceptionType],
gExceptionInfo->ExceptionType,
gExceptionInfo->ExceptionAddress,
gExceptionInfo->ArchExceptionCode
gExceptionInfo->ArchExceptionCode,
BREAK_REASON_STRINGS[DebuggerBreakpointReason]
);

break;
Expand Down
19 changes: 5 additions & 14 deletions DebuggerFeaturePkg/Library/DebugAgent/X64/DebugX64.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,14 @@ DebuggerExceptionHandler (
ExceptionInfo.ExceptionAddress = Context->Rip;
break;

case EXCEPT_X64_PAGE_FAULT:
ExceptionInfo.ExceptionType = ExceptionAccessViolation;
ExceptionInfo.ExceptionAddress = Context->Rip;
break;

case EXCEPT_X64_DOUBLE_FAULT:
case EXCEPT_X64_SEG_NOT_PRESENT:
case EXCEPT_X64_GP_FAULT:
case EXCEPT_X64_PAGE_FAULT:
ExceptionInfo.ExceptionType = ExceptionGenericFault;
ExceptionInfo.ExceptionAddress = Context->Rip;
break;
Expand All @@ -112,19 +116,6 @@ DebuggerExceptionHandler (

ExceptionInfo.ArchExceptionCode = InterruptType;

if (PcdGetBool (PcdEnableWindbgWorkarounds) &&
(InterruptType == EXCEPT_X64_BREAKPOINT) &&
(DebuggerBreakpointReason != BreakpointReasonNone) &&
(*((UINT8 *)Context->Rip) == 0xCC))
{
//
// Windbg will act oddly when broken in on a actual INT 3 instruction, so
// preemptively step past this.
//

Context->Rip++;
}

// Call into the core debugger module.
ReportEntryToDebugger (&ExceptionInfo, SystemContext);

Expand Down

0 comments on commit 6f04dea

Please sign in to comment.