当前位置:   article > 正文

vscode调试程序设置_vscode cscope

vscode cscope

主要设置和json内容如下:

cpp_properties.json内容:

  1. {
  2. "configurations": [ //C++ intellisense插件需要这个文件,主要是用于函数变量等符号的只能解析
  3. {
  4. "name": "Win32",
  5. "includePath": [
  6. "${workspaceFolder}/**"
  7. ],
  8. "browse":{//解析工作路径下的所有文件夹或者文件中的符号
  9. "path": ["${workspaceFolder}/**"]
  10. },
  11. "defines": [
  12. "_DEBUG",
  13. "UNICODE",
  14. "_UNICODE"
  15. ],
  16. "compilerPath": "C:\\mingw64\\bin\\gcc.exe",
  17. "cStandard": "c17",
  18. "cppStandard": "gnu++17",
  19. "intelliSenseMode": "windows-gcc-x64"
  20. }
  21. ],
  22. "version": 4
  23. }

lanuch.json内容(更改launch中的可执行文件路径,也可以调试makefile和cmake管理生成的项目)

  1. {
  2. // 使用 IntelliSense 了解相关属性。
  3. // 悬停以查看现有属性的描述。
  4. // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
  5. "version": "0.2.0",
  6. "configurations": [ //launch.json主要用于调试程序
  7. {
  8. "name": "(gdb) 启动",
  9. "type": "cppdbg", //注意这个地方,如果为gdb,遇到断点时可能变量的值显示不正确
  10. "request": "launch",
  11. "program": "${workspaceFolder}/pointerTest.exe", //需要调试的可执行文件的路径
  12. "args": [],
  13. "stopAtEntry": false, //程序是否停在开始处
  14. "cwd": "${fileDirname}",
  15. "environment": [],
  16. "externalConsole": false, //程序运行时是否新建终端,为false直接在vscode编辑器里面的终端显示
  17. "MIMode": "gdb",
  18. "miDebuggerPath": "C:/mingw64/bin/gdb.exe", //gdb命令的路径,不指定路径程序可能会运行不正常
  19. "setupCommands": [ //gdb调试前需要执行的命令
  20. {
  21. "description": "为 gdb 启用整齐打印",
  22. "text": "-enable-pretty-printing",
  23. "ignoreFailures": true
  24. },
  25. {
  26. "description": "将反汇编风格设置为 Intel",
  27. "text": "-gdb-set disassembly-flavor intel",
  28. "ignoreFailures": true
  29. },
  30. {
  31. "description": "忽略GDB中的SIGUSR1信号",
  32. "text": "handle SIGUSR1 nostop noprint pass", //三个参数notop noprint pass在vscode中需要全部加上才能生效
  33. "ignoreFailures": true
  34. }
  35. ]
  36. }
  37. ]
  38. }

task.json内容

  1. {
  2. "tasks": [ //task.json用于编译程序时使用
  3. {
  4. "type": "cppbuild",
  5. "label": "C/C++: gcc.exe 生成活动文件",
  6. "command": "C:\\mingw64\\bin\\gcc.exe", //指定编译器的绝对路径
  7. "args": [ //编译器进行编译时的指定的参数:可进行额外的参数添加,如 "-std=c++11"、指定需要链接的库的路径
  8. "-fdiagnostics-color=always",
  9. "-g",
  10. "${file}",
  11. "-o",
  12. "${fileDirname}\\${fileBasenameNoExtension}.exe"
  13. ],
  14. "options": {
  15. "cwd": "${fileDirname}"
  16. },
  17. "problemMatcher": [
  18. "$gcc"
  19. ],
  20. "group": {
  21. "kind": "build",
  22. "isDefault": true
  23. },
  24. "detail": "调试器生成的任务。"
  25. }
  26. ],
  27. "version": "2.0.0"
  28. }

另附vscode C++环境的一些推荐插件

cscope插件可用于智能解析项目中的符号, 一定程度上可替代C Call Hierarchy插件。

Ubuntu安装ctags:

1、首先从github上下载ctags可执行文件,使用tar -xf解压下载下来的.tar.xz文件

2、将可执行文件的路径添加到环境变量: vim /etc/profile

