Commit Graph

26 Commits

Author SHA1 Message Date
Alessandro Arzilli
2bd38fff90
dwarf/line: ignore end_of_sequence entry if AllPCsBetween (#2180)
* dwarf/line: ignore end_of_sequence entry if AllPCsBetween

Go 1.15 (but possibly prior versions of Go too) has a tendency to use
an address in the middle of an instruction for this entry, but if it
was correct it would be after the last instruction of the function
anyway.

This problem manifests especially frequently as a target crash in
TestStepConcurrentPtr on linux/arm64 (~6% of the runs).

* Travis-CI: add ignorechecksum option to chocolatey command

Looks like a configuration problem on chocolatey's end.

Co-authored-by: a <a@kra>
2020-09-24 08:03:46 -07:00
Alessandro Arzilli
4e83473154
dwarf/line: support DWARF version 5 (#2090)
DWARFv5 has a new format for the header, directory table and line table
of the debug_line section.
2020-07-21 13:39:09 -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
chainhelen
f3a191cd73
pkg/proc,service: support linux/386 (#1884)
Implement debugging function for 386 on linux with reference to AMD64.
There are a few remaining problems that need to be solved in another time.

1. The stacktrace of cgo are not exactly as expected.
2. Not implement `core` for now.
3. Not implement `call` for now. Can't not find `runtime·debugCallV1` or
   similar function in $GOROOT/src/runtime/asm_386.s.

Update #20
2020-03-10 09:34:40 -07:00
aarzilli
a8606afb0b proc,service: return build informations for each package
Adds an API call that returns a list of packages contained in the
program and the files that were used to build them, and also a best
guess at which filesystem directory contained the package when it was
built.

This can be used by IDEs to map file paths if the debugging environment
doesn't match the build environment exactly.
2020-01-09 20:19:02 +01:00
aarzilli
0e0d689246 dwarf/line: make LineToPCIn behave like LineToPC for lines without stmt
When a line has instructions associated but none of them have is_stmt
set LineToPC and LineToPCIn should behave in the same way.

Fixes #1817
2020-01-09 09:41:44 -08:00
Alessandro Arzilli
222deeec36 proc,debugger: implement logical breakpoints (#1717)
Modifies FindFileLocation, FindFunctionLocation and LineToPC as well as
service/debugger to support inlining and introduces the concept of
logical breakpoints.

For inlined functions FindFileLocation, FindFunctionLocation and
LineToPC will now return one PC address for each inlining and one PC
for the concrete implementation of the function (if present).

A proc.Breakpoint will continue to represent a physical breakpoint, at
a single memory location.

Breakpoints returned by service/debugger, however, will represent
logical breakpoints and may be associated with multiple memory
locations and, therefore, multiple proc.Breakpoints.

The necessary logic is introduced in service/debugger so that a change
to a logical breakpoint will be mirrored to all its physical
breakpoints and physical breakpoints are aggregated into a single
logical breakpoint when returned.
2019-11-01 12:41:06 -07:00
Alessandro Arzilli
45fb477379 proc: better handling of bad DW_TAG_inlined_subroutine without debug_line (#1722)
Avoid crashing with nil pointer dereference, signal error instead.

Fixes #1720
2019-10-21 10:43:03 -07:00
Alessandro Arzilli
fb3941324b dwarf/line: fix state machine behavior with multi-sequence units (#1681)
A compile unit can produce a debug_line program consisting of multiple
sequences according to the DWARF standard. The standard guarantees that
addresses monotonically increment within a single sequence but
different sequences may not follow this rule.

This commit changes dwarf/line (in particular PCToLine and
AllPCsBetween) to support debug_line sections containing units with
multiple sequences.

TestPCToLine needs to be changed so that it picks valid addresses (i.e.
addresses covered by a sequence) as values for basePC, instead of just
rounding.

Fixes #1694
2019-10-07 09:54:32 -07:00
Alessandro Arzilli
0c36cfb9b1 dwarf/line: implement missing DW_LNS_set_isa opcode (#1676) 2019-08-27 14:27:14 -07:00
David Chase
ecc62a0f3a dwarf/line: add some detail to unknown opcode messages (#1662) 2019-08-12 15:10:01 -07:00
David Chase
a25d2a2b24 proc: added *BinaryInfo.AllPCsForFileLine for faster bulk queries (#1592)
Support for bulk queries makes the DWARF quality checker
(github.com/dr2chase/dwarf-goodness/cmd/dwarf-goodness)
run much more efficiently (replace quadratic cost with
linear).
2019-06-27 19:39:15 -07:00
Derek Parker
4c9a72e486 *: Update import name to github.com/go-delve/delve
The repository is being switched from the personal account
github.com/derekparker/delve to the organization account
github.com/go-delve/delve. This patch updates imports and docs, while
preserving things which should not be changed such as my name in the
CHANGELOG and in TODO comments.
2019-01-04 19:43:13 +01:00
aarzilli
74c98bc961 proc: support position independent executables (PIE)
Support for position independent executables (PIE) on the native linux
backend, the gdbserver backend on linux and the core backend.
Also implemented in the windows native backend, but it can't be tested
because go doesn't support PIE on windows yet.
2018-10-11 11:21:27 -07:00
aarzilli
3f9875e272 dwarf/line: fix some bugs with the state machine
Adds a test that compares the output of our state machine with the
output of the debug_line reader in the standard library and checks that
they produce the same output for the debug_line section of grafana as
compiled on macOS (which is the most interesting case since it uses cgo
and therefore goes through dsymutil).

A few bugs were uncovered and fixed:

1. is_stmt was reset improperly after a DW_LNS_end_sequence instruction
2. basic_block, prologue_end and epilogue_begin were not reset after a
   DW_LNS_copy instruction
3. some opcodes were not decoded properly if the debug_line section
   declares fewer standard opcodes than we know about.

Fixes #1282
2018-07-31 12:01:14 -07:00
aarzilli
368cbeb0bc dwarf/line: remove foundFile "optimization" from LineToPC
There is no guarantee that files will end up stored contiguously in the
debug_line section which makes this optimization wrong in the general
case.
In particular with recent versions of go1.11 and a go.mod file present
the go compiler seems to sometimes produce executables that actually
violate this assumption.
2018-07-23 10:08:28 -07:00
Derek Parker
a208c89719 *: Use structured logging
Implements structured logging via Logrus. This gives us a logger per
boundry that we care about, allowing for easier parsing of logs if users
have more than one log option enabled. Also, cleans up a lot of
conditionals in the code by simply silencing the logger at creation as
opposed to conditionally logging everywhere.
2018-06-22 09:45:10 +02:00
aarzilli
5155ef047f proc,dwarf/line: support is_stmt and prologue_end flags
Go1.11 uses the is_stmt flag of .debug_line to communicate which
assembly instructions are good places for breakpoints, we should
respect this flag.

These changes were introduced by:
* https://go-review.googlesource.com/c/go/+/102435/

Additionally when setting next breakpoints ignore all PC addresses that
belong to the same line as the one currently under at the cursor. This
matches the behavior of gdb and avoids stopping multiple times at the
heading line of a for statement with go1.11.

Change: https://go-review.googlesource.com/c/go/+/110416 adds the
prologue_end flag to the .debug_line section to communicate the end of
the stack-split prologue. We should use it instead of pattern matching
the disassembly when available.

Fixes #550

type of interfaces
'c7cde8b'.
2018-06-11 11:09:02 -07:00
aarzilli
290e8e7528 proc: support inlining
Go 1.10 added inlined calls to debug_info, this commit adds support
for DW_TAG_inlined_call to delve, both for stack traces (where
inlined calls will appear as normal stack frames) and to correct
the behavior of next, step and stepout.

The calls to Next and Frame of stackIterator continue to work
unchanged and only return real stack frames, after reading each line
appendInlinedCalls is called to unpacked all the inlined calls that
involve the current PC.

The fake stack frames produced by appendInlinedCalls are
distinguished from real stack frames by having the Inlined attribute
set to true. Also their Current and Call locations are treated
differently. The Call location will be changed to represent the
position inside the inlined call, while the Current location will
always reference the real stack frame. This is done because:

* next, step and stepout need to access the debug_info entry of
the real function they are stepping through
* we are already manipulating Call in different ways while Current
is just what we read from the call stack

The strategy remains mostly the same, we disassemble the function
and we set a breakpoint on each instruction corresponding to a
different file:line. The function in question will be the one
corresponding to the first real (i.e. non-inlined) stack frame.

* If the current function contains inlined calls, 'next' will not
set any breakpoints on instructions that belong to inlined calls. We
do not do this for 'step'.

* If we are inside an inlined call that makes other inlined
functions, 'next' will not set any breakpoints that belong to
inlined calls that are children of the current inlined call.

* If the current function is inlined the breakpoint on the return
address won't be set, because inlined frames don't have a return
address.

* The code we use for stepout doesn't work at all if we are inside
an inlined call, instead we call 'next' but instruct it to remove
all PCs belonging to the current inlined call.
2018-03-26 14:30:38 -04:00
aarzilli
0fc4ed805b dwarf/line: fix output for the last line of a compile unit
The last entry of the debug_line table is supposed to be valid for
every PC address greater than its address.
2017-12-18 10:34:31 -08:00
aarzilli
b3246296d7 dwarf/line: handle DW_LNE_end_of_sequence correctly
We need to reset the current file and line number.

Fixes #1008
2017-12-08 02:16:26 -08:00
aarzilli
f098915192 proc/tests: testing apparatus for complex location expressions 2017-11-21 11:51:02 -08:00
aarzilli
ce83862d80 pkg/dwarf/line: support DW_LNE_define_file 2017-11-03 20:57:04 +01:00
aarzilli
73a39b985a pkg/dwarf/line: improve performance
1. Use a slice instead of a map to access standard and extended opcodes
   (reduces BenchmarkStateMachine from ~12ms/op to ~7ms/op)

2. Cache StateMachine values for the entry point of functions.
2017-11-03 20:57:04 +01:00
aarzilli
6d40517944 proc: replace all uses of gosymtab/gopclntab with uses of debug_line
gosymtab and gopclntab only contain informations about go code, linked
C code isn't there, we should use debug_line instead to also cover C.

Updates #935
2017-11-03 20:57:04 +01:00
Derek Parker
53f0d24057 Move top-level packages into pkg 2017-02-08 12:17:19 -08:00