mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-26 03:31:36 +01:00
give up on trac2line full porting, just call sh script for now
This commit is contained in:
13
common.py
13
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
|
||||
|
||||
8
runtc
8
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,
|
||||
))
|
||||
|
||||
85
trace2line
85
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
|
||||
|
||||
23
trace2line.sh
Executable file
23
trace2line.sh
Executable 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"
|
||||
Reference in New Issue
Block a user