TI E2E Community (Beta)
Welcome to the TI E2E (Engineer-to-Engineer) Community! We invite you to freely and openly interact with your peer Engineers, TI Engineers, and other experts in order to ask questions, share knowledge, explore ideas, and help solve problems.
More Search Options

Passing Command line Parameter in Code Composer Studio

rated by 0 users
Answered (Not Verified) This post has 0 verified answers | 9 Replies | 5 Followers

Not Ranked
11 Posts
Community Member
Anupam Srivastava posted on 6 May 2009 1:20 AM

Hi,

How we will pass command line parameter?

Thanks,

Anupam

All Replies

Top 10 Contributor
2,298 Posts
Texas Instruments Employee

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.

Top 25 Contributor
238 Posts
Texas Instruments Employee

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

Top 10 Contributor
366 Posts
Texas Instruments Employee

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.

Top 25 Contributor
238 Posts
Texas Instruments Employee

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
        }
    }
   
}

 

Top 10 Contributor
366 Posts
Texas Instruments Employee

Could you also post an example using GEL, please? I could not figure out how to get the address from __c_args__ even with the prepended '_'.

Top 25 Contributor
238 Posts
Texas Instruments Employee

You need to use either:

__c_args (with TWO prepended underscores)

___c_args__ (with THREE prepended underscores and TWO postpended underscores)

This should work with GEL (try typing it in the Watch Window)

Not Ranked
5 Posts
Community Member

 

Ki-Soo Lee:

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

 

Top 25 Contributor
238 Posts
Texas Instruments Employee
Suggested by RandyP

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

 

Not Ranked
5 Posts
Community Member

thanks for the pointer!  

 

Page 1 of 1 (10 items) |

ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". TI AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY TI. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM TI.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.