gocore: bugfix to Go 1.17 cores, Go 1.16 cores and Go 1.11+ cores

This CL fixes several bugs in `gocore`, the library that `viewcore` uses to
parse a core dump, as well as adds general updates for the more recent Go
versions.

First, we fix _func types for Go 1.16. In 1.16, the types of a few fields in
_func were changed. This commit makes the corresponding change to gocore. This
is the commit the changed the field types: CL 248332. Additionally, we
updated the func parsing to deal with the new split pclntab.

Previously, the code that deserialized the heapArena.bitmap field to
check whether addresses contained pointers or not was incorrect. It was
treating the entire bitmap as 1 bit per pointer.

However, that is not what the bitmap represents. Each byte in the bitmap
is actually split in half. The high bits contain the 4 scan bits. And
the low bits contain the 4 pointer bits.

See
https://github.com/golang/go/blob/3b304ce7fe35b9d1e8cf0b0518ed2550c361a010/src/runtime/mbitmap.go#L17-L35
for a more detailed description.

This commit corrects the issue and allows gocore to correctly traverse
the object graph.

Finally, for Go 1.17, we stop subtracting the heap unallocated space
represented by curArena from the total size of the heap. This reflects the
change that was made in CL 270537.

Also, a few incidental fixes:
- Stop thrashing the viewcore cache on the first command in interactive mode.
- Synthesize types for 0-size arrays in structs

Change-Id: Ia1636932d7c6c59bbd640f6b5b00b221369fed44
GitHub-Last-Rev: c66ea5a6d246f1f5f089a49824a91d34ebab5279
GitHub-Pull-Request: golang/debug#7
Reviewed-on: https://go-review.googlesource.com/c/debug/+/321736
Trust: Cherry Mui <cherryyz@google.com>
Trust: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
8 files changed
tree: 73a1eeecfdfbc47706d49f32313f715a02de297c
  1. cmd/
  2. dwtest/
  3. internal/
  4. AUTHORS
  5. codereview.cfg
  6. CONTRIBUTING.md
  7. CONTRIBUTORS
  8. go.mod
  9. go.sum
  10. LICENSE
  11. README.md
README.md

Go Debug

Go Reference

This repository holds utilities and libraries for debugging Go programs.

WARNING! Please expect breaking changes and unstable APIs. Most of them are currently are at an early, experimental stage.

Report Issues / Send Patches

This repository uses Gerrit for code changes. To learn how to submit changes to this repository, see https://golang.org/doc/contribute.html.

The main issue tracker for the debug repository is located at https://github.com/golang/go/issues. Prefix your issue with “x/debug:” in the subject line, so it is easy to find.