microsoft / microsoft/vscode-cpptools

GDB commands often fail with 'No symbol "someSymbol" in current context.'

Open
#5,235 6 comments 7 reactions 1 assignee View on GitHub

@WardenGnaw is already working on this.

Since Apr 1, 2020.

bug debugger
Dominant language
TypeScript
Stars
6.2k
Forks
1.7k
Avg merge
14h 46m
Merged PRs (30d)
61

Description

Type: Debugger

Describe the bug

  • OS and Version: Debian 9
  • VS Code Version: 1.43.2
  • C/C++ Extension Version: 27.0
  • Other extensions you installed (and if the issue persists after disabling them): None
  • A clear and concise description of what the bug is.

When debugging I find that when I first try to execute a gdb command with -exec, I get the error 'No symbol "someSymbol" in current context.' even though that variable is clearly in scope. If I hover over the variable or execute a non-gdb command first, and then execute the gdb command, that fixes the problem.

I attached a small repro where I can reproduce the problem by doing the following:

  1. Add a breakpoint inside Widget::doStuff
  2. Start debugging and switch away from the "Run/Debug" view before hitting the breakpoint. Go to the explorer view, for example.
  3. After hitting the breakpoint, try running '-exec p a' in the debug console and note that it doesn't work
  4. Switch back to the "Run/Debug" view and execute a gdb command. It works now.

This reproduces very frequently when trying to debug our project at work. I noticed that it happens most often when trying to print a member variable from within a method. Local variables often work. I attached the log output after following the above repro steps on my work example.

log.txt
repro.zip

Compile the repro with g++ -g main.cpp and debug with the following launch.json:

    {
        "name": "Debug Repro",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}/a.out",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": false,
        "MIMode": "gdb",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ],
        "miDebuggerPath": "/usr/bin/gdb"
    }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.