]>
Commit | Line | Data |
---|---|---|
e8a5ac7c | 1 | /** @file\r |
748edcd5 | 2 | \r |
e8a5ac7c DB |
3 | Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r |
4 | This program and the accompanying materials\r | |
748edcd5 PB |
5 | are licensed and made available under the terms and conditions of the BSD License\r |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | \r | |
e8a5ac7c | 12 | **/\r |
748edcd5 PB |
13 | \r |
14 | #include <Uefi.h>\r | |
15 | #include "Edb.h"\r | |
16 | \r | |
17 | EFI_DEBUGGER_PRIVATE_DATA mDebuggerPrivate = {\r | |
18 | EFI_DEBUGGER_SIGNATURE, // Signature\r | |
19 | IsaEbc, // Isa\r | |
20 | (EBC_DEBUGGER_MAJOR_VERSION << 16) |\r | |
21 | EBC_DEBUGGER_MINOR_VERSION, // EfiDebuggerRevision\r | |
22 | (VM_MAJOR_VERSION << 16) |\r | |
23 | VM_MINOR_VERSION, // EbcVmRevision\r | |
2b2efe33 PB |
24 | {\r |
25 | EFI_DEBUGGER_CONFIGURATION_VERSION,\r | |
26 | &mDebuggerPrivate,\r | |
27 | }, // DebuggerConfiguration\r | |
748edcd5 PB |
28 | NULL, // DebugImageInfoTableHeader\r |
29 | NULL, // Vol\r | |
30 | NULL, // PciRootBridgeIo\r | |
31 | mDebuggerCommandSet, // DebuggerCommandSet\r | |
32 | {0}, // DebuggerSymbolContext\r | |
33 | 0, // DebuggerBreakpointCount\r | |
34 | {{0}}, // DebuggerBreakpointContext\r | |
35 | 0, // CallStackEntryCount\r | |
36 | {{0}}, // CallStackEntry\r | |
37 | 0, // TraceEntryCount\r | |
38 | {{0}}, // TraceEntry\r | |
39 | {0}, // StepContext\r | |
40 | {0}, // GoTilContext\r | |
41 | 0, // InstructionScope\r | |
42 | EFI_DEBUG_DEFAULT_INSTRUCTION_NUMBER, // InstructionNumber\r | |
43 | EFI_DEBUG_FLAG_EBC_BOE | EFI_DEBUG_FLAG_EBC_BOT, // FeatureFlags\r | |
44 | 0, // StatusFlags\r | |
45 | FALSE, // EnablePageBreak\r | |
46 | NULL // BreakEvent\r | |
47 | };\r | |
48 | \r | |
49 | CHAR16 *mExceptionStr[] = {\r | |
50 | L"EXCEPT_EBC_UNDEFINED",\r | |
51 | L"EXCEPT_EBC_DIVIDE_ERROR",\r | |
52 | L"EXCEPT_EBC_DEBUG",\r | |
53 | L"EXCEPT_EBC_BREAKPOINT",\r | |
54 | L"EXCEPT_EBC_OVERFLOW",\r | |
55 | L"EXCEPT_EBC_INVALID_OPCODE",\r | |
56 | L"EXCEPT_EBC_STACK_FAULT",\r | |
57 | L"EXCEPT_EBC_ALIGNMENT_CHECK",\r | |
58 | L"EXCEPT_EBC_INSTRUCTION_ENCODING",\r | |
59 | L"EXCEPT_EBC_BAD_BREAK",\r | |
60 | L"EXCEPT_EBC_SINGLE_STEP",\r | |
61 | };\r | |
62 | \r | |
e8a5ac7c DB |
63 | /**\r |
64 | \r | |
65 | Clear all the breakpoint.\r | |
66 | \r | |
67 | @param DebuggerPrivate EBC Debugger private data structure\r | |
68 | @param NeedRemove Whether need to remove all the breakpoint\r | |
69 | \r | |
70 | **/\r | |
748edcd5 PB |
71 | VOID\r |
72 | EdbClearAllBreakpoint (\r | |
73 | IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r | |
74 | IN BOOLEAN NeedRemove\r | |
75 | )\r | |
748edcd5 PB |
76 | {\r |
77 | UINTN Index;\r | |
78 | \r | |
79 | //\r | |
80 | // Patch all the breakpoint\r | |
81 | //\r | |
82 | for (Index = 0; (Index < DebuggerPrivate->DebuggerBreakpointCount) && (Index < EFI_DEBUGGER_BREAKPOINT_MAX); Index++) {\r | |
83 | if (DebuggerPrivate->DebuggerBreakpointContext[Index].State) {\r | |
84 | CopyMem (\r | |
85 | (VOID *)(UINTN)DebuggerPrivate->DebuggerBreakpointContext[Index].BreakpointAddress,\r | |
86 | &DebuggerPrivate->DebuggerBreakpointContext[Index].OldInstruction,\r | |
87 | sizeof(UINT16)\r | |
88 | );\r | |
89 | }\r | |
90 | }\r | |
91 | \r | |
92 | //\r | |
93 | // Zero Breakpoint context, if need to remove all breakpoint\r | |
94 | //\r | |
95 | if (NeedRemove) {\r | |
96 | DebuggerPrivate->DebuggerBreakpointCount = 0;\r | |
97 | ZeroMem (DebuggerPrivate->DebuggerBreakpointContext, sizeof(DebuggerPrivate->DebuggerBreakpointContext));\r | |
98 | }\r | |
99 | \r | |
100 | //\r | |
101 | // Done\r | |
102 | //\r | |
103 | return ;\r | |
104 | }\r | |
105 | \r | |
e8a5ac7c DB |
106 | /**\r |
107 | \r | |
108 | Set all the breakpoint.\r | |
109 | \r | |
110 | @param DebuggerPrivate EBC Debugger private data structure\r | |
111 | \r | |
112 | **/\r | |
748edcd5 PB |
113 | VOID\r |
114 | EdbSetAllBreakpoint (\r | |
115 | IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate\r | |
116 | )\r | |
748edcd5 PB |
117 | {\r |
118 | UINTN Index;\r | |
119 | UINT16 Data16;\r | |
120 | \r | |
121 | //\r | |
122 | // Set all the breakpoint (BREAK(3) : 0x0300)\r | |
123 | //\r | |
124 | Data16 = 0x0300;\r | |
125 | for (Index = 0; (Index < DebuggerPrivate->DebuggerBreakpointCount) && (Index < EFI_DEBUGGER_BREAKPOINT_MAX); Index++) {\r | |
126 | if (DebuggerPrivate->DebuggerBreakpointContext[Index].State) {\r | |
127 | CopyMem (\r | |
128 | (VOID *)(UINTN)DebuggerPrivate->DebuggerBreakpointContext[Index].BreakpointAddress,\r | |
129 | &Data16,\r | |
130 | sizeof(UINT16)\r | |
131 | );\r | |
132 | }\r | |
133 | }\r | |
134 | \r | |
135 | //\r | |
136 | // Check if current break is caused by breakpoint set.\r | |
137 | // If so, we need to patch memory back to let user see the real memory.\r | |
138 | //\r | |
139 | if (DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX].BreakpointAddress != 0) {\r | |
140 | CopyMem (\r | |
141 | (VOID *)(UINTN)DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX].BreakpointAddress,\r | |
142 | &DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX].OldInstruction,\r | |
143 | sizeof(UINT16)\r | |
144 | );\r | |
145 | DebuggerPrivate->StatusFlags &= ~EFI_DEBUG_FLAG_EBC_B_BP;\r | |
146 | }\r | |
147 | \r | |
148 | //\r | |
149 | // Done\r | |
150 | //\r | |
151 | return ;\r | |
152 | }\r | |
153 | \r | |
e8a5ac7c | 154 | /**\r |
748edcd5 PB |
155 | \r |
156 | Check all the breakpoint, if match, then set status flag, and record current breakpoint.\r | |
157 | Then clear all breakpoint to let user see a clean memory\r | |
158 | \r | |
e8a5ac7c DB |
159 | @param DebuggerPrivate EBC Debugger private data structure\r |
160 | @param SystemContext EBC system context.\r | |
748edcd5 | 161 | \r |
e8a5ac7c DB |
162 | **/\r |
163 | VOID\r | |
164 | EdbCheckBreakpoint (\r | |
165 | IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r | |
166 | IN EFI_SYSTEM_CONTEXT SystemContext\r | |
167 | )\r | |
748edcd5 PB |
168 | {\r |
169 | UINT64 Address;\r | |
170 | UINTN Index;\r | |
748edcd5 PB |
171 | BOOLEAN IsHitBreakpoint;\r |
172 | \r | |
173 | //\r | |
174 | // Roll back IP for breakpoint instruction (BREAK(3) : 0x0300)\r | |
175 | //\r | |
176 | Address = SystemContext.SystemContextEbc->Ip - sizeof(UINT16);\r | |
177 | \r | |
178 | //\r | |
179 | // Check if the breakpoint is hit\r | |
180 | //\r | |
181 | IsHitBreakpoint = FALSE;\r | |
182 | for (Index = 0; (Index < DebuggerPrivate->DebuggerBreakpointCount) && (Index < EFI_DEBUGGER_BREAKPOINT_MAX); Index++) {\r | |
183 | if ((DebuggerPrivate->DebuggerBreakpointContext[Index].BreakpointAddress == Address) &&\r | |
184 | (DebuggerPrivate->DebuggerBreakpointContext[Index].State)) {\r | |
748edcd5 PB |
185 | IsHitBreakpoint = TRUE;\r |
186 | break;\r | |
187 | }\r | |
188 | }\r | |
189 | \r | |
190 | if (IsHitBreakpoint) {\r | |
191 | //\r | |
192 | // If hit, record current breakpoint\r | |
193 | //\r | |
194 | DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX] = DebuggerPrivate->DebuggerBreakpointContext[Index];\r | |
195 | DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX].State = TRUE;\r | |
196 | //\r | |
197 | // Update: IP and Instruction (NOTE: Since we not allow set breakpoint to BREAK 3, this update is safe)\r | |
198 | //\r | |
199 | SystemContext.SystemContextEbc->Ip = Address;\r | |
200 | //\r | |
201 | // Set Flags\r | |
202 | //\r | |
203 | DebuggerPrivate->StatusFlags |= EFI_DEBUG_FLAG_EBC_BP;\r | |
204 | } else {\r | |
205 | //\r | |
206 | // If not hit, check whether current IP is in breakpoint list,\r | |
207 | // because STEP will be triggered before execute the instruction.\r | |
208 | // We should not patch it in de-init.\r | |
209 | //\r | |
210 | Address = SystemContext.SystemContextEbc->Ip;\r | |
211 | \r | |
212 | //\r | |
213 | // Check if the breakpoint is hit\r | |
214 | //\r | |
215 | IsHitBreakpoint = FALSE;\r | |
216 | for (Index = 0; (Index < DebuggerPrivate->DebuggerBreakpointCount) && (Index < EFI_DEBUGGER_BREAKPOINT_MAX); Index++) {\r | |
217 | if ((DebuggerPrivate->DebuggerBreakpointContext[Index].BreakpointAddress == Address) &&\r | |
218 | (DebuggerPrivate->DebuggerBreakpointContext[Index].State)) {\r | |
748edcd5 PB |
219 | IsHitBreakpoint = TRUE;\r |
220 | break;\r | |
221 | }\r | |
222 | }\r | |
223 | \r | |
224 | if (IsHitBreakpoint) {\r | |
225 | //\r | |
226 | // If hit, record current breakpoint\r | |
227 | //\r | |
228 | DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX] = DebuggerPrivate->DebuggerBreakpointContext[Index];\r | |
229 | DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX].State = TRUE;\r | |
230 | //\r | |
231 | // Do not set Breakpoint flag. We record the address here just let it not patch breakpoint address when de-init.\r | |
232 | //\r | |
233 | } else {\r | |
234 | //\r | |
235 | // Zero current breakpoint\r | |
236 | //\r | |
237 | ZeroMem (\r | |
238 | &DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX],\r | |
239 | sizeof(DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX])\r | |
240 | );\r | |
241 | }\r | |
242 | }\r | |
243 | \r | |
244 | //\r | |
245 | // Done\r | |
246 | //\r | |
247 | return ;\r | |
248 | }\r | |
249 | \r | |
e8a5ac7c DB |
250 | /**\r |
251 | clear all the symbol.\r | |
252 | \r | |
253 | @param DebuggerPrivate EBC Debugger private data structure\r | |
254 | \r | |
255 | **/\r | |
748edcd5 PB |
256 | VOID\r |
257 | EdbClearSymbol (\r | |
258 | IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate\r | |
259 | )\r | |
748edcd5 PB |
260 | {\r |
261 | EFI_DEBUGGER_SYMBOL_CONTEXT *DebuggerSymbolContext;\r | |
262 | EFI_DEBUGGER_SYMBOL_OBJECT *Object;\r | |
263 | UINTN ObjectIndex;\r | |
264 | UINTN Index;\r | |
265 | \r | |
266 | //\r | |
267 | // Go throuth each object\r | |
268 | //\r | |
269 | DebuggerSymbolContext = &DebuggerPrivate->DebuggerSymbolContext;\r | |
270 | for (ObjectIndex = 0; ObjectIndex < DebuggerSymbolContext->ObjectCount; ObjectIndex++) {\r | |
271 | Object = &DebuggerSymbolContext->Object[ObjectIndex];\r | |
272 | //\r | |
273 | // Go throuth each entry\r | |
274 | //\r | |
275 | for (Index = 0; Index < Object->EntryCount; Index++) {\r | |
276 | ZeroMem (&Object->Entry[Index], sizeof(Object->Entry[Index]));\r | |
277 | }\r | |
278 | ZeroMem (Object->Name, sizeof(Object->Name));\r | |
279 | Object->EntryCount = 0;\r | |
280 | Object->BaseAddress = 0;\r | |
281 | Object->StartEntrypointRVA = 0;\r | |
282 | Object->MainEntrypointRVA = 0;\r | |
283 | //\r | |
284 | // Free source buffer\r | |
285 | //\r | |
286 | for (Index = 0; Object->SourceBuffer[Index] != NULL; Index++) {\r | |
287 | gBS->FreePool (Object->SourceBuffer[Index]);\r | |
288 | Object->SourceBuffer[Index] = NULL;\r | |
289 | }\r | |
290 | }\r | |
291 | DebuggerSymbolContext->ObjectCount = 0;\r | |
292 | \r | |
293 | return ;\r | |
294 | }\r | |
295 | \r | |
e8a5ac7c DB |
296 | /**\r |
297 | \r | |
298 | Initialize Debugger private data structure\r | |
299 | \r | |
300 | @param DebuggerPrivate EBC Debugger private data structure\r | |
301 | @param ExceptionType Exception type.\r | |
302 | @param SystemContext EBC system context.\r | |
303 | @param Initialized Whether the DebuggerPrivate data is initialized.\r | |
304 | \r | |
305 | **/\r | |
748edcd5 PB |
306 | EFI_STATUS\r |
307 | InitDebuggerPrivateData (\r | |
308 | IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r | |
309 | IN EFI_EXCEPTION_TYPE ExceptionType,\r | |
310 | IN EFI_SYSTEM_CONTEXT SystemContext,\r | |
311 | IN BOOLEAN Initialized\r | |
312 | )\r | |
748edcd5 PB |
313 | {\r |
314 | //\r | |
315 | // clear STEP flag in any condition.\r | |
316 | //\r | |
0978bd0d HW |
317 | if (SystemContext.SystemContextEbc->Flags & ((UINT64) VMFLAGS_STEP)) {\r |
318 | SystemContext.SystemContextEbc->Flags &= ~((UINT64) VMFLAGS_STEP);\r | |
748edcd5 PB |
319 | }\r |
320 | \r | |
321 | if (!Initialized) {\r | |
322 | //\r | |
323 | // Initialize everything\r | |
324 | //\r | |
325 | DebuggerPrivate->InstructionNumber = EFI_DEBUG_DEFAULT_INSTRUCTION_NUMBER;\r | |
326 | \r | |
327 | DebuggerPrivate->DebuggerBreakpointCount = 0;\r | |
328 | ZeroMem (DebuggerPrivate->DebuggerBreakpointContext, sizeof(DebuggerPrivate->DebuggerBreakpointContext));\r | |
329 | \r | |
330 | // DebuggerPrivate->StatusFlags = 0;\r | |
331 | \r | |
332 | DebuggerPrivate->DebuggerSymbolContext.DisplaySymbol = TRUE;\r | |
333 | DebuggerPrivate->DebuggerSymbolContext.DisplayCodeOnly = FALSE;\r | |
334 | DebuggerPrivate->DebuggerSymbolContext.ObjectCount = 0;\r | |
335 | } else {\r | |
336 | //\r | |
337 | // Already initialized, just check Breakpoint here.\r | |
338 | //\r | |
339 | if (ExceptionType == EXCEPT_EBC_BREAKPOINT) {\r | |
340 | EdbCheckBreakpoint (DebuggerPrivate, SystemContext);\r | |
341 | }\r | |
342 | \r | |
343 | //\r | |
344 | // Clear all breakpoint\r | |
345 | //\r | |
346 | EdbClearAllBreakpoint (DebuggerPrivate, FALSE);\r | |
347 | }\r | |
348 | \r | |
349 | //\r | |
350 | // Set Scope to currentl IP. (Note: Check Breakpoint may change Ip)\r | |
351 | //\r | |
352 | DebuggerPrivate->InstructionScope = SystemContext.SystemContextEbc->Ip;\r | |
353 | \r | |
354 | //\r | |
355 | // Done\r | |
356 | //\r | |
357 | return EFI_SUCCESS;\r | |
358 | }\r | |
359 | \r | |
e8a5ac7c DB |
360 | /**\r |
361 | \r | |
362 | De-initialize Debugger private data structure.\r | |
363 | \r | |
364 | @param DebuggerPrivate EBC Debugger private data structure\r | |
365 | @param ExceptionType Exception type.\r | |
366 | @param SystemContext EBC system context.\r | |
367 | @param Initialized Whether the DebuggerPrivate data is initialized.\r | |
368 | \r | |
369 | **/\r | |
748edcd5 PB |
370 | EFI_STATUS\r |
371 | DeinitDebuggerPrivateData (\r | |
372 | IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r | |
373 | IN EFI_EXCEPTION_TYPE ExceptionType,\r | |
374 | IN EFI_SYSTEM_CONTEXT SystemContext,\r | |
375 | IN BOOLEAN Initialized\r | |
376 | )\r | |
748edcd5 PB |
377 | {\r |
378 | if (!Initialized) {\r | |
379 | //\r | |
380 | // If it does not want initialized state, de-init everything\r | |
381 | //\r | |
382 | DebuggerPrivate->FeatureFlags = EFI_DEBUG_FLAG_EBC_BOE | EFI_DEBUG_FLAG_EBC_BOT;\r | |
383 | DebuggerPrivate->CallStackEntryCount = 0;\r | |
384 | DebuggerPrivate->TraceEntryCount = 0;\r | |
385 | ZeroMem (DebuggerPrivate->CallStackEntry, sizeof(DebuggerPrivate->CallStackEntry));\r | |
386 | ZeroMem (DebuggerPrivate->TraceEntry, sizeof(DebuggerPrivate->TraceEntry));\r | |
387 | \r | |
388 | //\r | |
389 | // Clear all breakpoint\r | |
390 | //\r | |
391 | EdbClearAllBreakpoint (DebuggerPrivate, TRUE);\r | |
392 | \r | |
393 | //\r | |
394 | // Clear symbol\r | |
395 | //\r | |
396 | EdbClearSymbol (DebuggerPrivate);\r | |
397 | } else {\r | |
398 | //\r | |
399 | // If it wants to keep initialized state, just set breakpoint.\r | |
400 | //\r | |
401 | EdbSetAllBreakpoint (DebuggerPrivate);\r | |
402 | }\r | |
403 | \r | |
404 | //\r | |
405 | // Clear Step context\r | |
406 | //\r | |
407 | ZeroMem (&mDebuggerPrivate.StepContext, sizeof(mDebuggerPrivate.StepContext));\r | |
408 | DebuggerPrivate->StatusFlags = 0;\r | |
409 | \r | |
410 | //\r | |
411 | // Done\r | |
412 | //\r | |
413 | return EFI_SUCCESS;\r | |
414 | }\r | |
415 | \r | |
e8a5ac7c DB |
416 | /**\r |
417 | \r | |
418 | Print the reason of current break to EbcDebugger.\r | |
419 | \r | |
420 | @param DebuggerPrivate EBC Debugger private data structure\r | |
421 | @param ExceptionType Exception type.\r | |
422 | @param SystemContext EBC system context.\r | |
423 | @param Initialized Whether the DebuggerPrivate data is initialized.\r | |
424 | \r | |
425 | **/\r | |
748edcd5 PB |
426 | VOID\r |
427 | PrintExceptionReason (\r | |
428 | IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r | |
429 | IN EFI_EXCEPTION_TYPE ExceptionType,\r | |
430 | IN EFI_SYSTEM_CONTEXT SystemContext,\r | |
431 | IN BOOLEAN Initialized\r | |
432 | )\r | |
748edcd5 PB |
433 | {\r |
434 | //\r | |
435 | // Print break status\r | |
436 | //\r | |
437 | if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_GT) == EFI_DEBUG_FLAG_EBC_GT) {\r | |
438 | EDBPrint (L"Break on GoTil\n");\r | |
439 | } else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_BOC) == EFI_DEBUG_FLAG_EBC_BOC) {\r | |
440 | EDBPrint (L"Break on CALL\n");\r | |
441 | } else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_BOCX) == EFI_DEBUG_FLAG_EBC_BOCX) {\r | |
442 | EDBPrint (L"Break on CALLEX\n");\r | |
443 | } else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_BOR) == EFI_DEBUG_FLAG_EBC_BOR) {\r | |
444 | EDBPrint (L"Break on RET\n");\r | |
445 | } else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_BOE) == EFI_DEBUG_FLAG_EBC_BOE) {\r | |
446 | EDBPrint (L"Break on Entrypoint\n");\r | |
447 | } else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_BOT) == EFI_DEBUG_FLAG_EBC_BOT) {\r | |
448 | EDBPrint (L"Break on Thunk\n");\r | |
449 | } else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_STEPOVER) == EFI_DEBUG_FLAG_EBC_STEPOVER) {\r | |
450 | EDBPrint (L"Break on StepOver\n");\r | |
451 | } else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_STEPOUT) == EFI_DEBUG_FLAG_EBC_STEPOUT) {\r | |
452 | EDBPrint (L"Break on StepOut\n");\r | |
453 | } else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_BP) == EFI_DEBUG_FLAG_EBC_BP) {\r | |
454 | EDBPrint (L"Break on Breakpoint\n");\r | |
455 | } else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_BOK) == EFI_DEBUG_FLAG_EBC_BOK) {\r | |
456 | EDBPrint (L"Break on Key\n");\r | |
457 | } else {\r | |
458 | EDBPrint (L"Exception Type - %x", (UINTN)ExceptionType);\r | |
459 | if ((ExceptionType >= EXCEPT_EBC_UNDEFINED) && (ExceptionType <= EXCEPT_EBC_STEP)) {\r | |
460 | EDBPrint (L" (%s)\n", mExceptionStr[ExceptionType]);\r | |
461 | } else {\r | |
462 | EDBPrint (L"\n");\r | |
463 | }\r | |
464 | }\r | |
465 | \r | |
466 | return ;\r | |
467 | }\r | |
468 | \r | |
e8a5ac7c | 469 | /**\r |
748edcd5 PB |
470 | \r |
471 | The default Exception Callback for the VM interpreter.\r | |
472 | In this function, we report status code, and print debug information\r | |
473 | about EBC_CONTEXT, then dead loop.\r | |
474 | \r | |
e8a5ac7c DB |
475 | @param ExceptionType Exception type.\r |
476 | @param SystemContext EBC system context.\r | |
748edcd5 | 477 | \r |
e8a5ac7c DB |
478 | **/\r |
479 | VOID\r | |
480 | EFIAPI\r | |
481 | EdbExceptionHandler (\r | |
482 | IN EFI_EXCEPTION_TYPE ExceptionType,\r | |
483 | IN OUT EFI_SYSTEM_CONTEXT SystemContext\r | |
484 | )\r | |
748edcd5 PB |
485 | {\r |
486 | CHAR16 InputBuffer[EFI_DEBUG_INPUS_BUFFER_SIZE];\r | |
487 | CHAR16 *CommandArg;\r | |
488 | EFI_DEBUGGER_COMMAND DebuggerCommand;\r | |
489 | EFI_DEBUG_STATUS DebugStatus;\r | |
8fd543c7 DB |
490 | STATIC BOOLEAN mInitialized;\r |
491 | \r | |
492 | mInitialized = FALSE;\r | |
748edcd5 PB |
493 | \r |
494 | DEBUG ((DEBUG_ERROR, "Hello EBC Debugger!\n"));\r | |
495 | \r | |
496 | if (!mInitialized) {\r | |
497 | //\r | |
498 | // Print version\r | |
499 | //\r | |
500 | EDBPrint (\r | |
501 | L"EBC Interpreter Version - %d.%d\n",\r | |
502 | (UINTN)VM_MAJOR_VERSION,\r | |
503 | (UINTN)VM_MINOR_VERSION\r | |
504 | );\r | |
505 | EDBPrint (\r | |
506 | L"EBC Debugger Version - %d.%d\n",\r | |
507 | (UINTN)EBC_DEBUGGER_MAJOR_VERSION,\r | |
508 | (UINTN)EBC_DEBUGGER_MINOR_VERSION\r | |
509 | );\r | |
510 | }\r | |
511 | //\r | |
512 | // Init Private Data\r | |
513 | //\r | |
514 | InitDebuggerPrivateData (&mDebuggerPrivate, ExceptionType, SystemContext, mInitialized);\r | |
515 | \r | |
516 | //\r | |
517 | // EDBPrint basic info\r | |
518 | //\r | |
519 | PrintExceptionReason (&mDebuggerPrivate, ExceptionType, SystemContext, mInitialized);\r | |
520 | \r | |
521 | EdbShowDisasm (&mDebuggerPrivate, SystemContext);\r | |
522 | // EFI_BREAKPOINT ();\r | |
523 | \r | |
524 | if (!mInitialized) {\r | |
525 | //\r | |
526 | // Interactive with user\r | |
527 | //\r | |
528 | EDBPrint (L"\nPlease enter command now, \'h\' for help.\n");\r | |
529 | EDBPrint (L"(Using <Command> -b <...> to enable page break.)\n");\r | |
530 | }\r | |
531 | mInitialized = TRUE;\r | |
532 | \r | |
533 | //\r | |
534 | // Dispatch each command\r | |
535 | //\r | |
536 | while (TRUE) {\r | |
537 | //\r | |
538 | // Get user input\r | |
539 | //\r | |
540 | Input (L"\n\r" EFI_DEBUG_PROMPT_STRING, InputBuffer, EFI_DEBUG_INPUS_BUFFER_SIZE);\r | |
541 | EDBPrint (L"\n");\r | |
542 | \r | |
543 | //\r | |
544 | // Get command\r | |
545 | //\r | |
546 | DebuggerCommand = MatchDebuggerCommand (InputBuffer, &CommandArg);\r | |
547 | if (DebuggerCommand == NULL) {\r | |
548 | EDBPrint (L"ERROR: Command not found!\n");\r | |
549 | continue;\r | |
550 | }\r | |
551 | \r | |
552 | //\r | |
553 | // Check PageBreak;\r | |
554 | //\r | |
555 | if (CommandArg != NULL) {\r | |
556 | if (StriCmp (CommandArg, L"-b") == 0) {\r | |
557 | CommandArg = StrGetNextTokenLine (L" ");\r | |
558 | mDebuggerPrivate.EnablePageBreak = TRUE;\r | |
559 | }\r | |
560 | }\r | |
561 | \r | |
562 | //\r | |
563 | // Dispatch command\r | |
564 | //\r | |
565 | DebugStatus = DebuggerCommand (CommandArg, &mDebuggerPrivate, ExceptionType, SystemContext);\r | |
566 | mDebuggerPrivate.EnablePageBreak = FALSE;\r | |
567 | \r | |
568 | //\r | |
569 | // Check command return status\r | |
570 | //\r | |
571 | if (DebugStatus == EFI_DEBUG_RETURN) {\r | |
572 | mInitialized = FALSE;\r | |
573 | break;\r | |
574 | } else if (DebugStatus == EFI_DEBUG_BREAK) {\r | |
575 | break;\r | |
576 | } else if (DebugStatus == EFI_DEBUG_CONTINUE) {\r | |
577 | continue;\r | |
578 | } else {\r | |
579 | ASSERT (FALSE);\r | |
580 | }\r | |
581 | }\r | |
582 | \r | |
583 | //\r | |
584 | // Deinit Private Data\r | |
585 | //\r | |
586 | DeinitDebuggerPrivateData (&mDebuggerPrivate, ExceptionType, SystemContext, mInitialized);\r | |
587 | \r | |
588 | DEBUG ((DEBUG_ERROR, "Goodbye EBC Debugger!\n"));\r | |
589 | \r | |
590 | return;\r | |
591 | }\r |