commit | 180a5d4e6e1521d466cad739007e9f00480188e3 | [log] [tgz] |
---|---|---|
author | Michael Pratt <mpratt@google.com> | Tue Jun 27 11:07:48 2023 -0400 |
committer | Michael Pratt <mpratt@google.com> | Fri Jun 30 18:45:26 2023 +0000 |
tree | 1bb37b02cd688ded28fc567e37bf2ff986ef9f8f | |
parent | 17953bea613c7852121bb3dc1cbb6579eceaece9 [diff] |
internal/core: refactor loading for maintainability Loading a new core.Process in core.Core is a rather long, complex process. Currently, this function creates a stub Process with very few fields set, and then subsequent method calls initially the remaining fields. The problem with this approach is that the inputs/requirements and outputs of these initialization methods is poorly documented. These methods (e.g., readCore) usually have some prerequisite fields in Process that must be set on entry, and some fields that they set prior to return. Neither of these are well documented, and many are far from obvious. For example, Process.mainExecName is initialized in readCore -> readNote -> readNTFile -> openMappedFile. This is made more of a mess by the fact that Process tries to do most initialization with a single pass, resulting in fields getting initialized in unintuitive locations (such as mainExecName). These combine to make refactoring to support new functionality difficult, as changing ordering breaks implicit dependencies between methods. This CL addresses these issues by eliminating the iterative initialization of Process. Instead, Process is only instantiated once all fields are ready. During loading, all work is done by free functions/types, where inputs and outputs are explicit via function arguments/returns. This may inadvertently improve golang/go#44757, as it makes main binary lookup more explicit. This CL intends to keep behavior the same, but there are a few changes: * If the entry point is unknown, We no longer apply the heuristic of assuming that first executable mapping is the main binary. This could be added back, but it is probably better to ensure that the entry point is available on all architectures. * Failure to ELF parse a file for symbols isn't a hard error (as the mapped file might not even be an ELF). For golang/go#57447. Change-Id: I7c3712ccb99ceddddc6adbae57d477c25ff4e5ba Reviewed-on: https://go-review.googlesource.com/c/debug/+/506558 Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
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.
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.