Skip to content
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

Improve tools/stack_decode.py #8041

Merged
merged 5 commits into from
Aug 27, 2019
Merged
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
20 changes: 13 additions & 7 deletions tools/stack_decode.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

# Call addr2line as needed to resolve addresses in a stack trace. The addresses
# will be replaced if they can be resolved into file and line numbers. The
Expand All @@ -11,7 +11,6 @@
# In each case this script will add file and line information to any backtrace log
# lines found and echo back all non-Backtrace lines untouched.

from __future__ import print_function
import collections
import re
import subprocess
Expand All @@ -24,10 +23,14 @@
# any nonmatching lines unmodified. End when EOF received.
def decode_stacktrace_log(object_file, input_source):
traces = {}
# Match something like [backtrace]
# bazel-out/local-dbg/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:84]
# Match something like:
# [backtrace] [bazel-out/local-dbg/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:84]
backtrace_marker = "\[backtrace\] [^\s]+"
stackaddr_re = re.compile("%s #\d+: .* \[(0x[0-9a-fA-F]+)\]$" % backtrace_marker)
# Match something like:
# ${backtrace_marker} #10: SYMBOL [0xADDR]
# or:
# ${backtrace_marker} #10: [0xADDR]
stackaddr_re = re.compile("%s #\d+:(?: .*)? \[(0x[0-9a-fA-F]+)\]$" % backtrace_marker)

try:
while True:
Expand All @@ -53,7 +56,7 @@ def decode_stacktrace_log(object_file, input_source):
#
# Returns list of result lines
def run_addr2line(obj_file, addr_to_resolve):
return subprocess.check_output(["addr2line", "-Cpie", obj_file, addr_to_resolve])
return subprocess.check_output(["addr2line", "-Cpie", obj_file, addr_to_resolve]).decode('utf-8')


# Because of how bazel compiles, addr2line reports file names that begin with
Expand All @@ -69,7 +72,10 @@ def trim_proc_cwd(file_and_line_number):
decode_stacktrace_log(sys.argv[2], sys.stdin)
sys.exit(0)
elif len(sys.argv) > 1:
rununder = subprocess.Popen(sys.argv[1:], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
rununder = subprocess.Popen(sys.argv[1:],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True)
decode_stacktrace_log(sys.argv[1], rununder.stdout)
rununder.wait()
sys.exit(rununder.returncode) # Pass back test pass/fail result
Expand Down