aboutsummaryrefslogtreecommitdiff
path: root/src/debug/dwarf
AgeCommit message (Collapse)Author
2017-08-18all: unindent some big chunks of codeDaniel Martí
Found with mvdan.cc/unindent. Prioritized the ones with the biggest wins for now. Change-Id: I2b032e45cdd559fc9ed5b1ee4c4de42c4c92e07b Reviewed-on: https://go-review.googlesource.com/56470 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-05-26debug/dwarf: heuristically handle both UNIX and Windows pathsAustin Clements
Currently debug/dwarf assumes all paths in line tables will be UNIX-style paths, which obviously isn't the case for binaries built on Windows. However, we can't simply switch from the path package to the filepath package because we don't know that we're running on the same host type that built the binary and we want this to work even if we're not. This is essentially the approach taken by GDB, which treats paths in accordance with the system GDB itself is compiled for. In fact, we can't even guess the compilation system from the type of the binary because it may have been cross-compiled. We fix this by heuristically determining whether paths are UNIX-style or DOS-style by looking for a drive letter or UNC path. If we see a DOS-style path, we use appropriate logic for determining whether the path is absolute and for joining two paths. This is helped by the fact that we should basically always be starting with an absolute path. However, it could mistake a relative UNIX-style path that begins with a directory like "C:" for an absolute DOS-style path. There doesn't seem to be any way around this. Fixes #19784. Change-Id: Ie13b546d2f1dcd8b02e668583a627b571b281588 Reviewed-on: https://go-review.googlesource.com/44017 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2016-04-15all: remove unnecessary type conversionsMatthew Dempsky
cmd and runtime were handled separately, and I'm intentionally skipped syscall. This is the rest of the standard library. CL generated mechanically with github.com/mdempsky/unconvert. Change-Id: I9e0eff886974dedc37adb93f602064b83e469122 Reviewed-on: https://go-review.googlesource.com/22104 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-03-22debug/dwarf: add Reader.SeekPC and Data.RangesIan Lance Taylor
These new methods help find the compilation unit to pass to the LineReader method in order to find the line information for a PC. The Ranges method also helps identify the specific function for a PC, needed to determine the function name. This uses the .debug.ranges section if necessary, and changes the object file format packages to pass in the section contents if available. Change-Id: I5ebc3d27faaf1a126ffb17a1e6027efdf64af836 Reviewed-on: https://go-review.googlesource.com/20769 Reviewed-by: Austin Clements <austin@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-03-02all: single space after period.Brad Fitzpatrick
The tree's pretty inconsistent about single space vs double space after a period in documentation. Make it consistently a single space, per earlier decisions. This means contributors won't be confused by misleading precedence. This CL doesn't use go/doc to parse. It only addresses // comments. It was generated with: $ perl -i -npe 's,^(\s*// .+[a-z]\.) +([A-Z]),$1 $2,' $(git grep -l -E '^\s*//(.+\.) +([A-Z])') $ go test go/doc -update Change-Id: Iccdb99c37c797ef1f804a94b22ba5ee4b500c4f7 Reviewed-on: https://go-review.googlesource.com/20022 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Dave Day <djd@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-03-01all: make copyright headers consistent with one space after periodBrad Fitzpatrick
This is a subset of https://golang.org/cl/20022 with only the copyright header lines, so the next CL will be smaller and more reviewable. Go policy has been single space after periods in comments for some time. The copyright header template at: https://golang.org/doc/contribute.html#copyright also uses a single space. Make them all consistent. Change-Id: Icc26c6b8495c3820da6b171ca96a74701b4a01b0 Reviewed-on: https://go-review.googlesource.com/20111 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-02-24all: fix typos and spellingMartin Möhrmann
Change-Id: Icd06d99c42b8299fd931c7da821e1f418684d913 Reviewed-on: https://go-review.googlesource.com/19829 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-01-14debug/dwarf: fix nil pointer dereference in cyclic type structuresAustin Clements
Currently readType simultaneously constructs a type graph and resolves the sizes of the types. However, these two operations are fundamentally at odds: the order we parse a cyclic structure in may be different than the order we need to resolve type sizes in. As a result, it's possible that when readType attempts to resolve the size of a typedef, it may dereference a nil Type field of another typedef retrieved from the type cache that's only partially constructed. To fix this, we delay resolving typedef sizes until the end of the readType recursion, when the full type graph is constructed. Fixes #13039. Change-Id: I9889af37fb3be5437995030fdd61e45871319d07 Reviewed-on: https://go-review.googlesource.com/18459 Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-09-15debug/dwarf: add test for split DWARFAustin Clements
This adds a test that debug/dwarf can read the skeleton DWARF data from a split DWARF image (though it doesn't currently support piecing the external DWARF data back together). This should work because there's nothing particularly different about skeleton DWARF data, but previously failed because of poor handling of unrecognized attributes. Updates #12592. Change-Id: I2fc5f4679883b05ebd7ec9f0b5c398a758181a32 Reviewed-on: https://go-review.googlesource.com/14542 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: jcd . <jcd@golang.org>
2015-09-15debug/dwarf: return ClassUnknown if attribute class cannot be determinedAustin Clements
Currently, if the .debug_abbrev section of an ELF file contains attributes that aren't known to the dwarf package and that have form formSecOffset, the dwarf package will fail to open the DWARF data with an error like "decoding dwarf section abbrev at offset 0x17: cannot determine class of unknown attribute with formSecOffset". For the most part, the class is implied by the form encoded in the abbrev section, but formSecOffset can imply many different DWARF classes. Hence, debug/dwarf disambiguates these using a table of known attributes. However, it will reject the entire image if it encounters an attribute it can't determine the class of. This is particularly unfortunate because the caller may never even uses the offending attribute. Fix this by introducing a ClassUnknown attribute class to use as a fallback in these cases. This allows the dwarf package to load the DWARF data and isolates the problem to just the affected attributes. Fixes #12592. Change-Id: I766227b136e9757f8b89c0b3ab8e9ddea899d94f Reviewed-on: https://go-review.googlesource.com/14541 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: jcd . <jcd@golang.org>
2015-09-04all: remove executable bit from several filesAndrew Gerrand
Change-Id: Iab669b2a9dd0510c0e54f9ec1cbe2b83b991bceb Reviewed-on: https://go-review.googlesource.com/14283 Reviewed-by: Minux Ma <minux@golang.org>
2015-06-11all: fix misprints in commentsAinar Garipov
These were found by grepping the comments from the go code and feeding the output to aspell. Change-Id: Id734d6c8d1938ec3c36bd94a4dbbad577e3ad395 Reviewed-on: https://go-review.googlesource.com/10941 Reviewed-by: Aamir Khan <syst3m.w0rm@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-05-07debug/dwarf: compute ByteSize for more DWARF typesJohn Dethridge
When AttrByteSize is not present for a type, we can still determine the size in two more cases: when the type is a Typedef referring to another type, and when the type is a pointer and we know the default address size. entry.go: return after setting an error if the offset is out of range. Change-Id: I63a922ca4e4ad2fc9e9be3e5b47f59fae7d0eb5c Reviewed-on: https://go-review.googlesource.com/9663 Reviewed-by: Austin Clements <austin@google.com>
2015-04-27debug/dwarf: update class_string.go to add ClassReferenceSig using stringer.John Dethridge
Change-Id: I677a5ee273a4d285a8adff71ffcfeac34afc887f Reviewed-on: https://go-review.googlesource.com/9235 Reviewed-by: Austin Clements <austin@google.com>
2015-04-12debug/dwarf: add Entry.AttrField method to get *Field by AttrAustin Clements
Currently, Entry has a Val method that looks up an attribute and returns its value. Now that Field has more fields than the attribute and its value, it's useful to return the whole Field and let the caller retrieve the parts it needs. This change adds an AttrField method to Entry that does the same lookup at Val, but returns the whole *Field rather than just the value. Change-Id: Ic629744c14c0e09d7528fa1026b0e1857789948c Reviewed-on: https://go-review.googlesource.com/8503 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-12debug/dwarf: add DWARF attribute value class to FieldAustin Clements
To return DWARF attribute values, debug/dwarf maps the DWARF attribute value classes to Go types. Unfortunately, this mapping is ambiguous in a way that makes it impossible to correctly interpret some DWARF attributes as of DWARF 4. For example, AttrStartScope can be either a constant or a rangelistptr. The attribute is interpreted differently depending on its class, but debug/dwarf maps both classes to int64, so the caller can't distinguish them from the Go type. AttrDataMemberLocation is similar. To address this, this change adds a field to type Field that indicates the exact DWARF attribute value class of that field's value. This makes it possible to distinguish value classes that can't be distinguished by their Go type alone. The root of this type ambiguity was DWARF itself. For example, DWARF 2 made no distinction between constants that were just constants and constants that were section offsets because no attribute could have both meanings. Hence, the single int64 type was sufficient. To avoid introducing just another layer of ambiguity, this change takes pains to canonicalize ambiguous classes in DWARF 2 and 3 files into the unambiguous classes of DWARF 4. Of course, there's no guarantee that future DWARF versions won't do the same thing again and further subdivide the DWARF 4 classes. This change gets ahead of this somewhat by distinguishing the various *ptr classes even though the encoding does not. If there's some other form of split, we can handle this in a backwards-compatible way by introducing, for example, a Class5 field and type. Change-Id: I4ef96d1223b0fd7f96ecf44fcc0e704a36af02b4 Reviewed-on: https://go-review.googlesource.com/8502 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-10debug/dwarf: document DWARF class -> Go type mappingAustin Clements
Currently, the only way to know the Go type of an attribute of some DWARF attribute class was to read the dwarf package code (or experiment). This makes it hard to go from the DWARF specification to writing code that uses the dwarf package. Fix this by adding a table to the documentation comment of the Field type that gives the correspondence between DWARF attribute classes and Go types. Change-Id: I57c678a551fa1eb46f8207085d5a53d44985e3e7 Reviewed-on: https://go-review.googlesource.com/7280 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-03-24debug/dwarf, encoding/asn1, go/ast: fix old commentsMatthew Dempsky
The debug/dwarf and encoding/asn1 examples were added in 2009, a few months before Go added implicit semicolons, and never updated. The go/ast node types have always been named just "Expr", "Stmt", and "Decl", so the comments about "ExprNode", "StmtNode", and "DeclNode" were likely just mistaken because the interface tag methods are "exprNode", "stmtNode", and "declNode", respectively. Change-Id: I9d138cc3a16c1a51453da1406914d7b320bf6270 Reviewed-on: https://go-review.googlesource.com/7980 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-03-11debug/dwarf: factor parsing of unit lengthsAustin Clements
Many headers in DWARF sections have a "unit length" that can be either 4 bytes or 12 bytes and indicates both the length of the unit and whether the unit is in 32-bit or 64-bit format. Currently, we implement unit length parsing in four different places. Add a "unitLength" method to buf that parses a unit length and use it in these four places. Change-Id: I7950b91caaa92aa5e19aa63debc8ae46178ecc4d Reviewed-on: https://go-review.googlesource.com/7281 Reviewed-by: Nigel Tao <nigeltao@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-03-10debug/dwarf: add unit tests for line table readerAustin Clements
This adds simple ELF test binaries generated by gcc and clang and compares the line tables returned by the line table reader against tables based on the output of readelf. The binaries were generated with # gcc --version | head -n1 gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2 # gcc -g -o line-gcc.elf line*.c # clang --version | head -n1 Ubuntu clang version 3.4-1ubuntu3 (tags/RELEASE_34/final) (based on LLVM 3.4) # clang -g -o line-clang.elf line*.c Change-Id: Id210fdc1d007ac9719e8f5dc845f2b94eed12234 Reviewed-on: https://go-review.googlesource.com/7070 Reviewed-by: Nigel Tao <nigeltao@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2015-03-10debug/dwarf: add support for line tablesAustin Clements
This implements a LineReader for line tables that parallels the existing Reader for debug entries. This code is partly based on the debug subrepo's fork of dwarf, but it is a more complete (and, I believe, correct) implementation of the spec and exposes a more general API. While the debug subrepo's implementation exposed only a PC-to-line function, this version exposes the line table rows to the caller. This way the caller can make its own trade-offs when implementing PC-to-line (or line-to-PC), such as whether or not to build an index for fast lookup. Change-Id: Ie157bc817f55e940b6f2e1ae010c5a4e1f29c5c8 Reviewed-on: https://go-review.googlesource.com/6734 Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-03-10debug/dwarf: factor finding unit containing entry offsetAustin Clements
This factors out the code for finding which unit contains an offset in the "info" section. The new code also replaces linear search with a binary search. The line table reader will also need this functionality. Change-Id: I2076e4fc6719b6f06fd2796cbbc7548ec1876cb3 Reviewed-on: https://go-review.googlesource.com/6733 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2014-09-24debug/dwarf: correct name for clang-generated complex typeRuss Cox
Fixes #8694. LGTM=iant R=iant CC=golang-codereviews https://golang.org/cl/143570043
2014-09-08build: move package sources from src/pkg to srcRuss Cox
Preparation was in CL 134570043. This CL contains only the effect of 'hg mv src/pkg/* src'. For more about the move, see golang.org/s/go14nopkg.