[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
Wed Jun 15 16:19:41 PDT 2022


bd1976llvm created this revision.
bd1976llvm added reviewers: dblaikie, aganea, pete, MaskRay, rnk.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
bd1976llvm requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Currently the backtrace emitted on windows when llvm-symbolizer is not available looks like:

  PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
  Stack dump:
  0.      Program arguments: c:\\u\\br2\\bin\\ld.lld.exe -o C:\\Users\\BDUNBO~1\\AppData\\Local\\Temp\\lit-tmp-8ymp966z\\tmpztn1fyw1
  0x00007FF64EE51D20 (0x0000000000000083 0x00007FF64EEFCAA1 0x0000000000000000 0x000001750CD01140)
  0x00007FF64EEFC9DB (0x0000000000000000 0x0000000703B8EBA9 0x0000017603357418 0x0000000000000001)
  ...

This is not useful in many circumstance as the program counter (RIP) (the numbers in the left-most column) cannot be easily decoded because the addresses have the containing module's run-time base address added into them, but we don't know what those base addresses are. This change emits a module offset rather than an address.

Example output after this change:

  PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
  Stack dump:
  0.      Program arguments: c:\\u\\br2\\bin\\ld.lld.exe -o C:\\Users\\BDUNBO~1\\AppData\\Local\\Temp\\lit-tmp-8ymp966z\\tmpztn1fyw1
  0x00CEE8F7 (0x00000060 0x00000068 0x00A502D8 0x0666F8E8), c:\u\br2\bin\ld.lld.exe(0x0000000000B70000) + 0x17E8F7 byte(s)
  0x775A6E2C (0x059D64D0 0x775A5DCE 0x00A8E7A8 0x00000000), C:\WINDOWS\SYSTEM32\ntdll.dll(0x0000000077560000) + 0x46E2C byte(s)
  ...

Note that the above output is an example of the output when file and line information cannot be retrieved for symbols. This is reasonably likely, for example if the .pdb files were not shipped with the toolchain binaries. If the file and line info can be retrieved lines like the following would be output:

  0x775A6E2C (0x059D64D0 0x775A5DCE 0x00A8E7A8 0x00000000), C:\WINDOWS\SYSTEM32\ntdll.dll(0x0000000077560000) + 0x46E2C byte(s), RtlAllocateHeap() + 0x109C byte(s)


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
@@ -355,18 +355,6 @@
       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);
@@ -381,16 +369,20 @@
     }
 
     buffer[511] = 0;
-    OS << format(", %s() + 0x%llX byte(s)", static_cast<char *>(symbol->Name),
-                 static_cast<long long>(dwDisp));
+    if (dwDisp > 0)
+      OS << format(", %s() + 0x%llX bytes(s)", (const char*)symbol->Name,
+                   dwDisp);
+    else
+      OS << format(", %s", (const char*)symbol->Name);
 
     // 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 + 0x%lX byte(s)", line.FileName,
-                   line.LineNumber, dwLineDisp);
+      OS << format(", %s, line %lu", line.FileName, line.LineNumber);
+      if (dwLineDisp > 0)
+        OS << format(" + 0x%lX byte(s)", dwLineDisp);
     }
 
     OS << '\n';


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127915.437379.patch
Type: text/x-patch
Size: 1756 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220615/97032ee3/attachment.bin>


More information about the llvm-commits mailing list