Skip to content

Commit

Permalink
Merge branch 'goplus:goplus' into goplus
Browse files Browse the repository at this point in the history
  • Loading branch information
LiusCraft authored Jan 11, 2024
2 parents de78929 + 0289735 commit c9165b6
Show file tree
Hide file tree
Showing 15 changed files with 137 additions and 38 deletions.
19 changes: 19 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: github-actions
directory: /
labels:
- dependabot
- actions
schedule:
interval: daily

- package-ecosystem: "gomod" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "daily"
25 changes: 25 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Go

on:
push:
branches: [ goplus ]
pull_request:
branches: [ goplus ]

jobs:
Test:
strategy:
matrix:
go-version: [1.18.x, 1.21.x]
os: [ubuntu-latest, windows-latest, macos-11]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- name: Build
run: go build -v ./...
21 changes: 13 additions & 8 deletions Documentation/cli/expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ Delve can evaluate a subset of go expression language, specifically the followin
- Calls to builtin functions: `cap`, `len`, `complex`, `imag` and `real`
- Type assertion on interface variables (i.e. `somevar.(concretetype)`)

# Special Variables

Delve defines two special variables:

* `runtime.curg` evaluates to the 'g' struct for the current goroutine, in particular `runtime.curg.goid` is the goroutine id of the current goroutine.
* `runtime.frameoff` is the offset of the frame's base address from the bottom of the stack.

# Nesting limit

When delve evaluates a memory address it will automatically return the value of nested struct members, array and slice items and dereference pointers.
Expand Down Expand Up @@ -118,8 +111,20 @@ Packages with the same name can be disambiguated by using the full package path.

Char pointers are always treated as NUL terminated strings, both indexing and the slice operator can be applied to them. Other C pointers can also be used similarly to Go slices, with indexing and the slice operator. In both of these cases it is up to the user to respect array bounds.

# Special Features

## Special Variables

Delve defines two special variables:

* `runtime.curg` evaluates to the 'g' struct for the current goroutine, in particular `runtime.curg.goid` is the goroutine id of the current goroutine.
* `runtime.frameoff` is the offset of the frame's base address from the bottom of the stack.

## Access to variables from previous frames

Variables from previous frames (i.e. stack frames other than the top of the stack) can be referred using the following notation `runtime.frame(n).name` which is the variable called 'name' on the n-th frame from the top of the stack.

# CPU Registers
## CPU Registers

The name of a CPU register, in all uppercase letters, will resolve to the value of that CPU register in the current frame. For example on AMD64 the expression `RAX` will evaluate to the value of the RAX register.

Expand Down
9 changes: 7 additions & 2 deletions cmd/dlv/cmds/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,11 @@ func dapCmd(cmd *cobra.Command, args []string) {
os.Exit(status)
}

// gopdlv: add `goTool`
func goTool(cmd *cobra.Command) string {
return "gop" // TODO
}

func buildBinary(cmd *cobra.Command, args []string, isTest bool) (string, bool) {
outputFlag := cmd.Flag("output").Value.String()
var debugname string
Expand All @@ -561,9 +566,9 @@ func buildBinary(cmd *cobra.Command, args []string, isTest bool) (string, bool)
}

