How to pass multi arguments to main() in Arm Development Studio?

我想将配置文本作为 argv[1] 传递给 main() 函数,并且已经尝试过命令行。set semihosting args "config txt" ,but it seems like the config txt is argv[0] not argv[1],so how to pass multi arguments to main()?

Parents
  • Hi

    My name is Stephen and I work at Arm.

    https://developer.arm.com/documentation/101471/6-7-0/Arm-Debugger-commands/Arm-Debugger-commands-listed-in-alphabetical-order/set-semihosting

    says
    set semihosting args <arguments>
    Specifies the command-line arguments that are passed to the main() function in the application using the argv parameter. The name of the image is always implicitly passed in argv[0] and it is not necessary to pass this as an argument.

    I've tested this in Arm Development Studio 2025.0 with a simple example, connected to a test board via DSTREAM, and it works as expected:

    ====
    #include <stdio.h>

    int main (int argc, char *argv[])
    {
    int i=0;
    printf("\ncmdline args count=%d", argc);

    /* First argument is executable name */
    printf("\nexe name=%s", argv[0]);

    for (i=1; i< argc; i++) {
        printf("\narg%d=%s", i, argv[i]);
    }

    printf("\n");
    return 0;
    }
    ====


    set semihosting args 1 2 3
    gives:
    cmdline args count=4
    exe name=args.axf
    arg1=1
    arg2=2
    arg3=3


    set semihosting args "config txt"
    gives:
    cmdline args count=3
    exe name=args.axf
    arg1=config
    arg2=txt


    Note: The set semihosting args command must be issued during target connection or before any code is executed.
    You must either put the command in a "target initialization debugger script" to be executed at connection time, or enter it at the image entry point (at main() is too late).

    Hope this helps

    Stephen

Reply
  • Hi

    My name is Stephen and I work at Arm.

    https://developer.arm.com/documentation/101471/6-7-0/Arm-Debugger-commands/Arm-Debugger-commands-listed-in-alphabetical-order/set-semihosting

    says
    set semihosting args <arguments>
    Specifies the command-line arguments that are passed to the main() function in the application using the argv parameter. The name of the image is always implicitly passed in argv[0] and it is not necessary to pass this as an argument.

    I've tested this in Arm Development Studio 2025.0 with a simple example, connected to a test board via DSTREAM, and it works as expected:

    ====
    #include <stdio.h>

    int main (int argc, char *argv[])
    {
    int i=0;
    printf("\ncmdline args count=%d", argc);

    /* First argument is executable name */
    printf("\nexe name=%s", argv[0]);

    for (i=1; i< argc; i++) {
        printf("\narg%d=%s", i, argv[i]);
    }

    printf("\n");
    return 0;
    }
    ====


    set semihosting args 1 2 3
    gives:
    cmdline args count=4
    exe name=args.axf
    arg1=1
    arg2=2
    arg3=3


    set semihosting args "config txt"
    gives:
    cmdline args count=3
    exe name=args.axf
    arg1=config
    arg2=txt


    Note: The set semihosting args command must be issued during target connection or before any code is executed.
    You must either put the command in a "target initialization debugger script" to be executed at connection time, or enter it at the image entry point (at main() is too late).

    Hope this helps

    Stephen

Children
No data