From e7fe794c4d6ca0dc6c8ebb732daa1f132cd9c365 Mon Sep 17 00:00:00 2001 From: jief666 Date: Mon, 14 Sep 2020 15:56:48 +0300 Subject: [PATCH] Generate debug symbol with Xcode8 Quick patch to make DumpEfiCalls works with OpenCore. --- BaseTools/Conf/build_rule.template | 2 +- BaseTools/Conf/tools_def.template | 10 +++++----- Protocols/DumpUefiCalls/DumpUefiCalls.c | 23 +++++++++++++++++++++++ Protocols/DumpUefiCalls/DumpUefiCalls.dsc | 2 ++ Protocols/DumpUefiCalls/FileLib.c | 11 +++++++++-- Protocols/DumpUefiCalls/build.sh | 8 ++++---- 6 files changed, 44 insertions(+), 12 deletions(-) diff --git a/BaseTools/Conf/build_rule.template b/BaseTools/Conf/build_rule.template index da7af7e9c..6b339e5f9 100644 --- a/BaseTools/Conf/build_rule.template +++ b/BaseTools/Conf/build_rule.template @@ -425,7 +425,7 @@ @"$(MTOC)" -subsystem $(MODULE_TYPE) $(MTOC_FLAGS) ${src} $(DEBUG_DIR)(+)$(MODULE_NAME).pecoff @"echo" [MTOC] $(MODULE_NAME) # create symbol file for GDB debug - #@-$(DSYMUTIL) ${src} + @-$(DSYMUTIL) ${src} @"$(GENFW)" -e $(MODULE_TYPE) -o ${dst} $(DEBUG_DIR)(+)$(MODULE_NAME).pecoff $(GENFW_FLAGS) @$(CP) ${dst} $(DEBUG_DIR) @$(CP) ${dst} $(BIN_DIR)(+)$(MODULE_NAME_GUID).efi diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template index 206ca4b6b..7fb6de528 100644 --- a/BaseTools/Conf/tools_def.template +++ b/BaseTools/Conf/tools_def.template @@ -2503,19 +2503,19 @@ RELEASE_XCODE5_X64_ASM_FLAGS = -arch x86_64 *_XCODE5_*_VFRPP_FLAGS = -x c -E -P -DVFRCOMPILE -include $(DEST_DIR_DEBUG)/$(MODULE_NAME)StrDefs.h - DEBUG_XCODE5_X64_CC_FLAGS = -target x86_64-pc-win32-macho -c -g -Os -Wall -Werror -Wextra -include AutoGen.h -funsigned-char -fno-ms-extensions -fno-stack-protector -fno-builtin -fshort-wchar -mms-bitfields -Wno-unused-parameter -Wno-missing-braces -Wno-missing-field-initializers -Wno-tautological-compare -Wno-sign-compare -DNO_MSABI_VA_FUNCS + DEBUG_XCODE5_X64_CC_FLAGS = -target x86_64-pc-win32-macho -c -g -gdwarf -O0 -Wall -Werror -Wextra -include AutoGen.h -funsigned-char -fno-ms-extensions -fno-stack-protector -fno-builtin -fshort-wchar -mms-bitfields -Wno-unused-parameter -Wno-missing-braces -Wno-missing-field-initializers -Wno-tautological-compare -Wno-sign-compare -DNO_MSABI_VA_FUNCS # -mno-implicit-float # -Wno-varargs # -ftrap-function=undefined_behavior_has_been_optimized_away_by_clang # $(PLATFORM_FLAGS) - NOOPT_XCODE5_X64_CC_FLAGS = -target x86_64-pc-win32-macho -c -g -O0 -Wall -Werror -Wextra -include AutoGen.h -funsigned-char -fno-ms-extensions -fno-stack-protector -fno-builtin -fshort-wchar -mms-bitfields -Wno-unused-parameter -Wno-missing-braces -Wno-missing-field-initializers -Wno-tautological-compare -Wno-sign-compare -DNO_MSABI_VA_FUNCS + NOOPT_XCODE5_X64_CC_FLAGS = -target x86_64-pc-win32-macho -c -g -gdwarf -O0 -Wall -Werror -Wextra -include AutoGen.h -funsigned-char -fno-ms-extensions -fno-stack-protector -fno-builtin -fshort-wchar -mms-bitfields -Wno-unused-parameter -Wno-missing-braces -Wno-missing-field-initializers -Wno-tautological-compare -Wno-sign-compare -DNO_MSABI_VA_FUNCS # -mno-implicit-float # -Wno-varargs # -ftrap-function=undefined_behavior_has_been_optimized_away_by_clang # $(PLATFORM_FLAGS) -RELEASE_XCODE5_X64_CC_FLAGS = -target x86_64-pc-win32-macho -c -Os -Wall -Werror -Wextra -include AutoGen.h -funsigned-char -fno-ms-extensions -fno-stack-protector -fno-builtin -fshort-wchar -mms-bitfields -Wno-unused-parameter -Wno-missing-braces -Wno-missing-field-initializers -Wno-tautological-compare -Wno-sign-compare -DNO_MSABI_VA_FUNCS +RELEASE_XCODE5_X64_CC_FLAGS = -target x86_64-pc-win32-macho -c -Os -Wall -Werror -Wextra -include AutoGen.h -funsigned-char -fno-ms-extensions -fno-stack-protector -fno-builtin -fshort-wchar -mms-bitfields -Wno-unused-parameter -Wno-missing-braces -Wno-missing-field-initializers -Wno-tautological-compare -Wno-sign-compare -DNO_MSABI_VA_FUNCS # -mno-implicit-float # -Wno-varargs # -Wno-unused-const-variable @@ -2577,10 +2577,10 @@ RELEASE_XCODE8_X64_ASM_FLAGS = -c -x assembler -arch x86_64 *_XCODE8_*_PP_FLAGS = DEF(GCC_PP_FLAGS) *_XCODE8_*_VFRPP_FLAGS = -x c -E -P -DVFRCOMPILE -include $(DEST_DIR_DEBUG)/$(MODULE_NAME)StrDefs.h - DEBUG_XCODE8_X64_CC_FLAGS = -target x86_64-pc-win32-macho -c -g -Os -Wall -Werror -Wextra -include AutoGen.h -funsigned-char -fno-ms-extensions -fno-stack-protector -fno-builtin -fshort-wchar -mms-bitfields -Wno-unused-parameter -Wno-missing-braces -Wno-missing-field-initializers -Wno-tautological-compare -Wno-sign-compare "-DNO_MSABI_VA_FUNCS" -mno-red-zone + DEBUG_XCODE8_X64_CC_FLAGS = -target x86_64-pc-win32-macho -c -g -gdwarf -O0 -Wall -Werror -Wextra -include AutoGen.h -funsigned-char -fno-ms-extensions -fno-stack-protector -fno-builtin -fshort-wchar -mms-bitfields -Wno-unused-parameter -Wno-missing-braces -Wno-missing-field-initializers -Wno-tautological-compare -Wno-sign-compare "-DNO_MSABI_VA_FUNCS" -mno-red-zone # -Wno-varargs # -mno-implicit-float -RELEASE_XCODE8_X64_CC_FLAGS = -target x86_64-pc-win32-macho -c -Os -Wall -Werror -Wextra -include AutoGen.h -funsigned-char -fno-ms-extensions -fno-stack-protector -fno-builtin -fshort-wchar -mms-bitfields -Wno-unused-parameter -Wno-missing-braces -Wno-missing-field-initializers -Wno-tautological-compare -Wno-sign-compare "-DNO_MSABI_VA_FUNCS" -mno-red-zone +RELEASE_XCODE8_X64_CC_FLAGS = -target x86_64-pc-win32-macho -c -Os -Wall -Werror -Wextra -include AutoGen.h -funsigned-char -fno-ms-extensions -fno-stack-protector -fno-builtin -fshort-wchar -mms-bitfields -Wno-unused-parameter -Wno-missing-braces -Wno-missing-field-initializers -Wno-tautological-compare -Wno-sign-compare "-DNO_MSABI_VA_FUNCS" -mno-red-zone # -mno-implicit-float # -Wno-varargs # -Wno-unused-const-variable diff --git a/Protocols/DumpUefiCalls/DumpUefiCalls.c b/Protocols/DumpUefiCalls/DumpUefiCalls.c index 08e45c45e..e922b3d2e 100644 --- a/Protocols/DumpUefiCalls/DumpUefiCalls.c +++ b/Protocols/DumpUefiCalls/DumpUefiCalls.c @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include //#include @@ -136,6 +138,27 @@ DumpUefiCallsEntrypoint ( IN EFI_SYSTEM_TABLE *SystemTable ) { + +#ifdef JIEF_DEBUG + { + EFI_LOADED_IMAGE* LoadedImage; + EFI_STATUS Status = gBS->HandleProtocol(ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &LoadedImage); + + if ( !EFI_ERROR(Status) ) { + CHAR8 buf[50]; + AsciiSPrint(buf, sizeof(buf)-1, "DumpEfiCalls : Image base = 0x%X\n", (UINTN)LoadedImage->ImageBase); // do not change, it's used by grep to feed the debugger + SerialPortWrite((UINT8*)buf, AsciiStrLen(buf)); + AsciiSPrint(buf, sizeof(buf)-1, "LoadedImage.DeviceHandle = 0x%X\n", (UINTN)LoadedImage->DeviceHandle); // do not change, it's used by grep to feed the debugger + SerialPortWrite((UINT8*)buf, AsciiStrLen(buf)); + } +// if ( !EFI_ERROR(Status) ) DBG("DumpEfiCalls : Image base = 0x%llX\n", (uintptr_t)LoadedImage->ImageBase); // do not change, it's used by grep to feed the debugger + + gBS->Stall(3500000); // to give time to gdb to connect +// gBS->Stall(0500000); // to give time to gdb to connect +// PauseForKey(L"press\n"); + } +#endif + // // Override StartImage // other overrides will be done from there when boot loader is started diff --git a/Protocols/DumpUefiCalls/DumpUefiCalls.dsc b/Protocols/DumpUefiCalls/DumpUefiCalls.dsc index 2454e3d87..bd5c3735a 100644 --- a/Protocols/DumpUefiCalls/DumpUefiCalls.dsc +++ b/Protocols/DumpUefiCalls/DumpUefiCalls.dsc @@ -41,6 +41,8 @@ UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf UefiLib|MdePkg/Library/UefiLib/UefiLib.inf UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf + PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf + PciCf8Lib|MdePkg/Library/BasePciCf8Lib/BasePciCf8Lib.inf [Components] Protocols/DumpUefiCalls/DumpUefiCalls.inf diff --git a/Protocols/DumpUefiCalls/FileLib.c b/Protocols/DumpUefiCalls/FileLib.c index 3b2ad6ae6..b41d9dc5e 100644 --- a/Protocols/DumpUefiCalls/FileLib.c +++ b/Protocols/DumpUefiCalls/FileLib.c @@ -81,8 +81,15 @@ FsGetSelfFileSystem(VOID) if (gLoadedImage == NULL) { return NULL; } - - return FsGetFileSystem(gLoadedImage->DeviceHandle); + if( gLoadedImage->DeviceHandle != NULL ) return FsGetFileSystem(gLoadedImage->DeviceHandle); + + EFI_STATUS Status = gBS->HandleProtocol(gLoadedImage->ParentHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &gLoadedImage); + if (Status != EFI_SUCCESS) { + Print(L"FsGetLoadedImage: HandleProtocol(gEfiLoadedImageProtocolGuid) = %r\n", Status); + return NULL; + } + + return FsGetFileSystem(gLoadedImage->DeviceHandle); } /** Returns root dir from given file system. */ diff --git a/Protocols/DumpUefiCalls/build.sh b/Protocols/DumpUefiCalls/build.sh index 5a592e6f0..876decbac 100644 --- a/Protocols/DumpUefiCalls/build.sh +++ b/Protocols/DumpUefiCalls/build.sh @@ -53,7 +53,7 @@ case `uname` in echo DumpUefiCalls requires Snow Leopard or later OS exit 1 else - TARGET_TOOLS=XCODE5 + TARGET_TOOLS=XCODE8 fi ;; Linux*) @@ -80,12 +80,12 @@ do if [[ $arg == cleanall ]]; then make -C $WORKSPACE/BaseTools clean - build -p $WORKSPACE/Clover/DumpUefiCalls/DumpUefiCalls.dsc -a $PROCESSOR -t $TARGET_TOOLS -n 3 clean + build -p $WORKSPACE/Protocols/DumpUefiCalls/DumpUefiCalls.dsc -a $PROCESSOR -t $TARGET_TOOLS -n 3 clean exit $? fi if [[ $arg == clean ]]; then - build -p $WORKSPACE/Clover/DumpUefiCalls/DumpUefiCalls.dsc -a $PROCESSOR -t $TARGET_TOOLS -n 3 clean + build -p $WORKSPACE/Protocols/DumpUefiCalls/DumpUefiCalls.dsc -a $PROCESSOR -t $TARGET_TOOLS -n 3 clean exit $? fi done @@ -95,6 +95,6 @@ done # Build the edk2 ShellPkg # echo Running edk2 build for DumpUefiCalls -build -p $WORKSPACE/Clover/DumpUefiCalls/DumpUefiCalls.dsc -a $PROCESSOR -t $TARGET_TOOLS -n 3 +build -p $WORKSPACE/Protocols/DumpUefiCalls/DumpUefiCalls.dsc -a $PROCESSOR -t $TARGET_TOOLS -b DEBUG -n 3 exit $?