From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: None (no SPF record) identity=mailfrom; client-ip=15.241.48.73; helo=g9t5009.houston.hpe.com; envelope-from=brian.johnson@hpe.com; receiver=edk2-devel@lists.01.org Received: from g9t5009.houston.hpe.com (g9t5009.houston.hpe.com [15.241.48.73]) (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 93D68220D4C13 for ; Tue, 14 Nov 2017 08:48:00 -0800 (PST) Received: from G2W6311.americas.hpqcorp.net (g2w6311.austin.hp.com [16.197.64.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by g9t5009.houston.hpe.com (Postfix) with ESMTPS id 39E1186; Tue, 14 Nov 2017 16:52:07 +0000 (UTC) Received: from G9W8669.americas.hpqcorp.net (16.220.49.28) by G2W6311.americas.hpqcorp.net (16.197.64.53) with Microsoft SMTP Server (TLS) id 15.0.1178.4; Tue, 14 Nov 2017 16:51:25 +0000 Received: from G4W10204.americas.hpqcorp.net (2002:10cf:5210::10cf:5210) by G9W8669.americas.hpqcorp.net (2002:10dc:311c::10dc:311c) with Microsoft SMTP Server (TLS) id 15.0.1178.4; Tue, 14 Nov 2017 16:51:25 +0000 Received: from NAM02-CY1-obe.outbound.protection.outlook.com (15.241.52.10) by G4W10204.americas.hpqcorp.net (16.207.82.16) with Microsoft SMTP Server (TLS) id 15.0.1178.4 via Frontend Transport; Tue, 14 Nov 2017 16:51:25 +0000 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brian.johnson@hpe.com; Received: from [10.0.2.15] (192.48.192.5) by CS1PR8401MB0406.NAMPRD84.PROD.OUTLOOK.COM (2a01:111:e400:7508::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.218.12; Tue, 14 Nov 2017 16:51:22 +0000 To: Paulo Alcantara , Andrew Fish CC: , Laszlo Ersek , Eric Dong References: <00e14f85d93a2e81ab008f32020f3048fe4857fb.1510662518.git.pcacjr@zytor.com> <60b6223a-f88a-5e56-e49a-31f2b1d94278@zytor.com> From: "Brian J. Johnson" Message-ID: Date: Tue, 14 Nov 2017 10:51:34 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <60b6223a-f88a-5e56-e49a-31f2b1d94278@zytor.com> X-Originating-IP: [192.48.192.5] X-ClientProxiedBy: DM5PR0401CA0010.namprd04.prod.outlook.com (2603:10b6:4:74::23) To CS1PR8401MB0406.NAMPRD84.PROD.OUTLOOK.COM (2a01:111:e400:7508::11) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 760a4fe1-0102-43b3-3fa8-08d52b7ff03d X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(48565401081)(2017052603258); SRVR:CS1PR8401MB0406; X-Microsoft-Exchange-Diagnostics: 1; CS1PR8401MB0406; 3:J/UZagQarJYCV4BF4Cf/A3G9i0KGGagMbtRa5FTWrUFuRcYW1ncUHdntu1KyvNZ3D+IEBMDiWvih2+cFxHzYXgonvQ34eiSqM2wajnD1Kfjf7jY3D773nL+b5kJl5YZzBrdSROmFnbTig1ks5Dj/V4bk8jliG7idhp4KqsATND9rV5mYIUVpIhl4WqsqCeezDpmrIvN1MjRjk6N3Wfu98QANKvXF8DTr35IcfWatQ6KtYFWE7NfuQv1mU5r/wrwb; 25:VQaK7OFz/TBcSzLVyN1g5l35FpCBLSpfmbJgpDd860E0u2wH5xC6zSJ4v5P75pAbf1jjSo9Wk72WoaZoDETp9TcLZM6VC1lq4DBommp7Vxo/uUvBfiNpcPQND0iOgkYW+CEVJBl1Cv38nrsbx8yGiiaUAaZNx5UcUVlgTN4Kl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sfNahLu4gLmTDbDabQ08ZsfBF5gU5iVsZOD9kotALbtme0WokZDRUqAei7wOjfF9kOA+6ZTQk/j/H53ffRVyFKYPqjuy0RbtnEXs3gohzYx0RKEW+Rsw4gMxCyIekPtf0eCdMWF/ECaVgEE2YR99f2XFSHHIxgnS5p4Yv/8abBcJ8XY3N6IdazvOME4AaD4dXCFhl07Q7FWfDnGeTDnCijlZB9zbp3B83Tt2jr9ZELBqcipiFYiH//XvGexzQvlkjmHL4D8vFGD34hP45JazF7lzDon+JwzQfHT0j6QVGYAGEfCj4yL71Kbx7l7pJjxe+GA6S1eFH18sN0QMTL2HKITL2cUA9WBFwqvxAqGg= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(227479698468861)(162533806227266)(228905959029699)(17755550239193); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(10201501046)(3231022)(3002001)(93006095)(93001095)(100000703101)(100105400095)(6055026)(6041248)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123555025)(20161123558100)(20161123564025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:CS1PR8401MB0406; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:CS1PR8401MB0406; X-Forefront-PRVS: 04916EA04C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6009001)(6049001)(376002)(39860400002)(346002)(199003)(24454002)(45984002)(189002)(50986999)(83506002)(33646002)(68736007)(76176999)(54356999)(16576012)(54906003)(36756003)(25786009)(58126008)(77096006)(6486002)(65826007)(86362001)(31696002)(2950100002)(31686004)(23676003)(6246003)(575784001)(229853002)(97736004)(93886005)(316002)(67846002)(5660300001)(47776003)(110136005)(65806001)(65956001)(101416001)(189998001)(66066001)(6666003)(105586002)(3846002)(106356001)(6306002)(8676002)(81166006)(81156014)(478600001)(64126003)(50466002)(45080400002)(8666007)(6116002)(4326008)(966005)(7736002)(8936002)(53936002)(2906002)(305945005)(53546010)(2870700001)(16526018); DIR:OUT; SFP:1102; SCL:1; SRVR:CS1PR8401MB0406; H:[10.0.2.15]; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: hpe.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtDUzFQUjg0MDFNQjA0MDY7MjM6cE0vczhNeW1HcFpvUjhwQzdOM0dkayta?= =?utf-8?B?b0VQNkhwWm9IZzZ6U1c0TmY0WC81T1F6eStxMk96OGJPYko4OUc3SHdXNlBI?= =?utf-8?B?STZtUFVtVTVpUDlNTm5qV095MjVINDlseXZqNm9OTTk0Zk9sTEVlVDJKV0h6?= =?utf-8?B?MGtJMThNK0FxNEwxaElwdDYzUkRMVnlQYkY3OEJzeVMxMUgyUUhTbFZzYVY1?= =?utf-8?B?bno5Y1B6SEMxaDJScXpOc3ZOZGJoNUFHc3A5SCt1Q3FXbzJscldmV0NvWDlM?= =?utf-8?B?dSszMTg5dE1OYnJMdTk5U2p6Sy90QmQxQlRib1BVYlF4a0Y1U0NuNVJBcWxM?= =?utf-8?B?MHdZdlZpa0RYb0pYUitIbTJ1TDMyTldSSFFqSExDajFIbWswNmtDUi80L1Y5?= =?utf-8?B?SWZBWnk1dUh6eHlGRmF4QUMwYWl0N2QrakRUZ0QwTzV0T1RIRWs5dnpaaDNB?= =?utf-8?B?UEZNMHJsNXZvaVdPTXMyYXFHZTgyTEdrSkpkd3dtb2FMOHhyWmd1VFQ1WUVs?= =?utf-8?B?bVdGeEdQYXZHVjh6YzFKbzJHV1ZOeHJNVzZlc0ZtTGlSK3lFSmV1T3lUaXRo?= =?utf-8?B?WFRSdk1IUGYvSVJnLzFEWnlrc2N0em5rcXEwN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sb3LPOk9rDg/BLo9xbqkp77o0AiAuGAeF8/9G7fRtXeydt+4mG1OuNup2dpBwD55KgT//kd/m8nUoFdaDAWawpwEOl3DNJ+fLeU9KfuWhbrVlIz47JM9+aYfFgBt2+AjuvNOsDqQTOPlQ2GBTxz5G3YZH4y9Nz9WKQ=; 24:zGYvNZISe5Y04/tanJLz79owXRULTCOxTXKcJkZc0gjMNZz9297jAUitCAcphsfDnxZQ2ZaiOJmfBoIUxnLaORm/Kpn9nyk03+OXkjDo/jc=; 7:xv9E6DLG7dQsnaJNu/aE5a1jyRAb0jvwtl/f5spCm0XULiBGWo0JKBZF1bhfpfSvPn4IU8CKZRRmT3RlamebrebBN34Oe63dpNBUtvmyxIDPPRTzEQIkcy0YkeNbxN1fesAbosclcJIybwjXYpP6AmSVY5yg5QO96o5g7zMh0i705tjlWfAmM9LhFJVs/27D6AwEHLwpw5mPaF5JX82KyLGdr1QOZK4rRv3Fn3waFhjLcA8DDaB+n9MiLPNuktoZ SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2017 16:51:22.4648 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 760a4fe1-0102-43b3-3fa8-08d52b7ff03d X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 105b2061-b669-4b31-92ac-24d304d195dc X-MS-Exchange-Transport-CrossTenantHeadersStamped: CS1PR8401MB0406 X-OriginatorOrg: hpe.com Subject: Re: [RFC 1/1] 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: Tue, 14 Nov 2017 16:48:00 -0000 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit On 11/14/2017 09:30 AM, Paulo Alcantara wrote: > Hi Andrew, > > On 14/11/2017 12:01, Andrew Fish wrote: > C> Paulo, >> >> Cool feature. How does this code deal with VC++ that code does not >> store the frame pointer and requires symbols to unwind. > > I haven't tested in with MSVC, so I'd hope to get some help from Intel's > guys to help supporting and testing it :-) > > Regarding the symbols, I performed some tests by writing a userspace > PE/COFF application [1] and tried to: > > (a) handle the RUNTIME_FUNCTION entries in exception table (.pdata > section) to find the function starting address and then its respective > symbol name in COFF symbol table. > > (b) Walk through UNWIND_INFO entries in .xdata section to figure out > which CPU register a function used as a frame pointer or if it didn't > use any at > all. > > The problem I had with (a) was that the COFF symbol table is not mapped > directory into the image's address space -- that is, the > "PointerToSymbolTable" in File Header *should* be 0 as per PE/COFF > format specific when handling an executable file rather a object file. > Additionally, if it's non-zero, it contains a file offset rather than a > RVA address, so impossible to parse it at runtime. > > In (b), I realized that the CodeView format data in debug directory > should be kept in a separate file (PDB file?) and they aren't mapped > into image's address space as well. > > I don't have so much experience with PE/COFF format, so please correct > me if I'm mistaken. > You are correct that unfortunately, Microsoft's compilers don't put symbolic information in the executable file, they put it in a separate PDB file. And the PDB file format is not documented (although the Wine project has reverse engineered parts of it) and changes with different compiler versions. I've struggled with it before, and concluded that the only feasible way to parse it is to use the APIs Microsoft provides for that purpose, such as dbghelp.dll. That doesn't work inside a BIOS, of course. It is possible to define a simple, compiler-agnostic symbol table format and write a build-time tool to extract symbol data from the PDB files, convert it, and insert it into each module. GenFw is a handy place to generate symbol data, since it's reformatting the images already. I actually have code which does this.... I'd have to get permission from my company's Open Source Review Board to release it, though. That would take time. Brian > IMHO, there should be exist a function like AsmGetFrameAddress() and/or > AsmGetStackAddress() which would get implemented for both GCC and MSVC > toolchains. > > Thank you very much for your comments! > >> Also on the page fault you can print the fault address since it is in >> CR2. > > Good point! We should also do that. > >> It should be possible to post process the text file and make a >> symbolicated backtrace. > > Yes. > > Thanks! > Paulo > >> >> Thanks, >> >> Andrew Fish >> >>> On Nov 14, 2017, at 4:47 AM, Paulo Alcantara wrote: >>> >>> This patch adds stack trace support during a X64 CPU exception. >>> >>> It will dump out back trace, stack contents as well as image module >>> names that were part of the call stack. >>> >>> Contributed-under: TianoCore Contribution Agreement 1.1 >>> Cc: Eric Dong >>> Cc: Laszlo Ersek >>> Signed-off-by: Paulo Alcantara >>> --- >>> UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c >>> | 344 +++++++++++++++++++- >>> 1 file changed, 342 insertions(+), 2 deletions(-) >>> >>> diff --git >>> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c >>> >>> index 65f0cff680..7048247be3 100644 >>> --- >>> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c >>> +++ >>> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c >>> @@ -14,6 +14,11 @@ >>> >>> #include "CpuExceptionCommon.h" >>> >>> +// >>> +// Unknown PDB file name >>> +// >>> +GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mUnknownPdbFileName = >>> "????"; >>> + >>> /** >>>    Return address map of exception handler template so that C code >>> can generate >>>    exception tables. >>> @@ -243,6 +248,325 @@ DumpCpuContext ( >>> } >>> >>> /** >>> +  Dump stack contents. >>> + >>> +  @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 = PeCoffLoaderGetPdbPointer ((VOID *)ImageBase); >>> +  if (PdbPointer == NULL) { >>> +    // >>> +    // No PDB file name found. Set it to an unknown file name. >>> +    // >>> +    *PdbFileName = (CHAR8 *)mUnknownPdbFileName; >>> +    if (PdbAbsoluteFilePath != NULL) { >>> +      *PdbAbsoluteFilePath = NULL; >>> +    } >>> +  } else { >>> +    // >>> +    // Get file name portion out of PDB file in PE/COFF image >>> +    // >>> +    Str = (CHAR8 *)((UINTN)PdbPointer + >>> +                    AsciiStrLen ((CHAR8 *)PdbPointer) - sizeof *Str); >>> +    for (; *Str != '/' && *Str != '\\'; Str--) { >>> +      ; >>> +    } >>> + >>> +    // >>> +    // Set PDB file name (also skip trailing path separator: '/' or >>> '\\') >>> +    // >>> +    *PdbFileName = Str + 1; >>> + >>> +    if (PdbAbsoluteFilePath != NULL) { >>> +      // >>> +      // Set absolute file path of PDB file >>> +      // >>> +      *PdbAbsoluteFilePath = PdbPointer; >>> +    } >>> +  } >>> +} >>> + >>> +/** >>> +  Dump stack contents. >>> + >>> +  @param[in]  CurrentRsp         Current stack pointer address. >>> +  @param[in]  UnwondStacksCount  Count of unwond stack frames. >>> +**/ >>> +STATIC >>> +VOID >>> +DumpStackContents ( >>> +  IN UINT64  CurrentRsp, >>> +  IN INTN    UnwondStacksCount >>> +  ) >>> +{ >>> +  if (UnwondStacksCount == 0) { >>> +    return; >>> +  } >>> + >>> +  // >>> +  // Dump out stack contents >>> +  // >>> +  InternalPrintMessage ("\nStack dump:\n"); >>> +  while (UnwondStacksCount-- > 0) { >>> +    InternalPrintMessage ( >>> +      "0x%016lx: %016lx %016lx\n", >>> +      CurrentRsp, >>> +      *(UINT64 *)CurrentRsp, >>> +      *(UINT64 *)((UINTN)CurrentRsp + 8) >>> +      ); >>> + >>> +    // >>> +    // As per Microsoft x64 ABI, the stack pointer must be aligned >>> on a 16 byte >>> +    // boundary. >>> +    // >>> +    CurrentRsp = CurrentRsp + 16; >>> +  } >>> +} >>> + >>> +/** >>> +  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; >>> + >>> +  // >>> +  // Set current RIP address >>> +  // >>> +  Rip = SystemContext.SystemContextX64->Rip; >>> + >>> +  // >>> +  // Set current frame pointer address >>> +  // >>> +  Rbp = SystemContext.SystemContextX64->Rbp; >>> + >>> +  // >>> +  // Get initial PE/COFF image base address from current RIP >>> +  // >>> +  ImageBase = PeCoffSearchImageBase (Rip); >>> +  if (ImageBase == 0) { >>> +    InternalPrintMessage ("!!!! Could not find image module names. >>> !!!!"); >>> +    return; >>> +  } >>> + >>> +  // >>> +  // Get initial PE/COFF image's entry point >>> +  // >>> +  Status = PeCoffLoaderGetEntryPoint ((VOID *)ImageBase, &EntryPoint); >>> +  if (EFI_ERROR (Status)) { >>> +    EntryPoint = 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 != NULL) { >>> +    InternalPrintMessage ( >>> +      "\n%a (ImageBase=0x%016lx, EntryPoint=0x%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 = *(UINT64 *)((UINTN)Rbp + 8); >>> + >>> +    // >>> +    // Check if RIP is within another PE/COFF image base address >>> +    // >>> +    if (Rip < ImageBase) { >>> +      // >>> +      // Search for the respective PE/COFF image based on RIP >>> +      // >>> +      ImageBase = PeCoffSearchImageBase (Rip); >>> +      if (ImageBase == 0) { >>> +        // >>> +        // Stop stack trace >>> +        // >>> +        break; >>> +      } >>> + >>> +      // >>> +      // Get PE/COFF image's entry point >>> +      // >>> +      Status = PeCoffLoaderGetEntryPoint ((VOID *)ImageBase, >>> &EntryPoint); >>> +      if (EFI_ERROR (Status)) { >>> +        EntryPoint = NULL; >>> +      } >>> + >>> +      // >>> +      // Get file name and absolute path of PDB file >>> +      // >>> +      GetPdbFileName (ImageBase, &PdbAbsoluteFilePath, &PdbFileName); >>> + >>> +      // >>> +      // Print out image module name (if any) >>> +      // >>> +      if (PdbAbsoluteFilePath != NULL) { >>> +        InternalPrintMessage ( >>> +          "%a (ImageBase=0x%016lx, EntryPoint=0x%016lx):\n", >>> +          PdbFileName, >>> +          ImageBase, >>> +          (UINTN)EntryPoint >>> +          ); >>> +        InternalPrintMessage ("%a\n", PdbAbsoluteFilePath); >>> +      } >>> +    } >>> + >>> +    // >>> +    // Unwind the stack >>> +    // >>> +    Rbp = *(UINT64 *)(UINTN)Rbp; >>> +  } >>> +} >>> + >>> +/** >>> +  Dump stack trace. >>> + >>> +  @param[in]  SystemContext      Pointer to EFI_SYSTEM_CONTEXT. >>> +  @param[out] UnwondStacksCount  Count of unwond stack frames. >>> +**/ >>> +STATIC >>> +VOID >>> +DumpStackTrace ( >>> +  IN  EFI_SYSTEM_CONTEXT   SystemContext, >>> +  OUT INTN                 *UnwondStacksCount >>> +  ) >>> +{ >>> +  UINT64  Rip; >>> +  UINT64  Rbp; >>> +  UINTN   ImageBase; >>> +  CHAR8   *PdbFileName; >>> + >>> +  // >>> +  // Initialize count of unwond stacks >>> +  // >>> +  *UnwondStacksCount = 0; >>> + >>> +  // >>> +  // Set current RIP address >>> +  // >>> +  Rip = SystemContext.SystemContextX64->Rip; >>> + >>> +  // >>> +  // Set current frame pointer address >>> +  // >>> +  Rbp = SystemContext.SystemContextX64->Rbp; >>> + >>> +  // >>> +  // Get initial PE/COFF image base address from current RIP >>> +  // >>> +  ImageBase = PeCoffSearchImageBase (Rip); >>> +  if (ImageBase == 0) { >>> +    InternalPrintMessage ("!!!! Could not find backtrace >>> information. !!!!"); >>> +    return; >>> +  } >>> + >>> +  // >>> +  // Get PDB file name from initial PE/COFF image >>> +  // >>> +  GetPdbFileName (ImageBase, NULL, &PdbFileName); >>> + >>> +  // >>> +  // Print out back trace >>> +  // >>> +  InternalPrintMessage ("\nBack 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", >>> +      *UnwondStacksCount, >>> +      Rip, >>> +      ImageBase, >>> +      Rip - ImageBase - 1, >>> +      Rbp, >>> +      PdbFileName >>> +      ); >>> + >>> +    // >>> +    // Set RIP with return address from current stack frame >>> +    // >>> +    Rip = *(UINT64 *)((UINTN)Rbp + 8); >>> + >>> +    // >>> +    // Check if RIP is within another PE/COFF image base address >>> +    // >>> +    if (Rip < ImageBase) { >>> +      // >>> +      // Search for the respective PE/COFF image based on RIP >>> +      // >>> +      ImageBase = PeCoffSearchImageBase (Rip); >>> +      if (ImageBase == 0) { >>> +        // >>> +        // Stop stack trace >>> +        // >>> +        break; >>> +      } >>> + >>> +      // >>> +      // Get PDB file name >>> +      // >>> +      GetPdbFileName (ImageBase, NULL, &PdbFileName); >>> +    } >>> + >>> +    // >>> +    // Unwind the stack >>> +    // >>> +    Rbp = *(UINT64 *)(UINTN)Rbp; >>> + >>> +    // >>> +    // Increment count of unwond stacks >>> +    // >>> +    (*UnwondStacksCount)++; >>> +  } >>> +} >>> + >>> +/** >>>    Display CPU information. >>> >>>    @param ExceptionType  Exception type. >>> @@ -254,9 +578,25 @@ DumpImageAndCpuContent ( >>>    IN EFI_SYSTEM_CONTEXT   SystemContext >>>    ) >>> { >>> +  INTN UnwondStacksCount; >>> + >>> +  // >>> +  // Dump CPU context >>> +  // >>>    DumpCpuContext (ExceptionType, SystemContext); >>> + >>> +  // >>> +  // Dump stack trace >>> +  // >>> +  DumpStackTrace (SystemContext, &UnwondStacksCount); >>> + >>> +  // >>> +  // 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, >>> UnwondStacksCount); >>> } >>> -- >>> 2.11.0 >>> >>> _______________________________________________ >>> edk2-devel mailing list >>> edk2-devel@lists.01.org >>> https://lists.01.org/mailman/listinfo/edk2-devel >> > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel -- Brian J. Johnson Enterprise X86 Lab Hewlett Packard Enterprise brian.johnson@hpe.com