mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-25 00:56:04 +00:00
[lldb] Refactor GetFormatFromCString to always check for partial matches (NFC) (#81018)
Refactors logic in `ParseInternal` that was previously calling `GetFormatFromCString` twice, once with `partial_match_ok` set to false, and the second time set to true. With this change, lldb formats (ie `%@`, `%S`, etc) are checked first. If a format is not one of those, then `GetFormatFromCString` is called once, and now always checks for partial matches.
This commit is contained in:
parent
f219cda7bd
commit
af97edff70
@ -138,7 +138,7 @@ public:
|
||||
}
|
||||
|
||||
static bool GetFormatFromCString(const char *format_cstr,
|
||||
bool partial_match_ok, lldb::Format &format);
|
||||
lldb::Format &format);
|
||||
|
||||
static char GetFormatAsFormatChar(lldb::Format format);
|
||||
|
||||
|
@ -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::
|
||||
@ -2198,20 +2194,20 @@ static Status ParseInternal(llvm::StringRef &format, Entry &parent_entry,
|
||||
eValueObjectRepresentationStyleExpressionPath;
|
||||
clear_printf = true;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
if (entry.number == 0) {
|
||||
if (FormatManager::GetFormatFromCString(
|
||||
entry.printf_format.c_str(), entry.fmt)) {
|
||||
clear_printf = true;
|
||||
} else if (entry.printf_format == "tid") {
|
||||
verify_is_thread_id = true;
|
||||
} else {
|
||||
error.SetErrorStringWithFormat("invalid format: '%s'",
|
||||
entry.printf_format.c_str());
|
||||
return error;
|
||||
}
|
||||
} else if (FormatManager::GetFormatFromCString(
|
||||
entry.printf_format.c_str(), true, entry.fmt)) {
|
||||
clear_printf = true;
|
||||
} else if (entry.printf_format == "tid") {
|
||||
verify_is_thread_id = true;
|
||||
} else {
|
||||
error.SetErrorStringWithFormat("invalid format: '%s'",
|
||||
entry.printf_format.c_str());
|
||||
return error;
|
||||
}
|
||||
|
||||
// Our format string turned out to not be a printf style format
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user