diff options
| author | Than McIntosh <thanm@golang.org> | 2025-03-07 14:16:28 -0500 |
|---|---|---|
| committer | Than McIntosh <thanm@golang.org> | 2025-03-10 09:05:58 -0700 |
| commit | e256e640604bff7916ef09451da7f4a6423152a6 (patch) | |
| tree | 28e3725997dfb1f8e9950805be882acd43bed9b7 /src/debug/dwarf/testdata | |
| parent | c3e7d5f5cee29669d5d824f697e3b16a08815df0 (diff) | |
| download | go-e256e640604bff7916ef09451da7f4a6423152a6.tar.xz | |
debug/dwarf: fix problem with DWARF 5 and Seek method
When clients use debug/dwarf to examine DWARF 5 binaries, we can run
into problems when the Seek() method is used to skip ahead from a DIE
in one compilation unit to a DIE in another unit. The problem here is
that it is common for DWARF 5 comp units to have attributes (ex:
DW_AT_addr_base) whose value must be applied as an offset when reading
certain forms (ex: DW_FORM_addrx) within that unit. The existing
implementation didn't have a good way to recover these attrs following
the Seek call, and had to essentially punt in this case, resulting in
incorrect attr values.
This patch adds new support for reading and caching the key comp unit
DIE attributes (DW_AT_addr_base, DW_AT_loclists_base, etc) prior to
visiting any of the DIE entries in a unit, storing the cache values of
these attrs the main table of units. This base attribute
reading/caching behavior also happens (where needed) after Seek calls.
Should resolve delve issue 3861.
Supercedes Go pull request 70400.
Updates #26379.
Fixes #57046.
Change-Id: I536a57e2ba4fc55132d91c7f36f67a91ac408dc3
Reviewed-on: https://go-review.googlesource.com/c/go/+/655976
Reviewed-by: Alessandro Arzilli <alessandro.arzilli@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/debug/dwarf/testdata')
| -rwxr-xr-x | src/debug/dwarf/testdata/issue57046-clang.elf5 | bin | 0 -> 19360 bytes | |||
| -rw-r--r-- | src/debug/dwarf/testdata/issue57046_part1.c | 42 | ||||
| -rw-r--r-- | src/debug/dwarf/testdata/issue57046_part2.c | 10 |
3 files changed, 52 insertions, 0 deletions
diff --git a/src/debug/dwarf/testdata/issue57046-clang.elf5 b/src/debug/dwarf/testdata/issue57046-clang.elf5 Binary files differnew file mode 100755 index 0000000000..009af83135 --- /dev/null +++ b/src/debug/dwarf/testdata/issue57046-clang.elf5 diff --git a/src/debug/dwarf/testdata/issue57046_part1.c b/src/debug/dwarf/testdata/issue57046_part1.c new file mode 100644 index 0000000000..8866ca66e1 --- /dev/null +++ b/src/debug/dwarf/testdata/issue57046_part1.c @@ -0,0 +1,42 @@ +// Copyright 2025 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Part 1 of the sources for issue 57046 test case. + +// Build instructions: +// +// clang-16 -O -g -gdwarf-5 -c issue57046_part1.c +// clang-16 -O -g -gdwarf-5 -c issue57046_part2.c +// clang-16 -o issue57046-clang.elf5 issue57046_part1.o issue57046_part2.o + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +extern const char *mom(); + +int gadgety() { + const char *ev = getenv("PATH"); + int n = strlen(ev); + int s1 = (int)ev[0]; + int s2 = (int)ev[1]; + int s3 = (int)ev[2]; + for (int i = 0; i < strlen(ev); i++) { + if (s1 == 101) { + int t = s1; + s1 = s3; + s3 = t; + } + if (ev[i] == 99) { + printf("%d\n", i); + } + } + s2 *= 2; + return n + s1 + s2; +} + +int main(int argc, char **argv) { + printf("Hi %s %d\n", mom(), gadgety()); + return 0; +} diff --git a/src/debug/dwarf/testdata/issue57046_part2.c b/src/debug/dwarf/testdata/issue57046_part2.c new file mode 100644 index 0000000000..2f4e9f0d24 --- /dev/null +++ b/src/debug/dwarf/testdata/issue57046_part2.c @@ -0,0 +1,10 @@ +// Copyright 2025 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Part 2 of the sources for issue 57046 test case. +// See part 1 for build instructions. + +const char *mom() { + return "mom"; +} |
