From: andrewfish Date: Fri, 19 Feb 2010 23:49:51 +0000 (+0000) Subject: Adding a command to show how symbols work in EFI X-Git-Tag: edk2-stable201903~16307 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=b2a73e21621d6d96194fc44d871da92bb85ec885 Adding a command to show how symbols work in EFI git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10029 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/BeagleBoardPkg/Library/EblCmdLib/EblCmdLib.c b/BeagleBoardPkg/Library/EblCmdLib/EblCmdLib.c index c69b28904b..01d7984193 100644 --- a/BeagleBoardPkg/Library/EblCmdLib/EblCmdLib.c +++ b/BeagleBoardPkg/Library/EblCmdLib/EblCmdLib.c @@ -1,7 +1,7 @@ /** @file Add custom commands for BeagleBoard development. - Copyright (c) 2008-2009, Apple Inc. All rights reserved. + Copyright (c) 2008-2010, Apple Inc. All rights reserved. All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -26,13 +26,81 @@ #include #include #include +#include -//PcdEmbeddedFdBaseAddress +#include +#include +#include /** - Fill Me In + Simple arm disassembler via a library - Argv[0] - "%CommandName%" + Argv[0] - symboltable + Argv[1] - Optional qoted format string + Argv[2] - Optional flag + + @param Argc Number of command arguments in Argv + @param Argv Array of strings that represent the parsed command line. + Argv[0] is the comamnd name + + @return EFI_SUCCESS + +**/ +EFI_STATUS +EblSymbolTable ( + IN UINTN Argc, + IN CHAR8 **Argv + ) +{ + EFI_STATUS Status; + EFI_DEBUG_IMAGE_INFO_TABLE_HEADER *DebugImageTableHeader = NULL; + EFI_DEBUG_IMAGE_INFO *DebugTable; + UINTN Entry; + CHAR8 *Format; + CHAR8 *Pdb; + UINT32 PeCoffSizeOfHeaders; + UINT32 ImageBase; + BOOLEAN Elf; + + // Need to add lots of error checking on the passed in string + Format = (Argc > 1) ? Argv[1] : "load /a /ni /np %a & 0x%x\n"; + Elf = (Argc > 2) ? FALSE : TRUE; + + Status = EfiGetSystemConfigurationTable (&gEfiDebugImageInfoTableGuid, (VOID **)&DebugImageTableHeader); + if (EFI_ERROR (Status)) { + return Status; + } + + DebugTable = DebugImageTableHeader->EfiDebugImageInfoTable; + if (DebugTable == NULL) { + return EFI_SUCCESS; + } + + for (Entry = 0; Entry < DebugImageTableHeader->TableSize; Entry++, DebugTable++) { + if (DebugTable->NormalImage != NULL) { + if ((DebugTable->NormalImage->ImageInfoType == EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL) && (DebugTable->NormalImage->LoadedImageProtocolInstance != NULL)) { + ImageBase = (UINT32)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase; + PeCoffSizeOfHeaders = PeCoffGetSizeOfHeaders ((VOID *)(UINTN)ImageBase); + Pdb = PeCoffLoaderGetPdbPointer (DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase); + if (Elf) { + // ELF and Mach-O images don't include the header so the linked address does not include header + ImageBase += PeCoffSizeOfHeaders; + } + AsciiPrint (Format, Pdb, ImageBase); + } + } + } + + return EFI_SUCCESS; +} + + +/** + Simple arm disassembler via a library + + Argv[0] - disasm + Argv[1] - Address to start disassembling from + ARgv[2] - Number of instructions to disassembly (optional) @param Argc Number of command arguments in Argv @param Argv Array of strings that represent the parsed command line. @@ -80,6 +148,12 @@ GLOBAL_REMOVE_IF_UNREFERENCED const EBL_COMMAND_TABLE mLibCmdTemplate[] = " disassemble count instructions", NULL, EblDisassembler + }, + { + "symboltable [\"format string\"] [TRUE]", + " show symbol table commands for debugger", + NULL, + EblSymbolTable } }; diff --git a/BeagleBoardPkg/Library/EblCmdLib/EblCmdLib.inf b/BeagleBoardPkg/Library/EblCmdLib/EblCmdLib.inf index 3590351517..9273aa92e4 100644 --- a/BeagleBoardPkg/Library/EblCmdLib/EblCmdLib.inf +++ b/BeagleBoardPkg/Library/EblCmdLib/EblCmdLib.inf @@ -43,7 +43,9 @@ ArmDisassemblerLib [Protocols] + gEfiDebugSupportProtocolGuid + gEfiLoadedImageProtocolGuid [Guids] + gEfiDebugImageInfoTableGuid -[Pcd]