Hi,
How we will pass command line parameter?
Thanks,
Anupam
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi,
How we will pass command line parameter?
Thanks,
Anupam
If you mean like passing in 'argc' and 'argv' into a program running within CCS like you were running the program from a command line, this is not possible. You would have to have the values initialized to the proper value in your build or change them by setting a breakpoint and modifying variables through the watch window.
Another option is to build your application with '--args' (non-BIOS apps) or set the '.args' section via BIOS config tool (BIOS apps). Then you can use GEL to write values to the section in target memory that has been allocated for argc, argv values.
See slides 12 and 13 of this presentation for more deatils. While the presentation gives an example on how to do it with CCScripting, you can use GEL to do you memory writes also.
Hope this helps,
ki
With either the non-BIOS or the BIOS version, how do you supply the arguments to the buffer?
I tried building a testcase with BIOS, and the __c_args__ variable only had 0xffffffff in it, but I had made the .args section size 0x18 to hold 3 arg ptrs. I could tell that if I manually put the right values into the .args section, using the structure in the presentation you pointed to, then I could get the right argc/argv values in my main() function.
But I could not find anywhere, in the presentation or in the BIOS API Guide, how to enter the arguments as if through a command line. And I could not find how to get the address of the .args section so it could be loaded via GEL.
Hi Randy,
There isn't an easy way to pass the arguments to main from the command-line in CCSv3 (This is much easier in CCSv4). WIth CCSv3, you can use CCScripting or GEL to write the values to target memory. You can look for the address of __c_args__ and then use offsets from that address to find the addresses to write the values of argc/argv.
A CCScripting JavaScript example function to write argc/argv would look something like:
/*
* WriteArgcArgv6x()
* Description: Sets up argc and argv[] into dsp memory, and write out
* all arguments that argv points to.
*
* Parameters:
* ccs - An instance of ccscripting COM object
* argc - argc to main() of .out executable
* argvArgs - arguments to be passed to main()
* biosFlag - Is this a bios program (1 for yes, 0 for no)
*
*/
function WriteArgcArgv6x(ccs, argc, argvArgs, biosFlag)
{
var cArgsBaseAddr = ccs.SymbolGetAddress("___c_args__");
var argcAddr = cArgsBaseAddr;
var argvPtrListAddr = cArgsBaseAddr + 4;
var argvArgsAddr;
/* write out argc */
ccs.MemoryWrite(PAGE_DATA, argcAddr, 32, argc);
if (biosFlag == 1) { // For bios based executables
ccs.MemoryWrite(PAGE_DATA, argvPtrListAddr, 32, cArgsBaseAddr + 4*3); // Write ptr to Argv pointer List
argvPtrListAddr += 4*2; // argv ptr list really starts on the 4th word
argvArgsAddr = cArgsBaseAddr + argc*4 + 3*4; // There are argc + 3 words before the arguments themselves
}
else { // For other executables
argvArgsAddr = cArgsBaseAddr + argc*4 + 1*4; // There are argc + 1 words before the arguments themselves
}
for (i = 0; i < argvArgs.length; i++) {
// Populate the list of pointers to arguments
ccs.MemoryWrite(PAGE_DATA, argvPtrListAddr, 32, argvArgsAddr);
argvPtrListAddr = argvPtrListAddr + 4;
// Write out the arguments themselves
switch (typeof(argvArgs[i])) {
case "number":
argvArgs[i] = argvArgs[i].toString(10); //Convert into a string
case "string":
for (j = 0; j < argvArgs[i].length; j++) {
ccs.MemoryWrite(PAGE_DATA, argvArgsAddr, 8, argvArgs[i].charCodeAt(j));
argvArgsAddr++; // Update write pointer
}
ccs.MemoryWrite(PAGE_DATA, argvArgsAddr, 8, ('\0').charCodeAt(0)); // Write null char
argvArgsAddr++; // Update write pointer
break;
default:
WScript.Echo("Invalid Argument " + argvArgs[i]);
break; // Invalid argument. Ignored
}
}
}
Ki-Soo Lee said:Hi Randy,
There isn't an easy way to pass the arguments to main from the command-line in CCSv3 (This is much easier in CCSv4). WIth CCSv3, you can use CCScripting or GEL to write the values to target memory. You can look for the address of __c_args__ and then use offsets from that address to find the addresses to write the values of argc/argv.
I came across this thread while wondering the exact same thing: in CCSv4, how do I get the debugger to pass arguments to main() via argc and *argv[]? You mentioned that it's much easier in CCSv4, but I don't see any obvious way via the Eclipse IDE. Any help would be appreciated.
thanks
You can pass arguments to main when loading the program by using the Scripting Console to call the DSS API: loadProgram()
loadProgram(java.lang.String sFileName, java.lang.Object[] args)
Load an executable file onto current target/CPU and pass an array of arguments to main().
The first argument is the out file to load. The second argument is an array of arguments to pass to main.
Hope this helps
ki
Here is a one-line script that will do the trick from the CCSv4 scripting console:
args=["123","abc"];ccxmlFile="C:/test/myconfig.ccxml";app="C:/test/myapp.out";core=".*";ds.setConfig(ccxmlFile);mySession=ds.openSession(core);mySession.target.connect();mySession.memory.loadProgram(app, args);
CCSv4 Procedure:
That's it! At this point you can use the GUI or the scripting console to continue your debug session.
Hint: For multi-core devices you will need to change the value of core to match the core you want to debug. This should be a regular expression that matches the device name as defined in your ccxml file.
Regarding the CCSv4 procedure,
For 1.: Does it make any difference whether the main function returns int, or should it be void? (e.g. would this be ok?: int main(int argc, char* argv[]) )
For 2.: When I set arg_size to 256, I get the following error:
ERROR: argument to option --arg_size ("size") is out of range (must be a non-negative number)
Here is my setting:
- linker tool:: TMS470 Code Generation Tools 4.5.1/bin/cl470
- setup: Build Options ->TMS470 Linker -> Runtime Environment -> Set C argc/argv memory size box: --arg_size=256
I tried different numbers, 1, 10, etc, no difference. A syntax error perhaps?
Thanks for the above trick by the way.
Update to my previous reply: I should have entered the arg size value only, not the whole text in the box. (Just 256, instead of --arg_size=256).
Then there is no build error.
Hello Ki-Soo Lee,
I am working on TI's C6670 based SoC. Can you please let me know how to retreive starting address of __c_args symbol in Gel file. I've gone through CCS documentation on GEL but seems like there is no GEL api which can get me the address from the symbol.
Your help will be highly appreciated.
Thanks,
Ankit
Ankit,
You can get the addresses of symbols by simply using a standard GEL expression:
addr = __c_args__;
As long as that variable is in debug scope, you can access it.
Thanks
ki
Hi,
Would it be possible to add a command line arguments field to the CCS 'Load Program' dialog? This would automate the process and make life easier. It would be nice if the values placed there would be remembered, so that reloading a program would reload it with the same arguments.
Thanks,
-itay
Hi Itay,
Itay Chamiel said:Would it be possible to add a command line arguments field to the CCS 'Load Program' dialog?
Your request is something that has come up before. If I recall correctly, it was something that was more tricky to implement then it looks so we held off and just suggested people do it via the console or create a custom command + hot menu to automate it like you said with a button click.
Thanks
ki
Hello,
Im trying to pass command line parameters to my program running on the TMS320C5502 eZdsp and i already tried your script however, when debugging i try:
printf("argc = %d\n", argc);
for (n = 0; n < argc; n++)
{
printf("%d: %s\n", n, argv[n]);
}
to check whether or not the parameters where passed and it does not work.
Any idea of what could i be missing?
Regards,
Oscar.
Has the situation improved?
I find this bit of code in the run time which calls main()
int _args_main() { #pragma diag_suppress 1107,173 register ARGS *pargs = (ARGS*)_symval(&__c_args__); #pragma diag_default 1107,173 register int argc = 0; register char **argv = 0; if (_symval(&__c_args__) != NO_C_ARGS) { argc = pargs->argc; argv = pargs->argv; } return main(argc, argv); }
It seems to hint at a way to pass arguments to main(). I searched the Wiki (Search seems to be down - got an empty response.) I searched help within CCS and found a reference to an "Arguments Page" (under C/C++ Run and Debug) but was unable to find that page.
This is CCS6.2, controlSUITE v190, controlCARD (F2837xD)
thanks,
hank
The "Arguments page" in the CCS help is for the stock Eclipse functionality, for when using Eclipse to debug a program running on the host.Hank Barta said:I searched help within CCS and found a reference to an "Arguments Page" (under C/C++ Run and Debug) but was unable to find that page.
The CCS Debug Configurations which is customized for debugging embedded targets doesn't have the "Arguments page".
The CCS Semihosting for use with the GCC ARM compiler has the SYS_GET_CMDLINE call which allows DSS Scripting or GEL to set the arguments to main.Hank Barta said:Has the situation improved?
I can't see the equivalent functionality in the CCS CIO.