summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEnrico Granata <granata.enrico@gmail.com>2011-08-19 01:47:11 +0000
committerEnrico Granata <granata.enrico@gmail.com>2011-08-19 01:47:11 +0000
commitda616d06e9a9fb235132915f427b45146cea456a (patch)
treef1538e80592ccb008bf26e2bc02a15162a224178
parent4938edb02c1f4efcf02a68079684adbbafdfe7b2 (diff)
downloadbcm5719-llvm-da616d06e9a9fb235132915f427b45146cea456a.tar.gz
bcm5719-llvm-da616d06e9a9fb235132915f427b45146cea456a.zip
More thorough fix for the spaces-in-typename issue
llvm-svn: 138026
-rw-r--r--lldb/include/lldb/Core/FormatManager.h28
-rw-r--r--lldb/test/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py3
2 files changed, 24 insertions, 7 deletions
diff --git a/lldb/include/lldb/Core/FormatManager.h b/lldb/include/lldb/Core/FormatManager.h
index c04cfdba756..f11ac7dcc6c 100644
--- a/lldb/include/lldb/Core/FormatManager.h
+++ b/lldb/include/lldb/Core/FormatManager.h
@@ -79,12 +79,24 @@ public:
};
+static inline bool
+IsWhitespace (char c)
+{
+ return ( (c == ' ') || (c == '\t') || (c == '\v') || (c == '\f') );
+}
+
+static inline bool
+HasPrefix (const char* str1, const char* str2)
+{
+ return ( ::strstr(str1, str2) == str1 );
+}
+
// if the user tries to add formatters for, say, "struct Foo"
// those will not match any type because of the way we strip qualifiers from typenames
// this method looks for the case where the user is adding a "class","struct","enum" or "union" Foo
// and strips the unnecessary qualifier
static ConstString
-GetValidTypeName_Impl(const ConstString& type)
+GetValidTypeName_Impl (const ConstString& type)
{
int strip_len = 0;
@@ -93,19 +105,23 @@ GetValidTypeName_Impl(const ConstString& type)
const char* type_cstr = type.AsCString();
- if ( ::strstr(type_cstr, "class ") == type_cstr)
+ if ( HasPrefix(type_cstr, "class ") )
strip_len = 6;
- if ( ::strstr(type_cstr, "enum ") == type_cstr)
+ else if ( HasPrefix(type_cstr, "enum ") )
strip_len = 5;
- if ( ::strstr(type_cstr, "struct ") == type_cstr)
+ else if ( HasPrefix(type_cstr, "struct ") )
strip_len = 7;
- if ( ::strstr(type_cstr, "union ") == type_cstr)
+ else if ( HasPrefix(type_cstr, "union ") )
strip_len = 6;
if (strip_len == 0)
return type;
- return ConstString(type_cstr + strip_len);
+ type_cstr += strip_len;
+ while (IsWhitespace(*type_cstr) && ++type_cstr)
+ ;
+
+ return ConstString(type_cstr);
}
template<typename KeyType, typename ValueType>
diff --git a/lldb/test/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py b/lldb/test/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py
index 0cc04f9ea86..a5862ac1e87 100644
--- a/lldb/test/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py
+++ b/lldb/test/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py
@@ -218,8 +218,9 @@ class DataFormatterTestCase(TestBase):
self.expect("frame variable the_coolest_guy",
substrs = ['(i_am_cooler) the_coolest_guy = goofy'])
+ # many spaces, but we still do the right thing
self.runCmd("type summary delete i_am_cool")
- self.runCmd("type summary add -f \"goofy\" \"union i_am_cool\"")
+ self.runCmd("type summary add -f \"goofy\" \"union i_am_cool\"")
self.expect("frame variable the_coolest_guy",
substrs = ['(i_am_cooler) the_coolest_guy = goofy'])
OpenPOWER on IntegriCloud