Skip to content

Commit 14948cc

Browse files
[GDBRemote] Fix processing of comma-separated memory region entries (llvm#105873)
The existing algorithm was performing the following comparisons for an `aaa,bbb,ccc,ddd`: aaa\0bbb,ccc,ddd == "stack" aaa\0bbb\0ccc,ddd == "stack" aaa\0bbb\0ccc\0ddd == "stack" Which wouldn't work. This commit just dispatches to a known algorithm implementation. (cherry picked from commit 8b4147d)
1 parent d6a7bca commit 14948cc

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,17 +1629,9 @@ Status GDBRemoteCommunicationClient::GetMemoryRegionInfo(
16291629
}
16301630
}
16311631
} else if (name == "type") {
1632-
std::string comma_sep_str = value.str();
1633-
size_t comma_pos;
1634-
while ((comma_pos = comma_sep_str.find(',')) != std::string::npos) {
1635-
comma_sep_str[comma_pos] = '\0';
1636-
if (comma_sep_str == "stack") {
1632+
for (llvm::StringRef entry : llvm::split(value, ',')) {
1633+
if (entry == "stack")
16371634
region_info.SetIsStackMemory(MemoryRegionInfo::eYes);
1638-
}
1639-
}
1640-
// handle final (or only) type of "stack"
1641-
if (comma_sep_str == "stack") {
1642-
region_info.SetIsStackMemory(MemoryRegionInfo::eYes);
16431635
}
16441636
} else if (name == "error") {
16451637
StringExtractorGDBRemote error_extractor(value);

lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,24 +343,27 @@ TEST_F(GDBRemoteCommunicationClientTest, GetMemoryRegionInfo) {
343343
EXPECT_EQ(MemoryRegionInfo::eYes, region_info.GetExecutable());
344344
EXPECT_EQ("/foo/bar.so", region_info.GetName().GetStringRef());
345345
EXPECT_EQ(MemoryRegionInfo::eDontKnow, region_info.GetMemoryTagged());
346+
EXPECT_EQ(MemoryRegionInfo::eDontKnow, region_info.IsStackMemory());
346347

347348
result = std::async(std::launch::async, [&] {
348349
return client.GetMemoryRegionInfo(addr, region_info);
349350
});
350351

351352
HandlePacket(server, "qMemoryRegionInfo:a000",
352-
"start:a000;size:2000;flags:;");
353+
"start:a000;size:2000;flags:;type:stack;");
353354
EXPECT_TRUE(result.get().Success());
354355
EXPECT_EQ(MemoryRegionInfo::eNo, region_info.GetMemoryTagged());
356+
EXPECT_EQ(MemoryRegionInfo::eYes, region_info.IsStackMemory());
355357

356358
result = std::async(std::launch::async, [&] {
357359
return client.GetMemoryRegionInfo(addr, region_info);
358360
});
359361

360362
HandlePacket(server, "qMemoryRegionInfo:a000",
361-
"start:a000;size:2000;flags: mt zz mt ;");
363+
"start:a000;size:2000;flags: mt zz mt ;type:ha,ha,stack;");
362364
EXPECT_TRUE(result.get().Success());
363365
EXPECT_EQ(MemoryRegionInfo::eYes, region_info.GetMemoryTagged());
366+
EXPECT_EQ(MemoryRegionInfo::eYes, region_info.IsStackMemory());
364367
}
365368

366369
TEST_F(GDBRemoteCommunicationClientTest, GetMemoryRegionInfoInvalidResponse) {

0 commit comments

Comments
 (0)