From 2b1006654909da7e3b8f64a60309723fd70783cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?UTF-8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Fri, 23 Nov 2018 00:00:01 +0000 Subject: [PATCH] run: forward --userland and --baremetal to tmux! It's just beautiful. --- README.adoc | 81 ++++++++++++++++++++++++++++------------------------- run | 30 +++++++++++--------- 2 files changed, 60 insertions(+), 51 deletions(-) diff --git a/README.adoc b/README.adoc index b6dde00..1a29c77 100644 --- a/README.adoc +++ b/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: .... -./build-qemu --arch arm --userland -./build-userland --arch arm -./build-buildroot --arch arm +./build-qemu --arch aarch64 --userland +./build-userland --arch aarch64 +./build-buildroot --arch aarch64 ./run \ - --arch arm \ + --arch aarch64 \ --userland print_argv \ -- \ asdf qwer \ @@ -2923,12 +2923,12 @@ You can also try statically linked executables with: .... ./build-userland \ - --arch arm \ + --arch aarch64 \ --make-args='CCFLAGS_EXTRA=-static' \ --userland-build-id static \ ; ./run \ - --arch arm \ + --arch aarch64 \ --userland-build-id static \ --userland print_argv \ -- \ @@ -2940,13 +2940,13 @@ Or you can run statically linked built by the host packaged toolchain with: .... ./build-userland \ - --arch arm \ + --arch aarch64 \ --host \ --make-args='-B CFLAGS_EXTRA=-static' \ --userland-build-id host-static \ ; ./run \ - --arch arm \ + --arch aarch64 \ --userland-build-id host-static \ --userland print_argv \ -- \ @@ -2962,9 +2962,9 @@ It's nice when <> just works, right? .... ./run \ - --arch arm \ - --wait-gdb \ + --arch aarch64 \ --userland print_argv \ + --wait-gdb \ -- \ asdf qwer \ ; @@ -2974,13 +2974,26 @@ and on another shell: .... ./run-gdb \ - --arch arm \ + --arch aarch64 \ --userland print_argv \ 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 <>, 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 @@ -10231,40 +10244,32 @@ For example, on the first 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 <>. - -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//no_bootloader/*.S`, e.g.: +Or if you are a <>, do everything in one go with: .... -./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 <>: + +.... +./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//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. -Alternatively, skip directly to the C program main function with: - -.... -./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: <>. +`aarch64` gem5 GDB step debug is broken as mentioned at: <>. === Baremetal bootloaders diff --git a/run b/run index 1962aa6..69d294b 100755 --- a/run +++ b/run @@ -367,25 +367,29 @@ def main(args, extra_args=None): if args.baremetal is None: cmd.extend(append) if args.tmux is not None: + tmux_args = '--run-id {}'.format(args.run_id) if common.emulator == 'gem5': - subprocess.Popen([os.path.join(common.root_dir, 'tmu'), - 'sleep 2;./gem5-shell -n {} {}' \ - .format(args.run_id, args.tmux) - ]) + tmux_cmd = './gem5-shell' elif args.wait_gdb: + tmux_cmd = './run-gdb' # TODO find a nicer way to forward all those args automatically. # Part of me wants to: https://github.com/jonathanslenders/pymux # but it cannot be used as a library properly it seems, and it is # slower than tmux. - subprocess.Popen([os.path.join(common.root_dir, 'tmu'), - "sleep 2;./run-gdb --arch '{}' --linux-build-id '{}' --run-id '{}' {}" \ - .format( - args.arch, - args.linux_build_id, - args.run_id, - args.tmux - ) - ]) + tmux_args += " --arch {} --linux-build-id '{}' --run-id '{}'".format( + args.arch, + args.linux_build_id, + args.run_id, + ) + if args.baremetal: + 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(args.extra_emulator_args) if debug_vm or args.terminal: