Commit Graph

166 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
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
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
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
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
Oleksandr Redko
d8003a74c8
pkg/proc: fix 404 links and change to https (#3775) 2024-07-11 08:03:32 -07:00
Jayant
a4196f35a9
refactor: move loadModuleData from runtimeTypeToDIE and expose the apis (#3741) 2024-06-25 08:03:28 -07:00
Oleksandr Redko
0d0d2e1b16
*: replace fmt.Errorf with errors.New (#3752) 2024-06-20 21:50:18 +02:00
Alessandro Arzilli
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
Alessandro Arzilli
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
Alessandro Arzilli
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
Alessandro Arzilli
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
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
Oleksandr Redko
938cb6e9d8
pkg,service: remove unnecessary convertions (#3564) 2023-11-14 16:36:55 +01: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
Alessandro Arzilli
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
Oleksandr Redko
e404917db7
pkg,service: fix typos in comments, exceptions, tests (#3486) 2023-08-29 14:44:18 +02:00
Alessandro Arzilli
c1482ca911
proc: check recursion level when loading pointers (#3431)
Fixes #3429
2023-07-07 10:32:05 -07:00
Oleksandr Redko
2d3fd35e04
pkg,service: refactor to use %q instead of "%s" (#3430) 2023-07-05 08:49:08 -07:00
Alessandro Arzilli
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
Derek Parker
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
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
cui fliter
e24a7b1174 fix some comments
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-04-25 11:19:13 +02: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
cf65f94776
proc: remove unused parameter from resolveParametricType (#3276) 2023-02-15 11:35:37 -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
Oleksandr Redko
a6e3d14455
proc: Fix typos in the comments (#3231) 2022-12-28 12:41:13 +01:00
Oleksandr Redko
9523849883
*: Change comments to match common Go standarts (#3221) 2022-12-14 08:56:07 -08:00
Oleksandr Redko
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
Derek Parker
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
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
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
Quim Muntal
4455d6a9ef
Add support for windows/arm64 (#3063)
* Add support for windows/arm64

* split sentinel files and add winarm64 experiment

* update loadBinaryInfoPE to support PIE binaries

* skip TestDump on windows/arm64

* run windows/arm64 compilation on windows/amd64

* add entry point check for pie binaries

* delete unusded code

* document windows/arm64 breakpoint

* implement changing windows/arm64 fp registers

* update crosscall offset names

* fix G load when using CGO

* fix testvariablescgo

* remove DerefGStructOffset

* derefrence gstructoffset in GStructOffset() if necessary
2022-09-21 13:39:44 -07:00
cui
5ebf020be9
proc: fix hang caused by g.atomicstatus has change to atomic.Uint32 (#3129)
Co-authored-by: weixiecui <weixiecui@futunn.com>
2022-09-20 11:54:56 -07:00
cui
9bcccf81ed
proc: reduntant type conversion (#3131)
Co-authored-by: weixiecui <weixiecui@futunn.com>
2022-09-09 16:16:07 +02:00
Alessandro Arzilli
5b9f65dac2
*: switch to int64 for goroutine IDs (#3110)
Go 1.20 switched to uint64 to represent goroutine IDs, we can't
actually follow suit because we have allowed clients to use -1 to refer
to the currently selected goroutine, however we should at least switch
to int64 and also update the rtype check to accept the 1.20 type.
2022-08-16 09:31:11 -07:00
Alessandro Arzilli
3de29a88f8
proc: do not panic reading bad G struct (#3098)
Fixes #3095
2022-08-09 10:02:55 -07:00
Alessandro Arzilli
ac81269eef
proc: fix prettyprint for register components with large values (#3022)
Fix pretty printing for CPU register components (created with the
XMM0.uintN syntax) while using format strings
Also fixes printing large literal constants with format strings.

Fixes #3020
2022-06-02 10:16:32 -07:00
Alessandro Arzilli
2b97231e30
proc,service: pretty print time.Time variables (#2865)
Fixes #999
2022-03-25 13:59:57 -07:00
cui fliter
9a9c1a9f33
*: fix some typos
Signed-off-by: cuishuang <imcusg@gmail.com>
2022-03-23 16:10:00 +01:00
Alessandro Arzilli
466f9b8c93
proc: change UserCurrent to exclude internal and runtime/internal (#2853)
packages

Changes UserCurrent to exclude frames stopped inside the 'internal' and
'runtime/internal' packages of the standard library.

Before this change a goroutine blocked accepting or reading from a
socket would be reported as having a user current frame of:

    internal/poll.runtime_pollWait

After this change accepting goroutines will be reported with a user
current frame of:

    net.(*netFD).accept

and reading goroutines as:

    net.(*netFD).read
2022-01-06 09:07:26 -08:00
aarzilli
18f2a4c46b proc,dwarf/godwarf: support parametric types with dictionaries
Change debug_info type reader and proc to convert parametric types into
their real types by reading the corresponding dictionary entry and
using the same method used for interfaces to retrieve the DIE from a
runtime._type address.

'2586e9b1'.
2021-10-02 15:44:30 +02:00
Alessandro Arzilli
29eae8f617
*: clean up staticcheck problems (#2723)
Fix problems that can be fixed, ignore the ones that don't make sense
2021-09-28 12:07:42 -07:00
Suzy Mueller
53eed29900
pkg/proc: update check for system goroutine (#2585)
* pkg/proc: update check for system goroutine

The finalizer goroutine can be either a system goroutine or a user goroutine. It is considered a user goroutine only when it calls back to user code. This change attempts to get closer to the implementation in the src/runtime/traceback.go by checking the value of fingRunning.

We could alternatively adopt the approximation done by src/cmd/trace/trace.go which only special cases "runtime.main", and always considers the finalizer to be a system goroutine.
2021-09-13 14:42:21 -07:00
Derek Parker
1b2f7f0051
pkg/proc: Parse Goroutine ID in eBPF tracer (#2654)
This patch enables the eBPF tracer backend to parse the ID of the
Goroutine which hit the uprobe. This implementation is specific to AMD64
and will have to be generalized further in order to be used on other
architectures.
2021-08-24 14:53:27 +02:00
Alessandro Arzilli
c379296cc8
_scripts: auto check that pkg/proc and runtime are synchronized (#2557)
Adds a script that check automatically that the the assumptions that
pkg/proc makes about runtime are met by the actual runtime, using a
combination of parsing and magic comments.

Also emits a file describing all the struct fields, constants and
variables of the runtime that we use in pkg/proc.
2021-08-23 11:32:02 -07:00
Alessandro Arzilli
f3e76238e3
proc: move breakpoint condition evaluation out of backends (#2628)
* proc: move breakpoint condition evaluation out of backends

Moves breakpoint condition evaluation from the point where breakpoints
are set, inside ContinueOnce, to (*Target).Continue.

This accomplishes three things:

1. the breakpoint evaluation method needs not be exported anymore
2. breakpoint condition evaluation can be done with a full scope,
   containing a Target object, something that wasn't possible before
   because ContinueOnce doesn't have access to the Target object.
3. moves breakpoint condition evaluation out of the critical section
   where some of the threads of the target process might be still
   running.

* proc/native: handle process death during stop() on Windows

It is possible that the thread dies while we are inside the stop()
function. This results in an Access is denied error being returned by
SuspendThread being called on threads that no longer exist.

Delay the reporting the error from SuspendThread until the end of
stop() and only report it if the thread still exists at that point.

Fixes flakyness with TestIssue1101 that was exacerbated by moving
breakpoint condition evaluation outside of the backends.
2021-08-09 10:16:24 -07:00
Alessandro Arzilli
fdb5189e8c
dwarf/op,proc: implement more DWARF expression opcodes (#2606) 2021-08-03 09:51:15 -07:00