public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 1/2] BaseTools/tools_def AARCH64: enable frame pointers for DEBUG builds
@ 2016-09-07  8:21 Ard Biesheuvel
  2016-09-07  8:21 ` [PATCH 2/2] ArmPkg/DefaultExceptionHandlerLib AARCH64: add minimal backtrace to crash dump Ard Biesheuvel
  2016-09-07 15:00 ` [PATCH 1/2] BaseTools/tools_def AARCH64: enable frame pointers for DEBUG builds Leif Lindholm
  0 siblings, 2 replies; 10+ messages in thread
From: Ard Biesheuvel @ 2016-09-07  8:21 UTC (permalink / raw)
  To: edk2-devel, leif.lindholm; +Cc: Ard Biesheuvel

Enable frame pointers on DEBUG builds so we can support backtraces in
crash dumps.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 BaseTools/Conf/tools_def.template | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template
index d8e3e3dc13b9..5414454ec7e3 100755
--- a/BaseTools/Conf/tools_def.template
+++ b/BaseTools/Conf/tools_def.template
@@ -4342,7 +4342,7 @@ DEFINE GCC_X64_CC_FLAGS            = DEF(GCC_ALL_CC_FLAGS) -mno-red-zone -Wno-ad
 DEFINE GCC_IPF_CC_FLAGS            = DEF(GCC_ALL_CC_FLAGS) -minline-int-divide-min-latency
 DEFINE GCC_ARM_CC_FLAGS            = DEF(GCC_ALL_CC_FLAGS) -mlittle-endian -mabi=aapcs -fno-short-enums -funsigned-char -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-builtin -Wno-address -mthumb -mfloat-abi=soft
 DEFINE GCC_ARM_CC_XIPFLAGS         = -mno-unaligned-access
-DEFINE GCC_AARCH64_CC_FLAGS        = DEF(GCC_ALL_CC_FLAGS) -mlittle-endian -fno-short-enums -fverbose-asm -funsigned-char  -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-builtin -Wno-address -fno-asynchronous-unwind-tables
+DEFINE GCC_AARCH64_CC_FLAGS        = DEF(GCC_ALL_CC_FLAGS) -mlittle-endian -fno-short-enums -fverbose-asm -funsigned-char  -ffunction-sections -fdata-sections -fno-builtin -Wno-address -fno-asynchronous-unwind-tables
 DEFINE GCC_AARCH64_CC_XIPFLAGS     = -mstrict-align
 DEFINE GCC_DLINK_FLAGS_COMMON      = -nostdlib --pie
 DEFINE GCC_DLINK2_FLAGS_COMMON     = -Wl,--script=$(EDK_TOOLS_PATH)/Scripts/GccBase.lds
@@ -4960,7 +4960,7 @@ RELEASE_GCC47_ARM_CC_FLAGS       = DEF(GCC47_ARM_CC_FLAGS) -Wno-unused-but-set-v
 *_GCC47_AARCH64_CC_XIPFLAGS      = DEF(GCC47_AARCH64_CC_XIPFLAGS)
 
   DEBUG_GCC47_AARCH64_CC_FLAGS   = DEF(GCC47_AARCH64_CC_FLAGS) -O0
-RELEASE_GCC47_AARCH64_CC_FLAGS   = DEF(GCC47_AARCH64_CC_FLAGS) -Wno-unused-but-set-variable
+RELEASE_GCC47_AARCH64_CC_FLAGS   = DEF(GCC47_AARCH64_CC_FLAGS) -Wno-unused-but-set-variable -fomit-frame-pointer
 
 ####################################################################################
 #
@@ -5093,7 +5093,7 @@ RELEASE_GCC48_ARM_CC_FLAGS       = DEF(GCC48_ARM_CC_FLAGS) -Wno-unused-but-set-v
 *_GCC48_AARCH64_CC_XIPFLAGS      = DEF(GCC48_AARCH64_CC_XIPFLAGS)
 
   DEBUG_GCC48_AARCH64_CC_FLAGS   = DEF(GCC48_AARCH64_CC_FLAGS) -O0
-RELEASE_GCC48_AARCH64_CC_FLAGS   = DEF(GCC48_AARCH64_CC_FLAGS) -Wno-unused-but-set-variable
+RELEASE_GCC48_AARCH64_CC_FLAGS   = DEF(GCC48_AARCH64_CC_FLAGS) -Wno-unused-but-set-variable -fomit-frame-pointer
 
 ####################################################################################
 #
@@ -5228,7 +5228,7 @@ RELEASE_GCC49_ARM_CC_FLAGS       = DEF(GCC49_ARM_CC_FLAGS) -Wno-unused-but-set-v
   DEBUG_GCC49_AARCH64_DLINK_FLAGS  = DEF(GCC49_AARCH64_DLINK_FLAGS) -z common-page-size=0x1000
   DEBUG_GCC49_AARCH64_DLINK_XIPFLAGS = -z common-page-size=0x20
 
-RELEASE_GCC49_AARCH64_CC_FLAGS     = DEF(GCC49_AARCH64_CC_FLAGS) -Wno-unused-but-set-variable -mcmodel=tiny
+RELEASE_GCC49_AARCH64_CC_FLAGS     = DEF(GCC49_AARCH64_CC_FLAGS) -Wno-unused-but-set-variable -mcmodel=tiny -fomit-frame-pointer
 RELEASE_GCC49_AARCH64_DLINK_FLAGS  = DEF(GCC49_AARCH64_DLINK_FLAGS)
 
 ####################################################################################
@@ -5364,7 +5364,7 @@ RELEASE_GCC5_ARM_DLINK_FLAGS     = DEF(GCC5_ARM_DLINK_FLAGS) -flto -Os -L$(WORKS
   DEBUG_GCC5_AARCH64_DLINK_FLAGS = DEF(GCC5_AARCH64_DLINK_FLAGS) -z common-page-size=0x1000
   DEBUG_GCC5_AARCH64_DLINK_XIPFLAGS = -z common-page-size=0x20
 
-RELEASE_GCC5_AARCH64_CC_FLAGS    = DEF(GCC5_AARCH64_CC_FLAGS) -flto -Wno-unused-but-set-variable -mcmodel=tiny
+RELEASE_GCC5_AARCH64_CC_FLAGS    = DEF(GCC5_AARCH64_CC_FLAGS) -flto -Wno-unused-but-set-variable -mcmodel=tiny -fomit-frame-pointer
 RELEASE_GCC5_AARCH64_DLINK_FLAGS = DEF(GCC5_AARCH64_DLINK_FLAGS) -flto -Os -L$(WORKSPACE)/ArmPkg/Library/GccLto -llto-aarch64 -Wl,-plugin-opt=-pass-through=-llto-aarch64
 
 ####################################################################################
@@ -5443,7 +5443,7 @@ RELEASE_CLANG35_ARM_CC_FLAGS     = DEF(CLANG35_ARM_CC_FLAGS) $(ARCHCC_FLAGS) $(P
 *_CLANG35_AARCH64_CC_XIPFLAGS    = DEF(GCC_AARCH64_CC_XIPFLAGS)
 
   DEBUG_CLANG35_AARCH64_CC_FLAGS = DEF(CLANG35_AARCH64_CC_FLAGS) $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) -O0
-RELEASE_CLANG35_AARCH64_CC_FLAGS = DEF(CLANG35_AARCH64_CC_FLAGS) $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) -Oz
+RELEASE_CLANG35_AARCH64_CC_FLAGS = DEF(CLANG35_AARCH64_CC_FLAGS) $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) -Oz -fomit-frame-pointer
 
 ####################################################################################
 #
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/2] ArmPkg/DefaultExceptionHandlerLib AARCH64: add minimal backtrace to crash dump
  2016-09-07  8:21 [PATCH 1/2] BaseTools/tools_def AARCH64: enable frame pointers for DEBUG builds Ard Biesheuvel
