From e0038717b9230db2b41e219735d9e352ea96ded1 Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Sun, 13 Nov 2016 02:08:22 +0000 Subject: [PATCH] Change ArgumentHelpCallbackFunction to return a StringRef. llvm-svn: 286740 --- lldb/include/lldb/Interpreter/CommandObject.h | 4 +- lldb/source/Interpreter/CommandObject.cpp | 53 +++++++++++---------------- 2 files changed, 24 insertions(+), 33 deletions(-) diff --git a/lldb/include/lldb/Interpreter/CommandObject.h b/lldb/include/lldb/Interpreter/CommandObject.h index 272d021..344e9b6 100644 --- a/lldb/include/lldb/Interpreter/CommandObject.h +++ b/lldb/include/lldb/Interpreter/CommandObject.h @@ -66,13 +66,13 @@ size_t FindLongestCommandWord(std::map &dict) { class CommandObject { public: - typedef const char *(ArgumentHelpCallbackFunction)(); + typedef llvm::StringRef(ArgumentHelpCallbackFunction)(); struct ArgumentHelpCallback { ArgumentHelpCallbackFunction *help_callback; bool self_formatting; - const char *operator()() const { return (*help_callback)(); } + llvm::StringRef operator()() const { return (*help_callback)(); } explicit operator bool() const { return (help_callback != nullptr); } }; diff --git a/lldb/source/Interpreter/CommandObject.cpp b/lldb/source/Interpreter/CommandObject.cpp index b3b52db..e71c109 100644 --- a/lldb/source/Interpreter/CommandObject.cpp +++ b/lldb/source/Interpreter/CommandObject.cpp @@ -390,7 +390,7 @@ void CommandObject::GetArgumentHelp(Stream &str, CommandArgumentType arg_type, name_str.Printf("<%s>", entry->arg_name); if (entry->help_function) { - const char *help_text = entry->help_function(); + llvm::StringRef help_text = entry->help_function(); if (!entry->help_function.self_formatting) { interpreter.OutputFormattedHelpText(str, name_str.GetData(), "--", help_text, name_str.GetSize()); @@ -553,7 +553,7 @@ CommandArgumentType CommandObject::LookupArgumentName(const char *arg_name) { return return_type; } -static const char *RegisterNameHelpTextCallback() { +static llvm::StringRef RegisterNameHelpTextCallback() { return "Register names can be specified using the architecture specific " "names. " "They can also be specified using generic names. Not all generic " @@ -571,7 +571,7 @@ static const char *RegisterNameHelpTextCallback() { "arg{1-6} - integer argument passing registers.\n"; } -static const char *BreakpointIDHelpTextCallback() { +static llvm::StringRef BreakpointIDHelpTextCallback() { return "Breakpoints are identified using major and minor numbers; the major " "number corresponds to the single entity that was created with a " "'breakpoint " @@ -590,7 +590,7 @@ static const char *BreakpointIDHelpTextCallback() { "3 or 3.2 could both be valid breakpoint IDs.)"; } -static const char *BreakpointIDRangeHelpTextCallback() { +static llvm::StringRef BreakpointIDRangeHelpTextCallback() { return "A 'breakpoint ID list' is a manner of specifying multiple " "breakpoints. " "This can be done through several mechanisms. The easiest way is to " @@ -609,7 +609,7 @@ static const char *BreakpointIDRangeHelpTextCallback() { " is legal; 2 - 5 is legal; but 3.2 - 4.4 is not legal."; } -static const char *BreakpointNameHelpTextCallback() { +static llvm::StringRef BreakpointNameHelpTextCallback() { return "A name that can be added to a breakpoint when it is created, or " "later " "on with the \"breakpoint name add\" command. " @@ -634,7 +634,7 @@ static const char *BreakpointNameHelpTextCallback() { "breakpoint locations."; } -static const char *GDBFormatHelpTextCallback() { +static llvm::StringRef GDBFormatHelpTextCallback() { return "A GDB format consists of a repeat count, a format letter and a size " "letter. " "The repeat count is optional and defaults to 1. The format letter is " @@ -671,12 +671,11 @@ static const char *GDBFormatHelpTextCallback() { "dw - show 1 4 byte decimal integer value\n"; } -static const char *FormatHelpTextCallback() { +static llvm::StringRef FormatHelpTextCallback() { + static std::string help_text; - static char *help_text_ptr = nullptr; - - if (help_text_ptr) - return help_text_ptr; + if (!help_text.empty()) + return help_text; StreamString sstr; sstr << "One of the format names (or one-character names) that can be used " @@ -694,20 +693,16 @@ static const char *FormatHelpTextCallback() { sstr.Flush(); - std::string data = sstr.GetString(); - - help_text_ptr = new char[data.length() + 1]; - - data.copy(help_text_ptr, data.length()); + help_text = sstr.GetString(); - return help_text_ptr; + return help_text; } -static const char *LanguageTypeHelpTextCallback() { - static char *help_text_ptr = nullptr; +static llvm::StringRef LanguageTypeHelpTextCallback() { + static std::string help_text; - if (help_text_ptr) - return help_text_ptr; + if (!help_text.empty()) + return help_text; StreamString sstr; sstr << "One of the following languages:\n"; @@ -716,16 +711,12 @@ static const char *LanguageTypeHelpTextCallback() { sstr.Flush(); - std::string data = sstr.GetString(); - - help_text_ptr = new char[data.length() + 1]; - - data.copy(help_text_ptr, data.length()); + help_text = sstr.GetString(); - return help_text_ptr; + return help_text; } -static const char *SummaryStringHelpTextCallback() { +static llvm::StringRef SummaryStringHelpTextCallback() { return "A summary string is a way to extract information from variables in " "order to present them using a summary.\n" "Summary strings contain static text, variables, scopes and control " @@ -800,7 +791,7 @@ static const char *SummaryStringHelpTextCallback() { "type summary add -s \"${svar%#}\" -x \"std::list<\""; } -static const char *ExprPathHelpTextCallback() { +static llvm::StringRef ExprPathHelpTextCallback() { return "An expression path is the sequence of symbols that is used in C/C++ " "to access a member variable of an aggregate object (class).\n" "For instance, given a class:\n" @@ -1028,7 +1019,7 @@ bool CommandObjectRaw::Execute(const char *args_string, return handled; } -static const char *arch_helper() { +static llvm::StringRef arch_helper() { static StreamString g_archs_help; if (g_archs_help.Empty()) { StringList archs; @@ -1036,7 +1027,7 @@ static const char *arch_helper() { g_archs_help.Printf("These are the supported architecture names:\n"); archs.Join("\n", g_archs_help); } - return g_archs_help.GetData(); + return g_archs_help.GetString(); } CommandObject::ArgumentTableEntry CommandObject::g_arguments_data[] = { -- 2.7.4