Skip to content

Commit f5ee068

Browse files
jschwartzentrubertysmith
authored andcommitted
fix: [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. see: llvm/llvm-project#148278
1 parent 4a94a22 commit f5ee068

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

src/ffpuppet/asan_symbolize.py

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import argparse
2424
import bisect
2525
import errno
26-
import getopt
2726
import logging
2827
import os
2928
import re
@@ -39,6 +38,7 @@
3938
allow_system_symbolizer = True
4039
force_system_symbolizer = False
4140

41+
4242
# FIXME: merge the code that calls fix_filename().
4343
def fix_filename(file_name):
4444
if fix_filename_patterns:
@@ -508,20 +508,29 @@ def symbolize_address(self, addr, binary, offset, arch):
508508
assert result
509509
return result
510510

511-
def get_symbolized_lines(self, symbolized_lines, inc_frame_counter=True):
511+
def get_symbolized_lines(self, symbolized_lines):
512512
if not symbolized_lines:
513-
if inc_frame_counter:
514-
self.frame_no += 1
515-
return [self.current_line]
516-
else:
517-
assert inc_frame_counter
518-
result = []
519-
for symbolized_frame in symbolized_lines:
520-
result.append(
521-
" #%s %s" % (str(self.frame_no), symbolized_frame.rstrip())
513+
# If it is an unparsable frame, but contains a frame counter and address
514+
# replace the frame counter so the stack is still consistent.
515+
unknown_stack_frame_format = r"^( *#([0-9]+) +)(0x[0-9a-f]+) +.*"
516+
match = re.match(unknown_stack_frame_format, self.current_line)
517+
if match:
518+
rewritten_line = (
519+
self.current_line[: match.start(2)]
520+
+ str(self.frame_no)
521+
+ self.current_line[match.end(2) :]
522522
)
523523
self.frame_no += 1
524-
return result
524+
return [rewritten_line]
525+
# Not a frame line so don't increment the frame counter.
526+
return [self.current_line]
527+
result = []
528+
for symbolized_frame in symbolized_lines:
529+
result.append(
530+
" #%s %s" % (str(self.frame_no), symbolized_frame.rstrip())
531+
)
532+
self.frame_no += 1
533+
return result
525534

526535
def process_logfile(self):
527536
self.frame_no = 0
@@ -547,8 +556,7 @@ def process_line_posix(self, line):
547556
match = re.match(stack_trace_line_format, line)
548557
if not match:
549558
logging.debug('Line "{}" does not match regex'.format(line))
550-
# Not a frame line so don't increment the frame counter.
551-
return self.get_symbolized_lines(None, inc_frame_counter=False)
559+
return self.get_symbolized_lines(None)
552560
logging.debug(line)
553561
_, frameno_str, addr, binary, offset = match.groups()
554562

@@ -604,6 +612,7 @@ def _load_plugin_from_file_impl_py_gt_2(self, file_path, globals_space):
604612
def load_plugin_from_file(self, file_path):
605613
logging.info('Loading plugins from "{}"'.format(file_path))
606614
globals_space = dict(globals())
615+
607616
# Provide function to register plugins
608617
def register_plugin(plugin):
609618
logging.info("Registering plugin %s", plugin.get_name())
@@ -780,9 +789,13 @@ def __str__(self):
780789
arch=self.arch,
781790
start_addr=self.start_addr,
782791
end_addr=self.end_addr,
783-
module_path=self.module_path
784-
if self.module_path == self.module_path_for_symbolization
785-
else "{} ({})".format(self.module_path_for_symbolization, self.module_path),
792+
module_path=(
793+
self.module_path
794+
if self.module_path == self.module_path_for_symbolization
795+
else "{} ({})".format(
796+
self.module_path_for_symbolization, self.module_path
797+
)
798+
),
786799
uuid=self.uuid,
787800
)
788801

0 commit comments

Comments
 (0)