Commit Graph

108 Commits

Author SHA1 Message Date
Alessandro Arzilli
d97b471292
pkg/proc,service/debugger: do not disable unsatisfiable breakpoints (#3868)
Previously breakpoints with hitcount conditions that became
unsatisfiable
would become disabled, this was done as an optimization so that the
continue loop would no longer need to stop on them and evaluate their
conditions.
As a side effect this meant that on restart these breakpoints would
remain disabled, even though their hit condition returned satisfiable.

This commit changes Delve behavior so that breakpoints with
unsatisifiable hitcount conditions are no longer disabled but the
associated physical breakpoints are removed anyway, preserving the
optimization.

Some refactoring is done to the way conditions are represented and the
enable status is managed so that in the future it will be possible to
use hitcount conditions to implement "chained" breakpoints (also known
as dependet breakpoints), i.e. breakpoints that become active only
after a second breakpoint has been hit.
2024-12-04 19:07:56 -08:00
Oleksandr Redko
b4cfc8f6c7
tests: calling os.Exit in TestMain is not required (#3856) 2024-11-12 08:03:50 -08:00
Oleksandr Redko
a8293a36f5
all: fix typos in docs, comments and package name (#3757) 2024-06-25 15:16:58 +02:00
Derek Parker
6d3556784d
pkg/terminal: clear erroneous name setting on postfix if (#3702)
When a breakpoint was set on the current line via `break if i ==3` style
condition setting, we would erroneously set the breakpoint name to be
'if'.
2024-04-15 10:07:36 +02:00
Derek Parker
689c86355b
pkg/terminal: allow postfix if for breakpoint conds (#3693)
Allows for a user to specify the breakpoint condition directly
when creating the breakpoint. The new syntax looks like the
following:

```
break <name> <locspec> [if <expression>]
```

Also updates docs to include more examples and locspec description
instead of directing users to the online / source documentation.
2024-04-09 15:15:38 +02:00
Derek Parker
d688d4c83b
pkg/terminal: print breakpoint number on stop (#3675) 2024-02-28 15:49:33 +01:00
Alessandro Arzilli
57dad9342a
proc: make some type casts less counterintuitive
* proc: make some type casts less counterintuitive

The interaction of type casts with load configuration is sometimes
counterintuitive. This commit changes the way it is performed so that
when converting slices to strings and vice versa the maximum size
corresponding to the target type is used (i.e. MaxStringLen when
converting slices to strings and MaxArrayValues when converting slices
to strings).

This doesn't fully solve the problem (conversions to []rune are
problematic and multiple chained type casts will still be confusing)
but removes the problem for the majority of practical uses.

Fixes #3595, #3539
2023-12-12 11:43:41 -08:00
Alessandro Arzilli
650f2d5e23
terminal: clear substitute path rules cache when config is used (#3567)
Fixes #3565
2023-11-16 10:43:23 -08:00
Derek Parker
1e2338d233
proc: allow evaluator to reference previous frames (#3534)
Fixes #3515
2023-10-24 18:57:39 +02:00
Oleksandr Redko
899ba72505
all: replace deprecated io/ioutil with io and os (#3509) 2023-09-25 11:41:59 -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
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
Alessandro Arzilli
ca611db449
terminal: restore breakpoints set with line offset on restart (#3425)
Change FindLocation so it can return a substitute location expression
and propagate it to pkg/terminal/command.
When breakpoints are set using the syntax :<lineno> or +<lineno>
produce a substitute location expression that doesn't depend on having
a valid scope and can be used to restore the breakpoint.

Fixes #3423
2023-07-20 12:29:59 +02:00
Álex Sáez
71f1220717
*: add ppc64le support (#2963)
* Add vendor/golang.org/x/arch/ppc64

* Add ppc64le support
2023-07-07 09:30:38 -07:00
Oleksandr Redko
c5d9baaeb6
pkg/proc,pkg/terminal: close response body in tests (#3372) 2023-05-17 12:01:26 +02:00
Alessandro Arzilli
13ad7dc1d5
*: misc improvements to config command and substitute-path rules (#3335)
A series of interconnected changes to both the terminal command
'config', DAP command 'dlv config', quality of life improvements to how
substitute-path works, and better documentation.

- Let 'config substitute-path' show the current substitute path rules
- Add a -clear command to 'config substitute-path'
- Support 'config-debug-info-directories'
- rewrite SubstitutePath to be platform independent (see below)
- document path substitution more

Regarding the rewrite of SubstitutePath: the previous version used
runtime.GOOS and filepath.IsAbs to determine which filepath separator to use
and if matching should be case insensitive. This is wrong in all situations
where the client and server run on different OSes, when examining core files
and when cross-compilation is involved.

The new version of SubstitutePath checks the rules and the input path to
determine if Windows is involved in the process, if it looks like it is it
switches to case-insensitive matching. It uses a lax version of
filepath.IsAbs to determine if a path is absolute and tries to avoid having
to select a path separator as much as possible

Fixes #2891, #2890, #2889, #3179, #3332, #3343
2023-05-02 12:23:59 -07:00
Oleksandr Redko
7a05a4326f
proc,terminal: remove unused unexported functions (#3299) 2023-03-06 07:58:07 +01:00
Alessandro Arzilli
37e44bf603
proc,proc/native: adds ability to automatically debug child processes (#3165)
Adds the ability to automatically debug child processes executed by the
target to the linux native backend.
This commit does not contain user interface or API to access this
functionality.

Updates #2551
2023-02-22 09:26:28 -08:00
Alessandro Arzilli
00df758d57
proc/native: fix FreeBSD backend (#3224)
- use PT_SUSPEND/PT_RESUME to control running threads in
  resume/stop/singleStep
- change manual stop signal from SIGTRAP to SIGSTOP to make manual stop
  handling simpler
- change (*nativeProcess).trapWaitInternal to suspend newly created
  threads when we are stepping a thread
- change (*nativeProcess).trapWaitInternal to handle some unhandled
  stop events
- remove misleading (*nativeProcess).waitFast which does not do
  anything different from the normal wait variant
- rewrite (*nativeProcess).stop to only set breakpoints for threads of
  which we have received SIGTRAP
- rewrite (*nativeThread).singleStep to actually execute a single
  instruction and to properly route signals
2022-12-20 09:54:16 -08:00
Alessandro Arzilli
d15c86e0cf
proc: prefer addresses when setting a breakpoint (#3193)
If a breakpoint has both a list of addresses and an expression prefer
the list of addresses, otherwise it is impossible to set breakpoint
with expressions that depend on the current scope, like 'break +0'
which sets a breakpoint on the current line.
2022-11-16 09:31:33 -08:00
Alessandro Arzilli
cb91509630
terminal: send large output to pager (#3060)
For commands that could produce large amounts of output switch to a
pager command ($DELVE_PAGER, $PAGER or more) after a certain amount of
output is produced.

Fixes #919
2022-08-17 09:02:53 +02:00
Alessandro Arzilli
1fe03e728c
terminal: add ability to show disassembly instead of source (#3047)
Adds ability to show current position as disassembly instead of source
listing every time execution stops. Change default to show disassembly
after step-instruction and source listing in every other case.

Fixes #2878
2022-07-14 14:08:47 -07:00
roketyyang
278e4d10c8
terminal/command: add -per-g-hitcount option to condition command (#3055)
Support use per goroutine hitcount as hintcond operand.

Fixes #3050

Co-authored-by: roketyyang <roketyyang@tencent.com>
2022-07-12 10:31:34 +02:00
cui fliter
9a9c1a9f33
*: fix some typos
Signed-off-by: cuishuang <imcusg@gmail.com>
2022-03-23 16:10:00 +01:00
chainhelen
bb88e8b52e
pkg/terminal: add '-clear' option to 'condition' command (#2882)
This change adds the '-clear' to 'condition' which will clear
condtion on the breakpoint.

Co-authored-by: qianhailong <qianhailong@bytedance.com>
2022-02-15 18:41:23 +01:00
Alessandro Arzilli
5b925d4f5d
terminal: add transcript command (#2814)
Adds a transcript command that appends all command output to a file.
This command is equivalent to gdb's 'set logging'.

As part of this refactor the pkg/terminal commands to always write to a
io.Writer instead of using os.Stdout directly (through
fmt.Printf/fmt.Println).

Fixes #2237
2022-01-27 13:18:25 -08:00
Alessandro Arzilli
8ebd2d83ae
Misc fixes for test problems (#2751)
* service/dap: remove deadlock in TestLaunchDebugRequest

Fixes #2746

* terminal: fix TestScopePrefix flakiness

When there are more than 10 frames api.PrintStack will prefix the
output with spaces to right justify the frame number, which confuses
TestScopePrefix.

* _scripts: pass -buildvcs for Go 1.18 and later on TeamCity

Go 1.18 will try to stamp builds with the VCS version, this doesn't
work on TeamCity because the checkout isn't a valid repository (but
looks like it).
Pass -buildvcs=false to disable this feature.

* proc: switch to goroutine stack if first frame's func can not be found

If the first frame on the system stack can not be resolved to a
function switch directly to the goroutine stack.
2021-10-18 13:17:47 -07:00
Alessandro Arzilli
1893c9769b
Miscellaneous fixes for Windows native backend (#2736)
* proc/native: always stop after RequestManualStop on Windows

On Windows RequestManualStop will generate an exception on a special
DbgUiRemoteBreakin thread, sometimes this thread will die before we
finish stopping the process. We need to account for that and still stop
even if the thread is gone and no other thread hit a breakpoint.

Fixes flakiness of TestIssue419.

* proc/native: fix watchpoints with new threads on Windows

When a new thread is created we must reapply all watchpoints to it,
like we do on linux.

* tests: be lenient on goroutinestackprog tests on Windows

We can not guarantee that we find all goroutines stopped in a good
place and sometimes the stacktrace fails on Windows.
2021-10-13 08:43:54 -07:00
Derek Parker
43d50202f3
pkg/terminal: Allow fuzzy searching tab completions (#2633)
This patch implements fuzzy searching for tab completions in the
terminal client. Under the hood it is using a trie data structure
(https://en.wikipedia.org/wiki/Trie) to perform very fast prefix / fuzzy
searches.
2021-08-05 19:55:27 +02:00
Derek Parker
cb73ef8f83
pkg/terminal: Ignore existing breakpoints for continue until (#2624)
Ignore existing breakpoints when using the continue command to continue
to a specific location such as `continue main.main`. The point of this
command is to continue to a specific location, so if there is already a
breakpoint set there there should be no error returned, just continue
until we hit the breakpoint already set in that location.
2021-07-28 13:13:32 +02:00
Alessandro Arzilli
2ecc025311
terminal: add prompt when breakpoint is hit during next/step/stepout (#2548)
* terminal: add prompt when breakpoint is hit during next/step/stepout

Adds a prompt asking the user what to do when a breakpoint is hit on a
different goroutine while next/step/stepout is being executed.
Gives the user the opportunity to cancel next/step/stepout, continue
once skipping the breakpoint or automatically skipping all other
concurrent breakpoints until next/step/stepout is finished.

Fixes #2317
2021-07-26 08:57:09 -07:00
Alessandro Arzilli
8989073548
terminal: improve 'on' command (#2556)
* terminal: improve 'on' command

Adds the ability to edit the list of commands executed after stopping
on a breakpoint, as well as converting a breakpoint into a tracepoint
and vice versa.

Prior to this it was possible to add commands to a breakpoint but
removing commands or changing a breakpoint into a tracepoint, or vice
versa, could only be done by removing and recreating the breakpoint.
2021-07-22 10:16:42 -07:00
Alessandro Arzilli
29825d41a6
terminal,api: move PrintStack function (#2537)
Commit 30cdedae6910f5e9af6739845bacfd5b8778e745 introduced a dependency
from service/dap to pkg/terminal to call a stack printing function,
it's weird to have code that implements the DAP protocol depend on the
code for the JSON-RPC client.
Move PrintStack to a different package that can be called by both.
2021-06-16 13:05:17 -07:00
Alessandro Arzilli
d72b03b846
terminal: support setting hitcount conditions on breakpoints (#2518)
Adds a -hitcount argument to condition that sets a hitcount condition
on breakpoints.
2021-06-02 13:47:32 -07:00
Felix Geisendörfer
7bf5482b32
examinememory: evaluate addr as expression (#2385)
* examinememory: evaluate addr as expression

This makes it easy to read memory locations at an offset of a known
address, e.g.:

x 0xc000046800 + 32

* use feedback from @aarzilli

- expression mode is now enabled via -x flag
- support "-x var", "-x &var" in addition to "-x <addr expr>"
- some refactoring

* add test cases

* deal with double spaces

* update docs

* add new failing test

* fix docs

* simplify implementation, update test & docs

* Fix docs
2021-04-26 10:36:24 -07:00
Alessandro Arzilli
623667b0f4
*: Skipped tests review (#2430)
Delete tests for old versions of Go that are no longer run, remove skip
from tests that seemingly work.
2021-04-12 14:56:12 -07:00
Alessandro Arzilli
b120b11cc3
terminal: add optional format argument to print, display (#2398)
Changes print so a format argument can be specified by using '%' as
prefix. For example:

    print %x d

will print variable 'd' in hexadecimal. The interpretarion of the
format argument is the same as that of fmt's package.

Fixes #1038
Fixes #1800
Fixes #2159
2021-03-25 09:45:30 -07:00
Alessandro Arzilli
363086b7ed
terminal: fix TestContinueUntil on linux/386 (#2387) 2021-03-15 09:33:13 -07:00
Ilia Choly
d1834df3c5
terminal: Add [linespec] argument to 'continue' command (#2376)
This change allows specifying an optional linespec after the 'continue'
command which sets a temporary breakpoint.

Fixes #2373
2021-03-11 22:27:29 +01:00
polinasok
90fb0a535f
service/dap: support auto-loading of unloaded interfaces (#2362)
* service/dap: support auto-loading of unloaded interfaces

* Make DeepSource happy

* Don't set reference if data failed to auto-load

* Use frame-less expressions

* Refine interface recursion capping test case

Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-03-08 09:41:47 -08:00
aarzilli
db93049813 service,terminal: apply substitute path to trace/break argument
Change FindLocation to apply substitute path rules to location
expressions. Changes terminal to always print paths after applying
substitutions.

Implements #2203
2020-11-17 16:41:35 +01:00
polinasok
c94db60d27
service/dap: support evaluate requests with expressions and calls (#2185)
* Support evaluate request

* Fix failing tests

* Call support

* Remove debugger.CurrentThread() that got accidentally reintroduced during merge

* Address review comments

* Function to stringify stop reason

* Add resetHandlesForStop

* Handle stop inside call

* More tests

* Address review comments

* Check all threads to determine if call completed

* Fix test

* Fix test

* Fix test

* Address review comments

Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2020-11-12 15:24:31 -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
Polina Sokolova
42a4c80678 Remove redundant check in call tests 2020-11-03 11:59:16 +01:00
hitzhangjie
37d1e0100a
terminal: add -size argument to examinemem command
Adds a -size argument to examinemem that specifies how to group bytes on output.
2020-09-11 08:21:11 +02:00
aarzilli
7555d1c063 cmd,proc,terminal,debugger: Support default file descriptor redirects
Adds features to support default file descriptor redirects for the
target process:

1. A new command line flag '--redirect' and '-r' are added to specify
   file redirects for the target process
2. New syntax is added to the 'restart' command to specify file
   redirects.
3. Interactive instances will check if stdin/stdout and stderr are
   terminals and print a helpful error message if they aren't.
2020-09-01 21:50:27 +02:00
Alessandro Arzilli
0fa2ac5a9c
proc: set OnlyAddr on variables created by typecast to pointer (#2142)
If OnlyAddr is not set pretty printing an interface will fail with an
index out of bounds error.
2020-08-24 13:37:06 -07:00
Alessandro Arzilli
5461acf361
tests: relax tests that use goroutinestackprog (#2136)
Commit 1ee8d5c reviewed in Pull Request #1960 relaxed some tests using
goroutinestackprog but missed others.

Fixes some test flakiness that isn't relevant.
2020-08-17 17:17:39 -07:00
Alessandro Arzilli
01909d0f0b
terminal: print breakpoint info for tracepoints (#2121)
Print breakpoint info (requested print variables, stacktrace) when a
tracepoint is hit.

Fixes #2116
2020-08-05 09:38:53 -07:00