2.3. Dry run to get commands for your project
One of the major features of this repository is that we try to support the --dry-run
option really well for all scripts.
This option, as the name suggests, outputs the external commands that would be run (or more precisely: equivalent commands), without actually running them.
This allows you to just clone this repository and get full working commands to integrate into your project, without having to build or use this setup further!
For example, we can obtain a QEMU run for the file userland/c/hello.c in User mode simulation by adding --dry-run
to the normal command:
./run --dry-run --userland userland/c/hello.c
which as of LKMC a18f28e263c91362519ef550150b5c9d75fa3679 + 1 outputs:
+ /path/to/linux-kernel-module-cheat/out/qemu/default/opt/x86_64-linux-user/qemu-x86_64 \ -L /path/to/linux-kernel-module-cheat/out/buildroot/build/default/x86_64/target \ -r 5.2.1 \ -seed 0 \ -trace enable=load_file,file=/path/to/linux-kernel-module-cheat/out/run/qemu/x86_64/0/trace.bin \ -cpu max \ /path/to/linux-kernel-module-cheat/out/userland/default/x86_64/c/hello.out \ ;
So observe that the command contains:
-
+
: sign to differentiate it from program stdout, much like bash-x
output. This is not a valid part of the generated Bash command however. -
the actual command nicely, indented and with arguments broken one per line, but with continuing backslashes so you can just copy paste into a terminal
For setups that don’t support the newline e.g. Eclipse debugging, you can turn them off with
--print-cmd-oneline
-
;
: both a valid part of the Bash command, and a visual mark the end of the command
For the specific case of running emulators such as QEMU, the last command is also automatically placed in a file for your convenience and later inspection:
cat "$(./getvar run_dir)/run.sh"
Since we need this so often, the last run command is also stored for convenience at:
cat out/run.sh
although this won’t of course work well for Simultaneous runs.
Furthermore, --dry-run
also automatically specifies, in valid Bash shell syntax:
-
environment variables used to run the command with syntax
+ ENV_VAR_1=abc ENV_VAR_2=def ./some/command
-
change in working directory with
+ cd /some/new/path && ./some/command