Commit Graph

2546 Commits

Author SHA1 Message Date
Derek Parker
cde14a46f1
*: Add explicit code of conduct (#3540)
Adds a callout to the standard Go code of conduct in the CONTRIBUTING.md doc.
2023-10-27 15:07:39 +02:00
Derek Parker
1e2338d233
proc: allow evaluator to reference previous frames (#3534)
Fixes #3515
2023-10-24 18:57:39 +02:00
Alessandro Arzilli
b9b553bccd
service/api: use bitfield for prettyprint flags (#3536)
Use a bitfield for the internal flags used by the prettyprinting code.
2023-10-24 09:35:37 -07:00
Alessandro Arzilli
d4104a6bcc
proc: remove expr evaluation goroutine from EvalExpressionWithCalls (#3532)
We have used a goroutine to keep track of some of the expression
evaluation status across target resumes during call injections.
Now that the expression interpreter has been rewritten to use a stack
machine we can move what little state is left into the stack machine
and get rid of the goroutine-and-channel mechanism.
2023-10-23 12:29:04 -07:00
Alessandro Arzilli
90a1571f88
CI: update staticcheck version (#3533)
Update staticcheck version and re-enable TestStaticcheck on Go 1.22.
2023-10-20 10:05:58 -07: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
Oleksandr Redko
0761d37c53
proc: fix comment typos (#3531) 2023-10-19 11:04:31 -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
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
Joel Sing
04bb7fda33
proc/native: use cgo instead of C for freebsd (#3529)
There is no benefit to having a small part of the freebsd backend
implemented in C, rather than using cgo. While here, add a missing
call to procstat_close and check the return value of
procstat_getpathname.
2023-10-16 08:56:17 -07:00
Alessandro Arzilli
9986a9845f
service/test: disable TestClientServer_chanGoroutines with rr backend (#3492)
It doesn't work with rr because it uses runtime.Breakpoint to stop.
2023-10-13 10:55:24 -07:00
Alessandro Arzilli
20350611ce
proc: implement follow exec mode on Windows (#3507) 2023-10-13 16:51:11 +02:00
Upils
70f21c9f86
Use a valid timezone in tested binary (#3527)
With recent changes to debian/ubuntu tzdata package, the Mexico/BajaSur is not valid anymore (not present by default). It is now present in the tzdata-legacy package, which is not a essential package. Without this timezone, the call to time.LoadLocation() will send a nil location, which will provoke a panic in time.ParseInLocation(). This change uses the underlying associated timezone America/Mazatlan.
2023-10-12 12:24:49 +02:00
Derek Parker
6185e673c2
pkg/terminal: support vscode in edit command (#3524) 2023-10-09 17:58:21 +02:00
Hyang-Ah Hana Kim
f90ede4653
service/dap: fix bugs in stdout/stderr handling (#3522)
Fixes bugs introduced in v1.21.1

* Avoid dropping the last bytes from stderr/stdout when Read returns an
  error. (Read returns n>0). And skip sending Output event if Read
  returns n==0.

* Fix the bug that drops all stdout in the existing noDebug mode.

For #3253
2023-10-09 08:27:32 -07:00
Suzy Mueller
b041bd8e98
service/dap: add the concrete type to interface type (#3510) 2023-10-03 08:51:46 -07:00
Oleksandr Redko
255afbfdb7
all: remove obsolete build tags "// +build" (#3513) 2023-10-03 08:50:11 -07:00
Derek Parker
2dba916a78
V1.21.1 (#3518)
Thank you to everyone who contributed to this release:

@alexsaezm, @pgavlin, @archanaravindar, @aarzilli, @hyangah, @thechampagne, @javierhonduco, @andreimatei, @gocurr, @alexandear, @stefanhaller.
2023-10-03 09:05:40 +02:00
Oleksandr Redko
899ba72505
all: replace deprecated io/ioutil with io and os (#3509) 2023-09-25 11:41:59 -07:00
Pat Gavlin
224a2805a4
pkg/proc: macho: Enable debugging stripped binaries (#3511)
Load a symbol table from pclntab as when debugging stripped ELF
binaries.
2023-09-25 11:41:34 -07:00
XXIV
bb59e23f2e
fix memory leak (#3512) 2023-09-25 11:40:57 -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
Derek Parker
4d30cd461b
pkg/terminal: support more editors with edit command (#3506)
The current implementation assumes a specific command line interface
for opening an editor at a specific location within the source file.
This patch updates for different formats, namely the one used by the
editor 'hx'.
2023-09-20 09:25:48 +02:00
Alessandro Arzilli
db7e60aef3
proc: move StepInstruction method to TargetGroup (#3488)
Move StepInstruction method to TargetGroup since it will need access to
the process group on Windows to call WaitForDebugEvent.
2023-09-20 09:17:45 +02: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
Hyang-Ah Hana Kim
30b70bc606
service/dap: accept a string list as launch request's buildFlags (#3496)
This change accepts both string type and []string. dap.BuildFlags
is a union of string and []string.

Fixes #2718
For golang/vscode-go#1831, golang/vscode-go#1027
2023-09-19 09:32:15 -07:00
Oleksandr Redko
ffd1c396c2
_scripts: remove unnecessary os.ExpandEnv (#3504) 2023-09-19 09:30:18 -07:00
Oleksandr Redko
2b9c3d5c04
proc,service: simplify tests with T.Setenv (#3503) 2023-09-19 09:29:47 -07:00
Hyang-Ah Hana Kim
e072a64903
pkg/terminal: add 'packages' command (#3499)
This command lists the packages included in the debugee.
The implementation utilizes "ListPackagesBuildInfo" RPC.

In order to support server-side filtering like `sources` and other
commands, expanded the ListPackagesBuildInfo RPC to take an optional
filter field.
2023-09-18 08:59:58 -07:00
Eng Zer Jun
382bb0fde6
pkg/proc/internal/ebpf: remove redundant nil check (#3502)
From the Go specification:

  "1. For a nil slice, the number of iterations is 0." [1]

Therefore, an additional nil check for before the loop is unnecessary.

[1]: https://go.dev/ref/spec#For_range

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2023-09-18 08:01:52 -07:00
Stefan Haller
c7097b8e1d
service/dap: strip package paths from symbols in callstack (#3500)
This solves the problem that function names with long package paths are hard to
read when the callstack window is narrow, because all you see is the beginning
of the package path.

For example, instead of

  github.com/some/long/package/path/pkg.(*SomeType).SomeMethod

we now display

  pkg.(*SomeType).SomeMethod
2023-09-16 06:06:28 +02:00
Archana Ravindar
86020cdd7a
pkg/proc: Fix PIE tests on ppc64le port (#3498)
* Fix PIE tests on ppc64le port

* formatted ppc64le_disasm.go as part of fixing PIE tests for ppc64le port
2023-09-14 10:08:29 -07:00
Alessandro Arzilli
f469a0a57a
go.mod: update version of github.com/cilium/ebpf (#3491)
Fixes #3490
2023-08-30 10:22:08 -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
Oleksandr Redko
e404917db7
pkg,service: fix typos in comments, exceptions, tests (#3486) 2023-08-29 14:44:18 +02:00
Alessandro Arzilli
7f094c81e9
proc: refactorings to implement follow-exec mode on Windows (#3441)
Miscellaneous non-functional changes to prepare for adding support for
follow-exec mode on Windows:

- removed (*nativeProcess).wait function from Windows backend (unused).
- move close of ptraceDoneChan from release to handlePtraceFuncs, this
  makes postExit callable by a function executed by execPtraceFunc.
- change addTarget to detach before creating the target object if we
  don't actually want to attach to the child process, also moved the
  detach call to (*processGroup).add instead of having one in addTarget
  and one in the code that calls (*processGroup).add.
- changed Detach to be a method of TargetGroup/ProcessGroup, the
  Windows backend will need access to the process group to call
  WaitForDebugEvent.
- moved resume method to processGroup. First all threads stopped at a
  breakpoint need to be stepped, then all other threads can be resumed.
  This is true also for linux even though it didn't cause the current
  tests to fail.
2023-08-28 12:46:19 -07:00
Alessandro Arzilli
0b35fe6d42
proc,service,terminal: add ways to list goroutines waiting on a channel (#3481)
Adds -chan option to the goroutines command to list only the goroutines
running on a specified channel.
Also when printing a variable if it is a channel also print the list of
goroutines that are waiting on it.
2023-08-23 13:02:34 -07:00
Alessandro Arzilli
80e6c28ab2
proc: disable "wait-for" tests on freebsd (#3482)
They are flaky in CI, I can not reproduce the problem locally.
2023-08-23 12:57:34 -07:00
Javier Honduvilla Coto
908876d6aa
DWARF CFI: use a stack for restore/remember opcodes (#3480)
Implementing the `DW_CFA_remember_state` and `DW_CFA_restore_state`
according to the DWARF specification requires us to create a stack that
can store an arbitrary number of elements, that is, there could be
multiple "pushes" before "popping" them.

From the 5th revision of the spec [0]:

> 6.4.2.4 Row State Instructions
> DW_CFA_remember_state
> 	The DW_CFA_remember_state instruction takes no operands. The required
>	action is to push the set of rules for every register onto an implicit stack.
>	DW_CFA_restore_state
> DW_CFA_restore_state
>	The DW_CFA_restore_state instruction takes no operands. The required action
>	is to pop the set of rules off the implicit stack and place them in the
>	current row.

- [0]: https://dwarfstd.org/doc/DWARF5.pdf

Signed-off-by: Francisco Javier Honduvilla Coto <javierhonduco@gmail.com>
2023-08-23 12:56:58 -07:00
Alessandro Arzilli
789f8b4054
proc: remove unused functions (#3479) 2023-08-23 09:49:54 -07:00
Derek Parker
5f01e72bb8
cmd/dlv: handle ctrl-c during tracing (#3477)
Ensure we send a Halt command to stop the process being traced so that
the deferred Detach can run ensuring proper cleanup upon exit.

Fixes #3228
2023-08-23 07:45:44 +02:00
Alessandro Arzilli
32b937c953
teamcity: misc changes to CI (#3476)
- add architecture rule for ppc64le so that incompatible agents don't
  pick up the build
- disable PIE tests on linux/ppc64le (the tests claim it doesn't work)
- enable PIE tests on darwin/amd64 now that the entry point calculation
  has been fixed
- remove dependency on wget and curl in the test script for linux to
  reduce test time
- only install git in the linux test script when we need it
- remove staticcheck from linux/ppc64le builds (it takes almost 5
  minutes between installation and execution and makes the test timeout
  sometimes)
- drop windows/arm64/tip build, the windows/arm64 build is broken
  anyway and since there is only one agent it makes CI runs slow
- drop linux/ppc64le/tip build, there is only one agent, it's slow and
  it will always timeout. CI runs in excess of 1h are too long.
2023-08-22 09:24:25 -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
Derek Parker
f0b534ddcc
pkg/proc: add support for more types in ebpf tracing backend (#3474) 2023-08-18 19:56:44 +02:00
Oleksandr Redko
8aa0050158
pkg,service: make receiver names consistent (#3473) 2023-08-17 14:24:43 -07:00
Alessandro Arzilli
53688a102f
goversion: parse new version format and simplify version representation (#3470)
Add parsing for the new version format with toolchain (X.Y.Z-something)
and simplify internal representation of versions so that revision, beta
version and rc version are all represented on a single field with rc
and beta versions being negative numbers (this limits rc versions to a
maximum of 1000 which will not be a problem in practice).
2023-08-16 09:55:02 -07:00
Ccheers
b07ef66fe4
Update target.go (#3471)
fix(proc): fix nil pointer panic
2023-08-16 15:17:03 +02:00
Derek Parker
1ec7320b1c
*: remove deepsource.toml (#3468)
We don't use deepsource anymore so this is just leftover configuration.
2023-08-15 07:01:30 +02:00
Alessandro Arzilli
e56490e78f
gobuild: pass user specified -C argument first (#3456)
The -C argument must come first on the command line of 'go build' if
the flags specified by the user via  build-flags start with -C pass it
first.

Replaces #3380
2023-08-14 15:37:57 -07:00
Alessandro Arzilli
4ce596b9dd
locspec: fix SubstitutePath when converting a Windows path to Linux (#3453)
Normalize separators when converting a Windows path into a Linux path.

Fixes #3447
2023-08-14 15:34:29 -07:00