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:
Ciro Santilli 六四事件 法轮功
2019-01-22 00:00:00 +00:00
parent 4ae3dea975
commit f388ad6460
3 changed files with 42 additions and 40 deletions

View File

@@ -2914,11 +2914,17 @@ First let's run a dynamically linked executable built with the Buildroot toolcha
./run \ ./run \
--arch aarch64 \ --arch aarch64 \
--userland print_argv \ --userland print_argv \
-- \ --userland-args 'asdf "qw er"' \
asdf qwer \
; ;
.... ....
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`>>. 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>>. `./build-userland` is further documented at: <<userland-directory>>.
@@ -2939,8 +2945,7 @@ You can also try statically linked executables with:
--arch aarch64 \ --arch aarch64 \
--userland-build-id static \ --userland-build-id static \
--userland print_argv \ --userland print_argv \
-- \ --userland-args 'asdf "qw er"' \
asdf qwer \
; ;
.... ....
@@ -2957,14 +2962,13 @@ Or you can run statically linked built by the host packaged toolchain with:
--arch aarch64 \ --arch aarch64 \
--userland-build-id host-static \ --userland-build-id host-static \
--userland print_argv \ --userland print_argv \
-- \ --userland-args 'asdf "qw er"' \
asdf qwer \
; ;
.... ....
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. 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? 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 \ ./run \
--arch aarch64 \ --arch aarch64 \
--userland print_argv \ --userland print_argv \
--userland-args 'asdf "qw er"' \
--wait-gdb \ --wait-gdb \
-- \
asdf qwer \
; ;
.... ....
@@ -2993,11 +2996,10 @@ Or alternatively, if you are using <<tmux>>, do everything in one go with:
.... ....
./run \ ./run \
--arch aarch64 \ --arch aarch64 \
--userland print_argv \
--tmux-args main \ --tmux-args main \
--userland print_argv \
--userland-args 'asdf "qw er"' \
--wait-gdb \ --wait-gdb \
-- \
asdf qwer \
; ;
.... ....
@@ -3035,28 +3037,25 @@ So let's just play with some static ones:
--arch aarch64 \ --arch aarch64 \
--gem5 \ --gem5 \
--userland print_argv \ --userland print_argv \
--userland-build-id static \ --userland-args 'asdf "qw er"' \
-- \
--options 'asdf "qw er"' \
; ;
.... ....
TODO: how to escape spaces? TODO: how to escape spaces on the command line arguments?
Step debug also works: Step debug also works:
.... ....
./run \ ./run \
--arch arm \ --arch aarch64 \
--wait-gdb \
--gem5 \ --gem5 \
--userland print_argv \ --userland print_argv \
--userland-args 'asdf "qw er"' \
--userland-build-id static \ --userland-build-id static \
-- \ --wait-gdb \
--options 'asdf "qw er"' \
; ;
./run-gdb \ ./run-gdb \
--arch arm \ --arch aarch64 \
--gem5 \ --gem5 \
--userland print_argv \ --userland print_argv \
--userland-build-id static \ --userland-build-id static \
@@ -3108,10 +3107,8 @@ time \
./run \ ./run \
--arch arm \ --arch arm \
--gem5 \ --gem5 \
--userland \ --userland "$(./getvar --arch arm buildroot_build_build_dir)/dhrystone-2/dhrystone" \
"$(./getvar --arch arm buildroot_build_build_dir)/dhrystone-2/dhrystone" \ --userland-args 'asdf qwer' \
-- \
--options 100000 \
; ;
.... ....

33
run
View File

@@ -191,11 +191,9 @@ Path resolution is similar to --baremetal.
''' '''
) )
self.add_argument( self.add_argument(
'--userland-before', default='', '--userland-args',
help='''\ help='''\
Pass these arguments to the QEMU user mode CLI before the program to execute. CLI arguments to pass to the userland executable.
This is required with --userland since arguments that come at the end are interpreted
as command line arguments to that executable.
''' '''
) )
self.add_argument( self.add_argument(
@@ -230,6 +228,8 @@ Run QEMU with VNC instead of the default SDL. Connect to it with:
kernel_cli_after_dash = '' kernel_cli_after_dash = ''
extra_emulator_args = [] extra_emulator_args = []
extra_qemu_args = [] extra_qemu_args = []
if self.env['tmux_args'] is not None:
self.env['tmux'] = True
if self.env['debug_vm']: if self.env['debug_vm']:
debug_vm = ['gdb', LF, '-q', LF] + self.sh.shlex_split(self.env['debug_vm_args']) + ['--args', LF] debug_vm = ['gdb', LF, '-q', LF] + self.sh.shlex_split(self.env['debug_vm_args']) + ['--args', LF]
else: else:
@@ -345,6 +345,8 @@ Run QEMU with VNC instead of the default SDL. Connect to it with:
self.env['gem5_se_file'], LF, self.env['gem5_se_file'], LF,
'--cmd', self.resolve_userland(self.env['userland']), 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: else:
if self.env['gem5_script'] == 'fs': if self.env['gem5_script'] == 'fs':
# TODO port # 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 '-L', self.env['target_dir'], LF
] + ] +
qemu_user_and_system_options + qemu_user_and_system_options +
self.sh.shlex_split(self.env['userland_before']) + debug_args
debug_args +
[
self.resolve_userland(self.env['userland']), LF
]
) )
else: else:
if not os.path.exists(self.env['image']): 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: if self.env['baremetal'] is None:
cmd.extend(append) cmd.extend(append)
if self.env['tmux_args'] is not None:
self.env['tmux'] = True
if self.env['tmux']: if self.env['tmux']:
tmux_args = '--run-id {}'.format(self.env['run_id']) tmux_args = '--run-id {}'.format(self.env['run_id'])
if self.env['emulator'] == 'gem5': 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(extra_emulator_args)
cmd.extend(self.env['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']: if debug_vm or self.env['terminal']:
out_file = None out_file = None
else: else:
@@ -605,13 +606,15 @@ Run QEMU with VNC instead of the default SDL. Connect to it with:
exit_status = 0 exit_status = 0
if out_file is not None and not self.env['dry_run']: if out_file is not None and not self.env['dry_run']:
with open(self.env['termout_file'], 'br') as logfile: with open(self.env['termout_file'], 'br') as logfile:
line = None
for line in logfile: for line in logfile:
if panic_re.search(line): if panic_re.search(line):
exit_status = 1 exit_status = 1
last_line = line.rstrip() if line is not None:
match = re.search(b'Simulated exit code not 0! Exit code is (\d+)', last_line) last_line = line.rstrip()
if match: match = re.search(b'Simulated exit code not 0! Exit code is (\d+)', last_line)
exit_status = int(match.group(1)) if match:
exit_status = int(match.group(1))
if not self.env['userland']: if not self.env['userland']:
if os.path.exists(self.env['guest_terminal_file']): if os.path.exists(self.env['guest_terminal_file']):
with open(self.env['guest_terminal_file'], 'br') as logfile: with open(self.env['guest_terminal_file'], 'br') as logfile:

View File

@@ -1,3 +1,5 @@
/* Print each command line argument received, one per line. */
#include <stdio.h> #include <stdio.h>
int main(int argc, char **argv) { int main(int argc, char **argv) {