From 2e44526d824e8f0da41c21ec4d30b644402ecd4f Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 26 Aug 2019 11:24:44 -0400 Subject: [PATCH 1/5] tools/stack_decode.py: Use 'python2' instead of 'python' Since the script does not work with python3. Signed-off-by: Luke Shumaker --- tools/stack_decode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/stack_decode.py b/tools/stack_decode.py index 3e3c7bd87e7a..b303ff50d9d9 100755 --- a/tools/stack_decode.py +++ b/tools/stack_decode.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2 # 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 From 3f888468002eeb5d264b29f2ce76a4ba534735cd Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 26 Aug 2019 11:29:33 -0400 Subject: [PATCH 2/5] tools/stack_decode.py: Clarify comments on regexps Signed-off-by: Luke Shumaker --- tools/stack_decode.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/stack_decode.py b/tools/stack_decode.py index b303ff50d9d9..0e4cd12967ba 100755 --- a/tools/stack_decode.py +++ b/tools/stack_decode.py @@ -24,9 +24,11 @@ # 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]+" + # Match something like: + # ${backtrace_marker} #10: SYMBOL [0xADDR] stackaddr_re = re.compile("%s #\d+: .* \[(0x[0-9a-fA-F]+)\]$" % backtrace_marker) try: From 00ee946ec8ee03c85d72b5872f91c961b126c599 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 26 Aug 2019 11:31:55 -0400 Subject: [PATCH 3/5] tools/stack_decode.py: backtrace.h doesn't always emit a symbol name Signed-off-by: Luke Shumaker --- tools/stack_decode.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/stack_decode.py b/tools/stack_decode.py index 0e4cd12967ba..df40029be2fc 100755 --- a/tools/stack_decode.py +++ b/tools/stack_decode.py @@ -25,11 +25,13 @@ 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] + # [backtrace] [bazel-out/local-dbg/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:84] backtrace_marker = "\[backtrace\] [^\s]+" # Match something like: # ${backtrace_marker} #10: SYMBOL [0xADDR] - stackaddr_re = re.compile("%s #\d+: .* \[(0x[0-9a-fA-F]+)\]$" % backtrace_marker) + # or: + # ${backtrace_marker} #10: [0xADDR] + stackaddr_re = re.compile("%s #\d+:(?: .*)? \[(0x[0-9a-fA-F]+)\]$" % backtrace_marker) try: while True: From 45f0f354e2eeee9f26a4f23f972293fc6fdc6493 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 27 Aug 2019 13:44:39 -0400 Subject: [PATCH 4/5] tools/stack_decode.py: Migrate to Python 3 Signed-off-by: Luke Shumaker --- tools/stack_decode.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tools/stack_decode.py b/tools/stack_decode.py index df40029be2fc..2f07f75fa4f1 100755 --- a/tools/stack_decode.py +++ b/tools/stack_decode.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/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 @@ -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 @@ -57,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 @@ -73,7 +72,7 @@ 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 From 8e79495bd077e7db9c6e2d0a1aad1212eb6e8125 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 27 Aug 2019 13:54:08 -0400 Subject: [PATCH 5/5] tools/stack_decode.py: Fix formatting complaint Signed-off-by: Luke Shumaker --- tools/stack_decode.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/stack_decode.py b/tools/stack_decode.py index 2f07f75fa4f1..cc22bfd82a39 100755 --- a/tools/stack_decode.py +++ b/tools/stack_decode.py @@ -72,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, text=True) + 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