[Lldb-commits] [lldb] [lldb] Add comment to ParseInternal in FormatEntity (NFC) (PR #81018)
Dave Lee via lldb-commits
lldb-commits at lists.llvm.org
Wed Feb 7 10:46:26 PST 2024
https://github.com/kastiglione updated https://github.com/llvm/llvm-project/pull/81018
>From f9d4abddb0f93d27ed14278566796babad9f7f4e Mon Sep 17 00:00:00 2001
From: Dave Lee <davelee.com at gmail.com>
Date: Wed, 7 Feb 2024 10:17:51 -0800
Subject: [PATCH 1/2] [lldb] Add comment to ParseInternal in FormatEntity
---
lldb/source/Core/FormatEntity.cpp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lldb/source/Core/FormatEntity.cpp b/lldb/source/Core/FormatEntity.cpp
index 3c665c2eb2133..b206b6e9983b8 100644
--- a/lldb/source/Core/FormatEntity.cpp
+++ b/lldb/source/Core/FormatEntity.cpp
@@ -2204,7 +2204,9 @@ static Status ParseInternal(llvm::StringRef &format, Entry &parent_entry,
return error;
}
} else if (FormatManager::GetFormatFromCString(
- entry.printf_format.c_str(), true, entry.fmt)) {
+ entry.printf_format.c_str(), true,
+ entry.fmt)) { // Try GetFormatFromCString again,
+ // with partial_match_ok = true.
clear_printf = true;
} else if (entry.printf_format == "tid") {
verify_is_thread_id = true;
>From ab7b6e3e97dcfba7cdac84845d6f1a4778683955 Mon Sep 17 00:00:00 2001
From: Dave Lee <davelee.com at gmail.com>
Date: Wed, 7 Feb 2024 10:46:01 -0800
Subject: [PATCH 2/2] Refactor GetFormatFromCString to always handle partial
matches
---
.../include/lldb/DataFormatters/FormatManager.h | 2 +-
lldb/source/Core/FormatEntity.cpp | 10 ++--------
lldb/source/DataFormatters/FormatManager.cpp | 17 +++++++----------
lldb/source/Interpreter/OptionArgParser.cpp | 3 +--
4 files changed, 11 insertions(+), 21 deletions(-)
diff --git a/lldb/include/lldb/DataFormatters/FormatManager.h b/lldb/include/lldb/DataFormatters/FormatManager.h
index 986614f0c5e43..db2fe99c44caf 100644
--- a/lldb/include/lldb/DataFormatters/FormatManager.h
+++ b/lldb/include/lldb/DataFormatters/FormatManager.h
@@ -138,7 +138,7 @@ class FormatManager : public IFormatChangeListener {
}
static bool GetFormatFromCString(const char *format_cstr,
- bool partial_match_ok, lldb::Format &format);
+ lldb::Format &format);
static char GetFormatAsFormatChar(lldb::Format format);
diff --git a/lldb/source/Core/FormatEntity.cpp b/lldb/source/Core/FormatEntity.cpp
index b206b6e9983b8..cdc3ea38fd201 100644
--- a/lldb/source/Core/FormatEntity.cpp
+++ b/lldb/source/Core/FormatEntity.cpp
@@ -2151,11 +2151,7 @@ static Status ParseInternal(llvm::StringRef &format, Entry &parent_entry,
if (entry.printf_format.find('%') == std::string::npos) {
bool clear_printf = false;
- if (FormatManager::GetFormatFromCString(
- entry.printf_format.c_str(), false, entry.fmt)) {
- // We have an LLDB format, so clear the printf format
- clear_printf = true;
- } else if (entry.printf_format.size() == 1) {
+ if (entry.printf_format.size() == 1) {
switch (entry.printf_format[0]) {
case '@': // if this is an @ sign, print ObjC description
entry.number = ValueObject::
@@ -2204,9 +2200,7 @@ static Status ParseInternal(llvm::StringRef &format, Entry &parent_entry,
return error;
}
} else if (FormatManager::GetFormatFromCString(
- entry.printf_format.c_str(), true,
- entry.fmt)) { // Try GetFormatFromCString again,
- // with partial_match_ok = true.
+ entry.printf_format.c_str(), entry.fmt)) {
clear_printf = true;
} else if (entry.printf_format == "tid") {
verify_is_thread_id = true;
diff --git a/lldb/source/DataFormatters/FormatManager.cpp b/lldb/source/DataFormatters/FormatManager.cpp
index f1f135de32ca8..092fa3c8ce496 100644
--- a/lldb/source/DataFormatters/FormatManager.cpp
+++ b/lldb/source/DataFormatters/FormatManager.cpp
@@ -91,7 +91,7 @@ static bool GetFormatFromFormatChar(char format_char, Format &format) {
}
static bool GetFormatFromFormatName(llvm::StringRef format_name,
- bool partial_match_ok, Format &format) {
+ Format &format) {
uint32_t i;
for (i = 0; i < g_num_format_infos; ++i) {
if (format_name.equals_insensitive(g_format_infos[i].format_name)) {
@@ -100,13 +100,11 @@ static bool GetFormatFromFormatName(llvm::StringRef format_name,
}
}
- if (partial_match_ok) {
- for (i = 0; i < g_num_format_infos; ++i) {
- if (llvm::StringRef(g_format_infos[i].format_name)
- .starts_with_insensitive(format_name)) {
- format = g_format_infos[i].format;
- return true;
- }
+ for (i = 0; i < g_num_format_infos; ++i) {
+ if (llvm::StringRef(g_format_infos[i].format_name)
+ .starts_with_insensitive(format_name)) {
+ format = g_format_infos[i].format;
+ return true;
}
}
format = eFormatInvalid;
@@ -124,7 +122,6 @@ void FormatManager::Changed() {
}
bool FormatManager::GetFormatFromCString(const char *format_cstr,
- bool partial_match_ok,
lldb::Format &format) {
bool success = false;
if (format_cstr && format_cstr[0]) {
@@ -134,7 +131,7 @@ bool FormatManager::GetFormatFromCString(const char *format_cstr,
return true;
}
- success = GetFormatFromFormatName(format_cstr, partial_match_ok, format);
+ success = GetFormatFromFormatName(format_cstr, format);
}
if (!success)
format = eFormatInvalid;
diff --git a/lldb/source/Interpreter/OptionArgParser.cpp b/lldb/source/Interpreter/OptionArgParser.cpp
index d13805a75ffbf..75ccad87467e9 100644
--- a/lldb/source/Interpreter/OptionArgParser.cpp
+++ b/lldb/source/Interpreter/OptionArgParser.cpp
@@ -93,8 +93,7 @@ Status OptionArgParser::ToFormat(const char *s, lldb::Format &format,
*byte_size_ptr = 0;
}
- const bool partial_match_ok = true;
- if (!FormatManager::GetFormatFromCString(s, partial_match_ok, format)) {
+ if (!FormatManager::GetFormatFromCString(s, format)) {
StreamString error_strm;
error_strm.Printf(
"Invalid format character or name '%s'. Valid values are:\n", s);
More information about the lldb-commits
mailing list