Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove windbg breakpoint workaround & improvements #25

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading