3 Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
4 SPDX-License-Identifier: BSD-2-Clause-Patent
13 Get file name from full path.
15 @param FullPath - full file path
21 GetFileNameFromFullPath (
29 TempFileName
= StrGetNewTokenLine (FullPath
, L
"\\");
31 while (TempFileName
!= NULL
) {
32 FileName
= TempFileName
;
33 TempFileName
= StrGetNextTokenLine (L
"\\");
34 PatchForStrTokenBefore (TempFileName
, L
'\\');
42 Get dir name from full path.
44 @param FullPath - full file path
50 GetDirNameFromFullPath (
56 FileName
= GetFileNameFromFullPath (FullPath
);
57 if (FileName
!= FullPath
) {
67 Construct full path according to dir and file path.
69 @param DirPath - dir path
70 @param FilePath - file path
71 @param Size - dir max size
73 @return Full file name
85 DirPathSize
= StrLen(DirPath
);
86 *(DirPath
+ DirPathSize
) = L
'\\';
87 StrnCatS (DirPath
, DirPathSize
+ Size
+ 1, FilePath
, Size
);
89 *(DirPath
+ DirPathSize
+ Size
+ 1) = 0;
94 CHAR16
*mSymbolTypeStr
[] = {
103 Comvert Symbol Type to string.
105 @param Type - Symbol Type
112 IN EFI_DEBUGGER_SYMBOL_TYPE Type
115 if (Type
< 0 || Type
>= EfiDebuggerSymbolTypeMax
) {
119 return mSymbolTypeStr
[Type
];
124 Find the symbol according to address and display symbol.
126 @param Address - SymbolAddress
127 @param DebuggerPrivate - EBC Debugger private data structure
129 @retval EFI_DEBUG_CONTINUE - formal return value
133 DebuggerDisplaySymbolAccrodingToAddress (
135 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
138 EFI_DEBUGGER_SYMBOL_OBJECT
*Object
;
139 EFI_DEBUGGER_SYMBOL_ENTRY
*Entry
;
140 UINTN CandidateAddress
;
143 // Find the nearest symbol address
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");
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");
162 L
" 0x%016lx %s %a\n",
163 (UINT64
)Entry
->Rva
+ Object
->BaseAddress
,
164 EdbSymbolTypeToStr (Entry
->Type
),
168 EDBPrint (L
" Address Type Symbol\n");
169 EDBPrint (L
" ========== ==== ========\n");
170 // EDBPrint (L" 0xFFFF0000 ( F) TestMain\n");
173 Entry
->Rva
+ Object
->BaseAddress
,
174 EdbSymbolTypeToStr (Entry
->Type
),
182 return EFI_DEBUG_CONTINUE
;
187 Find the symbol according to name and display symbol.
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
193 @retval EFI_DEBUG_CONTINUE - formal return value
197 DebuggerDisplaySymbolAccrodingToName (
198 IN CHAR16
*SymbolFileName
,
199 IN CHAR16
*SymbolName
,
200 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
205 EFI_DEBUGGER_SYMBOL_OBJECT
*Object
;
206 EFI_DEBUGGER_SYMBOL_ENTRY
*Entry
;
208 if (DebuggerPrivate
->DebuggerSymbolContext
.ObjectCount
== 0) {
209 EDBPrint (L
"No Symbol File!\n");
210 return EFI_DEBUG_CONTINUE
;
214 // Go throuth each symbol file
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)) {
224 // Break each symbol file
227 if (SetPageBreak ()) {
232 EDBPrint (L
"Symbol File Name: %s\n", Object
->Name
);
233 if (Object
->EntryCount
== 0) {
234 EDBPrint (L
"No Symbol!\n");
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");
243 EDBPrint (L
" Address Type Symbol\n");
244 EDBPrint (L
" ========== ==== ========\n");
245 // EDBPrint (L" 0xFFFF0000 ( F) TestMain (EbcTest.obj)\n");
249 // Go through each symbol name
251 for (SubIndex
= 0; SubIndex
< Object
->EntryCount
; SubIndex
++, Entry
++) {
252 if ((SymbolName
!= NULL
) &&
253 (StrCmpUnicodeAndAscii (SymbolName
, Entry
->Name
) != 0)) {
260 if (((SubIndex
% EFI_DEBUGGER_LINE_NUMBER_IN_PAGE
) == 0) &&
262 if (SetPageBreak ()) {
267 if (sizeof(UINTN
) == sizeof(UINT64
)) {
269 L
" 0x%016lx %s %a (%a)\n",
270 (UINT64
)Entry
->Rva
+ Object
->BaseAddress
,
271 EdbSymbolTypeToStr (Entry
->Type
),
277 L
" 0x%08x %s %a (%a)\n",
278 Entry
->Rva
+ Object
->BaseAddress
,
279 EdbSymbolTypeToStr (Entry
->Type
),
290 return EFI_DEBUG_CONTINUE
;
295 DebuggerCommand - ListSymbol.
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.
302 @retval EFI_DEBUG_CONTINUE - formal return value
307 IN CHAR16
*CommandArg
,
308 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
309 IN EFI_EXCEPTION_TYPE ExceptionType
,
310 IN OUT EFI_SYSTEM_CONTEXT SystemContext
313 CHAR16
*SymbolFileName
;
318 SymbolFileName
= NULL
;
320 CommandStr
= CommandArg
;
323 // display symbol according to address
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
);
334 // Get SymbolFileName
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
;
343 SymbolFileName
= CommandStr
;
344 CommandStr
= StrGetNextTokenLine (L
" ");
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
;
358 SymbolName
= CommandStr
;
359 CommandStr
= StrGetNextTokenLine (L
" ");
363 if (CommandStr
!= NULL
) {
364 EDBPrint (L
"Argument error!\n");
365 return EFI_DEBUG_CONTINUE
;
369 // display symbol according to name
371 return DebuggerDisplaySymbolAccrodingToName (SymbolFileName
, SymbolName
, DebuggerPrivate
);
376 DebuggerCommand - LoadSymbol.
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.
383 @retval EFI_DEBUG_CONTINUE - formal return value
388 IN CHAR16
*CommandArg
,
389 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
390 IN EFI_EXCEPTION_TYPE ExceptionType
,
391 IN OUT EFI_SYSTEM_CONTEXT SystemContext
401 CHAR16 CodFile
[EFI_DEBUGGER_SYMBOL_NAME_MAX
];
406 // Check the argument
408 if (CommandArg
== NULL
) {
409 EDBPrint (L
"SymbolFile not found!\n");
410 return EFI_DEBUG_CONTINUE
;
413 CommandArg2
= StrGetNextTokenLine (L
" ");
414 if (CommandArg2
!= NULL
) {
415 if (StriCmp (CommandArg2
, L
"a") == 0) {
418 EDBPrint (L
"Argument error!\n");
419 return EFI_DEBUG_CONTINUE
;
423 if (StrLen (CommandArg
) <= 4) {
424 EDBPrint (L
"SymbolFile name error!\n");
425 return EFI_DEBUG_CONTINUE
;
427 if (StriCmp (CommandArg
+ (StrLen (CommandArg
) - 4), L
".map") != 0) {
428 EDBPrint (L
"SymbolFile name error!\n");
429 return EFI_DEBUG_CONTINUE
;
433 // Read MAP file to memory
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
;
441 FileName
= GetFileNameFromFullPath (CommandArg
);
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
;
451 gBS
->FreePool (Buffer
);
454 // Patch Symbol for RVA
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
);
460 DEBUG ((DEBUG_ERROR
, "PatchSymbol RVA successfully!\n"));
464 return EFI_DEBUG_CONTINUE
;
468 // load each cod file
470 DirName
= GetDirNameFromFullPath (CommandArg
);
471 ZeroMem (CodFile
, sizeof(CodFile
));
472 if (StrCmp (DirName
, L
"") != 0) {
473 StrCpyS (CodFile
, sizeof(CodFile
), DirName
);
479 // Go throuth each file under this dir
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
);
490 // read cod file to memory
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
);
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
);
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
);
524 CodFileName
= GetFileNameUnderDir (DebuggerPrivate
, DirName
, L
".cod", &Index
);
530 return EFI_DEBUG_CONTINUE
;
535 DebuggerCommand - UnloadSymbol
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.
542 @retval EFI_DEBUG_CONTINUE - formal return value
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
556 CHAR16 CodFile
[EFI_DEBUGGER_SYMBOL_NAME_MAX
];
562 // Check the argument
564 if (CommandArg
== NULL
) {
565 EDBPrint (L
"SymbolFile not found!\n");
566 return EFI_DEBUG_CONTINUE
;
569 FileName
= GetFileNameFromFullPath (CommandArg
);
574 DirName
= GetDirNameFromFullPath (CommandArg
);
575 ZeroMem (CodFile
, sizeof(CodFile
));
576 if (StrCmp (DirName
, L
"") != 0) {
577 StrCpyS (CodFile
, sizeof(CodFile
), DirName
);
583 // Go through each file under this dir
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
);
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
);
604 // Delete the code buffer
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
);
616 CodFileName
= GetFileNameUnderDir (DebuggerPrivate
, DirName
, L
".cod", &Index
);
622 Status
= EdbUnloadSymbol (DebuggerPrivate
, FileName
);
623 if (EFI_ERROR(Status
)) {
624 EDBPrint (L
"UnloadSymbol error!\n");
630 return EFI_DEBUG_CONTINUE
;
635 DebuggerCommand - DisplaySymbol.
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.
642 @retval EFI_DEBUG_CONTINUE - formal return value
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
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
);
663 EDBPrint (L
"DisplaySymbol - argument error\n");
666 return EFI_DEBUG_CONTINUE
;
671 DebuggerCommand - LoadCode.
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.
678 @retval EFI_DEBUG_CONTINUE - formal return value
683 IN CHAR16
*CommandArg
,
684 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
685 IN EFI_EXCEPTION_TYPE ExceptionType
,
686 IN OUT EFI_SYSTEM_CONTEXT SystemContext
697 // Check the argument
699 if (CommandArg
== NULL
) {
700 EDBPrint (L
"CodeFile not found!\n");
701 return EFI_DEBUG_CONTINUE
;
703 CommandArg2
= StrGetNextTokenLine (L
" ");
704 if (CommandArg2
== NULL
) {
705 EDBPrint (L
"SymbolFile not found!\n");
706 return EFI_DEBUG_CONTINUE
;
709 if (StrLen (CommandArg
) <= 4) {
710 EDBPrint (L
"CodeFile name error!\n");
711 return EFI_DEBUG_CONTINUE
;
713 if (StriCmp (CommandArg
+ (StrLen (CommandArg
) - 4), L
".cod") != 0) {
714 EDBPrint (L
"CodeFile name error!\n");
715 return EFI_DEBUG_CONTINUE
;
717 if (StrLen (CommandArg2
) <= 4) {
718 EDBPrint (L
"SymbolFile name error!\n");
719 return EFI_DEBUG_CONTINUE
;
721 if (StriCmp (CommandArg2
+ (StrLen (CommandArg2
) - 4), L
".map") != 0) {
722 EDBPrint (L
"SymbolFile name error!\n");
723 return EFI_DEBUG_CONTINUE
;
727 // read cod file to memory
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
;
735 FileName
= GetFileNameFromFullPath (CommandArg
);
736 MapFileName
= GetFileNameFromFullPath (CommandArg2
);
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
;
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
;
760 return EFI_DEBUG_CONTINUE
;
765 DebuggerCommand - UnloadCode.
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.
772 @retval EFI_DEBUG_CONTINUE - formal return value
777 IN CHAR16
*CommandArg
,
778 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
779 IN EFI_EXCEPTION_TYPE ExceptionType
,
780 IN OUT EFI_SYSTEM_CONTEXT SystemContext
790 // Check the argument
792 if (CommandArg
== NULL
) {
793 EDBPrint (L
"CodeFile not found!\n");
794 return EFI_DEBUG_CONTINUE
;
796 CommandArg2
= StrGetNextTokenLine (L
" ");
797 if (CommandArg2
== NULL
) {
798 EDBPrint (L
"SymbolFile not found!\n");
799 return EFI_DEBUG_CONTINUE
;
802 FileName
= GetFileNameFromFullPath (CommandArg
);
803 MapFileName
= GetFileNameFromFullPath (CommandArg2
);
808 Status
= EdbUnloadCode (DebuggerPrivate
, MapFileName
, FileName
, &BufferPtr
);
809 if (EFI_ERROR (Status
)) {
810 EDBPrint (L
"UnloadCode error!\n");
811 return EFI_DEBUG_CONTINUE
;
815 // Delete Code buffer
817 Status
= EdbDeleteCodeBuffer (DebuggerPrivate
, MapFileName
, FileName
, BufferPtr
);
818 if (EFI_ERROR (Status
)) {
819 EDBPrint (L
"DeleteCodeBuffer error!\n");
825 return EFI_DEBUG_CONTINUE
;
830 DebuggerCommand - DisplayCode.
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.
837 @retval EFI_DEBUG_CONTINUE - formal return value
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
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
);
858 EDBPrint (L
"DisplayCode - argument error\n");
861 return EFI_DEBUG_CONTINUE
;