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.

CCSTUDIO: Debug Server Automation in CCS

Part Number: CCSTUDIO

Hi, 

I have a self-managed makefile project for a C28x MCU and I'm trying to simplify the debugging process in CCS 20.3.1.

Currently, in order to run a debug session I perform the following steps:

  1. Build and load the application via makefile on CLI (or through a task defined in tasks.json)
  2. Open the Debug Panel
  3. Import the target configuration file for the project (one-time).
  4. Start a project less debug session (this gets loaded in tasks.json).
  5. Connect the debugger to the target.
  6. Load symbols from my *.out file
  7. Set a breakpoint to `main()`
  8. Run the target.

I'd like to automate steps 4 through 8 so that debugging is less painful for myself and my team. Additionally, we'd really like to make it so this can be a portable solution that is either managed in the repo or easily reproducible via a config file (pasted in our Wiki or similar).

 

A couple things I've tried so far, and the questions I have regarding each:

Defining a session in `launch.json` file.

Based on the information in this page: https://software-dl.ti.com/ccs/esd/documents/users_guide/ccs_debug-main.html

I've created a launch configuration that looks like this:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug myProject",
            "type": "ccs-debug",
            "request": "launch",
            "targetConfig": "/path/to/project/target_configs/bh560v2.ccxml",
            "connections": [
              {
                "name": "Blackhawk XDS560v2-USB System Trace Emulator IcePick_C_0",
                "cores": [
                  {
                    "name": "C28xx_CPU1",
                    "program": "/path/to/project/build/out/myProject.out",
                    "autoConnect": true,
                    "loadSymbolsOnly": true
                  }
                ]
              }
            ]
        }
    ]
}

However, running this launch only seems to accomplish Step 4 above, rather than accomplishing Steps 4-6. When running, I still have to connect the target, load the symbol file before I can set my breakpoints and start running the application.

 

Is there something I'm missing here or should this technically work?

Scripting Console

This seemed promising and is close to being a full solution with a couple of issues:

  1. Using the Scripting Console directly in CCS means that you still need to execute commands in ordeer to get the debug session started. This quickly becomes cumbersome to do.
  2. Using the file load option is better, but still requires you to manually select the .js file you want to run, and then also ensure that you include commands for navigating to the root directory of your project since the CWD is wherever `consoleMain.js` is located.

With this method, is there a way to automatically invoke the Scripting Console with an initialization script, similar to how a .gdbinit or .bashrc file might? Or maybe invoke this as an action in tasks.json or launch.json?

Scripting Commands via CLI

Similar to the above, it looks like we can run custom scripts with the supplied run.bat/sh. Then, it looks like we can open a graphical debug session with `ds.launchCCS()`. This seems to work really well, and it is possible to wrap the whole thing into a script or as a target in the makefile. The biggest issue though, is that it fails if CCS is already open. Specifically, the error is due to two instances of CCS having the same "workspace" or folder opened. Since we'd likely already have CCS open to view the source code before opening a debug session, we would need to close the window before executing this .... not ideal.

Seems to me that a missing option for the `launchCCS()` function is to attach to an already existing CCS proceess. Is this something that exists or it is possible to get this sort of behavior in some other way? Or is there some insight you might be able to give related to how to control what folder CCS opens when launched this way?

 

