VSCode: run build-script in debugger

Hello,

I’m trying to write a script that setup and build a Yocto image:

#!/bin/bash

set -eo pipefail

mkdir -p build
cd build

repo init -u https://git.toradex.com/toradex-manifest.git -b refs/tags/6.8.2 -m torizoncore/default.xml
repo sync
MACHINE=verdin-imx8mm EULA=1 source setup-environment

# todo build image

echo "finished"

When I call this script on the command line, everything works fine.
But when I use Visual Studio Code with the extension ‘Bash Debug’ to debug the script, I get the following error message when running the script in the debugger:

sha512sum: /layers/meta-toradex-torizon/scripts/setup-environment-internal: No such file or directory

When I execute the script in the debugger with single stepping, the error don’t occur.

This is my launch.json for the debugger:

{
    "version": "0.2.0",
    "configurations": [
    
        {
            "type": "bashdb",
            "request": "launch",
            "name": "Bash-Debug (simplest configuration)",
            "program": "${file}",
            "cwd": "${workspaceFolder}",
            "terminalKind": "integrated",
        }
    ]
}

Best regards,
Markus

Hi, I’m the Toradex AI Assistant.

I might make mistakes. Our support team will step in if needed. If I answered your question, please tick the “Solution” checkbox. For follow-up questions to me, please use @ToradexAI in your post.

Did you like my answer? :+1: :-1:


Hello Markus,

Thank you for your detailed question!

This issue arises because sourcing environment scripts like setup-environment and using Repo within shell scripts can behave differently when run directly versus being invoked within debuggers or special shells (such as those invoked by the Bash Debug extension in VS Code).

Why does it fail in Bash Debug?

Many Yocto scripts, especially setup-environment, rely heavily on the current working directory, specific environment variables, and a clean shell environment. Debuggers may not honor these, or they may not maintain changes made by sourced scripts (such as modifying $PATH), particularly when stepping versus running.

The error:

sha512sum: /layers/meta-toradex-torizon/scripts/setup-environment-internal: No such file or directory

usually means the script failed to find the expected Yocto workspace layout—often because the working directory or the sourced environment isn’t set up the way the script expects.

Recommendations

  • Use the Official Tools: For complex workflows like Yocto builds, it’s recommended to use the standard CLI in a Linux terminal, or leverage the Torizon IDE Extension for Visual Studio Code which is specifically designed for Toradex workflows instead of general shell script debuggers.

  • Debug in Steps: If you want to debug part of your script, consider isolating logic into smaller shell scripts/functions and debug those, or use set -x to trace steps.

  • Modify launch.json: If you need to debug the full process, try setting the "cwd" property in your launch.json explicitly to where your Yocto environment and folders are set up, and ensure any environment variables (like MACHINE and EULA) are included in the config.

    {
        "version": "0.2.0",
        "configurations": [
            {
                "type": "bashdb",
                "request": "launch",
                "name": "Bash-Debug (simplest configuration)",
                "program": "${file}",
                "cwd": "/absolute/path/to/your/build/folder",
                "env": {
                    "MACHINE": "verdin-imx8mm",
                    "EULA": "1"
                },
                "terminalKind": "integrated"
            }
        ]
    }
    
  • Single-Stepping vs. Running: The fact that stepping works but running doesn’t suggests a timing or state issue—often related to (re-)setting environment or current working directory. Sourcing scripts dynamically changes the shell’s environment, but this doesn’t always propagate in subprocesses as expected with debuggers.

Further Reading

Summary

For setting up and building Yocto/Torizon OS images, use the CLI or the Torizon IDE extension for best results. Debugging the shell scripts that source environment files within VS Code debuggers is non-trivial due to how these scripts modify their surrounding shell environment.

Let me know if you’d like tips on scripting the image build with just bash and logging, or if you’d like information about the Visual Studio Code Torizon extension!

Best regards,
Toradex AI Assistant.

Hello @Mowlwurf,

I could not install the bash debug extension that you use (I found it on Marketplace, but it does not show up after the installation).

It looks like a timing issue from what you are describing. It could be that the setup-environment is likely being sourced/executed before the repo sync has actually completed writing the full directory structure.

If you could verify that this is the problem, then I suggest either splitting the setup and build logic into two different bash scripts or adding a wait or file check logic before moving on to setting up the environment.