@ 2016-09-07  8:21 ` Ard Biesheuvel
  2016-09-07  9:48   ` Michael Zimmermann
  2016-09-09 16:03   ` Andrew Fish
  2016-09-07 15:00 ` [PATCH 1/2] BaseTools/tools_def AARCH64: enable frame pointers for DEBUG builds Leif Lindholm
  1 sibling, 2 replies; 10+ messages in thread
From: Ard Biesheuvel @ 2016-09-07  8:21 UTC (permalink / raw)
  To: edk2-devel, leif.lindholm; +Cc: Ard Biesheuvel

When dumping the CPU state after an unhandled fault, walk the stack
frames and decode the return addresses so we can show a minimal
backtrace. Unfortunately, we do not have sufficient information to
show the function names, but at least we can see the modules and the
return addresses inside the modules.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---

Example output:

Synchronous Exception at 0x00000000F5EA4C8C
/home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG/ArmVeNorFlashDxe.dll loaded at 0x00000000F5E90000
called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG/ArmVeNorFlashDxe.dll (0x00000000F5EA4AE8) loaded at 0x00000000F5E90000
called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG/ArmVeNorFlashDxe.dll (0x00000000F5EA1BFC) loaded at 0x00000000F5E90000
called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG/ArmVeNorFlashDxe.dll (0x00000000F5EA23F4) loaded at 0x00000000F5E90000
called from /work/jenkins/workspace/ap-uefi-bin/EDK2_ARCH/ARM/EDK2_BINARY/FatPkg/label/sas-sw/Build/Fat/RELEASE_GCC49/AARCH64/FatPkg/EnhancedFatDxe/Fat/DEBUG/Fat.dll (0x00000000FADC454C) loaded at 0x00000000FADC3000
called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll (0x00000000FE47C868) loaded at 0x00000000FE471000
called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll (0x00000000FAE2C50C) loaded at 0x00000000FAE01000
called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll (0x00000000FAE2C674) loaded at 0x00000000FAE01000
called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll (0x00000000FAE2C264) loaded at 0x00000000FAE01000
called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll (0x00000000FAE36998) loaded at 0x00000000FAE01000
called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll (0x00000000FAE03668) loaded at 0x00000000FAE01000
called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll (0x00000000FE4733F0) loaded at 0x00000000FE471000
called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll (0x00000000FE4724A0) loaded at 0x00000000FE471000
called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll (0x00000000FE472024) loaded at 0x00000000FE471000
---
 .../AArch64/DefaultExceptionHandler.c               | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c b/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c
index 31fc936b21ff..84b442f2b6f4 100644
--- a/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c
+++ b/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c
@@ -152,9 +152,30 @@ DefaultExceptionHandler (
     CHAR8  *Pdb;
     UINTN  ImageBase;
     UINTN  PeCoffSizeOfHeader;
+    UINT64 *Fp;
+
     Pdb = GetImageName (SystemContext.SystemContextAArch64->ELR, &ImageBase, &PeCoffSizeOfHeader);
     if (Pdb != NULL) {
       DEBUG ((EFI_D_ERROR, "%a loaded at 0x%016lx \n", Pdb, ImageBase));
+
+      Pdb = GetImageName (SystemContext.SystemContextAArch64->LR, &ImageBase,
+              &PeCoffSizeOfHeader);
+      if (Pdb != NULL) {
+        DEBUG ((EFI_D_ERROR, "called from %a (0x%016lx) loaded at 0x%016lx \n",
+          Pdb, SystemContext.SystemContextAArch64->LR, ImageBase));
+      }
+      for (Fp = (UINT64 *)SystemContext.SystemContextAArch64->FP;
+           *Fp != 0;
+           Fp = (UINT64 *)Fp[0]) {
+        if (Fp[1] == SystemContext.SystemContextAArch64->LR) {
+         continue;
+        }
+        Pdb = GetImageName (Fp[1], &ImageBase, &PeCoffSizeOfHeader);
+        if (Pdb != NULL) {
+          DEBUG ((EFI_D_ERROR, "called from %a (0x%016lx) loaded at 0x%016lx \n",
+            Pdb, Fp[1], ImageBase));
+        }
+      }
     }
   DEBUG_CODE_END ();
 
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] ArmPkg/DefaultExceptionHandlerLib AARCH64: add minimal backtrace to crash dump
  2016-09-07  8:21 ` [PATCH 2/2] ArmPkg/DefaultExceptionHandlerLib AARCH64: add minimal backtrace to crash dump Ard Biesheuvel
@ 2016-09-07  9:48   ` Michael Zimmermann
  2016-09-07 11:03     ` Ard Biesheuvel
  2016-09-09 16:03   ` Andrew Fish
  1 sibling, 1 reply; 10+ messages in thread
From: Michael Zimmermann @ 2016-09-07  9:48 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: edk2-devel@lists.01.org, Leif Lindholm

nice, can we do this for ARM too? I usually need to add DEBUG((...))'s all
over the place for hours until I found the reason for a fault.

Thanks
Michael

On Wed, Sep 7, 2016 at 10:21 AM, Ard Biesheuvel <ard.biesheuvel@linaro.org>
wrote:

