在使用 VSCode 进行 Go 语言开发时,我们经常需要进行调试以解决问题。然而,对于特定的 .go 文件,我们可能需要创建自定义的调试配置。那么,如何在 VSCode 中为特定 .go 文件创建调试配置呢?在本文中,php小编柚子将为您详细介绍具体步骤和注意事项,帮助您轻松实现这一目标。无论您是初学者还是有经验的开发者,本文都将为您提供有价值的指导。让我们开始吧!
问题内容
目前,必须先在编辑器中聚焦.go
文件进行调试,然后按F5键开始调试。
我想要的是能够按 F5 开始调试,但不必首先在编辑器中关注 main.go
。
这是VSCode生成的库存配置,F5之前必须关注.go
文件:
{ "name": "Launch Package", "type": "go", "request": "launch", "mode": "auto", "program": "${fileDirname}", }
尝试指定 program
和 cwd
以使其满意:
{ "name": "Launch Package", "type": "go", "request": "launch", "mode": "auto", "program": "${workspaceFolder}/cmd/sym_dump/main.go", "cwd": "${workspaceFolder}/cmd/sym_dump", }
但这不起作用,它抱怨未找到函数:
Starting: C:\Users\aybe\go\bin\dlv.exe dap --listen=127.0.0.1:49541 from C:\GitHub\psx_mnd_sym/cmd/sym_dump DAP server listening at: 127.0.0.1:49541 Build Error: go build -o C:\GitHub\psx_mnd_sym\cmd\sym_dump\__debug_bin2780105186.exe -gcflags all=-N -l .\main.go # command-line-arguments .\main.go:340:13: undefined: dumpTypes .\main.go:344:14: undefined: dumpSourceFiles .\main.go:348:14: undefined: dumpDecls .\main.go:357:13: undefined: dumpTypes .\main.go:365:13: undefined: dumpIDAScripts .\main.go:380:13: undefined: dumpTypes (exit status 1)
实际函数位于与 program
同一目录下的另一个 program
同一目录下的另一个 .go
文件中。
这两个文件都在其顶部指定了 package main
。
在这种情况下,如何为特定的 .go
文件创建调试配置?
解决方法
将 program
文件创建调试配置?
解决方法${fileDirname}
是 当前打开文件的文件夹路径。默认 Launch Package
模板使用 ${fileDirname}
而不是 ${file}
(由 Launch file
program
属性指定为目录:
{ "version": "0.2.0", "configurations": [ { "name": "Launch Package", "type": "go", "request": "launch", "mode": "auto", "program": "${workspaceFolder}/cmd/sym_dump" } ] }模板使用)是有原因的。
dlv debug
让我们看看文档package
的信息并不多。让我们转向 go run
首先对 :
的 program
属性指定为 ${workspaceFolder}/cmd/sym_dump/main.go
,则表示该包包含单个文件 (main.go
)。但事实是该包包含另一个定义 dumpTypes
、dumpSourceFiles
doc
如果我们将 program
属性指定为 ${workspaceFolder}/cmd/sym_dump/main.go
,则表示该包包含单个文件 ()。但事实是该包包含另一个定义 dumpTypes
、dumpSourceFiles
等的文件。这就是它无法构建程序的原因。cwd
以上是如何在 VSCode 中为特定 .go 文件创建调试配置?的详细内容。更多信息请关注PHP中文网其他相关文章!

goisidealforbuildingscalablesystemsduetoitssimplicity,效率和建筑物内currencysupport.1)go'scleansyntaxandaxandaxandaxandMinimalisticDesignenhanceProductivityAndRedCoductivityAndRedCuceErr.2)ItSgoroutinesAndInesAndInesAndInesAndineSandChannelsEnablenableNablenableNableNablenableFifficConcurrentscorncurrentprogragrammentworking torkermenticmminging

Initfunctionsingorunautomationbeforemain()andareusefulforsettingupenvorments和InitializingVariables.usethemforsimpletasks,避免使用辅助效果,andbecautiouswithTestingTestingTestingAndLoggingTomaintAnainCodeCodeCodeClarityAndTestesto。

goinitializespackagesintheordertheordertheyimported,thenexecutesInitFunctionswithinApcageIntheirdeFinityOrder,andfilenamesdetermineTheOrderAcractacractacrosmultiplefiles.thisprocessCanbeCanbeinepessCanbeInfleccessByendercrededBydeccredByDependenciesbetenciesbetencemendencenciesbetnependendpackages,whermayleLeadtocomplexinitialitialializizesizization

CustomInterfacesingoarecrucialforwritingFlexible,可维护,andTestableCode.TheyEnableDevelostOverostOcusonBehaviorBeiroveration,增强ModularityAndRobustness.byDefiningMethodSigntulSignatulSigntulSignTypaterSignTyperesthattypesmustemmustemmustemmustemplement,InterfaceSallowForCodeRepodEreusaperia

使用接口进行模拟和测试的原因是:接口允许定义合同而不指定实现方式,使得测试更加隔离和易于维护。1)接口的隐式实现使创建模拟对象变得简单,这些对象在测试中可以替代真实实现。2)使用接口可以轻松地在单元测试中替换服务的真实实现,降低测试复杂性和时间。3)接口提供的灵活性使得可以为不同测试用例更改模拟行为。4)接口有助于从一开始就设计可测试的代码,提高代码的模块化和可维护性。

在Go中,init函数用于包初始化。1)init函数在包初始化时自动调用,适用于初始化全局变量、设置连接和加载配置文件。2)可以有多个init函数,按文件顺序执行。3)使用时需考虑执行顺序、测试难度和性能影响。4)建议减少副作用、使用依赖注入和延迟初始化以优化init函数的使用。

go'SselectStatementTreamLinesConcurrentProgrambyMultiplexingOperations.1)itallowSwaitingOnMultipleChannEloperations,执行thefirstreadyone.2)theDefirstreadyone.2)thedefefcasepreventlocksbysbysbysbysbysbythoplocktrograpraproxrograpraprocrecrecectefnoopeready.3)

contextancandwaitgroupsarecrucialingoformanaginggoroutineseflect.1)context contextsallowsAllowsAllowsAllowsAllowsAllingCancellationAndDeadLinesAcrossapibiboundaries,确保GoroutinesCanbestoppedGrace.2)WaitGroupsSynChronizeGoroutines,确保Allimizegoroutines,确保AllizeNizeGoROutines,确保AllimizeGoroutines


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

Dreamweaver Mac版
视觉化网页开发工具

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

Dreamweaver CS6
视觉化网页开发工具