From 4a3d408d18df344dd8e597b46f7ddb963a9d9ddf Mon Sep 17 00:00:00 2001 From: Heschi Kreinick Date: Thu, 16 Nov 2017 16:19:19 -0500 Subject: [PATCH] cmd/link: use . as DW_AT_comp_dir Go's DWARF usually has absolute paths, in which case DW_AT_comp_dir doesn't matter. But the -trimpath flag produces relative paths, and then the spec says that they are relative to _comp_dir. There's no way to know what the "right" value of _comp_dir is without more user input, but we can at least leave the paths alone rather than making them absolute. After this change, Delve can find sources to a program built with -gcflags=-trimpath=$(pwd) as long as it's run in the right directory. Change-Id: I8bc7bed098e352d2c06800bfbbe14e8392e1bbed Reviewed-on: https://go-review.googlesource.com/78415 Run-TryBot: Heschi Kreinick Reviewed-by: Russ Cox --- src/cmd/link/internal/ld/dwarf.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cmd/link/internal/ld/dwarf.go b/src/cmd/link/internal/ld/dwarf.go index 03facbcd58..d1ce921df1 100644 --- a/src/cmd/link/internal/ld/dwarf.go +++ b/src/cmd/link/internal/ld/dwarf.go @@ -1028,9 +1028,13 @@ func putpclcdelta(linkctxt *Link, ctxt dwarf.Context, s *sym.Symbol, deltaPC uin */ func getCompilationDir() string { - // OS X requires this, but it's really none of its business. - // Hard-code "/" for reproducible builds. - return "/" + // OSX requires this be set to something, but it's not easy to choose + // a value. Linking takes place in a temporary directory, so there's + // no point including it here. Paths in the file table are usually + // absolute, in which case debuggers will ignore this value. -trimpath + // produces relative paths, but we don't know where they start, so + // all we can do here is try not to make things worse. + return "." } func importInfoSymbol(ctxt *Link, dsym *sym.Symbol) {