From 07bcf0cb130d348320078dc7e6bb2b7c8b9e8392 Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Wed, 22 Dec 2021 18:38:39 +0100 Subject: [PATCH] Documentation: document runtime.curg and runtime.frameoff (#2835) --- Documentation/cli/README.md | 13 ++++++++++--- Documentation/cli/expr.md | 8 ++++++++ pkg/terminal/command.go | 15 +++++++++++---- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Documentation/cli/README.md b/Documentation/cli/README.md index b84643cc..53f6c84a 100644 --- a/Documentation/cli/README.md +++ b/Documentation/cli/README.md @@ -182,6 +182,8 @@ Set breakpoint condition. Specifies that the breakpoint, tracepoint or watchpoint should break only if the boolean expression is true. +See Documentation/cli/expr.md for a description of supported expressions. + With the -hitcount option a condition on the breakpoint hit count can be set, the following operators are supported condition -hitcount bp > n @@ -194,6 +196,11 @@ With the -hitcount option a condition on the breakpoint hit count can be set, th The '% n' form means we should stop at the breakpoint when the hitcount is a multiple of n. +Examples: + cond 2 i == 10 breakpoint 2 will stop when variable i equals 10 + cond name runtime.curg.goid == 5 breakpoint 'name' will stop only on goroutine 5 + + Aliases: cond ## config @@ -489,7 +496,7 @@ Evaluate an expression. [goroutine ] [frame ] print [%format] -See [Documentation/cli/expr.md](//github.com/go-delve/delve/tree/master/Documentation/cli/expr.md) for a description of supported expressions. +See Documentation/cli/expr.md for a description of supported expressions. The optional format argument is a format specifier, like the ones used by the fmt package. For example "print %x v" will print v as an hexadecimal number. @@ -504,7 +511,7 @@ Print contents of CPU registers. regs [-a] -Argument -a shows more registers. Individual registers can also be displayed by 'print' and 'display'. See [Documentation/cli/expr.md.](//github.com/go-delve/delve/tree/master/Documentation/cli/expr.md.) +Argument -a shows more registers. Individual registers can also be displayed by 'print' and 'display'. See Documentation/cli/expr.md. ## restart @@ -547,7 +554,7 @@ Changes the value of a variable. [goroutine ] [frame ] set = -See [Documentation/cli/expr.md](//github.com/go-delve/delve/tree/master/Documentation/cli/expr.md) for a description of supported expressions. Only numerical variables and pointers can be changed. +See Documentation/cli/expr.md for a description of supported expressions. Only numerical variables and pointers can be changed. ## source diff --git a/Documentation/cli/expr.md b/Documentation/cli/expr.md index 89d94590..3cb67d7a 100644 --- a/Documentation/cli/expr.md +++ b/Documentation/cli/expr.md @@ -14,6 +14,13 @@ 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. @@ -129,3 +136,4 @@ Because many architectures have SIMD registers that can be used by the applicati * `REGNAME.floatN` returns the register REGNAME as an array fo floatN elements. In all cases N must be a power of 2. + diff --git a/pkg/terminal/command.go b/pkg/terminal/command.go index 272f6071..5e37271a 100644 --- a/pkg/terminal/command.go +++ b/pkg/terminal/command.go @@ -300,7 +300,7 @@ Specifying -a prints all physical breakpoint, including internal breakpoints.`}, [goroutine ] [frame ] print [%format] -See $GOPATH/src/github.com/go-delve/delve/Documentation/cli/expr.md for a description of supported expressions. +See Documentation/cli/expr.md for a description of supported expressions. The optional format argument is a format specifier, like the ones used by the fmt package. For example "print %x v" will print v as an hexadecimal number.`}, {aliases: []string{"whatis"}, group: dataCmds, cmdFn: whatisCommand, helpMsg: `Prints type of an expression. @@ -310,7 +310,7 @@ The optional format argument is a format specifier, like the ones used by the fm [goroutine ] [frame ] set = -See $GOPATH/src/github.com/go-delve/delve/Documentation/cli/expr.md for a description of supported expressions. Only numerical variables and pointers can be changed.`}, +See Documentation/cli/expr.md for a description of supported expressions. Only numerical variables and pointers can be changed.`}, {aliases: []string{"sources"}, cmdFn: sources, helpMsg: `Print list of source files. sources [] @@ -347,7 +347,7 @@ If regex is specified only package variables with a name matching it will be ret regs [-a] -Argument -a shows more registers. Individual registers can also be displayed by 'print' and 'display'. See $GOPATH/src/github.com/go-delve/delve/Documentation/cli/expr.md.`}, +Argument -a shows more registers. Individual registers can also be displayed by 'print' and 'display'. See Documentation/cli/expr.md.`}, {aliases: []string{"exit", "quit", "q"}, cmdFn: exitCommand, helpMsg: `Exit the debugger. exit [-c] @@ -454,6 +454,8 @@ The command 'on x -edit' can be used to edit the list of commands executed when Specifies that the breakpoint, tracepoint or watchpoint should break only if the boolean expression is true. +See Documentation/cli/expr.md for a description of supported expressions. + With the -hitcount option a condition on the breakpoint hit count can be set, the following operators are supported condition -hitcount bp > n @@ -464,7 +466,12 @@ With the -hitcount option a condition on the breakpoint hit count can be set, th condition -hitcount bp != n condition -hitcount bp % n -The '% n' form means we should stop at the breakpoint when the hitcount is a multiple of n.`}, +The '% n' form means we should stop at the breakpoint when the hitcount is a multiple of n. + +Examples: + cond 2 i == 10 breakpoint 2 will stop when variable i equals 10 + cond name runtime.curg.goid == 5 breakpoint 'name' will stop only on goroutine 5 +`}, {aliases: []string{"config"}, cmdFn: configureCmd, helpMsg: `Changes configuration parameters. config -list