Support printing function parameters with varying verbosity levels [0 .. 4] with the -trace option#4251
Support printing function parameters with varying verbosity levels [0 .. 4] with the -trace option#4251archanaravindar wants to merge 4 commits intogo-delve:masterfrom
Conversation
modified tests for expected output
| stackdepth = 20 | ||
| } | ||
| // Get LoadConfig based on verbosity level | ||
| loadCfg := api.GetLoadConfigForVerbosity(traceVerbose) |
There was a problem hiding this comment.
Why is this a function in a different package?
| traceCommand.Flags().String("output", "", "Output path for the binary.") | ||
| must(traceCommand.MarkFlagFilename("output")) | ||
| traceCommand.Flags().IntVarP(&traceFollowCalls, "follow-calls", "", 0, "Trace all children of the function to the required depth. Trace also supports defer functions and cases where functions are dynamically returned and passed as parameters.") | ||
| traceCommand.Flags().IntVarP(&traceVerbose, "trace-verbose", "V", 2, "Parameter verbosity: 0=none, 1=types, 2=inline, 3=expanded, 4=full (default 2)") |
There was a problem hiding this comment.
I would expect the default to be the same thing we do now, for backwards compatibility. We don't guarantee backwards compatibility for this but I don't see a compelling reason not to do it in this case.
|
|
||
| // Get verbosity level from breakpoint | ||
| verbosity := 0 | ||
| if th.Breakpoint != nil { |
There was a problem hiding this comment.
We already know th.Breakpoint != nil here.
| // TraceFollowCalls indicates the Depth of tracing | ||
| TraceFollowCalls int | ||
| // Verbosity level to print function parameters as part of the trace [0-4] | ||
| TraceVerbosity int |
There was a problem hiding this comment.
I don't think this belongs here. The only piece of code that uses it (as far as I can see), can just check the value of LoadArgs.
| fmt.Fprintf(t.stdout, "%s> %s %s%s\n%s\n", | ||
| depthPrefix, tracePrefix, bpname, fn.Name(), paramStr) | ||
| } else { | ||
| // Levels 0-2: Single-line format |
There was a problem hiding this comment.
These two branches do the same thing.
| paramStr := formatTraceParameters(th, verbosity) | ||
| if verbosity >= 3 && paramStr != "" { | ||
| // Levels 3-4: Multi-line format | ||
| fmt.Fprintf(t.stdout, "%s> %s %s%s\n%s\n", |
There was a problem hiding this comment.
Move the common parts of these Fprintf calls out of the if.
| // Print trace only if there was a match on the function while TraceFollowCalls is on or if it's a regular trace | ||
| if rootindex != -1 || th.Breakpoint.TraceFollowCalls <= 0 { | ||
| fmt.Fprintf(t.stdout, "%s>> %s %s => (%s)\n", depthPrefix, tracePrefix, fn.Name(), strings.Join(retVals, ",")) | ||
| if verbosity > 0 { |
There was a problem hiding this comment.
Move the common parts of the fmt.Fprintf calls out of the if.
| withTestTerminal("issue573", t, func(term *FakeTerminal) { | ||
| term.MustExec("trace foo") | ||
| out, _ := term.Exec("continue") | ||
| fmt.Printf("output %s\n", out) |
| } | ||
|
|
||
| // FormatWithVerbosity formats a variable according to trace verbosity level | ||
| func (v *Variable) FormatWithVerbosity(verbosity int) string { |
There was a problem hiding this comment.
This is a helper function that is only used by the pkg/terminal package, it belongs there.
Fixes #3586
The current implementation supports the following verbosity levels
Verbosity Levels:
<int>, <Person>)To give an idea of what the output looks like pls refer to the attached .go test file and the related output seen with -trace and -trace-follow options
plainout.txt
testout.txt
traceverbcomplex.zip