Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clone strings to free DWARF objects in dynamic instrumentation #34647

Merged
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions pkg/dynamicinstrumentation/diconfig/dwarf.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"io"
"reflect"
"slices"
"strings"

"github.com/go-delve/delve/pkg/dwarf/godwarf"

Expand Down Expand Up @@ -64,10 +65,11 @@ entryLoop:
}

if entry.Tag == dwarf.TagCompileUnit {
name, ok := entry.Val(dwarf.AttrName).(string)
_, ok := entry.Val(dwarf.AttrName).(string)
if !ok {
continue entryLoop
}
name = strings.Clone(entry.Val(dwarf.AttrName).(string))
ranges, err := dwarfData.Ranges(entry)
if err != nil {
log.Infof("couldnt retrieve ranges for compile unit %s: %s", name, err)
Expand All @@ -81,7 +83,15 @@ entryLoop:
}
var files []*dwarf.LineFile
if cuLineReader != nil {
files = cuLineReader.Files()
for _, file := range cuLineReader.Files() {
if file != nil {
files = append(files, &dwarf.LineFile{
Name: strings.Clone(file.Name),
Mtime: file.Mtime,
Length: file.Length,
})
}
}
}

for i := range ranges {
Expand All @@ -100,7 +110,7 @@ entryLoop:
)
for _, field := range entry.Field {
if field.Attr == dwarf.AttrName {
fn = field.Val.(string)
fn = strings.Clone(field.Val.(string))
}
if field.Attr == dwarf.AttrDeclFile {
fileNumber = field.Val.(int64)
Expand All @@ -124,7 +134,7 @@ entryLoop:

for _, field := range entry.Field {
if field.Attr == dwarf.AttrName {
funcName = field.Val.(string)
funcName = strings.Clone(field.Val.(string))
if !targetFunctions[funcName] {
continue entryLoop
}
Expand Down Expand Up @@ -153,7 +163,7 @@ entryLoop:

// ditypes.Parameter name
if entry.Field[i].Attr == dwarf.AttrName {
name = entry.Field[i].Val.(string)
name = strings.Clone(entry.Field[i].Val.(string))
}

if entry.Field[i].Attr == dwarf.AttrVarParam {
Expand Down Expand Up @@ -369,7 +379,7 @@ func getStructFields(offset dwarf.Offset, dwarfData *dwarf.Data, seenTypes map[s

// Struct Field Name
if fieldEntry.Field[i].Attr == dwarf.AttrName {
newStructField.Name = fieldEntry.Field[i].Val.(string)
newStructField.Name = strings.Clone(fieldEntry.Field[i].Val.(string))
}

// Struct Field Type
Expand Down Expand Up @@ -455,7 +465,7 @@ func getTypeEntryBasicInfo(typeEntry *dwarf.Entry) (typeName string, typeSize in
}
for i := range typeEntry.Field {
if typeEntry.Field[i].Attr == dwarf.AttrName {
typeName = typeEntry.Field[i].Val.(string)
typeName = strings.Clone(typeEntry.Field[i].Val.(string))
}
if typeEntry.Field[i].Attr == dwarf.AttrByteSize {
typeSize = typeEntry.Field[i].Val.(int64)
Expand Down Expand Up @@ -592,7 +602,7 @@ func resolveUnsupportedEntry(e *dwarf.Entry) *ditypes.Parameter {
kind = uint(e.Field[f].Val.(int64))
}
if e.Field[f].Attr == dwarf.AttrName {
name = e.Field[f].Val.(string)
name = strings.Clone(e.Field[f].Val.(string))
}
}
if name == "unsafe.Pointer" {
Expand Down