diff --git a/README.adoc b/README.adoc index 31875bd..0dac338 100644 --- a/README.adoc +++ b/README.adoc @@ -25348,7 +25348,7 @@ For this reason, we use it in particular often in this README to reduce the need ==== run-toolchain -While you could just manually find/learn the path to toolchain tools, e.g. in LKMC b15a0e455d691afa49f3b813ad9b09394dfb02b7 they are +While you could just manually find/learn the path to toolchain tools, e.g. in LKMC b15a0e455d691afa49f3b813ad9b09394dfb02b7 they are: .... ./out/buildroot/build/default/aarch64/host/bin/aarch64-buildroot-linux-gnu-gcc userland/c/hello.c @@ -25374,6 +25374,12 @@ which outputs as of LKMC b15a0e455d691afa49f3b813ad9b09394dfb02b7: /path/to/linux-kernel-module-cheat/out/buildroot/build/default/aarch64/host/usr/bin/aarch64-buildroot-linux-gnu .... +Since disassembly of a single function with GDB is such a common use case https://stackoverflow.com/questions/22769246/how-to-disassemble-one-single-function-using-objdump[], we have a shortcut for it: + +.... +./disas --arch aarch64 --userland userland/c/hello.c main +.... + === Rebuild Buildroot while running It is not possible to rebuild the root filesystem while running QEMU because QEMU holds the file qcow2 file: diff --git a/cli_function.py b/cli_function.py index e4103af..09f7cc5 100755 --- a/cli_function.py +++ b/cli_function.py @@ -231,7 +231,7 @@ class CliFunction: def cli_noexit(self, cli_args=None): ''' Call the function from the CLI. Parse command line arguments - to get all arguments. + to get all arguments. Does not exit the program after running this function. :return: the return of main ''' @@ -435,6 +435,8 @@ amazing function! # Positional out = one_cli_function(pos_mandatory=1, pos_optional=2, args_star=['3', '4']) + # TODO: make actual positional arguments work. + # out = one_cli_function(1, 2, '3', '4') assert out['pos_mandatory'] == 1 assert out['pos_optional'] == 2 assert out['args_star'] == ['3', '4'] diff --git a/common.py b/common.py index e96b1c9..9badba5 100644 --- a/common.py +++ b/common.py @@ -1345,6 +1345,8 @@ lunch aosp_{}-eng These are arguments that might be used by more than one script, and are all defined in this class instead of in the derived class of the script. + + This can be used to forward common arguments to a call of another CLI function. ''' return { key:self.env[key] for key in self._common_args if diff --git a/disas b/disas new file mode 100755 index 0000000..4e65529 --- /dev/null +++ b/disas @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 + +import os + +import lkmc.import_path + +import common +from shell_helpers import LF + +class Main(common.LkmcCliFunction): + def __init__(self): + super().__init__( + defaults = { + 'show_time': False, + }, + description='''\ +Disassemble one function of the given executable. +https://cirosantilli.com/linux-kernel-module-cheat#run-toolchain +''', + ) + self.add_argument('function', help='Which function to disassemble.') + + def timed_main(self): + lkmc.import_path.import_path_main('run-toolchain')( + tool='gdb', + extra_args=[ + '-nh', + '-batch', + '-ex', + 'disas/rs {}'.format(self.env['function']), + self.env['image'], + ], + quiet=True, + **self.get_common_args() + ) + +if __name__ == '__main__': + Main().cli() diff --git a/run-toolchain b/run-toolchain index 7dd6b72..60f430e 100755 --- a/run-toolchain +++ b/run-toolchain @@ -34,10 +34,6 @@ Suitable for programmatic consumption by other shell programs. ) def timed_main(self): - if self.env['baremetal']: - image = self.env['vmlinux'] - else: - image = self.env['image'] tool = self.get_toolchain_tool(self.env['tool']) if self.env['print_tool']: print(tool)