我想将配置文本作为 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()?
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()?
HiMy 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
saysset 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 3gives:cmdline args count=4exe name=args.axfarg1=1arg2=2arg3=3set semihosting args "config txt"gives:cmdline args count=3exe name=args.axfarg1=configarg2=txtNote: 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 helpsStephen
====
#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;