Skip to content

Commit 8b4147d

Browse files
[GDBRemote] Fix processing of comma-separated memory region entries (#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.
1 parent aa61925 commit 8b4147d

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
@@ -1632,17 +1632,9 @@ Status GDBRemoteCommunicationClient::GetMemoryRegionInfo(
16321632
}
16331633
}
16341634
} else if (name == "type") {
1635-
std::string comma_sep_str = value.str();
1636-
size_t comma_pos;
1637-
while ((comma_pos = comma_sep_str.find(',')) != std::string::npos) {
1638-
comma_sep_str[comma_pos] = '\0';
1639-
if (comma_sep_str == "stack") {
1635+
for (llvm::StringRef entry : llvm::split(value, ',')) {
1636+
if (entry == "stack")
16401637
region_info.SetIsStackMemory(MemoryRegionInfo::eYes);
1641-
}
1642-
}
1643-
// handle final (or only) type of "stack"
1644-
if (comma_sep_str == "stack") {
1645-
region_info.SetIsStackMemory(MemoryRegionInfo::eYes);
16461638
}
16471639
} else if (name == "error") {
16481640
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)