]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdBreakpoint.c
MdeModulePkg: Apply uncrustify changes
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / EbcDebugger / EdbCmdBreakpoint.c
1 /** @file
2
3 Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
4 SPDX-License-Identifier: BSD-2-Clause-Patent
5
6
7 **/
8
9 #include "Edb.h"
10
11 /**
12
13 Check whether current IP is EBC BREAK3 instruction.
14
15 @param Address EBC IP address.
16
17 @retval TRUE Current IP is EBC BREAK3 instruction
18 @retval FALSE Current IP is not EBC BREAK3 instruction
19
20 **/
21 BOOLEAN
22 IsEBCBREAK3 (
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
37 /**
38
39 Check whether the Address is already set in breakpoint.
40
41 @param DebuggerPrivate EBC Debugger private data structure
42 @param Address Breakpoint Address
43
44 @retval TRUE breakpoint is found
45 @retval FALSE breakpoint is not found
46
47 **/
48 BOOLEAN
49 DebuggerBreakpointIsDuplicated (
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
74 /**
75
76 Add this breakpoint.
77
78 @param DebuggerPrivate EBC Debugger private data structure
79 @param Address Breakpoint Address
80
81 @retval EFI_SUCCESS breakpoint added successfully
82 @retval EFI_ALREADY_STARTED breakpoint is already added
83 @retval EFI_OUT_OF_RESOURCES all the breakpoint entries are used
84
85 **/
86 EFI_STATUS
87 DebuggerBreakpointAdd (
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
133 /**
134
135 Delete this breakpoint.
136
137 @param DebuggerPrivate EBC Debugger private data structure
138 @param Index Breakpoint Index
139
140 @retval EFI_SUCCESS breakpoint deleted successfully
141 @retval EFI_NOT_FOUND breakpoint not found
142
143 **/
144 EFI_STATUS
145 DebuggerBreakpointDel (
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
182 /**
183
184 Disable this breakpoint.
185
186 @param DebuggerPrivate EBC Debugger private data structure
187 @param Index Breakpoint Index
188
189 @retval EFI_SUCCESS breakpoint disabled successfully
190 @retval EFI_NOT_FOUND breakpoint not found
191
192 **/
193 EFI_STATUS
194 DebuggerBreakpointDis (
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
213 /**
214
215 Enable this breakpoint.
216
217 @param DebuggerPrivate - EBC Debugger private data structure
218 @param Index - Breakpoint Index
219
220 @retval EFI_SUCCESS - breakpoint enabled successfully
221 @retval EFI_NOT_FOUND - breakpoint not found
222
223 **/
224 EFI_STATUS
225 DebuggerBreakpointEn (
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
244 /**
245
246 DebuggerCommand - BreakpointList.
247
248 @param CommandArg - The argument for this command
249 @param DebuggerPrivate - EBC Debugger private data structure
250 @param ExceptionType - Exception type.
251 @param SystemContext - EBC system context.
252
253 @retval EFI_DEBUG_CONTINUE - formal return value
254
255 **/
256 EFI_DEBUG_STATUS
257 DebuggerBreakpointList (
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
304 /**
305
306 DebuggerCommand - BreakpointSet.
307
308 @param CommandArg The argument for this command
309 @param DebuggerPrivate EBC Debugger private data structure
310 @param ExceptionType Exception type.
311 @param SystemContext EBC system context.
312
313 @retval EFI_DEBUG_CONTINUE - formal return value
314
315 **/
316 EFI_DEBUG_STATUS
317 DebuggerBreakpointSet (
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
362 /**
363
364 DebuggerCommand - BreakpointClear
365
366 @param CommandArg The argument for this command
367 @param DebuggerPrivate EBC Debugger private data structure
368 @param ExceptionType Exception type.
369 @param SystemContext EBC system context.
370
371 @retval EFI_DEBUG_CONTINUE formal return value
372
373 **/
374 EFI_DEBUG_STATUS
375 DebuggerBreakpointClear (
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
430 /**
431
432 DebuggerCommand - BreakpointDisable
433
434 @param CommandArg The argument for this command
435 @param DebuggerPrivate EBC Debugger private data structure
436 @param ExceptionType Exception type.
437 @param SystemContext EBC system context.
438
439 @retval EFI_DEBUG_CONTINUE formal return value
440
441 **/
442 EFI_DEBUG_STATUS
443 DebuggerBreakpointDisable (
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
493 /**
494 DebuggerCommand - BreakpointEnable.
495
496 @param CommandArg The argument for this command
497 @param DebuggerPrivate EBC Debugger private data structure
498 @param ExceptionType Exception type.
499 @param SystemContext EBC system context.
500
501 @retval EFI_DEBUG_CONTINUE formal return value
502
503 **/
504 EFI_DEBUG_STATUS
505 DebuggerBreakpointEnable (
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 }