> When dumping the CPU state after an unhandled fault, walk the stack
> frames and decode the return addresses so we can show a minimal
> backtrace. Unfortunately, we do not have sufficient information to
> show the function names, but at least we can see the modules and the
> return addresses inside the modules.
>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
>
> Example output:
>
> Synchronous Exception at 0x00000000F5EA4C8C
> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_
> GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG/ArmVeNorFlashDxe.dll
> loaded at 0x00000000F5E90000
> called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_
> GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG/ArmVeNorFlashDxe.dll
> (0x00000000F5EA4AE8) loaded at 0x00000000F5E90000
> called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_
> GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG/ArmVeNorFlashDxe.dll
> (0x00000000F5EA1BFC) loaded at 0x00000000F5E90000
> called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_
> GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG/ArmVeNorFlashDxe.dll
> (0x00000000F5EA23F4) loaded at 0x00000000F5E90000
> called from /work/jenkins/workspace/ap-uefi-bin/EDK2_ARCH/ARM/EDK2_
> BINARY/FatPkg/label/sas-sw/Build/Fat/RELEASE_GCC49/
> AARCH64/FatPkg/EnhancedFatDxe/Fat/DEBUG/Fat.dll (0x00000000FADC454C)
> loaded at 0x00000000FADC3000
> called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_
> GCC5/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll
> (0x00000000FE47C868) loaded at 0x00000000FE471000
> called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_
> GCC5/AARCH64/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll
> (0x00000000FAE2C50C) loaded at 0x00000000FAE01000
> called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_
> GCC5/AARCH64/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll
> (0x00000000FAE2C674) loaded at 0x00000000FAE01000
> called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_
> GCC5/AARCH64/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll
> (0x00000000FAE2C264) loaded at 0x00000000FAE01000
> called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_
> GCC5/AARCH64/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll
> (0x00000000FAE36998) loaded at 0x00000000FAE01000
> called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_
> GCC5/AARCH64/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll
> (0x00000000FAE03668) loaded at 0x00000000FAE01000
> called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_
> GCC5/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll
> (0x00000000FE4733F0) loaded at 0x00000000FE471000
> called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_
> GCC5/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll
> (0x00000000FE4724A0) loaded at 0x00000000FE471000
> called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_
> GCC5/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll
> (0x00000000FE472024) loaded at 0x00000000FE471000
> ---
>  .../AArch64/DefaultExceptionHandler.c               | 21
> +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
>
> diff --git a/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c
> b/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/
> DefaultExceptionHandler.c
> index 31fc936b21ff..84b442f2b6f4 100644
> --- a/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/
> DefaultExceptionHandler.c
> +++ b/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/
> DefaultExceptionHandler.c
> @@ -152,9 +152,30 @@ DefaultExceptionHandler (
>      CHAR8  *Pdb;
>      UINTN  ImageBase;
>      UINTN  PeCoffSizeOfHeader;
> +    UINT64 *Fp;
> +
>      Pdb = GetImageName (SystemContext.SystemContextAArch64->ELR,
> &ImageBase, &PeCoffSizeOfHeader);
>      if (Pdb != NULL) {
>        DEBUG ((EFI_D_ERROR, "%a loaded at 0x%016lx \n", Pdb, ImageBase));
> +
> +      Pdb = GetImageName (SystemContext.SystemContextAArch64->LR,
> &ImageBase,
> +              &PeCoffSizeOfHeader);
> +      if (Pdb != NULL) {
> +        DEBUG ((EFI_D_ERROR, "called from %a (0x%016lx) loaded at
> 0x%016lx \n",
> +          Pdb, SystemContext.SystemContextAArch64->LR, ImageBase));
> +      }
> +      for (Fp = (UINT64 *)SystemContext.SystemContextAArch64->FP;
> +           *Fp != 0;
> +           Fp = (UINT64 *)Fp[0]) {
> +        if (Fp[1] == SystemContext.SystemContextAArch64->LR) {
> +         continue;
> +        }
> +        Pdb = GetImageName (Fp[1], &ImageBase, &PeCoffSizeOfHeader);
> +        if (Pdb != NULL) {
> +          DEBUG ((EFI_D_ERROR, "called from %a (0x%016lx) loaded at
> 0x%016lx \n",
> +            Pdb, Fp[1], ImageBase));
> +        }
> +      }
>      }
>    DEBUG_CODE_END ();
>
> --
> 2.7.4
>
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] ArmPkg/DefaultExceptionHandlerLib AARCH64: add minimal backtrace to crash dump
  2016-09-07  9:48   ` Michael Zimmermann
@ 2016-09-07 11:03     ` Ard Biesheuvel
  2016-09-07 11:25       ` Michael Zimmermann
  0 siblings, 1 reply; 10+ messages in thread
From: Ard Biesheuvel @ 2016-09-07 11:03 UTC (permalink / raw)
  To: Michael Zimmermann; +Cc: edk2-devel@lists.01.org, Leif Lindholm

On 7 September 2016 at 10:48, Michael Zimmermann
<sigmaepsilon92@gmail.com> wrote:
> nice, can we do this for ARM too? I usually need to add DEBUG((...))'s all
> over the place for hours until I found the reason for a fault.
>

This is going to be tricky. Unlike AARCH64, which unambiguously
describes in the AAPCS how to link the stack frames using x29, the
AAPCS for ARM does not standardise this, and so different compilers
may do different things, also depending on whether you are executing
in ARM or Thumb mode. For instance, the following prologue was snipped
from a BdsDxe.dll build using GCC5 in Thumb2 mode.

00000254 <_ModuleEntryPoint>:
     254:       e96d 7e02       strd    r7, lr, [sp, #-8]!
     258:       b084            sub     sp, #16
     25a:       af00            add     r7, sp, #0

Googling around, i can indeed find sources that describe how GCC uses
r7 as the frame pointer for Thumb2 code. However, looking at this
code, this is still not sufficient to find the *next* frame pointer on
the stack. IOW, there is no standardised layout to find the next frame
pointer inside the stack frame.

The only way to do this reliably is using unwind tables, but this is
*much* more complicated than the 20 line patch that enables it for
AArch64

Ard.


> On Wed, Sep 7, 2016 at 10:21 AM, Ard Biesheuvel <ard.biesheuvel@linaro.org>
> wrote:
>>
>> When dumping the CPU state after an unhandled fault, walk the stack
>> frames and decode the return addresses so we can show a minimal
>> backtrace. Unfortunately, we do not have sufficient information to
>> show the function names, but at least we can see the modules and the
>> return addresses inside the modules.
>>
>> Contributed-under: TianoCore Contribution Agreement 1.0
>> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
>> ---
>>
>> Example output:
>>
>> Synchronous Exception at 0x00000000F5EA4C8C
>>
>> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG/ArmVeNorFlashDxe.dll
>> loaded at 0x00000000F5E90000
>> called from
>> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG/ArmVeNorFlashDxe.dll
>> (0x00000000F5EA4AE8) loaded at 0x00000000F5E90000
>> called from
>> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG/ArmVeNorFlashDxe.dll
>> (0x00000000F5EA1BFC) loaded at 0x00000000F5E90000
>> called from
>> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG/ArmVeNorFlashDxe.dll
>> (0x00000000F5EA23F4) loaded at 0x00000000F5E90000
>> called from
>> /work/jenkins/workspace/ap-uefi-bin/EDK2_ARCH/ARM/EDK2_BINARY/FatPkg/label/sas-sw/Build/Fat/RELEASE_GCC49/AARCH64/FatPkg/EnhancedFatDxe/Fat/DEBUG/Fat.dll
>> (0x00000000FADC454C) loaded at 0x00000000FADC3000
>> called from
>> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll
>> (0x00000000FE47C868) loaded at 0x00000000FE471000
>> called from
>> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll
>> (0x00000000FAE2C50C) loaded at 0x00000000FAE01000
>> called from
>> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll
>> (0x00000000FAE2C674) loaded at 0x00000000FAE01000
>> called from
>> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll
>> (0x00000000FAE2C264) loaded at 0x00000000FAE01000
>> called from
>> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll
>> (0x00000000FAE36998) loaded at 0x00000000FAE01000
>> called from
>> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll
>> (0x00000000FAE03668) loaded at 0x00000000FAE01000
>> called from
>> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll
>> (0x00000000FE4733F0) loaded at 0x00000000FE471000
>> called from
>> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll
>> (0x00000000FE4724A0) loaded at 0x00000000FE471000
>> called from
>> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll
>> (0x00000000FE472024) loaded at 0x00000000FE471000
>> ---
>>  .../AArch64/DefaultExceptionHandler.c               | 21
>> +++++++++++++++++++++
>>  1 file changed, 21 insertions(+)
>>
>> diff --git
>> a/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c
>> b/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c
>> index 31fc936b21ff..84b442f2b6f4 100644
>> ---
>> a/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c
>> +++
>> b/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c
>> @@ -152,9 +152,30 @@ DefaultExceptionHandler (
>>      CHAR8  *Pdb;
>>      UINTN  ImageBase;
>>      UINTN  PeCoffSizeOfHeader;
>> +    UINT64 *Fp;
>> +
>>      Pdb = GetImageName (SystemContext.SystemContextAArch64->ELR,
>> &ImageBase, &PeCoffSizeOfHeader);
>>      if (Pdb != NULL) {
>>        DEBUG ((EFI_D_ERROR, "%a loaded at 0x%016lx \n", Pdb, ImageBase));
>> +
>> +      Pdb = GetImageName (SystemContext.SystemContextAArch64->LR,
>> &ImageBase,
>> +              &PeCoffSizeOfHeader);
>> +      if (Pdb != NULL) {
>> +        DEBUG ((EFI_D_ERROR, "called from %a (0x%016lx) loaded at
>> 0x%016lx \n",
>> +          Pdb, SystemContext.SystemContextAArch64->LR, ImageBase));
>> +      }
>> +      for (Fp = (UINT64 *)SystemContext.SystemContextAArch64->FP;
>> +           *Fp != 0;
>> +           Fp = (UINT64 *)Fp[0]) {
>> +        if (Fp[1] == SystemContext.SystemContextAArch64->LR) {
>> +         continue;
>> +        }
>> +        Pdb = GetImageName (Fp[1], &ImageBase, &PeCoffSizeOfHeader);
>> +        if (Pdb != NULL) {
>> +          DEBUG ((EFI_D_ERROR, "called from %a (0x%016lx) loaded at
>> 0x%016lx \n",
>> +            Pdb, Fp[1], ImageBase));
>> +        }
>> +      }
>>      }
>>    DEBUG_CODE_END ();
>>
>> --
>> 2.7.4
>>
>> _______________________________________________
>> edk2-devel mailing list
>> edk2-devel@lists.01.org
>> https://lists.01.org/mailman/listinfo/edk2-devel
>
>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] ArmPkg/DefaultExceptionHandlerLib AARCH64: add minimal backtrace to crash dump
  2016-09-07 11:03     ` Ard Biesheuvel
