山西网站建设价格/千峰培训多少钱
环境配置
delve仓库,含有教程:https://github.com/go-delve/delve
golang的debugging教程:https://github.com/golang/vscode-go/wiki/debugging
> go version
go version go1.20 windows/amd64> go install github.com/go-delve/delve/cmd/dlv@latest
快捷键
F8 下一步F7 进入函数
Shift+F8 退出函数F9 下一个断点
golang的调试有三种模式
1、Launch package
// Launch package: Debug/test the package of the open file
{"name": "Launch Package","type": "go","request": "launch","mode": "auto","args": ["new", " conda"],"program": "${fileDirname}"
}
从说明上看出这是调试当前打开的文件所在的包,所以当前打开的文件需要是main包,里面有main函数,或者是测试文件,也就是需要可直接运行的文件。类比于我们直接进入该目录执行go run
可以带上运行参数 args
测试程序
ctl/ctl.go
package mainimport ("fmt""voteapi/ctl/cmd"
)func main() {fmt.Println("xxx")cmd.Execute()
}
在fmt.Println("xxx")
打上断点,因为调试器会直接跳到第一个断点的地方,如果一个断点都没有那就直接结束了。
控制台输出
Starting: D:\dev\php\magook\trunk\server\golang\path\bin\dlv.exe dap --listen=127.0.0.1:20155 from D:\dev\php\magook\trunk\server\voteapi\ctl
DAP server listening at: 127.0.0.1:20155
Type 'dlv help' for list of commands.
mode
参数的值
debug
: build and debug a main packagetest
: build and debug a testexec
: debug a precompiled binary- The binary must be built with
go build -gcflags=all="-N -l"
to disable inlining and optimizations that can interfere with debugging.
- The binary must be built with
auto
: automatically choose betweendebug
andtest
depending on the open file
2、Attach to process
// Attach to local process: Attach to an existing process by process ID
{"name": "Attach to Process","type": "go","request": "attach","mode": "local","processId": 0
}
attach: You can use this configuration to attach to a running process or a running debug session.
mode
参数的值
- local: attaches to a local process.
- The binary must be built with
go build -gcflags=all="-N -l"
to disable inlining and optimizations that can interfere with debugging.
- The binary must be built with
remote
: attaches to an in-progress debug session run by an external server.
You can debug an already running program using the local
mode type configuration. The Go extension will start dlv dap
and configure it to attach to the specified process. Users can select the process to debug with one of the following options:
- Specifying the numeric process id (PID) with the
processId
attribute. - Specifying the target program name in the
processId
attribute. If there are multiple processes matching the specified program name, the extension will show the list of matching processes at the start of the debug session. - Specifying
0
in theprocessId
attribute and selecting the process from the drop-down menu at the start of the debug session.
attach 的 local 模式的应用场景是常驻内存的程序,比如 http server,我们编译运行程序后,来到VScode,主要配置 processId 属性,可以是进程ID,可以是进程名称,也可以给0,然后编辑器会弹出下拉框让你选择要attach上的程序。
示例,还是 ctl.go 文件,改一下
package mainimport ("fmt""net/http"
)func main() {http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {fmt.Fprintf(w, "%s", "hello")})http.ListenAndServe(":9999", nil)
}
go build ctl.go
ctl.exe
我们选择Attach to Process
,点击运行调试三角形按钮,在弹出的下拉框输入ctl.exe
,启动调试,同样的要先打几个断点。
此时调试工具栏是这样的
是出于暂停状态的,我们在浏览器请求一下这个服务,它就被激活了,就可以逐步调试了。
一个请求被调试完之后,调试不会结束,而是暂停了,等待下一个请求来触发。
3、Connect to server
说明 https://github.com/golang/vscode-go/wiki/debugging#remote-debugging
这是 vscode 的 Remote debugging 功能,他是基于 Remote Development,即远程开发,远程调试,这还需要安装额外的vscode扩展,将远程代码映射到本地,然后本地代码能时时推送到远程服务器,最终在远程服务器上运行代码。
我是直接在本地来的,发现也可以调试。
package mainimport ("fmt""voteapi/ctl/cmd"
)func main() {fmt.Println("xxx")cmd.Execute()
}
// Connect to server: Connect to a remote headless debug server
{"name": "Connect to server","type": "go","debugAdapter": "dlv-dap","request": "attach","mode": "remote","remotePath": "${workspaceFolder}","port": 2345,"host": "127.0.0.1"
}
dlv debug --headless --listen=:2345
launch.json配置项
文档 https://github.com/golang/vscode-go/wiki/debugging#configuration
// 命令行参数,要自己打空格
"args": ["-config", " server.json"],// 编译参数
"buildFlags": "-tags 'server'",// key:value
"env": {},
相关文章:

