998 Commits

Author SHA1 Message Date
cui
922470c995
proc: compile hit-condition regexp once (#4335)
parseHitCondition rebuilt the same regexp from a MustCompile literal on
every call. Move hitConditionRegex to package scope so the pattern is
compiled once at initialization while keeping parseHitCondition behavior
unchanged.
2026-05-04 13:13:02 -07:00
cui
b936c580be
proc: bail out of loadArrayValues after stride overflow (#4328)
Detecting uint overflow when computing Base+stride*count already sets
v.Unreadable, but execution continued into memory prefetch and element
loading with inconsistent state. Return immediately like other guard
clauses in this function.
2026-05-04 13:12:27 -07:00
cui
7a6b813d1b
proc: fix OR handling in breakpointConditionSatisfiable (#4325)
The token.OR branch required both operands to pass satisf recursively,
matching AND semantics incorrectly. Use logical disjunction so hit-count
fast paths treat disjunctive breakpoint conditions accurately.
2026-05-04 13:10:25 -07:00
cui
3e7fcd4e06
proc/internal/ebpf: fix AddressToOffset off-by-one at section load (#4324)
AddressToOffset compared virtual addresses with strict inequality against
each executable ELF section load address. PCs landing exactly on Section
.Addr were never matched while still within [Addr, Addr+Size).

Use inclusive lower bounds so the scan matches the usual VMA half-open
interval.
2026-05-04 13:09:14 -07:00
cui
129dde8de3
proc: propagate AddrPiece ReadMemory errors in composite memory (#4323)
newCompositeMemory ignored errors from MemoryReadWriter.ReadMemory when
building address-based DWARF fragments, so failed reads silently produced
zero-filled data. Return a wrapped error with size and address context,
consistent with RegPiece failures.
2026-05-04 13:08:02 -07:00
cui
46ca47a530
native: propagate PtraceGetRegs error on linux/ppc64le (#4322)
ptraceGetGRegs ignored the return value from sys.PtraceGetRegs, so
registers() never reported syscall failures when reading general purpose
registers. Assign the error and normalize syscall.Errno(0) to nil like
other ptrace helpers.
2026-05-04 13:06:29 -07:00
cui
087a500040
native: propagate PtraceSetRegs error on linux/ppc64le (#4321)
ptraceSetGRegs ignored the return value from sys.PtraceSetRegs, so
setPC and SetReg never reported syscall failures when writing general
purpose registers. Assign the error and normalize errno(0) to nil like
the rest of the ptrace helpers.
2026-05-04 13:05:56 -07:00
Álex Sáez
59d9aeee99
proc: fix SP calculation for sigpanic frames on arm64 (#4319)
* proc: fix SP calculation for sigpanic frames on arm64

Without this fix, stack traces from linux/arm64 core dumps showed SP
values that differed from the runtime's panic output.

Fixes #3591

* Update withCoreFile
2026-04-30 12:01:49 -07:00
Álex Sáez
1d5a7eb404
proc: implement frame pointer unwinding (#4288)
* Add BenchmarkStacktrace test

* proc: implement frame pointer unwinding

Add hybrid stack unwinding that attempts frame-pointer-based unwinding before falling back to DWARF.

* Rename useDWARF and change to funcToImage

* Update comment

Remove _fixtures/deeprecursion.go

* Add check of non-go code

* Fix ARM64 FP unwind false positives and Windows failures.
2026-04-28 11:19:03 -07:00
Archana Ravindar
29aa227c5c
pkg/proc: extend feature to print procedure parameters in trace on eBPF backend (#4305)
* Extend feature to print procedure parameters in trace on eBPF backend
Fixes #4266

* address review comments

* ran go fmt
2026-04-23 11:52:31 -07:00
Varun Gandhi
08ef5f3d75
pkg/proc: Fix flakiness in TestWaitFor (#4306)
TestWaitFor could have the following sequence of events:
1. cmd.Start() is called.
2. The process is started in the kernel.
3. CreateToolhelp32Snapshot (inside waitForSearchProcess) sees
   the process and returns from native.WaitFor.
4. The test immediately deferences cmd.Process, but cmd.Process
   has not been assigned yet in cmd.Start() -> nil panic.

This patch fixes the issue by introducing a channel that is
written to from testWaitForSetup() _after_ cmd.Start() returns.
Unlike the mutex + boolean, this channel can be waited upon
without spinning, and only then cmd.Process is read inside
the test code.
2026-04-23 11:49:00 -07:00
LuaLighter
c4280281d2
chore: fix typos(#4316)
Signed-off-by: purelualight <purelualight@outlook.com>
2026-04-23 11:47:50 -07:00
Derek Parker
0b686c36d0
proc/internal/ebpf,build: extend eBPF tracing type support (#4285)
* proc/internal/ebpf,build: extend eBPF tracing type support and update Docker build

Add support for additional Go types in the eBPF tracing backend:

- Bool: use BoolType with ByteSize 1 instead of IntType with ByteSize 8
- Int/Uint: use actual DWARF size instead of hardcoded ByteSize 8
- Float32/Float64: synthesize FloatType, detect XMM registers as unreadable
- Complex64/Complex128: synthesize ComplexType with XMM detection
- Pointer: capture pointer address and dereference pointed-to value via
  bpf_probe_read_user in eBPF C code
- Slice: capture slice header (ptr+len+cap) and dereference element data
- Graceful degradation: map, chan, interface, func, struct, and array
  types now produce specific "not yet supported" errors instead of
  generic "type not supported by ebpf"

Add Unreadable field to RawUProbeParam so the Go-side parser can
propagate specific error messages through to Variable display.

Update eBPF build infrastructure:
- Replace EOL Ubuntu 21.04 base image with Ubuntu 22.04
- Use clang-12 (required: newer clang generates BPF code that fails
  the kernel verifier with "dereference of modified ctx ptr disallowed")
- Update Go from 1.17 to 1.24
- Remove sudo requirement from build-ebpf-builder-img.sh
- Add -u flag to Docker run to avoid root-owned output files

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* dwarf/godwarf,proc: fix slice ReflectKind and address PR review feedback

Fix a bug in the DWARF type parser where SliceType.ReflectKind was not
set (stayed 0/reflect.Invalid). When parsing struct types, the code
creates a new StructType, sets ReflectKind on it, then for slices
creates a new SliceType and reassigns the pointer — losing the
ReflectKind. The String case already had an explicit fix for this
(str.ReflectKind = reflect.String), but the Slice case was missing it.

This caused the eBPF tracing backend (which uses dt.Common().ReflectKind
to determine type kind) to see kind=0 for slice parameters, making them
appear as unsupported types. The ptrace backend was unaffected because it
uses Go type assertions (case *godwarf.SliceType) instead of ReflectKind.

Also addresses PR review feedback:
- Add t.Parallel() to TestTraceEBPFTypes subtests
- Use regexp matching for pointer/slice address verification
- Add content verification for slice test output
- Add comment explaining -u flag in build-ebpf-objects.sh
- Add comment explaining amd64-only XMM register threshold
- Handle CreateCompositeMemory errors in target.go
- Remove debug prints from target.go

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* docs: document eBPF type support pipeline and TestTraceEBPFTypes

Add documentation for the eBPF type support pipeline, currently
supported types, the canonical test (TestTraceEBPFTypes) for adding
new type support, and the clang-12 build constraint.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* proc/internal/ebpf: clarify pointer/slice comments per review

Clarify that the eBPF probe does capture dereferenced data, but
loadValue runs Go-side after the probe returns and cannot follow
pointer chains through fake memory addresses. Also remove unicode
arrow from XMM register comment.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* proc/internal/ebpf: clarify pointer/slice deref_val limitations

Explain why we display raw addresses instead of dereferenced values:
element type info isn't propagated through the eBPF pipeline, and
deref_val is limited to 48 bytes which is insufficient for nested
or variable-length types.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* address review feedback

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-26 09:27:35 +01:00
aarzilli
b37872a6db pkg/terminal,service: add TypeInfo API
Add an API to retrieve type information and make the 'whatis' command
accept a type name and print what we know about it.

Fixes #2249
2026-03-26 08:41:03 +01:00
Varun Gandhi
0355633b29
pkg/proc: Fix flaky test on Windows (#4292)
TestWaitFor was flaky on Windows. This seems to be linked to
prefix-based matching, where the fixture process spawned by
one test could be waited upon by another test. Adding a
unique no-op argument to different invocations of the
same fixture binary appears to fix the flakiness issue.
2026-03-25 10:42:21 -07:00
cui
160c32bef1
proc: fix stack watch breaklet index for recorded replay (#4295)
* proc: fix stack watch breaklet index for recorded replay

When adding the extra WatchOutOfScope breakpoint at the CALL before the
return PC, the code used len(retbp.Breaklets) to index into retbp2.Breaklets.
If the return address already had other breaklets (e.g. a user breakpoint),
that index could be out of range.

Add TestWatchpointStackRecordedOutOfScopeBreakletIndex (runs with -backend=rr)
to cover this path.

* fix: review
2026-03-25 10:42:01 -07:00
cui
f7be04f153
native: return ptrace error from riscv64 setSP (#4298)
setSP ignored the error from ptraceSetGRegs and always returned nil,
so callers could not detect failures when updating the stack pointer.
2026-03-25 10:40:54 -07:00
cui
a8e6978c26
proc: clear stepping breakpoints on every target in TargetGroup (#4299)
ClearSteppingBreakpoints returned after the first target with stepping
breakpoints, so other targets in the group were never cleared.
2026-03-25 10:40:23 -07:00
Alessandro Arzilli
ea13840996
pkg/proc,service,pkg/terminal: add stacktrace caching (#4277)
Adds caching to stacktraces so that stacktrace requests are not
quadratic. Also add a Skip parameter to the Stacktrace RPC request so
that clients can only request the frames they need.

Fixes #3809
Fixes #989
2026-03-09 10:23:11 -07:00
Derek Parker
ad2756669a
service/dap,pkg/proc: fix misc test failures (#4273)
* service/dap,proc: tolerate debuginfod events in tests

When debuginfod is available on the system (e.g. Fedora), asynchronous
"Download debug info" output events can arrive during DAP sessions and
EventBinaryInfoDownload events can appear in the proc event stream.
Tests were not expecting these and would fail.

Fix the DAP test client to skip debuginfod download output events in
ExpectMessage, and fix TestBreakpointMaterializedEvent to search for the
materialized event rather than assuming it is the first event.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* proc: fix test failures with Go 1.27 (gotip)

TestClassicMap: replace panic with t.Skip since the noswissmap
GOEXPERIMENT was removed in Go 1.27.

TestRangeOverFuncNextInlined: extend skip to all Go >= 1.24. The
inlined range-over-func symbol name issue (#3882) still requires a
compiler fix that has not landed in 1.27.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* cmd/dlv: skip TestStaticcheck on development versions of Go

Staticcheck output depends on the Go version used to build it. When
running against a development version (e.g. gotip), the output will
not match the checked-in baseline, causing spurious failures.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-04 09:34:20 +01:00
Varun Gandhi
093f1eba60
proc: Remove special-casing for 1.23 in tests (#4271)
go.mod specifies 1.24, so it's not possible to compile the
tests with Go toolchains <= 1.23 anyway. It doesn't make
sense to skip certain tests for older toolchains, because
attempting to use old toolchains will fail at build time.
2026-03-03 09:36:12 -08:00
Alessandro Arzilli
368a2ef33d
pkg/proc/debuginfod: fix debuginfod download progress (#4270)
debuginfod-find broke the documented way to get progress information:

https://sourceware.org/bugzilla/show_bug.cgi?id=33937

Restore this functionality by using the --verbose flag instead.
2026-03-02 12:10:18 -08:00
Derek Parker
50c3bbcb93
proc: support debugging stripped non-Go binaries (#4263)
* proc: support debugging non-Go binaries that dlopen Go shared libraries

Add support for debugging non-Go stub binaries that dynamically load Go
shared libraries via dlopen or other dynamic linkage modes. When the
initial binary has no Go runtime symbols or DWARF info, Delve now marks
it as non-Go and defers Go-specific initialization. A breakpoint on the
dynamic linker's _dl_debug_state function detects shared library loads,
allowing Delve to pick up Go debug info when a Go .so is loaded at
runtime.

* proc: address PR review feedback for non-Go binary debugging

- Deduplicate auxv parsing by extracting searchAuxv helper
- Rename IsNonGo to IsGo (positive flag is easier to reason about)
- Move Go image detection into loadDebugInfoMaps to avoid reparsing
  debug_info; uses DW_AT_language == DW_LANG_Go which is already
  checked there for cu.isgo
- Remove hasGoProducer function (no longer needed)
- Remove pkg/proc import from pkg/terminal/command.go; use string
  literal for stop reason comparison instead
- Update CLAUDE.md with DWARF parsing and layer boundary guidance

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 15:05:11 +01:00
Alessandro Arzilli
60b512f718
service/api: remove variable formatting helper methods (#4259)
Replace SinglelineStringFormatted, SinglelineStringWithShortTypes and
MultilineString with a single configurable StringWithOptions.
The Variable type was starting to have too many formatting helper methods.

Keep SinglelineString since it's used everywhere.

Co-authored-by: Shang Jian Ding <rifflegrass@gmail.com>
2026-02-16 09:23:06 -08:00
Derek Parker
380dd7ed0d
proc: fix sigpanics in swiss map iterator (#4261)
The fix adds validation at every point where pointers are dereferenced
or struct fields are accessed:

- loadTypes: check dirPtr after maybeDereference for both small map
  (dirLen <= 0) and large map (dirLen > 0) paths.
- loadCurrentTable: check tab after maybeDereference; check all
  toField() returns for the index, groups, groups.data, and
  groups.lengthMask fields; extend existing groups nil check to also
  check Unreadable.
- loadCurrentGroup: check toField() returns for slots and ctrl fields.

In all cases, the map is marked as Unreadable with a descriptive error
message rather than panicking.

Fixes #4005
2026-02-14 13:00:06 +01:00
Alessandro Arzilli
0f96809892
proc: fix TestRangeOverFuncNext for go1.26 on arm64 (#4254) 2026-02-09 11:24:19 -08:00
Alessandro Arzilli
e5398432d1
proc,service: detect and warn about trimpath (#4241)
Detect if the binary we are debugging was built using trimpath,
propagate it through the API and warn about it in DAP.
2026-01-30 12:37:55 -05:00
Derek Parker
e7c6842466
cmd/dlv: Add trace backend parity test and fix eBPF formatting (#4250)
Adds a comprehensive parity test ensuring ptrace and eBPF trace backends
produce identical output, preventing formatting divergence as new types
are added.

The test revealed and fixes several eBPF formatting issues:
1. Goroutine format: Now uses "goroutine(N):" to match ptrace
2. Return value format: Now uses ">> goroutine(N): func => (val)"
3. String capture bug: Strings were showing as empty - fixed by adding
   StringType to eBPF helpers so string values are properly loaded

Test coverage:
- Fixture tests all currently supported types: int64, uint64, bool,
string
- Runs dlv trace with both backends on same function
- Compares outputs byte-for-byte (filtering process exit messages)
- Updated all existing eBPF test expectations to match new format

All eBPF trace tests now pass with consistent formatting between
backends.

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-29 15:24:15 +01:00
Derek Parker
4deebafb7f
pkg/proc: fix ebpf uprobe placement to skip function prologue (#4249)
Use FirstPCAfterPrologue instead of fn.Entry when setting entry
uprobes to avoid duplicate events when the runtime grows the stack.
2026-01-29 15:21:21 +01:00
Derek Parker
0288b22328
proc/internal/ebpf: fix goroutine leak and shutdown sequence for ebpf (#4231) 2026-01-15 09:59:35 +01:00
Derek Parker
1ea883a22d
*: downgrade riscv64 (#4232)
The riscv64 builder has been broken since it was  enabled. While we wait
for a stable builder and assurances that riscv64 is passing, disable the
CI target and require the `exp.linuxrisc
2026-01-15 09:54:56 +01:00
Derek Parker
e93cbe86a1
proc: fix finding moduledata in 1.26+ (#4228)
Go switched to having a dedicated section to store this information, so
we no longer have to use the brittle approach we used before.
2026-01-07 10:38:31 +01:00
Derek Parker
7f42ac8564
*: modernize codebase (#4221)
Run go run
golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest
-fix -test ./... on the codebase now that the module version has updated
to 1.24.
2025-12-21 15:33:54 +01:00
Alessandro Arzilli
b1c7c0e586
gdbserial: do not set detached if we kill the process (#4216)
To mach the behaviour of the native backend, do not set detached to
true if when we kill the process. This fixes a test failure of
TestRestartRequestRebuildFail on macOS.
2025-12-17 13:47:56 -05:00
Alessandro Arzilli
3f9b21ea31
*: More fixes for Go 1.26 (#4211)
* TeamCity: fix download url in test_mac.sh

The direct link to storage.googleapis.com no longer works, use the one
that's on the website.

* proc: fix loading goroutine labels

The format used to store goroutine labels changed again. Adapt to the change.

* Cirrus-CI: upgrade FreeBSD image used

14.2 no longer exists
2025-12-08 13:56:00 -05:00
Ethan Reesor
763fc5f54f
pkg/proc: process spawned event (#4171) 2025-12-06 12:36:12 +01:00
Quim Muntal
867c71b0f7
*: replace github.com/hashicorp/golang-lru with a custom lru cache (#4196)
* replace github.com/hashicorp/golang-lru with a custom lru cache

* fix caplocks

* use a mutex instead of rwmutex

* add lrucache tests

* move lru to its own package
2025-11-25 14:21:26 -05:00
lrzlin
997463564b
*: update riscv64 support and adding it in test matrix (#4190) 2025-11-25 14:02:02 -05:00
Alessandro Arzilli
18970f4690
pkg/proc: add way to disable stop-on-error for breakpoint conditions (#4191)
Add a fake delve.catch function that can be used to wrap the expression
of breakpoint conditions so that they do not stop if the expression can
not be evaluated correctly.
The main use case for this is that it's hard to set breakpoint
conditions on interface variables that assume different types but it
can also be useful in other cases (for example checking the value of a
pointer-to-struct that sometimes is nil).
2025-11-24 12:33:53 -05:00
Alessandro Arzilli
622594ce54
*: fix tests on windows and arm64 for go1.26 (#4205)
Fix some failing tests for go1.26. The arm64 failures are due to
different optimizations. The test failures on windows are due to there
being an extra goroutine with a starting location for which we do not
have line number informations.
2025-11-24 12:32:21 -05:00
Alessandro Arzilli
f147ac3f28
pkg/proc: guard register logging from nil pointer dereferences (#4188)
If we can't read a thread's registers don't try to print them.

Fixes #4187
2025-10-28 11:59:57 -04:00
Archana Ravindar
35ccc94914
Add support to trace defer function calls under trace follow option (#3978) 2025-10-28 15:28:56 +01:00
Derek Parker
7080b62cf9
pkg/dwarf: do not insist stmt is same line as entry (#4186)
This invariant does not hold for optimized binaries. For the example
program included in this patch, the disassembly of the function for an
optimized build looks like the following:

``` TEXT main.ManyArgsWithNamedReturns(SB)
/home/deparker/Code/delve/_fixtures/multinamedreturns.go
multinamedreturns.go:24 0x4a9f40 4c894c2470 mov qword ptr [rsp+0x70], r9
multinamedreturns.go:24 0x4a9f45 4c899c2480000000 mov qword ptr
[rsp+0x80], r11 => multinamedreturns.go:7 0x4a9f4d 488d1403 lea rdx, ptr
[rbx+rax*1] multinamedreturns.go:7 0x4a9f51 4801ca add rdx, rcx
multinamedreturns.go:7 0x4a9f54 4801fa add rdx, rdi
multinamedreturns.go:7 0x4a9f57 4801f2 add rdx, rsi
multinamedreturns.go:7 0x4a9f5a 4c01c2 add rdx, r8
multinamedreturns.go:7 0x4a9f5d 4c01ca add rdx, r9
multinamedreturns.go:7 0x4a9f60 4c01d2 add rdx, r10 ... ```

As you can see the entry is marked as line 24, whereas the first line we
really want to stop at is line 7 in this build. Enforcing that we want
to find a statement with the same line as the entry, this makes Delve
stop at the end at the `ret` instruction:

``` multinamedreturns.go:22 0x4aa01b 488d1c11 lea rbx, ptr [rcx+rdx*1]
multinamedreturns.go:22 0x4aa01f 48d1fb sar rbx, 0x1
multinamedreturns.go:24 0x4aa022 c3 ret ```
2025-10-28 15:27:37 +01:00
Derek Parker
e61c678d6b
pkg/terminal: allow custom starlark commands to be used in on prefix (#4170)
Fixes #4160
2025-10-16 13:56:19 +02:00
George Adams
cd7257f518
winarm64: remove experimental build tags (#4176)
* winarm64: remove experimental build tags

* update faq
2025-10-15 16:49:21 -04:00
Jayant
4b670ea7f8
pkg/terminal: lazy init functions trie to reduce unnecessary memory usage (#4177) 2025-10-14 13:38:38 -04:00
Alessandro Arzilli
d5d75768ff
proc: add test for interfaces with otherwise unreachable runtime types (#4096)
Add a test to read the runtime type of an interface variable that is
not used in any other ways except through interfaces.
This is a regression check for issue #4080 which is a compiler problem.

Fixes #4080
2025-10-08 18:02:16 -04:00
Alessandro Arzilli
ba539b8aa1
proc: simplify and rename structMember (#4159)
With the recent changes in 1e3ccee (#4118) structMember became largely
reduntant with the new findStructMemberOrMethod. This commit simplifies
the code of structMember so that it does not handle embedded structs
and interfaces and changes its name to structField so that it can be
kept as an internal lightweight version of findStructMemberOrMethod.
2025-10-08 18:01:32 -04:00
George Adams
cb52d0cc1b
CI: add windows arm64 workflow (#4175)
* CI: add windows arm64 workflow

* add win-arm64 capslock

* add capslock build tag

* add servive test build tag

* skip proc_test.go

* unskip more tests

* skip TestHardcodedBreakpointCounts as flaky

* add gotip

* add version log to ps1

* switch logic to use stable json endpoint for getting latest go

* add continue-on-error for gotip
2025-10-08 17:44:12 -04:00
Alessandro Arzilli
7b41ab9324
service/dap: use exception breakpoints for predefined breakpoints (#4169)
Use DAP's exception breakpoints to represent the predefined breakpoints
we set for unrecovered panics and fatal throws, so that DAP users can
disable those breakpoints.

Fixes #4038
2025-10-07 19:10:13 -04:00