Skip to content

Commit 647c510

Browse files
committed
[lldb] Fix bug to update process public run lock with process state
This patch should address an issue that caused the process public run lock to not be updated during a process launch/attach when the process stops. That caused the public run lock to report its state as running while the process state is stopped. This prevents the users to interact with the process (through the command line or via the SBAPI) since it's considered still running. To address that, this patch refactors the name of the internal hijack listeners to a specific pattern `lldb.internal.<action>.hijack` that are used to ensure that we've attached to or launched a process successfully. Then, when updating the process public state, after updating the state value, if the process is not hijacked externally, meaning if the process doens't have a hijack listener that matches the internal hijack listeners pattern, we can update the public run lock accordingly. rdar://108283017 Differential Revision: https://reviews.llvm.org/D148400 Signed-off-by: Med Ismail Bennani <[email protected]>
1 parent caf7689 commit 647c510

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

lldb/include/lldb/Target/Process.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,13 @@ class Process : public std::enable_shared_from_this<Process>,
389389

390390
static ConstString &GetStaticBroadcasterClass();
391391

392+
static constexpr llvm::StringRef AttachSynchronousHijackListenerName =
393+
"lldb.internal.Process.AttachSynchronous.hijack";
394+
static constexpr llvm::StringRef LaunchSynchronousHijackListenerName =
395+
"lldb.internal.Process.LaunchSynchronous.hijack";
396+
static constexpr llvm::StringRef ResumeSynchronousHijackListenerName =
397+
"lldb.internal.Process.ResumeSynchronous.hijack";
398+
392399
ConstString &GetBroadcasterClass() const override {
393400
return GetStaticBroadcasterClass();
394401
}

lldb/source/Target/Process.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,8 +1493,6 @@ Status Process::Resume() {
14931493
return error;
14941494
}
14951495

1496-
static const char *g_resume_sync_name = "lldb.Process.ResumeSynchronous.hijack";
1497-
14981496
Status Process::ResumeSynchronous(Stream *stream) {
14991497
Log *log(GetLog(LLDBLog::State | LLDBLog::Process));
15001498
LLDB_LOGF(log, "Process::ResumeSynchronous -- locking run lock");
@@ -1505,7 +1503,7 @@ Status Process::ResumeSynchronous(Stream *stream) {
15051503
}
15061504

15071505
ListenerSP listener_sp(
1508-
Listener::MakeListener(g_resume_sync_name));
1506+
Listener::MakeListener(ResumeSynchronousHijackListenerName.data()));
15091507
HijackProcessEvents(listener_sp);
15101508

15111509
Status error = PrivateResume();
@@ -1531,19 +1529,17 @@ Status Process::ResumeSynchronous(Stream *stream) {
15311529

15321530
bool Process::StateChangedIsExternallyHijacked() {
15331531
if (IsHijackedForEvent(eBroadcastBitStateChanged)) {
1534-
const char *hijacking_name = GetHijackingListenerName();
1535-
if (hijacking_name &&
1536-
strcmp(hijacking_name, g_resume_sync_name))
1532+
llvm::StringRef hijacking_name = GetHijackingListenerName();
1533+
if (!hijacking_name.starts_with("lldb.internal"))
15371534
return true;
15381535
}
15391536
return false;
15401537
}
15411538

15421539
bool Process::StateChangedIsHijackedForSynchronousResume() {
15431540
if (IsHijackedForEvent(eBroadcastBitStateChanged)) {
1544-
const char *hijacking_name = GetHijackingListenerName();
1545-
if (hijacking_name &&
1546-
strcmp(hijacking_name, g_resume_sync_name) == 0)
1541+
llvm::StringRef hijacking_name = GetHijackingListenerName();
1542+
if (hijacking_name == ResumeSynchronousHijackListenerName)
15471543
return true;
15481544
}
15491545
return false;

lldb/source/Target/Target.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3582,8 +3582,8 @@ Status Target::Launch(ProcessLaunchInfo &launch_info, Stream *stream) {
35823582
// its own hijacking listener or if the process is created by the target
35833583
// manually, without the platform).
35843584
if (!launch_info.GetHijackListener())
3585-
launch_info.SetHijackListener(
3586-
Listener::MakeListener("lldb.Target.Launch.hijack"));
3585+
launch_info.SetHijackListener(Listener::MakeListener(
3586+
Process::LaunchSynchronousHijackListenerName.data()));
35873587

35883588
// If we're not already connected to the process, and if we have a platform
35893589
// that can launch a process for debugging, go ahead and do that here.
@@ -3759,8 +3759,8 @@ Status Target::Attach(ProcessAttachInfo &attach_info, Stream *stream) {
37593759
ListenerSP hijack_listener_sp;
37603760
const bool async = attach_info.GetAsync();
37613761
if (!async) {
3762-
hijack_listener_sp =
3763-
Listener::MakeListener("lldb.Target.Attach.attach.hijack");
3762+
hijack_listener_sp = Listener::MakeListener(
3763+
Process::AttachSynchronousHijackListenerName.data());
37643764
attach_info.SetHijackListener(hijack_listener_sp);
37653765
}
37663766

0 commit comments

Comments
 (0)