From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=17.151.62.26; helo=mail-in4.apple.com; envelope-from=afish@apple.com; receiver=edk2-devel@lists.01.org Received: from mail-in4.apple.com (mail-out4.apple.com [17.151.62.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id B5C07220C1C20 for ; Thu, 23 Nov 2017 10:30:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; d=apple.com; s=mailout2048s; c=relaxed/simple; q=dns/txt; i=@apple.com; t=1511462065; h=From:Sender:Reply-To:Subject:Date:Message-id:To:Cc:MIME-version:Content-type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-reply-to:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=b+tdaG0ETqcguKPJAwhAk90iqfJMtm8/j7Lm88Y+QlI=; b=07JDRzyYhltE1FAJx10KVRJfjq7k6csOeq8jSHgX3QhiNl6v787lTXfhySQd0Sud jEyf6VtecQnbtwuT0dP7Pay+1gwtMHvB2QVcpyT9BvAR1viDGAlmry1oCTT07dMm dVid6ApzK/aGAf0M/+R7+y8Cd5EYefesVjUjNDo0l86CsaBi6W2nq6o2lswXNYrd RSc35ktvnn8lTVM3nSY0wmErllJa0uHfitfmk8wJW8U0w80W+niwFplNPV0/4W3U QBpzLYSkUXWo4IIib6ZZHSZ+4rCr0B2iDRGUtkHsPQcETYvozvzZETXzO1/f9ovE 8ofzIdID4gqbNgBtOsLUjw==; Received: from relay7.apple.com (relay7.apple.com [17.128.113.101]) (using TLS with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mail-in4.apple.com (Apple Secure Mail Relay) with SMTP id 4D.90.16042.1B4171A5; Thu, 23 Nov 2017 10:34:25 -0800 (PST) X-AuditID: 11973e12-801fd9c000003eaa-e2-5a1714b1197b Received: from nwk-mmpp-sz13.apple.com (nwk-mmpp-sz13.apple.com [17.128.115.216]) by relay7.apple.com (Apple SCV relay) with SMTP id 8C.90.05443.0B4171A5; Thu, 23 Nov 2017 10:34:24 -0800 (PST) MIME-version: 1.0 Received: from [17.235.53.133] by nwk-mmpp-sz13.apple.com (Oracle Communications Messaging Server 8.0.2.1.20171102 64bit (built Nov 2 2017)) with ESMTPSA id <0OZV00AT9VLB7C00@nwk-mmpp-sz13.apple.com>; Thu, 23 Nov 2017 10:34:24 -0800 (PST) Sender: afish@apple.com From: Andrew Fish Message-id: <88E97D68-8EF4-476D-884C-5301AD3551BE@apple.com> Date: Thu, 23 Nov 2017 10:34:26 -0800 In-reply-to: Cc: Paulo Alcantara , "edk2-devel@lists.01.org" , Laszlo Ersek , Eric Dong To: Fan Jeff References: <86955028c6e8f82de1dc1e8206d2b5441cbbf33c.1510868616.git.pcacjr@zytor.com> <2da80d1e-8b3a-f56b-6a34-871e32b8aba1@zytor.com> X-Mailer: Apple Mail (2.3273) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrMLMWRmVeSWpSXmKPExsUi2FCYqrtRRDzK4O4xVos9h44yW2x+EWyx 7NgOFot9rz8yWpz4PI/NgdXjcc8ZNo/Fe14yeXTP/sfi8X7fVTaPEy1fWANYo7hsUlJzMstS i/TtErgyHu46zl5wtI2l4tefW4wNjEd2M3cxcnBICJhITP0S2MXIxSEksIZJ4t/rDrYuRk6w eOPRPewQiUOMEruf/GUHSfAKCEr8mHyPBcRmFgiT+HV2MytE0VdGiZP3GhhBEsIC4hLvzmxi BrHZBJQlVsz/wA6yjVfARuL8UneIkiSJpuYusHIWAVWJL1vPgC3mFIiX+Dq/DWwms8AiRomp K7aCFYkIqElcmvOQDWLZTSaJvinfWSBOlZW4NfsSM0hCQuAIm0Tnsv+MExiFZiG5dhaSa2cB HcIsoC4xZUouRFhb4sm7C6wQtprEwt+LmJDFFzCyrWIUyk3MzNHNzDPRSywoyEnVS87P3cQI iqXpdkI7GE+tsjrEKMDBqMTDW/BILEqINbGsuDL3EKM0B4uSOG+vsHiUkEB6YklqdmpqQWpR fFFpTmrxIUYmDk6pBsbe73tv/74b+bvp3UXXHVflji4+v7CmIvHrSdd5rt+LzguVlt8wXO96 huefblmB84NZUyL/2e9pun+WVW4xq4mP14a61t/iKg1d1v9u7bv5xWHj2rIdJzrM5JdMmLEw b9fasj0lqy+8v82zbBqTecMN6bkTJl8LZNE/as2jcf6KqiT3z2+tXbullViKMxINtZiLihMB 54/n1YYCAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrOLMWRmVeSWpSXmKPExsUi2FB8Q3eDiHiUwZlP1hZ7Dh1lttj8Ithi 2bEdLBb7Xn9ktDjxeR6bA6vH454zbB6L97xk8uie/Y/F4/2+q2weJ1q+sAawRnHZpKTmZJal FunbJXBlPNx1nL3gaBtLxa8/txgbGI/sZu5i5OSQEDCRaDy6h72LkYtDSOAQo8TuJ3/ZQRK8 AoISPybfYwGxmQXCJH6d3cwKUfSVUeLkvQZGkISwgLjEuzObwCaxCShLrJj/AaiZA6jZRuL8 UneIkiSJpuYusHIWAVWJL1vPsIHYnALxEl/nt4HNZBZYxCgxdcVWsCIRATWJS3MeskEsu8kk 0TflOwvEqbISt2ZfYp7AyD8LyYGzkBw4C2g3s4C6xJQpuRBhbYkn7y6wQthqEgt/L2JCFl/A yLaKUaAoNSex0lwvsaAgJ1UvOT93EyM4+AtTdzA2Lrc6xCjAwajEw1vwSCxKiDWxrLgyFxhK HMxKIrzyT4FCvCmJlVWpRfnxRaU5qcWHGKU5WJTEeZ+cA0oJpCeWpGanphakFsFkmTg4pRoY SyRv7+59f9F/gbrdbYNWAyvjg1XBSTMN3N7dNTcs4f719nQzV/ghwYv3tsuHxX50vdAS7Vm6 6oppcXDYnKk7Ezf+fiw+IUtnl+D/Zdu92to/3asIqdfu9Je52Pt3oyqz6Ctflo0v/3Wdr//5 eFLIwkcbIorl+LVXx3KauhoufB+7vGlq7noXJZbijERDLeai4kQAmq1vg3oCAAA= X-Content-Filtered-By: Mailman/MimeDel 2.1.22 Subject: Re: [RFC v3 1/3] UefiCpuPkg/CpuExceptionHandlerLib/X64: Add stack trace support X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Nov 2017 18:30:07 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable > On Nov 23, 2017, at 6:27 AM, Fan Jeff > wrote: >=20 > Hi Paulo, >=20 >=20 >=20 > I=E2=80=99d like to clarify my question. >=20 > The following call trace information is abstracted from your x64 dump = contents. >=20 > Call trace: >=20 > 0 0x7DBCD580 @ 0x7DBCD000+0x57F (0x7EEC8DDC) in PartitionDxe.dll >=20 > 1 0x7DBD41BE @ 0x7DBCD000+0x71BD (0x7EEC8DFC) in PartitionDxe.dll >=20 >=20 >=20 > I guess you used CpuBreakpoint() to do your validation. >=20 > For 0x7DBCD580, it is return address followed by =E2=80=9Cint 3=E2=80=9D= from your case. >=20 > If we dump obj file, we would see the following asm code. >=20 > 000000007DBCD57F: CC int 3 >=20 > 000000007DBCD580: C3 ret >=20 Jeff, Can you walk the stack without a frame pointer? I don't think the common = nasm code supports that. For x86 GCC and clang use %rbp as the frame = pointer. The common nasm code may be why his walk is off? As you can see when emit frame pointer is on you get: pushq %rbp movq %rsp, %rbp ... popq %rbp retq vs. this without the frame pointer, like your example above.=20 ... retq Without a frame pointer you need debug symbols as you don't know how = deep the return address is on the stack in any given location in a = function.=20 Simple frame pointer example with clang: ~/work/Compiler>cat breakpoint.c void CpuBreakpoint ( void ) { __asm__ __volatile__ ("int $3"); } ~/work/Compiler>clang breakpoint.c -S ~/work/Compiler>cat breakpoint.S .section __TEXT,__text,regular,pure_instructions .macosx_version_min 10, 12 .globl _CpuBreakpoint .p2align 4, 0x90 _CpuBreakpoint: ## @CpuBreakpoint .cfi_startproc ## BB#0: pushq %rbp Lcfi0: .cfi_def_cfa_offset 16 Lcfi1: .cfi_offset %rbp, -16 movq %rsp, %rbp Lcfi2: .cfi_def_cfa_register %rbp ## InlineAsm Start int3 ## InlineAsm End popq %rbp retq .cfi_endproc .subsections_via_symbols ~/work/Compiler> Thanks, Andrew Fish PS some lldb Python that walks an x86 stack frame, assuming you have a = stack pointer. Given dereferencing a non-canonical addresses causes a = General Protection fault it is good to error check for them if your = stack walk code can not tolerate exceptions. EFI_BAD_POINTER, aka = 0xAFAFAFAFAFAFAFAF, is the most common thing you hit (Thanks to Vincent = Zimmer making sure EFI faults have my initials in them, not to mention = the header for TE images is VZ).=20 def NotCanonicalAddress(addr, start=3D0x00007FFFFFFFFFFF, = end=3D0xFF800000000000000): return addr > start and addr < end def print_raw_stacktrace(debugger, fp, pc, address =3D 0, verbose =3D = False): # Do a raw stack trace =20 stride =3D4 =20 SBTarget =3D debugger.GetSelectedTarget() if SBTarget: Triple =3D SBTarget.triple if Triple.find ("x86_64") !=3D -1: stride =3D 8 frame_num =3D 0 if address !=3D 0: frame_addr =3D readPointer (debugger, address + 0) frame_pc =3D readPointer (debugger, address + stride) else: frame_addr =3D fp frame_pc =3D pc while frame_num < 50: print "0x%x: 0x%x: %s" % (frame_addr, frame_pc, = disassembleInstruction (debugger, frame_pc)) if verbose: str =3D efiSymbolicate (debugger, None, frame_pc, False) if str !=3D '': print " %s" % str frame_pc =3D readPointer (debugger, frame_addr + stride) frame_addr =3D readPointer (debugger, frame_addr + 0) frame_num +=3D 1 if frame_pc =3D=3D 0: break if NotCanonicalAddress(frame_pc) or NotCanonicalAddress(frame_addr): break =20 return frame_num > (On case 0, the code at offset 0x57F is int 3) >=20 > 000000007DBD41B9: E8 AF 2A 00 00 call CpuBreakpoint >=20 > 000000007DBD41BE: XX XX XX XX XXX XXXXXX >=20 > (On case 1, what=E2=80=99s the code at offset 0x71BD??) >=20 >=20 >=20 > If the upper asm code is not correct, please copy your obj file here. >=20 >=20 >=20 > If the upper asm code is correct, I think we should show the return = address as below, since we cannot calculate the calling IP address on = most cases. (return address =E2=80=93 1 is not always the calling IP = address on IA arch). >=20 > 0 0x7DBCD580 @ 0x7DBCD000+0x580 (0x7EEC8DDC) in PartitionDxe.dll >=20 > 1 0x7DBD41BE @ 0x7DBCD000+0x71BE (0x7EEC8DFC) in PartitionDxe.dll >=20 >=20 >=20 > Thanks! >=20 > Jeff >=20 >=20 >=20 > ________________________________ > From: Paulo Alcantara > > Sent: Monday, November 20, 2017 10:59:41 PM > To: Fan Jeff; edk2-devel@lists.01.org > Cc: Laszlo Ersek; Eric Dong > Subject: Re: =E7=AD=94=E5=A4=8D: [edk2] [RFC v3 1/3] = UefiCpuPkg/CpuExceptionHandlerLib/X64: Add stack trace support >=20 > Hi Jeff, >=20 > (sorry for the late response) >=20 > On 11/17/2017 5:24 AM, Fan Jeff wrote: >> Paulo, >>=20 >>=20 >> I don't understand why you - 1 when calculating EIP offset in image, = it >> confused me. >=20 > That's an offset relative to the PE/COFF image base: 0 - (ImageBase + > ImageBaseSize - 1) >=20 > Doesn't that look right to you? >=20 > Thanks > Paulo >=20 >>=20 >>=20 >> + for (;;) { >> + // >> + // Print stack frame in the following format: >> + // >> + // # @ + (RBP) in [ | = ????] >> + // >> + InternalPrintMessage ( >> + "%d 0x%016lx @ 0x%016lx+0x%x (0x%016lx) in %a\n", >> + *UnwoundStacksCount - 1, >> + Rip, >> + ImageBase, >> + Rip - ImageBase - 1, // ???? >> + Rbp, >> + PdbFileName >> + ); >> + >>=20 >> Jeff >>=20 >>=20 >>=20 >>=20 >> = ------------------------------------------------------------------------ >> *=E5=8F=91=E4=BB=B6=E4=BA=BA:* edk2-devel = > =E4=BB=A3=E8=A1=A8 Paulo >> Alcantara > >> *=E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4:* 2017=E5=B9=B411=E6=9C=8817=E6=97= =A5 5:56 >> *=E6=94=B6=E4=BB=B6=E4=BA=BA:* edk2-devel@lists.01.org = >> *=E6=8A=84=E9=80=81:* Laszlo Ersek; Eric Dong >> *=E4=B8=BB=E9=A2=98:* [edk2] [RFC v3 1/3] = UefiCpuPkg/CpuExceptionHandlerLib/X64: Add >> stack trace support >> This patch adds stack trace support during a X64 CPU exception. >>=20 >> It will dump out back trace, stack contents as well as image module >> names that were part of the call stack. >>=20 >> Contributed-under: TianoCore Contribution Agreement 1.1 >> Cc: Eric Dong > >> Cc: Laszlo Ersek > >> Signed-off-by: Paulo Alcantara > >> --- >> UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c = | >> 376 +++++++++++++++++++- >> 1 file changed, 374 insertions(+), 2 deletions(-) >>=20 >> diff --git >> = a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c >> = b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c >> index 65f0cff680..fe776ccc2d 100644 >> --- = a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c >> +++ = b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c >> @@ -14,6 +14,11 @@ >>=20 >> #include "CpuExceptionCommon.h" >>=20 >> +// >> +// Unknown PDB file name >> +// >> +GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mUnknownPdbFileName =3D = "????"; >> + >> /** >> Return address map of exception handler template so that C code = can >> generate >> exception tables. >> @@ -242,6 +247,357 @@ DumpCpuContext ( >> ); >> } >>=20 >> +/** >> + Get absolute path and file name of PDB file in PE/COFF image. >> + >> + @param[in] ImageBase Base address of PE/COFF image. >> + @param[out] PdbAbsoluteFilePath Absolute path of PDB file. >> + @param[out] PdbFileName File name of PDB file. >> +**/ >> +STATIC >> +VOID >> +GetPdbFileName ( >> + IN UINTN ImageBase, >> + OUT CHAR8 **PdbAbsoluteFilePath, >> + OUT CHAR8 **PdbFileName >> + ) >> +{ >> + VOID *PdbPointer; >> + CHAR8 *Str; >> + >> + // >> + // Get PDB file name from PE/COFF image >> + // >> + PdbPointer =3D PeCoffLoaderGetPdbPointer ((VOID *)ImageBase); >> + if (PdbPointer =3D=3D NULL) { >> + // >> + // No PDB file name found. Set it to an unknown file name. >> + // >> + *PdbFileName =3D (CHAR8 *)mUnknownPdbFileName; >> + if (PdbAbsoluteFilePath !=3D NULL) { >> + *PdbAbsoluteFilePath =3D NULL; >> + } >> + } else { >> + // >> + // Get file name portion out of PDB file in PE/COFF image >> + // >> + Str =3D (CHAR8 *)((UINTN)PdbPointer + >> + AsciiStrLen ((CHAR8 *)PdbPointer) - sizeof = *Str); >> + for (; *Str !=3D '/' && *Str !=3D '\\'; Str--) { >> + ; >> + } >> + >> + // >> + // Set PDB file name (also skip trailing path separator: '/' or = '\\') >> + // >> + *PdbFileName =3D Str + 1; >> + >> + if (PdbAbsoluteFilePath !=3D NULL) { >> + // >> + // Set absolute file path of PDB file >> + // >> + *PdbAbsoluteFilePath =3D PdbPointer; >> + } >> + } >> +} >> + >> +/** >> + Dump stack contents. >> + >> + @param[in] CurrentRsp Current stack pointer address. >> + @param[in] UnwoundStacksCount Count of unwound stack frames. >> +**/ >> +STATIC >> +VOID >> +DumpStackContents ( >> + IN UINT64 CurrentRsp, >> + IN INTN UnwoundStacksCount >> + ) >> +{ >> + // >> + // Check for proper stack pointer alignment >> + // >> + if (((UINTN)CurrentRsp & (CPU_STACK_ALIGNMENT - 1)) !=3D 0) { >> + InternalPrintMessage ("!!!! Unaligned stack pointer. !!!!\n"); >> + return; >> + } >> + >> + // >> + // Dump out stack contents >> + // >> + InternalPrintMessage ("\nStack dump:\n"); >> + while (UnwoundStacksCount-- > 0) { >> + InternalPrintMessage ( >> + "0x%016lx: %016lx %016lx\n", >> + CurrentRsp, >> + *(UINT64 *)CurrentRsp, >> + *(UINT64 *)((UINTN)CurrentRsp + 8) >> + ); >> + >> + // >> + // Point to next stack >> + // >> + CurrentRsp +=3D CPU_STACK_ALIGNMENT; >> + } >> +} >> + >> +/** >> + Dump all image module names from call stack. >> + >> + @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT. >> +**/ >> +STATIC >> +VOID >> +DumpImageModuleNames ( >> + IN EFI_SYSTEM_CONTEXT SystemContext >> + ) >> +{ >> + EFI_STATUS Status; >> + UINT64 Rip; >> + UINTN ImageBase; >> + VOID *EntryPoint; >> + CHAR8 *PdbAbsoluteFilePath; >> + CHAR8 *PdbFileName; >> + UINT64 Rbp; >> + UINTN LastImageBase; >> + >> + // >> + // Set current RIP address >> + // >> + Rip =3D SystemContext.SystemContextX64->Rip; >> + >> + // >> + // Set current frame pointer address >> + // >> + Rbp =3D SystemContext.SystemContextX64->Rbp; >> + >> + // >> + // Check for proper frame pointer alignment >> + // >> + if (((UINTN)Rbp & (CPU_STACK_ALIGNMENT - 1)) !=3D 0) { >> + InternalPrintMessage ("!!!! Unaligned frame pointer. !!!!\n"); >> + return; >> + } >> + >> + // >> + // Get initial PE/COFF image base address from current RIP >> + // >> + ImageBase =3D PeCoffSearchImageBase (Rip); >> + if (ImageBase =3D=3D 0) { >> + InternalPrintMessage ("!!!! Could not find image module names. = !!!!"); >> + return; >> + } >> + >> + // >> + // Set last PE/COFF image base address >> + // >> + LastImageBase =3D ImageBase; >> + >> + // >> + // Get initial PE/COFF image's entry point >> + // >> + Status =3D PeCoffLoaderGetEntryPoint ((VOID *)ImageBase, = &EntryPoint); >> + if (EFI_ERROR (Status)) { >> + EntryPoint =3D NULL; >> + } >> + >> + // >> + // Get file name and absolute path of initial PDB file >> + // >> + GetPdbFileName (ImageBase, &PdbAbsoluteFilePath, &PdbFileName); >> + >> + // >> + // Print out initial image module name (if any) >> + // >> + if (PdbAbsoluteFilePath !=3D NULL) { >> + InternalPrintMessage ( >> + "\n%a (ImageBase=3D0x%016lx, EntryPoint=3D0x%016lx):\n", >> + PdbFileName, >> + ImageBase, >> + (UINTN)EntryPoint >> + ); >> + InternalPrintMessage ("%a\n", PdbAbsoluteFilePath); >> + } >> + >> + // >> + // Walk through call stack and find next module names >> + // >> + for (;;) { >> + // >> + // Set RIP with return address from current stack frame >> + // >> + Rip =3D *(UINT64 *)((UINTN)Rbp + 8); >> + >> + // >> + // If RIP is zero, then stop unwinding the stack >> + // >> + if (Rip =3D=3D 0) { >> + break; >> + } >> + >> + // >> + // Search for the respective PE/COFF image based on RIP >> + // >> + ImageBase =3D PeCoffSearchImageBase (Rip); >> + if (ImageBase =3D=3D 0) { >> + // >> + // Stop stack trace >> + // >> + break; >> + } >> + >> + // >> + // If RIP points to another PE/COFF image, then find its = respective >> PDB file >> + // name. >> + // >> + if (LastImageBase !=3D ImageBase) { >> + // >> + // Get PE/COFF image's entry point >> + // >> + Status =3D PeCoffLoaderGetEntryPoint ((VOID *)ImageBase, = &EntryPoint); >> + if (EFI_ERROR (Status)) { >> + EntryPoint =3D NULL; >> + } >> + >> + // >> + // Get file name and absolute path of PDB file >> + // >> + GetPdbFileName (ImageBase, &PdbAbsoluteFilePath, = &PdbFileName); >> + >> + // >> + // Print out image module name (if any) >> + // >> + if (PdbAbsoluteFilePath !=3D NULL) { >> + InternalPrintMessage ( >> + "%a (ImageBase=3D0x%016lx, EntryPoint=3D0x%016lx):\n", >> + PdbFileName, >> + ImageBase, >> + (UINTN)EntryPoint >> + ); >> + InternalPrintMessage ("%a\n", PdbAbsoluteFilePath); >> + } >> + >> + // >> + // Save last PE/COFF image base address >> + // >> + LastImageBase =3D ImageBase; >> + } >> + >> + // >> + // Unwind the stack >> + // >> + Rbp =3D *(UINT64 *)(UINTN)Rbp; >> + } >> +} >> + >> +/** >> + Dump stack trace. >> + >> + @param[in] SystemContext Pointer to EFI_SYSTEM_CONTEXT. >> + @param[out] UnwoundStacksCount Count of unwound stack frames. >> +**/ >> +STATIC >> +VOID >> +DumpStackTrace ( >> + IN EFI_SYSTEM_CONTEXT SystemContext, >> + OUT INTN *UnwoundStacksCount >> + ) >> +{ >> + UINT64 Rip; >> + UINT64 Rbp; >> + UINTN ImageBase; >> + CHAR8 *PdbFileName; >> + >> + // >> + // Set current RIP address >> + // >> + Rip =3D SystemContext.SystemContextX64->Rip; >> + >> + // >> + // Set current frame pointer address >> + // >> + Rbp =3D SystemContext.SystemContextX64->Rbp; >> + >> + // >> + // Get initial PE/COFF image base address from current RIP >> + // >> + ImageBase =3D PeCoffSearchImageBase (Rip); >> + if (ImageBase =3D=3D 0) { >> + InternalPrintMessage ("!!!! Could not find backtrace = information. >> !!!!"); >> + return; >> + } >> + >> + // >> + // Get PDB file name from initial PE/COFF image >> + // >> + GetPdbFileName (ImageBase, NULL, &PdbFileName); >> + >> + // >> + // Initialize count of unwound stacks >> + // >> + *UnwoundStacksCount =3D 1; >> + >> + // >> + // Print out back trace >> + // >> + InternalPrintMessage ("\nCall trace:\n"); >> + >> + for (;;) { >> + // >> + // Print stack frame in the following format: >> + // >> + // # @ + (RBP) in [ | = ????] >> + // >> + InternalPrintMessage ( >> + "%d 0x%016lx @ 0x%016lx+0x%x (0x%016lx) in %a\n", >> + *UnwoundStacksCount - 1, >> + Rip, >> + ImageBase, >> + Rip - ImageBase - 1, >> + Rbp, >> + PdbFileName >> + ); >> + >> + // >> + // Set RIP with return address from current stack frame >> + // >> + Rip =3D *(UINT64 *)((UINTN)Rbp + 8); >> + >> + // >> + // If RIP is zero, then stop unwinding the stack >> + // >> + if (Rip =3D=3D 0) { >> + break; >> + } >> + >> + // >> + // Search for the respective PE/COFF image based on RIP >> + // >> + ImageBase =3D PeCoffSearchImageBase (Rip); >> + if (ImageBase =3D=3D 0) { >> + // >> + // Stop stack trace >> + // >> + break; >> + } >> + >> + // >> + // Get PDB file name >> + // >> + GetPdbFileName (ImageBase, NULL, &PdbFileName); >> + >> + // >> + // Unwind the stack >> + // >> + Rbp =3D *(UINT64 *)(UINTN)Rbp; >> + >> + // >> + // Increment count of unwound stacks >> + // >> + (*UnwoundStacksCount)++; >> + } >> +} >> + >> /** >> Display CPU information. >>=20 >> @@ -254,9 +610,25 @@ DumpImageAndCpuContent ( >> IN EFI_SYSTEM_CONTEXT SystemContext >> ) >> { >> + INTN UnwoundStacksCount; >> + >> + // >> + // Dump CPU context >> + // >> DumpCpuContext (ExceptionType, SystemContext); >> + >> + // >> + // Dump stack trace >> + // >> + DumpStackTrace (SystemContext, &UnwoundStacksCount); >> + >> + // >> + // Dump image module names >> + // >> + DumpImageModuleNames (SystemContext); >> + >> // >> - // Dump module image base and module entry point by RIP >> + // Dump stack contents >> // >> - DumpModuleImageInfo (SystemContext.SystemContextX64->Rip); >> + DumpStackContents (SystemContext.SystemContextX64->Rsp, >> UnwoundStacksCount); >> } >> -- >> 2.14.3 >>=20 >> _______________________________________________ >> edk2-devel mailing list >> edk2-devel@lists.01.org >> https://lists.01.org/mailman/listinfo/edk2-devel >>=20 >> edk2-devel Info Page - 01.org >> >> lists.01.org >> Your email address: Your name (optional): You may enter a privacy >> password below. This provides only mild security, but should prevent >> others from messing ... >>=20 >>=20 >>=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel