Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 30 additions & 17 deletions compiler-rt/lib/asan/scripts/asan_symbolize.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import argparse
import bisect
import errno
import getopt
import logging
import os
import re
Expand All @@ -38,6 +37,7 @@
allow_system_symbolizer = True
force_system_symbolizer = False


# FIXME: merge the code that calls fix_filename().
def fix_filename(file_name):
if fix_filename_patterns:
Expand Down Expand Up @@ -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
Expand All @@ -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()

Expand Down Expand Up @@ -603,6 +611,7 @@ def _load_plugin_from_file_impl_py_gt_2(self, file_path, globals_space):
def load_plugin_from_file(self, file_path):
logging.info('Loading plugins from "{}"'.format(file_path))
globals_space = dict(globals())

# Provide function to register plugins
def register_plugin(plugin):
logging.info("Registering plugin %s", plugin.get_name())
Expand Down Expand Up @@ -779,9 +788,13 @@ def __str__(self):
arch=self.arch,
start_addr=self.start_addr,
end_addr=self.end_addr,
module_path=self.module_path
if self.module_path == self.module_path_for_symbolization
else "{} ({})".format(self.module_path_for_symbolization, self.module_path),
module_path=(
self.module_path
if self.module_path == self.module_path_for_symbolization
else "{} ({})".format(
self.module_path_for_symbolization, self.module_path
)
),
uuid=self.uuid,
)

Expand Down