Skip to content

Commit 8891a07

Browse files
authored
Merge pull request #6683 from medismailben/swift/release/5.9
[lldb] Fix bug to update process public run lock with process state
2 parents d07bd3c + 647c510 commit 8891a07

File tree

6 files changed

+59
-43
lines changed

6 files changed

+59
-43
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

llvm/include/llvm/ADT/StringRef.h

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,22 +253,35 @@ namespace llvm {
253253
/// @{
254254

255255
/// Check if this string starts with the given \p Prefix.
256-
[[nodiscard]] bool startswith(StringRef Prefix) const {
256+
[[nodiscard]] bool starts_with(StringRef Prefix) const {
257257
return Length >= Prefix.Length &&
258258
compareMemory(Data, Prefix.Data, Prefix.Length) == 0;
259259
}
260+
[[nodiscard]] bool startswith(StringRef Prefix) const {
261+
return starts_with(Prefix);
262+
}
260263

261264
/// Check if this string starts with the given \p Prefix, ignoring case.
262-
[[nodiscard]] bool startswith_insensitive(StringRef Prefix) const;
265+
[[nodiscard]] bool starts_with_insensitive(StringRef Prefix) const;
266+
[[nodiscard]] bool startswith_insensitive(StringRef Prefix) const {
267+
return starts_with_insensitive(Prefix);
268+
}
263269

264270
/// Check if this string ends with the given \p Suffix.
265-
[[nodiscard]] bool endswith(StringRef Suffix) const {
271+
[[nodiscard]] bool ends_with(StringRef Suffix) const {
266272
return Length >= Suffix.Length &&
267-
compareMemory(end() - Suffix.Length, Suffix.Data, Suffix.Length) == 0;
273+
compareMemory(end() - Suffix.Length, Suffix.Data, Suffix.Length) ==
274+
0;
275+
}
276+
[[nodiscard]] bool endswith(StringRef Suffix) const {
277+
return ends_with(Suffix);
268278
}
269279

270280
/// Check if this string ends with the given \p Suffix, ignoring case.
271-
[[nodiscard]] bool endswith_insensitive(StringRef Suffix) const;
281+
[[nodiscard]] bool ends_with_insensitive(StringRef Suffix) const;
282+
[[nodiscard]] bool endswith_insensitive(StringRef Suffix) const {
283+
return ends_with_insensitive(Suffix);
284+
}
272285

273286
/// @}
274287
/// @name String Searching
@@ -622,7 +635,7 @@ namespace llvm {
622635
/// Returns true if this StringRef has the given prefix and removes that
623636
/// prefix.
624637
bool consume_front(StringRef Prefix) {
625-
if (!startswith(Prefix))
638+
if (!starts_with(Prefix))
626639
return false;
627640

628641
*this = drop_front(Prefix.size());
@@ -642,7 +655,7 @@ namespace llvm {
642655
/// Returns true if this StringRef has the given suffix and removes that
643656
/// suffix.
644657
bool consume_back(StringRef Suffix) {
645-
if (!endswith(Suffix))
658+
if (!ends_with(Suffix))
646659
return false;
647660

648661
*this = drop_back(Suffix.size());

llvm/lib/Support/StringRef.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ int StringRef::compare_insensitive(StringRef RHS) const {
4242
return Length < RHS.Length ? -1 : 1;
4343
}
4444

45-
bool StringRef::startswith_insensitive(StringRef Prefix) const {
45+
bool StringRef::starts_with_insensitive(StringRef Prefix) const {
4646
return Length >= Prefix.Length &&
4747
ascii_strncasecmp(Data, Prefix.Data, Prefix.Length) == 0;
4848
}
4949

50-
bool StringRef::endswith_insensitive(StringRef Suffix) const {
50+
bool StringRef::ends_with_insensitive(StringRef Suffix) const {
5151
return Length >= Suffix.Length &&
5252
ascii_strncasecmp(end() - Suffix.Length, Suffix.Data, Suffix.Length) == 0;
5353
}

llvm/unittests/ADT/StringRefTest.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -356,20 +356,20 @@ TEST(StringRefTest, Trim) {
356356

357357
TEST(StringRefTest, StartsWith) {
358358
StringRef Str("hello");
359-
EXPECT_TRUE(Str.startswith(""));
360-
EXPECT_TRUE(Str.startswith("he"));
361-
EXPECT_FALSE(Str.startswith("helloworld"));
362-
EXPECT_FALSE(Str.startswith("hi"));
359+
EXPECT_TRUE(Str.starts_with(""));
360+
EXPECT_TRUE(Str.starts_with("he"));
361+
EXPECT_FALSE(Str.starts_with("helloworld"));
362+
EXPECT_FALSE(Str.starts_with("hi"));
363363
}
364364

365365
TEST(StringRefTest, StartsWithInsensitive) {
366366
StringRef Str("heLLo");
367-
EXPECT_TRUE(Str.startswith_insensitive(""));
368-
EXPECT_TRUE(Str.startswith_insensitive("he"));
369-
EXPECT_TRUE(Str.startswith_insensitive("hell"));
370-
EXPECT_TRUE(Str.startswith_insensitive("HELlo"));
371-
EXPECT_FALSE(Str.startswith_insensitive("helloworld"));
372-
EXPECT_FALSE(Str.startswith_insensitive("hi"));
367+
EXPECT_TRUE(Str.starts_with_insensitive(""));
368+
EXPECT_TRUE(Str.starts_with_insensitive("he"));
369+
EXPECT_TRUE(Str.starts_with_insensitive("hell"));
370+
EXPECT_TRUE(Str.starts_with_insensitive("HELlo"));
371+
EXPECT_FALSE(Str.starts_with_insensitive("helloworld"));
372+
EXPECT_FALSE(Str.starts_with_insensitive("hi"));
373373
}
374374

375375
TEST(StringRefTest, ConsumeFront) {
@@ -408,21 +408,21 @@ TEST(StringRefTest, ConsumeFrontInsensitive) {
408408

409409
TEST(StringRefTest, EndsWith) {
410410
StringRef Str("hello");
411-
EXPECT_TRUE(Str.endswith(""));
412-
EXPECT_TRUE(Str.endswith("lo"));
413-
EXPECT_FALSE(Str.endswith("helloworld"));
414-
EXPECT_FALSE(Str.endswith("worldhello"));
415-
EXPECT_FALSE(Str.endswith("so"));
411+
EXPECT_TRUE(Str.ends_with(""));
412+
EXPECT_TRUE(Str.ends_with("lo"));
413+
EXPECT_FALSE(Str.ends_with("helloworld"));
414+
EXPECT_FALSE(Str.ends_with("worldhello"));
415+
EXPECT_FALSE(Str.ends_with("so"));
416416
}
417417

418418
TEST(StringRefTest, EndsWithInsensitive) {
419419
StringRef Str("heLLo");
420-
EXPECT_TRUE(Str.endswith_insensitive(""));
421-
EXPECT_TRUE(Str.endswith_insensitive("lo"));
422-
EXPECT_TRUE(Str.endswith_insensitive("LO"));
423-
EXPECT_TRUE(Str.endswith_insensitive("ELlo"));
424-
EXPECT_FALSE(Str.endswith_insensitive("helloworld"));
425-
EXPECT_FALSE(Str.endswith_insensitive("hi"));
420+
EXPECT_TRUE(Str.ends_with_insensitive(""));
421+
EXPECT_TRUE(Str.ends_with_insensitive("lo"));
422+
EXPECT_TRUE(Str.ends_with_insensitive("LO"));
423+
EXPECT_TRUE(Str.ends_with_insensitive("ELlo"));
424+
EXPECT_FALSE(Str.ends_with_insensitive("helloworld"));
425+
EXPECT_FALSE(Str.ends_with_insensitive("hi"));
426426
}
427427

428428
TEST(StringRefTest, ConsumeBack) {

0 commit comments

Comments
 (0)