skip to Main Content

I have my launch.json file that contains:

        {
            "request": "launch",
            "type": "cortex-debug",
            "name": "Rt117xDemo Start",
            "cwd": "${workspaceFolder}",
            "executable": "${workspaceFolder}/FW/image/Rt117xDemo.elf",
            "servertype": "jlink",
            "device": "MIMXRT1176xxxA_M7",
            "interface": "swd",
            "rtos": "FreeRTOS",
            "svdFile": "${workspaceFolder}/FW/bsp/device/MIMXRT1175_cm7.svd",
            "runToEntryPoint": "main",
            "preLaunchTask": "build",
            "serverArgs": [
                "-gui"
            ],
            "preLaunchCommands": [
                "directory ${workspaceFolder}/FW"
            ],
            "postLaunchCommands": [
                "monitor reg pc 0x30002100"
            ]
        }

I would like the address of the last line ("monitor reg pc 0x30002100") to be either the output of a bash command, or perhaps a "variable" (like ${workspaceFolder}) that I would like to populate with the output of a bash command.

how can I achieve this?

EDIT 2023-23-06

I explain what I would like to do in this example.

I should run the following command:

/path/to/arm-none-eabi-readelf -l FW/image/Rt117xDemo.elf | sed -n 's/Entry point (0x[[:xdigit:]]{8})/1/p'

this command prints the address I need. It is taken from the compiled file so this command should be run every time I launch debugging (and certainly after running the build task).

so I’d like to be able to edit the launch.json line like this:

"postLaunchCommands": [
    "monitor reg pc ${command: /path/to/arm-none-eabi-readelf -l ${workspaceFolder}/FW/image/Rt117xDemo.elf | sed -n 's/Entry point (0x[[:xdigit:]]{8})/1/p'}"
]

2

Answers


  1. you can use the extension Command Variable and the command:

    extension.commandvariable.file.content

    Use an ${input} variable:

    "postLaunchCommands": [
      "${input:fileContent}"
    ]
    
    Login or Signup to reply.
  2. most likely the variables in the launch config are resolved before any execution is performed.

    You then need to defer the execution of your monitor command to a shell script

    "postLaunchCommands": [
        "/path/to/run-monitor.sh ${workspaceFolder}"
    ]
    

    /path/to/run-monitor.sh

    #!/bin/sh
    ADDRESS=(/path/to/arm-none-eabi-readelf -l $1/FW/image/Rt117xDemo.elf | sed -n 's/Entry point (0x[[:xdigit:]]{8})/1/p')
    monitor reg pc $ADDRESS
    

    (my bash is a bit rusty, but you see the point)

    Assign the result of the command arm-none-eabi-readelf | sed to a variable and use that variable.

    The workspace path to use is a parameter of the run-monitor.sh script.

    If you put run-monitor.sh in your PATH and give it exe permission you don’t have to specify the path.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search