@ 2016-09-07 11:25       ` Michael Zimmermann
  2016-09-07 11:32         ` Ard Biesheuvel
  0 siblings, 1 reply; 10+ messages in thread
From: Michael Zimmermann @ 2016-09-07 11:25 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: edk2-devel@lists.01.org, Leif Lindholm

> However, looking at this
> code, this is still not sufficient to find the *next* frame pointer on
> the stack.
are you sure about that? this code looks like it does just that:
https://github.com/torvalds/linux/blob/master/arch/arm/kernel/stacktrace.c

On Wed, Sep 7, 2016 at 1:03 PM, Ard Biesheuvel <ard.biesheuvel@linaro.org>
wrote:

> On 7 September 2016 at 10:48, Michael Zimmermann
> <sigmaepsilon92@gmail.com> wrote:
> > nice, can we do this for ARM too? I usually need to add DEBUG((...))'s
> all
> > over the place for hours until I found the reason for a fault.
> >
>
> This is going to be tricky. Unlike AARCH64, which unambiguously
> describes in the AAPCS how to link the stack frames using x29, the
> AAPCS for ARM does not standardise this, and so different compilers
> may do different things, also depending on whether you are executing
> in ARM or Thumb mode. For instance, the following prologue was snipped
> from a BdsDxe.dll build using GCC5 in Thumb2 mode.
>
> 00000254 <_ModuleEntryPoint>:
>      254:       e96d 7e02       strd    r7, lr, [sp, #-8]!
>      258:       b084            sub     sp, #16
>      25a:       af00            add     r7, sp, #0
>
> Googling around, i can indeed find sources that describe how GCC uses
> r7 as the frame pointer for Thumb2 code. However, looking at this
> code, this is still not sufficient to find the *next* frame pointer on
> the stack. IOW, there is no standardised layout to find the next frame
> pointer inside the stack frame.
>
> The only way to do this reliably is using unwind tables, but this is
> *much* more complicated than the 20 line patch that enables it for
> AArch64
>
> Ard.
>
>
> > On Wed, Sep 7, 2016 at 10:21 AM, Ard Biesheuvel <
> ard.biesheuvel@linaro.org>
> > wrote:
> >>
> >> When dumping the CPU state after an unhandled fault, walk the stack
> >> frames and decode the return addresses so we can show a minimal
> >> backtrace. Unfortunately, we do not have sufficient information to
> >> show the function names, but at least we can see the modules and the
> >> return addresses inside the modules.
> >>
> >> Contributed-under: TianoCore Contribution Agreement 1.0
> >> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> >> ---
> >>
> >> Example output:
> >>
> >> Synchronous Exception at 0x00000000F5EA4C8C
> >>
> >> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_
> GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG/
> ArmVeNorFlashDxe.dll
> >> loaded at 0x00000000F5E90000
> >> called from
> >> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_
> GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG/
> ArmVeNorFlashDxe.dll
> >> (0x00000000F5EA4AE8) loaded at 0x00000000F5E90000
> >> called from
> >> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_
> GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG/
> ArmVeNorFlashDxe.dll
> >> (0x00000000F5EA1BFC) loaded at 0x00000000F5E90000
> >> called from
> >> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_
> GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG/
> ArmVeNorFlashDxe.dll
> >> (0x00000000F5EA23F4) loaded at 0x00000000F5E90000
> >> called from
> >> /work/jenkins/workspace/ap-uefi-bin/EDK2_ARCH/ARM/EDK2_
> BINARY/FatPkg/label/sas-sw/Build/Fat/RELEASE_GCC49/
> AARCH64/FatPkg/EnhancedFatDxe/Fat/DEBUG/Fat.dll
> >> (0x00000000FADC454C) loaded at 0x00000000FADC3000
> >> called from
> >> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_
> GCC5/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll
> >> (0x00000000FE47C868) loaded at 0x00000000FE471000
> >> called from
> >> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/
> IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll
> >> (0x00000000FAE2C50C) loaded at 0x00000000FAE01000
> >> called from
> >> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/
> IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll
> >> (0x00000000FAE2C674) loaded at 0x00000000FAE01000
> >> called from
> >> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/
> IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll
> >> (0x00000000FAE2C264) loaded at 0x00000000FAE01000
> >> called from
> >> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/
> IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll
> >> (0x00000000FAE36998) loaded at 0x00000000FAE01000
> >> called from
> >> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/
> IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll
> >> (0x00000000FAE03668) loaded at 0x00000000FAE01000
> >> called from
> >> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_
> GCC5/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll
> >> (0x00000000FE4733F0) loaded at 0x00000000FE471000
> >> called from
> >> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_
> GCC5/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll
> >> (0x00000000FE4724A0) loaded at 0x00000000FE471000
> >> called from
> >> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_
> GCC5/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll
> >> (0x00000000FE472024) loaded at 0x00000000FE471000
> >> ---
> >>  .../AArch64/DefaultExceptionHandler.c               | 21
> >> +++++++++++++++++++++
> >>  1 file changed, 21 insertions(+)
> >>
> >> diff --git
> >> a/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/
> DefaultExceptionHandler.c
> >> b/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/
> DefaultExceptionHandler.c
> >> index 31fc936b21ff..84b442f2b6f4 100644
> >> ---
> >> a/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/
> DefaultExceptionHandler.c
> >> +++
> >> b/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/
> DefaultExceptionHandler.c
> >> @@ -152,9 +152,30 @@ DefaultExceptionHandler (
> >>      CHAR8  *Pdb;
> >>      UINTN  ImageBase;
> >>      UINTN  PeCoffSizeOfHeader;
> >> +    UINT64 *Fp;
> >> +
> >>      Pdb = GetImageName (SystemContext.SystemContextAArch64->ELR,
> >> &ImageBase, &PeCoffSizeOfHeader);
> >>      if (Pdb != NULL) {
> >>        DEBUG ((EFI_D_ERROR, "%a loaded at 0x%016lx \n", Pdb,
> ImageBase));
> >> +
> >> +      Pdb = GetImageName (SystemContext.SystemContextAArch64->LR,
> >> &ImageBase,
> >> +              &PeCoffSizeOfHeader);
> >> +      if (Pdb != NULL) {
> >> +        DEBUG ((EFI_D_ERROR, "called from %a (0x%016lx) loaded at
> >> 0x%016lx \n",
> >> +          Pdb, SystemContext.SystemContextAArch64->LR, ImageBase));
> >> +      }
> >> +      for (Fp = (UINT64 *)SystemContext.SystemContextAArch64->FP;
> >> +           *Fp != 0;
> >> +           Fp = (UINT64 *)Fp[0]) {
> >> +        if (Fp[1] == SystemContext.SystemContextAArch64->LR) {
> >> +         continue;
> >> +        }
> >> +        Pdb = GetImageName (Fp[1], &ImageBase, &PeCoffSizeOfHeader);
> >> +        if (Pdb != NULL) {
> >> +          DEBUG ((EFI_D_ERROR, "called from %a (0x%016lx) loaded at
> >> 0x%016lx \n",
> >> +            Pdb, Fp[1], ImageBase));
> >> +        }
> >> +      }
> >>      }
> >>    DEBUG_CODE_END ();
> >>
> >> --
> >> 2.7.4
> >>
> >> _______________________________________________
> >> edk2-devel mailing list
> >> edk2-devel@lists.01.org
> >> https://lists.01.org/mailman/listinfo/edk2-devel
> >
> >
>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] ArmPkg/DefaultExceptionHandlerLib AARCH64: add minimal backtrace to crash dump
  2016-09-07 11:25       ` Michael Zimmermann
@ 2016-09-07 11:32         ` Ard Biesheuvel
  2016-09-09 13:08           ` Ard Biesheuvel
  0 siblings, 1 reply; 10+ messages in thread
From: Ard Biesheuvel @ 2016-09-07 11:32 UTC (permalink / raw)
  To: Michael Zimmermann; +Cc: edk2-devel@lists.01.org, Leif Lindholm

On 7 September 2016 at 12:25, Michael Zimmermann
<sigmaepsilon92@gmail.com> wrote:
>> However, looking at this
>> code, this is still not sufficient to find the *next* frame pointer on
>> the stack.
> are you sure about that? this code looks like it does just that:
> https://github.com/torvalds/linux/blob/master/arch/arm/kernel/stacktrace.c
>

First of all, that comment makes little sense:

* With framepointer enabled, a simple function prologue looks like this:
* mov ip, sp
* stmdb sp!, {fp, ip, lr, pc}

I assume this should be

stmdb sp!, {fp, ip, lr}

* sub fp, ip, #4
*
* A simple function epilogue looks like this:
* ldm sp, {fp, sp, pc}

But then, it looks like GCC in ARM mode happens to generate stack
frames that are easily unwound.

However, in EDK2 we use Thumb2 primarily, and the code I snipped is
actually from a -fno-omit-frame-pointer Thumb2 build, and it does not
look like whatever is pushed onto the stack can be decoded
unambiguously like that.


> On Wed, Sep 7, 2016 at 1:03 PM, Ard Biesheuvel <ard.biesheuvel@linaro.org>
> wrote:
>>
>> On 7 September 2016 at 10:48, Michael Zimmermann
>> <sigmaepsilon92@gmail.com> wrote:
>> > nice, can we do this for ARM too? I usually need to add DEBUG((...))'s
>> > all
>> > over the place for hours until I found the reason for a fault.
>> >
>>
>> This is going to be tricky. Unlike AARCH64, which unambiguously
>> describes in the AAPCS how to link the stack frames using x29, the
>> AAPCS for ARM does not standardise this, and so different compilers
>> may do different things, also depending on whether you are executing
>> in ARM or Thumb mode. For instance, the following prologue was snipped
>> from a BdsDxe.dll build using GCC5 in Thumb2 mode.
>>
>> 00000254 <_ModuleEntryPoint>:
>>      254:       e96d 7e02       strd    r7, lr, [sp, #-8]!
>>      258:       b084            sub     sp, #16
>>      25a:       af00            add     r7, sp, #0
>>
>> Googling around, i can indeed find sources that describe how GCC uses
>> r7 as the frame pointer for Thumb2 code. However, looking at this
>> code, this is still not sufficient to find the *next* frame pointer on
>> the stack. IOW, there is no standardised layout to find the next frame
>> pointer inside the stack frame.
>>
>> The only way to do this reliably is using unwind tables, but this is
>> *much* more complicated than the 20 line patch that enables it for
>> AArch64
>>
>> Ard.
>>
>>
>> > On Wed, Sep 7, 2016 at 10:21 AM, Ard Biesheuvel
>> > <ard.biesheuvel@linaro.org>
>> > wrote:
>> >>
>> >> When dumping the CPU state after an unhandled fault, walk the stack
>> >> frames and decode the return addresses so we can show a minimal
>> >> backtrace. Unfortunately, we do not have sufficient information to
>> >> show the function names, but at least we can see the modules and the
>> >> return addresses inside the modules.
>> >>
>> >> Contributed-under: TianoCore Contribution Agreement 1.0
>> >> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
>> >> ---
>> >>
>> >> Example output:
>> >>
>> >> Synchronous Exception at 0x00000000F5EA4C8C
>> >>
>> >>
>> >> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG/ArmVeNorFlashDxe.dll
>> >> loaded at 0x00000000F5E90000
>> >> called from
>> >>
>> >> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG/ArmVeNorFlashDxe.dll
>> >> (0x00000000F5EA4AE8) loaded at 0x00000000F5E90000
>> >> called from
>> >>
>> >> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG/ArmVeNorFlashDxe.dll
>> >> (0x00000000F5EA1BFC) loaded at 0x00000000F5E90000
>> >> called from
>> >>
>> >> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG/ArmVeNorFlashDxe.dll
>> >> (0x00000000F5EA23F4) loaded at 0x00000000F5E90000
>> >> called from
>> >>
>> >> /work/jenkins/workspace/ap-uefi-bin/EDK2_ARCH/ARM/EDK2_BINARY/FatPkg/label/sas-sw/Build/Fat/RELEASE_GCC49/AARCH64/FatPkg/EnhancedFatDxe/Fat/DEBUG/Fat.dll
>> >> (0x00000000FADC454C) loaded at 0x00000000FADC3000
>> >> called from
>> >>
>> >> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll
>> >> (0x00000000FE47C868) loaded at 0x00000000FE471000
>> >> called from
>> >>
>> >> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll
>> >> (0x00000000FAE2C50C) loaded at 0x00000000FAE01000
>> >> called from
>> >>
>> >> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll
>> >> (0x00000000FAE2C674) loaded at 0x00000000FAE01000
>> >> called from
>> >>
>> >> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll
>> >> (0x00000000FAE2C264) loaded at 0x00000000FAE01000
>> >> called from
>> >>
>> >> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll
>> >> (0x00000000FAE36998) loaded at 0x00000000FAE01000
>> >> called from
>> >>
>> >> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll
>> >> (0x00000000FAE03668) loaded at 0x00000000FAE01000
>> >> called from
>> >>
>> >> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll
>> >> (0x00000000FE4733F0) loaded at 0x00000000FE471000
>> >> called from
>> >>
>> >> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll
>> >> (0x00000000FE4724A0) loaded at 0x00000000FE471000
>> >> called from
>> >>
>> >> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll
>> >> (0x00000000FE472024) loaded at 0x00000000FE471000
>> >> ---
>> >>  .../AArch64/DefaultExceptionHandler.c               | 21
>> >> +++++++++++++++++++++
>> >>  1 file changed, 21 insertions(+)
>> >>
>> >> diff --git
>> >>
>> >> a/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c
>> >>
>> >> b/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c
>> >> index 31fc936b21ff..84b442f2b6f4 100644
>> >> ---
>> >>
>> >> a/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c
>> >> +++
>> >>
>> >> b/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c
>> >> @@ -152,9 +152,30 @@ DefaultExceptionHandler (
>> >>      CHAR8  *Pdb;
>> >>      UINTN  ImageBase;
>> >>      UINTN  PeCoffSizeOfHeader;
>> >> +    UINT64 *Fp;
>> >> +
>> >>      Pdb = GetImageName (SystemContext.SystemContextAArch64->ELR,
>> >> &ImageBase, &PeCoffSizeOfHeader);
>> >>      if (Pdb != NULL) {
>> >>        DEBUG ((EFI_D_ERROR, "%a loaded at 0x%016lx \n", Pdb,
>> >> ImageBase));
>> >> +
>> >> +      Pdb = GetImageName (SystemContext.SystemContextAArch64->LR,
>> >> &ImageBase,
>> >> +              &PeCoffSizeOfHeader);
>> >> +      if (Pdb != NULL) {
>> >> +        DEBUG ((EFI_D_ERROR, "called from %a (0x%016lx) loaded at
>> >> 0x%016lx \n",
>> >> +          Pdb, SystemContext.SystemContextAArch64->LR, ImageBase));
>> >> +      }
>> >> +      for (Fp = (UINT64 *)SystemContext.SystemContextAArch64->FP;
>> >> +           *Fp != 0;
>> >> +           Fp = (UINT64 *)Fp[0]) {
>> >> +        if (Fp[1] == SystemContext.SystemContextAArch64->LR) {
>> >> +         continue;
>> >> +        }
>> >> +        Pdb = GetImageName (Fp[1], &ImageBase, &PeCoffSizeOfHeader);
>> >> +        if (Pdb != NULL) {
>> >> +          DEBUG ((EFI_D_ERROR, "called from %a (0x%016lx) loaded at
>> >> 0x%016lx \n",
>> >> +            Pdb, Fp[1], ImageBase));
>> >> +        }
>> >> +      }
>> >>      }
>> >>    DEBUG_CODE_END ();
>> >>
>> >> --
>> >> 2.7.4
>> >>
>> >> _______________________________________________
>> >> edk2-devel mailing list
>> >> edk2-devel@lists.01.org
>> >> https://lists.01.org/mailman/listinfo/edk2-devel
>> >
>> >
>
>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] BaseTools/tools_def AARCH64: enable frame pointers for DEBUG builds
  2016-09-07  8:21 [PATCH 1/2] BaseTools/tools_def AARCH64: enable frame pointers for DEBUG builds Ard Biesheuvel
  2016-09-07  8:21 ` [PATCH 2/2] ArmPkg/DefaultExceptionHandlerLib AARCH64: add minimal backtrace to crash dump Ard Biesheuvel
@ 2016-09-07 15:00 ` Leif Lindholm
  1 sibling, 0 replies; 10+ messages in thread
From: Leif Lindholm @ 2016-09-07 15:00 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: edk2-devel

On Wed, Sep 07, 2016 at 09:21:54AM +0100, Ard Biesheuvel wrote:
> Enable frame pointers on DEBUG builds so we can support backtraces in
> crash dumps.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

This is really handy - for the series:
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Tested-by: Leif Lindholm <leif.lindholm@linaro.org>

> ---
>  BaseTools/Conf/tools_def.template | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template
> index d8e3e3dc13b9..5414454ec7e3 100755
> --- a/BaseTools/Conf/tools_def.template
> +++ b/BaseTools/Conf/tools_def.template
> @@ -4342,7 +4342,7 @@ DEFINE GCC_X64_CC_FLAGS            = DEF(GCC_ALL_CC_FLAGS) -mno-red-zone -Wno-ad
>  DEFINE GCC_IPF_CC_FLAGS            = DEF(GCC_ALL_CC_FLAGS) -minline-int-divide-min-latency
>  DEFINE GCC_ARM_CC_FLAGS            = DEF(GCC_ALL_CC_FLAGS) -mlittle-endian -mabi=aapcs -fno-short-enums -funsigned-char -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-builtin -Wno-address -mthumb -mfloat-abi=soft
>  DEFINE GCC_ARM_CC_XIPFLAGS         = -mno-unaligned-access
> -DEFINE GCC_AARCH64_CC_FLAGS        = DEF(GCC_ALL_CC_FLAGS) -mlittle-endian -fno-short-enums -fverbose-asm -funsigned-char  -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-builtin -Wno-address -fno-asynchronous-unwind-tables
> +DEFINE GCC_AARCH64_CC_FLAGS        = DEF(GCC_ALL_CC_FLAGS) -mlittle-endian -fno-short-enums -fverbose-asm -funsigned-char  -ffunction-sections -fdata-sections -fno-builtin -Wno-address -fno-asynchronous-unwind-tables
>  DEFINE GCC_AARCH64_CC_XIPFLAGS     = -mstrict-align
>  DEFINE GCC_DLINK_FLAGS_COMMON      = -nostdlib --pie
>  DEFINE GCC_DLINK2_FLAGS_COMMON     = -Wl,--script=$(EDK_TOOLS_PATH)/Scripts/GccBase.lds
> @@ -4960,7 +4960,7 @@ RELEASE_GCC47_ARM_CC_FLAGS       = DEF(GCC47_ARM_CC_FLAGS) -Wno-unused-but-set-v
>  *_GCC47_AARCH64_CC_XIPFLAGS      = DEF(GCC47_AARCH64_CC_XIPFLAGS)
>  
>    DEBUG_GCC47_AARCH64_CC_FLAGS   = DEF(GCC47_AARCH64_CC_FLAGS) -O0
> -RELEASE_GCC47_AARCH64_CC_FLAGS   = DEF(GCC47_AARCH64_CC_FLAGS) -Wno-unused-but-set-variable
> +RELEASE_GCC47_AARCH64_CC_FLAGS   = DEF(GCC47_AARCH64_CC_FLAGS) -Wno-unused-but-set-variable -fomit-frame-pointer
>  
>  ####################################################################################
>  #
> @@ -5093,7 +5093,7 @@ RELEASE_GCC48_ARM_CC_FLAGS       = DEF(GCC48_ARM_CC_FLAGS) -Wno-unused-but-set-v
>  *_GCC48_AARCH64_CC_XIPFLAGS      = DEF(GCC48_AARCH64_CC_XIPFLAGS)
>  
>    DEBUG_GCC48_AARCH64_CC_FLAGS   = DEF(GCC48_AARCH64_CC_FLAGS) -O0
> -RELEASE_GCC48_AARCH64_CC_FLAGS   = DEF(GCC48_AARCH64_CC_FLAGS) -Wno-unused-but-set-variable
> +RELEASE_GCC48_AARCH64_CC_FLAGS   = DEF(GCC48_AARCH64_CC_FLAGS) -Wno-unused-but-set-variable -fomit-frame-pointer
>  
>  ####################################################################################
>  #
> @@ -5228,7 +5228,7 @@ RELEASE_GCC49_ARM_CC_FLAGS       = DEF(GCC49_ARM_CC_FLAGS) -Wno-unused-but-set-v
>    DEBUG_GCC49_AARCH64_DLINK_FLAGS  = DEF(GCC49_AARCH64_DLINK_FLAGS) -z common-page-size=0x1000
>    DEBUG_GCC49_AARCH64_DLINK_XIPFLAGS = -z common-page-size=0x20
>  
> -RELEASE_GCC49_AARCH64_CC_FLAGS     = DEF(GCC49_AARCH64_CC_FLAGS) -Wno-unused-but-set-variable -mcmodel=tiny
> +RELEASE_GCC49_AARCH64_CC_FLAGS     = DEF(GCC49_AARCH64_CC_FLAGS) -Wno-unused-but-set-variable -mcmodel=tiny -fomit-frame-pointer
>  RELEASE_GCC49_AARCH64_DLINK_FLAGS  = DEF(GCC49_AARCH64_DLINK_FLAGS)
>  
>  ####################################################################################
> @@ -5364,7 +5364,7 @@ RELEASE_GCC5_ARM_DLINK_FLAGS     = DEF(GCC5_ARM_DLINK_FLAGS) -flto -Os -L$(WORKS
>    DEBUG_GCC5_AARCH64_DLINK_FLAGS = DEF(GCC5_AARCH64_DLINK_FLAGS) -z common-page-size=0x1000
>    DEBUG_GCC5_AARCH64_DLINK_XIPFLAGS = -z common-page-size=0x20
>  
> -RELEASE_GCC5_AARCH64_CC_FLAGS    = DEF(GCC5_AARCH64_CC_FLAGS) -flto -Wno-unused-but-set-variable -mcmodel=tiny
> +RELEASE_GCC5_AARCH64_CC_FLAGS    = DEF(GCC5_AARCH64_CC_FLAGS) -flto -Wno-unused-but-set-variable -mcmodel=tiny -fomit-frame-pointer
>  RELEASE_GCC5_AARCH64_DLINK_FLAGS = DEF(GCC5_AARCH64_DLINK_FLAGS) -flto -Os -L$(WORKSPACE)/ArmPkg/Library/GccLto -llto-aarch64 -Wl,-plugin-opt=-pass-through=-llto-aarch64
>  
>  ####################################################################################
> @@ -5443,7 +5443,7 @@ RELEASE_CLANG35_ARM_CC_FLAGS     = DEF(CLANG35_ARM_CC_FLAGS) $(ARCHCC_FLAGS) $(P
>  *_CLANG35_AARCH64_CC_XIPFLAGS    = DEF(GCC_AARCH64_CC_XIPFLAGS)
>  
>    DEBUG_CLANG35_AARCH64_CC_FLAGS = DEF(CLANG35_AARCH64_CC_FLAGS) $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) -O0
> -RELEASE_CLANG35_AARCH64_CC_FLAGS = DEF(CLANG35_AARCH64_CC_FLAGS) $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) -Oz
> +RELEASE_CLANG35_AARCH64_CC_FLAGS = DEF(CLANG35_AARCH64_CC_FLAGS) $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) -Oz -fomit-frame-pointer
>  
>  ####################################################################################
>  #
> -- 
> 2.7.4
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] ArmPkg/DefaultExceptionHandlerLib AARCH64: add minimal backtrace to crash dump
  2016-09-07 11:32         ` Ard Biesheuvel
@ 2016-09-09 13:08           ` Ard Biesheuvel
  2016-09-09 18:03             ` Michael Zimmermann
  0 siblings, 1 reply; 10+ messages in thread
From: Ard Biesheuvel @ 2016-09-09 13:08 UTC (permalink / raw)
  To: Michael Zimmermann; +Cc: edk2-devel@lists.01.org, Leif Lindholm

On 7 September 2016 at 12:32, Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
> On 7 September 2016 at 12:25, Michael Zimmermann
> <sigmaepsilon92@gmail.com> wrote:
>>> However, looking at this
>>> code, this is still not sufficient to find the *next* frame pointer on
>>> the stack.
>> are you sure about that? this code looks like it does just that:
>> https://github.com/torvalds/linux/blob/master/arch/arm/kernel/stacktrace.c
>>
>
> First of all, that comment makes little sense:
>
> * With framepointer enabled, a simple function prologue looks like this:
> * mov ip, sp
> * stmdb sp!, {fp, ip, lr, pc}
>
> I assume this should be
>
> stmdb sp!, {fp, ip, lr}
>
> * sub fp, ip, #4
> *
> * A simple function epilogue looks like this:
> * ldm sp, {fp, sp, pc}
>

OK, I spoke a bit too soon. The 'pop' does not actually increment the
stack pointer, so while the push does make sense (and pushing the pc
in addition is just informational), the pop should actually be
implemented as

ldm sp, {fp, sp, lr}

... do other stuff including incrementing the sp to its original value ...

bx lr

In any case, unless you have any information that suggests that GCC in
Thumb2 mode can be coerced into managing the frame pointer in a way
that allows us to do something similar in EDK2, I am going to stick
with my assertion that this is not currently possible on ARM.

Thanks,
Ard.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] ArmPkg/DefaultExceptionHandlerLib AARCH64: add minimal backtrace to crash dump
  2016-09-07  8:21 ` [PATCH 2/2] ArmPkg/DefaultExceptionHandlerLib AARCH64: add minimal backtrace to crash dump Ard Biesheuvel
  2016-09-07  9:48   ` Michael Zimmermann