vscode使用delve调试golang程序
环境配置 delve仓库,含有教程:https://github.com/go-delve/delve golang的debugging教程:https://github.com/golang/vscode-go/wiki/debugging > go version go version go1.20 windows/amd64> go install github.com/go-delve/de…...

如何从任何苹果、Windows或安卓设备访问iCloud照片
本文介绍了如何在各种设备上访问iCloud照片库,包括iPhone和iPad、Mac、Windows PC和Android设备。说明适用于iOS 13及以上版本、iPadOS 13及以上、macOS Big Sur(10.16)和Catalina(10.15)、Windows 10或11以及Android 10。 从iPhone、iPod Touch和iPad访问iCloud照片 照…...

关于“找不到mfc140u.dll,无法继续执行代码”问题的分析处理方法
我想和大家分享一个在编程过程中经常会遇到的问题——找不到mfc140u.dll,无法继续执行代码。找不到 mfc140u.dll,这个问题可能会让我们感到困扰。mfc140u.dll 是 Microsoft Foundation Classes(MFC)库的一部分,它是一个 Windows 系…...

用 TripletLoss 优化bert ranking
下面是 用 TripletLoss 优化bert ranking 的demo import torch from torch.utils.data import DataLoader, Dataset from transformers import BertModel, BertTokenizer from sklearn.metrics.pairwise import pairwise_distancesclass TripletRankingDataset(Dataset):def __…...

Tomcat安装及使用
这里写目录标题 Tomcat一.java基础1.java历史2.java组成3.实现动态网页功能serveltjsp 4.jdkJDK 和 JRE 关系安装openjdk安装oracle官方JDK 二.tomcat基础功能1.Tomcat介绍2.安装tomcat二进制安装Tomcat 3.配置文件介绍及核心组件配置文件组件 4.状态页5.常见的配置详解6.tomca…...

法国新法案强迫 Firefox 等浏览器审查网站
导读Mozilla 基金会已发起了一份请愿书,旨在阻止法国政府强迫 Mozilla Firefox 等浏览器审查网站。 据悉,法国政府正在制定一项旨在打击网络欺诈的 SREN 法案 (“Projet de loi Visant scuriser et reguler lespace numrique”),包含大约 2…...

开源电商项目 Mall:构建高效电商系统的终极选择
文章目录 Mall 项目概览前台商城系统后台管理系统系统架构图业务架构图 模块介绍后台管理系统 mall-admin商品管理:功能结构图-商品订单管理:功能结构图-订单促销管理:功能结构图-促销内容管理:功能结构图-内容用户管理࿱…...

QT(9.1)对话框与事件处理
作业: 1. 完善登录框 点击登录按钮后,判断账号(admin)和密码(123456)是否一致,如果匹配失败,则弹出错误对话框,文本内容“账号密码不匹配,是否重新登录”&…...

C++项目实战——基于多设计模式下的同步异步日志系统-③-前置知识补充-设计模式
文章目录 专栏导读六大原则单例模式饿汉模式懒汉模式 工厂模式简单工厂模式工厂方法模式抽象工厂模式 建造者模式代理模式 专栏导读 🌸作者简介:花想云 ,在读本科生一枚,C/C领域新星创作者,新星计划导师,阿…...

C++ 新旧版本两种读写锁
一、简介 读写锁(Read-Write Lock)是一种并发控制机制,用于多线程环境中实现对共享资源的高效读写操作。读写锁允许多个线程同时读取共享资源,但在有写操作时,需要互斥地独占对共享资源的访问,以确保数据的…...

ES6 字符串的repeat()方法
repeat() 方法返回一个新字符串,表示将原字符串重复n次 格式:str.repeat(n) 参数n:str需要重复多少次 参数n的取值: n是正整数: x.repeat(3) // 输出结果:"xxx" hello.repeat(2) // 输出结果…...

