microsoft / vscode-cpptools

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

Breakpoint get ignored since a Cproject trans into a C++ project #5926

Open Tracker647 opened 4 years ago

Tracker647 commented 4 years ago

Type: Debugger

my debugger:GNU gdb (GDB) 8.1

Describe the bug:

To Reproduce Please include a code sample and launch.json configuration. Steps to reproduce the behavior:

  1. rename all c files as cpp files,and change complier command in makefile from gcc to g++.

  2. Click on Ctrl+F5 for debugging.

  3. Termiral:'.

    Executing task: powershell -c mingw32-make < g++ -std=c++17 -Wall -Wextra -g -Iinclude -Llib src/tree.o src/petclub.o -o bin/main.exe Terminal will be reused by tasks, press any key to close it....'

  4. the director is disappeared and the red break dot become grey.

my C++ project structure: D:. │ Makefile │ ├─.vscode │ launch.json │ tasks.json │ ├─bin │ main.exe │ ├─include ├─lib └─src petclub.cpp petclub.o tree.cpp tree.h tree.o

launch.json { "version": "0.2.0", "configurations": [ { "name": "Debug", "type": "cppdbg", "request": "launch", "args": [], "stopAtEntry": true, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "linux": { "MIMode": "gdb", "miDebuggerPath": "gdb", "program": "${workspaceFolder}/bin/main" }, "osx": { "MIMode": "lldb", "miDebuggerPath": "lldb-mi", "program": "${workspaceFolder}/bin/main" }, "windows": { "MIMode": "gdb", "miDebuggerPath": "gdb.exe", "program": "${workspaceFolder}/bin/main.exe" }, "preLaunchTask": "build" } ] }

makefile `CC := g++ CFLAGS := -std=c++17 -Wall -Wextra -g

BIN := bin SRC := src INCLUDE := include LIB := lib

LIBRARIES :=

ifeq ($(OS),Windows_NT) EXECUTABLE := main.exe SOURCEDIRS := $(SRC) INCLUDEDIRS := $(INCLUDE) LIBDIRS := $(LIB) else EXECUTABLE := main SOURCEDIRS := $(shell find $(SRC) -type d) INCLUDEDIRS := $(shell find $(INCLUDE) -type d) LIBDIRS := $(shell find $(LIB) -type d) endif

CINCLUDES := $(patsubst %,-I%, $(INCLUDEDIRS:%/=%)) CLIBS := $(patsubst %,-L%, $(LIBDIRS:%/=%))

SOURCES := $(wildcard $(patsubst %,%/*.cpp, $(SOURCEDIRS))) OBJECTS := $(SOURCES:.cpp=.o)

all: $(BIN)/$(EXECUTABLE)

.PHONY: clean clean: -$(RM) $(BIN)/$(EXECUTABLE) -$(RM) $(OBJECTS)

run: all ./$(BIN)/$(EXECUTABLE)

$(BIN)/$(EXECUTABLE): $(OBJECTS) $(CC) $(CFLAGS) $(CINCLUDES) $(CLIBS) $^ -o $@ $(LIBRARIES)`

WardenGnaw commented 4 years ago

Does this issue occur if you run make clean then have it recompile as .cpp files?

Tracker647 commented 4 years ago

Does this issue occur if you run make clean then have it recompile as .cpp files?

I type command in bin file and the project root file but not success message,I used to delete the main.exeand rebuild it but the breakpoint is still become grey.

the message when I type make cleanin:

PS D:\myprogramming\C\Chapter17\TREE__> mingw32-make clean
rm -f bin/main.exe
process_begin: CreateProcess(NULL, rm -f bin/main.exe, ...) failed.
make (e=2): 系统找不到指定的文件。(No such file or directory)
mingw32-make: [Makefile:33: clean] Error 2 (ignored)
rm -f src/tree.o src/petclub.o
process_begin: CreateProcess(NULL, rm -f src/tree.o src/petclub.o, ...) failed.
make (e=2): 系统找不到指定的文件。(No such file or directory)
mingw32-make: [Makefile:34: clean] Error 2 (ignored)
PS D:\myprogramming\C\Chapter17\TREE__\bin> mingw32-make clean
mingw32-make: *** No rule to make target 'clean'.  Stop.
WardenGnaw commented 4 years ago

can you clean up all .exe and .o files and try to rebuild? it seems like it is trying to use the old .o's to rebuild and that has the file name with .c in it that is causing it to find the wrong file to bind the breakpoint.

Tracker647 commented 4 years ago

can you clean up all .exe and .o files and try to rebuild? it seems like it is trying to use the old .o's to rebuild and that has the file name with .c in it that is causing it to find the wrong file to bind the breakpoint.

You mean delete all .o files and .exe files? I try it,still failed.https://imgchr.com/i/dCtzS1

WardenGnaw commented 4 years ago

Can you add the following to your launch.json and share the output from the debug console?

"logging": {
   "engineLogging": true
}