Commit Graph

119 Commits

Author SHA1 Message Date
Derek Parker
26ad5f1d82 Introduce target interface 2017-02-08 12:16:51 -08:00
Alessandro Arzilli
098457e59e Trace optimizations (#695)
* proc: Added trace benchmark

Results:

BenchmarkTrace-4   	    5000	  36195899 ns/op

* proc/linux: faster single step implementation.

BenchmarkTrace-4   	    5000	   2093271 ns/op

* proc: Cache function debug_info entries to speed up variable lookup.

BenchmarkTrace-4   	    5000	   1864846 ns/op

* proc/variables: Optimize FunctionArguments by prefetching frame

BenchmarkTrace-4   	    5000	   1815795 ns/op

* proc/variables: optimized parseG

BenchmarkTrace-4   	   10000	    712767 ns/op
2017-02-07 13:08:11 -08:00
Alessandro Arzilli
8724b3fce7 Go 1.8 compatibility (part 2) (#667)
* dwarf/line: bugfix: not all values of the state machine can be used

According to DWARF Version 3 Section 6.2 "Line Number Information" not
all the values transversed by the line numbers state machine are valid
instructions, only the ones after a "special opcode", after the
standard opcode DW_LNS_copy and the extended opcode
DW_LINE_end_sequence.

DWARF3 describes this by specifying that only the opcodes listed above
"append a row to the matrix".

Additionally the implementation of DW_LNS_const_add_pc was wrong.

Fixes #664

* dwarf/line: fixed test failing with go1.8

* service/test: fix prologue detection tests

The conditions about which function prologue is emitted by the compiler
changed in go1.8, changed the test program so that callme2 will still
have a prologue under go1.8.

* service/test: fix step test

compilation units are linked in a different order under go1.8 so the
code of 'fmt' is no longer located after 'main' in the executable,
changed the tests so that they don't rely on this assumption anymore.

* proc: change runtime.Breakpoint support for go1.8

Before 1.8 it was sufficient to step twice to exit a
runtime.Breakpoint(), but go 1.8 added frame pointer tracking to small
functions making runtime.Breakpoint longer.
This changes runtime.Breakpoint handling in Continue to single step as
many times as are needed to exit runtime.Breakpoint.

* proc/test: fix TestIssue561 for go1.8
2017-02-07 13:07:18 -08:00
Alessandro Arzilli
f4aaffbbf3 Two bugfixes regarding stale executable files, and executables changing between restarts (#689)
* service/debugger: Restore breakpoints using file:line on restart

Restoring by address can cause the breakpoint to be inserted in the
middle of an instruction if the executable file has changed.

* terminal: Warn of stale executable when printing source
2016-12-22 10:53:34 -06:00
aarzilli
8f0646e426 proc: load more registers
Adds ability to load x87, SSE and AVX registers.

Fixes #666
2016-12-19 21:29:45 +01:00
aarzilli
f62bf8d1e3 proc: Names of concrete types of interfaces parsing their runtime._type
Generate names of the concrete types stored inside interface variables
by fully parsing their runtime._type instead of simply using the str
field.

This allows delve to read the contents of an interface variable when
the program imports multiple packages that have the same name. It also
allows delve to correctly interpret some complex anonymous types.

Fixes #455
2016-10-27 09:56:15 +02:00
aarzilli
0f4b5150c3 proc, terminal: stepout command
Command to step out of the currently executing function.

Implements #358
2016-10-23 17:09:26 +02:00
aarzilli
9cbe768836 proc: Renamed temp breakpoints to internal breakpoints 2016-09-30 08:35:29 +02:00
aarzilli
7c49d4968d proc: Implement Step using Continue
Instead of repeatedly calling StepInstruction set breakpoints to the
destination of CALL instructions (or on the CALL instructions
themselves for indirect CALLs), then call Continue.
Calls to unexported runtime functions are skipped.
Reduces the number of code paths managing inferior state from 3 to 2
(StepInstruction, Continue).

Fixes #561
2016-09-27 09:37:33 +02:00
Alessandro Arzilli
e4c7df1469 Fix prologue detection on testvariables2.go's main.main (#625) 2016-09-06 10:27:07 -07:00
Alex Brainman
f09ef23f9e proc: implement attach on windows
Updates #363
2016-08-12 12:30:01 +10:00
dr2chase
218c2b953b proc: Fix stepping into runtime.duff* (#575)
Detect calls that do not target a function's entrypoint
(i.e, calls to runtime.duffzero and runtime.duffcopy) and
instead step into them directly.  StepInto sets a breakpoint
past the called function's prologue and expects that continue
will hit that breakpoint, but because the call is into the
interior of the function (well past the prologue) this fails.

Fixes #573
2016-07-21 13:10:35 -07:00
Alessandro Arzilli
372869c9e1 proc: Back to using vendored golang.org/x/debug/ (#585)
Patch https://go-review.googlesource.com/23085 has been merged so we
can go back to using golang.org/x/debug/.
2016-07-05 11:58:11 -07:00
aarzilli
51c39ed171 proc: detect when Launching non-executable files
This provides a better error message when the user tries to run dlv
debug on a directory that does not contain a main package, when `dlv
exec` is used with a source file.

Additionally the architecture of the executable is checked as suggested
by @alexbrainman in #443.

Fixes #509
2016-06-30 09:39:18 +02:00
aarzilli
9d70adf5c9 proc: Removed setChanRecvBreakpoints
This function was broken for a very long time until the changes in this
PR fixed it. However I do not think it is desirable to be catapulted
into some other goroutine by 'next' just because that other goroutine
happened to receive a message on a channel.

This feature should be implemented by a new command, not next.
2016-06-24 21:22:30 +02:00
aarzilli
80952e14d4 proc, terminal: step-instruction on parked goroutines 2016-06-24 21:22:30 +02:00
aarzilli
6faa78ff7c proc, terminal: step on parked goroutines
Previously Step would step through the goroutine associated with
CurrentThread if SelectedGoroutine was parked
2016-06-24 21:22:30 +02:00
aarzilli
d17c7c3a61 proc, terminal: next on parked goroutines
Previously Next would step through the goroutine associated with
CurrentThread if SelectedGoroutine was parked

Also fixes a bug with proc.(*Process).StepInto where StepInto could
switch to a different goroutine.
2016-06-24 21:22:30 +02:00
Alessandro Arzilli
7761faad5b terminal: show current thread of goroutines (#564) 2016-06-20 10:20:44 -07:00
Alessandro Arzilli
9bc6ad4f46 Go 1.7 compatibility (#524)
* tests: update to cope with go1.7 SSA compiler

* de-vendored golang.org/x/debug/dwarf

We need our own tweaked version

* dwarf/debug/dwarf: always use the entry's name attribute

Using the name attribute leads to better type names as well as fixes
inconsistencies between 1.5, 1.6 and 1.7.

* proc: Updated loadInterface to work with go1.7

go1.7 changed the internal representation of types, removing the string
field from runtime._type.
Updated loadInterface to use the new str field.
2016-05-29 12:20:09 -07:00
Alessandro Arzilli
c4e01da5ca terminal,service: auto-continue during next and step (#448)
* proc: bugfix: StepInto can not function when temp bps exist

* terminal,service: auto-continue during next and step

Make dlv call continue automatically when a breakpoint is hit on a
different goroutine during a next or step operation.
Added API hooks to implement the other solution to this problem (cancel
the next/step operation if a different breakpoint is hit).

Fixes #387
2016-04-24 16:20:02 -07:00
Alessandro Arzilli
473b66387c proc: Improvements to Variable printing (#444)
* service/api: Removed unused fields of service/api.Function

* proc/eval: Set return variable name to input expression

* all: fine-grained control of loadValue for better variable printing

Makes proc.(*Variable).loadValue loading parameters configurable
through one extra argument of type LoadConfig.
This interface is also exposed through the API so clients can control
how much of a variable delve should read.
2016-04-24 10:15:39 -07:00
aarzilli
497b526194 proc: stacktrace refactoring
- made GoroutineStacktrace a method of struct G
- made stacktrace a method of StackIterator
- renamed StackIterator to stackIterator
- factored out logic to obtain a stackIterator from a goroutine that's
used by both (*G).Stacktrace and by (*G).UserCurrent
2016-03-28 09:01:16 -07:00
Hubert Krauze
37f124817d dlv: Misc refactors 2016-03-17 15:32:30 -07:00
aarzilli
c4797ea445 proc: Breakpoint to catch unrecovered panics
Automatically sets a breakpoint on runtime.startpanic, the function
that gets called by runtime.dopanic when a panic is not recovered.

Implements #317
2016-03-09 14:15:30 +01:00
aarzilli
c66c6408a5 proc: Caching type offsets
Caches the mapping of type names to offset in debug_info to speed up
variable evaluation.

BEFORE:
	BenchmarkArray-4         	     100	  13'238'441 ns/op	   0.62 MB/s
	BenchmarkArrayPointer-4  	     200	  10'044'093 ns/op	   0.87 MB/s
	BenchmarkMap-4           	    1000	   1'332'530 ns/op	   0.77 MB/s
	BenchmarkGoroutinesInfo-4	      10	 114'677'462 ns/op
	BenchmarkLocalVariables-4	    2000	   1'223'975 ns/op
AFTER:
	BenchmarkArray-4         	     200	   9'925'686 ns/op	   0.83 MB/s
	BenchmarkArrayPointer-4  	     100	  11'143'930 ns/op	   0.78 MB/s
	BenchmarkMap-4           	    2000	   1'302'520 ns/op	   0.79 MB/s
	BenchmarkGoroutinesInfo-4	      30	  35'079'549 ns/op
	BenchmarkLocalVariables-4	    1000	   1'137'299 ns/op

Note in particular the speedup of BenchmarkGoroutinesInfo, since
proc.(*Variable).parseG is a function we call a lot.
2016-03-05 13:04:11 +01:00
aarzilli
49a0a121e0 tests: Add test for #149, fixed TestNextGeneral on tip
The go compiler changed and break statements no longer get compiled to
nothing when -N is passed:

https://go-review.googlesource.com/#/c/19848/
https://go-review.googlesource.com/#/c/19854/
2016-02-28 16:44:22 -08:00
aarzilli
c8f4cee97d New command 'types'
Lists all the types defined in the debugged program.
2016-02-27 15:39:11 -08:00
aarzilli
852f0c95b3 proc: Step should skip function prologue
Step disassembles the current instruction, if it is a CALL sets a
temp breakpoint inside the called function, after the prologue and
calls Continue.

Fixes #332
2016-02-18 09:15:37 -08:00
aarzilli
4116d66c8d proc: Replaced FunctionEntryToFirstLine with disassembly alternative
- Unlike FunctionEntryToFirstLine can skip the prologue on functions
that are defined on a single line, either because they weren't
formatted or because they were autogenerated
- Can skip the prologue on most functions when setting a breakpoint
with the filename:line syntax

Fixes #396
2016-02-18 09:11:34 -08:00
Luke Hoban
cf3a07b584 Fix path lookup logic on Windows.
Fixes #370.
2016-02-05 14:45:27 -08:00
aarzilli
3a8730de72 proc: Do not panic when a command is executed on an exited process
Fixes #355
2016-01-30 07:23:21 +01:00
Luke Hoban
d756eba13a [service/debugger] Case-insensitive paths on Windows
Fixes #370.
2016-01-26 18:50:53 -08:00
Derek Parker
39bc379dd2 proc: Fix step when on breakpoint
Fixes #361
2016-01-26 16:45:26 -08:00
Derek Parker
1bda586115 proc: step now goes to next line, including funcs
This patch modifies the `step` command to step to the next source line,
stepping into any function encountered along the way.

Fixes #360
2016-01-24 15:48:36 -08:00
aarzilli
54f1c9b3d4 proc: replace debug/dwarf with golang.org/x/debug/dwarf
Typedefs that resolve to slices are not recorded in DWARF as typedefs
but instead as structs in a way that there is no way to know they
are really slices using debug/dwarf.
Using golang.org/x/debug/dwarf instead this problem is solved and
as a bonus some types are printed with a nicer names: (struct string
→ string, struct []int → []int, etc)

 Fixes #356 and #293
2016-01-24 15:41:41 -08:00
aarzilli
91743d9472 go fmt 2016-01-24 17:30:23 +01:00
aarzilli
d9a31dd598 proc: implement conditional breakpoints
Backend only, no UI

Implements #120 (partial)
2016-01-24 08:32:28 +01:00
aarzilli
092571591f proc: added fake runtime.curg variable 2016-01-24 08:31:16 +01:00
Luke Hoban
bddb712a6b Add support for Windows.
Fixes #198.
2016-01-20 19:06:31 -08:00
Derek Parker
98ae684096 proc: Single step only "current" thread
Instead of the `step` command single stepping every thread, instead only
step the "current" thread. This fixes a few issues surrounding single
stepping, and simplifies the logic. The original concerns around only
stepping a single thread (with regard to coordination) are invalid and
generally non-issues.
2016-01-20 12:22:39 -08:00
aarzilli
70cbbdc083 service/locations: hooked expression evaluator to location specifiers
Location specifiers starting with '*' can be followed by any
expression supported by the evaluator.
The expression should evaluate to either an integer (which will be
interpreted as an address) or to a function pointer (which will be
dereferenced to get the function's entry point).
2016-01-17 21:45:28 -08:00
aarzilli
453bd0217f proc: bugfix: clearing temp breakpoints
Temp breakpoints should be cleared even if a non-temp breakpoint is
triggered on the same goroutine that the temp breakpoints are set on.

Fixes #305
2016-01-16 09:13:15 +01:00
Derek Parker
0188dc2c8b misc: cleanup and documentation 2016-01-10 02:10:51 -08:00
aarzilli
ab2b9ad1c6 proc: refactoring of Continue 2016-01-09 08:44:41 +01:00
aarzilli
5354e462e8 proc: bugfix: race condition between termination and Continue (linux)
resume loops in continueOnce moved to a OS specific resume function,
this makes the problem easier to deal with and seems to be more
appropriate to a windows port given what transpired from discussion
of Pull Request #276
2016-01-09 08:44:37 +01:00
aarzilli
2f9f20188a proc: bugfix: proc.Launch race (OS X) 2016-01-09 08:44:35 +01:00
aarzilli
5441135668 proc: Next implemented as conditional breakpoints + Continue
Next sets its temporary breakpoints with the condition that they
must only activate on the current goroutine, and then calls Continue
When Continue encounters a temporary breakpoint it clears all
the breakpoint.

User visible changes: breakpoints that get hit while executing Next
are not ignored.

This commit does not implement full conditional breakpoints
functionality, the only condition that can be set is on the
goroutine id.

Fixes race conditions in Next affecting TestNextConcurrent.
2016-01-09 08:44:32 +01:00
aarzilli
78c79927d6 proc: bugfix: [OS X] desync of mach message queue in Continue 2016-01-09 08:44:30 +01:00
aarzilli
a9e2696f46 proc: bugfix: proc.(*Process).Continue skips breakpoints
Breakpoints are skipped either because:
1. when multiple breakpoints are hit simultaneously only one is
processed
2. a thread hits a breakpoint while another thread is being
singlestepped over the breakpoint.

Additionally fixed a race condition between Continue and tracee
termination.
2016-01-09 08:28:36 +01:00