give up on trac2line full porting, just call sh script for now

This commit is contained in:
Ciro Santilli
2018-09-06 08:01:58 +01:00
parent df47eba450
commit 24b539f152
4 changed files with 88 additions and 41 deletions

View File

@@ -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())) argcopy.__dict__ = dict(list(defaults.items()) + list(argcopy.__dict__.items()) + list(extra_args.items()))
return argcopy 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. 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 = {} extra_env = {}
env = os.environ.copy() env = os.environ.copy()
env.update(extra_env) 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: # Otherwise Ctrl + C gives:
# - ugly Python stack trace for gem5 (QEMU takes over terminal and is fine). # - 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 # - 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

8
runtc
View File

@@ -1,5 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os
import subprocess import subprocess
import sys import sys
@@ -30,4 +31,9 @@ parser.add_argument(
nargs='*' nargs='*'
) )
args = common.setup(parser) 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,
))

View File

@@ -1,5 +1,12 @@
#!/usr/bin/env python3 #!/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 os
import re import re
import subprocess 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' 'description': 'Convert an execution trace containing PC values into the Linux kernel linex executed'
}) })
args = common.setup(parser) args = common.setup(parser)
if args.gem5: sys.exit(subprocess.Popen([
def get_pc(line): os.path.join(common.root_dir, 'trace2line.sh'),
# pc_re = 'true' if args.gem5 else 'false',
# stdin = sed -r 's/^.* (0x[^. ]*)[. ].*/\1/' "$common_trace_txt_file") common.trace_txt_file,
pass common.get_toolchain_tool('addr2line'),
else: common.vmlinux,
def get_pc(line): common.run_dir,
return line.split('=')[-1] ]).wait())
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
# sed -E "s|at ${common.linux_build_dir}/(\./\|)||" # This was the full conversion attempt.
# uniq -c
# if args.gem5:
# def get_pc(line):
# # TODO
# sys.exit() # # 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

23
trace2line.sh Executable file
View File

@@ -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"