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

Method ipDebug

pkg/exprhelpers/debugger.go:367–423  ·  view source on GitHub ↗
(ip int, vm *vm.VM, program *vm.Program, parts []string, outputs []OpOutput)

Source from the content-addressed store, hash-verified

365}
366
367func (erp ExprRuntimeDebug) ipDebug(ip int, vm *vm.VM, program *vm.Program, parts []string, outputs []OpOutput) []OpOutput {
368 IdxOut := len(outputs)
369 prevIdxOut := 0
370 currentDepth := 0
371
372 // when there is a function call or comparison, we need to wait for the next instruction to get the result and "finalize" the previous one
373 if IdxOut > 0 {
374 prevIdxOut = IdxOut - 1
375 currentDepth = outputs[prevIdxOut].CodeDepth
376
377 if outputs[prevIdxOut].Func && !outputs[prevIdxOut].Finalized {
378 stack := vm.Stack
379 num_items := 1
380
381 for i := len(stack) - 1; i >= 0 && num_items > 0; i-- {
382 outputs[prevIdxOut].FuncResults = append(outputs[prevIdxOut].FuncResults, autoQuote(stack[i]))
383 num_items--
384 }
385
386 outputs[prevIdxOut].Finalized = true
387 } else if (outputs[prevIdxOut].Comparison || outputs[prevIdxOut].Condition) && !outputs[prevIdxOut].Finalized {
388 stack := vm.Stack
389 outputs[prevIdxOut].StrConditionResult = fmt.Sprintf("%+v", stack)
390
391 if val, ok := stack[0].(bool); ok {
392 outputs[prevIdxOut].ConditionResult = new(bool)
393 *outputs[prevIdxOut].ConditionResult = val
394 }
395
396 outputs[prevIdxOut].Finalized = true
397 }
398 }
399
400 erp.Logger.Tracef("[STEP %d:%s] (stack:%+v) (parts:%+v) {depth:%d}", ip, parts[1], vm.Stack, parts, currentDepth)
401
402 var prevOut *OpOutput
403
404 if handler, ok := opHandlers[parts[1]]; ok {
405 if len(outputs) > 0 {
406 prevOut = &outputs[prevIdxOut]
407 }
408
409 out := handler(
410 OpOutput{
411 CodeDepth: currentDepth,
412 Code: erp.extractCode(ip, program),
413 },
414 prevOut,
415 ip, parts, vm, program)
416
417 if out != nil {
418 outputs = append(outputs, *out)
419 }
420 }
421
422 return outputs
423}
424

Callers 1

RunWithDebugFunction · 0.95

Calls 3

extractCodeMethod · 0.95
autoQuoteFunction · 0.85
TracefMethod · 0.80

Tested by

no test coverage detected