diff --git a/builder/sizes.go b/builder/sizes.go index f7feeeda..fe912a1a 100644 --- a/builder/sizes.go +++ b/builder/sizes.go @@ -117,7 +117,7 @@ var ( // alloc: heap allocations during init interpretation // pack: data created when storing a constant in an interface for example // string: buffer behind strings - packageSymbolRegexp = regexp.MustCompile(`\$(alloc|embedfsslice|embedslice|pack|string)(\.[0-9]+)?$`) + packageSymbolRegexp = regexp.MustCompile(`\$(alloc|embedfsslice|pack|string)(\.[0-9]+)?$`) ) // readProgramSizeFromDWARF reads the source location for each line of code and diff --git a/compiler/compiler.go b/compiler/compiler.go index c02dcdc3..ecc00330 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -970,6 +970,19 @@ func (c *compilerContext) createEmbedGlobal(member *ssa.Global, global llvm.Valu global.SetInitializer(sliceObj) global.SetVisibility(llvm.HiddenVisibility) + if c.Debug { + // Add debug info to the slice backing array. + position := c.program.Fset.Position(member.Pos()) + diglobal := c.dibuilder.CreateGlobalVariableExpression(llvm.Metadata{}, llvm.DIGlobalVariableExpression{ + File: c.getDIFile(position.Filename), + Line: position.Line, + Type: c.getDIType(types.NewArray(types.Typ[types.Byte], int64(len(file.Data)))), + LocalToUnit: true, + Expr: c.dibuilder.CreateExpression(nil), + }) + bufferGlobal.AddMetadata(0, diglobal) + } + case *types.Struct: // Assume this is an embed.FS struct: // https://cs.opensource.google/go/go/+/refs/tags/go1.18.2:src/embed/embed.go;l=148