From df47eba450e23c9de8b75f262b8db3252b778f02 Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Wed, 5 Sep 2018 09:47:12 +0100 Subject: [PATCH] failed attempt at trace2line --- bisect-linux-boot-gem5 | 2 +- trace2line | 75 +++++++++++++++++++++++++++++------------- 2 files changed, 54 insertions(+), 23 deletions(-) diff --git a/bisect-linux-boot-gem5 b/bisect-linux-boot-gem5 index adf144a..6e28652 100755 --- a/bisect-linux-boot-gem5 +++ b/bisect-linux-boot-gem5 @@ -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 ;; ?) diff --git a/trace2line b/trace2line index f4b4404..1f8dd98 100755 --- a/trace2line +++ b/trace2line @@ -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()