[compiler-rt] [compiler-rt] Fix frame numbering for unparsable frames. (PR #148278)

Jesse Schwartzentruber via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 19 06:39:56 PDT 2025


https://github.com/jschwartzentruber updated https://github.com/llvm/llvm-project/pull/148278

>From 0b3e75a5a7133df8b2e2d3e24d2fe169eb29f790 Mon Sep 17 00:00:00 2001
From: Jesse Schwartzentruber <truber at mozilla.com>
Date: Mon, 18 Aug 2025 15:18:36 -0400
Subject: [PATCH] [compiler-rt] Fix frame numbering for unparsable frames.

This can happen when JIT code is run, and we can't symbolize those
frames, but they should remain numbered in the stack.
---
 .../lib/asan/scripts/asan_symbolize.py        | 34 ++++++++++++-------
 .../anon_wrong_frame_number.cpp               |  1 -
 2 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/compiler-rt/lib/asan/scripts/asan_symbolize.py b/compiler-rt/lib/asan/scripts/asan_symbolize.py
index 058a1614b55e6..8ecd66c745119 100755
--- a/compiler-rt/lib/asan/scripts/asan_symbolize.py
+++ b/compiler-rt/lib/asan/scripts/asan_symbolize.py
@@ -507,20 +507,29 @@ def symbolize_address(self, addr, binary, offset, arch):
         assert result
         return result
 
-    def get_symbolized_lines(self, symbolized_lines, inc_frame_counter=True):
+    def get_symbolized_lines(self, symbolized_lines):
         if not symbolized_lines:
-            if inc_frame_counter:
-                self.frame_no += 1
-            return [self.current_line]
-        else:
-            assert inc_frame_counter
-            result = []
-            for symbolized_frame in symbolized_lines:
-                result.append(
-                    "    #%s %s" % (str(self.frame_no), symbolized_frame.rstrip())
+            # If it is an unparsable frame, but contains a frame counter and address
+            # replace the frame counter so the stack is still consistent.
+            unknown_stack_frame_format = r"^( *#([0-9]+) +)(0x[0-9a-f]+) +.*"
+            match = re.match(unknown_stack_frame_format, self.current_line)
+            if match:
+                rewritten_line = (
+                    self.current_line[: match.start(2)]
+                    + str(self.frame_no)
+                    + self.current_line[match.end(2) :]
                 )
                 self.frame_no += 1
-            return result
+                return [rewritten_line]
+            # Not a frame line so don't increment the frame counter.
+            return [self.current_line]
+        result = []
+        for symbolized_frame in symbolized_lines:
+            result.append(
+                "    #%s %s" % (str(self.frame_no), symbolized_frame.rstrip())
+            )
+            self.frame_no += 1
+        return result
 
     def process_logfile(self):
         self.frame_no = 0
@@ -546,8 +555,7 @@ def process_line_posix(self, line):
         match = re.match(stack_trace_line_format, line)
         if not match:
             logging.debug('Line "{}" does not match regex'.format(line))
-            # Not a frame line so don't increment the frame counter.
-            return self.get_symbolized_lines(None, inc_frame_counter=False)
+            return self.get_symbolized_lines(None)
         logging.debug(line)
         _, frameno_str, addr, binary, offset = match.groups()
 
diff --git a/compiler-rt/test/asan/TestCases/Posix/asan_symbolize_script/anon_wrong_frame_number.cpp b/compiler-rt/test/asan/TestCases/Posix/asan_symbolize_script/anon_wrong_frame_number.cpp
index 0f47f44738520..157fe11d2224e 100644
--- a/compiler-rt/test/asan/TestCases/Posix/asan_symbolize_script/anon_wrong_frame_number.cpp
+++ b/compiler-rt/test/asan/TestCases/Posix/asan_symbolize_script/anon_wrong_frame_number.cpp
@@ -5,7 +5,6 @@
 // UNSUPPORTED: aarch64
 // UNSUPPORTED: darwin
 // UNSUPPORTED: ios
-// XFAIL: *
 
 // RUN: %clangxx_asan -O0 -g %s -o %t
 // RUN: %env_asan_opts=symbolize=0 not %run %t DUMMY_ARG > %t.asan_report 2>&1



More information about the llvm-commits mailing list