Skip to content

Commit 4101e3a

Browse files
committed
pkg/cover: fix handling of compile unit name
The 'attrName' is often an absolute path for out-of-tree modules. This commit avoids redundant path concatenation when 'attrName' is already absolute, enabling developers to view coverage correctly in the web UI.
1 parent ed3e87f commit 4101e3a

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,4 @@ Rivos Inc.
140140
Alexandre Ghiti
141141
Jeongjun Park
142142
Nikita Zhandarovich
143+
Jiacheng Xu

pkg/cover/backend/dwarf.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,11 @@ func readTextRanges(debugInfo *dwarf.Data, module *vminfo.KernelModule, pcFix pc
407407
} else {
408408
// Compile unit names are relative to the compilation dir,
409409
// while per-line info isn't.
410-
// Let's stick to the common approach.
411-
unitName := filepath.Join(attrCompDir, attrName)
410+
// attrName could be an absolute path for out-of-tree modules.
411+
unitName := attrName
412+
if !filepath.IsAbs(attrName) {
413+
unitName = filepath.Join(attrCompDir, attrName)
414+
}
412415
ranges1, err := debugInfo.Ranges(ent)
413416
if err != nil {
414417
return nil, nil, err

0 commit comments

Comments
 (0)