gitlab.com/Raven-IO/raven-delve@v1.22.4/Documentation/cli/expr.md (about)

     1  # Expressions
     2  
     3  Delve can evaluate a subset of go expression language, specifically the following features are supported:
     4  
     5  - All (binary and unary) on basic types except <-, ++ and --
     6  - Comparison operators on any type
     7  - Type casts between numeric types
     8  - Type casts of integer constants into any pointer type and vice versa
     9  - Type casts between string, []byte and []rune
    10  - Struct member access (i.e. `somevar.memberfield`)
    11  - Slicing and indexing operators on arrays, slices and strings
    12  - Map access
    13  - Pointer dereference
    14  - Calls to builtin functions: `cap`, `len`, `complex`, `imag` and `real`
    15  - Type assertion on interface variables (i.e. `somevar.(concretetype)`)
    16  
    17  # Nesting limit
    18  
    19  When delve evaluates a memory address it will automatically return the value of nested struct members, array and slice items and dereference pointers.
    20  However to limit the size of the output evaluation will be limited to two levels deep. Beyond two levels only the address of the item will be returned, for example:
    21  
    22  ```
    23  (dlv) print c1
    24  main.cstruct {
    25  	pb: *struct main.bstruct {
    26  		a: (*main.astruct)(0xc82000a430),
    27  	},
    28  	sa: []*main.astruct len: 3, cap: 3, [
    29  		*(*main.astruct)(0xc82000a440),
    30  		*(*main.astruct)(0xc82000a450),
    31  		*(*main.astruct)(0xc82000a460),
    32  	],
    33  }
    34  ```
    35  
    36  To see the contents of the first item of the slice `c1.sa` there are two possibilities:
    37  
    38  1. Execute `print c1.sa[0]`
    39  2. Use the address directly, executing: `print *(*main.astruct)(0xc82000a440)`
    40  
    41  # Elements limit
    42  
    43  For arrays, slices, strings and maps delve will only return a maximum of 64 elements at a time:
    44  
    45  ```
    46  (dlv) print ba
    47  []int len: 200, cap: 200, [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,...+136 more]
    48  ```
    49  
    50  To see more values use the slice operator:
    51  
    52  ```
    53  (dlv) print ba[64:]
    54  []int len: 136, cap: 136, [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,...+72 more]
    55  ```
    56  
    57  For this purpose delve allows use of the slice operator on maps, `m[64:]` will return the key/value pairs of map `m` that follow the first 64 key/value pairs (note that delve iterates over maps using a fixed ordering).
    58  
    59  These limits can be configured with `max-string-len` and `max-array-values`. See [config](https://github.com/go-delve/delve/tree/master/Documentation/cli#config) for usage.
    60  
    61  # Interfaces
    62  
    63  Interfaces will be printed using the following syntax:
    64  ```
    65  <interface name>(<concrete type>) <value>
    66  ```
    67  
    68  For example:
    69  
    70  ```
    71  (dlv) p iface1
    72  (dlv) p iface1
    73  interface {}(*struct main.astruct) *{A: 1, B: 2}
    74  (dlv) p iface2
    75  interface {}(*struct string) *"test"
    76  (dlv) p err1
    77  error(*struct main.astruct) *{A: 1, B: 2}
    78  ```
    79  
    80  To use the contents of an interface variable use a type assertion:
    81  
    82  ```
    83  (dlv) p iface1.(*main.astruct).B
    84  2
    85  ```
    86  
    87  Or just use the special `.(data)` type assertion:
    88  
    89  ```
    90  (dlv) p iface1.(data).B
    91  2
    92  ```
    93  
    94  If the contents of the interface variable are a struct or a pointer to struct the fields can also be accessed directly:
    95  
    96  ```
    97  (dlv) p iface1.B
    98  2
    99  ```
   100  
   101  # Specifying package paths
   102  
   103  Packages with the same name can be disambiguated by using the full package path. For example, if the application imports two packages, `some/package` and `some/other/package`, both defining a variable `A`, the two variables can be accessed using this syntax:
   104  
   105  ```
   106  (dlv) p "some/package".A
   107  (dlv) p "some/other/package".A
   108  ```
   109  
   110  # Pointers in Cgo
   111  
   112  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.
   113  
   114  # Special Features
   115  
   116  ## Special Variables
   117  
   118  Delve defines two special variables:
   119  
   120  * `runtime.curg` evaluates to the 'g' struct for the current goroutine, in particular `runtime.curg.goid` is the goroutine id of the current goroutine.
   121  * `runtime.frameoff` is the offset of the frame's base address from the bottom of the stack.
   122  
   123  ## Access to variables from previous frames
   124  
   125  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.
   126  
   127  ## CPU Registers
   128  
   129  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. 
   130  
   131  Register names are shadowed by both local and global variables, so if a local variable called "RAX" exists, the `RAX` expression will evaluate to it instead of the CPU register.
   132  
   133  Register names can optionally be prefixed by any number of underscore characters, so `RAX`, `_RAX`, `__RAX`, etc... can all be used to refer to the same RAX register and, in absence of shadowing from other variables, will all evaluate to the same value.
   134  
   135  Registers of 64bits or less are returned as uint64 variables. Larger registers are returned as strings of hexadecimal digits.
   136  
   137  Because many architectures have SIMD registers that can be used by the application in different ways the following syntax is also available:
   138  
   139  * `REGNAME.intN` returns the register REGNAME as an array of intN elements.
   140  * `REGNAME.uintN` returns the register REGNAME as an array of uintN elements.
   141  * `REGNAME.floatN` returns the register REGNAME as an array of floatN elements.
   142  
   143  In all cases N must be a power of 2.
   144