@ 2016-09-09 16:03   ` Andrew Fish
  1 sibling, 0 replies; 10+ messages in thread
From: Andrew Fish @ 2016-09-09 16:03 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: edk2-devel, leif.lindholm


> On Sep 7, 2016, at 1:21 AM, Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
> 
> When dumping the CPU state after an unhandled fault, walk the stack
> frames and decode the return addresses so we can show a minimal
> backtrace. Unfortunately, we do not have sufficient information to
> show the function names, but at least we can see the modules and the
> return addresses inside the modules.
> 

Ard,

In these kind of dumps I find it useful to also display the offset into the PE/COFF image. 
ArmVeNorFlashDxe.dll (0x00000000F5EA4AE8)  loaded at 0x00000000F5E90000 offset 0x00014AE9

The reason is it makes it easy to use the gdb list command to display the C source code. 
gdb /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG/ArmVeNorFlashDxe.dll 
(gdb) list * 0x14AE9

This assumes the .dll is the ELF linked near zero to accommodate the PE/COFF header, or PE/COFF.  For TE you need to know the adjustment value from the TE header. 

Seems like it would be possible to write a script to symbolicate the stack trace on the build machine. 

It might be more useful to have the summary 1st (I have to admit I like things to line up in columns):
Synchronous Exception at 0x00000000F5EA4C8C
PC 0x00000000F5EA4C8C (0x00000000F5E90000+0x00014C8C) ArmVeNorFlashDxe.dll  /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG
PC 0x00000000F5EA4AE8 (0x00000000F5E90000+0x00014AE9) ArmVeNorFlashDxe.dll  /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG
PC 0x00000000F5EA1BFC (0x00000000F5E90000+0x00011BFC) ArmVeNorFlashDxe.dll  /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG

In the example above I also made the the exception line the summary and showed that location like the rest of the frame. This seems to be the way debuggers like to do it so it seems to match with what a developer would expect. 

Thanks,

Andrew Fish

PS. Just saw the remove the path commit. So maybe something like:

Synchronous Exception at 0x00000000F5EA4C8C
PC 0x00000000F5EA4C8C (0x00000000F5E90000+0x00014C8C) ArmVeNorFlashDxe.dll  [1]
PC 0x00000000F5EA4AE8 (0x00000000F5E90000+0x00014AE9) ArmVeNorFlashDxe.dll  [1]
PC 0x00000000F5EA1BFC (0x00000000F5E90000+0x00011BFC) ArmVeNorFlashDxe.dll [1]
PC 0x00000000FADC454C (0x00000000FADC3000+0x0000154C) Fat.dll [2]

[1] /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG
[2] /work/jenkins/workspace/ap-uefi-bin/EDK2_ARCH/ARM/EDK2_BINARY/FatPkg/label/sas-sw/Build/Fat/RELEASE_GCC49/AARCH64/FatPkg/EnhancedFatDxe/Fat/DEBUG/

I think your example points out why it is useful.  Also the Shell or application running at he Shell could come from different locations, but still be on your system. Not to mention if you are debugging you might as well dump out all the information you have. 

> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
> 
> Example output:
> 
> Synchronous Exception at 0x00000000F5EA4C8C
> /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG/ArmVeNorFlashDxe.dll loaded at 0x00000000F5E90000
> called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG/ArmVeNorFlashDxe.dll (0x00000000F5EA4AE8) loaded at 0x00000000F5E90000
> called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG/ArmVeNorFlashDxe.dll (0x00000000F5EA1BFC) loaded at 0x00000000F5E90000
> called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe/DEBUG/ArmVeNorFlashDxe.dll (0x00000000F5EA23F4) loaded at 0x00000000F5E90000
> called from /work/jenkins/workspace/ap-uefi-bin/EDK2_ARCH/ARM/EDK2_BINARY/FatPkg/label/sas-sw/Build/Fat/RELEASE_GCC49/AARCH64/FatPkg/EnhancedFatDxe/Fat/DEBUG/Fat.dll (0x00000000FADC454C) loaded at 0x00000000FADC3000
> called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll (0x00000000FE47C868) loaded at 0x00000000FE471000
> called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll (0x00000000FAE2C50C) loaded at 0x00000000FAE01000
> called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll (0x00000000FAE2C674) loaded at 0x00000000FAE01000
> called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll (0x00000000FAE2C264) loaded at 0x00000000FAE01000
> called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll (0x00000000FAE36998) loaded at 0x00000000FAE01000
> called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll (0x00000000FAE03668) loaded at 0x00000000FAE01000
> called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll (0x00000000FE4733F0) loaded at 0x00000000FE471000
> called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll (0x00000000FE4724A0) loaded at 0x00000000FE471000
> called from /home/ard/build/edk2/Build/ArmVExpress-FVP-AArch64/DEBUG_GCC5/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll (0x00000000FE472024) loaded at 0x00000000FE471000
> ---
> .../AArch64/DefaultExceptionHandler.c               | 21 +++++++++++++++++++++
> 1 file changed, 21 insertions(+)
> 
> diff --git a/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c b/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c
> index 31fc936b21ff..84b442f2b6f4 100644
> --- a/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c
> +++ b/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c
> @@ -152,9 +152,30 @@ DefaultExceptionHandler (
>     CHAR8  *Pdb;
>     UINTN  ImageBase;
>     UINTN  PeCoffSizeOfHeader;
> +    UINT64 *Fp;
> +
>     Pdb = GetImageName (SystemContext.SystemContextAArch64->ELR, &ImageBase, &PeCoffSizeOfHeader);
>     if (Pdb != NULL) {
>       DEBUG ((EFI_D_ERROR, "%a loaded at 0x%016lx \n", Pdb, ImageBase));
> +
> +      Pdb = GetImageName (SystemContext.SystemContextAArch64->LR, &ImageBase,
> +              &PeCoffSizeOfHeader);
> +      if (Pdb != NULL) {
> +        DEBUG ((EFI_D_ERROR, "called from %a (0x%016lx) loaded at 0x%016lx \n",
> +          Pdb, SystemContext.SystemContextAArch64->LR, ImageBase));
> +      }
> +      for (Fp = (UINT64 *)SystemContext.SystemContextAArch64->FP;
> +           *Fp != 0;
> +           Fp = (UINT64 *)Fp[0]) {
> +        if (Fp[1] == SystemContext.SystemContextAArch64->LR) {
> +         continue;
> +        }
> +        Pdb = GetImageName (Fp[1], &ImageBase, &PeCoffSizeOfHeader);
> +        if (Pdb != NULL) {
> +          DEBUG ((EFI_D_ERROR, "called from %a (0x%016lx) loaded at 0x%016lx \n",
> +            Pdb, Fp[1], ImageBase));
> +        }
> +      }
>     }
>   DEBUG_CODE_END ();
> 
> -- 
> 2.7.4
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] ArmPkg/DefaultExceptionHandlerLib AARCH64: add minimal backtrace to crash dump
  2016-09-09 13:08           ` Ard Biesheuvel
