aboutsummaryrefslogtreecommitdiff
path: root/src/debug/dwarf
AgeCommit message (Collapse)Author
2022-11-05all: fix comment typosDan Kortschak
Change-Id: Ic16824482142d4de4d0b949459e36505ee944ff7 Reviewed-on: https://go-review.googlesource.com/c/go/+/448175 Reviewed-by: Robert Griesemer <gri@google.com> Run-TryBot: Dan Kortschak <dan@kortschak.io> Auto-Submit: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Dan Kortschak <dan@kortschak.io> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-10-13debug: add top level security docs for dwarf, elf, macho, pe, and plan9objRoland Shoemaker
Adds a package level doc comment to the debug/dwarf, debug/elf, debug/macho, debug/pe, and debug/plan9obj noting that these packages are not designed to be hardened against adversarial inputs. Change-Id: I678d01bcdc8ad01c23805f09cc59e64cec6c3f76 Reviewed-on: https://go-review.googlesource.com/c/go/+/435417 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Julie Qiu <julieqiu@google.com> Run-TryBot: Roland Shoemaker <roland@golang.org> Auto-Submit: Roland Shoemaker <roland@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-01debug/dwarf: don't crash on negative range/rnglist offsetIan Lance Taylor
No test case because the problem can only happen for invalid data. Let the fuzzer find cases like this. Fixes #55948 Change-Id: I7ba40ba928d2a14d4ac5b39f966173f3868d4729 Reviewed-on: https://go-review.googlesource.com/c/go/+/436876 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Than McIntosh <thanm@google.com>
2022-09-27debug/dwarf: don't crash on invalid range/rnglist offsetIan Lance Taylor
No test case because the problem can only happen for invalid data. Let the fuzzer find cases like this. Fixes #53529 Change-Id: I318c87795e545fe5a006d16b4d361cd4bf5d502d Reviewed-on: https://go-review.googlesource.com/c/go/+/434936 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
2022-06-23debug/dwarf: handle malformed line table with bad program offsetThan McIntosh
Touch up the line table reader to ensure that it can detect and reject an invalid program offset field in the table header. Fixes #53329. Change-Id: Ia8d684e909af3aca3014b4a3d0dfd431e3f5a9f0 Reviewed-on: https://go-review.googlesource.com/c/go/+/413814 Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-05-19all: gofmt main repoRuss Cox
Excluding vendor and testdata. CL 384268 already reformatted most, but these slipped past. The struct in the doc comment in debug/dwarf/type.go was fixed up by hand to indent the first and last lines as well. For #51082. Change-Id: Iad020f83aafd671ff58238fe491907e85923d0c7 Reviewed-on: https://go-review.googlesource.com/c/go/+/407137 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-04-14debug/dwarf: better stmt list attr checking in LineReaderThan McIntosh
Check for insane statement list attribute values when constructing LineReader's for a compilation unit. Fixes #52354. Change-Id: Icb5298db31f6c5fe34c44e0ed4fe277a7cd676b9 Reviewed-on: https://go-review.googlesource.com/c/go/+/400255 Run-TryBot: Than McIntosh <thanm@google.com> Auto-Submit: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-04-11all: gofmt main repoRuss Cox
[This CL is part of a sequence implementing the proposal #51082. The design doc is at https://go.dev/s/godocfmt-design.] Run the updated gofmt, which reformats doc comments, on the main repository. Vendored files are excluded. For #51082. Change-Id: I7332f099b60f716295fb34719c98c04eb1a85407 Reviewed-on: https://go-review.googlesource.com/c/go/+/384268 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-04-05all: replace `` and '' with “ (U+201C) and ” (U+201D) in doc commentsRuss Cox
go/doc in all its forms applies this replacement when rendering the comments. We are considering formatting doc comments, including doing this replacement as part of the formatting. Apply it to our source files ahead of time. For #51082. Change-Id: Ifcc1f5861abb57c5d14e7d8c2102dfb31b7a3a19 Reviewed-on: https://go-review.googlesource.com/c/go/+/384262 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-04-01all: remove trailing blank doc comment linesRuss Cox
A future change to gofmt will rewrite // Doc comment. // func f() to // Doc comment. func f() Apply that change preemptively to all doc comments. For #51082. Change-Id: I4023e16cfb0729b64a8590f071cd92f17343081d Reviewed-on: https://go-review.googlesource.com/c/go/+/384259 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-04-01debug/dwarf: better error handling in SeekPCThan McIntosh
The dwarf.Reader "SeekPC" method was not properly handling the case of a truncated/empty unit (something that has header information but an empty abbrev table and no DIEs). Add some guards to handle this case. Fixes #52045. Change-Id: I978163eca3b610f7528058693b840931e90d3f63 Reviewed-on: https://go-review.googlesource.com/c/go/+/397054 Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Than McIntosh <thanm@google.com> Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-21debug/dwarf: better error detection in parseUnitsThan McIntosh
Tweak the (*Data).parseUnits method to check a bit more carefully for buffer read errors, so as to avoid infinite looping on malformed inputs. Fixes #51758. Updates #47653. Change-Id: I6d67fcb53392acf651ceec636789ab9e49ad5a5c Reviewed-on: https://go-review.googlesource.com/c/go/+/393874 Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Than McIntosh <thanm@google.com> Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-06all: fix some typosDan Kortschak
Change-Id: I7dfae0fc91c2d70873ec7ec920be7c0a4888153a Reviewed-on: https://go-review.googlesource.com/c/go/+/390175 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Trust: Daniel Martí <mvdan@mvdan.cc>
2022-01-28debug/dwarf: fix problems with handling of bit offsets for bitfieldsThan McIntosh
This patch reworks the handling of the DWARF DW_AT_bit_offset and DW_AT_data_bit_offset attributes to resolve problems arising from a previous related change (CL 328709). In CL 328709 the DWARF type reader was updated to look for and use the DW_AT_data_bit_offset attribute for structure fields, handling the value of the attribute in the same way as for DW_AT_bit_offset. This caused problems for clients, since the two attributes have very different semantics. This CL effectively reverts CL 328709 and moves to a scheme in which we detect and report the two attributes separately/independently. This patch also corrects a problem in the DWARF type reader in the code that detects and fixes up the type of struct fields corresponding to zero-length arrays; the code in question was testing the DW_AT_bit_offset attribute value but assuming DW_AT_data_bit_offset semantics, meaning that it would fail to fix up cases such as typedef struct another_struct { unsigned short quix; int xyz[0]; unsigned x:1; long long array[40]; } t; The code in question has been changed to avoid using BitOffset and instead consider only ByteOffset and BitSize. Fixes #50685. Updates #46784. Change-Id: Ic15ce01c851af38ebd81af827973ec49badcab6f Reviewed-on: https://go-review.googlesource.com/c/go/+/380714 Trust: Than McIntosh <thanm@google.com> Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-12-13all: gofmt -w -r 'interface{} -> any' srcRuss Cox
And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-11-15debug/dwarf: better error message when reading absent debug_line_strAlessandro Arzilli
When a DW_FORM_line_strp is used without a debug_line_str section a good error message (about the missing section) is generated but immediately overwritten by the underflow error generated by trying to read the non-existent section. Updates #49590 Change-Id: I1c431392123a86c78c95ef1f185ebd6f17f2476a Reviewed-on: https://go-review.googlesource.com/c/go/+/363894 Run-TryBot: Alessandro Arzilli <alessandro.arzilli@gmail.com> Trust: David Chase <drchase@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
2021-09-02debug/dwarf: check for DWARFv4 AttrDataBitOffset valueJoe Sylve
AttrBitOffset is deprecated (but reserved) in DWARFv4. This fix adds logic to check the new AttrDataBitOffset attribute if AttrBitOffset attribute is not present. Fixes #46784 Change-Id: I7406dcaa4c98e95df72361fd4462c39e6be8879d GitHub-Last-Rev: 5aa10d04910a09538320b4de8fbd8a1f5fd8c17d GitHub-Pull-Request: golang/go#46790 Reviewed-on: https://go-review.googlesource.com/c/go/+/328709 Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Michael Knyszek <mknyszek@google.com>
2021-05-13debug/dwarf: delay array type fixup to handle type cyclesThan McIntosh
A user encountered a debug/dwarf crash when running the dwarf2json tool (https://github.com/volatilityfoundation/dwarf2json) on a debug-built copy of the linux kernel. In this crash, the DWARF type reader was trying to examine the contents of an array type while that array type was still in the process of being constructed (due to cycles in the type graph). To avoid such situations, this patch extends the mechanism introduced in https://go-review.googlesource.com/18459 (which handles typedef types) to delay fixup of array types as well. Change-Id: I303f6ce5db1ca4bd79da3581957dfc2bfc17cc01 Reviewed-on: https://go-review.googlesource.com/c/go/+/319329 Trust: Than McIntosh <thanm@google.com> Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Yi Chou <yich@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2021-04-23debug/dwarf: skip over zero-length compilation unitsRuss Cox
DWARF sections generated by mingw-clang seem to include these (not often - only one out of many in the binary that I am looking at). Skipping over them, everything parses correctly. This makes TestDefaultLinkerDWARF pass on windows/arm64. Change-Id: Ie4a7daa1423f51cbc8c4aac88b1d27c3b52ee880 Reviewed-on: https://go-review.googlesource.com/c/go/+/312031 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2021-03-17debug/dwarf: support DW_FORM_rnglistx aka formRnglistxIan Lance Taylor
Change-Id: I7df915978af3488f46a27595a1b04d0d33f81f7b Reviewed-on: https://go-review.googlesource.com/c/go/+/302369 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
2021-03-13all: remove duplicate wordsJohn Bampton
Change-Id: Ib0469232a2b69a869e58d5d24990ad74ac96ea56 GitHub-Last-Rev: eb38e049ee1e773392ff3747e1eb2af20dd50dcd GitHub-Pull-Request: golang/go#44805 Reviewed-on: https://go-review.googlesource.com/c/go/+/299109 Trust: Emmanuel Odeke <emmanuel@orijtech.com> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-12-14debug/dwarf: don't try to parse addr/rnglists headerIan Lance Taylor
In an executable, the debug_addr and debug_rnglists sections are assembled by concatenating the input sections, and each input section has a header, and each header may have different attributes. So just parsing the single header isn't right. Parsing the header is not necessary to handle offsets into these sections which is all we do. Looking at the header is also problematic because GCC with -gsplit-dwarf when using DWARF versions 2 through 4 emits a .debug_addr section, but it has no header. The header was only added for DWARF 5. So we can't parse the header at all for that case, and we can't even detect that case in general. This CL also fixes SeekPC with addrx and strx formats, by not using the wrong compilation unit to find the address or string base. To make that work when parsing the compilation unit itself, we add support for delay the resolution of those values until we know the base. New test binaries built with gcc -gdwarf-5 -no-pie debug/dwarf/testdata/line[12].c (gcc (Debian 10.2.0-15) 10.2.0) clang -gdwarf-5 -no-pie debug/dwarf/testdata/line[12].c (clang version 9.0.1-14) Change-Id: I66783e0eded629bf80c467767f781164d344a54d Reviewed-on: https://go-review.googlesource.com/c/go/+/277233 Trust: Ian Lance Taylor <iant@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
2020-12-09all: update to use os.ReadFile, os.WriteFile, os.CreateTemp, os.MkdirTempRuss Cox
As part of #42026, these helpers from io/ioutil were moved to os. (ioutil.TempFile and TempDir became os.CreateTemp and MkdirTemp.) Update the Go tree to use the preferred names. As usual, code compiled with the Go 1.4 bootstrap toolchain and code vendored from other sources is excluded. ReadDir changes are in a separate CL, because they are not a simple search and replace. For #42026. Change-Id: If318df0216d57e95ea0c4093b89f65e5b0ababb3 Reviewed-on: https://go-review.googlesource.com/c/go/+/266365 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-10-30cmd/link: emit include directories in DWARF line table prologueThan McIntosh
This patch changes the way the linker emits the DWARF line table prologue, specifically the file table. Previously files were left unmodified, and the directory table was empty. For each compilation unit we now scan the unit file table and build up a common set of directories, emit them into the directory table, and then emit file entries that refer to the dirs. This provides a modest binary size savings. For kubernetes kubelet: $ objdump -h /tmp/kubelet.old | fgrep debug_line 36 .zdebug_line 019a55f5 0000000000000000 0000000000000000 084a5123 2**0 $ objdump -h /tmp/kubelet.new | fgrep debug_line 36 .zdebug_line 01146fd2 0000000000000000 0000000000000000 084a510a 2**0 [where the value following the section name above is the section size in hex, so roughly a 30% decrease in this case.] The actual savings will depend on the length of the pathnames involved, so it's hard to really pin down how much savings we'll see here. In addition, emitting the files this way reduces the "compressibility" of the line table, so there could even be cases where we don't win at all. Updates #6853, #19784, #36495. Change-Id: I298d8561da5ed3ebc9d38aa772874851baa2f4f4 Reviewed-on: https://go-review.googlesource.com/c/go/+/263017 Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com> Trust: Than McIntosh <thanm@google.com>
2020-10-24debug/dwarf: add support for DWARFv5 to (*Data).RangesAlessandro Arzilli
Updates the (*Data).Ranges method to work with DWARFv5 which uses the new debug_rnglists section instead of debug_ranges. This does not include supporting DW_FORM_rnglistx. General support for DWARFv5 was added by CL 175138. Change-Id: I01f919a865616a3ff12f5bf649c2c9abf89fcf52 Reviewed-on: https://go-review.googlesource.com/c/go/+/236657 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Emmanuel Odeke <emm.odeke@gmail.com>
2020-09-21debug/dwarf: speed up SkipChildren for compilation unitsDmitry Vyukov
For a common pattern of iterating only over top-level compilation units (CU) Reader.SkipChildren has decode and meterialize all CU subentries just to skip them, because DW_TAG_compile_unit does not have DW_AT_sibling. However, CUs have total size encoded before the unit and we already parse them and know all unit sizes. Optimize Reader.SkipChildren to use that size when skipping CUs children. This speeds up iteration over a 1.3GB object file from 7.5s to 0.73s. Change-Id: I2a8f00955159b4bd13571409f4817805f934cb69 Reviewed-on: https://go-review.googlesource.com/c/go/+/256217 Run-TryBot: Dmitry Vyukov <dvyukov@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Than McIntosh <thanm@google.com>
2019-10-26debug/dwarf: call strings.EqualFold instead of calling Lower twiceVivek V
Change-Id: I8dcb425c37a067277549ba3bda6a21206459890a GitHub-Last-Rev: dc51b9b425ca51cd0a4ac494d4c7a3c0e2306951 GitHub-Pull-Request: golang/go#35132 Reviewed-on: https://go-review.googlesource.com/c/go/+/203097 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-09-20debug/dwarf: optimize buf.stringEmmanuel T Odeke
(*buf).string previously manually searched through its underlying byte slice until we encountered a '0'. This change instead uses bytes.IndexByte that results in a speed up: $ benchstat before.txt after.txt name old time/op new time/op delta BufString-8 257ns ± 1% 174ns ± 1% -32.37% (p=0.000 n=9+8) name old speed new speed delta BufString-8 495MB/s ± 1% 732MB/s ± 1% +47.76% (p=0.000 n=10+8) name old alloc/op new alloc/op delta BufString-8 162B ± 0% 162B ± 0% ~ (all equal) name old allocs/op new allocs/op delta BufString-8 3.00 ± 0% 3.00 ± 0% ~ (all equal) Change-Id: I7cf241742cc091d5d30d987a168b02d83955b1cf Reviewed-on: https://go-review.googlesource.com/c/go/+/196657 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2019-09-18debug/dwarf: expose file name table from line table readerAustin Clements
Currently, the line table reader keeps the file name table internal. However, there are various attributes like AttrDeclFile and AttrCallFile whose value is an index into this table. Hence, in order to interpret these attributes, we need access to the file name table. This CL adds a method to LineReader that exposes the file table of the current compilation unit in order to allow consumers to interpret attributes that index into this table. Change-Id: I6b64b815f23b3b0695036ddabe1a67c3954867dd Reviewed-on: https://go-review.googlesource.com/c/go/+/192699 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-09-18debug/dwarf: expose CU byte orderAustin Clements
Currently, dwarf.Reader exposes the current compilation unit's address size, but doesn't expose its byte order. Both are important for decoding many attributes. For example, location descriptions include addresses that are encoded in native form for the CU. This CL exposes the byte order of the compilation unit in the same way we already expose its address size, which makes it possible to decode attributes containing native addresses. Change-Id: I92f156818fe92b049d1dfc1613816bb1689cfadf Reviewed-on: https://go-review.googlesource.com/c/go/+/192698 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-09-09src: gofmt -sAinar Garipov
Change-Id: I56d7eeaf777ac30886ee77428ca1ac72b77fbf7d Reviewed-on: https://go-review.googlesource.com/c/go/+/193849 Run-TryBot: Dave Cheney <dave@cheney.net> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-09-03debug/dwarf: better handling for DW_FORM_indirectThan McIntosh
Fix a buglet in abbrev processing related to DW_FORM_indirect. When reading an abbrev entry if we encounter an attribute with form DW_FORM_indirect, leave the class as ClassUnknown, then when the abbrev is walked during the reading of the DIE fill in the class based on the value read at that point (code for handling DW_FORM_indirect seems to be already partially in place in the DIE reader). Updates #33488. Change-Id: I9dc89abf5cc8d7ea96824c0011bef979de0540bf Reviewed-on: https://go-review.googlesource.com/c/go/+/190158 Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
2019-09-03debug/dwarf, debug/elf: support DWARF 5Ian Lance Taylor
Change-Id: I6e9d47865c198299d497911c58235cd40f775e34 Reviewed-on: https://go-review.googlesource.com/c/go/+/175138 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
2019-09-03debug/dwarf: add new constants defined in DWARF 5Ian Lance Taylor
Also add a few other missing constants. Also rerun current version of stringer. Change-Id: I004ef27f6b40fe2cab64c52d169255dfea43fa01 Reviewed-on: https://go-review.googlesource.com/c/go/+/175137 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
2019-03-15debug/dwarf: more graceful handling of unsupported typesThan McIntosh
Enhance the type decoder to do a better job handling unknown type tags. DWARF has a number of type DIEs that this package doesn't handle (things like "pointer to member" types in C++); avoid crashing for such types, but instead return a placeholder "UnsupportedType" object (this idea suggested by Austin). This provides a compromise between implementing the entire kitchen sink and simply returning an error outright on any unknown type DIE. Fixes #29601. Change-Id: I2eeffa094c86ef3a2c358ee42e8e629d74cec2ed Reviewed-on: https://go-review.googlesource.com/c/go/+/158797 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-12-02all: use "reports whether" consistently instead of "returns whether"Tobias Klauser
Follow-up for CL 147037 and after Brad noticed the "returns whether" pattern during the review of CL 150621. Go documentation style for boolean funcs is to say: // Foo reports whether ... func Foo() bool (rather than "returns whether") Created with: $ perl -i -npe 's/returns whether/reports whether/' $(git grep -l "returns whether" | grep -v vendor) Change-Id: I15fe9ff99180ad97750cd05a10eceafdb12dc0b4 Reviewed-on: https://go-review.googlesource.com/c/150918 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-02-19all: add more uses of stringerDaniel Martí
By grepping for ]string{$, one can find many manual implementations of stringer. The debug/dwarf ones needed the new -trimprefix flag, too. html/template was fairly simple, just implementing the fallback as stringer would. The changes there are trivial. The ones in debug/dwarf needed a bit of extra logic since the GoString wants to use its own format, depending on whether or not the value is one of the known constants. Change-Id: I501ea7deaa538fa425c8e9c2bb895f480169273f Reviewed-on: https://go-review.googlesource.com/77253 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-02-15debug/dwarf: formStrp uses a 64-bit value for 64-bit DWARFIan Lance Taylor
No test as the only system I know that uses 64-bit DWARF is AIX. Change-Id: I24e225253075be188845656b6778993c2d24ebf5 Reviewed-on: https://go-review.googlesource.com/84379 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Austin Clements <austin@google.com>
2017-10-18debug/dwarf: clarify StructField.ByteSize docHeschi Kreinick
StructField.ByteSize is almost always unset; document that Type.Size() is the place to look. The dwarf package doesn't spend much effort teaching you DWARF, so I don't know what level of handholding is appropriate. Still, no harm in a little comment. Closes #21093 Change-Id: I0ed8cad2fa18e10a47d264ff16c176d603d6033c Reviewed-on: https://go-review.googlesource.com/71671 Run-TryBot: Heschi Kreinick <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2017-10-17debug/dwarf: support 64-bit DWARF in byte order checkIan Lance Taylor
Also fix 64-bit DWARF to read a 64-bit abbrev offset in the compilation unit. Change-Id: Idc22e59ffb354d58e9973b62fdbd342acf695859 Reviewed-on: https://go-review.googlesource.com/71171 Reviewed-by: Austin Clements <austin@google.com>
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>