We can't let GetStackFrameCount get interrupted or it will give the
authorJim Ingham <jingham@apple.com>
Thu, 11 May 2023 00:48:48 +0000 (17:48 -0700)
committerJim Ingham <jingham@apple.com>
Thu, 11 May 2023 21:48:54 +0000 (14:48 -0700)
commite19387e6936c9ccc6200b32f3affea7b1020664c
tree17c33ecd481a53bdf768687de885a92d36c69746
parentc45ee7c0fba8daa2b5b6b201faa99d02c01cce8b
We can't let GetStackFrameCount get interrupted or it will give the
wrong answer. Plus, it's useful in some places to have a way to force
the full stack to be created even in the face of
interruption. Moreover, most of the time when you're just getting
frames, you don't need to know the number of frames in the stack to
start with. You just keep calling
Thread::GetStackFrameAtIndex(index++) and when you get a null
StackFrameSP back, you're done. That's also more amenable to
interruption if you are doing some work frame by frame.

So this patch makes GetStackFrameCount always return the full count,
suspending interruption. I also went through all the places that use
GetStackFrameCount to make sure that they really needed the full stack
walk. In many cases, they did not. For instance frame select -r 10 was
getting the number of frames just to check whether cur_frame_idx + 10
was within the stack. It's better in that case to see if that frame
exists first, since that doesn't force a full stack walk, and only
deal with walking off the end of the stack if it doesn't...

I also added a test for some of these behaviors.

Differential Revision: https://reviews.llvm.org/D150236
lldb/include/lldb/Target/StackFrameList.h
lldb/include/lldb/lldb-private-enumerations.h
lldb/source/Commands/CommandCompletions.cpp
lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
lldb/source/Target/StackFrameList.cpp
lldb/test/API/functionalities/bt-interrupt/Makefile [new file with mode: 0644]
lldb/test/API/functionalities/bt-interrupt/TestInterruptBacktrace.py [new file with mode: 0644]
lldb/test/API/functionalities/bt-interrupt/main.c [new file with mode: 0644]