@ 2016-09-09 18:03             ` Michael Zimmermann
  0 siblings, 0 replies; 10+ messages in thread
From: Michael Zimmermann @ 2016-09-09 18:03 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: edk2-devel@lists.01.org, Leif Lindholm

> In any case, unless you have any information that suggests that GCC in
> Thumb2 mode can be coerced into managing the frame pointer in a way
> that allows us to do something similar in EDK2, I am going to stick
> with my assertion that this is not currently possible on ARM.

I think it's not possible because they enable ARM_UNWIND when compiling
a THUMB2_KERNEL.

porting libunwind would be hard because of UEFI's architecture. every *.efi
would need a section with unwind information, and I don't even know if the
spec allows additional sections.

Thanks
Michael

On Fri, Sep 9, 2016 at 3:08 PM, Ard Biesheuvel <ard.biesheuvel@linaro.org>
wrote:

> On 7 September 2016 at 12:32, Ard Biesheuvel <ard.biesheuvel@linaro.org>
> wrote:
> > On 7 September 2016 at 12:25, Michael Zimmermann
> > <sigmaepsilon92@gmail.com> wrote:
> >>> However, looking at this
> >>> code, this is still not sufficient to find the *next* frame pointer on
> >>> the stack.
> >> are you sure about that? this code looks like it does just that:
> >> https://github.com/torvalds/linux/blob/master/arch/arm/
> kernel/stacktrace.c
> >>
> >
> > First of all, that comment makes little sense:
> >
> > * With framepointer enabled, a simple function prologue looks like this:
> > * mov ip, sp
> > * stmdb sp!, {fp, ip, lr, pc}
> >
> > I assume this should be
> >
> > stmdb sp!, {fp, ip, lr}
> >
> > * sub fp, ip, #4
> > *
> > * A simple function epilogue looks like this:
> > * ldm sp, {fp, sp, pc}
> >
>
> OK, I spoke a bit too soon. The 'pop' does not actually increment the
> stack pointer, so while the push does make sense (and pushing the pc
> in addition is just informational), the pop should actually be
> implemented as
>
> ldm sp, {fp, sp, lr}
>
> ... do other stuff including incrementing the sp to its original value ...
>
> bx lr
>
> In any case, unless you have any information that suggests that GCC in
> Thumb2 mode can be coerced into managing the frame pointer in a way
> that allows us to do something similar in EDK2, I am going to stick
> with my assertion that this is not currently possible on ARM.
>
> Thanks,
> Ard.
>


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-09-09 18:03 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-07  8:21 [PATCH 1/2] BaseTools/tools_def AARCH64: enable frame pointers for DEBUG builds Ard Biesheuvel
2016-09-07  8:21 ` [PATCH 2/2] ArmPkg/DefaultExceptionHandlerLib AARCH64: add minimal backtrace to crash dump Ard Biesheuvel
2016-09-07  9:48   ` Michael Zimmermann
2016-09-07 11:03     ` Ard Biesheuvel
2016-09-07 11:25       ` Michael Zimmermann
2016-09-07 11:32         ` Ard Biesheuvel
2016-09-09 13:08           ` Ard Biesheuvel
2016-09-09 18:03             ` Michael Zimmermann
2016-09-09 16:03   ` Andrew Fish
2016-09-07 15:00 ` [PATCH 1/2] BaseTools/tools_def AARCH64: enable frame pointers for DEBUG builds Leif Lindholm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox