'spidev_test.c works in release but not in debugging mode using VSC (Visual Studio Code) and docker

I am cross-compiling code to my target from a Windows laptop running VSC. I am trying to debug my SPI interface, which seems to be mostly working from what I can see so far, aside from some minor issues I want to debug.

My SPI is based entirely from the example code spidev_test.c found here: https://github.com/torvalds/linux/blob/master/tools/spi/spidev_test.c with very little modification.

I can reliably get the program to run when I create the executable (on my target, an ARM 32-bit processor on the Colibri iMX6DL 512MB IT module running on a Toradex Colibri Evaluation Board carrier board) and run it from the command line prompt.

However, when I run it using the debugger, it aborts on the line indicated below. The debugger inspects the value of device to be /dev/spidev3.0 as it should be, but the O_RDWR does not seem to evaluate to anything... although this might be #define:d (can you inspect a #define:d value with the debugger?)

parse_opts(argc, argv);
if (input_tx && input_file)
    pabort("ERROR 220: only one of -p and --input may be selected");

fileDescriptor = open(device, O_RDWR);                  // returns -1 
if (fileDescriptor < 0)
    pabort("ERROR 221: SPI can't open SPI device");  // exits the program inside this function

I am wondering if there is something I am doing wrong... I am new to VSC so any of the .json properties may be wrong...

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C++ Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceRoot}\\EmeraBlockEnergyBox",
            "args": [
                "-I", "5000", 
                "-s", "50", 
                "-v"
            ],
            "miDebuggerServerAddress": "",
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "gdb-multiarch",
            "targetArchitecture": "",
            "preLaunchTask": "${defaultBuildTask}",
            "setupCommands": [
                {
                    "description": "Setting architecture",
                    "text": "set architecture %{torizon.gdb-arch}",
                    "ignoreFailures": false,
                    "externalConsole":false
                }
            ]
        }
    ]
}

settings.json

{
    "torizon.configuration": "debug",
    "torizon.appfolder": "appconfig_0",
    "files.associations": {
        "numeric": "c",
        "stdlib.h": "c",
        "emerablockenergybox.h": "c",
        "spidev.h": "c",
        "cstdio": "c"
    }
}

tasks.json

{
"version": "2.0.0",
"tasks": [
    {
        "label": "build_debug",
        "command": "make",
        "type": "shell",
        "args": [],
        "problemMatcher": {
            "base": "$gcc"
        },
        "options": {
            "env": {
                "CFLAGS": "-g",
                "CXXFLAGS": "-g"
            }
        },
        "group": {
            "kind": "build",
            "isDefault": true
        }
    },
    {
        "label": "build_release",
        "command": "make",
        "type": "shell",
        "args": [],
        "problemMatcher": {
            "base": "$gcc"
        },
        "options": {
            "env": {
                "CFLAGS": ""
            }
        },
        "group": "build"
    },
    {
        "label": "clean",
        "command": "make",
        "type": "shell",
        "args": [
            "clean"
        ],
        "problemMatcher": {
            "base": "$gcc"
        },
        "group": "build"
    },
    {
        "detail": "deploy application to work folder",
        "label": "deploy",
        "command": "make",
        "args": [
            "WORKDIR=${command:torizon.ccpp.getTargetFolder}",
            "install"
        ],
        "type": "shell",
        "group": "none"
    }
],
"options": {
    "env": {
        "TORIZON_PROP_ARG": "ARG SSHUSERNAME=#%application.username%#\n"
    }
}
}

devcontainer.json

{
    "name": "torizon_EmeraBlockEnergyBox",
    "dockerFile": "Dockerfile",
    "extensions": [
        "ms-vscode.cpptools"
    ],
    "containerEnv": {
        "AR": "arm-linux-gnueabihf-ar",
        "AS": "arm-linux-gnueabihf-as",
        "CC": "arm-linux-gnueabihf-gcc",
        "CXX": "arm-linux-gnueabihf-g++",
        "CPP": "arm-linux-gnueabihf-cpp",
        "LD": "arm-linux-gnueabihf-ld",
        "STRIP": "arm-linux-gnueabihf-strip",
        "CROSS_COMPILE": "arm-linux-gnueabihf-"
    },
    "runArgs": [
        "--network=host"
    ],
    "remoteUser": "torizon",
    "postCreateCommand": "mkdir -p /home/torizon/.vscode-server-insiders/extensions ; mkdir -p /home/torizon/.vscode-server/extensions; ln -s /home/torizon/.torizon-extension /home/torizon/.vscode-server-insiders/extensions/toradex.torizon ; ln -s /home/torizon/.torizon-extension /home/torizon/.vscode-server/extensions/toradex.torizon ; chgrp docker /var/run/docker.sock ; true",
    "mounts": [
        "source=${localEnv:HOME}${localEnv:USERPROFILE}/.moses,target=/home/torizon/.moses,type=bind",
        "source=//var/run/docker.sock,target=/var/run/docker.sock,type=bind",
        "source=c:\\Users\\LeighBoyd\\.vscode\\extensions\\toradex.torizon-1.3.0,target=/home/torizon/.torizon-extension,type=bind"
    ]
}

Any ideas what I can try to make it work in debug mode?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source