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.

TMS320F28377D: DSS script fails to get static variable address

Part Number: TMS320F28377D
Other Parts Discussed in Thread: CCSTUDIO, TEST2


I am running a DSS script on C2837xD target.


The line below in the script fails.

var max_num_fault_entries_addr = debugSession.symbol.getAddress("max_num_fault_entries");

js:> loadJSFile C:\ti\DSS\DSS_SCRIPT_SINGLE_AXIS_HES_FAULTS_TEST.js
Unable to get address for symbol: max_num_fault_entries (C:\ti\DSS\DSS_SCRIPT_SINGLE_AXIS_HES_FAULTS_TEST.js#55)

The static variable exists in the .map file
    0000c3de local _max_num_fault_entries$8 (.ebss)

Code is below:
    void LCD_add_fault_to_log(uint16_t fault_bit, uint16_t module, uint16_t index)
    {
        static uint16_t max_num_fault_entries = 0;
        ...


I added "--mapfile_contents=sym_defs" linker flag.
I added "--output_all_syms" assembler flag.
I turned Off optimization


What am I missing ? I need to read the value of this static variable in my test script.

  • Hi Paul,

    Assuming the correct symbols are loaded, what you are doing should work. When you add max_num_fault_entries to the Expressions view, is the debugger able to evaluate it? 

    Thanks

    ki

  • Correct symbols are loaded and I have no problem getting addresses for global variables with same method in the script.

    Doing the reverse returns the correct symbol name "max_num_fault_entries". I verified this in Rhino.

        var max_num_fault_entries_symbol = debugSession.symbol.lookupSymbol(1, 0x0000c3de);

    I am running Version: 8.3.1.00004 of CCS if that matters.

    The FAE suggested I try to add the module name in front of the variable, but that did not work either. Might be I do not know the exact syntax.

        var max_num_fault_entries_addr = debugSession.symbol.getAddress("lcd.c::max_num_fault_entries");
  • Can you provide a reproducible test case? I don't need the full application. Something stripped down as simple as possible, but that can reproduce the issue, would be good. 

  • Ki,

    Here an an example simplified C file. I don't have a script to match this.

    Thanks,

    Stuart

    volatile static int test;
    volatile int test2;
    
    /**
     * main.c
     */
    int main(void)
    {
        while (1)
        {
            ++test;
            ++test2;
        }
    	return 0;
    }
    

  • I have seen the script work once or twice this morning. And now never again.

    I am starting to think is something with the scripting console and perhaps the .js script file.

    I use loadJSFile to run the script in the scripting console.

    I am not able to use the unloadJSFile command without it complaining is not finding the file.

    When issuing restart command, scripting console and CCS just hangs.

    I am pasting the complete script file, maybe there is something wrong I am doing there.

    ====================================================================

    importPackage (Packages.com.ti.debug.engine.scripting);
    importPackage (Packages.com.ti.ccstudio.scripting.environment);
    importPackage (Packages.java.lang);
    var ccsInstallDir = "C:/ti/ccsv8";
    var dssDir = "C/ti/DSS";
    var CCXMLFile = "C:/Users/pmmotora/ti/CCSTargetConfigurations/NewTargetConfiguration.ccxml"
    var programToLoad = "C:/CODE/devel_HTA_mmi_2085_2086_dbg/Releases/HTA/HTA_Master_runtime/HTA_Master_runtime.out"
    //var logFile = "C:/ti/DSS";
    var script = ScriptingEnvironment.instance();
    script.traceBegin("logFile.xml", "C:/ti/ccsv8/ccs_base/scripting/examples/DebugServerExamples/DefaultStylesheet.xsl");
    script.traceSetConsoleLevel(TraceLevel.INFO);
    script.traceSetFileLevel(TraceLevel.INFO);
    script.traceWrite("Begin Script Session");
    var debugServer = script.getServer("DebugServer.1");
    debugServer.setConfig("C:\\Users\\pmmotora\\ti\\CCSTargetConfigurations\\NewTargetConfiguration.ccxml");
    var debugSession = debugServer.openSession("Texas Instruments XDS2xx USB Debug Probe_0/C28xx_CPU1");

    //This is needed since DSS is not able to use the "CCXMLFile". If the option
    //below is not set, the bootrom and manufacturing data in Flash will be erased.
    debugSession.options.setString("FlashEraseSelection", "Necessary Sectors Only (for Program Load)");

    //Set debugger in Realtime mode. Not sure this is needed ! Debuggr cannot connect if this is set !
    //debugSession.options.setBoolean("AllowInterruptsWhenHalted",true);

    debugSession.target.connect();
    debugSession.memory.loadProgram(programToLoad);

    var Hes_boards_0 = debugSession.symbol.getAddress("Hes_boards");
    var DELAY_TIME_BETWEEN_STEPS = 2000; //2 seconds delay in script

    //var DSS_HES_NOT_RESPONDING_LABEL_ADDR = debugSession.symbol.getAddress("DSS_HES_NOT_RESPONDING_LABEL");
    //debugSession.breakpoint.add(DSS_HES_NOT_RESPONDING_LABEL_ADDR);

    //var DSS_HES_LCD_ADD_FAULT_LABEL_ADDR = debugSession.symbol.getAddress("DSS_HES_LCD_ADD_FAULT_LABEL");
    //debugSession.breakpoint.add(DSS_HES_LCD_ADD_FAULT_LABEL_ADDR);

    //Running "Asynch" means following statements in this script will be allowed to run.
    debugSession.target.runAsynch();

    Thread.sleep(DELAY_TIME_BETWEEN_STEPS); //wait time in between test steps

    //var DSS_HES_MSG_RX_LABEL_ADDR = debugSession.symbol.getAddress("DSS_HES_MSG_RX_LABEL");
    //debugSession.breakpoint.add(DSS_HES_MSG_RX_LABEL_ADDR);

    var DSS_HES_TIMEOUT_LABEL_ADDR = debugSession.symbol.getAddress("DSS_HES_TIMEOUT_LABEL");
    var DSS_HES_TIMEOUT_LABEL_BRK = debugSession.breakpoint.add(DSS_HES_TIMEOUT_LABEL_ADDR);

    var time_since_HES_data_received_addr = Hes_boards_0 + 0x20;

    //debugSession.memory.writeData(1, x_address, your_data, 16); // This writes your_data to the global variable x.
    //var time_since_HES_data_received_before = debugSession.memory.readData(1, time_since_HES_data_received_addr, 16);
    debugSession.memory.writeData(1, time_since_HES_data_received_addr, 100, 16);
    //var time_since_HES_data_received_after = debugSession.memory.readData(1, time_since_HES_data_received_addr, 16);

    debugSession.breakpoint.remove(DSS_HES_TIMEOUT_LABEL_BRK);

    //var DSS_HES_DISCARD_REPLY_LABEL_ADDR = debugSession.symbol.getAddress("DSS_HES_DISCARD_REPLY_LABEL");
    //debugSession.breakpoint.add(DSS_HES_DISCARD_REPLY_LABEL_ADDR);
    //debugSession.memory.writeData(1, time_since_HES_data_received_addr, 10, 16);

    var max_num_fault_entries_addr = debugSession.symbol.getAddress("max_num_fault_entries");
    //var max_num_fault_entries_symbol = debugSession.symbol.lookupSymbol(1, 0x0000c3de);
    //var max_num_fault_entries_addr = debugSession.symbol.getAddress("_max_num_fault_entries");
    var max_num_fault_entries_before = debugSession.memory.readData(1, max_num_fault_entries_addr, 16);

    //var max_num_fault_entries_before = debugSession.memory.readData(1, 0x0000c3de, 16);
    print("max_num_fault_entries_before is: ", max_num_fault_entries_before);

    debugSession.target.runAsynch();

    Thread.sleep(2000); //wait 2 seconds

    var max_num_fault_entries_after = debugSession.memory.readData(1, max_num_fault_entries_addr, 16);
    //var max_num_fault_entries_after = debugSession.memory.readData(1, 0x0000c3de, 16);
    print("max_num_fault_entries_after is: ", max_num_fault_entries_after);

    var DSS_HES_OVERTEMP_LABEL_ADDR = debugSession.symbol.getAddress("DSS_HES_OVERTEMP_LABEL");
    var DSS_HES_OVERTEMP_LABEL = debugSession.breakpoint.add(DSS_HES_OVERTEMP_LABEL_ADDR);

    Thread.sleep(200); //wait 200 ms

    var phaseATemperature_addr = Hes_boards_0 + 0x8;
    debugSession.memory.writeData(1, phaseATemperature_addr, 0xEFFF, 16);

    debugSession.breakpoint.remove(DSS_HES_OVERTEMP_LABEL);

    debugSession.target.runAsynch();




  • The simplified script below works reliably...

    Question now is what exactly is the problem with the full script.

    ========================================================

    importPackage (Packages.com.ti.debug.engine.scripting);
    importPackage (Packages.com.ti.ccstudio.scripting.environment);
    importPackage (Packages.java.lang);
    var ccsInstallDir = "C:/ti/ccsv8";
    var dssDir = "C/ti/DSS";
    var CCXMLFile = "C:/Users/pmmotora/ti/CCSTargetConfigurations/NewTargetConfiguration.ccxml"
    var programToLoad = "C:/CODE/devel_HTA_mmi_2085_2086_dbg/Releases/HTA/HTA_Master_runtime/HTA_Master_runtime.out"
    //var logFile = "C:/ti/DSS";
    var script = ScriptingEnvironment.instance();
    script.traceBegin("logFile.xml", "C:/ti/ccsv8/ccs_base/scripting/examples/DebugServerExamples/DefaultStylesheet.xsl");
    script.traceSetConsoleLevel(TraceLevel.INFO);
    script.traceSetFileLevel(TraceLevel.INFO);
    script.traceWrite("Begin Script Session");
    var debugServer = script.getServer("DebugServer.1");
    debugServer.setConfig("C:\\Users\\pmmotora\\ti\\CCSTargetConfigurations\\NewTargetConfiguration.ccxml");
    var debugSession = debugServer.openSession("Texas Instruments XDS2xx USB Debug Probe_0/C28xx_CPU1");

    //This is needed since DSS is not able to use the "CCXMLFile". If the option
    //below is not set, the bootrom and manufacturing data in Flash will be erased.
    debugSession.options.setString("FlashEraseSelection", "Necessary Sectors Only (for Program Load)");

    //Set debugger in Realtime mode. Not sure this is needed ! Debugger cannot connect if this is set !
    //debugSession.options.setBoolean("AllowInterruptsWhenHalted",true);

    debugSession.target.connect();
    debugSession.memory.loadProgram(programToLoad);

    //Running "Asynch" means following statements in this script will be allowed to run.
    debugSession.target.runAsynch();

    Thread.sleep(DELAY_TIME_BETWEEN_STEPS); //wait time in between test steps

    var max_num_fault_entries_addr = debugSession.symbol.getAddress("max_num_fault_entries");
    var max_num_fault_entries_before = debugSession.memory.readData(1, max_num_fault_entries_addr, 16);
    print("max_num_fault_entries_before is: ", max_num_fault_entries_before);
  • I tried the example main.c without issue.

    When at main, enter the below command in the scripting console:

    js:> activeDS.symbol.getAddress("test2")

    It should return the address (as an integer value). Does that work? If so, then it may be an issue with your script

  • Ki,

    You will see in my main.c example, "test2" is NOT static. Paul is not having an issue with non-static globals. He is however having a problem with static globals, in this case, from my example, a variable called "test".

    I put "test" and "test2" in the example so that I could contrast them with the TI CGT objdump tools. BTW, the compiler is TI C2000 CGT.

    Thanks,

    Stuart

  • Stuart Baker said:
    You will see in my main.c example, "test2" is NOT static. Paul is not having an issue with non-static globals. He is however having a problem with static globals, in this case, from my example, a variable called "test".

    I do not have an issue with either test or test2:

  • Ki,

    Upon further thought, my example is probably too simplified. I probably need to have the static variable in another compilation unit (*.c file) from where my current program counter context is to reproduce the issue. Otherwise, the debugger will see the static variable as in scope, even if it is static.

    Thoughts?

    Stuart

  • Ki,

    I moved the static variable into its own compilation unit. I can reproduce the issue (static variable out of scope).

    extern void test_method(void);
    
    /**
     * main.c
     */
    int main(void)
    {
        while (1)
        {
            test_method();
        }
    	return 0;
    }
    

    volatile static int test;
    volatile int test2;
    
    void test_method(void)
    {
        ++test;
        ++test2;
    }
    

  • Yes that would be expected since 'test' is out of scope. If Paul is trying to access the variable "as-is" while the variable is out of scope, that would explain the script failure.

  • Ki,

    I agree. In the watch expression window, we can use the '<filename>'::<variable name> syntax to "scope" the access of static variables. Can we do something similar in the scripting console to give it the scope necessary to find the static variable?

    Thanks,

    Stuart

  • Not with symbol.getAddress API. But as a workaround you can use a GEL expression with the expression.evaluate API:

    js:> var addr1 = activeDS.expression.evaluate("&'test.c'::test")

  • Ki,

    This is interesting. It does seem to work for me. Paul, can you evaluate this on your end to see if it meets your need?

    Thanks,

    Stuart

  • I will try this soon. My remote computer is acting up and needs a reboot.

    But I am still wondering why getting the static variable symbol in the simplified script works. 

  • Sweet. That worked. Thanks.

    So do not try "getAddress" with static variables is the lesson ?

  • One more thing before I mark this issue Resolved...

    Where do I find the documentation on specifying the filename in front of the static variable ?

        var max_num_fault_entries_addr = debugSession.expression.evaluate("&'lcd.c'::max_num_fault_entries")
    I looked in DSS_API documentation but could not find this detail.
  • Paul Motora1 said:
    So do not try "getAddress" with static variables is the lesson ?

    I would need to confirm this but it appears that getAddress would require the variable to be in scope.

    expression.evaluate allows you to use GEL to workaround this limitation.

  • Paul Motora1 said:
    I looked in DSS_API documentation but could not find this detail.

    It would not be in the DSS API documentation since expression.evaluate is simply a way to call GEL expressions. You can reference the GEL documentation in the CCS User's Guide:

    https://software-dl.ti.com/ccs/esd/documents/users_guide/gel/namespace.html#gel-namespace

    Thanks

    ki

  • Thanks a lot for helping me out.