mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-26 19:51:35 +01:00
trace-boot: port to clifunction
This commit is contained in:
@@ -62,6 +62,7 @@ fi
|
|||||||
|
|
||||||
arch=arm
|
arch=arm
|
||||||
bench "$arch --eval '/poweroff.out'"
|
bench "$arch --eval '/poweroff.out'"
|
||||||
|
newline
|
||||||
if [ "$test_size" -ge 2 ]; then
|
if [ "$test_size" -ge 2 ]; then
|
||||||
bench "$arch --eval '/poweroff.out' --trace exec_tb"
|
bench "$arch --eval '/poweroff.out' --trace exec_tb"
|
||||||
qemu_insts "$arch"
|
qemu_insts "$arch"
|
||||||
|
|||||||
@@ -777,6 +777,11 @@ Valid emulators: {}
|
|||||||
return imp.load_source(basename.replace('-', '_'), os.path.join(self.env['root_dir'], basename))
|
return imp.load_source(basename.replace('-', '_'), os.path.join(self.env['root_dir'], basename))
|
||||||
|
|
||||||
def import_path_main(self, path):
|
def import_path_main(self, path):
|
||||||
|
'''
|
||||||
|
Import an object of the Main class of a given file.
|
||||||
|
|
||||||
|
By convention, we call the main object of all our CLI scripts as Main.
|
||||||
|
'''
|
||||||
return self.import_path(path).Main()
|
return self.import_path(path).Main()
|
||||||
|
|
||||||
def log_error(self, msg):
|
def log_error(self, msg):
|
||||||
@@ -795,7 +800,7 @@ Valid emulators: {}
|
|||||||
env = kwargs.copy()
|
env = kwargs.copy()
|
||||||
self.input_args = env.copy()
|
self.input_args = env.copy()
|
||||||
env.update(consts)
|
env.update(consts)
|
||||||
real_all_archs= env['all_archs']
|
real_all_archs = env['all_archs']
|
||||||
if real_all_archs:
|
if real_all_archs:
|
||||||
real_archs = consts['all_long_archs']
|
real_archs = consts['all_long_archs']
|
||||||
else:
|
else:
|
||||||
|
|||||||
105
trace-boot
105
trace-boot
@@ -1,63 +1,62 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import imp
|
|
||||||
import os
|
|
||||||
import subprocess
|
|
||||||
import re
|
|
||||||
|
|
||||||
import common
|
import common
|
||||||
run = imp.load_source('run', os.path.join(kwargs['root_dir'], 'run'))
|
from shell_helpers import LF
|
||||||
qemu_trace2txt = imp.load_source('qemu_trace2txt', os.path.join(kwargs['root_dir'], 'qemu-trace2txt'))
|
|
||||||
|
|
||||||
parser = self.get_argparse(argparse_args={
|
class Main(common.LkmcCliFunction):
|
||||||
'description': '''Trace the PIC addresses executed on a Linux kernel boot.
|
def __init__(self):
|
||||||
|
super().__init__(
|
||||||
|
description='''Trace the PIC addresses executed on a Linux kernel boot.
|
||||||
|
|
||||||
More information at: https://github.com/cirosantilli/linux-kernel-module-cheat#tracing
|
More information at: https://github.com/cirosantilli/linux-kernel-module-cheat#tracing
|
||||||
'''
|
'''
|
||||||
})
|
)
|
||||||
parser.add_argument(
|
|
||||||
'extra_emulator_args', nargs='*',
|
def timed_main(self):
|
||||||
help='Extra options to append at the end of the emulator command line'
|
args = self.get_common_args()
|
||||||
)
|
run = self.import_path_main('run')
|
||||||
args = self.setup(parser)
|
if self.env['emulator'] == 'gem5':
|
||||||
extra_args = {
|
args.update({
|
||||||
'extra_emulator_args': kwargs['extra_emulator_args'],
|
'eval': 'm5 exit',
|
||||||
}
|
'trace': 'Exec,-ExecSymbol,-ExecMicro',
|
||||||
if kwargs['emulator'] == 'gem5':
|
})
|
||||||
extra_args.update({
|
run.main(**args)
|
||||||
'eval': 'm5 exit',
|
elif self.env['emulator'] == 'qemu':
|
||||||
'trace': 'Exec,-ExecSymbol,-ExecMicro',
|
run_args = args.copy()
|
||||||
})
|
run_args.update({
|
||||||
run.main(args, extra_args)
|
'kernel_cli': 'init=/poweroff.out',
|
||||||
else:
|
'trace': 'exec_tb',
|
||||||
extra_args.update({
|
})
|
||||||
'kernel_cli': 'init=/poweroff.out',
|
run.main(**run_args)
|
||||||
'trace': 'exec_tb',
|
qemu_trace2txt = self.import_path_main('qemu-trace2txt')
|
||||||
})
|
qemu_trace2txt.main(**args)
|
||||||
run.main(args, extra_args)
|
# Instruction count.
|
||||||
qemu_trace2txt.main()
|
# We could put this on a separate script, but it just adds more arch boilerplate to a new script.
|
||||||
# Instruction count.
|
# So let's just leave it here for now since it did not add a significant processing time.
|
||||||
# We could put this on a separate script, but it just adds more arch boilerplate to a new script.
|
kernel_entry_addr = hex(self.get_elf_entry(self.env['vmlinux']))
|
||||||
# So let's just leave it here for now since it did not add a significant processing time.
|
nlines = 0
|
||||||
kernel_entry_addr = hex(self.get_elf_entry(kwargs['vmlinux']))
|
nlines_firmware = 0
|
||||||
nlines = 0
|
with open(self.env['qemu_trace_txt_file'], 'r') as trace_file:
|
||||||
nlines_firmware = 0
|
in_firmware = True
|
||||||
with open(kwargs['qemu_trace_txt_file'], 'r') as trace_file:
|
for line in trace_file:
|
||||||
in_firmware = True
|
line = line.rstrip()
|
||||||
for line in trace_file:
|
nlines += 1
|
||||||
line = line.rstrip()
|
pc = line.split('=')[-1]
|
||||||
nlines += 1
|
if pc == kernel_entry_addr:
|
||||||
pc = line.split('=')[-1]
|
in_firmware = False
|
||||||
if pc == kernel_entry_addr:
|
if in_firmware:
|
||||||
in_firmware = False
|
nlines_firmware += 1
|
||||||
if in_firmware:
|
print('''\
|
||||||
nlines_firmware += 1
|
|
||||||
print('''\
|
|
||||||
instructions {}
|
instructions {}
|
||||||
entry_address {}
|
entry_address {}
|
||||||
instructions_firmware {}\
|
instructions_firmware {}
|
||||||
'''.format(
|
'''.format(
|
||||||
nlines,
|
nlines,
|
||||||
kernel_entry_addr,
|
kernel_entry_addr,
|
||||||
nlines_firmware
|
nlines_firmware
|
||||||
))
|
),
|
||||||
|
end=''
|
||||||
|
)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
Main().cli()
|
||||||
|
|||||||
Reference in New Issue
Block a user