microsoft / microsoft/vscode-cpptools

Issue with Variable Values when Debugging

Open
#7,821 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hi,

I'm debugging Fortran code in Mac OSX 11.4 using Visual Studio Code using GDB and the C+/C++ Debugger with Fortran Breakpoint Support in Visual Studio Code. In launch.json, I have the following code:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Run GDB",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceRoot}/a.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "externalConsole": false,
            "MIMode": "gdb",
            "preLaunchTask": "make"
        },
    ]
}

In tasks.json, I have the following code:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "make",
            "type": "shell",
            "command": "make",
            "options": {
                "cwd": "${workspaceRoot}"
            }
        }
  
    ]
}

In my Makefile I have:

# variables
FC=gfortran
SRC=Parameters.f90 Globals.f90 Procedures.f90 random.f90 SimulateEarnings.f90 Grids.f90 ValueFunctions.f90 Simulations.f90 RunSimulations.f90
OBJ=${SRC:.f90=.o}

# convert all .f90 files into .o files
%.o: %.f90
	$(FC) -c -g $<

# create executable
a.out: ${OBJ}
	$(FC) ${OBJ}

# clean
clean:
	rm *.o a.out

# execute
run:
	make
	./a.out

I can run make and make run in the terminal with no issues. In Visual Studio Code, I then place a breakpoint using F9 at a place in my code and press F5 to begin debugging. When doing so, three issues arise:

  1. The code does not always stop at my breakpoint and the only way I can get it to eventually stop is to repeatedly restart debugging until it finally stops.
  2. Once it does finally stop, the values of all variables are not displayed. The only way I can find them is by manually adding variables to "WATCH".
  3. The values of some of the variables in "WATCH" are incorrect. If I set a breakpoint on the line of code at which I print a variable to the console, the value printed to the console doesn't match what is displayed in "WATCH".

Thanks in advance for the help and sorry for the long question!

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.

Research direction

Start by reproducing the breakpoint and variable-display problems with the provided launch.json, tasks.json, and Makefile on macOS using GDB and the Fortran executable. Compare the debugger behavior with the console output and determine whether the issue can be isolated to the VS Code C/C++ extension; done means a confirmed cause with a targeted fix or documented limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
fortran, macos, vscode
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.