mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-25 19:21:35 +01:00
run: add --userland-args to make userland arguments across QEMU and gem5
Get rid of --userland-before as a consequence.
This commit is contained in:
47
README.adoc
47
README.adoc
@@ -2914,11 +2914,17 @@ First let's run a dynamically linked executable built with the Buildroot toolcha
|
||||
./run \
|
||||
--arch aarch64 \
|
||||
--userland print_argv \
|
||||
-- \
|
||||
asdf qwer \
|
||||
--userland-args 'asdf "qw er"' \
|
||||
;
|
||||
....
|
||||
|
||||
Output:
|
||||
|
||||
....
|
||||
asdf
|
||||
qw er
|
||||
....
|
||||
|
||||
This runs link:userland/print_argv.c[]. `--userland` path resolution is analogous to <<baremetal-setup-getting-started,that of `./run --baremetal`>>.
|
||||
|
||||
`./build-userland` is further documented at: <<userland-directory>>.
|
||||
@@ -2939,8 +2945,7 @@ You can also try statically linked executables with:
|
||||
--arch aarch64 \
|
||||
--userland-build-id static \
|
||||
--userland print_argv \
|
||||
-- \
|
||||
asdf qwer \
|
||||
--userland-args 'asdf "qw er"' \
|
||||
;
|
||||
....
|
||||
|
||||
@@ -2957,14 +2962,13 @@ Or you can run statically linked built by the host packaged toolchain with:
|
||||
--arch aarch64 \
|
||||
--userland-build-id host-static \
|
||||
--userland print_argv \
|
||||
-- \
|
||||
asdf qwer \
|
||||
--userland-args 'asdf "qw er"' \
|
||||
;
|
||||
....
|
||||
|
||||
TODO expose dynamically linked executables built by the host toolchain. It also works, we just have to use e.g. `-L /usr/aarch64-linux-gnu`, so it's not really hard, I'm just lazy.
|
||||
|
||||
==== QEMU user mode GDB
|
||||
==== User mode GDB
|
||||
|
||||
It's nice when <<gdb,the obvious>> just works, right?
|
||||
|
||||
@@ -2972,9 +2976,8 @@ It's nice when <<gdb,the obvious>> just works, right?
|
||||
./run \
|
||||
--arch aarch64 \
|
||||
--userland print_argv \
|
||||
--userland-args 'asdf "qw er"' \
|
||||
--wait-gdb \
|
||||
-- \
|
||||
asdf qwer \
|
||||
;
|
||||
....
|
||||
|
||||
@@ -2993,11 +2996,10 @@ Or alternatively, if you are using <<tmux>>, do everything in one go with:
|
||||
....
|
||||
./run \
|
||||
--arch aarch64 \
|
||||
--userland print_argv \
|
||||
--tmux-args main \
|
||||
--userland print_argv \
|
||||
--userland-args 'asdf "qw er"' \
|
||||
--wait-gdb \
|
||||
-- \
|
||||
asdf qwer \
|
||||
;
|
||||
....
|
||||
|
||||
@@ -3035,28 +3037,25 @@ So let's just play with some static ones:
|
||||
--arch aarch64 \
|
||||
--gem5 \
|
||||
--userland print_argv \
|
||||
--userland-build-id static \
|
||||
-- \
|
||||
--options 'asdf "qw er"' \
|
||||
--userland-args 'asdf "qw er"' \
|
||||
;
|
||||
....
|
||||
|
||||
TODO: how to escape spaces?
|
||||
TODO: how to escape spaces on the command line arguments?
|
||||
|
||||
Step debug also works:
|
||||
|
||||
....
|
||||
./run \
|
||||
--arch arm \
|
||||
--wait-gdb \
|
||||
--arch aarch64 \
|
||||
--gem5 \
|
||||
--userland print_argv \
|
||||
--userland-args 'asdf "qw er"' \
|
||||
--userland-build-id static \
|
||||
-- \
|
||||
--options 'asdf "qw er"' \
|
||||
--wait-gdb \
|
||||
;
|
||||
./run-gdb \
|
||||
--arch arm \
|
||||
--arch aarch64 \
|
||||
--gem5 \
|
||||
--userland print_argv \
|
||||
--userland-build-id static \
|
||||
@@ -3108,10 +3107,8 @@ time \
|
||||
./run \
|
||||
--arch arm \
|
||||
--gem5 \
|
||||
--userland \
|
||||
"$(./getvar --arch arm buildroot_build_build_dir)/dhrystone-2/dhrystone" \
|
||||
-- \
|
||||
--options 100000 \
|
||||
--userland "$(./getvar --arch arm buildroot_build_build_dir)/dhrystone-2/dhrystone" \
|
||||
--userland-args 'asdf qwer' \
|
||||
;
|
||||
....
|
||||
|
||||
|
||||
33
run
33
run
@@ -191,11 +191,9 @@ Path resolution is similar to --baremetal.
|
||||
'''
|
||||
)
|
||||
self.add_argument(
|
||||
'--userland-before', default='',
|
||||
'--userland-args',
|
||||
help='''\
|
||||
Pass these arguments to the QEMU user mode CLI before the program to execute.
|
||||
This is required with --userland since arguments that come at the end are interpreted
|
||||
as command line arguments to that executable.
|
||||
CLI arguments to pass to the userland executable.
|
||||
'''
|
||||
)
|
||||
self.add_argument(
|
||||
@@ -230,6 +228,8 @@ Run QEMU with VNC instead of the default SDL. Connect to it with:
|
||||
kernel_cli_after_dash = ''
|
||||
extra_emulator_args = []
|
||||
extra_qemu_args = []
|
||||
if self.env['tmux_args'] is not None:
|
||||
self.env['tmux'] = True
|
||||
if self.env['debug_vm']:
|
||||
debug_vm = ['gdb', LF, '-q', LF] + self.sh.shlex_split(self.env['debug_vm_args']) + ['--args', LF]
|
||||
else:
|
||||
@@ -345,6 +345,8 @@ Run QEMU with VNC instead of the default SDL. Connect to it with:
|
||||
self.env['gem5_se_file'], LF,
|
||||
'--cmd', self.resolve_userland(self.env['userland']), LF,
|
||||
])
|
||||
if self.env['userland_args'] is not None:
|
||||
cmd.extend(['--options', self.env['userland_args'], LF])
|
||||
else:
|
||||
if self.env['gem5_script'] == 'fs':
|
||||
# TODO port
|
||||
@@ -429,11 +431,7 @@ Run QEMU with VNC instead of the default SDL. Connect to it with:
|
||||
'-L', self.env['target_dir'], LF
|
||||
] +
|
||||
qemu_user_and_system_options +
|
||||
self.sh.shlex_split(self.env['userland_before']) +
|
||||
debug_args +
|
||||
[
|
||||
self.resolve_userland(self.env['userland']), LF
|
||||
]
|
||||
debug_args
|
||||
)
|
||||
else:
|
||||
if not os.path.exists(self.env['image']):
|
||||
@@ -559,8 +557,6 @@ Run QEMU with VNC instead of the default SDL. Connect to it with:
|
||||
)
|
||||
if self.env['baremetal'] is None:
|
||||
cmd.extend(append)
|
||||
if self.env['tmux_args'] is not None:
|
||||
self.env['tmux'] = True
|
||||
if self.env['tmux']:
|
||||
tmux_args = '--run-id {}'.format(self.env['run_id'])
|
||||
if self.env['emulator'] == 'gem5':
|
||||
@@ -588,6 +584,11 @@ Run QEMU with VNC instead of the default SDL. Connect to it with:
|
||||
])
|
||||
cmd.extend(extra_emulator_args)
|
||||
cmd.extend(self.env['extra_emulator_args'])
|
||||
if self.env['emulator'] == 'qemu' and self.env['userland']:
|
||||
# The program and arguments must come at the every end of the CLI.
|
||||
cmd.extend([self.resolve_userland(self.env['userland']), LF])
|
||||
if self.env['userland_args'] is not None:
|
||||
cmd.extend(self.sh.shlex_split(self.env['userland_args']))
|
||||
if debug_vm or self.env['terminal']:
|
||||
out_file = None
|
||||
else:
|
||||
@@ -605,13 +606,15 @@ Run QEMU with VNC instead of the default SDL. Connect to it with:
|
||||
exit_status = 0
|
||||
if out_file is not None and not self.env['dry_run']:
|
||||
with open(self.env['termout_file'], 'br') as logfile:
|
||||
line = None
|
||||
for line in logfile:
|
||||
if panic_re.search(line):
|
||||
exit_status = 1
|
||||
last_line = line.rstrip()
|
||||
match = re.search(b'Simulated exit code not 0! Exit code is (\d+)', last_line)
|
||||
if match:
|
||||
exit_status = int(match.group(1))
|
||||
if line is not None:
|
||||
last_line = line.rstrip()
|
||||
match = re.search(b'Simulated exit code not 0! Exit code is (\d+)', last_line)
|
||||
if match:
|
||||
exit_status = int(match.group(1))
|
||||
if not self.env['userland']:
|
||||
if os.path.exists(self.env['guest_terminal_file']):
|
||||
with open(self.env['guest_terminal_file'], 'br') as logfile:
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* Print each command line argument received, one per line. */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
Reference in New Issue
Block a user