if isTest {
err = gobuild.GoTestBuild(debugname, args, buildFlags)
err = gobuild.GoTestBuild(goTool(cmd), debugname, args, buildFlags)
} else {
err = gobuild.GoBuild(debugname, args, buildFlags)
err = gobuild.GoBuild(goTool(cmd), debugname, args, buildFlags)
}
if err != nil {
if outputFlag == "" {
Expand Down
2 changes: 1 addition & 1 deletion cmd/dlv/dlv_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main_test
package dlv_test // gopdlv: change application name

import (
"bufio"
Expand Down
4 changes: 2 additions & 2 deletions cmd/dlv/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package dlv // gopdlv: change application name

import (
"os"
Expand All @@ -11,7 +11,7 @@ import (
// Build is the git sha of this binaries build.
var Build string

func main() {
func Main() {
if Build != "" {
version.DelveVersion.Build = Build
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/dlv/tools.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package dlv // gopdlv: change application name

// List packages used by _scripts

Expand Down
9 changes: 9 additions & 0 deletions cmd/gopdlv/gopdlv.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

import (
"github.com/go-delve/delve/cmd/dlv"
)

func main() {
dlv.Main()
}
39 changes: 24 additions & 15 deletions pkg/gobuild/gobuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,40 @@ func Remove(path string) {

// GoBuild builds non-test files in 'pkgs' with the specified 'buildflags'
// and writes the output at 'debugname'.
func GoBuild(debugname string, pkgs []string, buildflags string) error {
// gopdlv: add `goTool` param
func GoBuild(goTool, debugname string, pkgs []string, buildflags string) error {
args := goBuildArgs(debugname, pkgs, buildflags, false)
return gocommandRun("build", args...)
return gocommandRun(goTool, "build", args...)
}

// GoBuildCombinedOutput builds non-test files in 'pkgs' with the specified 'buildflags'
// and writes the output at 'debugname'.
func GoBuildCombinedOutput(debugname string, pkgs []string, buildflags interface{}) (string, []byte, error) {
// gopdlv: add `goTool` param
func GoBuildCombinedOutput(goTool, debugname string, pkgs []string, buildflags interface{}) (string, []byte, error) {
args, err := goBuildArgs2(debugname, pkgs, buildflags, false)
if err != nil {
return "", nil, err
}
return gocommandCombinedOutput("build", args...)
return gocommandCombinedOutput(goTool, "build", args...)
}

// GoTestBuild builds test files 'pkgs' with the specified 'buildflags'
// and writes the output at 'debugname'.
func GoTestBuild(debugname string, pkgs []string, buildflags string) error {
// gopdlv: add `goTool` param
func GoTestBuild(goTool, debugname string, pkgs []string, buildflags string) error {
args := goBuildArgs(debugname, pkgs, buildflags, true)
return gocommandRun("test", args...)
return gocommandRun(goTool, "test", args...)
}

// GoTestBuildCombinedOutput builds test files 'pkgs' with the specified 'buildflags'
// and writes the output at 'debugname'.
func GoTestBuildCombinedOutput(debugname string, pkgs []string, buildflags interface{}) (string, []byte, error) {
// gopdlv: add `goTool` param
func GoTestBuildCombinedOutput(goTool, debugname string, pkgs []string, buildflags interface{}) (string, []byte, error) {
args, err := goBuildArgs2(debugname, pkgs, buildflags, true)
if err != nil {
return "", nil, err
}
return gocommandCombinedOutput("test", args...)
return gocommandCombinedOutput(goTool, "test", args...)
}

func goBuildArgs(debugname string, pkgs []string, buildflags string, isTest bool) []string {
Expand Down Expand Up @@ -111,22 +115,27 @@ func goBuildArgs2(debugname string, pkgs []string, buildflags interface{}, isTes
return append(args, pkgs...), nil
}

func gocommandRun(command string, args ...string) error {
_, goBuild := gocommandExecCmd(command, args...)
// gopdlv: add `goTool` param
func gocommandRun(goTool, command string, args ...string) error {
_, goBuild := gocommandExecCmd(goTool, command, args...)
goBuild.Stderr = os.Stdout
goBuild.Stdout = os.Stderr
return goBuild.Run()
}

func gocommandCombinedOutput(command string, args ...string) (string, []byte, error) {
buildCmd, goBuild := gocommandExecCmd(command, args...)
// gopdlv: add `goTool` param
func gocommandCombinedOutput(goTool, command string, args ...string) (string, []byte, error) {
buildCmd, goBuild := gocommandExecCmd(goTool, command, args...)
out, err := goBuild.CombinedOutput()
return buildCmd, out, err
}

func gocommandExecCmd(command string, args ...string) (string, *exec.Cmd) {
func gocommandExecCmd(goTool, command string, args ...string) (string, *exec.Cmd) {
allargs := []string{command}
allargs = append(allargs, args...)
goBuild := exec.Command("gop", allargs...)
return strings.Join(append([]string{"gop"}, allargs...), " "), goBuild
// gopdlv: add `goTool` param
// goBuild := exec.Command("go", allargs...)
// return strings.Join(append([]string{"go"}, allargs...), " "), goBuild
goBuild := exec.Command(goTool, allargs...)
return strings.Join(append([]string{goTool}, allargs...), " "), goBuild
}
4 changes: 2 additions & 2 deletions service/dap/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -989,9 +989,9 @@ func (s *Session) onLaunchRequest(request *dap.LaunchRequest) {

switch args.Mode {
case "debug":
cmd, out, err = gobuild.GoBuildCombinedOutput(args.Output, []string{args.Program}, args.BuildFlags.value)
cmd, out, err = gobuild.GoBuildCombinedOutput(args.goTool(), args.Output, []string{args.Program}, args.BuildFlags.value)
case "test":
cmd, out, err = gobuild.GoTestBuildCombinedOutput(args.Output, []string{args.Program}, args.BuildFlags.value)
cmd, out, err = gobuild.GoTestBuildCombinedOutput(args.goTool(), args.Output, []string{args.Program}, args.BuildFlags.value)
}
args.DlvCwd, _ = filepath.Abs(args.DlvCwd)
s.config.log.Debugf("building from %q: [%s]", args.DlvCwd, cmd)
Expand Down
11 changes: 11 additions & 0 deletions service/dap/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ type LaunchConfig struct {
// Default is "debug".
Mode string `json:"mode,omitempty"`

// goxdlv: add `goTool`
// Tool is the command to build/test packages. Default is `gop` (not `go`).
Tool string `json:"tool,omitempty"`

// Path to the program folder (or any go file within that folder)
// when in `debug` or `test` mode, and to the pre-built binary file
// to debug in `exec` mode.
Expand Down Expand Up @@ -160,6 +164,13 @@ type LaunchConfig struct {
LaunchAttachCommonConfig
}

func (p *LaunchConfig) goTool() string {
if p.Tool == "" {
return "gop"
}
return p.Tool
}

// LaunchAttachCommonConfig is the attributes common in both launch/attach requests.
type LaunchAttachCommonConfig struct {
// Automatically stop program after launch or attach.
Expand Down
15 changes: 13 additions & 2 deletions service/debugger/debugger.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ type Config struct {
// TTY for that process.
TTY string

// goxdlv: add `goTool`
// Tool is the command to build/test packages. Default is `gop` (not `go`).
Tool string

// Packages contains the packages that we are debugging.
Packages []string

Expand All @@ -160,6 +164,13 @@ type Config struct {
RrOnProcessPid int
}

func (p *Config) goTool() string {
if p.Tool == "" {
return "gop"
}
return p.Tool
}

// New creates a new Debugger. ProcessArgs specify the commandline arguments for the
// new process.
func New(config *Config, processArgs []string) (*Debugger, error) {
Expand Down Expand Up @@ -515,12 +526,12 @@ func (d *Debugger) Restart(rerecord bool, pos string, resetArgs bool, newArgs []
if rebuild {
switch d.config.ExecuteKind {
case ExecutingGeneratedFile:
err = gobuild.GoBuild(d.processArgs[0], d.config.Packages, d.config.BuildFlags)
err = gobuild.GoBuild(d.config.goTool(), d.processArgs[0], d.config.Packages, d.config.BuildFlags)
if err != nil {
return nil, fmt.Errorf("could not rebuild process: %s", err)
}
case ExecutingGeneratedTest:
err = gobuild.GoTestBuild(d.processArgs[0], d.config.Packages, d.config.BuildFlags)
err = gobuild.GoTestBuild(d.config.goTool(), d.processArgs[0], d.config.Packages, d.config.BuildFlags)
if err != nil {
return nil, fmt.Errorf("could not rebuild process: %s", err)
}
Expand Down
10 changes: 7 additions & 3 deletions service/debugger/debugger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ import (
"github.com/go-delve/delve/service/api"
)

const (
goTool = "go" // gopdlv: add `goTool`
)

func TestDebugger_LaunchNoMain(t *testing.T) {
fixturesDir := protest.FindFixturesDir()
nomaindir := filepath.Join(fixturesDir, "nomaindir")
debugname := "debug"
exepath := filepath.Join(nomaindir, debugname)
defer os.Remove(exepath)
if err := gobuild.GoBuild(debugname, []string{nomaindir}, fmt.Sprintf("-o %s", exepath)); err != nil {
if err := gobuild.GoBuild(goTool, debugname, []string{nomaindir}, fmt.Sprintf("-o %s", exepath)); err != nil {
t.Fatalf("go build error %v", err)
}

Expand Down Expand Up @@ -51,7 +55,7 @@ func TestDebugger_LaunchInvalidFormat(t *testing.T) {
}
t.Setenv("GOOS", switchOS[runtime.GOOS])
exepath := filepath.Join(buildtestdir, debugname)
if err := gobuild.GoBuild(debugname, []string{buildtestdir}, fmt.Sprintf("-o %s", exepath)); err != nil {
if err := gobuild.GoBuild(goTool, debugname, []string{buildtestdir}, fmt.Sprintf("-o %s", exepath)); err != nil {
t.Fatalf("go build error %v", err)
}
defer os.Remove(exepath)
Expand Down Expand Up @@ -81,7 +85,7 @@ func TestDebugger_LaunchCurrentDir(t *testing.T) {
t.Fatalf("error removing executable %v", err)
}
}()
if err := gobuild.GoBuild(debugname, []string{testDir}, fmt.Sprintf("-o %s", exepath)); err != nil {
if err := gobuild.GoBuild(goTool, debugname, []string{testDir}, fmt.Sprintf("-o %s", exepath)); err != nil {
t.Fatalf("go build error %v", err)
}

Expand Down
4 changes: 2 additions & 2 deletions service/debugger/debugger_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestDebugger_LaunchNoExecutablePerm(t *testing.T) {
t.Setenv("GOOS", switchOS[runtime.GOOS])
exepath := filepath.Join(buildtestdir, debugname)
defer os.Remove(exepath)
if err := gobuild.GoBuild(debugname, []string{buildtestdir}, fmt.Sprintf("-o %s", exepath)); err != nil {
if err := gobuild.GoBuild(goTool, debugname, []string{buildtestdir}, fmt.Sprintf("-o %s", exepath)); err != nil {
t.Fatalf("go build error %v", err)
}
if err := os.Chmod(exepath, 0644); err != nil {
Expand Down Expand Up @@ -74,7 +74,7 @@ func TestDebugger_LaunchWithTTY(t *testing.T) {
buildtestdir := filepath.Join(fixturesDir, "buildtest")
debugname := "debugtty"
exepath := filepath.Join(buildtestdir, debugname)
if err := gobuild.GoBuild(debugname, []string{buildtestdir}, fmt.Sprintf("-o %s", exepath)); err != nil {
if err := gobuild.GoBuild(goTool, debugname, []string{buildtestdir}, fmt.Sprintf("-o %s", exepath)); err != nil {
t.Fatalf("go build error %v", err)
}
defer os.Remove(exepath)
Expand Down
1 change: 1 addition & 0 deletions vendor/golang.org/x/tools/go/packages/golist.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c9165b6

Please sign in to comment.