qemu-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: qemu-arm 6.2.0 command line argument


From: Peter Maydell
Subject: Re: qemu-arm 6.2.0 command line argument
Date: Thu, 1 Jun 2023 10:42:30 +0100

On Wed, 31 May 2023 at 18:48, Tanmay Das <tanmay.das.1982@gmail.com> wrote:
>
> Hi,
>
> Hope all is well with you!
>
> I am trying to use qemu-arm to run a binary and trying to pass a command line 
> argument to the main method like below
>
> qemu-arm -cpu cortex-m3 path-to-the-binary <command line argument>

This is the correct syntax. It works for me:

$ cat hello.c
#include <stdio.h>
int main(int argc, char **argv) {
    if (argc <= 1) {
        printf("no arguments\n");
    } else {
        printf("argv[1] = %s\n", argv[1]);
    }
    return 0;
}
$ arm-linux-gnueabihf-gcc -g -o hello -static hello.c
$ qemu-arm -cpu cortex-a15 ./hello
no arguments
$ qemu-arm -cpu cortex-a15 ./hello foo
argv[1] = foo

I used cortex-a15 as the CPU because I don't have a cross
compiler that builds M-profile Linux binaries. But the
principle is the same.

If your binary isn't seeing the command line arguments
then it's likely something else is wrong. Some questions
to try to help in diagnosing what:

 * Is your guest binary built for M-profile Linux?
 * How exactly is the C runtime it's built against expecting
   to get the command line arguments? (The other option that
   can be made to work is semihosting.)
 * Is the guest binary definitely successfully executing
   main() and just not seeing the right command line arguments?
   (i.e. check the problem is not that it is crashing before
   it even gets to main, or that you're trying to print
   the argument but the printing-output part goes wrong, etc.)

thanks
-- PMM



reply via email to

[Prev in Thread] Current Thread [Next in Thread]