cmd/viewcore: fix commandPath recursion

commandPath recursively called itself with the same command when the
command had a parent. The recursion therefore never reached the root
command and eventually caused a stack overflow.

Recurse with c.Parent() so each call advances toward the root. Add
table-driven tests covering root, one-level, and two-level command paths.

Change-Id: I8d258a9f2d4d2c42c1cd66df0873fa99185a8aa9
Reviewed-on: https://go-review.googlesource.com/c/debug/+/811640
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Keith Randall <khr@golang.org>
2 files changed
tree: f2968397bce1ba628d3fb106cc58c3977c073aa9
  1. cmd/
  2. dwtest/
  3. internal/
  4. third_party/
  5. codereview.cfg
  6. CONTRIBUTING.md
  7. go.mod
  8. go.sum
  9. LICENSE
  10. 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 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://go.dev/doc/contribute.

The git repository is https://go.googlesource.com/debug.

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