From 42759e7a9f4e6c45d2e043a404e444160e6cddba Mon Sep 17 00:00:00 2001 From: Ophestra Date: Fri, 14 Nov 2025 21:38:35 +0900 Subject: ldd: create musl entry representation This mostly helps with debugging. Signed-off-by: Ophestra --- ldd/ldd.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'ldd/ldd.go') diff --git a/ldd/ldd.go b/ldd/ldd.go index 7b88e698..9c892d7a 100644 --- a/ldd/ldd.go +++ b/ldd/ldd.go @@ -13,6 +13,7 @@ import ( "fmt" "io" "strconv" + "strings" "hakurei.app/container/check" ) @@ -117,6 +118,37 @@ func (e *Entry) UnmarshalText(data []byte) error { return e.decodeLocationSegment(segments[iL]) } +// String returns the musl ldd(1) representation of [Entry]. +func (e *Entry) String() string { + // nameInvalid is used for a zero-length e.Name + const nameInvalid = "invalid" + + var buf strings.Builder + + // libzstd.so.1 => /usr/lib/libzstd.so.1 (0x7ff71bfd2000) + l := len(e.Name) + 1 + if e.Name == "" { + l += len(nameInvalid) + } + if e.Path != nil { + l += len(entrySegmentFullSeparator) + 1 + len(e.Path.String()) + 1 + } + l += len(entrySegmentLocationPrefix) + 1<<4 + 1 + buf.Grow(l) + + if e.Name != "" { + buf.WriteString(e.Name + " ") + } else { + buf.WriteString(nameInvalid + " ") + } + if e.Path != nil { + buf.WriteString(entrySegmentFullSeparator + " " + e.Path.String() + " ") + } + buf.WriteString(entrySegmentLocationPrefix + strconv.FormatUint(e.Location, 16) + string(entrySegmentLocationSuffix)) + + return buf.String() +} + // Path returns a deduplicated slice of absolute directory paths in entries. func Path(entries []*Entry) []*check.Absolute { p := make([]*check.Absolute, 0, len(entries)*2) -- cgit v1.3.1