[Lldb-commits] [lldb] [GDBRemote] Fix processing of comma-separated memory region entries (PR #105873)
Felipe de Azevedo Piovezan via lldb-commits
lldb-commits at lists.llvm.org
Fri Aug 23 12:02:29 PDT 2024
https://github.com/felipepiovezan created https://github.com/llvm/llvm-project/pull/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.
>From 8ef8ecdc8d87d474b906835d04ffdd9a19216406 Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan <fpiovezan at apple.com>
Date: Fri, 23 Aug 2024 11:43:16 -0700
Subject: [PATCH] [GDBRemote] Fix processing of comma-separated memory region
entries
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.
---
.../gdb-remote/GDBRemoteCommunicationClient.cpp | 12 ++----------
.../gdb-remote/GDBRemoteCommunicationClientTest.cpp | 7 +++++--
2 files changed, 7 insertions(+), 12 deletions(-)
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index 83ba27783da471..d80ccae0518088 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -1632,17 +1632,9 @@ Status GDBRemoteCommunicationClient::GetMemoryRegionInfo(
}
}
} else if (name == "type") {
- std::string comma_sep_str = value.str();
- size_t comma_pos;
- while ((comma_pos = comma_sep_str.find(',')) != std::string::npos) {
- comma_sep_str[comma_pos] = '\0';
- if (comma_sep_str == "stack") {
+ for (llvm::StringRef entry: llvm::split(value, ',')) {
+ if (entry == "stack")
region_info.SetIsStackMemory(MemoryRegionInfo::eYes);
- }
- }
- // handle final (or only) type of "stack"
- if (comma_sep_str == "stack") {
- region_info.SetIsStackMemory(MemoryRegionInfo::eYes);
}
} else if (name == "error") {
StringExtractorGDBRemote error_extractor(value);
diff --git a/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp b/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
index 11e14f9472164d..18020c8e43fe06 100644
--- a/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
+++ b/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
@@ -343,24 +343,27 @@ TEST_F(GDBRemoteCommunicationClientTest, GetMemoryRegionInfo) {
EXPECT_EQ(MemoryRegionInfo::eYes, region_info.GetExecutable());
EXPECT_EQ("/foo/bar.so", region_info.GetName().GetStringRef());
EXPECT_EQ(MemoryRegionInfo::eDontKnow, region_info.GetMemoryTagged());
+ EXPECT_EQ(MemoryRegionInfo::eDontKnow, region_info.IsStackMemory());
result = std::async(std::launch::async, [&] {
return client.GetMemoryRegionInfo(addr, region_info);
});
HandlePacket(server, "qMemoryRegionInfo:a000",
- "start:a000;size:2000;flags:;");
+ "start:a000;size:2000;flags:;type:stack;");
EXPECT_TRUE(result.get().Success());
EXPECT_EQ(MemoryRegionInfo::eNo, region_info.GetMemoryTagged());
+ EXPECT_EQ(MemoryRegionInfo::eYes, region_info.IsStackMemory());
result = std::async(std::launch::async, [&] {
return client.GetMemoryRegionInfo(addr, region_info);
});
HandlePacket(server, "qMemoryRegionInfo:a000",
- "start:a000;size:2000;flags: mt zz mt ;");
+ "start:a000;size:2000;flags: mt zz mt ;type:ha,ha,stack;");
EXPECT_TRUE(result.get().Success());
EXPECT_EQ(MemoryRegionInfo::eYes, region_info.GetMemoryTagged());
+ EXPECT_EQ(MemoryRegionInfo::eYes, region_info.IsStackMemory());
}
TEST_F(GDBRemoteCommunicationClientTest, GetMemoryRegionInfoInvalidResponse) {
More information about the lldb-commits
mailing list