This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Parsing arguments to main() through debugger

I am trying to pass arguments to main function while calling the program to execute through the debugger but it does not work. The debugger has automatically enabled me semihosting on my target (in ELF) but I cannot pass any arguments in main().

My test program is something like :

int main(int argc, char *argv[]) {

 

printf("%d\n",argc);
return 0;

}

so I want to print the number of arguments that passed. I call the debugger using a script file and inside that script I have load the .axf file and set the parameters like:

set semihosting args "Hello" "World"
cd "path-to-Workspace"

set debug-from main
run "Hello" "World" 

The debugger keeps answering me [target] 0

So what an i doing wrong? There is not much information for that in the internet and I cannot find any relevant information about it.

  • Are you connecting to a hardware target or a model?

    The "set semihosting args" command only works for hardware targets.

    If you are using a FVP model, you will need to start the model using

    -C cluster.cpu0.semihosting-cmd_line="<string>"

    to have arguments passed to main().
  • Thank you very much for the information, I did't know that "set semihosting args" works only for hardware. I am using ARM FVP model and I call the debugger like this :

    debugger --cdb-entry="ARM FVP::Cortex-A8::Bare Metal Debug::Bare Metal Debug::Debug Cortex-A8" --script="<path-to-script>\Debugg_Script.ds"

    I want to pass some parameters to command prompt while calling the .axf file (loadfile inside the .ds script). The .axf is created by building the code above. The problem with the above line is that the debugger does not accepts anything in general, it does not even stops in fgets(),scanf() functions, in order for me to pass something in the command prompt. Also, using --interactive or putting breakoints the debugger bypasses all my input functions (even if the script commands are extracted from the history of the debugger). On the other hand, when I am running the code through DS-5 IDE with the same debugger the code runs and stops to input functions. But i have the same problem here about the arguments, when I am writing them in the debug configuration -> Arguments (nothing happens). 

    As far as I can understand the command bellow must be inserted as parameter using the model_shell command, to call my debugger from that model. If so, how will I do that?  

    -C cluster.cpu0.semihosting-cmd_line="<string>"

    Thanks in advance.

    Edit : Found it!! Thank you for your help!

    FVP_EB_Cortex-A8 --config-file <YourConfiguration.launch> --application <YourAXF.axf>