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))
225 // Break each symbol file
228 if (SetPageBreak ()) {
233 EDBPrint (L
"Symbol File Name: %s\n", Object
->Name
);
234 if (Object
->EntryCount
== 0) {
235 EDBPrint (L
"No Symbol!\n");
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");
245 EDBPrint (L
" Address Type Symbol\n");
246 EDBPrint (L
" ========== ==== ========\n");
247 // EDBPrint (L" 0xFFFF0000 ( F) TestMain (EbcTest.obj)\n");
251 // Go through each symbol name
253 for (SubIndex
= 0; SubIndex
< Object
->EntryCount
; SubIndex
++, Entry
++) {
254 if ((SymbolName
!= NULL
) &&
255 (StrCmpUnicodeAndAscii (SymbolName
, Entry
->Name
) != 0))
263 if (((SubIndex
% EFI_DEBUGGER_LINE_NUMBER_IN_PAGE
) == 0) &&
266 if (SetPageBreak ()) {
271 if (sizeof (UINTN
) == sizeof (UINT64
)) {
273 L
" 0x%016lx %s %a (%a)\n",
274 (UINT64
)Entry
->Rva
+ Object
->BaseAddress
,
275 EdbSymbolTypeToStr (Entry
->Type
),
281 L
" 0x%08x %s %a (%a)\n",
282 Entry
->Rva
+ Object
->BaseAddress
,
283 EdbSymbolTypeToStr (Entry
->Type
),
294 return EFI_DEBUG_CONTINUE
;
299 DebuggerCommand - ListSymbol.
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.
306 @retval EFI_DEBUG_CONTINUE - formal return value
311 IN CHAR16
*CommandArg
,
312 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
313 IN EFI_EXCEPTION_TYPE ExceptionType
,
314 IN OUT EFI_SYSTEM_CONTEXT SystemContext
317 CHAR16
*SymbolFileName
;
322 SymbolFileName
= NULL
;
324 CommandStr
= CommandArg
;
327 // display symbol according to address
329 if (CommandStr
!= NULL
) {
330 if ((StriCmp (CommandStr
, L
"F") != 0) &&
331 (StriCmp (CommandStr
, L
"S") != 0))
333 Address
= Xtoi (CommandStr
);
334 return DebuggerDisplaySymbolAccrodingToAddress (Address
, DebuggerPrivate
);
339 // Get SymbolFileName
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
;
348 SymbolFileName
= CommandStr
;
349 CommandStr
= StrGetNextTokenLine (L
" ");
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
;
364 SymbolName
= CommandStr
;
365 CommandStr
= StrGetNextTokenLine (L
" ");
370 if (CommandStr
!= NULL
) {
371 EDBPrint (L
"Argument error!\n");
372 return EFI_DEBUG_CONTINUE
;
376 // display symbol according to name
378 return DebuggerDisplaySymbolAccrodingToName (SymbolFileName
, SymbolName
, DebuggerPrivate
);
383 DebuggerCommand - LoadSymbol.
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.
390 @retval EFI_DEBUG_CONTINUE - formal return value
395 IN CHAR16
*CommandArg
,
396 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
397 IN EFI_EXCEPTION_TYPE ExceptionType
,
398 IN OUT EFI_SYSTEM_CONTEXT SystemContext
408 CHAR16 CodFile
[EFI_DEBUGGER_SYMBOL_NAME_MAX
];
413 // Check the argument
415 if (CommandArg
== NULL
) {
416 EDBPrint (L
"SymbolFile not found!\n");
417 return EFI_DEBUG_CONTINUE
;
421 CommandArg2
= StrGetNextTokenLine (L
" ");
422 if (CommandArg2
!= NULL
) {
423 if (StriCmp (CommandArg2
, L
"a") == 0) {
426 EDBPrint (L
"Argument error!\n");
427 return EFI_DEBUG_CONTINUE
;
431 if (StrLen (CommandArg
) <= 4) {
432 EDBPrint (L
"SymbolFile name error!\n");
433 return EFI_DEBUG_CONTINUE
;
436 if (StriCmp (CommandArg
+ (StrLen (CommandArg
) - 4), L
".map") != 0) {
437 EDBPrint (L
"SymbolFile name error!\n");
438 return EFI_DEBUG_CONTINUE
;
442 // Read MAP file to memory
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
;
450 FileName
= GetFileNameFromFullPath (CommandArg
);
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
;
461 gBS
->FreePool (Buffer
);
464 // Patch Symbol for RVA
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
);
470 DEBUG ((DEBUG_ERROR
, "PatchSymbol RVA successfully!\n"));
474 return EFI_DEBUG_CONTINUE
;
478 // load each cod file
480 DirName
= GetDirNameFromFullPath (CommandArg
);
481 ZeroMem (CodFile
, sizeof (CodFile
));
482 if (StrCmp (DirName
, L
"") != 0) {
483 StrCpyS (CodFile
, sizeof (CodFile
), DirName
);
489 // Go throuth each file under this dir
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
);
500 // read cod file to memory
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
);
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
);
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
);
534 CodFileName
= GetFileNameUnderDir (DebuggerPrivate
, DirName
, L
".cod", &Index
);
540 return EFI_DEBUG_CONTINUE
;
545 DebuggerCommand - UnloadSymbol
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.
552 @retval EFI_DEBUG_CONTINUE - formal return value
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
566 CHAR16 CodFile
[EFI_DEBUGGER_SYMBOL_NAME_MAX
];
572 // Check the argument
574 if (CommandArg
== NULL
) {
575 EDBPrint (L
"SymbolFile not found!\n");
576 return EFI_DEBUG_CONTINUE
;
579 FileName
= GetFileNameFromFullPath (CommandArg
);
584 DirName
= GetDirNameFromFullPath (CommandArg
);
585 ZeroMem (CodFile
, sizeof (CodFile
));
586 if (StrCmp (DirName
, L
"") != 0) {
587 StrCpyS (CodFile
, sizeof (CodFile
), DirName
);
593 // Go through each file under this dir
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
);
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
);
614 // Delete the code buffer
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
);
626 CodFileName
= GetFileNameUnderDir (DebuggerPrivate
, DirName
, L
".cod", &Index
);
632 Status
= EdbUnloadSymbol (DebuggerPrivate
, FileName
);
633 if (EFI_ERROR (Status
)) {
634 EDBPrint (L
"UnloadSymbol error!\n");
640 return EFI_DEBUG_CONTINUE
;
645 DebuggerCommand - DisplaySymbol.
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.
652 @retval EFI_DEBUG_CONTINUE - formal return value
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
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
);
673 EDBPrint (L
"DisplaySymbol - argument error\n");
676 return EFI_DEBUG_CONTINUE
;
681 DebuggerCommand - LoadCode.
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.
688 @retval EFI_DEBUG_CONTINUE - formal return value
693 IN CHAR16
*CommandArg
,
694 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
695 IN EFI_EXCEPTION_TYPE ExceptionType
,
696 IN OUT EFI_SYSTEM_CONTEXT SystemContext
707 // Check the argument
709 if (CommandArg
== NULL
) {
710 EDBPrint (L
"CodeFile not found!\n");
711 return EFI_DEBUG_CONTINUE
;
714 CommandArg2
= StrGetNextTokenLine (L
" ");
715 if (CommandArg2
== NULL
) {
716 EDBPrint (L
"SymbolFile not found!\n");
717 return EFI_DEBUG_CONTINUE
;
720 if (StrLen (CommandArg
) <= 4) {
721 EDBPrint (L
"CodeFile name error!\n");
722 return EFI_DEBUG_CONTINUE
;
725 if (StriCmp (CommandArg
+ (StrLen (CommandArg
) - 4), L
".cod") != 0) {
726 EDBPrint (L
"CodeFile name error!\n");
727 return EFI_DEBUG_CONTINUE
;
730 if (StrLen (CommandArg2
) <= 4) {
731 EDBPrint (L
"SymbolFile name error!\n");
732 return EFI_DEBUG_CONTINUE
;
735 if (StriCmp (CommandArg2
+ (StrLen (CommandArg2
) - 4), L
".map") != 0) {
736 EDBPrint (L
"SymbolFile name error!\n");
737 return EFI_DEBUG_CONTINUE
;
741 // read cod file to memory
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
;
749 FileName
= GetFileNameFromFullPath (CommandArg
);
750 MapFileName
= GetFileNameFromFullPath (CommandArg2
);
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
;
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
;
774 return EFI_DEBUG_CONTINUE
;
779 DebuggerCommand - UnloadCode.
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.
786 @retval EFI_DEBUG_CONTINUE - formal return value
791 IN CHAR16
*CommandArg
,
792 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
793 IN EFI_EXCEPTION_TYPE ExceptionType
,
794 IN OUT EFI_SYSTEM_CONTEXT SystemContext
804 // Check the argument
806 if (CommandArg
== NULL
) {
807 EDBPrint (L
"CodeFile not found!\n");
808 return EFI_DEBUG_CONTINUE
;
811 CommandArg2
= StrGetNextTokenLine (L
" ");
812 if (CommandArg2
== NULL
) {
813 EDBPrint (L
"SymbolFile not found!\n");
814 return EFI_DEBUG_CONTINUE
;
817 FileName
= GetFileNameFromFullPath (CommandArg
);
818 MapFileName
= GetFileNameFromFullPath (CommandArg2
);
823 Status
= EdbUnloadCode (DebuggerPrivate
, MapFileName
, FileName
, &BufferPtr
);
824 if (EFI_ERROR (Status
)) {
825 EDBPrint (L
"UnloadCode error!\n");
826 return EFI_DEBUG_CONTINUE
;
830 // Delete Code buffer
832 Status
= EdbDeleteCodeBuffer (DebuggerPrivate
, MapFileName
, FileName
, BufferPtr
);
833 if (EFI_ERROR (Status
)) {
834 EDBPrint (L
"DeleteCodeBuffer error!\n");
840 return EFI_DEBUG_CONTINUE
;
845 DebuggerCommand - DisplayCode.
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.
852 @retval EFI_DEBUG_CONTINUE - formal return value
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
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
);
873 EDBPrint (L
"DisplayCode - argument error\n");
876 return EFI_DEBUG_CONTINUE
;