Commit Graph

523 Commits

Author SHA1 Message Date
Alessandro Arzilli
9881edaa99
vendor: remove github.com/pkg/profile dependency (#2053)
It is only used in benchmarks and 'go test' now has command line
options to enable profiling as appropriate (but maybe it didn't in
2014).
2020-05-14 10:16:09 -07:00
chainhelen
e28e3d30d2
[WIP] pkg/proc: avoid target process leaks. (#2018)
* pkg/proc: avoid target process leaks.

Target process should exit when dlv launch failed.

Fix #2017.
2020-05-14 14:23:16 +02:00
Alessandro Arzilli
200994bc8f
proc/*: only load floating point registers when needed (#1981)
Changes implementations of proc.Registers interface and the
op.DwarfRegisters struct so that floating point registers can be loaded
only when they are needed.
Removes the floatingPoint parameter from proc.Thread.Registers.
This accomplishes three things:

1. it simplifies the proc.Thread.Registers interface
2. it makes it impossible to accidentally create a broken set of saved
   registers or of op.DwarfRegisters by accidentally calling
   Registers(false)
3. it improves general performance of Delve by avoiding to load
   floating point registers as much as possible

Floating point registers are loaded under two circumstances:

1. When the Slice method is called with floatingPoint == true
2. When the Copy method is called

Benchmark before:

BenchmarkConditionalBreakpoints-4   	       1	4327350142 ns/op

Benchmark after:

BenchmarkConditionalBreakpoints-4   	       1	3852642917 ns/op

Updates #1549
2020-05-13 11:56:50 -07:00
Derek Parker
f96663a243
cmd/dlv: Fix trace output (#2038)
* cmd/dlv,debugger: Improve dlv trace and trace command output

This patch improves the `dlv trace` subcommand output by reducing the
noise that is generated and providing clearer more concise information.

Also adds new tests closing a gap in our testing (we previously never
really tested this subcommand).

This patch also fixes the `dlv trace` REPL command to behave like the
subcommand in certain situations. If the tracepoint is for a function,
we now show function arguements and return values properly.

Also makes the overall output of the trace subcommand clearer.

Fixes #2027
2020-05-13 08:38:10 +02:00
Anders Kaare
71a460fc0f
config: add option for printfile() line count (#2043)
The option is "source-list-line-count". It defaults to 5, which was previously
hardcoded in printfile(), but now you can change it dynamically, for instance:

 $ config source-list-line-count 20
 $ list
2020-05-11 09:50:25 -07:00
Alessandro Arzilli
f559c3c421
gobuild: pass-through stdout to 'go' command invocation (#2044)
When trying to compile tests in a package that does not contain tests
'go' emits an error message on stdout instead of stderr. Let the 'go'
command write to stdout too.

Fixes #2042
2020-05-11 09:44:25 -07:00
chainhelen
5b7d764b15
gdbserial/gdbserver: optimize the search of debugserver binary (#2005)
Unexport `GetDebugServerAbsolutePath` and avoid unnecessary repeated calls.
Remove `os.Stat` because `Exec.LookPath` has already used `os.Stat`.And Fix
some comments.
2020-05-04 09:59:34 -07:00
colinnewell
99a0468b9b
cmd,Documentation: Add some simple examples for the list command to the help (#2034) 2020-05-04 09:27:55 -07:00
aarzilli
8f5df19948 proc: fix findCompileUnitForOffset when plugins are used
Splits the compileUnits slice between images so that we can search for
an offset inside the debug info of a specific image file.
2020-05-01 11:51:34 -07:00
aarzilli
96890bbe1e dwarf/op: return register values when they are the only piece
When there is a single piece and it's a register value just return it.
This is important for clang compiled programs which will use DW_OP_regN
to specify the value of the frame base.
2020-05-01 11:11:51 -07:00
aarzilli
c078223d56 proc: use cached packageVars in proc.(*EvalScope).PackageVariables 2020-05-01 11:01:35 -07:00
aarzilli
cf37512aed proc: move g.stackhi/g.stacklo to a struct
Mirroring the way this is implemented in the Go runtime and introducing
a type that will be useful to support the call injection changes in Go
1.15
2020-05-01 10:44:06 -07:00
aarzilli
bb2525a7d5 proc: keep debugger state consistent if callInjectionProtocol fails
pickCurrentThread should always run.
2020-05-01 10:15:29 -07:00
aarzilli
6102c31d6d terminal: clarify Ctrl-C options with multiclient servers
Fixes #2028
2020-04-27 09:15:44 -07:00
Min Zhou
3e04ad0fad proc: Find executable should follow symbol links.
On linux platform, we simply treated `/proc/$pid/exe` as the
executable of targeting process when doing `dlv attach`. The
`/proc/$pid/exe` is a symbol link of the real executable file.
Delve couldn't find the corrsponding external debug file based on the
symbol link:

```
could not attach to pid $pid: could not open debug info
```

The fix is to evaluate the symbol links to the actual executable path.
2020-04-27 09:14:58 -07:00
chainhelen
37bee98a88 pkg/config: add disassemble-flavor option for config
Allow user to specify output syntax flavor of assembly in the
disassemble command.

Close #415
2020-04-23 12:10:05 -07:00
aarzilli
9c24b56f62 proc/tests: disable TestIssue414 on linux/386/PIE
This test will occasionally hang in SetBreakpoint/WriteMemory
2020-04-20 11:08:28 -07:00
aarzilli
f9b6c43910 proc/native: report trapWaitInternal errors in nativeProcess.stop
The process could quit while we are inside stop, we should report the
error otherwise the following code will try to send on the closed
ptrace channel.
Fixes a sporadic error in TestIssue1101.
2020-04-17 09:22:18 -07:00
Alessandro Arzilli
bc299a7a30
tests: properly check if cgo is enabled for cgo related tests (#2010) 2020-04-16 10:42:22 -07:00
Derek Parker
e5d24a96bf *: Consolidate service/debugger config
Embed the debugger config object in the service config object to avoid needless duplication of fields.
2020-04-14 21:02:38 +02:00
chainhelen
ad9d13c671
proc: Don't set fileFound if there's a compileUnit without line section (#2006)
We should not return error directly which set `fileFound` to be true
if there's a compileUnit without line section.
2020-04-13 14:24:04 -07:00
aarzilli
c534677ece proc/native: disable async preemption on freebsd 2020-04-10 11:03:21 -07:00
aarzilli
ae846a51f2 proc: StepOut remove if condition that is always true 2020-04-10 10:49:19 -07:00
Derek Parker
3e60ae202b *: Add --tty flag for debug / exec
This flag allows users on UNIX systems to set the tty for the program
being debugged by Delve. This is useful for debugging command line
applications which need access to their own TTY, and also for
controlling the output of the debugged programs so that IDEs may open a
dedicated terminal to show the output for the process.
2020-04-10 09:53:13 -07:00
Alessandro Arzilli
c3a4d726e2
Miscellaneous debug_line improvements (#1999)
* dwarf/line: implement DW_LNE_set_discriminator

We don't use the discriminator field in any way but we need to at least
parse it to support debub_line programs that use it.

* dwarf/line: support parsing DWARF4 debug_line sections

There is an extra field maximum_operations_per_instruction that is used
for VLIW CPUs. We don't support this feature but we have to at least
parse the field to not crash.
2020-04-09 13:57:44 -07:00
Darren Rambaud
bc30b53926
gdbserial/gdbserver: Dynamically resolve debugserver binary (#1994)
* gdbserial/gdbserver: Dynamically resolve debugserver binary

Instead of hardcoding the absolute path to the Command Line
Tools (CLT) binary, will attempt to resolve the path at the
$PATH, or at the Xcode bundle. If none are available, will
fallback to the default CLT location.

Fixes #986

* gdbserial/gdbserver: Log outgoing executed commands

Add logging to capture the executable and associated arguments used
in LLDBLaunch and LLDBAttach

Related to #986

* gdbserial/gdbserver: Add unit tests for helper function

Define unit tests for helper function. Setup each test to temporarily make
PATH variable, and file system changes, and subsequently revert them.

Related to #986

* gdbserial/gdbserver: Lazily load function

Lazily obtain absolute path to avoid increasing load times.

Remove flaky tests.

Related to #986
2020-04-09 13:48:38 -07:00
aarzilli
7dedf1ed55 proc: simplify next/step/stepout condition code
Adds a library of utility functions to generated breakpoint conditions
for next, step and stepout.
2020-04-04 11:00:54 -07:00
Derek Parker
aa0b4eb180 *: Better error launching invalid binary format
Fixes #1310
2020-04-02 18:41:16 +02:00
aarzilli
3c8d4d52b8 *: un-export unnecessarily public symbols 2020-03-31 14:47:29 -07:00
aarzilli
1ee8d5c218 tests: relax TestStacktraceGoroutine with Go 1.14
The test was always flaky because we can't fully control the state of
all goroutines in the target program, Go 1.14's asynchronous preemption
exacerbates the problem.

See for example:
https://travis-ci.com/github/go-delve/delve/jobs/302407282

This commit relaxes the checks made by the test to avoid irrelevante
flakiness.
2020-03-31 10:43:10 -07:00
aarzilli
a61b6c0d7c proc: avoid constructing unnecessary strings when evaluating variables
Avoids constructing:

1. name of runtime.curg fields while executing parseG
2. the location expression while evaluating any variable.

Benchmark before:

BenchmarkConditionalBreakpoints-4   	       1	4953889884 ns/op

Benchmark after:

BenchmarkConditionalBreakpoints-4   	       1	4419775128 ns/op

Updates #1549
2020-03-31 10:29:26 -07:00
aarzilli
431dea7ee6 proc: skip autogenerated wrappers when stepping in and out
Under some circumstances (methods with non-pointer receivers or from
embedded fields called through an interface) the compiler will
autogenerate wrapper functions.

This commit changes next, step and stepout to skip all autogenerated
wrappers.

Fixes #1908
2020-03-31 10:04:36 -07:00
Alessandro Arzilli
223e0a57ca
proc: convert Arch into a struct (#1972)
Replace the interface type Arch with a struct with the same
functionality.
2020-03-30 11:03:29 -07:00
Derek Parker
85c34e47ee *: mv scripts _scripts
Instead of selectively excluding this directory, hide it from the go
tooling by applying the "_" prefix.
2020-03-28 20:28:51 +01:00
Derek Parker
5d109cb197 *: Add some more documentation to exported types and methods 2020-03-28 19:14:58 +01:00
Derek Parker
5177c247f6 pkg/proc: Remove unused parameter
Also cleanup some typos.
2020-03-28 16:32:09 +01:00
Derek Parker
4abf4f1c1f pkg/proc: Rename proc.go -> target_exec.go 2020-03-25 17:45:12 +01:00
Derek Parker
ccd438c65f pkg/proc: Move proc exec funcs to Target methods 2020-03-25 17:45:12 +01:00
Alessandro Arzilli
8bb93e9ae1
proc/gdbserial,debugger: allow clients to stop a recording (#1890)
Allows Delve clients to stop a recording midway by sending a
Command('halt')
request.

This is implemented by changing debugger.New to start recording the
process on a separate goroutine while holding the processMutex locked.
By locking the processMutex we ensure that almost all RPC requests will
block until the recording is done, since we can not respond correctly
to any of them.
API calls that do not require manipulating or examining the target
process, such as "IsMulticlient", "SetApiVersion" and
"GetState(nowait=true)" will work while we are recording the process.

Two other internal changes are made to the API: both GetState and
Restart become asynchronous requests, like Command. Restart because
this way it can be interrupted by a StopRecording request if the
rerecord option is passed.
GetState because clients need a call that will block until the
recording is compelted and can also be interrupted with a
StopRecording.

Clients that are uninterested in allowing the user to stop a recording
can ignore this change, since eventually they will make a request to
Delve that will block until the recording is completed.

Clients that wish to support this feature must:

1. call GetState(nowait=false) after connecting to Delve, before any
   call that would need to manipulate the target process
2. allow the user to send a StopRecording request during the initial
   GetState call
3. allow the user to send a StopRecording request during any subsequent
   Restart(rerecord=true) request (if supported).

Implements #1747
2020-03-24 09:09:28 -07:00
Derek Parker
475551cf3d pkg/proc: Reset time after continue in benchmarks
Reset the timer once we start executing the code paths we actually care
to measure, since the setup and continue steps can be relatively
expensive.

Also, disable recording on benchmarks. This seems less useful, and also
cuts out a lot of noise when benchmarks are run.
2020-03-24 09:48:34 +01:00
Derek Parker
c4fd80fcd0 pkg/proc: Clean up proc.go
This patch moves out unrelated types, variables and functions from
proc.go into a place where they make more sense.
2020-03-24 09:45:29 +01:00
Alessandro Arzilli
112049176f
proc: fix switch to goroutine stack (#1948)
When switching to the goroutine stack the stack iterator registers
might not have any entry for the BP register, make sure to add it
instead of just trying to change it.
2020-03-20 11:32:41 -07:00
Alessandro Arzilli
7cd12c34fd
proc,dwarf: cache debug.Entry objects (#1931)
Instead of rescanning debug_info every time we want to read a function
(either to find inlined calls or its variables) cache the tree of
dwarf.Entry that we would generate and use that.

Benchmark before:

BenchmarkConditionalBreakpoints-4   	       1	5164689165 ns/op

Benchmark after:

BenchmarkConditionalBreakpoints-4   	       1	4817425836 ns/op

Updates #1549
2020-03-20 10:23:10 -07:00
Derek Parker
3c683ae30f pkg/terminal: Use less permissive file permission on history file 2020-03-20 12:17:52 +01:00
Derek Parker
ad2563f008 pkg/terminal: Remove unused slice and append 2020-03-20 09:16:17 +01:00
Derek Parker
5a83bdd632 pkg/terminal: Use buffered channel for signal notify 2020-03-20 09:15:10 +01:00
Derek Parker
f05ce09473 *: Fix use of deprecated functionality 2020-03-20 09:05:14 +01:00
Alessandro Arzilli
0cfd52787f
proc/gdbserial: add logging when Thread.Location will fail (#1937)
Add logging for Issue #1927. The bug happens during the call to
api.ConvertThread, returning an error will not suffice since
ConvertThread will not surface it.

Updates #1927
2020-03-19 12:28:27 -07:00
Alessandro Arzilli
e1cfd72795
proc: fix bad cached goroutines after a call injection (#1926)
Inserts a call to ClearAllGCache into stepInstructionOut so that cached
goroutine state is not inconsistent after an injected function call.\

Fixes #1925
2020-03-19 12:27:31 -07:00
Alessandro Arzilli
c6de961be8
terminal: add display command (#1917)
Implements #1256
2020-03-19 11:58:40 -07:00