microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.45k stars 1.53k forks source link

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

Open froha opened 2 weeks ago

froha commented 2 weeks ago

Environment

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

github-actions[bot] commented 2 weeks ago

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.

froha commented 2 weeks ago

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.