Golang language learning day 2_GoLand Debug

Past review:

Golang language learning day 1_Installation environment configuration and development tools

1. Local debugging

1、Go Demo

package main

import (
	"flag"
	"fmt"
)

// 声明输入参数hxpInputParam 默认值为0 用途描述
var hxpInputParam = flag.Int("hxpInputParam", 0, "Input parameter for 珩小派")

func main() {
	fmt.Println("珩小派-本地调试,配置演示开始")
	//解析命令行参数并设置相应的标志变量
	flag.Parse()
	var x = 5
	fmt.Println("The value of x is:", x)
	// 两数相加
	sum := *hxpInputParam + x
	fmt.Println("The sum of add x and hxpInputParam is:", sum)
	fmt.Println("珩小派-本地调试  End!")
}

2、GoLand Run/Debug Configurations

config-step1 config-step2 config-step3 config-step4 Final output

珩小派-本地调试,配置演示开始
The value of x is: 5
The sum of add x and hxpInputParam is: 55
珩小派-本地调试  End!      

2. Attach to process

1、Go Demo

package main

import (
	"flag"
	"fmt"
	"time"
)

var hxpInputParam1 = flag.Int("hxpInputParam1", 0, "Input parameter for 珩小派")

func main() {
	flag.Parse()
	var i = 0
	for {
		fmt.Println("print", i, *hxpInputParam1)
		i++
		time.Sleep(time.Second)
	}
}

2. Install gops plug-in

Execute the following command

go install github.com/google/gops@latest Plug-in installed successfully

gops-plugin GoLand-Run-Attach to Process

GoLand-Run-Attach to Process find process

Attach to Process Attachment to process ERROR

Although Debug has been run, Debug information cannot be obtained.

could not attach to pid 2684: decoding dwarf section info at offset 0x0: too sho
rt - debuggee must not be built with 'go run' or -ldflags='-s -w', which strip d
ebug info

ERROR

3. Compile and run the executable file

Compile and generate executable files

go build -gcflags="all=-N -l" -o StudyDebugProcess.exe compile

Run executable file

step1 step2

This article is a reprint of the article Heng Xiaopai , and the copyright belongs to the original author. It is recommended to visit the original text. To reprint this article, please contact the original author.

Linus took matters into his own hands to prevent kernel developers from replacing tabs with spaces. His father is one of the few leaders who can write code, his second son is the director of the open source technology department, and his youngest son is a core contributor to open source. Huawei: It took 1 year to convert 5,000 commonly used mobile applications Comprehensive migration to Hongmeng Java is the language most prone to third-party vulnerabilities. Wang Chenglu, the father of Hongmeng: open source Hongmeng is the only architectural innovation in the field of basic software in China. Ma Huateng and Zhou Hongyi shake hands to "remove grudges." Former Microsoft developer: Windows 11 performance is "ridiculously bad " " Although what Laoxiangji is open source is not the code, the reasons behind it are very heartwarming. Meta Llama 3 is officially released. Google announces a large-scale restructuring
{{o.name}}
{{m.name}}

Guess you like

Origin my.oschina.net/u/6851747/blog/11045658