TianoCore EDK2 master
Loading...
Searching...
No Matches
EdbCmdBreakpoint.c
Go to the documentation of this file.
1
9#include "Edb.h"
10
21BOOLEAN
23 IN UINTN Address
24 )
25{
26 if (GET_OPCODE (Address) != OPCODE_BREAK) {
27 return FALSE;
28 }
29
30 if (GET_OPERANDS (Address) != 3) {
31 return FALSE;
32 } else {
33 return TRUE;
34 }
35}
36
48BOOLEAN
50 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
51 IN UINTN Address
52 )
53{
54 UINTN Index;
55
56 //
57 // Go through each breakpoint context
58 //
59 for (Index = 0; Index < DebuggerPrivate->DebuggerBreakpointCount; Index++) {
60 if (DebuggerPrivate->DebuggerBreakpointContext[Index].BreakpointAddress == Address) {
61 //
62 // Found it
63 //
64 return TRUE;
65 }
66 }
67
68 //
69 // Not found
70 //
71 return FALSE;
72}
73
88 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
89 IN UINTN Address
90 )
91{
92 //
93 // Check duplicated breakpoint
94 //
95 if (DebuggerBreakpointIsDuplicated (DebuggerPrivate, Address)) {
96 EDBPrint (L"Breakpoint duplicated!\n");
97 return EFI_ALREADY_STARTED;
98 }
99
100 //
101 // Check whether the address is a breakpoint 3 instruction
102 //
103 if (IsEBCBREAK3 (Address)) {
104 EDBPrint (L"Breakpoint can not be set on BREAK 3 instruction!\n");
105 return EFI_ALREADY_STARTED;
106 }
107
108 if (DebuggerPrivate->DebuggerBreakpointCount >= EFI_DEBUGGER_BREAKPOINT_MAX) {
109 EDBPrint (L"Breakpoint out of resource!\n");
110 return EFI_OUT_OF_RESOURCES;
111 }
112
113 //
114 // Set the breakpoint
115 //
116 DebuggerPrivate->DebuggerBreakpointContext[DebuggerPrivate->DebuggerBreakpointCount].BreakpointAddress = Address;
117 DebuggerPrivate->DebuggerBreakpointContext[DebuggerPrivate->DebuggerBreakpointCount].State = TRUE;
118 DebuggerPrivate->DebuggerBreakpointContext[DebuggerPrivate->DebuggerBreakpointCount].OldInstruction = 0;
119 CopyMem (
120 &DebuggerPrivate->DebuggerBreakpointContext[DebuggerPrivate->DebuggerBreakpointCount].OldInstruction,
121 (VOID *)Address,
122 sizeof (UINT16)
123 );
124
125 DebuggerPrivate->DebuggerBreakpointCount++;
126
127 //
128 // Done
129 //
130 return EFI_SUCCESS;
131}
132
146 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
147 IN UINTN Index
148 )
149{
150 UINTN BpIndex;
151
152 if ((Index >= EFI_DEBUGGER_BREAKPOINT_MAX) ||
153 (Index >= DebuggerPrivate->DebuggerBreakpointCount))
154 {
155 return EFI_NOT_FOUND;
156 }
157
158 //
159 // Delete this breakpoint
160 //
161 for (BpIndex = Index; BpIndex < DebuggerPrivate->DebuggerBreakpointCount - 1; BpIndex++) {
162 CopyMem (
163 &DebuggerPrivate->DebuggerBreakpointContext[BpIndex],
164 &DebuggerPrivate->DebuggerBreakpointContext[BpIndex + 1],
165 sizeof (DebuggerPrivate->DebuggerBreakpointContext[BpIndex])
166 );
167 }
168
169 ZeroMem (
170 &DebuggerPrivate->DebuggerBreakpointContext[BpIndex],
171 sizeof (DebuggerPrivate->DebuggerBreakpointContext[BpIndex])
172 );
173
174 DebuggerPrivate->DebuggerBreakpointCount--;
175
176 //
177 // Done
178 //
179 return EFI_SUCCESS;
180}
181
195 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
196 IN UINTN Index
197 )
198{
199 if ((Index >= EFI_DEBUGGER_BREAKPOINT_MAX) ||
200 (Index >= DebuggerPrivate->DebuggerBreakpointCount))
201 {
202 return EFI_NOT_FOUND;
203 }
204
205 //
206 // Disable this breakpoint
207 //
208 DebuggerPrivate->DebuggerBreakpointContext[Index].State = FALSE;
209
210 return EFI_SUCCESS;
211}
212
226 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
227 IN UINTN Index
228 )
229{
230 if ((Index >= EFI_DEBUGGER_BREAKPOINT_MAX) ||
231 (Index >= DebuggerPrivate->DebuggerBreakpointCount))
232 {
233 return EFI_NOT_FOUND;
234 }
235
236 //
237 // Enable this breakpoint
238 //
239 DebuggerPrivate->DebuggerBreakpointContext[Index].State = TRUE;
240
241 return EFI_SUCCESS;
242}
243
256EFI_DEBUG_STATUS
258 IN CHAR16 *CommandArg,
259 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
260 IN EFI_EXCEPTION_TYPE ExceptionType,
261 IN OUT EFI_SYSTEM_CONTEXT SystemContext
262 )
263{
264 UINTN Index;
265
266 //
267 // Check breakpoint cound
268 //
269 if (DebuggerPrivate->DebuggerBreakpointCount == 0) {
270 EDBPrint (L"No Breakpoint\n");
271 return EFI_DEBUG_CONTINUE;
272 } else if (DebuggerPrivate->DebuggerBreakpointCount > EFI_DEBUGGER_BREAKPOINT_MAX) {
273 EDBPrint (L"Breakpoint too many!\n");
274 DebuggerPrivate->DebuggerBreakpointCount = 0;
275 return EFI_DEBUG_CONTINUE;
276 }
277
278 //
279 // Go through each breakpoint
280 //
281 EDBPrint (L"Breakpoint :\n");
282 EDBPrint (L" Index Address Status\n");
283 EDBPrint (L"======= ================== ========\n");
284 // EDBPrint (L" 1 0xFFFFFFFF00000000 *\n");
285 // EDBPrint (L" 12 0x00000000FFFFFFFF\n");
286 for (Index = 0; Index < DebuggerPrivate->DebuggerBreakpointCount; Index++) {
287 //
288 // Print the breakpoint
289 //
290 EDBPrint (L" %2d 0x%016lx", Index, DebuggerPrivate->DebuggerBreakpointContext[Index].BreakpointAddress);
291 if (DebuggerPrivate->DebuggerBreakpointContext[Index].State) {
292 EDBPrint (L" *\n");
293 } else {
294 EDBPrint (L"\n");
295 }
296 }
297
298 //
299 // Done
300 //
301 return EFI_DEBUG_CONTINUE;
302}
303
316EFI_DEBUG_STATUS
318 IN CHAR16 *CommandArg,
319 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
320 IN EFI_EXCEPTION_TYPE ExceptionType,
321 IN OUT EFI_SYSTEM_CONTEXT SystemContext
322 )
323{
324 UINTN Address;
325 EFI_STATUS Status;
326
327 if (CommandArg == NULL) {
328 EDBPrint (L"BreakpointSet Argument error!\n");
329 return EFI_DEBUG_CONTINUE;
330 }
331
332 //
333 // Get breakpoint address
334 //
335 Status = Symboltoi (CommandArg, &Address);
336 if (EFI_ERROR (Status)) {
337 if (Status == EFI_NOT_FOUND) {
338 Address = Xtoi (CommandArg);
339 } else {
340 //
341 // Something wrong, let Symboltoi print error info.
342 //
343 EDBPrint (L"Command Argument error!\n");
344 return EFI_DEBUG_CONTINUE;
345 }
346 }
347
348 //
349 // Add breakpoint
350 //
351 Status = DebuggerBreakpointAdd (DebuggerPrivate, Address);
352 if (EFI_ERROR (Status)) {
353 EDBPrint (L"BreakpointSet error!\n");
354 }
355
356 //
357 // Done
358 //
359 return EFI_DEBUG_CONTINUE;
360}
361
374EFI_DEBUG_STATUS
376 IN CHAR16 *CommandArg,
377 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
378 IN EFI_EXCEPTION_TYPE ExceptionType,
379 IN OUT EFI_SYSTEM_CONTEXT SystemContext
380 )
381{
382 UINTN Index;
383 EFI_STATUS Status;
384
385 if (CommandArg == NULL) {
386 EDBPrint (L"BreakpointClear Argument error!\n");
387 return EFI_DEBUG_CONTINUE;
388 }
389
390 if (StriCmp (CommandArg, L"*") == 0) {
391 //
392 // delete all breakpoint
393 //
394 DebuggerPrivate->DebuggerBreakpointCount = 0;
395 ZeroMem (DebuggerPrivate->DebuggerBreakpointContext, sizeof (DebuggerPrivate->DebuggerBreakpointContext));
396 EDBPrint (L"All the Breakpoint is cleared\n");
397 return EFI_DEBUG_CONTINUE;
398 }
399
400 //
401 // Get breakpoint index
402 //
403 Index = Atoi (CommandArg);
404 if (Index == (UINTN)-1) {
405 EDBPrint (L"BreakpointClear Argument error!\n");
406 return EFI_DEBUG_CONTINUE;
407 }
408
409 if ((Index >= EFI_DEBUGGER_BREAKPOINT_MAX) ||
410 (Index >= DebuggerPrivate->DebuggerBreakpointCount))
411 {
412 EDBPrint (L"BreakpointClear error!\n");
413 return EFI_DEBUG_CONTINUE;
414 }
415
416 //
417 // Delete breakpoint
418 //
419 Status = DebuggerBreakpointDel (DebuggerPrivate, Index);
420 if (EFI_ERROR (Status)) {
421 EDBPrint (L"BreakpointClear error!\n");
422 }
423
424 //
425 // Done
426 //
427 return EFI_DEBUG_CONTINUE;
428}
429
442EFI_DEBUG_STATUS
444 IN CHAR16 *CommandArg,
445 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
446 IN EFI_EXCEPTION_TYPE ExceptionType,
447 IN OUT EFI_SYSTEM_CONTEXT SystemContext
448 )
449{
450 UINTN Index;
451 EFI_STATUS Status;
452
453 if (CommandArg == NULL) {
454 EDBPrint (L"BreakpointDisable Argument error!\n");
455 return EFI_DEBUG_CONTINUE;
456 }
457
458 if (StriCmp (CommandArg, L"*") == 0) {
459 //
460 // disable all breakpoint
461 //
462 for (Index = 0; Index < DebuggerPrivate->DebuggerBreakpointCount; Index++) {
463 Status = DebuggerBreakpointDis (DebuggerPrivate, Index);
464 }
465
466 EDBPrint (L"All the Breakpoint is disabled\n");
467 return EFI_DEBUG_CONTINUE;
468 }
469
470 //
471 // Get breakpoint index
472 //
473 Index = Atoi (CommandArg);
474 if (Index == (UINTN)-1) {
475 EDBPrint (L"BreakpointDisable Argument error!\n");
476 return EFI_DEBUG_CONTINUE;
477 }
478
479 //
480 // Disable breakpoint
481 //
482 Status = DebuggerBreakpointDis (DebuggerPrivate, Index);
483 if (EFI_ERROR (Status)) {
484 EDBPrint (L"BreakpointDisable error!\n");
485 }
486
487 //
488 // Done
489 //
490 return EFI_DEBUG_CONTINUE;
491}
492
504EFI_DEBUG_STATUS
506 IN CHAR16 *CommandArg,
507 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
508 IN EFI_EXCEPTION_TYPE ExceptionType,
509 IN OUT EFI_SYSTEM_CONTEXT SystemContext
510 )
511{
512 UINTN Index;
513 EFI_STATUS Status;
514
515 if (CommandArg == NULL) {
516 EDBPrint (L"BreakpointEnable Argument error!\n");
517 return EFI_DEBUG_CONTINUE;
518 }
519
520 if (StriCmp (CommandArg, L"*") == 0) {
521 //
522 // enable all breakpoint
523 //
524 for (Index = 0; Index < DebuggerPrivate->DebuggerBreakpointCount; Index++) {
525 Status = DebuggerBreakpointEn (DebuggerPrivate, Index);
526 }
527
528 EDBPrint (L"All the Breakpoint is enabled\n");
529 return EFI_DEBUG_CONTINUE;
530 }
531
532 //
533 // Get breakpoint index
534 //
535 Index = Atoi (CommandArg);
536 if (Index == (UINTN)-1) {
537 EDBPrint (L"BreakpointEnable Argument error!\n");
538 return EFI_DEBUG_CONTINUE;
539 }
540
541 //
542 // Enable breakpoint
543 //
544 Status = DebuggerBreakpointEn (DebuggerPrivate, Index);
545 if (EFI_ERROR (Status)) {
546 EDBPrint (L"BreakpointEnable error!\n");
547 }
548
549 //
550 // Done
551 //
552 return EFI_DEBUG_CONTINUE;
553}
UINT64 UINTN
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_DEBUG_STATUS DebuggerBreakpointDisable(IN CHAR16 *CommandArg, IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate, IN EFI_EXCEPTION_TYPE ExceptionType, IN OUT EFI_SYSTEM_CONTEXT SystemContext)
EFI_DEBUG_STATUS DebuggerBreakpointList(IN CHAR16 *CommandArg, IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate, IN EFI_EXCEPTION_TYPE ExceptionType, IN OUT EFI_SYSTEM_CONTEXT SystemContext)
BOOLEAN DebuggerBreakpointIsDuplicated(IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate, IN UINTN Address)
EFI_DEBUG_STATUS DebuggerBreakpointEnable(IN CHAR16 *CommandArg, IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate, IN EFI_EXCEPTION_TYPE ExceptionType, IN OUT EFI_SYSTEM_CONTEXT SystemContext)
BOOLEAN IsEBCBREAK3(IN UINTN Address)
EFI_STATUS DebuggerBreakpointDel(IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate, IN UINTN Index)
EFI_STATUS DebuggerBreakpointDis(IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate, IN UINTN Index)
EFI_STATUS DebuggerBreakpointAdd(IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate, IN UINTN Address)
EFI_DEBUG_STATUS DebuggerBreakpointSet(IN CHAR16 *CommandArg, IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate, IN EFI_EXCEPTION_TYPE ExceptionType, IN OUT EFI_SYSTEM_CONTEXT SystemContext)
EFI_DEBUG_STATUS DebuggerBreakpointClear(IN CHAR16 *CommandArg, IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate, IN EFI_EXCEPTION_TYPE ExceptionType, IN OUT EFI_SYSTEM_CONTEXT SystemContext)
EFI_STATUS DebuggerBreakpointEn(IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate, IN UINTN Index)
UINTN EFIAPI Xtoi(CHAR16 *Str)
UINTN EFIAPI Atoi(CHAR16 *Str)
UINTN EFIAPI EDBPrint(IN CONST CHAR16 *Format,...)
Definition: EdbSupportUI.c:683
INTN EFIAPI StriCmp(IN CHAR16 *String, IN CHAR16 *String2)
EFI_STATUS Symboltoi(IN CHAR16 *Symbol, OUT UINTN *Address)
Definition: EdbSymbol.c:2222
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
INTN EFI_EXCEPTION_TYPE
Definition: DebugSupport.h:35
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112