vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

gdb executes expression from hovering over a define (expression) without brackets

Open froha opened this issue 1 year ago • 2 comments

Environment

  • OS and version: Win11 22H2
  • VS Code: 1.92.2
  • C/C++ extension: ms-vscode.cpptools
  • OS and version of remote machine (if applicable):
  • GDB / LLDB version: GNU gdb (Arm GNU Toolchain 13.3.Rel1 (Build arm-13.24)) 14.2.90.20240526-git

Bug Summary and Steps to Reproduce

Bug Summary: I'm not sure if this is the correct extension for the bug. It is from an old c-project.

Hovering over a define with an expression, will lead the gdb to execute the expression. #define LED_ON led = 100 #define LED_OFF led = 0

uint8_t led = 0;

LED_ON; dely(100); LED_OFF;

The extension tries to get the value of the define. But the gdb executes the expression of the define and sets the this value to the memory of the halted microcontroller.

197-var-create --thread 4 --frame 0 hover_41cfaa7f209f0751459adf07e2163093f0baf6914b74b82363bf47de05986d92 @ "LED_ON" -> =memory-changed,thread-group="i1",addr="0x20010f92",len="0x1"

So i can switch on or off the LED only with hovering over the define. It is the same with a normal variable.

Debugger Configurations

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug cortex-debug jlink",
            "request": "launch",
            "type": "cortex-debug",
            "servertype": "jlink",
            "cwd": "${workspaceFolder}",
            "executable": "${command:cmake.launchTargetPath}",
            "serverpath": "JLinkGDBServerCL.exe",
            "toolchainPrefix": "arm-none-eabi",
            "device": "STM32F205VG",
            "interface": "swd",
            "runToEntryPoint": "main",
            "svdPath": "${workspaceFolder}/Tools/Debug/STM32F215.svd",
            "rtos": "FreeRTOS",
            "showDevDebugOutput": "both",
            "liveWatch": {
                "enabled": true,
                "samplesPerSecond": 4
            },
            "swoConfig": {
                "enabled": true,
                "source": "socket",
                "swoFrequency": 4000000,
                // "swoFrequency": 6000000, // Only J-Link Ultra
                "cpuFrequency": 120000000,
                "decoders": [
                    // {
                    //     "label": "Port 0",
                    //     "type": "console",
                    //     "port": 0,
                    //     "showOnStartup": true,
                    //     // "logfile": "",
                    //     "timestamp": false,
                    //     "encoding": "ascii",
                    // },
                    // ... copy and change port and label
                ]
            }
        }

Debugger Logs

197-var-create --thread 4 --frame 0 hover_41cfaa7f209f0751459adf07e2163093f0baf6914b74b82363bf47de05986d92 @ "TEST_0"
-> =memory-changed,thread-group="i1",addr="0x20010f92",len="0x1"
GDB -> App: {"output":"","outOfBandRecord":[{"isStream":false,"type":"notify","asyncClass":"memory-changed","output":[["thread-group","i1"],["addr","0x20010f92"],["len","0x1"]]}]}
-> 197^done,name="hover_41cfaa7f209f0751459adf07e2163093f0baf6914b74b82363bf47de05986d92",numchild="0",value="0x0",type="uint8_t",has_more="0"
GDB -> App: {"output":"","token":197,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[["name","hover_41cfaa7f209f0751459adf07e2163093f0baf6914b74b82363bf47de05986d92"],["numchild","0"],["value","0x0"],["type","uint8_t"],["has_more","0"]]}}

Other Extensions

marus25.cortex-debug

Additional Information

No response

froha avatar Aug 26 '24 15:08 froha

Thank you for reporting this issue. We’ll let you know if we need more information to investigate it. Additionally, if you're working with GDB/LLDB, please note that the code is open source at https://github.com/microsoft/MIEngine/wiki/Contributing-Code . Your contributions are always welcome and appreciated.

github-actions[bot] avatar Aug 27 '24 12:08 github-actions[bot]

Don't trust the debugger! And it is dangerous for debugging microcontrollers, when the wrong output is switching.

  1. Run to the line Screenshot 2024-08-28 090608 test = 5 is correct
  2. move your mouse to line 71 on the define and wait for the hover to show up Now it shows 0 Screenshot 2024-08-28 090619
  3. After one step with the debugger the watch shows also 0 instead of 5 Screenshot 2024-08-28 090634

Debugsession was with cppdebug and mingw-w64.

froha avatar Aug 28 '24 07:08 froha

I can't repoduce this bug anymore. actual installed version: 1.25.3 (also tested with pre-release 1.26.2) Hovering over the define shows an empty small hovering box.

froha avatar Jun 23 '25 12:06 froha