From bc711e0575fb6f1b58bfb0cea6b0647bda679490 Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Wed, 26 Mar 2014 22:35:52 +0000 Subject: [PATCH] =?UTF-8?q?Fixed=20a=20crasher=20when=20using=201=20charac?= =?UTF-8?q?ter=20type=20names=20in=20=E2=80=9Ctype=20summary=E2=80=9D,=20?= =?UTF-8?q?=E2=80=9Ctype=20synthetic=E2=80=9D=20and=20=E2=80=9Ctype=20filt?= =?UTF-8?q?er=E2=80=9D.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also fixed a missing return when making python summary functions on the fly. llvm-svn: 204867 --- lldb/source/Commands/CommandObjectType.cpp | 58 ++++++++++------------ 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/lldb/source/Commands/CommandObjectType.cpp b/lldb/source/Commands/CommandObjectType.cpp index f1b1d2c1900c..a8cef0fb1ba5 100644 --- a/lldb/source/Commands/CommandObjectType.cpp +++ b/lldb/source/Commands/CommandObjectType.cpp @@ -17,6 +17,8 @@ // C++ Includes +#include "llvm/ADT/StringRef.h" + #include "lldb/Core/ConstString.h" #include "lldb/Core/Debugger.h" #include "lldb/Core/IOHandler.h" @@ -204,7 +206,7 @@ public: static const char *g_summary_addreader_instructions = "Enter your Python command(s). Type 'DONE' to end.\n" "def function (valobj,internal_dict):\n" " \"\"\"valobj: an SBValue which you want to provide a summary for\n" - " internal_dict: an LLDB support object not to be used\"\"\""; + " internal_dict: an LLDB support object not to be used\"\"\"\n"; StreamFileSP output_sp(io_handler.GetOutputStreamFile()); if (output_sp) @@ -1814,6 +1816,25 @@ CommandObjectTypeSummaryAdd::DoExecute (Args& command, CommandReturnObject &resu return Execute_StringSummary(command, result); } +static bool +FixArrayTypeNameWithRegex (ConstString &type_name) +{ + llvm::StringRef type_name_ref(type_name.GetStringRef()); + + if (type_name_ref.endswith("[]")) + { + std::string type_name_str(type_name.GetCString()); + type_name_str.resize(type_name_str.length()-2); + if (type_name_str.back() != ' ') + type_name_str.append(" \\[[0-9]+\\]"); + else + type_name_str.append("\\[[0-9]+\\]"); + type_name.SetCString(type_name_str.c_str()); + return true; + } + return false; +} + bool CommandObjectTypeSummaryAdd::AddSummary(ConstString type_name, TypeSummaryImplSP entry, @@ -1826,17 +1847,8 @@ CommandObjectTypeSummaryAdd::AddSummary(ConstString type_name, if (type == eRegularSummary) { - std::string type_name_str(type_name.GetCString()); - if (type_name_str.compare(type_name_str.length() - 2, 2, "[]") == 0) - { - type_name_str.resize(type_name_str.length()-2); - if (type_name_str.back() != ' ') - type_name_str.append(" \\[[0-9]+\\]"); - else - type_name_str.append("\\[[0-9]+\\]"); - type_name.SetCString(type_name_str.c_str()); + if (FixArrayTypeNameWithRegex (type_name)) type = eRegexSummary; - } } if (type == eRegexSummary) @@ -3897,17 +3909,8 @@ CommandObjectTypeSynthAdd::AddSynth(ConstString type_name, if (type == eRegularSynth) { - std::string type_name_str(type_name.GetCString()); - if (type_name_str.compare(type_name_str.length() - 2, 2, "[]") == 0) - { - type_name_str.resize(type_name_str.length()-2); - if (type_name_str.back() != ' ') - type_name_str.append(" \\[[0-9]+\\]"); - else - type_name_str.append("\\[[0-9]+\\]"); - type_name.SetCString(type_name_str.c_str()); - type = eRegularSynth; - } + if (FixArrayTypeNameWithRegex (type_name)) + type = eRegexSynth; } if (category->AnyMatches(type_name, @@ -4076,17 +4079,8 @@ private: if (type == eRegularFilter) { - std::string type_name_str(type_name.GetCString()); - if (type_name_str.compare(type_name_str.length() - 2, 2, "[]") == 0) - { - type_name_str.resize(type_name_str.length()-2); - if (type_name_str.back() != ' ') - type_name_str.append(" \\[[0-9]+\\]"); - else - type_name_str.append("\\[[0-9]+\\]"); - type_name.SetCString(type_name_str.c_str()); + if (FixArrayTypeNameWithRegex (type_name)) type = eRegexFilter; - } } if (category->AnyMatches(type_name,