failed attempt at trace2line

This commit is contained in:
Ciro Santilli
2018-09-05 09:47:12 +01:00
parent 485c071a4d
commit df47eba450
2 changed files with 54 additions and 23 deletions

View File

@@ -3,7 +3,7 @@
while getopts "h${common_getopts_flags}" OPT; do
case "$OPT" in
h)
echo "https://github.com/cirosantilli/linux-kernel-module-cheat#getvar" 2>&1
echo "https://github.com/cirosantilli/linux-kernel-module-cheat#bisection" 2>&1
exit
;;
?)

View File

@@ -1,22 +1,53 @@
#!/usr/bin/env bash
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
while getopts "${common_getopts_flags}" OPT; do
case "$OPT" in
?)
common_getopts_case "$OPT"
;;
esac
done
common_setup
kernel_dir="${common_build_dir}/linux-custom"
(
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_host_dir}/bin/${common_arch}-linux-addr2line" -e "${common_vmlinux}" -fp | \
sed -E "s|at ${kernel_dir}/(\./\|)||" | \
uniq -c \
> "${common_run_dir}/trace-lines.txt"
#!/usr/bin/env python3
import os
import re
import subprocess
import sys
import common
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
# sed -E "s|at ${common.linux_build_dir}/(\./\|)||"
# uniq -c
# sys.exit()