]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdSymbol.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[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) {
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 continue;
221 }
222
223 //
224 // Break each symbol file
225 //
226 if (Index != 0) {
227 if (SetPageBreak ()) {
228 break;
229 }
230 }
231
232 EDBPrint (L"Symbol File Name: %s\n", Object->Name);
233 if (Object->EntryCount == 0) {
234 EDBPrint (L"No Symbol!\n");
235 continue;
236 }
237 Entry = Object->Entry;
238 if (sizeof(UINTN) == sizeof(UINT64)) {
239 EDBPrint (L" Address Type Symbol\n");
240 EDBPrint (L" ================== ==== ========\n");
241 // EDBPrint (L" 0xFFFFFFFF00000000 ( F) TestMain (EbcTest.obj)\n");
242 } else {
243 EDBPrint (L" Address Type Symbol\n");
244 EDBPrint (L" ========== ==== ========\n");
245 // EDBPrint (L" 0xFFFF0000 ( F) TestMain (EbcTest.obj)\n");
246 }
247
248 //
249 // Go through each symbol name
250 //
251 for (SubIndex = 0; SubIndex < Object->EntryCount; SubIndex++, Entry++) {
252 if ((SymbolName != NULL) &&
253 (StrCmpUnicodeAndAscii (SymbolName, Entry->Name) != 0)) {
254 continue;
255 }
256
257 //
258 // Break symbol
259 //
260 if (((SubIndex % EFI_DEBUGGER_LINE_NUMBER_IN_PAGE) == 0) &&
261 (SubIndex != 0)) {
262 if (SetPageBreak ()) {
263 break;
264 }
265 }
266
267 if (sizeof(UINTN) == sizeof(UINT64)) {
268 EDBPrint (
269 L" 0x%016lx %s %a (%a)\n",
270 (UINT64)Entry->Rva + Object->BaseAddress,
271 EdbSymbolTypeToStr (Entry->Type),
272 Entry->Name,
273 Entry->ObjName
274 );
275 } else {
276 EDBPrint (
277 L" 0x%08x %s %a (%a)\n",
278 Entry->Rva + Object->BaseAddress,
279 EdbSymbolTypeToStr (Entry->Type),
280 Entry->Name,
281 Entry->ObjName
282 );
283 }
284 }
285 }
286
287 //
288 // Done
289 //
290 return EFI_DEBUG_CONTINUE;
291 }
292
293 /**
294
295 DebuggerCommand - ListSymbol.
296
297 @param CommandArg - The argument for this command
298 @param DebuggerPrivate - EBC Debugger private data structure
299 @param ExceptionType - Exception type.
300 @param SystemContext - EBC system context.
301
302 @retval EFI_DEBUG_CONTINUE - formal return value
303
304 **/
305 EFI_DEBUG_STATUS
306 DebuggerListSymbol (
307 IN CHAR16 *CommandArg,
308 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
309 IN EFI_EXCEPTION_TYPE ExceptionType,
310 IN OUT EFI_SYSTEM_CONTEXT SystemContext
311 )
312 {
313 CHAR16 *SymbolFileName;
314 CHAR16 *SymbolName;
315 CHAR16 *CommandStr;
316 UINTN Address;
317
318 SymbolFileName = NULL;
319 SymbolName = NULL;
320 CommandStr = CommandArg;
321
322 //
323 // display symbol according to address
324 //
325 if (CommandStr != NULL) {
326 if ((StriCmp (CommandStr, L"F") != 0) &&
327 (StriCmp (CommandStr, L"S") != 0)) {
328 Address = Xtoi (CommandStr);
329 return DebuggerDisplaySymbolAccrodingToAddress (Address, DebuggerPrivate);
330 }
331 }
332
333 //
334 // Get SymbolFileName
335 //
336 if (CommandStr != NULL) {
337 if (StriCmp (CommandStr, L"F") == 0) {
338 CommandStr = StrGetNextTokenLine (L" ");
339 if (CommandStr == NULL) {
340 EDBPrint (L"Symbol File Name missing!\n");
341 return EFI_DEBUG_CONTINUE;
342 } else {
343 SymbolFileName = CommandStr;
344 CommandStr = StrGetNextTokenLine (L" ");
345 }
346 }
347 }
348 //
349 // Get SymbolName
350 //
351 if (CommandStr != NULL) {
352 if (StriCmp (CommandStr, L"S") == 0) {
353 CommandStr = StrGetNextTokenLine (L" ");
354 if (CommandStr == NULL) {
355 EDBPrint (L"Symbol Name missing!\n");
356 return EFI_DEBUG_CONTINUE;
357 } else {
358 SymbolName = CommandStr;
359 CommandStr = StrGetNextTokenLine (L" ");
360 }
361 }
362 }
363 if (CommandStr != NULL) {
364 EDBPrint (L"Argument error!\n");
365 return EFI_DEBUG_CONTINUE;
366 }
367
368 //
369 // display symbol according to name
370 //
371 return DebuggerDisplaySymbolAccrodingToName (SymbolFileName, SymbolName, DebuggerPrivate);
372 }
373
374 /**
375
376 DebuggerCommand - LoadSymbol.
377
378 @param CommandArg - The argument for this command
379 @param DebuggerPrivate - EBC Debugger private data structure
380 @param ExceptionType - Exception type.
381 @param SystemContext - EBC system context.
382
383 @retval EFI_DEBUG_CONTINUE - formal return value
384
385 **/
386 EFI_DEBUG_STATUS
387 DebuggerLoadSymbol (
388 IN CHAR16 *CommandArg,
389 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
390 IN EFI_EXCEPTION_TYPE ExceptionType,
391 IN OUT EFI_SYSTEM_CONTEXT SystemContext
392 )
393 {
394 UINTN BufferSize;
395 VOID *Buffer;
396 EFI_STATUS Status;
397 CHAR16 *FileName;
398 CHAR16 *CommandArg2;
399 BOOLEAN IsLoadCode;
400 CHAR16 *DirName;
401 CHAR16 CodFile[EFI_DEBUGGER_SYMBOL_NAME_MAX];
402 CHAR16 *CodFileName;
403 UINTN Index;
404
405 //
406 // Check the argument
407 //
408 if (CommandArg == NULL) {
409 EDBPrint (L"SymbolFile not found!\n");
410 return EFI_DEBUG_CONTINUE;
411 }
412 IsLoadCode = FALSE;
413 CommandArg2 = StrGetNextTokenLine (L" ");
414 if (CommandArg2 != NULL) {
415 if (StriCmp (CommandArg2, L"a") == 0) {
416 IsLoadCode = TRUE;
417 } else {
418 EDBPrint (L"Argument error!\n");
419 return EFI_DEBUG_CONTINUE;
420 }
421 }
422
423 if (StrLen (CommandArg) <= 4) {
424 EDBPrint (L"SymbolFile name error!\n");
425 return EFI_DEBUG_CONTINUE;
426 }
427 if (StriCmp (CommandArg + (StrLen (CommandArg) - 4), L".map") != 0) {
428 EDBPrint (L"SymbolFile name error!\n");
429 return EFI_DEBUG_CONTINUE;
430 }
431
432 //
433 // Read MAP file to memory
434 //
435 Status = ReadFileToBuffer (DebuggerPrivate, CommandArg, &BufferSize, &Buffer, TRUE);
436 if (EFI_ERROR(Status)) {
437 EDBPrint (L"SymbolFile read error!\n");
438 return EFI_DEBUG_CONTINUE;
439 }
440
441 FileName = GetFileNameFromFullPath (CommandArg);
442 //
443 // Load Symbol
444 //
445 Status = EdbLoadSymbol (DebuggerPrivate, FileName, BufferSize, Buffer);
446 if (EFI_ERROR(Status)) {
447 EDBPrint (L"LoadSymbol error!\n");
448 gBS->FreePool (Buffer);
449 return EFI_DEBUG_CONTINUE;
450 }
451 gBS->FreePool (Buffer);
452
453 //
454 // Patch Symbol for RVA
455 //
456 Status = EdbPatchSymbolRVA (DebuggerPrivate, FileName, EdbEbcImageRvaSearchTypeLast);
457 if (EFI_ERROR(Status)) {
458 EDBPrint (L"PatchSymbol RVA - %r! Using the RVA in symbol file.\n", Status);
459 } else {
460 DEBUG ((DEBUG_ERROR, "PatchSymbol RVA successfully!\n"));
461 }
462
463 if (!IsLoadCode) {
464 return EFI_DEBUG_CONTINUE;
465 }
466
467 //
468 // load each cod file
469 //
470 DirName = GetDirNameFromFullPath (CommandArg);
471 ZeroMem (CodFile, sizeof(CodFile));
472 if (StrCmp (DirName, L"") != 0) {
473 StrCpyS (CodFile, sizeof(CodFile), DirName);
474 } else {
475 DirName = L"\\";
476 }
477
478 //
479 // Go throuth each file under this dir
480 //
481 Index = 0;
482 CodFileName = GetFileNameUnderDir (DebuggerPrivate, DirName, L".cod", &Index);
483 while (CodFileName != NULL) {
484 ZeroMem (CodFile, sizeof(CodFile));
485 if (StrCmp (DirName, L"\\") != 0) {
486 StrCpyS (CodFile, sizeof(CodFile), DirName);
487 }
488
489 //
490 // read cod file to memory
491 //
492 Status = ReadFileToBuffer (DebuggerPrivate, ConstructFullPath (CodFile, CodFileName, EFI_DEBUGGER_SYMBOL_NAME_MAX - StrLen (CodFile) - 2), &BufferSize, &Buffer, FALSE);
493 if (EFI_ERROR(Status)) {
494 EDBPrint (L"CodeFile read error!\n");
495 CodFileName = GetFileNameUnderDir (DebuggerPrivate, DirName, L".cod", &Index);
496 continue;
497 }
498
499 //
500 // Load Code
501 //
502 Status = EdbLoadCode (DebuggerPrivate, FileName, CodFileName, BufferSize, Buffer);
503 if (EFI_ERROR (Status)) {
504 EDBPrint (L"LoadCode error!\n");
505 gBS->FreePool (Buffer);
506 CodFileName = GetFileNameUnderDir (DebuggerPrivate, DirName, L".cod", &Index);
507 continue;
508 }
509
510 //
511 // Record the buffer
512 //
513 Status = EdbAddCodeBuffer (DebuggerPrivate, FileName, CodFileName, BufferSize, Buffer);
514 if (EFI_ERROR (Status)) {
515 EDBPrint (L"AddCodeBuffer error!\n");
516 gBS->FreePool (Buffer);
517 CodFileName = GetFileNameUnderDir (DebuggerPrivate, DirName, L".cod", &Index);
518 continue;
519 }
520
521 //
522 // Get next file
523 //
524 CodFileName = GetFileNameUnderDir (DebuggerPrivate, DirName, L".cod", &Index);
525 }
526
527 //
528 // Done
529 //
530 return EFI_DEBUG_CONTINUE;
531 }
532
533 /**
534
535 DebuggerCommand - UnloadSymbol
536
537 @param CommandArg - The argument for this command
538 @param DebuggerPrivate - EBC Debugger private data structure
539 @param ExceptionType - Exception type.
540 @param SystemContext - EBC system context.
541
542 @retval EFI_DEBUG_CONTINUE - formal return value
543
544 **/
545 EFI_DEBUG_STATUS
546 DebuggerUnloadSymbol (
547 IN CHAR16 *CommandArg,
548 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
549 IN EFI_EXCEPTION_TYPE ExceptionType,
550 IN OUT EFI_SYSTEM_CONTEXT SystemContext
551 )
552 {
553 EFI_STATUS Status;
554 CHAR16 *FileName;
555 CHAR16 *DirName;
556 CHAR16 CodFile[EFI_DEBUGGER_SYMBOL_NAME_MAX];
557 CHAR16 *CodFileName;
558 UINTN Index;
559 VOID *BufferPtr;
560
561 //
562 // Check the argument
563 //
564 if (CommandArg == NULL) {
565 EDBPrint (L"SymbolFile not found!\n");
566 return EFI_DEBUG_CONTINUE;
567 }
568
569 FileName = GetFileNameFromFullPath (CommandArg);
570
571 //
572 // Unload Code
573 //
574 DirName = GetDirNameFromFullPath (CommandArg);
575 ZeroMem (CodFile, sizeof(CodFile));
576 if (StrCmp (DirName, L"") != 0) {
577 StrCpyS (CodFile, sizeof(CodFile), DirName);
578 } else {
579 DirName = L"\\";
580 }
581
582 //
583 // Go through each file under this dir
584 //
585 Index = 0;
586 CodFileName = GetFileNameUnderDir (DebuggerPrivate, DirName, L".cod", &Index);
587 while (CodFileName != NULL) {
588 ZeroMem (CodFile, sizeof(CodFile));
589 if (StrCmp (DirName, L"\\") != 0) {
590 StrCpyS (CodFile, sizeof(CodFile), DirName);
591 }
592
593 //
594 // Unload Code
595 //
596 Status = EdbUnloadCode (DebuggerPrivate, FileName, CodFileName, &BufferPtr);
597 if (EFI_ERROR (Status)) {
598 EDBPrint (L"UnloadCode error!\n");
599 CodFileName = GetFileNameUnderDir (DebuggerPrivate, DirName, L".cod", &Index);
600 continue;
601 }
602
603 //
604 // Delete the code buffer
605 //
606 Status = EdbDeleteCodeBuffer (DebuggerPrivate, FileName, CodFileName, BufferPtr);
607 if (EFI_ERROR (Status)) {
608 EDBPrint (L"DeleteCodeBuffer error!\n");
609 CodFileName = GetFileNameUnderDir (DebuggerPrivate, DirName, L".cod", &Index);
610 continue;
611 }
612
613 //
614 // Get next file
615 //
616 CodFileName = GetFileNameUnderDir (DebuggerPrivate, DirName, L".cod", &Index);
617 }
618
619 //
620 // Unload Symbol
621 //
622 Status = EdbUnloadSymbol (DebuggerPrivate, FileName);
623 if (EFI_ERROR(Status)) {
624 EDBPrint (L"UnloadSymbol error!\n");
625 }
626
627 //
628 // Done
629 //
630 return EFI_DEBUG_CONTINUE;
631 }
632
633 /**
634
635 DebuggerCommand - DisplaySymbol.
636
637 @param CommandArg - The argument for this command
638 @param DebuggerPrivate - EBC Debugger private data structure
639 @param ExceptionType - Exception type.
640 @param SystemContext - EBC system context.
641
642 @retval EFI_DEBUG_CONTINUE - formal return value
643
644 **/
645 EFI_DEBUG_STATUS
646 DebuggerDisplaySymbol (
647 IN CHAR16 *CommandArg,
648 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
649 IN EFI_EXCEPTION_TYPE ExceptionType,
650 IN OUT EFI_SYSTEM_CONTEXT SystemContext
651 )
652 {
653 if (CommandArg == NULL) {
654 DebuggerPrivate->DebuggerSymbolContext.DisplaySymbol = !DebuggerPrivate->DebuggerSymbolContext.DisplaySymbol;
655 EdbShowDisasm (DebuggerPrivate, SystemContext);
656 } else if (StriCmp (CommandArg, L"on") == 0) {
657 DebuggerPrivate->DebuggerSymbolContext.DisplaySymbol = TRUE;
658 EdbShowDisasm (DebuggerPrivate, SystemContext);
659 } else if (StriCmp (CommandArg, L"off") == 0) {
660 DebuggerPrivate->DebuggerSymbolContext.DisplaySymbol = FALSE;
661 EdbShowDisasm (DebuggerPrivate, SystemContext);
662 } else {
663 EDBPrint (L"DisplaySymbol - argument error\n");
664 }
665
666 return EFI_DEBUG_CONTINUE;
667 }
668
669 /**
670
671 DebuggerCommand - LoadCode.
672
673 @param CommandArg - The argument for this command
674 @param DebuggerPrivate - EBC Debugger private data structure
675 @param ExceptionType - Exception type.
676 @param SystemContext - EBC system context.
677
678 @retval EFI_DEBUG_CONTINUE - formal return value
679
680 **/
681 EFI_DEBUG_STATUS
682 DebuggerLoadCode (
683 IN CHAR16 *CommandArg,
684 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
685 IN EFI_EXCEPTION_TYPE ExceptionType,
686 IN OUT EFI_SYSTEM_CONTEXT SystemContext
687 )
688 {
689 UINTN BufferSize;
690 VOID *Buffer;
691 EFI_STATUS Status;
692 CHAR16 *CommandArg2;
693 CHAR16 *FileName;
694 CHAR16 *MapFileName;
695
696 //
697 // Check the argument
698 //
699 if (CommandArg == NULL) {
700 EDBPrint (L"CodeFile not found!\n");
701 return EFI_DEBUG_CONTINUE;
702 }
703 CommandArg2 = StrGetNextTokenLine (L" ");
704 if (CommandArg2 == NULL) {
705 EDBPrint (L"SymbolFile not found!\n");
706 return EFI_DEBUG_CONTINUE;
707 }
708
709 if (StrLen (CommandArg) <= 4) {
710 EDBPrint (L"CodeFile name error!\n");
711 return EFI_DEBUG_CONTINUE;
712 }
713 if (StriCmp (CommandArg + (StrLen (CommandArg) - 4), L".cod") != 0) {
714 EDBPrint (L"CodeFile name error!\n");
715 return EFI_DEBUG_CONTINUE;
716 }
717 if (StrLen (CommandArg2) <= 4) {
718 EDBPrint (L"SymbolFile name error!\n");
719 return EFI_DEBUG_CONTINUE;
720 }
721 if (StriCmp (CommandArg2 + (StrLen (CommandArg2) - 4), L".map") != 0) {
722 EDBPrint (L"SymbolFile name error!\n");
723 return EFI_DEBUG_CONTINUE;
724 }
725
726 //
727 // read cod file to memory
728 //
729 Status = ReadFileToBuffer (DebuggerPrivate, CommandArg, &BufferSize, &Buffer, TRUE);
730 if (EFI_ERROR(Status)) {
731 EDBPrint (L"CodeFile read error!\n");
732 return EFI_DEBUG_CONTINUE;
733 }
734
735 FileName = GetFileNameFromFullPath (CommandArg);
736 MapFileName = GetFileNameFromFullPath (CommandArg2);
737 //
738 // Load Code
739 //
740 Status = EdbLoadCode (DebuggerPrivate, MapFileName, FileName, BufferSize, Buffer);
741 if (EFI_ERROR (Status)) {
742 EDBPrint (L"LoadCode error!\n");
743 gBS->FreePool (Buffer);
744 return EFI_DEBUG_CONTINUE;
745 }
746
747 //
748 // Record the buffer
749 //
750 Status = EdbAddCodeBuffer (DebuggerPrivate, MapFileName, FileName, BufferSize, Buffer);
751 if (EFI_ERROR (Status)) {
752 EDBPrint (L"AddCodeBuffer error!\n");
753 gBS->FreePool (Buffer);
754 return EFI_DEBUG_CONTINUE;
755 }
756
757 //
758 // Done
759 //
760 return EFI_DEBUG_CONTINUE;
761 }
762
763 /**
764
765 DebuggerCommand - UnloadCode.
766
767 @param CommandArg - The argument for this command
768 @param DebuggerPrivate - EBC Debugger private data structure
769 @param ExceptionType - Exception type.
770 @param SystemContext - EBC system context.
771
772 @retval EFI_DEBUG_CONTINUE - formal return value
773
774 **/
775 EFI_DEBUG_STATUS
776 DebuggerUnloadCode (
777 IN CHAR16 *CommandArg,
778 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
779 IN EFI_EXCEPTION_TYPE ExceptionType,
780 IN OUT EFI_SYSTEM_CONTEXT SystemContext
781 )
782 {
783 CHAR16 *CommandArg2;
784 CHAR16 *FileName;
785 CHAR16 *MapFileName;
786 EFI_STATUS Status;
787 VOID *BufferPtr;
788
789 //
790 // Check the argument
791 //
792 if (CommandArg == NULL) {
793 EDBPrint (L"CodeFile not found!\n");
794 return EFI_DEBUG_CONTINUE;
795 }
796 CommandArg2 = StrGetNextTokenLine (L" ");
797 if (CommandArg2 == NULL) {
798 EDBPrint (L"SymbolFile not found!\n");
799 return EFI_DEBUG_CONTINUE;
800 }
801
802 FileName = GetFileNameFromFullPath (CommandArg);
803 MapFileName = GetFileNameFromFullPath (CommandArg2);
804
805 //
806 // Unload Code
807 //
808 Status = EdbUnloadCode (DebuggerPrivate, MapFileName, FileName, &BufferPtr);
809 if (EFI_ERROR (Status)) {
810 EDBPrint (L"UnloadCode error!\n");
811 return EFI_DEBUG_CONTINUE;
812 }
813
814 //
815 // Delete Code buffer
816 //
817 Status = EdbDeleteCodeBuffer (DebuggerPrivate, MapFileName, FileName, BufferPtr);
818 if (EFI_ERROR (Status)) {
819 EDBPrint (L"DeleteCodeBuffer error!\n");
820 }
821
822 //
823 // Done
824 //
825 return EFI_DEBUG_CONTINUE;
826 }
827
828 /**
829
830 DebuggerCommand - DisplayCode.
831
832 @param CommandArg - The argument for this command
833 @param DebuggerPrivate - EBC Debugger private data structure
834 @param ExceptionType - Exception type.
835 @param SystemContext - EBC system context.
836
837 @retval EFI_DEBUG_CONTINUE - formal return value
838
839 **/
840 EFI_DEBUG_STATUS
841 DebuggerDisplayCode (
842 IN CHAR16 *CommandArg,
843 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
844 IN EFI_EXCEPTION_TYPE ExceptionType,
845 IN OUT EFI_SYSTEM_CONTEXT SystemContext
846 )
847 {
848 if (CommandArg == NULL) {
849 DebuggerPrivate->DebuggerSymbolContext.DisplayCodeOnly = !DebuggerPrivate->DebuggerSymbolContext.DisplayCodeOnly;
850 EdbShowDisasm (DebuggerPrivate, SystemContext);
851 } else if (StriCmp (CommandArg, L"on") == 0) {
852 DebuggerPrivate->DebuggerSymbolContext.DisplayCodeOnly = TRUE;
853 EdbShowDisasm (DebuggerPrivate, SystemContext);
854 } else if (StriCmp (CommandArg, L"off") == 0) {
855 DebuggerPrivate->DebuggerSymbolContext.DisplayCodeOnly = FALSE;
856 EdbShowDisasm (DebuggerPrivate, SystemContext);
857 } else {
858 EDBPrint (L"DisplayCode - argument error\n");
859 }
860
861 return EFI_DEBUG_CONTINUE;
862 }