mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-28 12:34:26 +01:00
run: forward --userland and --baremetal to tmux! It's just beautiful.
This commit is contained in:
81
README.adoc
81
README.adoc
@@ -2900,11 +2900,11 @@ The target Linux kernel of the executable is a GCC toolchain build-time configur
|
|||||||
First let's run a dynamically linked executable built with the Buildroot toolchain:
|
First let's run a dynamically linked executable built with the Buildroot toolchain:
|
||||||
|
|
||||||
....
|
....
|
||||||
./build-qemu --arch arm --userland
|
./build-qemu --arch aarch64 --userland
|
||||||
./build-userland --arch arm
|
./build-userland --arch aarch64
|
||||||
./build-buildroot --arch arm
|
./build-buildroot --arch aarch64
|
||||||
./run \
|
./run \
|
||||||
--arch arm \
|
--arch aarch64 \
|
||||||
--userland print_argv \
|
--userland print_argv \
|
||||||
-- \
|
-- \
|
||||||
asdf qwer \
|
asdf qwer \
|
||||||
@@ -2923,12 +2923,12 @@ You can also try statically linked executables with:
|
|||||||
|
|
||||||
....
|
....
|
||||||
./build-userland \
|
./build-userland \
|
||||||
--arch arm \
|
--arch aarch64 \
|
||||||
--make-args='CCFLAGS_EXTRA=-static' \
|
--make-args='CCFLAGS_EXTRA=-static' \
|
||||||
--userland-build-id static \
|
--userland-build-id static \
|
||||||
;
|
;
|
||||||
./run \
|
./run \
|
||||||
--arch arm \
|
--arch aarch64 \
|
||||||
--userland-build-id static \
|
--userland-build-id static \
|
||||||
--userland print_argv \
|
--userland print_argv \
|
||||||
-- \
|
-- \
|
||||||
@@ -2940,13 +2940,13 @@ Or you can run statically linked built by the host packaged toolchain with:
|
|||||||
|
|
||||||
....
|
....
|
||||||
./build-userland \
|
./build-userland \
|
||||||
--arch arm \
|
--arch aarch64 \
|
||||||
--host \
|
--host \
|
||||||
--make-args='-B CFLAGS_EXTRA=-static' \
|
--make-args='-B CFLAGS_EXTRA=-static' \
|
||||||
--userland-build-id host-static \
|
--userland-build-id host-static \
|
||||||
;
|
;
|
||||||
./run \
|
./run \
|
||||||
--arch arm \
|
--arch aarch64 \
|
||||||
--userland-build-id host-static \
|
--userland-build-id host-static \
|
||||||
--userland print_argv \
|
--userland print_argv \
|
||||||
-- \
|
-- \
|
||||||
@@ -2962,9 +2962,9 @@ It's nice when <<gdb,the obvious>> just works, right?
|
|||||||
|
|
||||||
....
|
....
|
||||||
./run \
|
./run \
|
||||||
--arch arm \
|
--arch aarch64 \
|
||||||
--wait-gdb \
|
|
||||||
--userland print_argv \
|
--userland print_argv \
|
||||||
|
--wait-gdb \
|
||||||
-- \
|
-- \
|
||||||
asdf qwer \
|
asdf qwer \
|
||||||
;
|
;
|
||||||
@@ -2974,13 +2974,26 @@ and on another shell:
|
|||||||
|
|
||||||
....
|
....
|
||||||
./run-gdb \
|
./run-gdb \
|
||||||
--arch arm \
|
--arch aarch64 \
|
||||||
--userland print_argv \
|
--userland print_argv \
|
||||||
main \
|
main \
|
||||||
;
|
;
|
||||||
....
|
....
|
||||||
|
|
||||||
or to stop at the very first instruction of a freestanding program, just use `--no-continue` TODO example.
|
Or alternatively, if you are using <<tmux>>, do everything in one go with:
|
||||||
|
|
||||||
|
....
|
||||||
|
./run \
|
||||||
|
--arch aarch64 \
|
||||||
|
--userland print_argv \
|
||||||
|
--tmux=main \
|
||||||
|
--wait-gdb \
|
||||||
|
-- \
|
||||||
|
asdf qwer \
|
||||||
|
;
|
||||||
|
....
|
||||||
|
|
||||||
|
To stop at the very first instruction of a freestanding program, just use `--no-continue` TODO example.
|
||||||
|
|
||||||
=== gem5 syscall emulation mode
|
=== gem5 syscall emulation mode
|
||||||
|
|
||||||
@@ -10231,40 +10244,32 @@ For example, on the first shell:
|
|||||||
then on the second shell:
|
then on the second shell:
|
||||||
|
|
||||||
....
|
....
|
||||||
./run-gdb --arch arm --baremetal interactive/prompt --no-continue
|
./run-gdb --arch arm --baremetal interactive/prompt -- main
|
||||||
....
|
....
|
||||||
|
|
||||||
and now we are left at the very first executed instruction of our tiny <<baremetal-bootloaders>>.
|
Or if you are a <<tmux,tmux pro>>, do everything in one go with:
|
||||||
|
|
||||||
Then just use `stepi` to when jumping into main to go to the C code in link:baremetal/interactive/prompt.c[].
|
|
||||||
|
|
||||||
You can also find executables that don't use the bootloader at all under `baremetal/arch/<arch>/no_bootloader/*.S`, e.g.:
|
|
||||||
|
|
||||||
....
|
....
|
||||||
./run --arch arm --baremetal arch/arm/no_bootloader/semihost_exit --wait-gdb
|
./run --arch arm --baremetal interactive/prompt --wait-gdb --tmux=main
|
||||||
|
....
|
||||||
|
|
||||||
|
Alternatively, to start from the very first executed instruction of our tiny <<baremetal-bootloaders>>:
|
||||||
|
|
||||||
|
....
|
||||||
|
./run --arch arm --baremetal interactive/prompt --wait-gdb --tmux=--no-continue
|
||||||
|
....
|
||||||
|
|
||||||
|
Now you can just `stepi` to when jumping into main to go to the C code in link:baremetal/interactive/prompt.c[].
|
||||||
|
|
||||||
|
This is specially interesting for the executables that don't use the bootloader from under `baremetal/arch/<arch>/no_bootloader/*.S`, e.g.:
|
||||||
|
|
||||||
|
....
|
||||||
|
./run --arch arm --baremetal arch/arm/no_bootloader/semihost_exit --wait-gdb --tmux=--no-continue
|
||||||
....
|
....
|
||||||
|
|
||||||
The cool thing about those examples is that you start at the very first instruction of your program, which gives more control.
|
The cool thing about those examples is that you start at the very first instruction of your program, which gives more control.
|
||||||
|
|
||||||
Alternatively, skip directly to the C program main function with:
|
`aarch64` gem5 GDB step debug is broken as mentioned at: <<gem5-gdb-step-debug-kernel-aarch64>>.
|
||||||
|
|
||||||
....
|
|
||||||
./run-gdb --arch arm --baremetal interactive/prompt main
|
|
||||||
....
|
|
||||||
|
|
||||||
and then proceed as usual:
|
|
||||||
|
|
||||||
....
|
|
||||||
./run --arch arm --baremetal interactive/prompt --wait-gdb --gem5
|
|
||||||
....
|
|
||||||
|
|
||||||
and on another shell:
|
|
||||||
|
|
||||||
....
|
|
||||||
./run-gdb --arch arm --baremetal interactive/prompt --gem5 --no-continue
|
|
||||||
....
|
|
||||||
|
|
||||||
`aarch64` GDB step debug is broken as mentioned at: <<gem5-gdb-step-debug-kernel-aarch64>>.
|
|
||||||
|
|
||||||
=== Baremetal bootloaders
|
=== Baremetal bootloaders
|
||||||
|
|
||||||
|
|||||||
30
run
30
run
@@ -367,25 +367,29 @@ def main(args, extra_args=None):
|
|||||||
if args.baremetal is None:
|
if args.baremetal is None:
|
||||||
cmd.extend(append)
|
cmd.extend(append)
|
||||||
if args.tmux is not None:
|
if args.tmux is not None:
|
||||||
|
tmux_args = '--run-id {}'.format(args.run_id)
|
||||||
if common.emulator == 'gem5':
|
if common.emulator == 'gem5':
|
||||||
subprocess.Popen([os.path.join(common.root_dir, 'tmu'),
|
tmux_cmd = './gem5-shell'
|
||||||
'sleep 2;./gem5-shell -n {} {}' \
|
|
||||||
.format(args.run_id, args.tmux)
|
|
||||||
])
|
|
||||||
elif args.wait_gdb:
|
elif args.wait_gdb:
|
||||||
|
tmux_cmd = './run-gdb'
|
||||||
# TODO find a nicer way to forward all those args automatically.
|
# TODO find a nicer way to forward all those args automatically.
|
||||||
# Part of me wants to: https://github.com/jonathanslenders/pymux
|
# Part of me wants to: https://github.com/jonathanslenders/pymux
|
||||||
# but it cannot be used as a library properly it seems, and it is
|
# but it cannot be used as a library properly it seems, and it is
|
||||||
# slower than tmux.
|
# slower than tmux.
|
||||||
subprocess.Popen([os.path.join(common.root_dir, 'tmu'),
|
tmux_args += " --arch {} --linux-build-id '{}' --run-id '{}'".format(
|
||||||
"sleep 2;./run-gdb --arch '{}' --linux-build-id '{}' --run-id '{}' {}" \
|
args.arch,
|
||||||
.format(
|
args.linux_build_id,
|
||||||
args.arch,
|
args.run_id,
|
||||||
args.linux_build_id,
|
)
|
||||||
args.run_id,
|
if args.baremetal:
|
||||||
args.tmux
|
tmux_args += " --baremetal '{}'".format(args.baremetal)
|
||||||
)
|
if args.userland:
|
||||||
])
|
tmux_args += " --userland '{}'".format(args.userland)
|
||||||
|
tmux_args += ' {}'.format(args.tmux)
|
||||||
|
subprocess.Popen([
|
||||||
|
os.path.join(common.root_dir, 'tmu'),
|
||||||
|
"sleep 2;{} {}".format(tmux_cmd, tmux_args)
|
||||||
|
])
|
||||||
cmd.extend(extra_emulator_args)
|
cmd.extend(extra_emulator_args)
|
||||||
cmd.extend(args.extra_emulator_args)
|
cmd.extend(args.extra_emulator_args)
|
||||||
if debug_vm or args.terminal:
|
if debug_vm or args.terminal:
|
||||||
|
|||||||
Reference in New Issue
Block a user