Thanks!

  • Hello,

    I assume the goal is to have a automate the launch of a debug session in the IDE to set up the environment for manual debug of an out file created outside CCS IDE.

    1. Start a project less debug session (this gets loaded in tasks.json).
    2. Connect the debugger to the target.
    3. Load symbols from my *.out file
    4. Set a breakpoint to `main()`
    5. Run the target.

    I'd like to automate steps 4 through 8 so that debugging is less painful for myself and my team.

    What I would recommend is using an initialization script associated with your debug launch:

    https://software-dl.ti.com/ccs/esd/documents/users_guide_ccs/ccs_debug-main.html#initialization-scripts

    Hence you can execute the launch configuration for your target configuration and then automate all the desired actions in the referenced initialization script using CCS Scripting.

    Thanks

    ki

  • Hi Ki,

    Thanks for the reply. Yes, I am looking for a way to automate a debug session from an non-CCS project.

    The solution you provide does look like it should resolve the issue, but I'm having some troubles getting the initialization script to run.

    My launch.json

    {
      // Use IntelliSense to learn about possible attributes.
      // Hover to view descriptions of existing attributes.
      "version": "0.2.0",
      "configurations": [
        {
          "name": "bh560v2.ccxml",
          "type": "ccs-debug",
          "request": "launch",
          "targetConfig": "${workspaceFolder}/target_configs/bh560v2.ccxml",
          "initialihttps://e2e.ti.com/support/processors-group/processors/f/processors-forum/1588038/ccstudio-debug-server-automation-in-ccs/6119110#zationScript": "${workspaceFolder}/target_configs/debug_init.mjs"
        }
      ]
    }

    And then my initialization script

    // Initialize scripting
    const ds = initScripting();
    
    // Open our session
    const session = ds.openSession(/CPU1/);
    
    // Connect to our target
    session.target.connect();
    
    // Run
    session.target.run();
    

    When I run this launch configuration, the debug session starts, but the target does not connect. Is there a way to debug this at all?

  • Looks like you have a copy and paste typo in your launch.json file on line 11. But I know what you are trying to do.

    Is there a way to debug this at all?

    Try running your initialization script from the Scripting Console. Few remove line 11 from the json file (and the trailing comma on line 10). Then comment out line 2 of the init scipt and then add a ds.config call after line 2 that passes in the full path to the ccxml file used in you json script. The load your js script in the Scripting Console and see if it runs successfully.

  • The problem I seem to be having is that the initialization script isn't being invoked. I tried adding some code to the beginning of my initialization script that writes to a file, but the file isn't written when running my launch configuration. When I manually copy/paste this bit of code into the scripting console, it runs (and my file is created), so I'm fairly positive that the issue isn't the code

    Again, my launch.json (Note: I've tried this with absolute paths as well with no change in behavior).

    {
      // Use IntelliSense to learn about possible attributes.
      // Hover to view descriptions of existing attributes.
      "version": "0.2.0",
      "configurations": [
            {
            "name": "bh560v2.ccxml",
            "type": "ccs-debug",
            "request": "launch",
            "targetConfig": "${workspaceFolder}/target_configs/bh560v2.ccxml",
            "initializationScript": "${workspaceFolder}/target_configs/debug_init.mjs"
            }
      ]
    }

    and then my updated debug_init.mjs

    // Initialization Script
    
    // File Writer to show signs of life
    const fs = require('node:fs');
    
    const content = 'Hello world';
    
    fs.writeFile('/absolute/path/to/my/file/test.txt', content, err => {
      if (err) {
        console.error(err);
      } else {
        // file written successfully
      }
    });
    
    
    // Start Debug Server Scripting
    const ds = initScripting();
    
    // Open our session
    const session = ds.openSession(/CPU1/);
    
    // Connect to our target
    session.target.connect();
    
    // Run to main()
    session.target.run();

    I'm not quite sure what the issue could be here since it looks like I'm following everything in the documentation. Is it possible there's a setting hidden away that I'm missing?

    Regarding your second note:

    Few remove line 11 from the json file (and the trailing comma on line 10). Then comment out line 2 of the init scipt and then add a ds.config call after line 2 that passes in the full path to the ccxml file used in you json script.

    This doesn't seem possible. When attempting to run a launch configuration from the Debug Panel that doesn't contain a targetConfig key, I receive this error.

    Edit: Just in case it comes up. My hardware setup is: BlackHawk USB560v2 System Trace + TMS320F2837xD C2000 DSP

  • If you rename the .mjs extension to .js and use that, does it work?

  • Aha, that seemed to work.

    Thanks!

  • Great! 

    I checked with engineering and looks like CCS is explicitly looking for just *.js files. They are looking into allowing *.mjs files also.