From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 34E531A1EC7 for ; Wed, 7 Sep 2016 04:25:53 -0700 (PDT) Received: by mail-wm0-x244.google.com with SMTP id w12so2506422wmf.1 for ; Wed, 07 Sep 2016 04:25:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=+ha50jRUqvx+UdkWvEtBNSTfk2LH9WIMciIUcd85EFI=; b=fL/1zsPq1iYNfnJqtRv58jv7Y/4byTzGmSiV8lRUuFFQaME3ksIF7fxbohmzlcEGqp 7vlBERkhzdqC9RlEm0zRPLIr++MOEVB3c1Gq+QzmnzmwAjTJbr6mM2/k0FmPfqmrp1/G uO26p1ATrZqv4WM0x8iRRaRjxYEeEOeOYNrKATJBGhdcCGB1AJmkDA847sRmd5Lg1nM7 s9e+5nGyoL3YoSVN3WVMJtutloEZSB92ilODmJpTH4mf7Au1JoIFuCDMlUimORbF1XEJ rtBDoFQe0GjQiEuJ31r4R/hFHoWEmMcAhWbvCj5RN+ihpnGlPsmZ7kfZ3txk1KJy4rkf wtDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=+ha50jRUqvx+UdkWvEtBNSTfk2LH9WIMciIUcd85EFI=; b=bj9JMTtUe2MCnxkbUP7nAr7yJ7Z46JxawDJkqM5T0I0sDk0DaToPiNYmZCI6u0M7S7 izkL5dBtSgjjJ3MpLe3mXZgnuRzcZqZoXHTmTSvU5SJBrOYsOovxgC5HQiLpOsdN3Que DspDk1pnHfxhxnQaPtoHh57V4ZjhDKS+ZeQcbkpytO8AGjv0vUBUUiWOhYSXbTffQ3wN syIUNOr9Zj0TPWo6wFCDmQXhEWyVapu8wJ/ablVWFWK1dMdTUscHuLSTr4Zijuk8V68U fP8pzACf2KNQja4Ix0x3bVSfoz+YFID2e+Ihd7iW5mCTg31x4VPMbgVec+du+tn+2UQw 2gig== X-Gm-Message-State: AE9vXwOfGfoea7Igx6bPNeTDNTUSA6LFH4/Rh9/g+XJb+4l5TgIZeqASqZIihOoYSPYc39oaPRpptWizT3toCA== X-Received: by 10.28.4.23 with SMTP id 23mr3577593wme.96.1473247551687; Wed, 07 Sep 2016 04:25:51 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.0.204 with HTTP; Wed, 7 Sep 2016 04:25:51 -0700 (PDT) In-Reply-To: References: <1473236515-8318-1-git-send-email-ard.biesheuvel@linaro.org> <1473236515-8318-2-git-send-email-ard.biesheuvel@linaro.org> From: Michael Zimmermann Date: Wed, 7 Sep 2016 13:25:51 +0200 Message-ID: To: Ard Biesheuvel Cc: "edk2-devel@lists.01.org" , Leif Lindholm X-Content-Filtered-By: Mailman/MimeDel 2.1.21 Subject: Re: [PATCH 2/2] ArmPkg/DefaultExceptionHandlerLib AARCH64: add minimal backtrace to crash dump X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Sep 2016 11:25:53 -0000 Content-Type: text/plain; charset=UTF-8 > 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 wrote: > On 7 September 2016 at 10:48, Michael Zimmermann > 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 > >> --- > >> > >> 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 > > > > >