export  PATH=$PATH:/usr/bin/uctags/bin

其中/user/bin/uctags/bin是我的ctags可执行文件的路径,操作时需要修改为博友们自己的路径

3 执行source /etc/profile命令使得添加的环境变量立即生效

4 在ubuntu终端执行命令:apt-get install cscope universal-ctags即可生效。

5在vscode中按f1,弹出窗口输入c call ,如下图所示

6选择显示调用层次或者build database(有时候会显示build database,有时候不会显示),然后会构建项目的解析文件,如下图所示:

7构建完成之后,.vscode文件夹下面会有cscope.out和ctags.out文件,此时C Call Hierarchy即可正常工作。

注意:此处uctags可能会被装了两遍,第一遍在步骤1,第二遍在步骤4。只执行步骤4,vscode并不能主动识别到uctags的路径,因此C Call Hierarchy插件也就不能正常工作。

另附clang-format格式化模板

  1. ---
  2. BasedOnStyle: Google
  3. ---
  4. Language: Cpp
  5. AccessModifierOffset: -4
  6. # AlignAfterOpenBracket: Align
  7. # AlignConsecutiveMacros: false
  8. # 连续赋值时,对齐所有等号
  9. AlignConsecutiveAssignments: true
  10. # AlignConsecutiveDeclarations: false
  11. # AlignEscapedNewlines: Left
  12. # AlignOperands: true
  13. # AlignTrailingComments: true
  14. # AllowAllArgumentsOnNextLine: true
  15. AllowAllConstructorInitializersOnNextLine: false
  16. # AllowAllParametersOfDeclarationOnNextLine: true
  17. # AllowShortBlocksOnASingleLine: Never
  18. AllowShortCaseLabelsOnASingleLine: true
  19. # AllowShortFunctionsOnASingleLine: All
  20. # AllowShortLambdasOnASingleLine: All
  21. # AllowShortIfStatementsOnASingleLine: WithoutElse
  22. # AllowShortLoopsOnASingleLine: true
  23. # AlwaysBreakAfterDefinitionReturnType: None
  24. # AlwaysBreakAfterReturnType: None
  25. AlwaysBreakBeforeMultilineStrings: false
  26. # AlwaysBreakTemplateDeclarations: Yes
  27. # BinPackArguments: true
  28. # BinPackParameters: true
  29. BraceWrapping:
  30. # AfterCaseLabel: false
  31. AfterClass: true
  32. AfterControlStatement: Always
  33. AfterEnum: true
  34. AfterFunction: true
  35. AfterNamespace: true
  36. # AfterObjCDeclaration: false
  37. AfterStruct: true
  38. AfterUnion: true
  39. AfterExternBlock: true
  40. BeforeCatch: true
  41. BeforeElse: true
  42. # IndentBraces: false
  43. # SplitEmptyFunction: true
  44. # SplitEmptyRecord: true
  45. # SplitEmptyNamespace: true
  46. # BreakBeforeBinaryOperators: None
  47. BreakBeforeBraces: Custom
  48. # BreakBeforeInheritanceComma: false
  49. # BreakInheritanceList: BeforeColon
  50. # BreakBeforeTernaryOperators: true
  51. # BreakConstructorInitializersBeforeComma: false
  52. # BreakConstructorInitializers: BeforeColon
  53. # BreakAfterJavaFieldAnnotations: false
  54. # BreakStringLiterals: true
  55. ColumnLimit: 100
  56. CommentPragmas: "^ NOLINT:"
  57. # CompactNamespaces: false
  58. # ConstructorInitializerAllOnOneLineOrOnePerLine: true
  59. # ConstructorInitializerIndentWidth: 4
  60. # ContinuationIndentWidth: 4
  61. # Cpp11BracedListStyle: true
  62. # DeriveLineEnding: true
  63. # DerivePointerAlignment: true
  64. # DisableFormat: false
  65. # ExperimentalAutoDetectBinPacking: false
  66. # FixNamespaceComments: true
  67. # ForEachMacros:
  68. # - foreach
  69. # - Q_FOREACH
  70. # - BOOST_FOREACH
  71. # IncludeBlocks: Regroup
  72. # IncludeCategories:
  73. # - Regex: '^<ext/.*\.h>'
  74. # Priority: 2
  75. # SortPriority: 0
  76. # - Regex: '^<.*\.h>'
  77. # Priority: 1
  78. # SortPriority: 0
  79. # - Regex: "^<.*"
  80. # Priority: 2
  81. # SortPriority: 0
  82. # - Regex: ".*"
  83. # Priority: 3
  84. # SortPriority: 0
  85. # IncludeIsMainRegex: "([-_](test|unittest))?$"
  86. # IncludeIsMainSourceRegex: ""
  87. # IndentCaseLabels: true
  88. # IndentGotoLabels: true
  89. # IndentPPDirectives: None
  90. IndentWidth: 4
  91. # IndentWrappedFunctionNames: false
  92. # JavaScriptQuotes: Leave
  93. # JavaScriptWrapImports: true
  94. # KeepEmptyLinesAtTheStartOfBlocks: false
  95. # MacroBlockBegin: ""
  96. # MacroBlockEnd: ""
  97. # MaxEmptyLinesToKeep: 1
  98. # NamespaceIndentation: None
  99. # ObjCBinPackProtocolList: Never
  100. # ObjCBlockIndentWidth: 2
  101. # ObjCSpaceAfterProperty: false
  102. # ObjCSpaceBeforeProtocolList: true
  103. # PenaltyBreakAssignment: 2
  104. # PenaltyBreakBeforeFirstCallParameter: 1
  105. # PenaltyBreakComment: 300
  106. # PenaltyBreakFirstLessLess: 120
  107. # PenaltyBreakString: 1000
  108. # PenaltyBreakTemplateDeclaration: 10
  109. # PenaltyExcessCharacter: 1000000
  110. # PenaltyReturnTypeOnItsOwnLine: 200
  111. PointerAlignment: Right
  112. # RawStringFormats:
  113. # - Language: Cpp
  114. # Delimiters:
  115. # - cc
  116. # - CC
  117. # - cpp
  118. # - Cpp
  119. # - CPP
  120. # - "c++"
  121. # - "C++"
  122. # CanonicalDelimiter: ""
  123. # BasedOnStyle: google
  124. # - Language: TextProto
  125. # Delimiters:
  126. # - pb
  127. # - PB
  128. # - proto
  129. # - PROTO
  130. # EnclosingFunctions:
  131. # - EqualsProto
  132. # - EquivToProto
  133. # - PARSE_PARTIAL_TEXT_PROTO
  134. # - PARSE_TEST_PROTO
  135. # - PARSE_TEXT_PROTO
  136. # - ParseTextOrDie
  137. # - ParseTextProtoOrDie
  138. # CanonicalDelimiter: ""
  139. # BasedOnStyle: google
  140. # ReflowComments: true
  141. SortIncludes: false
  142. SortUsingDeclarations: false
  143. # SpaceAfterCStyleCast: false
  144. # SpaceAfterLogicalNot: false
  145. # SpaceAfterTemplateKeyword: true
  146. # SpaceBeforeAssignmentOperators: true
  147. # SpaceBeforeCpp11BracedList: false
  148. # SpaceBeforeCtorInitializerColon: true
  149. # SpaceBeforeInheritanceColon: true
  150. # SpaceBeforeParens: ControlStatements
  151. # SpaceBeforeRangeBasedForLoopColon: true
  152. # SpaceInEmptyBlock: false
  153. # SpaceInEmptyParentheses: false
  154. SpacesBeforeTrailingComments: 1
  155. # SpacesInAngles: false
  156. # SpacesInConditionalStatement: false
  157. SpacesInContainerLiterals: false
  158. # SpacesInCStyleCastParentheses: false
  159. # SpacesInParentheses: false
  160. # SpacesInSquareBrackets: false
  161. # SpaceBeforeSquareBrackets: false
  162. Standard: Cpp11
  163. # StatementMacros:
  164. # - Q_UNUSED
  165. # - QT_REQUIRE_VERSION
  166. TabWidth: 4
  167. # UseCRLF: false
  168. UseTab: Never

模板源自:我使用的 clang-format 配置文件 - 乌合之众 - 博客园 (cnblogs.com)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/461212
推荐阅读
相关标签
  

闽ICP备14008679号