问题一
项目场景:
debug时无法调试断点,断点信息提示信息如下:
Module containing this breakpoint has not yet loaded or the breakpoint address not be obtained
调试代码如下
statepattern
文件目录如下图
.├── main
├── MusicPlayer.cpp
├── MusicPlayer.h
├── MusicPlayerState.cpp
├── MusicPlayerState.h
├── MusicPlayerTest.cpp
├── PausedState.cpp
├── PausedState.h
├── PlayingState.cpp
├── PlayingState.h
├── README.md
├── StoppedState.cpp
└── StoppedState.h
问题描述:
# 原因分析:
手动编译程序时,编译语句没有写对少写了一个-g
g++ ./MusicPlayerTest.cpp ./MusicPlayer.cpp ./MusicPlayerState.cpp ./PausedState.cpp ./StoppedState.cpp ./PlayingState.cpp -o main
解决方案:
g++ -g ./MusicPlayerTest.cpp ./MusicPlayer.cpp ./MusicPlayerState.cpp ./PausedState.cpp ./StoppedState.cpp ./PlayingState.cpp -o main。
通过修改,程序能够顺利进入断点进行运行
问题二
项目场景:
tasks.json
launch.json 文件配置,能够实现编译以及调试功能
参考文档如下:
https://www.it1352.com/1977381.html
https://www.cnblogs.com/gwzz/p/13993367.html
文件目录如下图 (已经将上面的文件结构进行更改)
.
├── main
├── MusicPlayerTest.cpp
└── src
├── MusicPlayer.cpp
├── MusicPlayer.h
├── MusicPlayerState.cpp
├── MusicPlayerState.h
├── PausedState.cpp
├── PausedState.h
├── PlayingState.cpp
├── PlayingState.h
├── README.md
├── StoppedState.cpp
└── StoppedState.h
问题描述:
文档debug时老是出错,编译通不过,只能进行调试,
原因分析:
解决方案:
关键点如下,多路径编写,头文件路径
“args”: [
“-g”,
“
f
i
l
e
D
i
r
n
a
m
e
/
∗
∗
.
c
p
p
"
,
"
{fileDirname}/**.cpp", "
fileDirname/∗∗.cpp","{fileDirname}/src/**.cpp”,
“-I
w
o
r
k
s
p
a
c
e
F
o
l
d
e
r
/
s
r
c
"
,
"
−
o
"
,
"
{workspaceFolder}/src", "-o", "
workspaceFolder/src","−o","{workspaceFolder}/main”
],
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${fileDirname}/**.cpp",
"${fileDirname}/src/**.cpp",
"-I${workspaceFolder}/src",
"-o",
"${workspaceFolder}/main"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/g++"
}
]
}
launch.json
{
// 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": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/main",
"args": [],
"stopAtEntry": true,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}