Skip to content

Commit c3e8617

Browse files
[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.
1 parent bf94c8d commit c3e8617

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

compiler-rt/lib/asan/scripts/asan_symbolize.py

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import argparse
2323
import bisect
2424
import errno
25-
import getopt
2625
import logging
2726
import os
2827
import re
@@ -38,6 +37,7 @@
3837
allow_system_symbolizer = True
3938
force_system_symbolizer = False
4039

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

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

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

@@ -603,6 +611,7 @@ def _load_plugin_from_file_impl_py_gt_2(self, file_path, globals_space):
603611
def load_plugin_from_file(self, file_path):
604612
logging.info('Loading plugins from "{}"'.format(file_path))
605613
globals_space = dict(globals())
614+
606615
# Provide function to register plugins
607616
def register_plugin(plugin):
608617
logging.info("Registering plugin %s", plugin.get_name())
@@ -779,9 +788,13 @@ def __str__(self):
779788
arch=self.arch,
780789
start_addr=self.start_addr,
781790
end_addr=self.end_addr,
782-
module_path=self.module_path
783-
if self.module_path == self.module_path_for_symbolization
784-
else "{} ({})".format(self.module_path_for_symbolization, self.module_path),
791+
module_path=(
792+
self.module_path
793+
if self.module_path == self.module_path_for_symbolization
794+
else "{} ({})".format(
795+
self.module_path_for_symbolization, self.module_path
796+
)
797+
),
785798
uuid=self.uuid,
786799
)
787800

0 commit comments

Comments
 (0)