Skip to content

Commit d87e3ce

Browse files
committed
compiler: add debug information to []embed.file slice global
1 parent 11a6c84 commit d87e3ce

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

builder/sizes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ var (
117117
// alloc: heap allocations during init interpretation
118118
// pack: data created when storing a constant in an interface for example
119119
// string: buffer behind strings
120-
packageSymbolRegexp = regexp.MustCompile(`\$(alloc|embedfsslice|pack|string)(\.[0-9]+)?$`)
120+
packageSymbolRegexp = regexp.MustCompile(`\$(alloc|pack|string)(\.[0-9]+)?$`)
121121
)
122122

123123
// readProgramSizeFromDWARF reads the source location for each line of code and

compiler/compiler.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,17 @@ func (c *compilerContext) createEmbedGlobal(member *ssa.Global, global llvm.Valu
10711071
sliceGlobal.SetGlobalConstant(true)
10721072
sliceGlobal.SetUnnamedAddr(true)
10731073
sliceGlobal.SetAlignment(c.targetData.ABITypeAlignment(sliceInitializer.Type()))
1074+
if c.Debug {
1075+
position := c.program.Fset.Position(member.Pos())
1076+
diglobal := c.dibuilder.CreateGlobalVariableExpression(llvm.Metadata{}, llvm.DIGlobalVariableExpression{
1077+
File: c.getDIFile(position.Filename),
1078+
Line: position.Line,
1079+
Type: c.getDIType(types.NewSlice(embedFileStructType)),
1080+
LocalToUnit: true,
1081+
Expr: c.dibuilder.CreateExpression(nil),
1082+
})
1083+
sliceGlobal.AddMetadata(0, diglobal)
1084+
}
10741085

10751086
// Define the embed.FS struct. It has only one field: the files (as a
10761087
// *[]embed.file).

0 commit comments

Comments
 (0)