12 EFI_DEBUGGER_SIGNATURE,
14 (EBC_DEBUGGER_MAJOR_VERSION << 16) |
15 EBC_DEBUGGER_MINOR_VERSION,
16 (VM_MAJOR_VERSION << 16) |
19 EFI_DEBUGGER_CONFIGURATION_VERSION,
42 EFI_DEBUG_DEFAULT_INSTRUCTION_NUMBER,
43 EFI_DEBUG_FLAG_EBC_BOE | EFI_DEBUG_FLAG_EBC_BOT,
49CHAR16 *mExceptionStr[] = {
50 L
"EXCEPT_EBC_UNDEFINED",
51 L
"EXCEPT_EBC_DIVIDE_ERROR",
53 L
"EXCEPT_EBC_BREAKPOINT",
54 L
"EXCEPT_EBC_OVERFLOW",
55 L
"EXCEPT_EBC_INVALID_OPCODE",
56 L
"EXCEPT_EBC_STACK_FAULT",
57 L
"EXCEPT_EBC_ALIGNMENT_CHECK",
58 L
"EXCEPT_EBC_INSTRUCTION_ENCODING",
59 L
"EXCEPT_EBC_BAD_BREAK",
60 L
"EXCEPT_EBC_SINGLE_STEP",
82 for (Index = 0; (Index < DebuggerPrivate->DebuggerBreakpointCount) && (Index < EFI_DEBUGGER_BREAKPOINT_MAX); Index++) {
83 if (DebuggerPrivate->DebuggerBreakpointContext[Index].State) {
85 (VOID *)(
UINTN)DebuggerPrivate->DebuggerBreakpointContext[Index].BreakpointAddress,
86 &DebuggerPrivate->DebuggerBreakpointContext[Index].OldInstruction,
96 DebuggerPrivate->DebuggerBreakpointCount = 0;
97 ZeroMem (DebuggerPrivate->DebuggerBreakpointContext, sizeof (DebuggerPrivate->DebuggerBreakpointContext));
125 for (Index = 0; (Index < DebuggerPrivate->DebuggerBreakpointCount) && (Index < EFI_DEBUGGER_BREAKPOINT_MAX); Index++) {
126 if (DebuggerPrivate->DebuggerBreakpointContext[Index].State) {
128 (VOID *)(
UINTN)DebuggerPrivate->DebuggerBreakpointContext[Index].BreakpointAddress,
139 if (DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX].BreakpointAddress != 0) {
141 (VOID *)(
UINTN)DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX].BreakpointAddress,
142 &DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX].OldInstruction,
145 DebuggerPrivate->StatusFlags &= ~EFI_DEBUG_FLAG_EBC_B_BP;
171 BOOLEAN IsHitBreakpoint;
176 Address = SystemContext.SystemContextEbc->Ip -
sizeof (UINT16);
181 IsHitBreakpoint =
FALSE;
182 for (Index = 0; (Index < DebuggerPrivate->DebuggerBreakpointCount) && (Index < EFI_DEBUGGER_BREAKPOINT_MAX); Index++) {
183 if ((DebuggerPrivate->DebuggerBreakpointContext[Index].BreakpointAddress == Address) &&
184 (DebuggerPrivate->DebuggerBreakpointContext[Index].State))
186 IsHitBreakpoint =
TRUE;
191 if (IsHitBreakpoint) {
195 DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX] = DebuggerPrivate->DebuggerBreakpointContext[Index];
196 DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX].State =
TRUE;
200 SystemContext.SystemContextEbc->Ip = Address;
204 DebuggerPrivate->StatusFlags |= EFI_DEBUG_FLAG_EBC_BP;
211 Address = SystemContext.SystemContextEbc->Ip;
216 IsHitBreakpoint =
FALSE;
217 for (Index = 0; (Index < DebuggerPrivate->DebuggerBreakpointCount) && (Index < EFI_DEBUGGER_BREAKPOINT_MAX); Index++) {
218 if ((DebuggerPrivate->DebuggerBreakpointContext[Index].BreakpointAddress == Address) &&
219 (DebuggerPrivate->DebuggerBreakpointContext[Index].State))
221 IsHitBreakpoint =
TRUE;
226 if (IsHitBreakpoint) {
231 &DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX],
232 &DebuggerPrivate->DebuggerBreakpointContext[Index],
233 sizeof (DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX])
235 DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX].State =
TRUE;
244 &DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX],
245 sizeof (DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX])
275 DebuggerSymbolContext = &DebuggerPrivate->DebuggerSymbolContext;
276 for (ObjectIndex = 0; ObjectIndex < DebuggerSymbolContext->ObjectCount; ObjectIndex++) {
277 Object = &DebuggerSymbolContext->Object[ObjectIndex];
281 for (Index = 0; Index < Object->EntryCount; Index++) {
282 ZeroMem (&Object->Entry[Index], sizeof (Object->Entry[Index]));
285 ZeroMem (Object->Name, sizeof (Object->Name));
286 Object->EntryCount = 0;
287 Object->BaseAddress = 0;
288 Object->StartEntrypointRVA = 0;
289 Object->MainEntrypointRVA = 0;
293 for (Index = 0; Object->SourceBuffer[Index] !=
NULL; Index++) {
294 gBS->FreePool (Object->SourceBuffer[Index]);
295 Object->SourceBuffer[Index] =
NULL;
299 DebuggerSymbolContext->ObjectCount = 0;
319 IN BOOLEAN Initialized
325 if (SystemContext.SystemContextEbc->Flags & ((UINT64)VMFLAGS_STEP)) {
326 SystemContext.SystemContextEbc->Flags &= ~((UINT64)VMFLAGS_STEP);
333 DebuggerPrivate->InstructionNumber = EFI_DEBUG_DEFAULT_INSTRUCTION_NUMBER;
335 DebuggerPrivate->DebuggerBreakpointCount = 0;
336 ZeroMem (DebuggerPrivate->DebuggerBreakpointContext, sizeof (DebuggerPrivate->DebuggerBreakpointContext));
340 DebuggerPrivate->DebuggerSymbolContext.DisplaySymbol =
TRUE;
341 DebuggerPrivate->DebuggerSymbolContext.DisplayCodeOnly =
FALSE;
342 DebuggerPrivate->DebuggerSymbolContext.ObjectCount = 0;
347 if (ExceptionType == EXCEPT_EBC_BREAKPOINT) {
360 DebuggerPrivate->InstructionScope = SystemContext.SystemContextEbc->Ip;
383 IN BOOLEAN Initialized
390 DebuggerPrivate->FeatureFlags = EFI_DEBUG_FLAG_EBC_BOE | EFI_DEBUG_FLAG_EBC_BOT;
391 DebuggerPrivate->CallStackEntryCount = 0;
392 DebuggerPrivate->TraceEntryCount = 0;
393 ZeroMem (DebuggerPrivate->CallStackEntry, sizeof (DebuggerPrivate->CallStackEntry));
394 ZeroMem (DebuggerPrivate->TraceEntry, sizeof (DebuggerPrivate->TraceEntry));
415 ZeroMem (&mDebuggerPrivate.StepContext, sizeof (mDebuggerPrivate.StepContext));
416 DebuggerPrivate->StatusFlags = 0;
439 IN BOOLEAN Initialized
445 if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_GT) == EFI_DEBUG_FLAG_EBC_GT) {
447 }
else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_BOC) == EFI_DEBUG_FLAG_EBC_BOC) {
449 }
else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_BOCX) == EFI_DEBUG_FLAG_EBC_BOCX) {
451 }
else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_BOR) == EFI_DEBUG_FLAG_EBC_BOR) {
453 }
else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_BOE) == EFI_DEBUG_FLAG_EBC_BOE) {
454 EDBPrint (L
"Break on Entrypoint\n");
455 }
else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_BOT) == EFI_DEBUG_FLAG_EBC_BOT) {
457 }
else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_STEPOVER) == EFI_DEBUG_FLAG_EBC_STEPOVER) {
459 }
else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_STEPOUT) == EFI_DEBUG_FLAG_EBC_STEPOUT) {
461 }
else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_BP) == EFI_DEBUG_FLAG_EBC_BP) {
462 EDBPrint (L
"Break on Breakpoint\n");
463 }
else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_BOK) == EFI_DEBUG_FLAG_EBC_BOK) {
468 EDBPrint (L
" (%s)\n", mExceptionStr[ExceptionType]);
494 CHAR16 InputBuffer[EFI_DEBUG_INPUS_BUFFER_SIZE];
496 EFI_DEBUGGER_COMMAND DebuggerCommand;
497 EFI_DEBUG_STATUS DebugStatus;
498 STATIC BOOLEAN mInitialized;
500 mInitialized =
FALSE;
502 DEBUG ((DEBUG_ERROR,
"Hello EBC Debugger!\n"));
509 L
"EBC Interpreter Version - %d.%d\n",
510 (
UINTN)VM_MAJOR_VERSION,
511 (
UINTN)VM_MINOR_VERSION
514 L
"EBC Debugger Version - %d.%d\n",
515 (
UINTN)EBC_DEBUGGER_MAJOR_VERSION,
516 (
UINTN)EBC_DEBUGGER_MINOR_VERSION
537 EDBPrint (L
"\nPlease enter command now, \'h\' for help.\n");
538 EDBPrint (L
"(Using <Command> -b <...> to enable page break.)\n");
550 Input (L
"\n\r" EFI_DEBUG_PROMPT_STRING, InputBuffer, EFI_DEBUG_INPUS_BUFFER_SIZE);
557 if (DebuggerCommand ==
NULL) {
558 EDBPrint (L
"ERROR: Command not found!\n");
565 if (CommandArg !=
NULL) {
566 if (
StriCmp (CommandArg, L
"-b") == 0) {
568 mDebuggerPrivate.EnablePageBreak =
TRUE;
575 DebugStatus = DebuggerCommand (CommandArg, &mDebuggerPrivate, ExceptionType, SystemContext);
576 mDebuggerPrivate.EnablePageBreak =
FALSE;
581 if (DebugStatus == EFI_DEBUG_RETURN) {
582 mInitialized =
FALSE;
584 }
else if (DebugStatus == EFI_DEBUG_BREAK) {
586 }
else if (DebugStatus == EFI_DEBUG_CONTINUE) {
598 DEBUG ((DEBUG_ERROR,
"Goodbye EBC Debugger!\n"));
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID PrintExceptionReason(IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate, IN EFI_EXCEPTION_TYPE ExceptionType, IN EFI_SYSTEM_CONTEXT SystemContext, IN BOOLEAN Initialized)
VOID EdbClearSymbol(IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate)
EFI_STATUS InitDebuggerPrivateData(IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate, IN EFI_EXCEPTION_TYPE ExceptionType, IN EFI_SYSTEM_CONTEXT SystemContext, IN BOOLEAN Initialized)
VOID EdbClearAllBreakpoint(IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate, IN BOOLEAN NeedRemove)
EFI_STATUS DeinitDebuggerPrivateData(IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate, IN EFI_EXCEPTION_TYPE ExceptionType, IN EFI_SYSTEM_CONTEXT SystemContext, IN BOOLEAN Initialized)
VOID EdbCheckBreakpoint(IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate, IN EFI_SYSTEM_CONTEXT SystemContext)
VOID EdbSetAllBreakpoint(IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate)
VOID EFIAPI EdbExceptionHandler(IN EFI_EXCEPTION_TYPE ExceptionType, IN OUT EFI_SYSTEM_CONTEXT SystemContext)
EFI_DEBUGGER_COMMAND MatchDebuggerCommand(IN CHAR16 *CommandName, IN CHAR16 **CommandArg)
EFI_STATUS EdbShowDisasm(IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate, IN EFI_SYSTEM_CONTEXT SystemContext)
CHAR16 *EFIAPI StrGetNextTokenLine(IN CHAR16 *CharSet)
VOID EFIAPI Input(IN CHAR16 *Prompt OPTIONAL, OUT CHAR16 *InStr, IN UINTN StrLen)
UINTN EFIAPI EDBPrint(IN CONST CHAR16 *Format,...)
INTN EFIAPI StriCmp(IN CHAR16 *String, IN CHAR16 *String2)
#define DEBUG(Expression)
#define EXCEPT_EBC_UNDEFINED