Commit Graph

28 Commits

Author SHA1 Message Date
aarzilli
16d8bd647f proc/*: remove Process.Running
Implementing proc.Process.Running in a thread safe way is complicated
and nothing actually uses it besides tests, so we are better off
rewriting the tests without Running and removing it.

In particular:

* The call to d.target.Running() in service/debugger/debugger.go
  (Restart) can never return true because that line executes while
  holding processMutex and all continue operations are also executed
  while holding processMutex.
* The call to dbp.Running() pkg/proc/native/proc.go (Detach) can never
  return true, because it's only called from
  debugger.(*Debugger).detach() which is also always called while
  holding processMutex.

Since some tests are hard to write correctly without Process.Running a
simpler interface, Process.NotifyResumed, is introduced.

Fixes #830
2017-06-13 08:53:54 +02:00
aarzilli
40b482130a proc/variables: protect form invalid G struct in parseG
A waitreason string that has invalid length (because the G struct is
corrupted or being modified) could cause a crash.
2017-05-25 21:04:09 +02:00
Alessandro Arzilli
354055836a proc: next, stepout should work on recursive goroutines (#831)
Before this commit our temp breakpoints only checked that we would stay
on the same goroutine.
However this isn't enough for recursive functions we must check that we
stay on the same goroutine AND on the same stack frame (or, in the case
of the StepOut breakpoint, the previous stack frame).

This commit:
1. adds a new synthetic variable runtime.frameoff that returns the
   offset of the current frame from the base of the call stack.
   This is similar to runtime.curg
2. Changes the condition used for breakpoints on the lines of the
   current function to check that runtime.frameoff hasn't changed.
3. Changes the condition used for breakpoints on the return address to
   check that runtime.frameoff corresponds to the previous frame in the
   stack.
4. All other temporary breakpoints (the step-into breakpoints and defer
   breakpoints) remain unchanged.

Fixes #828
2017-05-16 11:23:33 -07:00
Alessandro Arzilli
8d3e74a445 proc/gdbserial: fix passing arguments to target via debugserver (#843)
Debugserver does not work as documented, "--" needs to be specified to
pass arguments to the target process (but only if it's an argument that
starts with a dash).

Fixes #839
2017-05-15 10:11:46 -07:00
Alessandro Arzilli
a843f7944e proc/gdbserial: mozilla rr support (#804)
Implements #727
2017-05-05 15:17:52 -07:00
Alessandro Arzilli
1f1535802e proc/native: Detach should use Kill with child processes we want killed (#822)
While implementing the gdbserial backend everything was changed to call
Detach to "close" a process so that gdbserial could do its clean up in
a single place. However the native implementation of Detach does not
actually kill processes we launched.

Fixes #821
2017-05-05 10:04:32 -07:00
Alessandro Arzilli
f29b9edad2 proc/gdbserial: pass environment variables to target (#820)
debugserver requires a special option to forward the environment to the target.

Fixes #818
2017-05-04 10:46:45 -07:00
Alessandro Arzilli
a731eb661f Minor post-refactoring cleanup (#808)
* proc/native: remove unused utility methods

* proc: turn FindFileLocation, FindFunctionLocation, FirstPCAfterPrologue methods into function
2017-04-28 10:15:39 -07:00
Alessandro Arzilli
d9bd90d7e4 Pull Request #731 but with tests (#802)
* proc/eval: fix length calculation for string concatenation

* proc/variable: find package variables when the package has a path
2017-04-25 10:42:41 -07:00
Nathan Bruer
43f26fb4d6 pkg/proc: Fixed delve's version extraction to allow propsals (#798)
Go recently introduced proposal tags to their version tags, we
are simply allowing delve to handle it appropriately.

See:
0954fdd51e
2017-04-21 17:45:20 -07:00
aarzilli
b6fe5aebaf proc: refactoring: merge target into proc
- moved target.Interface into proc as proc.Process
- rename proc.IThread to proc.Thread
- replaced interfaces DisassembleInfo, Continuable and
  EvalScopeConvertible with Process.
- removed superfluous Gdbserver prefix from types in the gdbserial
  backend.
- removed superfluous Core prefix from types in the core backend.
2017-04-21 14:00:04 -07:00
aarzilli
15bac71979 proc: refactoring: split backends to separate packages
- move native backend to pkg/proc/native
- move gdbserver backend to pkg/proc/gdbserial
- move core dumps backend to pkg/proc/core
2017-04-21 14:00:04 -07:00
aarzilli
182f805094 proc: Use MemoryReader inside memoryReadWriter 2017-04-18 13:25:11 -07:00
aarzilli
c8d9352522 proc: Implement target.Interface for gdbserver backend 2017-04-18 13:25:11 -07:00
aarzilli
3dacc25d2e proc: refactor Continue to work on any Process implementation 2017-04-18 13:25:11 -07:00
aarzilli
510b7db2a7 proc: introduce IThread interface to abstract threads 2017-04-18 13:25:11 -07:00
Alessandro Arzilli
b5a06f7aa8 proc refactoring: make stack, disassemble and eval independent of proc.Process (#786)
* proc: Refactor stackIterator to use memoryReadWriter and BinaryInfo

* proc: refactor EvalScope to use memoryReadWriter and BinaryInfo

* proc: refactor Disassemble to use memoryReadWriter and BinaryInfo
2017-04-13 16:19:57 -07:00
Alessandro Arzilli
436a3c2149 proc refactor: split out BinaryInfo implementation (#745)
* proc: refactor BinaryInfo part of proc.Process to own type

The data structures and associated code used by proc.Process
to implement target.BinaryInfo will also be useful to support a
backend for examining core dumps, split this part of proc.Process
to a different type.

* proc: compile support for all executable formats unconditionally

So far we only compiled in support for loading the executable format
supported by the host operating system.
Once support for core files is introduced it is however useful to
support loading in all executable formats, there is no reason why it
shouldn't be possible to examine a linux coredump on windows, or
viceversa.

* proc: bugfix: do not resume threads on detach if killing

* Replace BinaryInfo interface with BinInfo() method returning proc.BinaryInfo
2017-04-06 11:14:01 -07:00
Alessandro Arzilli
7b19fe9e69 proc: add test for attach/detach, fix detach (#773)
Detach did not work for processes we attach to via PID.

Linux: we were only detaching from the main thread, all threads are
detached independently

Windows: we must resume all threads before detaching.

macOS: still broken.

Updates #772
2017-03-28 09:30:27 -07:00
dr2chase
bd48358de3 pkg/proc: tolerate absence of stack barriers in Go 1.9 (#762)
Stack barriers were removed in Go 1.9, and thus code that
expected various stack-barrier-related symbols to exist
does not find them.  Check for their absence and do not
crash when they are missing.  Disable stack-barrier-handling
test for 1.9 and beyond.

Fixes #754.
2017-03-13 10:53:16 -07:00
Alessandro Arzilli
97e3fc261c proc/tests: make TestStacktraceGoroutine more reliable (#764)
One of those goroutines could also conceivably be stopped on line 8.
2017-03-13 10:45:53 -07:00
Alessandro Arzilli
cda7316421 proc/tests: use Detach(true) instead of Kill in tests (#765)
The rest of the code uses Detach to "close" a proc.Process, the tests
should do the same.
Any cleanup that proc.Process needs to do can then be put inside Detach
and the tests will run it.
2017-03-13 10:44:27 -07:00
aarzilli
f2581e608a proc/test: improve TestStepParked
It was possible for TestStepParked to pick a runtime goroutine and
attempt to step it. Nothing guarantees that a goroutine other than the
ones we are using to run the code would actually ever resume before the
end of the program.

This makes the test more discerning in its choice of goroutines.
2017-02-22 20:39:28 +01:00
aarzilli
92faa95bf9 proc/stack: use BP when FDE is not available
On Windows we can sometimes encounter threads stopped in locations for
which we do not have entries in debug_frame.
These cases seem to be due to calls to Windows API in the go runtime,
we can still produce a (partial) stack trace in this circumstance by
following frame pointers (starting with BP).
We still prefer debug_frame entries when available since go functions
do not have frame pointers before go1.8.
2017-02-22 20:39:28 +01:00
aarzilli
1a68f8d351 proc/windows: handle delayed events
Sometimes windows will send us events about breakpoints we have
already removed from the code despite the fact that we go to great
lengths to avoid this already.

Change waitForDebugEvent to check that when we receive a breakpoint
event the corresponding memory actually contains an INT 3
instruction, if it doesn't ignore the event and restart the thread.
2017-02-22 20:39:28 +01:00
Alessandro Arzilli
b9bdf597b0 proc_test: TestStacktraceWithBarriers failing on go1.8 (#735)
Changes to the GC in 1.8 make this test fail because the GC isn't
inserting stack barriers into our test program anymore. This isn't the
same thing as being unable to print stacktraces in presence of stack
barriers so the test shouldn't fail.
2017-02-21 10:38:13 -08:00
Alessandro Arzilli
fc0d40144a proc/variables: fix infinite recursion with pointer loop (#725)
loadValue didn't react correctly to pointer loops going through
slice -> interface{} -> slice or pointer -> interface{} -> pointer.
2017-02-09 16:26:38 -08:00
Derek Parker
53f0d24057 Move top-level packages into pkg 2017-02-08 12:17:19 -08:00