From 24b539f1528daadd0f97914a70e25c59076d2f3f Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Thu, 6 Sep 2018 08:01:58 +0100 Subject: [PATCH] give up on trac2line full porting, just call sh script for now --- common.py | 13 ++++++-- runtc | 8 ++++- trace2line | 85 ++++++++++++++++++++++++++++----------------------- trace2line.sh | 23 ++++++++++++++ 4 files changed, 88 insertions(+), 41 deletions(-) create mode 100755 trace2line.sh diff --git a/common.py b/common.py index 112c705..496c285 100644 --- a/common.py +++ b/common.py @@ -200,7 +200,15 @@ def resolve_args(defaults, args, extra_args): argcopy.__dict__ = dict(list(defaults.items()) + list(argcopy.__dict__.items()) + list(extra_args.items())) return argcopy -def run_cmd(cmd, cmd_file=None, out_file=None, show_stdout=True, extra_env=None, **kwargs): +def run_cmd( + cmd, + cmd_file=None, + out_file=None, + show_stdout=True, + show_cmd=True, + extra_env=None, + **kwargs + ): ''' Run a command. Write the command to stdout before running it. @@ -235,7 +243,8 @@ def run_cmd(cmd, cmd_file=None, out_file=None, show_stdout=True, extra_env=None, extra_env = {} env = os.environ.copy() env.update(extra_env) - print_cmd(cmd, cmd_file, extra_env=extra_env) + if show_cmd: + print_cmd(cmd, cmd_file, extra_env=extra_env) # Otherwise Ctrl + C gives: # - ugly Python stack trace for gem5 (QEMU takes over terminal and is fine). # - kills Python, and that then kills GDB: https://stackoverflow.com/questions/19807134/does-python-always-raise-an-exception-if-you-do-ctrlc-when-a-subprocess-is-exec diff --git a/runtc b/runtc index b7e3fd9..fcb14cb 100755 --- a/runtc +++ b/runtc @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +import os import subprocess import sys @@ -30,4 +31,9 @@ parser.add_argument( nargs='*' ) args = common.setup(parser) -sys.exit(subprocess.Popen([common.get_toolchain_tool(args.tool)] + args.extra_args).wait()) +sys.exit(common.run_cmd( + [common.get_toolchain_tool(args.tool)] + args.extra_args, + cmd_file=os.path.join(common.run_dir, 'runtc.sh'), + cwd=common.linux_variant_dir, + show_cmd=False, +)) diff --git a/trace2line b/trace2line index 1f8dd98..9a7c542 100755 --- a/trace2line +++ b/trace2line @@ -1,5 +1,12 @@ #!/usr/bin/env python3 +''' +TODO port this to Python fully. I started it, but then it was hanging on some +IO blocking annoyance in the pipeline, and I don't have the time to deal with +it, so I'm just going to forward the common options to the old shell script for +now... +''' + import os import re import subprocess @@ -11,43 +18,45 @@ parser = common.get_argparse(argparse_args={ 'description': 'Convert an execution trace containing PC values into the Linux kernel linex executed' }) args = common.setup(parser) -if args.gem5: - def get_pc(line): - # pc_re = - # stdin = sed -r 's/^.* (0x[^. ]*)[. ].*/\1/' "$common_trace_txt_file") - pass -else: - def get_pc(line): - return line.split('=')[-1] -with \ - subprocess.Popen( - [ - common.get_toolchain_tool('addr2line'), - '-e', - common.vmlinux, - '-f', - '-p', - ], - stdout=subprocess.PIPE, - stdin=subprocess.PIPE, - ) as proc, \ - open(common.trace_txt_file, 'r') as infile, \ - open(os.path.join(common.run_dir, 'trace-lines.txt'), 'w') as outfile \ - : - i = 0; - __import__('ipdb').set_trace() - for in_line in infile: - print(i) - proc.stdin.write(get_pc(in_line).encode()) - proc.stdin.flush() - stdout = proc.stdout.read() - outfile.write(stdout.decode()) - i+=1 +sys.exit(subprocess.Popen([ + os.path.join(common.root_dir, 'trace2line.sh'), + 'true' if args.gem5 else 'false', + common.trace_txt_file, + common.get_toolchain_tool('addr2line'), + common.vmlinux, + common.run_dir, +]).wait()) - # sed -E "s|at ${common.linux_build_dir}/(\./\|)||" - # uniq -c +# This was the full conversion attempt. - - - -# sys.exit() +# if args.gem5: +# def get_pc(line): +# # TODO +# # stdin = sed -r 's/^.* (0x[^. ]*)[. ].*/\1/' "$common_trace_txt_file") +# pass +# else: +# def get_pc(line): +# return line.split('=')[-1] +# with \ +# subprocess.Popen( +# [ +# common.get_toolchain_tool('addr2line'), +# '-e', +# common.vmlinux, +# '-f', +# '-p', +# ], +# stdout=subprocess.PIPE, +# stdin=subprocess.PIPE, +# ) as proc, \ +# open(common.trace_txt_file, 'r') as infile, \ +# open(os.path.join(common.run_dir, 'trace-lines.txt'), 'w') as outfile \ +# : +# for in_line in infile: +# proc.stdin.write(get_pc(in_line).encode()) +# proc.stdin.flush() +# stdout = proc.stdout.read() +# outfile.write(stdout.decode()) +# # TODO +# # sed -E "s|at ${common.linux_build_dir}/(\./\|)||" +# # uniq -c diff --git a/trace2line.sh b/trace2line.sh new file mode 100755 index 0000000..949121d --- /dev/null +++ b/trace2line.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +set -eu +common_gem5="$1" +shift +common_trace_txt_file="$1" +shift +common_addr2line="$1" +shift +common_vmlinux="$1" +shift +common_run_dir="$1" +shift +( + if "$common_gem5"; then + sed -r 's/^.* (0x[^. ]*)[. ].*/\1/' "$common_trace_txt_file" + else + sed -r 's/.*pc=//' "$common_trace_txt_file" + fi +) | \ + xargs "${common_addr2line}" -e "${common_vmlinux}" -fp | \ + sed -E "s|at ${common_vmlinux}/(\./\|)||" | \ + uniq -c \ +> "${common_run_dir}/trace-lines.txt"