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