[PATCH] D127915: [windows][support] Improve backtrace emitted in crash report without llvm-symbolizer

ben via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 17 09:43:25 PDT 2022


bd1976llvm updated this revision to Diff 437946.
bd1976llvm edited the summary of this revision.
bd1976llvm added a comment.

I have asked around and no one made use of those numbers so I have removed them in the latest diff. However, people would have found the exception code useful so I have added that. Output now looks like:

With llvm-symbolizer:
Stack dump:
0.      Program arguments: C:\\u\\br2\\bin\\ld.lld.exe
Exception Code: 0x80000003
#0 0x00007ff61d276294 (C:\u\br2\bin\ld.lld.exe+0x1f6294)
#1 0x00007ff61d2761dd (C:\u\br2\bin\ld.lld.exe+0x1f61dd)
#2 0x00007ff61d12652c (C:\u\br2\bin\ld.lld.exe+0xa652c)
...

Without llvm-symbolizer:
Stack dump:
0.      Program arguments: C:\\u\\br2\\bin\\ld.lld.exe
Exception Code: 0x80000003
0x00007FF61D276294, C:\u\br2\bin\ld.lld.exe(0x00007FF61D080000) + 0x1F6294 byte(s)
0x00007FF61D2761DD, C:\u\br2\bin\ld.lld.exe(0x00007FF61D080000) + 0x1F61DD byte(s)
0x00007FF61D12652C, C:\u\br2\bin\ld.lld.exe(0x00007FF61D080000) + 0xA652C byte(s)
...


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127915/new/

https://reviews.llvm.org/D127915

Files:
  llvm/lib/Support/Windows/Signals.inc


Index: llvm/lib/Support/Windows/Signals.inc
===================================================================
--- llvm/lib/Support/Windows/Signals.inc
+++ llvm/lib/Support/Windows/Signals.inc
@@ -337,24 +337,24 @@
     OS << format("0x%08lX", static_cast<DWORD>(PC));
 #endif
 
-// Print the parameters.  Assume there are four.
-#if defined(_M_X64) || defined(_M_ARM64)
-    OS << format(" (0x%016llX 0x%016llX 0x%016llX 0x%016llX)",
-            StackFrame.Params[0], StackFrame.Params[1], StackFrame.Params[2],
-            StackFrame.Params[3]);
-#elif defined(_M_IX86) || defined(_M_ARM)
-    OS << format(" (0x%08lX 0x%08lX 0x%08lX 0x%08lX)",
-            static_cast<DWORD>(StackFrame.Params[0]),
-            static_cast<DWORD>(StackFrame.Params[1]),
-            static_cast<DWORD>(StackFrame.Params[2]),
-            static_cast<DWORD>(StackFrame.Params[3]));
-#endif
     // Verify the PC belongs to a module in this process.
     if (!fSymGetModuleBase64(hProcess, PC)) {
       OS << " <unknown module>\n";
       continue;
     }
 
+    IMAGEHLP_MODULE64 M;
+    memset(&M, 0, sizeof(IMAGEHLP_MODULE64));
+    M.SizeOfStruct = sizeof(IMAGEHLP_MODULE64);
+    if (fSymGetModuleInfo64(hProcess, fSymGetModuleBase64(hProcess, PC), &M)) {
+      DWORD64 const disp = PC - M.BaseOfImage;
+      OS << format(", %s(0x%016llX) + 0x%llX byte(s)",
+                   static_cast<char *>(M.ImageName), M.BaseOfImage,
+                   static_cast<long long>(disp));
+    } else {
+      OS << ", <unknown module>";
+    }
+
     // Print the symbol name.
     char buffer[512];
     IMAGEHLP_SYMBOL64 *symbol = reinterpret_cast<IMAGEHLP_SYMBOL64 *>(buffer);
@@ -369,20 +369,16 @@
     }
 
     buffer[511] = 0;
-    if (dwDisp > 0)
-      OS << format(", %s() + 0x%llX bytes(s)", (const char*)symbol->Name,
-                   dwDisp);
-    else
-      OS << format(", %s", (const char*)symbol->Name);
+    OS << format(", %s() + 0x%llX byte(s)", static_cast<char *>(symbol->Name),
+                 static_cast<long long>(dwDisp));
 
     // Print the source file and line number information.
     IMAGEHLP_LINE64 line = {};
     DWORD dwLineDisp;
     line.SizeOfStruct = sizeof(line);
     if (fSymGetLineFromAddr64(hProcess, PC, &dwLineDisp, &line)) {
-      OS << format(", %s, line %lu", line.FileName, line.LineNumber);
-      if (dwLineDisp > 0)
-        OS << format(" + 0x%lX byte(s)", dwLineDisp);
+      OS << format(", %s, line %lu + 0x%lX byte(s)", line.FileName,
+                   line.LineNumber, dwLineDisp);
     }
 
     OS << '\n';
@@ -821,6 +817,12 @@
 static LONG WINAPI LLVMUnhandledExceptionFilter(LPEXCEPTION_POINTERS ep) {
   Cleanup(true);
 
+  // Write out the exception code.
+  if (ep && ep->ExceptionRecord)
+    llvm::errs() << format("Exception Code: 0x%08X",
+                           ep->ExceptionRecord->ExceptionCode)
+                 << "\n";
+
   // We'll automatically write a Minidump file here to help diagnose
   // the nasty sorts of crashes that aren't 100% reproducible from a set of
   // inputs (or in the event that the user is unable or unwilling to provide a


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127915.437946.patch
Type: text/x-patch
Size: 3123 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220617/6d67a943/attachment.bin>


More information about the llvm-commits mailing list