clayborg wrote:

>From the DAP protocol for "StackTraceRequest", I see this in the response:
```
    /**
     * The total number of frames available in the stack. If omitted or if
     * `totalFrames` is larger than the available frames, a client is expected
     * to request frames until a request returns less frames than requested
     * (which indicates the end of the stack). Returning monotonically
     * increasing `totalFrames` values for subsequent requests can be used to
     * enforce paging in the client.
     */
    totalFrames?: number;
```
Right now we are making the requests to `thread.GetCurrentExceptionBacktrace()` 
and `thread.GetExtendedBacktraceThread("libdispatch")` just to update the total 
number of frames even though we may never access those items. Most stack frame 
requests for threads that are not expanded in the GUI will ask for 1 frame: 
frame zero.

Seeing the above statement from the spec: `Returning monotonically increasing 
`totalFrames` values for subsequent requests can be used to enforce paging in 
the client.`. We should be able to use this to just replace this:
```
    auto totalFrames = thread.GetNumFrames();

    // This will always return an invalid thread when
    // libBacktraceRecording.dylib is not loaded or if there is no extended
    // backtrace.
    lldb::SBThread queue_backtrace_thread =
        thread.GetExtendedBacktraceThread("libdispatch");
    if (queue_backtrace_thread.IsValid()) {
      // One extra frame as a label to mark the enqueued thread.
      totalFrames += queue_backtrace_thread.GetNumFrames() + 1;
    }

    // This will always return an invalid thread when there is no exception in
    // the current thread.
    lldb::SBThread exception_backtrace_thread =
        thread.GetCurrentExceptionBacktrace();
    if (exception_backtrace_thread.IsValid()) {
      // One extra frame as a label to mark the exception thread.
      totalFrames += exception_backtrace_thread.GetNumFrames() + 1;
    }

```
with:
```
    auto totalFrames = startFrame + levels + STACK_PAGE_SIZE;
```
So then we don't need to accurately calculate the number of stack frames. This 
will make all of our code more performant as just calling 
`thread.GetNumFrames();` is expensize. It will also keep us from calling 
`thread.GetExtendedBacktraceThread("libdispatch");` or 
`thread.GetCurrentExceptionBacktrace();` unless we need to. Since we can lazily 
populate these items when we need to.


https://github.com/llvm/llvm-project/pull/104874
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to