Debug golang program in vscode

Basic config install delve use debug config template in vscode Debug with stdin input The default delve debug mod doesn’t support stdin input. To tackle this issue, use the method of launching a delve debug server and attach program to debug server instead. tasks.json { "tasks": [ { "label": "Delve debug server", "type": "shell", "command": "cd \"${fileDirname}\" && source /etc/profile && ~/go/bin/dlv debug --headless --listen=:2346 --api-version=2", "problemMatcher": [], "group": { "kind": "build", "isDefault": false } } ], "version": "2....

May 1, 2022 · 1 min · Andyliu

Linux环境下使用vscode进行c/c++语言debug

VScode中debug运行逻辑概述 工作区 VScode由两种运行模式:单文件打开模式和文件夹打开模式。界面上最明显的区分是VScode底部的颜色条如果是紫色的,说明在单文件打开模式,如果为天蓝色,即处于文件夹打开模式。 在文件夹打开模式下,左侧文件浏览器界面可以看到当前文件夹路径下的所有文件以及文件夹。这个所谓的“当前文件夹路径”在VScode中被称为“工作区路径”。如果不清楚当前的工作区路径,在VScode中新建——注意不是显示之前隐藏的终端——一个终端后所处在的路径就是当前的工作区路径,由VScode自动帮你切换好了。可以在打开后不更改路径的情况下使用pwd命令打印当前的绝对路径。 Debug相关配置文件 以${workspaceFolder}表示当前工作区文件夹,则与这个工作区相关的所有VScode的配置文件都放在${workspaceFolder}/.vscode文件夹下,若要进行c语言程序的debug,需要用到两个文件: launch.json 这个文件里面记录的是与debug直接相关的配置,包括debug任务名称、debug程序(c语言对应gdb)、相关参数等等。对于python这种不需要编译的解释性语言,仅用这个文件就够了。但是c语言是编译型语言,在调用gdbdebug之前还需要调用gcc进行编译,对应到launch.json里面就要配置一个参数"preLaunchTask",里面调用接下来要说的tasks.json文件里的配置进行编译。 tasks.json 这个文件就是一些常用任务的配置,写成配置文件后就可以一键运行,而不用每次都敲繁琐的命令行了。在debug的相关配置中常用来填写编译(build)任务的相关配置,里面可以指定使用的编译器、使用的语言版本、编译参数等等。 debug相关设置以及快捷键 F5在debug启动前为“启动debug”命令,在debug启动后为“继续”命令(继续运行直到遇到下一个断点暂停) F9在光标所在的行设置断点 F10下一步,遇到函数不会进入 F11下一个语句,遇到函数会进入函数 shift + F11单步跳出,即执行完当前函数并返回后暂停程序 shift + F5停止debug 或者在遇到断点后点击debug工具栏里的按钮也可以 有可能启动debug之后弹出的终端界面在debug console中,而非terminal中,此时进行的输入不会被引导到stdin中,而是会交给调试器。点击下图中红框圈起来的terminal(中文翻译应该是“终端”)即可回到正常的终端,此时进行的输入将直接进入stdin交给程序。 更多进阶玩法参见微软官方文档 一次C语言Debug的流程(配合下文给出的配置) 在左侧的debug面板中选择debug任务名称(由于下文给出的配置中实际上只含有1个配置,会被默认选中,这步可以被跳过。但是如果有多个debug配置则需要先选中一个。) 打开含有main函数的c语言源文件,待会编译的时候默认当前打开的文件中含有main函数 摁下F5键,启动一个debug流程 vscode按照选择的任务名称读取${workspaceFolder}/.vscode/launch.json文件,发现里面有参数"preLaunchTask" 于是vscode调用${workspaceFolder}/.vscode/tasks.json文件中指定的编译任务,调用gcc完成c程序的编译 完成编译后,vscode继续按照${workspaceFolder}/.vscode/launch.json文件中定义的debug配置调用gdb启动debug过程 程序遇到断点后暂停,此时可以在左侧debug面板中查看变量、调用栈等等信息 按下弹出的debug工具栏最右侧的红色方块停止debug 配置文件 windows和linux下的配置文件有所不同,请根据运行环境选择。在写入配置文件前请确认在终端中可以正常使用gcc和gdb命令。 Linux tasks.json { "tasks": [ { "type": "cppbuild", "label": "C/C++: gcc build active file", "command": "/usr/bin/gcc", "args": [ "-fdiagnostics-color=always", "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}", "-lpthread" ], "options": { "cwd": "${fileDirname}" }, "problemMatcher": ["$gcc"], "group": "build", "detail": "compiler: /usr/bin/gcc" } ], "version": "2....

April 30, 2022 · 2 min · Andyliu

Verilog with vscode

linting using vscode extension Verilog-HDL/SystemVerilog/Bluespec SystemVerilog. using iverilog go to extension settings and set verilog > linting : linter = iverilog then the linting function should work for verilog files. Notice: the dir to verilog file should not contain chinese characters and spaces. if you imported module from other file without include command, iverilog willl report an error. As it is always the case when using vivado, add -i to extention setting Verilog › Linting › Iverilog: Arguments to ignore this error....

November 24, 2021 · 1 min · Andyliu