Commit Graph

151 Commits

Author SHA1 Message Date
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
Alessandro Arzilli
f0a32c8e1b
Go 1.17 support branch (#2451)
* proc: support new Go 1.17 panic/defer mechanism

Go 1.17 will create wrappers for deferred calls that take arguments.
Change defer reading code so that wrappers are automatically unwrapped.

Also the deferred function is called directly by runtime.gopanic, without going through runtime.callN which means that sometimes when a panic happens the stack is either:

0. deferred function call
1. deferred call wrapper
2. runtime.gopanic

or:

0. deferred function call
1. runtime.gopanic

instead of always being:

0. deferred function call
1. runtime.callN
2. runtime.gopanic

the isPanicCall check is changed accordingly.

* test: miscellaneous minor test fixes for Go 1.17

* proc: resolve inlined calls when stepping out of runtime.breakpoint

Calls to runtime.Breakpoint are inlined in Go 1.17 when inlining is
enabled, resolve inlined calls in stepInstructionOut.

* proc: add support for debugCallV2 with regabi

This change adds support for the new debug call protocol which had to
change for the new register ABI introduced in Go 1.17.

Summary of changes:
- Abstracts over the debug call version depending on the Go version
  found in the binary.
- Uses R12 instead of RAX as the debug protocol register when the binary
  is from Go 1.17 or later.
- Creates a variable directly from the DWARF entry for function
  arguments to support passing arguments however the ABI expects.
- Computes a very conservative stack frame size for the call when
  injecting a call into a Go process whose version is >=1.17.

Co-authored-by: Michael Anthony Knyszek <mknyszek@google.com>
Co-authored-by: Alessandro Arzilli <alessandro.arzilli@gmail.com>

* TeamCity: enable tests on go-tip

* goversion: version compatibility bump

* TeamCity: fix go-tip builds on macOS/arm64

Co-authored-by: Michael Anthony Knyszek <mknyszek@google.com>
2021-07-08 08:47:53 -07:00
Alessandro Arzilli
1b0c4310c4
proc: give unique addresses to registerized variables (#2527)
We told clients that further loading of variables can be done by
specifying a type cast using the address of a variable that we
returned.
This does not work for registerized variables (or, in general,
variables that have a complex location expression) because we don't
give them unique addresses and we throw away the compositeMemory object
we made to read them.

This commit changes proc so that:

1. variables with location expression divided in pieces do get a unique
   memory address
2. the compositeMemory object is saved somewhere
3. when an integer is cast back into a pointer type we look through our
   saved compositeMemory objects to see if there is one that covers the
   specified address and use it.

The unique memory addresses we generate have the MSB set to 1, as
specified by the Intel 86x64 manual addresses in this form are reserved
for kernel memory (which we can not read anyway) so we are guaranteed
to never generate a fake memory address that overlaps a real memory
address of the application.

The unfortunate side effect of this is that it will break clients that
do not deserialize the address to a 64bit integer. This practice is
contrary to how we defined our types and contrary to the specification
of the JSON format, as of json.org, however it is also fairly common,
due to javascript itself having only 53bit integers.

We could come up with a new mechanism but then even more old clients
would have to be changed.
2021-07-02 18:37:55 +02:00
Alessandro Arzilli
7c82164264
terminal,service: Add filtering and grouping to goroutines command (#2504)
Adds filtering and grouping to the goroutines command.

The current implementation of the goroutines command is modeled after
the threads command of gdb. It works well for programs that have up to
a couple dozen goroutines but becomes unusable quickly after that.

This commit adds the ability to filter and group goroutines by several
different properties, allowing a better debugging experience on
programs that have hundreds or thousands of goroutines.
2021-07-01 11:25:33 -07:00
Derek Parker
d3f4a8d443
proc: remove stack barrier support (#2540)
* proc: remove stack barrier support

Stack barriers were removed way back in Go 1.9 so it's safe to
eliminate and clean up this code now.
2021-06-17 14:35:33 +02:00
Alessandro Arzilli
585c711ce5
proc: when converting registers to slices set Base address (#2517)
If the base address isn't set then indexing and slicing will not work.
Large floating point registers already had the base set but small
general purpose registers did not.
2021-06-02 13:46:24 -07:00
Suzy Mueller
1b8428eb6c
service/dap: add type information to dap variables (#2465)
* service/dap: add type information to dap variables

* add comment explaining map type choice

* rename to setClientCapabilities

* respond to review

* update TypeString definition
2021-05-10 11:34:42 -07:00
Alessandro Arzilli
c5d58f494a
proc: add way to use CPU registers in expressions (#2446)
Changes the expression evaluation code so that register names, when not
shadowed by local or global variables, will evaluate to the current
value of the corresponding CPU register.

This allows a greater flexibility with displaying CPU registers than is
possible with using the ListRegisters API call. Also it allows
debuggers users to view register values even if the frontend they are
using does not implement a register view.
2021-05-04 12:56:17 -07:00
Alessandro Arzilli
6a70d531bb
proc/*: implement proc.(*compositeMemory).WriteMemory (#2271)
Delve represents registerized variables (fully or partially) using
compositeMemory, implementing proc.(*compositeMemory).WriteMemory is
necessary to make SetVariable and function calls work when Go will
switch to using the register calling convention in 1.17.

This commit also makes some refactoring by moving the code that
converts between register numbers and register names out of pkg/proc
into a different package.
2021-03-04 10:28:28 -08:00
Alessandro Arzilli
f19d5e5c13
proc: fix embedded field search (#2320)
Both structMember and findMethod implemented a depth-first search in
embedded fields but the Go specification requires a breadth-first
search. They also allowed promotion of fields in the concrete type of
embedded interfaces even though this is not allowed by Go.
Furthermore they both lacked protection from infinite recursion
when a type embeds itself and the user requests a non-existent field.

Fixes #2316
2021-01-29 09:25:31 -08:00
Alessandro Arzilli
3c86d68a99
proc: remove dead code (#2321) 2021-01-27 06:54:50 -08:00
nd
6726ec3aa3
pkg/proc: Fix panic in goroutine parsing for binaries compiled with go1.10 (#2283)
Before go1.11 waitreason field was a string, not an int. Return 0
waitreason for old go versions.

Should fix #2282
2021-01-04 08:53:23 -08:00
Florin Pățan
7ac317a7e8
service/api: Expose WaitSince and WaitReason fields for goroutines (#2264)
This adds the WaitSince and WaitReason fields for the goroutines to allow the users to easily understand why a goroutine is waiting.
2020-12-14 09:31:45 -08:00
Alessandro Arzilli
0843376018
proc/*: remove proc.Thread.Blocked, refactor memory access (#2206)
On linux we can not read memory if the thread we use to do it is
occupied doing certain system calls. The exact conditions when this
happens have never been clear.

This problem was worked around by using the Blocked method which
recognized the most common circumstances where this would happen.

However this is a hack: Blocked returning true doesn't mean that the
problem will manifest and Blocked returning false doesn't necessarily
mean the problem will not manifest. A side effect of this is issue
#2151 where sometimes we can't read the memory of a thread and find its
associated goroutine.

This commit fixes this problem by always reading memory using a thread
we know to be good for this, specifically the one returned by
ContinueOnce. In particular the changes are as follows:

1. Remove (ProcessInternal).CurrentThread and
(ProcessInternal).SetCurrentThread, the "current thread" becomes a
field of Target, CurrentThread becomes a (*Target) method and
(*Target).SwitchThread basically just sets a field Target.

2. The backends keep track of their own internal idea of what the
current thread is, to use it to read memory, this is the thread they
return from ContinueOnce as trapthread

3. The current thread in the backend and the current thread in Target
only ever get synchronized in two places: when the backend creates a
Target object the currentThread field of Target is initialized with the
backend's current thread and when (*Target).Restart gets called (when a
recording is rewound the currentThread used by Target might not exist
anymore).

4. We remove the MemoryReadWriter interface embedded in Thread and
instead add a Memory method to Process that returns a MemoryReadWriter.
The  backends will return something here that will read memory using
the current thread saved by the backend.

5. The Thread.Blocked method is removed

One possible problem with this change is processes that have threads
with different memory maps. As far as I can determine this could happen
on old versions of linux but this option was removed in linux 2.5.

Fixes #2151
2020-11-09 11:28:40 -08:00
Alessandro Arzilli
12009e9833
proc/*,service: replace uses of uintptr with uint64 (#2163)
Since proc is supposed to work independently from the target
architecture it shouldn't use architecture-dependent types, like
uintptr. For example when reading a 64bit core file on a 32bit
architecture, uintptr will be 32bit but the addresses proc needs to
represent will be 64bit.
2020-09-09 10:36:15 -07:00
aarzilli
f90134eb4d proc: prevent internal breakpoint conditions from failing
An internal breakpoint condition shouldn't ever error:
* use a ThreadContext to evaluate conditions if a goroutine isn't
  available
* evaluate runtime.curg to a fake g variable containing only
  `goid == 0` when there is no current goroutine

Fixes #2113
2020-09-01 15:01:39 +02:00