182 Commits

Author SHA1 Message Date
992c46c1b3 proc: additional checks parsing g structs (#4140)
The fields of the sched structure could be unreadable if what we are
parsing isn't a real G struct.

Fixes #4138
2025-09-10 11:26:58 -04:00
0b74953f0c pkg/proc: optimize range body lookup cost by trie searching and use moduledata cache to reduce LoadModuleData cost (#4113)
Fixes #4112
2025-09-01 12:51:22 -04:00
61573cffb3 *: modernize codebase with newer syntax / helpers (#4110)
Changes came from running
https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/modernize
on the codebase.
2025-08-29 15:50:08 +02:00
6346593568 pkg/proc: return better error attempting to call nonexistent function (#4062)
Fixes #4051
2025-08-24 21:27:14 +02:00
c6bc2dc38b proc: early fixes for Go 1.26 (#4070)
Change 091ff506 fixed loading the direct flag for Go 1.26 when we go
from a runtime type to a dwarf type, we also did the same check from
the dwarf type to a runtime type when converting variables into
'interface {}'.
This commit deletes unifies the two code paths deleting the one that
wasn't updated.

Fixes the tests on tip.
2025-08-20 10:40:36 -07:00
091ff50645 proc: handle moving of direct interface flag in Go 1.26 (#4032)
This flag in internal/abi.Type is moving from the Kind_ field to
the TFlag field. See https://go-review.googlesource.com/c/go/+/681936

A few of the other Kind fields dlv doesn't use (and don't exist
in Go anymore), so this code can be simplified somewhat.
2025-06-17 16:04:52 -07:00
99ec109dd3 proc: fill bi member of constants (#4026)
Fill the bi field of constant variables when we create them. This is
meant to address #4021 which is caused by trying to access a member
field of a variable with a nil bi. I couldn't find a way to make a
constant reach that point into the code but this still looks like the
most likely explanation.

Fixes #4021
2025-06-13 14:22:10 -07:00
d13bd49203 proc: limit the max length of goroutine's label map (#3928) (#3968)
Co-authored-by: Huang Hongyu <hongyu.huang@shopee.com>
2025-04-07 11:47:29 -07:00
193f21e49b proc: replace Thread.Location method with a function (#3972)
Replaces the Thread.Location method with a ThreadLocation function. All
backends implemented the Location method exactly the same way, this
change deduplicates it.
2025-04-07 11:45:17 -07:00
2408761fba proc: skip invalid goroutine labels when debugging on Go 1.24 (#3928) (#3962) 2025-04-02 09:25:22 -07:00
18ce5d6baa proc: add support for struct literals (#3935)
* service/test: fix compile error in tests

Due to a merge conflict the tests in service/test are not compiling.

* proc: add support for struct literals

Adds support for evaluating struct literals, and allocating them into
the target's memory.

Updates #1465
2025-03-18 10:11:05 -07:00
6ef45f534c proc: expose breakpoint hitcounts in expressions (#3874)
Expose breakpoint hitcounts in the expression language through the
special variable runtime.bphitcount:
  delve.bphitcount[1]
  delve.bphitcount["bpname"]
will evaluate respectively to the hitcount of breakpoint with id == 1
and to the hitcount of the breakpoint named "bpname".

This is intended to be used in breakpoint conditions and allows
breakpoints to be chained such that one breakpoint is only hit after a
different is hit first.

A few optimizations are implemented so that chained breakpoints are
evaluated efficiently.
2025-03-05 12:39:47 -08:00
62cd2d423c proc: some refactorings for supporting struct literals (#3909)
* deduplicates exprToString, defined in multiple packages, and moves it
  to astutil
* moves resolveTypedef into pkg/dwarf/godwarf, this is currently only
  used by pkg/proc but we will need to call it from pkg/proc/evalop
* creates a new FakePointerType function in pkg/dwarf/godwarf, this is
  also a function that is only used by pkg/proc but pkg/proc/evalop will
  also need.

Updates #1465
2025-02-07 07:36:23 -08:00
75c20c328c pkg: refactor sort.Sort to slices.SortFunc (#3880) 2025-01-03 10:44:28 -08:00
1a55e8e30e fix check it.Err() != nil but return a nil value error err (#3886) 2024-12-19 10:13:07 -08:00
530afae62e proc: fix loading goroutine labels on Go 1.24 (#3879)
Go 1.24 changed the way goroutine labels are stored.
2024-12-16 12:31:24 -08:00
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
7b9a379e59 proc: allow accessing captured variable as if they were struct fields (#3866)
If 'a' is a captured variable in a function pointer called 'f' let
'f.a' evaluate to its value.
2024-12-02 11:20:51 -08:00
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
def0688e7a proc: step into coroutine (#3791)
The step command is changed such that when the function being currently
called is a coroutine switch function it will move to the associated
coroutine.
Functions that switch coroutines are currently the next, stop and yield
closures produced by the iter.Pull function.
2024-09-24 10:22:04 -07:00
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
d8003a74c8 pkg/proc: fix 404 links and change to https (#3775) 2024-07-11 08:03:32 -07:00
a4196f35a9 refactor: move loadModuleData from runtimeTypeToDIE and expose the apis (#3741) 2024-06-25 08:03:28 -07:00
0d0d2e1b16 *: replace fmt.Errorf with errors.New (#3752) 2024-06-20 21:50:18 +02:00
2ec2e831d6 proc: initial stepping with range-over-func support (#3736)
Initial support for stepping in functions that use the new
range-over-func statement in go1.23.
Does not support:

- inlining
- viewing variables of the enclosing function from a range-over-func
  body closure
- the correct way to find the enclosing function from a range-over-func
  body closure (but it should work most of the time).

Updates #3733
2024-06-04 12:52:30 -07:00
2e88b7ead3 tests: fix tests on Go 1.23 (#3697)
* Adjust rtype.go script to handle constants moved to internal/abi from
  runtime
* Remove tests in service/dap/server_test that relied on knowledge of
  the internal layout of channels.
2024-04-11 09:40:57 -07:00
bbcea6b9f4 proc: support reading captured variables of closures (#3682)
Supports showing captured variables for function closures on versions
of Go that export informations about the closure struct (Go >= 1.23)

Fixes #3612
2024-04-07 21:36:50 -07:00
5bd835a801 *: misc fixes for go1.23 (#3663)
- skip staticcheck on go1.23 for now
- fix reading interface values in go1.23
- sync list of waitreasons from go1.23
2024-02-22 11:35:15 -08:00
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
938cb6e9d8 pkg,service: remove unnecessary convertions (#3564) 2023-11-14 16:36:55 +01:00
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
788df884e6 proc: use DW_AT_trampoline to detect auto-generated code (#3528)
Use the trampoline attribute to detect auto-generated code. This fixes
a bug where stepping into a method of a generic type called through an
interface will take the debugger into an auto-generated wrapper that
does not have a dictionary and using next will step out of the wrapper.

Fixes a bug reported on the #delve channel of the gophers slack server.
2023-10-16 08:57:33 -07:00
e404917db7 pkg,service: fix typos in comments, exceptions, tests (#3486) 2023-08-29 14:44:18 +02:00
c1482ca911 proc: check recursion level when loading pointers (#3431)
Fixes #3429
2023-07-07 10:32:05 -07:00
2d3fd35e04 pkg,service: refactor to use %q instead of "%s" (#3430) 2023-07-05 08:49:08 -07:00
d963eb1057 proc: read context from sigtrampgo, fixes TestCgoStacktrace2 on 1.21 (#3401)
* logflags,proc: flag to log stacktrace execution

Add a log flag to write logs about what the stacktracer does.

* proc: read context from sigtrampgo, fixes TestCgoStacktrace2 on 1.21

Changes stacktrace code to read the signal context from the arguments
of sigtrampgo.
Also changes the automatic fatalthrow breakpoint for go 1.21.
In combination these two changes fix TestCgoStacktrace2 on Go 1.21 on
various platforms.
2023-06-27 09:33:07 -07:00
ccf17a6f42 pkg/proc: enable basic debug functionality for stripped ELF binaries (#3408)
We used to parse the .gopclntab section but removed support in favor of
simply using DWARF debug information, due to lack of C symbols among
other reasons. This makes it impossible to debug stripped binaries,
which some distrubutions ship by default.

Add back in basic support for .gopclntab which survives if the binary
is stripped, allowing for rudimentary debugging such as basic
program navigation, tracing, etc...
2023-06-14 13:23:46 +02:00
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
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
e24a7b1174 fix some comments
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-04-25 11:19:13 +02:00
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
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
cf65f94776 proc: remove unused parameter from resolveParametricType (#3276) 2023-02-15 11:35:37 -08:00
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
a6e3d14455 proc: Fix typos in the comments (#3231) 2022-12-28 12:41:13 +01:00
9523849883 *: Change comments to match common Go standarts (#3221) 2022-12-14 08:56:07 -08:00
34b6ee869f proc: replace os.SEEK_CUR with io.SeekCurrent (#3214)
Because os.SEEK_CUR is deprecated as stated in the documentation.
2022-12-12 19:16:49 +01:00
18ebd9195a pkg/proc: fix arm64 linux cgo stacktrace (#3192)
This patch introduces some changes, particularly to arm64SwitchStack
which fixes the test when running on linux/arm64. The changes causes the
same test to fail on darwin/m1 so temporarily keeping both versions.
Next step should be to refactor and unify the two so they both work with
the same function.

Fixes #2340
2022-11-15 09:05:43 +01:00
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
4372ce0d27 proc,_scripts/rtype.go: add rtype annotations for g.atomicstatus (#3143)
Adds some rtype annotations for g.atomicstatus and update
_scripts/rtype.go to handle types outside of the runtime package.
2022-09-26 10:10:51 -07:00