【车载以太网测试从入门到精通】系列文章目录汇总
【车载以太网测试从入门到精通】——物理层测试 【车载以太网测试从入门到精通】——数据链路层测试 【车载以太网测试从入门到精通】——网络层测试 【车载以太网测试从入门到精通】——传输层测试 【车载以太网测试从入门到精通】——以太网TCP/IP协议自动化测试(…...

LLM推理优化技术综述:KVCache、PageAttention、FlashAttention、MQA、GQA
LLM推理优化技术综述:KVCache、PageAttention、FlashAttention、MQA、GQA 随着大模型被越来越多的应用到不同的领域,随之而来的问题是应用过程中的推理优化问题,针对LLM推理性能优化有一些新的方向,最近一直在学习和研究…...

go开发之个微机器人的二次开发
请求URL: http://域名/addRoomMemberFriend 请求方式: POST 请求头Headers: Content-Type:application/jsonAuthorization:login接口返回 参数: 参数名必选类型说明wId是String登录实例标识chatRoom…...

2023国赛数学建模B题思路代码 - 多波束测线问题
# 1 赛题 B 题 多波束测线问题 单波束测深是利用声波在水中的传播特性来测量水体深度的技术。声波在均匀介质中作匀 速直线传播, 在不同界面上产生反射, 利用这一原理,从测量船换能器垂直向海底发射声波信 号,并记录从声波发射到…...

SpringAOP面向切面编程
文章目录 一. AOP是什么?二. AOP相关概念三. SpringAOP的简单演示四. SpringAOP实现原理 一. AOP是什么? AOP(Aspect Oriented Programming):面向切面编程,它是一种编程思想,是对某一类事情的集…...

A Guide to Java HashMap
原文链接: A Guide to Java HashMap → https://www.baeldung.com/java-hashmap 从Map里取值 # 原生方法 Map<String, Integer> map new HashMap<>();// map自身的方法 → 取不到返回null Integer age6 map.get("name"); // Integer时返回null可…...

LeetCode 449. Serialize and Deserialize BST【树,BFS,DFS,栈】困难
本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章…...

嵌入式IDE(1):IAR中ICF链接文件详解和实例分析
最近在使用NXP的提供的MCUXPresso IDE,除了Eclipse固有的优点外,我觉得它最大的优点就是在链接脚本的生成上,提供了非常直观的GUI配置界面。但这个IDE仅仅支持NXP相关的产品,而且调试的性能在某些情况下并不理想。而我们用得比较多…...

分布式版本控制工具——git
✅<1>主页::我的代码爱吃辣 📃<2>知识讲解:Linux——git ☂️<3>开发环境:Centos7 💬<4>前言:git是一个开源的分布式版本控制系统,可以有效、高速地处理从很…...

C基础-数组
1.一维数组的创建和初始化 int main() {// int arr1[10];int n 0;scanf("%d",&n);//int count 10;int arr2[n]; //局部的变量,这些局部的变量或者数组是存放在栈区的,存放在栈区上的数组,如果不初始化的话,默认…...

springboot项目配置flyway菜鸟级别教程
1、Flyway的工作原理 Flyway在第一次执行时,会创建一个默认名为flyway_schema_history的历史记录表,这张表会用来跟踪或记录数据库的状态,然后每次项目启动时都会自动扫描在resources/db/migration下的文件的版本号并且通过查询flyway_schem…...

成都精灵云初试
最近参加了成都精灵云的笔试与面试,岗位是c工程师。后面自己复盘了过程,初试部分总结如下,希望能对各位相进该公司以及面试C工程师的同学提供一些参考。这也是博主第一次参加面试,很多东西都还没准备,很多答得不好&…...

css relative 和absolute布局
1、relative和absolute内部的元素都是相对于父容器,若父容器没有指定为relative,则默认为整个文档视图空间,absolute可以重叠元素,relative则不行。relative意味着元素的任意属性如left和right都是相对于其他元素的。absolute则相…...

更健康舒适更科技的照明体验!书客SKY护眼台灯SUKER L1上手体验
低价又好用的护眼台灯是多数人的需求,很多人只追求功能性护眼台灯,显色高、无频闪、无蓝光等基础需求。但是在较低价格中很难面面俱到,然而刚发布的SUKER书客L1护眼台灯却是一款不可多得的性价比护眼台灯,拥有高品质光源ÿ…...

经管博士科研基础【19】齐次线性方程组
1. 线性方程组 2. 非线性方程组 非线性方程,就是因变量与自变量之间的关系不是线性的关系,这类方程很多,例如平方关系、对数关系、指数关系、三角函数关系等等。求解此类方程往往很难得到精确解,经常需要求近似解问题。相应的求近似解的方法也逐渐得到大家的重视。 3. 线…...

django报错解决 Forbidden (403) CSRF verification failed. Request aborted.
django报错解决 Forbidden (403) CSRF verification failed. Request aborted. 报错内容 Forbidden (403) CSRF verification failed. Request aborted.Help Reason given for failure:Origin checking failed - https://active-mantis-distinct.ngrok-free.app does not mat…...

k8s-实战——yapi平台部署
文章目录 k8s 部署yapi平台前言准备工作构建yapi镜像Dockerfileentrypoint.shbuild.sh源码下载构建镜像启动mongo数据库新建nfs服务mongo创建mongo服务初始化数据启动yapi服务创建yapi服务查看密码访问地址k8s 部署yapi平台 前言 部署yapi平台需要mo...

Excel VSTO开发5 -Excel对象结构
版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。 5 Excel对象结构 Excel提供了几个比较重要的对象: Application、Workbooks、Workbook、Worksheets、Worksheet 为了便…...

Javafx集成sqlite数据库
什么是SQLite SQLite是一款非常轻量级的关系数据库系统,支持多数SQL92标准。SQLite在使用前不需要安装设置,不需要进程来启动、停止或配置,而其他大多数SQL数据库引擎是作为一个单独的服务器进程,被程序使用某种内部进程通信(典型…...