-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[lldb] Guard SBFrame/SBThread methods against running processes #152020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
|
||
#include <mutex> | ||
|
||
#include "lldb/Host/ProcessRunLock.h" | ||
#include "lldb/Target/StackID.h" | ||
#include "lldb/lldb-private.h" | ||
|
||
|
@@ -318,11 +319,13 @@ class ExecutionContext { | |
// These two variants take in a locker, and grab the target, lock the API | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment isn't correct anymore. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's also worth pointing out that IF the stop_locker is locked, the process and target have to be valid, so you don't need to check for that after checking the stop_locker... |
||
// mutex into locker, then fill in the rest of the shared pointers. | ||
ExecutionContext(const ExecutionContextRef &exe_ctx_ref, | ||
std::unique_lock<std::recursive_mutex> &locker) | ||
: ExecutionContext(&exe_ctx_ref, locker) {} | ||
std::unique_lock<std::recursive_mutex> &locker, | ||
ProcessRunLock::ProcessRunLocker &stop_locker) | ||
: ExecutionContext(&exe_ctx_ref, locker, stop_locker) {} | ||
|
||
ExecutionContext(const ExecutionContextRef *exe_ctx_ref, | ||
std::unique_lock<std::recursive_mutex> &locker); | ||
std::unique_lock<std::recursive_mutex> &locker, | ||
ProcessRunLock::ProcessRunLocker &stop_locker); | ||
// Create execution contexts from execution context scopes | ||
ExecutionContext(ExecutionContextScope *exe_scope); | ||
ExecutionContext(ExecutionContextScope &exe_scope); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: The "error message warning" is somewhat confusing. How about:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the SB API level, if you are getting the ExecutionContext from an ExecutionContextRef represented by a Target, Process, Thread or Frame you should also hold the API mutex. There are some cases where we don't actually require a process. For instance SBTarget::CreateValueFromAddress can work on either a live process that's stopped or to look at static data on a non-running target. But those seem like they are in the minority, and in that case, for instance, you could easily do:
if (!process || stop_locker.IsLocked())
so that wouldn't be particularly awkward.
I can't think of a good reason why you would want to drop the API lock before the stop lock or vice versa. There's the one place where Felipe swaps the stop_locker originally set for another, so long as this doesn't make that particularly awkward, this seems doable.