On 02/04/2015 17:47, Liviu Ionescu wrote: > >> On 02 Apr 2015, at 17:27, Matthew Fortune <matthew.fort...@imgtec.com> wrote: >> >> Liviu Ionescu <i...@livius.net> writes: >>> for completeness: >>> >>> ilg-mbp:gnuarmeclipse-qemu.git ilg$ "/Applications/GNU ARM >>> Eclipse/QEMU/2.2.91-201504021111-dev/bin/qemu-system-gnuarmeclipse" - >>> verbose -machine STM32-H103 -gdb tcp::1234 -semihosting-config >>> enable=on,target=native,cmdline='n "1 a" 2 3' >> >> I see here that you have switched quotes because you know that you are >> providing a double quoted argument within the string. > > my code works both ways symmetrically: > > ilg-mbp:~ ilg$ "/Applications/GNU ARM > Eclipse"/QEMU/2.2.91-201504021111-dev/bin/qemu-system-gnuarmeclipse -verbose > -machine STM32-H103 -gdb tcp::1234 -semihosting-config > enable=on,target=native,cmdline="name 1 '2 a' 3" > > GNU ARM Eclipse QEMU v2.2.91 (qemu-system-gnuarmeclipse). > Board: 'STM32-H103' (Olimex Header Board for STM32F103RBT6 (Experimental)). > Device: 'STM32F103RB' (cortex-m3, MPU), Flash: 128 KB, RAM: 20 KB. > Command line: 'name 1 '2 a' 3' (14 bytes). > GDB Server listening on: 'tcp::1234'... > ... connection accepted from 127.0.0.1. > > Execute 'mon system_reset'. > main(argc=4, argv=["name", "1", "2 a", "3"]); > Hello ARM World! > > in other words, after being delivered by SYS_GET_CMDLINE to the application, > the startup parser uses either single or double quotes to split the string > into arguments, similarly to a real life shell. > >> The root of all >> argument passing issues tends to boil down to how to quote and or escape >> characters appropriately. Because you know the arguments you can quote >> correctly but for an unknown user-provided set of arguments (where they >> do not know how their arguments will flow down to an application) then >> the appropriate quoting and escaping becomes harder. >> >> The problem characters are obviously single and double quotes. Having >> different quoting rules for any of the layers between a user and >> the emulated program is always going to cause some confusion so when >> quoting is necessary I have always found that following the standard >> argument passing rules of the native application is the least >> problematic. > > I guess you are generally right, but in this case any quoting is perfectly > fine. > >> qemu-system... -semihosting-config "arg=foo bar" -semihosting-config >> "arg=second" >> >> This should give an argv of ["foo bar", "second"] > > yes, but for the casual user the above syntax is already not natural and even > more confusing: should I use "arg=foo bar" or arg="foo bar"? should I repeat > -semihosting-config for each argument, or I can group all together > (-semihosting-config arg="foo bar",arg="second")? > > > if for your use cases this syntax is acceptable, ok, go for it.
Hmm... the -semihosting-config group would be indeed unusual comparing to the other groups, but on the other hand this would solve also the double-comma problem. For simple cases the casual user can just stick to the cmdline. > > > my first use of qemu is as a background GDB server started by an Eclipse > plug-in. the plug-in will have a single edit field, where the user can enter > the semihosting command line args. for args that include spaces, the user > should use either single or double quotes, as in any other field. > > my preferred implemention for this would be the original -semihosting-cmdline > "some string". > > both proposed implementations (-semihosting-config cmdline="some-string") and > even worse for the multiple (-semihosting-config arg=some-string), are way > more complicated to use in my Eclipse plug-in, requiring special precautions > for passing single/double quotes, commas and possibly equals. > > with the -semihosting-cmdline some-string, the only thing I have to do is to > pass [-semihosting-cmdline] in one string array element, and the unmodified > [some-string], regardless the quoting used, as the next string array element, > and call exec(). > > given the above reasons, there are good chances that in my qemu fork (GNU ARM > Eclipse QEMU) I'll have to use the separate -semihosting-cmdline option; if > you'll accept my patches in the main trunk, ok, if not... no problem; > > as a conclusion, if you like arg=, go for it, but just be aware that this > solution does not cover all use cases properly. I wasn't focussing on a specific use case, I just thought that having only one flexible command line option used for passing input arguments regardless of semi-hosting interface would be ideal. I do understand however that in your particular case cmdline is more convenient, thus I personally don’t mind having both options: the user-friendly cmdline and more flexible arg. Leon