]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdSymbol.c
MdeModulePkg: Apply uncrustify changes
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / EbcDebugger / EdbCmdSymbol.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 Get file name from full path.
14
15 @param FullPath - full file path
16
17 @return file name
18
19 **/
20 CHAR16 *
21 GetFileNameFromFullPath (
22 IN CHAR16 *FullPath
23 )
24 {
25 CHAR16 *FileName;
26 CHAR16 *TempFileName;
27
28 FileName = FullPath;
29 TempFileName = StrGetNewTokenLine (FullPath, L"\\");
30
31 while (TempFileName != NULL) {
32 FileName = TempFileName;
33 TempFileName = StrGetNextTokenLine (L"\\");
34 PatchForStrTokenBefore (TempFileName, L'\\');
35 }
36
37 return FileName;
38 }
39
40 /**
41
42 Get dir name from full path.
43
44 @param FullPath - full file path
45
46 @return dir name
47
48 **/
49 CHAR16 *
50 GetDirNameFromFullPath (
51 IN CHAR16 *FullPath
52 )
53 {
54 CHAR16 *FileName;
55
56 FileName = GetFileNameFromFullPath (FullPath);
57 if (FileName != FullPath) {
58 *(FileName - 1) = 0;
59 return FullPath;
60 }
61
62 return L"";
63 }
64
65 /**
66
67 Construct full path according to dir and file path.
68
69 @param DirPath - dir path
70 @param FilePath - file path
71 @param Size - dir max size
72
73 @return Full file name
74
75 **/
76 CHAR16 *
77 ConstructFullPath (
78 IN CHAR16 *DirPath,
79 IN CHAR16 *FilePath,
80 IN UINTN Size
81 )
82 {
83 UINTN DirPathSize;
84
85 DirPathSize = StrLen (DirPath);
86 *(DirPath + DirPathSize) = L'\\';
87 StrnCatS (DirPath, DirPathSize + Size + 1, FilePath, Size);
88
89 *(DirPath + DirPathSize + Size + 1) = 0;
90
91 return DirPath;
92 }
93
94 CHAR16 *mSymbolTypeStr[] = {
95 L"( F)",
96 L"(SF)",
97 L"(GV)",
98 L"(SV)",
99 };
100
101 /**
102
103 Comvert Symbol Type to string.
104
105 @param Type - Symbol Type
106
107 @return String
108
109 **/
110 CHAR16 *
111 EdbSymbolTypeToStr (
112 IN EFI_DEBUGGER_SYMBOL_TYPE Type
113 )
114 {
115 if ((Type < 0) || (Type >= EfiDebuggerSymbolTypeMax)) {
116 return L"(?)";
117 }
118
119 return mSymbolTypeStr[Type];
120 }
121
122 /**
123
124 Find the symbol according to address and display symbol.
125
126 @param Address - SymbolAddress
127 @param DebuggerPrivate - EBC Debugger private data structure
128
129 @retval EFI_DEBUG_CONTINUE - formal return value
130
131 **/
132 EFI_DEBUG_STATUS
133 DebuggerDisplaySymbolAccrodingToAddress (
134 IN UINTN Address,
135 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate
136 )
137 {
138 EFI_DEBUGGER_SYMBOL_OBJECT *Object;
139 EFI_DEBUGGER_SYMBOL_ENTRY *Entry;
140 UINTN CandidateAddress;
141
142 //
143 // Find the nearest symbol address
144 //
145 CandidateAddress = EbdFindSymbolAddress (Address, EdbMatchSymbolTypeNearestAddress, &Object, &Entry);
146 if ((CandidateAddress == 0) || (CandidateAddress == (UINTN)-1) || (Entry == NULL)) {
147 EDBPrint (L"Symbole at Address not found!\n");
148 return EFI_DEBUG_CONTINUE;
149 } else if (Address != CandidateAddress) {
150 EDBPrint (L"Symbole at Address not found, print nearest one!\n");
151 }
152
153 //
154 // Display symbol
155 //
156 EDBPrint (L"Symbol File Name: %s\n", Object->Name);
157 if (sizeof (UINTN) == sizeof (UINT64)) {
158 EDBPrint (L" Address Type Symbol\n");
159 EDBPrint (L" ================== ==== ========\n");
160 // EDBPrint (L" 0xFFFFFFFF00000000 ( F) TestMain\n");
161 EDBPrint (
162 L" 0x%016lx %s %a\n",
163 (UINT64)Entry->Rva + Object->BaseAddress,
164 EdbSymbolTypeToStr (Entry->Type),
165 Entry->Name
166 );
167 } else {
168 EDBPrint (L" Address Type Symbol\n");
169 EDBPrint (L" ========== ==== ========\n");
170 // EDBPrint (L" 0xFFFF0000 ( F) TestMain\n");
171 EDBPrint (
172 L" 0x%08x %s %a\n",
173 Entry->Rva + Object->BaseAddress,
174 EdbSymbolTypeToStr (Entry->Type),
175 Entry->Name
176 );
177 }
178
179 //
180 // Done
181 //
182 return EFI_DEBUG_CONTINUE;
183 }
184
185 /**
186
187 Find the symbol according to name and display symbol.
188
189 @param SymbolFileName - The Symbol File Name, NULL means for all
190 @param SymbolName - The Symbol Name, NULL means for all
191 @param DebuggerPrivate - EBC Debugger private data structure
192
193 @retval EFI_DEBUG_CONTINUE - formal return value
194
195 **/
196 EFI_DEBUG_STATUS
197 DebuggerDisplaySymbolAccrodingToName (
198 IN CHAR16 *SymbolFileName,
199 IN CHAR16 *SymbolName,
200 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate
201 )
202 {
203 UINTN Index;
204 UINTN SubIndex;
205 EFI_DEBUGGER_SYMBOL_OBJECT *Object;
206 EFI_DEBUGGER_SYMBOL_ENTRY *Entry;
207
208 if (DebuggerPrivate->DebuggerSymbolContext.ObjectCount == 0) {
209 EDBPrint (L"No Symbol File!\n");
210 return EFI_DEBUG_CONTINUE;
211 }
212
213 //
214 // Go throuth each symbol file
215 //
216 Object = DebuggerPrivate->DebuggerSymbolContext.Object;
217 for (Index = 0; Index < DebuggerPrivate->DebuggerSymbolContext.ObjectCount; Index++, Object++) {
218 if ((SymbolFileName != NULL) &&
219 (StriCmp (SymbolFileName, Object->Name) != 0))
220 {
221 continue;
222 }
223
224 //
225 // Break each symbol file
226 //
227 if (Index != 0) {
228 if (SetPageBreak ()) {
229 break;
230 }
231 }
232
233 EDBPrint (L"Symbol File Name: %s\n", Object->Name);
234 if (Object->EntryCount == 0) {
235 EDBPrint (L"No Symbol!\n");
236 continue;
237 }
238
239 Entry = Object->Entry;
240 if (sizeof (UINTN) == sizeof (UINT64)) {
241 EDBPrint (L" Address Type Symbol\n");
242 EDBPrint (L" ================== ==== ========\n");
243 // EDBPrint (L" 0xFFFFFFFF00000000 ( F) TestMain (EbcTest.obj)\n");
244 } else {
245 EDBPrint (L" Address Type Symbol\n");
246 EDBPrint (L" ========== ==== ========\n");
247 // EDBPrint (L" 0xFFFF0000 ( F) TestMain (EbcTest.obj)\n");
248 }
249
250 //
251 // Go through each symbol name
252 //
253 for (SubIndex = 0; SubIndex < Object->EntryCount; SubIndex++, Entry++) {
254 if ((SymbolName != NULL) &&
255 (StrCmpUnicodeAndAscii (SymbolName, Entry->Name) != 0))
256 {
257 continue;
258 }
259
260 //
261 // Break symbol
262 //
263 if (((SubIndex % EFI_DEBUGGER_LINE_NUMBER_IN_PAGE) == 0) &&
264 (SubIndex != 0))
265 {
266 if (SetPageBreak ()) {
267 break;
268 }
269 }
270
271 if (sizeof (UINTN) == sizeof (UINT64)) {
272 EDBPrint (
273 L" 0x%016lx %s %a (%a)\n",
274 (UINT64)Entry->Rva + Object->BaseAddress,
275 EdbSymbolTypeToStr (Entry->Type),
276 Entry->Name,
277 Entry->ObjName
278 );
279 } else {
280 EDBPrint (
281 L" 0x%08x %s %a (%a)\n",
282 Entry->Rva + Object->BaseAddress,
283 EdbSymbolTypeToStr (Entry->Type),
284 Entry->Name,
285 Entry->ObjName
286 );
287 }
288 }
289 }
290
291 //
292 // Done
293 //
294 return EFI_DEBUG_CONTINUE;
295 }
296
297 /**
298
299 DebuggerCommand - ListSymbol.
300
301 @param CommandArg - The argument for this command
302 @param DebuggerPrivate - EBC Debugger private data structure
303 @param ExceptionType - Exception type.
304 @param SystemContext - EBC system context.
305
306 @retval EFI_DEBUG_CONTINUE - formal return value
307
308 **/
309 EFI_DEBUG_STATUS
310 DebuggerListSymbol (
311 IN CHAR16 *CommandArg,
312 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
313 IN EFI_EXCEPTION_TYPE ExceptionType,
314 IN OUT EFI_SYSTEM_CONTEXT SystemContext
315 )
316 {
317 CHAR16 *SymbolFileName;
318 CHAR16 *SymbolName;
319 CHAR16 *CommandStr;
320 UINTN Address;
321
322 SymbolFileName = NULL;
323 SymbolName = NULL;
324 CommandStr = CommandArg;
325
326 //
327 // display symbol according to address
328 //
329 if (CommandStr != NULL) {
330 if ((StriCmp (CommandStr, L"F") != 0) &&
331 (StriCmp (CommandStr, L"S") != 0))
332 {
333 Address = Xtoi (CommandStr);
334 return DebuggerDisplaySymbolAccrodingToAddress (Address, DebuggerPrivate);
335 }
336 }
337
338 //
339 // Get SymbolFileName
340 //
341 if (CommandStr != NULL) {
342 if (StriCmp (CommandStr, L"F") == 0) {
343 CommandStr = StrGetNextTokenLine (L" ");
344 if (CommandStr == NULL) {
345 EDBPrint (L"Symbol File Name missing!\n");
346 return EFI_DEBUG_CONTINUE;
347 } else {
348 SymbolFileName = CommandStr;
349 CommandStr = StrGetNextTokenLine (L" ");
350 }
351 }
352 }
353
354 //
355 // Get SymbolName
356 //
357 if (CommandStr != NULL) {
358 if (StriCmp (CommandStr, L"S") == 0) {
359 CommandStr = StrGetNextTokenLine (L" ");
360 if (CommandStr == NULL) {
361 EDBPrint (L"Symbol Name missing!\n");
362 return EFI_DEBUG_CONTINUE;
363 } else {
364 SymbolName = CommandStr;
365 CommandStr = StrGetNextTokenLine (L" ");
366 }
367 }
368 }
369
370 if (CommandStr != NULL) {
371 EDBPrint (L"Argument error!\n");
372 return EFI_DEBUG_CONTINUE;
373 }
374
375 //
376 // display symbol according to name
377 //
378 return DebuggerDisplaySymbolAccrodingToName (SymbolFileName, SymbolName, DebuggerPrivate);
379 }
380
381 /**
382
383 DebuggerCommand - LoadSymbol.
384
385 @param CommandArg - The argument for this command
386 @param DebuggerPrivate - EBC Debugger private data structure
387 @param ExceptionType - Exception type.
388 @param SystemContext - EBC system context.
389
390 @retval EFI_DEBUG_CONTINUE - formal return value
391
392 **/
393 EFI_DEBUG_STATUS
394 DebuggerLoadSymbol (
395 IN CHAR16 *CommandArg,
396 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
397 IN EFI_EXCEPTION_TYPE ExceptionType,
398 IN OUT EFI_SYSTEM_CONTEXT SystemContext
399 )
400 {
401 UINTN BufferSize;
402 VOID *Buffer;
403 EFI_STATUS Status;
404 CHAR16 *FileName;
405 CHAR16 *CommandArg2;
406 BOOLEAN IsLoadCode;
407 CHAR16 *DirName;
408 CHAR16 CodFile[EFI_DEBUGGER_SYMBOL_NAME_MAX];
409 CHAR16 *CodFileName;
410 UINTN Index;
411
412 //
413 // Check the argument
414 //
415 if (CommandArg == NULL) {
416 EDBPrint (L"SymbolFile not found!\n");
417 return EFI_DEBUG_CONTINUE;
418 }
419
420 IsLoadCode = FALSE;
421 CommandArg2 = StrGetNextTokenLine (L" ");
422 if (CommandArg2 != NULL) {
423 if (StriCmp (CommandArg2, L"a") == 0) {
424 IsLoadCode = TRUE;
425 } else {
426 EDBPrint (L"Argument error!\n");
427 return EFI_DEBUG_CONTINUE;
428 }
429 }
430
431 if (StrLen (CommandArg) <= 4) {
432 EDBPrint (L"SymbolFile name error!\n");
433 return EFI_DEBUG_CONTINUE;
434 }
435
436 if (StriCmp (CommandArg + (StrLen (CommandArg) - 4), L".map") != 0) {
437 EDBPrint (L"SymbolFile name error!\n");
438 return EFI_DEBUG_CONTINUE;
439 }
440
441 //
442 // Read MAP file to memory
443 //
444 Status = ReadFileToBuffer (DebuggerPrivate, CommandArg, &BufferSize, &Buffer, TRUE);
445 if (EFI_ERROR (Status)) {
446 EDBPrint (L"SymbolFile read error!\n");
447 return EFI_DEBUG_CONTINUE;
448 }
449
450 FileName = GetFileNameFromFullPath (CommandArg);
451 //
452 // Load Symbol
453 //
454 Status = EdbLoadSymbol (DebuggerPrivate, FileName, BufferSize, Buffer);
455 if (EFI_ERROR (Status)) {
456 EDBPrint (L"LoadSymbol error!\n");
457 gBS->FreePool (Buffer);
458 return EFI_DEBUG_CONTINUE;
459 }
460
461 gBS->FreePool (Buffer);
462
463 //
464 // Patch Symbol for RVA
465 //
466 Status = EdbPatchSymbolRVA (DebuggerPrivate, FileName, EdbEbcImageRvaSearchTypeLast);
467 if (EFI_ERROR (Status)) {
468 EDBPrint (L"PatchSymbol RVA - %r! Using the RVA in symbol file.\n", Status);
469 } else {
470 DEBUG ((DEBUG_ERROR, "PatchSymbol RVA successfully!\n"));
471 }
472
473 if (!IsLoadCode) {
474 return EFI_DEBUG_CONTINUE;
475 }
476
477 //
478 // load each cod file
479 //
480 DirName = GetDirNameFromFullPath (CommandArg);
481 ZeroMem (CodFile, sizeof (CodFile));
482 if (StrCmp (DirName, L"") != 0) {
483 StrCpyS (CodFile, sizeof (CodFile), DirName);
484 } else {
485 DirName = L"\\";
486 }
487
488 //
489 // Go throuth each file under this dir
490 //
491 Index = 0;
492 CodFileName = GetFileNameUnderDir (DebuggerPrivate, DirName, L".cod", &Index);
493 while (CodFileName != NULL) {
494 ZeroMem (CodFile, sizeof (CodFile));
495 if (StrCmp (DirName, L"\\") != 0) {
496 StrCpyS (CodFile, sizeof (CodFile), DirName);
497 }
498
499 //
500 // read cod file to memory
501 //
502 Status = ReadFileToBuffer (DebuggerPrivate, ConstructFullPath (CodFile, CodFileName, EFI_DEBUGGER_SYMBOL_NAME_MAX - StrLen (CodFile) - 2), &BufferSize, &Buffer, FALSE);
503 if (EFI_ERROR (Status)) {
504 EDBPrint (L"CodeFile read error!\n");
505 CodFileName = GetFileNameUnderDir (DebuggerPrivate, DirName, L".cod", &Index);
506 continue;
507 }
508
509 //
510 // Load Code
511 //
512 Status = EdbLoadCode (DebuggerPrivate, FileName, CodFileName, BufferSize, Buffer);
513 if (EFI_ERROR (Status)) {
514 EDBPrint (L"LoadCode error!\n");
515 gBS->FreePool (Buffer);
516 CodFileName = GetFileNameUnderDir (DebuggerPrivate, DirName, L".cod", &Index);
517 continue;
518 }
519
520 //
521 // Record the buffer
522 //
523 Status = EdbAddCodeBuffer (DebuggerPrivate, FileName, CodFileName, BufferSize, Buffer);
524 if (EFI_ERROR (Status)) {
525 EDBPrint (L"AddCodeBuffer error!\n");
526 gBS->FreePool (Buffer);
527 CodFileName = GetFileNameUnderDir (DebuggerPrivate, DirName, L".cod", &Index);
528 continue;
529 }
530
531 //
532 // Get next file
533 //
534 CodFileName = GetFileNameUnderDir (DebuggerPrivate, DirName, L".cod", &Index);
535 }
536
537 //
538 // Done
539 //
540 return EFI_DEBUG_CONTINUE;
541 }
542
543 /**
544
545 DebuggerCommand - UnloadSymbol
546
547 @param CommandArg - The argument for this command
548 @param DebuggerPrivate - EBC Debugger private data structure
549 @param ExceptionType - Exception type.
550 @param SystemContext - EBC system context.
551
552 @retval EFI_DEBUG_CONTINUE - formal return value
553
554 **/
555 EFI_DEBUG_STATUS
556 DebuggerUnloadSymbol (
557 IN CHAR16 *CommandArg,
558 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
559 IN EFI_EXCEPTION_TYPE ExceptionType,
560 IN OUT EFI_SYSTEM_CONTEXT SystemContext
561 )
562 {
563 EFI_STATUS Status;
564 CHAR16 *FileName;
565 CHAR16 *DirName;
566 CHAR16 CodFile[EFI_DEBUGGER_SYMBOL_NAME_MAX];
567 CHAR16 *CodFileName;
568 UINTN Index;
569 VOID *BufferPtr;
570
571 //
572 // Check the argument
573 //
574 if (CommandArg == NULL) {
575 EDBPrint (L"SymbolFile not found!\n");
576 return EFI_DEBUG_CONTINUE;
577 }
578
579 FileName = GetFileNameFromFullPath (CommandArg);
580
581 //
582 // Unload Code
583 //
584 DirName = GetDirNameFromFullPath (CommandArg);
585 ZeroMem (CodFile, sizeof (CodFile));
586 if (StrCmp (DirName, L"") != 0) {
587 StrCpyS (CodFile, sizeof (CodFile), DirName);
588 } else {
589 DirName = L"\\";
590 }
591
592 //
593 // Go through each file under this dir
594 //
595 Index = 0;
596 CodFileName = GetFileNameUnderDir (DebuggerPrivate, DirName, L".cod", &Index);
597 while (CodFileName != NULL) {
598 ZeroMem (CodFile, sizeof (CodFile));
599 if (StrCmp (DirName, L"\\") != 0) {
600 StrCpyS (CodFile, sizeof (CodFile), DirName);
601 }
602
603 //
604 // Unload Code
605 //
606 Status = EdbUnloadCode (DebuggerPrivate, FileName, CodFileName, &BufferPtr);
607 if (EFI_ERROR (Status)) {
608 EDBPrint (L"UnloadCode error!\n");
609 CodFileName = GetFileNameUnderDir (DebuggerPrivate, DirName, L".cod", &Index);
610 continue;
611 }
612
613 //
614 // Delete the code buffer
615 //
616 Status = EdbDeleteCodeBuffer (DebuggerPrivate, FileName, CodFileName, BufferPtr);
617 if (EFI_ERROR (Status)) {
618 EDBPrint (L"DeleteCodeBuffer error!\n");
619 CodFileName = GetFileNameUnderDir (DebuggerPrivate, DirName, L".cod", &Index);
620 continue;
621 }
622
623 //
624 // Get next file
625 //
626 CodFileName = GetFileNameUnderDir (DebuggerPrivate, DirName, L".cod", &Index);
627 }
628
629 //
630 // Unload Symbol
631 //
632 Status = EdbUnloadSymbol (DebuggerPrivate, FileName);
633 if (EFI_ERROR (Status)) {
634 EDBPrint (L"UnloadSymbol error!\n");
635 }
636
637 //
638 // Done
639 //
640 return EFI_DEBUG_CONTINUE;
641 }
642
643 /**
644
645 DebuggerCommand - DisplaySymbol.
646
647 @param CommandArg - The argument for this command
648 @param DebuggerPrivate - EBC Debugger private data structure
649 @param ExceptionType - Exception type.
650 @param SystemContext - EBC system context.
651
652 @retval EFI_DEBUG_CONTINUE - formal return value
653
654 **/
655 EFI_DEBUG_STATUS
656 DebuggerDisplaySymbol (
657 IN CHAR16 *CommandArg,
658 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
659 IN EFI_EXCEPTION_TYPE ExceptionType,
660 IN OUT EFI_SYSTEM_CONTEXT SystemContext
661 )
662 {
663 if (CommandArg == NULL) {
664 DebuggerPrivate->DebuggerSymbolContext.DisplaySymbol = !DebuggerPrivate->DebuggerSymbolContext.DisplaySymbol;
665 EdbShowDisasm (DebuggerPrivate, SystemContext);
666 } else if (StriCmp (CommandArg, L"on") == 0) {
667 DebuggerPrivate->DebuggerSymbolContext.DisplaySymbol = TRUE;
668 EdbShowDisasm (DebuggerPrivate, SystemContext);
669 } else if (StriCmp (CommandArg, L"off") == 0) {
670 DebuggerPrivate->DebuggerSymbolContext.DisplaySymbol = FALSE;
671 EdbShowDisasm (DebuggerPrivate, SystemContext);
672 } else {
673 EDBPrint (L"DisplaySymbol - argument error\n");
674 }
675
676 return EFI_DEBUG_CONTINUE;
677 }
678
679 /**
680
681 DebuggerCommand - LoadCode.
682
683 @param CommandArg - The argument for this command
684 @param DebuggerPrivate - EBC Debugger private data structure
685 @param ExceptionType - Exception type.
686 @param SystemContext - EBC system context.
687
688 @retval EFI_DEBUG_CONTINUE - formal return value
689
690 **/
691 EFI_DEBUG_STATUS
692 DebuggerLoadCode (
693 IN CHAR16 *CommandArg,
694 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
695 IN EFI_EXCEPTION_TYPE ExceptionType,
696 IN OUT EFI_SYSTEM_CONTEXT SystemContext
697 )
698 {
699 UINTN BufferSize;
700 VOID *Buffer;
701 EFI_STATUS Status;
702 CHAR16 *CommandArg2;
703 CHAR16 *FileName;
704 CHAR16 *MapFileName;
705
706 //
707 // Check the argument
708 //
709 if (CommandArg == NULL) {
710 EDBPrint (L"CodeFile not found!\n");
711 return EFI_DEBUG_CONTINUE;
712 }
713
714 CommandArg2 = StrGetNextTokenLine (L" ");
715 if (CommandArg2 == NULL) {
716 EDBPrint (L"SymbolFile not found!\n");
717 return EFI_DEBUG_CONTINUE;
718 }
719
720 if (StrLen (CommandArg) <= 4) {
721 EDBPrint (L"CodeFile name error!\n");
722 return EFI_DEBUG_CONTINUE;
723 }
724
725 if (StriCmp (CommandArg + (StrLen (CommandArg) - 4), L".cod") != 0) {
726 EDBPrint (L"CodeFile name error!\n");
727 return EFI_DEBUG_CONTINUE;
728 }
729
730 if (StrLen (CommandArg2) <= 4) {
731 EDBPrint (L"SymbolFile name error!\n");
732 return EFI_DEBUG_CONTINUE;
733 }
734
735 if (StriCmp (CommandArg2 + (StrLen (CommandArg2) - 4), L".map") != 0) {
736 EDBPrint (L"SymbolFile name error!\n");
737 return EFI_DEBUG_CONTINUE;
738 }
739
740 //
741 // read cod file to memory
742 //
743 Status = ReadFileToBuffer (DebuggerPrivate, CommandArg, &BufferSize, &Buffer, TRUE);
744 if (EFI_ERROR (Status)) {
745 EDBPrint (L"CodeFile read error!\n");
746 return EFI_DEBUG_CONTINUE;
747 }
748
749 FileName = GetFileNameFromFullPath (CommandArg);
750 MapFileName = GetFileNameFromFullPath (CommandArg2);
751 //
752 // Load Code
753 //
754 Status = EdbLoadCode (DebuggerPrivate, MapFileName, FileName, BufferSize, Buffer);
755 if (EFI_ERROR (Status)) {
756 EDBPrint (L"LoadCode error!\n");
757 gBS->FreePool (Buffer);
758 return EFI_DEBUG_CONTINUE;
759 }
760
761 //
762 // Record the buffer
763 //
764 Status = EdbAddCodeBuffer (DebuggerPrivate, MapFileName, FileName, BufferSize, Buffer);
765 if (EFI_ERROR (Status)) {
766 EDBPrint (L"AddCodeBuffer error!\n");
767 gBS->FreePool (Buffer);
768 return EFI_DEBUG_CONTINUE;
769 }
770
771 //
772 // Done
773 //
774 return EFI_DEBUG_CONTINUE;
775 }
776
777 /**
778
779 DebuggerCommand - UnloadCode.
780
781 @param CommandArg - The argument for this command
782 @param DebuggerPrivate - EBC Debugger private data structure
783 @param ExceptionType - Exception type.
784 @param SystemContext - EBC system context.
785
786 @retval EFI_DEBUG_CONTINUE - formal return value
787
788 **/
789 EFI_DEBUG_STATUS
790 DebuggerUnloadCode (
791 IN CHAR16 *CommandArg,
792 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
793 IN EFI_EXCEPTION_TYPE ExceptionType,
794 IN OUT EFI_SYSTEM_CONTEXT SystemContext
795 )
796 {
797 CHAR16 *CommandArg2;
798 CHAR16 *FileName;
799 CHAR16 *MapFileName;
800 EFI_STATUS Status;
801 VOID *BufferPtr;
802
803 //
804 // Check the argument
805 //
806 if (CommandArg == NULL) {
807 EDBPrint (L"CodeFile not found!\n");
808 return EFI_DEBUG_CONTINUE;
809 }
810
811 CommandArg2 = StrGetNextTokenLine (L" ");
812 if (CommandArg2 == NULL) {
813 EDBPrint (L"SymbolFile not found!\n");
814 return EFI_DEBUG_CONTINUE;
815 }
816
817 FileName = GetFileNameFromFullPath (CommandArg);
818 MapFileName = GetFileNameFromFullPath (CommandArg2);
819
820 //
821 // Unload Code
822 //
823 Status = EdbUnloadCode (DebuggerPrivate, MapFileName, FileName, &BufferPtr);
824 if (EFI_ERROR (Status)) {
825 EDBPrint (L"UnloadCode error!\n");
826 return EFI_DEBUG_CONTINUE;
827 }
828
829 //
830 // Delete Code buffer
831 //
832 Status = EdbDeleteCodeBuffer (DebuggerPrivate, MapFileName, FileName, BufferPtr);
833 if (EFI_ERROR (Status)) {
834 EDBPrint (L"DeleteCodeBuffer error!\n");
835 }
836
837 //
838 // Done
839 //
840 return EFI_DEBUG_CONTINUE;
841 }
842
843 /**
844
845 DebuggerCommand - DisplayCode.
846
847 @param CommandArg - The argument for this command
848 @param DebuggerPrivate - EBC Debugger private data structure
849 @param ExceptionType - Exception type.
850 @param SystemContext - EBC system context.
851
852 @retval EFI_DEBUG_CONTINUE - formal return value
853
854 **/
855 EFI_DEBUG_STATUS
856 DebuggerDisplayCode (
857 IN CHAR16 *CommandArg,
858 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
859 IN EFI_EXCEPTION_TYPE ExceptionType,
860 IN OUT EFI_SYSTEM_CONTEXT SystemContext
861 )
862 {
863 if (CommandArg == NULL) {
864 DebuggerPrivate->DebuggerSymbolContext.DisplayCodeOnly = !DebuggerPrivate->DebuggerSymbolContext.DisplayCodeOnly;
865 EdbShowDisasm (DebuggerPrivate, SystemContext);
866 } else if (StriCmp (CommandArg, L"on") == 0) {
867 DebuggerPrivate->DebuggerSymbolContext.DisplayCodeOnly = TRUE;
868 EdbShowDisasm (DebuggerPrivate, SystemContext);
869 } else if (StriCmp (CommandArg, L"off") == 0) {
870 DebuggerPrivate->DebuggerSymbolContext.DisplayCodeOnly = FALSE;
871 EdbShowDisasm (DebuggerPrivate, SystemContext);
872 } else {
873 EDBPrint (L"DisplayCode - argument error\n");
874 }
875
876 return EFI_DEBUG_CONTINUE;
877 }