Commit Graph

43 Commits

Author SHA1 Message Date
Alessandro Arzilli
477e46ebbd
pkg/proc: support swiss table map implementation (#3838)
Adds support for the swiss table implementation for Go's maps.
2024-12-04 19:14:47 -08:00
Alessandro Arzilli
025d47c6e9
proc: adds pointer pinning to call injection (#3787)
This commit adds a new mode to call injection. If the runtime.debugPinner
function is available in the target executable it obtains a pinner by
calling it and then uses it to pin the pointers in the results of call
injection.

This allows the code for call injection to be refactored to execute the
calls in the normal order, since it doesn't need to be concerned with having
space on the target's memory to store intermediate values.

Updates #3310
2024-10-04 10:44:57 -07:00
Alessandro Arzilli
582305a813
proc: for optimized functions allow .closureptr to not exist (#3808)
* proc: flag variables correctly when range-over-func stmts are used

Argument variables of a range-over-func body closure should be returned
flagged as normal local variables, not as function arguments.

Updates #3806

* proc: for optimized functions allow .closureptr to not exist

For optimized functions .closureptr is sometimes omitted from DWARF,
allow it to be 0 and try to recover the range-over-func stack by best
effort.

Fixes #3806
2024-09-18 14:16:34 -07:00
Alessandro Arzilli
a63cc8a1a3
proc: fix result type of division of untyped constants (#3794)
The Go specification says that the result of division of untyped
constants should be an untyped integer constant if both constants are
untyped integers, the go/constant package however does something
different by always producing an untyped floating constant.

Fixes #3793
2024-09-05 09:23:21 +02:00
Jille Timmermans
a164b89df1
eval: Allow reslicing a slice up to its cap, rather than its length (#3796)
fix a couple of places where we needed to track the cap
2024-08-28 11:41:23 -07:00
Alessandro Arzilli
64f3d34663
proc: move stepping test to their own file (#3784)
Move all tests of the functionality of proc.next,
proc.(*TargetGroup).Next, proc.(*TargetGroup).Step,
proc.(*TargetGroup).StepOut to their own test file.
2024-07-19 21:29:56 -07:00
Oleksandr Redko
0d0d2e1b16
*: replace fmt.Errorf with errors.New (#3752) 2024-06-20 21:50:18 +02:00
Alessandro Arzilli
4b628b81cb
proc: refactor identifier evaluation for range-over-func support (#3738)
Because of how range-over-func is implemented it is difficult to
determine the set of visible local variables during expression
compilation (i.e. it is difficulto to keep the HasLocal function
correct).
This commit moves that logic from expression compilation to expression
evaluation.

Updates #3733
2024-06-14 14:36:11 -07:00
Oleksandr Redko
8347f97c00
*: remove redundant lines at the start/end of block (#3730) 2024-05-20 14:16:22 -07:00
Alessandro Arzilli
6cd0b70b30
proc: if a reslice operator is used load the whole slice (#3623)
When the users uses a reslice operation load the whole resliced
variable, ignoring the MaxArrayValues setting.
Only apply this when the 'high' part is specified and a literal and the
'low' part is either unspecified or a literal.

Fixes #3600
2024-01-24 09:21:59 -08:00
Alessandro Arzilli
ba403e365d
proc: fix TestPackageRenames on go1.22 on linux/386 (#3610) 2023-12-26 10:17:25 -08:00
Alessandro Arzilli
57dad9342a
proc: make some type casts less counterintuitive
* proc: make some type casts less counterintuitive

The interaction of type casts with load configuration is sometimes
counterintuitive. This commit changes the way it is performed so that
when converting slices to strings and vice versa the maximum size
corresponding to the target type is used (i.e. MaxStringLen when
converting slices to strings and MaxArrayValues when converting slices
to strings).

This doesn't fully solve the problem (conversions to []rune are
problematic and multiple chained type casts will still be confusing)
but removes the problem for the majority of practical uses.

Fixes #3595, #3539
2023-12-12 11:43:41 -08:00
Alessandro Arzilli
e06a1163d0
proc: add regression test for issue #3548 (#3553)
Issue #3548 describes a bug in the compiler which was fixed by commit
505e50b. But this case wasn't covered by our current tests (obviously)
and the fix in the compiler looks accidental so it's worth adding a
test for it.

Fixes #3548
2023-11-04 10:31:03 -05:00
Alessandro Arzilli
909add7894
proc: add min and max builtins (#3530)
Go 1.21 added two new builtins: min and max. Add them to the expression
evaluator.
2023-10-19 11:05:36 -07:00
Alessandro Arzilli
2c700230de
proc: use stack machine to evaluate expressions (#3508)
* proc: use stack machine to evaluate expressions

This commit splits expression evaluation into two parts. The first part (in
pkg/proc/evalop/evalcompile.go) "compiles" as ast.Expr into a list of
instructions (defined in pkg/proc/evalop/ops.go) for a stack machine
(defined by `proc.(*evalStack)`).
The second part is a stack machine (implemented by `proc.(*EvalScope).eval`
and `proc.(*EvalScope).evalOne`) that has two modes of operation: in the
main mode it executes inteructions from the list (by calling `evalOne`), in
the second mode it executes the call injection protocol by calling
`funcCallStep` repeatedly until it either the protocol finishes, needs more
input from the stack machine (to set call arguments) or fails.

This approach has several benefits:

- it is now possible to remove the goroutine we use to evaluate expression
  and the channel used to communicate with the Continue loop.
- every time we resume the target to execute the call injection protocol we
  need to update several local variables to match the changed state of the
  target, this is now done at the top level of the evaluation loop instead of
  being hidden inside a recurisive evaluator
- using runtime.Pin to pin addresses returned by an injected call would
  allow us to use a more natural evaluation order for function calls, which
  would solve some bugs #3310, allow users to inspect values returned by a
  call injection #1599 and allow implementing some other features #1465. Doing
  this with the recursive evaluator, while keeping backwards compatibility
  with versions of Go that do not have runtime.Pin is very hard. However after
  this change we can simply conditionally change how compileFunctionCall works
  and add some opcodes.

* review round 1

* review round 2
2023-10-17 11:21:59 -07:00
Oleksandr Redko
899ba72505
all: replace deprecated io/ioutil with io and os (#3509) 2023-09-25 11:41:59 -07:00
Archana Ravindar
ebc3e61367
pky/proc: enable function call injection in Delve for linux/ppc64le (#3449)
* enable func call injection on delve for ppc64le

* Function call injection on Delve/ppc64le, modified DWARF encoding and decoding for floating point registers to make floatsum test work

* Function call injection on Delve/ppc64le cleanup

* skip PIE tests for function call injection on other packages

* Address review comments

* accounted for additional skipped PIE tests for function call injection

* Code cleanup and undoing revert of previous commit

* Enable function call injection only on 1.22 and above and some cleanup

* additional cleanup, go fmt run

* Debug function call tests fail on ppc64le/PIE mode adjusted the backup_test_health.md file accordingly
2023-09-21 10:39:57 -07:00
Alessandro Arzilli
e0b4bfbed3
Various fixes for go 1.22 (#3455)
* proc: correctly update local variables after continue

At various point during the execution of the call injection protocol
the process is resumed and the call injection goroutine could migrate
to a different thread, we must make sure to update our local variables
correctly after every point where the target program is resumed.

'fncall122debug_clean' on 'f469a0a5'.

* go.mod: update golang.org/x/tools

Go 1.22 broke golang.org/x/tools/packages

* cmd/dlv: disable TestStaticcheck with go1.22

Go 1.22 is not yet supported by staticcheck.
2023-09-19 09:34:34 -07:00
Alessandro Arzilli
7fb9ddae4d
api,dap: fix hexadecimal printing of vars with symbolic const values (#3487)
Fix hexadecimal printing of variables that can be represented using
symbolic const values in DAP as well as the command line interface.

Fixes #3485
2023-08-29 09:24:10 -07:00
Alessandro Arzilli
6a0423a1e9
proc: when stepping set condition on thread ID if there is no curg (#3475)
If there is no current goroutine when 'next', 'step' or 'stepout' are
used set a condition that the thread ID should stay the same instead.
This makes stepping work for multithreaded C programs or Go programs
that have threads started by cgo code.

Fixes #3262
2023-08-21 12:30:56 -07:00
Alessandro Arzilli
a53f1bf45d
service/api: in multiline mode print address of pointers (#3448)
When printing a pointer variable first print the address that it points
to before printing its dereferenced value.

Fixes #3446
2023-07-25 16:27:00 -07:00
Alessandro Arzilli
c1482ca911
proc: check recursion level when loading pointers (#3431)
Fixes #3429
2023-07-07 10:32:05 -07:00
Álex Sáez
71f1220717
*: add ppc64le support (#2963)
* Add vendor/golang.org/x/arch/ppc64

* Add ppc64le support
2023-07-07 09:30:38 -07:00
gocurr
80840dd2bf
all: fix typos (#3434) 2023-07-06 11:16:06 +02:00
Oleksandr Redko
2d3fd35e04
pkg,service: refactor to use %q instead of "%s" (#3430) 2023-07-05 08:49:08 -07:00
Zeke Lu
463b97dd36
pkg/proc: pad variable mem in extractVarInfoFromEntry (#3365)
* pkg/proc: pad variable mem in extractVarInfoFromEntry

On 64 bit system, the byte size of the following struct is 16:
    type myStruct struct {
       a int
       b uint32
    }
But extractVarInfoFromEntry only allocates a mem of 12 bytes for it.
When calling method of this struct with the "call" command, it will
result in this error:
    write out of bounds

This patch extends the mem by adding padding bytes to the end of the
mem.

Fixes #3364.

* move the padding logic into newCompositeMemory
2023-05-15 14:46:33 -07:00
Alessandro Arzilli
674bd63996
proc: fix runtime type handling for Go 1.21 (#3370)
Go 1.21 renamed runtime._type to internal/abi.Type and changed the name
of its fields. Update Delve so that it uses the new names for loading
interfaces and generic type parameters.
2023-05-15 10:21:52 -07:00
Alessandro Arzilli
5c7049b7b1
dwarf/godwarf: fix alignment calculation for typedef types (#3362)
Alignment calculation for typedef types was wrong due to a missing
Align method.

Fixes #3360
2023-05-08 10:38:53 -07:00
Alessandro Arzilli
1522382336
proc: fuzzing expression evaluator and variable loader (#3293)
Add code to fuzz the expression evaluator and variable loader, see
comment to FuzzEvalExpression for how to use this.
2023-03-16 12:13:10 -07:00
Alessandro Arzilli
9faf66b7a1
proc: limit maximum time.Time we try to format (#3294)
The loop adding maxAddSeconds to format a time.Time can take multiple
seconds to complete if the time is very far into the future. To avoid
this loop slowing down debugging too much limit it to an arbitrary
maximum.
The chosen maximum is 1000 times the maximum expressible time.Duration,
which is 262 years. This means that we will not format dates beyond
year 262000 AD.
2023-03-16 12:12:20 -07:00
Alessandro Arzilli
212c2002bb
proc: do not try to load a non-empty slice if the base address is 0 (#3295) 2023-03-01 11:27:06 -08:00
Alessandro Arzilli
37e44bf603
proc,proc/native: adds ability to automatically debug child processes (#3165)
Adds the ability to automatically debug child processes executed by the
target to the linux native backend.
This commit does not contain user interface or API to access this
functionality.

Updates #2551
2023-02-22 09:26:28 -08:00
Alessandro Arzilli
7c835342d3
*: remove some code for Go 1.12 or earlier (#3271)
Delve no longer compiles on Go1.12 and earlier, we don't test it on
these versions and they are 4 years old and unsupported. Remove some
code related to Go 1.12 and earlier, mostly from tests.
2023-02-14 09:38:15 -08:00
Andrei Matei
aee401b69a
pkg/proc: populate pointer values (#3229)
* proc: add a test for dangling unsafe pointers

This new tests checks the behavior when dereferencing dangling pointers.
The behavior does not fully make sense; the test checks the current
behavior for now, which will be improved in subsequent commits.

* proc: populate pointer values

This patch changes how Value and Unreadable are populated for pointer
Variables. Before this patch, variables of kind reflect.Ptr did not have
their Value field populated. This patch populates it in
Variable.loadValue(), which seems natural and consistent with other
types of variables. The Value is the address that the pointer points to.
The Unreadable field was populated inconsistently for pointer variables:
it was never populated for an outer pointer, but it could be populated
for an inner pointer in pointer-to-pointer types. Before this patch,
in pointer whose value could not be read was not easily distinguishable
from a pointer with a value that could be read, but that cannot be
dereferenced (i.e. a dangling pointer): neither of these would be marked
as Unreadable, and both would have a child marked as Unreadable. This
patch makes it so that a pointer variable whose pointer value cannot be
read is marked as Unreadable.

Using this new distinction, this patch fixes a bug around dereferencing
dangling pointers: before, attempting such a dereference produced a
"nil pointer dereference" error. This was bogus, since the pointer was
not nil. Now, we are more discerning and generate a different error.
2023-01-04 09:07:23 -08:00
Hyang-Ah Hana Kim
bbc22707d0
pkg/proc: apply simplifycompositelit analysis fixes (#3236)
https://pkg.go.dev/golang.org/x/tools/internal/lsp/analysis/simplifycompositelit
2023-01-03 08:13:28 -08:00
Alessandro Arzilli
824e0a81e8
Two fixes to type cast evaluation (#3186)
* proc: allow casts form unsafe.Pointer to any pointer and vice versa

We've allowed doing this with uintptr but we should allow
unsafe.Pointer to be used like Go uses it.

* proc: fix type casts to ptr-to-ptr types

Fix type casts to **type.
2022-11-10 09:53:28 -08:00
Alessandro Arzilli
cba16f92e8
proc: fix index access to already-loaded string values (#3184)
Fixes #3176
2022-11-07 15:22:12 -08:00
Alessandro Arzilli
6bda7085c7
proc: allow type casts between compatible types (#3149)
Go allows some type casts when the underlying types are the same.
Conform to that behavior.

Fixes #3130
2022-09-29 10:08:19 -07:00
Alessandro Arzilli
b0ac6db339
proc: fix cast to empty interface type (#3146)
Fix cast to empty interface type. This is a workaround for a
discrepancy between how type names are serialized by the compiler vs
how type expressions are formatted by go/printer.
2022-09-26 10:08:01 -07:00
Alessandro Arzilli
f82d225bdb
proc: fuse evalToplevelTypeCast and evalTypeCast (#3057)
We allowed integer and pointer type casts everywhere but type casts to
string, []byte and []rune only at toplevel.
Fuse evalToplevelTypeCast and evalTypeCast and allow both kinds
everywhere. There are multiple other ways to create variables than
don't reference user memory anyway (which wasn't the case back when
evalToplevelTypeCast was implemented).

Fixes #1423
2022-08-11 13:13:55 +02:00
Alessandro Arzilli
6f34add5db
proc,service/debugger: introduce TargetGroup abstraction (#3030)
Introduces a new TargetGroup abstraction that can be used to manage
multiple related targets.
No actual management of child processes is implemented here, this is
just a refactoring to make it possible to do that in the future.

Updates #2551
2022-07-14 14:14:45 -07:00
Alessandro Arzilli
db3e5ef2cd
proc: map access with string literal key should always succeed (#3036)
When doing a map lookup with a string literal we should load as much of
the keys to at least match the length of the string literal, so that
the lookup doesn't fail with the "string too long" error.

Fixes #3034
2022-06-24 06:48:16 -07:00
Alessandro Arzilli
ac8720eb6e
service/test,proc: move variable evaluation test to pkg/proc (#3024)
Moves variable evaluation tests to pkg/proc which is where most of the
code they test exists, this also allows the removal of a bunch of
duplicate support code.
2022-06-08 08:59:42 -07:00