MCPcopy
hub / github.com/crowdsecurity/crowdsec / extractCode

Method extractCode

pkg/exprhelpers/debugger.go:117–141  ·  view source on GitHub ↗
(ip int, program *vm.Program)

Source from the content-addressed store, hash-verified

115}
116
117func (ExprRuntimeDebug) extractCode(ip int, program *vm.Program) string {
118 locations := program.Locations()
119 src := program.Source().String()
120
121 currentInstruction := locations[ip]
122
123 var closest *file.Location
124
125 for i := ip + 1; i < len(locations); i++ {
126 if locations[i].From > currentInstruction.From {
127 if closest == nil || locations[i].From < closest.From {
128 closest = &locations[i]
129 }
130 }
131 }
132
133 var end int
134 if closest == nil {
135 end = len(src)
136 } else {
137 end = closest.From
138 }
139
140 return cleanTextForDebug(src[locations[ip].From:end])
141}
142
143func autoQuote(v any) string {
144 switch x := v.(type) {

Callers 1

ipDebugMethod · 0.95

Calls 2

cleanTextForDebugFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected