Skip to content

Commit

Permalink
[generickprobe.go] Add ExtractParam/OverwriteType usage for kprobes
Browse files Browse the repository at this point in the history
Add very similar code as in `genericlsm.go` file to handle those params.
In a future commit, a refactoring should be acheived to avoid code
redundant code with `genericlsm.go`

Signed-off-by: Tristan d'Audibert <[email protected]>
  • Loading branch information
ScriptSathi committed Nov 21, 2024
1 parent 4371787 commit ba048b3
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pkg/sensors/tracing/generickprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ func addKprobe(funcName string, instance int, f *v1alpha1.KProbeSpec, in *addKpr
var setRetprobe bool
var argRetprobe *v1alpha1.KProbeArg
var argsBTFSet [api.MaxArgsSupported]bool
var allArgsBtfChilds [api.EventConfigMaxArgs][api.MaxBtfArgChildDepth]api.ConfigBtfArgChild

errFn := func(err error) (idtable.EntryID, error) {
return idtable.UninitializedEntryID, err
Expand Down Expand Up @@ -758,6 +759,34 @@ func addKprobe(funcName string, instance int, f *v1alpha1.KProbeSpec, in *addKpr
argType = gt.GenericTypeFromString(a.Type)
}

if a.ExtractParam != "" && j < api.EventConfigMaxArgs {
allArgsBtfChilds[j] = [api.MaxBtfArgChildDepth]api.ConfigBtfArgChild{}
spec, err := btf.NewBTF()
if err != nil {
return errFn(fmt.Errorf("Unable to load BTF file"))
}

partialPath := strings.Split(a.ExtractParam, ".")
if len(partialPath) > api.MaxBtfArgChildDepth {
return errFn(fmt.Errorf("Exausted research in BTF for type %s. The maximum depth allowed is %d", a.Type, api.MaxBtfArgChildDepth))
}

rootType, err := spec.AnyTypeByName(a.Type)
if err != nil {
return errFn(fmt.Errorf("Type %s has not been found in BTF", a.Type))
}
lastChild, err := btf.FindNextBTFType(&allArgsBtfChilds[j], rootType, &partialPath, 0)
if err != nil {
return errFn(err)
}

if a.OverwriteType != "" {
argType = gt.GenericTypeFromString(a.OverwriteType)
} else {
argType = gt.GenericTypeFromBTF(*lastChild)
}
}

if argType == gt.GenericInvalidType {
return errFn(fmt.Errorf("Arg(%d) type '%s' unsupported", j, a.Type))
}
Expand All @@ -781,6 +810,7 @@ func addKprobe(funcName string, instance int, f *v1alpha1.KProbeSpec, in *addKpr
return errFn(fmt.Errorf("Error add arg: ArgType %s Index %d out of bounds",
a.Type, int(a.Index)))
}
config.BtfArgChild = allArgsBtfChilds
config.Arg[a.Index] = int32(argType)
config.ArgM[a.Index] = uint32(argMValue)

Expand Down

0 comments on commit ba048b3

Please sign in to comment.