Files
linux-kernel-module-cheat/trace2line
Ciro Santilli 六四事件 法轮功 fe9c31f737 fix run-toolchain, qemu-monitor, trace-boot, trace2line, bisect-linux-boot-gem5. Fixes part of #63
I'm sad no one reported qemu-monitor break, that one is kind of important.

count.out arguments broke it as an init program, since the kernel adds trash
parameters to every init.

Is anyone using this repo, I wonder? Keep pushing, keep pushing.
One day it gets good enough, and the whole world will see.
2019-05-12 00:00:00 +00:00

75 lines
2.1 KiB
Python
Executable File

#!/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 common
from shell_helpers import LF
class Main(common.LkmcCliFunction):
def __init__(self):
super().__init__(
defaults = {
'show_time': False,
},
description='''\
Convert an execution trace containing PC values into the Linux kernel lines executed.
''',
)
def timed_main(self):
self.sh.run_cmd([
os.path.join(self.env['root_dir'], 'trace2line.sh'), LF,
'true' if self.env['emulator'] == 'gem5' else 'false', LF,
self.env['trace_txt_file'], LF,
self.get_toolchain_tool('addr2line'), LF,
self.env['vmlinux'], LF,
self.env['run_dir'], LF,
])
if __name__ == '__main__':
Main().cli()
# This was the old full Python port attempt that was failing:
# import subprocess
# import sys
# if kwargs['emulator'] == '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(
# [
# self.get_toolchain_tool('addr2line'),
# '-e',
# kwargs['vmlinux'],
# '-f',
# '-p',
# ],
# stdout=subprocess.PIPE,
# stdin=subprocess.PIPE,
# ) as proc, \
# open(kwargs['trace_txt_file'], 'r') as infile, \
# open(os.path.join(kwargs['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 ${kwargs['linux_build_dir']}/(\./\|)||"
# # uniq -c