diff --git a/lldb/include/lldb/Core/ArchSpec.h b/lldb/include/lldb/Core/ArchSpec.h index 4b253d9a35df..60e823354f54 100644 --- a/lldb/include/lldb/Core/ArchSpec.h +++ b/lldb/include/lldb/Core/ArchSpec.h @@ -142,6 +142,10 @@ public: const ArchSpec& operator= (const ArchSpec& rhs); + static uint32_t + AutoComplete (const char *name, + StringList &matches); + //------------------------------------------------------------------ /// Returns a static string representing the current architecture. /// diff --git a/lldb/include/lldb/Core/Log.h b/lldb/include/lldb/Core/Log.h index 7c300400ccc3..893a715ea223 100644 --- a/lldb/include/lldb/Core/Log.h +++ b/lldb/include/lldb/Core/Log.h @@ -105,6 +105,13 @@ public: static void Terminate (); + + //------------------------------------------------------------------ + // Auto completion + //------------------------------------------------------------------ + static void + AutoCompleteChannelName (const char *channel_name, + StringList &matches); //------------------------------------------------------------------ // Member functions @@ -193,9 +200,6 @@ public: virtual ~LogChannel (); - static const char * - GetPluginSuffix (); - static lldb::LogChannelSP FindPlugin (const char *plugin_name); diff --git a/lldb/include/lldb/Core/PluginManager.h b/lldb/include/lldb/Core/PluginManager.h index ca1f2888d1b5..c4e00ad3a208 100644 --- a/lldb/include/lldb/Core/PluginManager.h +++ b/lldb/include/lldb/Core/PluginManager.h @@ -192,6 +192,9 @@ public: static const char * GetPlatformPluginDescriptionAtIndex (uint32_t idx); + static uint32_t + AutoCompletePlatformName (const char *partial_name, + StringList &matches); //------------------------------------------------------------------ // Process //------------------------------------------------------------------ diff --git a/lldb/include/lldb/Interpreter/CommandCompletions.h b/lldb/include/lldb/Interpreter/CommandCompletions.h index 11e7346f4b50..85127fd87c2c 100644 --- a/lldb/include/lldb/Interpreter/CommandCompletions.h +++ b/lldb/include/lldb/Interpreter/CommandCompletions.h @@ -38,16 +38,19 @@ public: lldb_private::StringList &matches); // The array of matches we return. typedef enum { - eNoCompletion = 0, - eSourceFileCompletion = (1 << 0), - eDiskFileCompletion = (1 << 1), - eDiskDirectoryCompletion = (1 << 2), - eSymbolCompletion = (1 << 3), - eModuleCompletion = (1 << 4), - eSettingsNameCompletion = (1 << 5), - eCustomCompletion = (1 << 6) // This item serves two purposes. It is the last element in the enum, - // so you can add custom enums starting from here in your Option class. - // Also if you & in this bit the base code will not process the option. + eNoCompletion = 0u, + eSourceFileCompletion = (1u << 0), + eDiskFileCompletion = (1u << 1), + eDiskDirectoryCompletion = (1u << 2), + eSymbolCompletion = (1u << 3), + eModuleCompletion = (1u << 4), + eSettingsNameCompletion = (1u << 5), + ePlatformPluginCompletion = (1u << 6), + eArchitectureCompletion = (1u << 7), + // This item serves two purposes. It is the last element in the enum, + // so you can add custom enums starting from here in your Option class. + // Also if you & in this bit the base code will not process the option. + eCustomCompletion = (1u << 8) } CommonCompletionTypes; @@ -121,6 +124,25 @@ public: SearchFilter *searcher, bool &word_complete, lldb_private::StringList &matches); + + static int + PlatformPluginNames (CommandInterpreter &interpreter, + const char *partial_file_name, + int match_start_point, + int max_return_elements, + SearchFilter *searcher, + bool &word_complete, + lldb_private::StringList &matches); + + + static int + ArchitectureNames (CommandInterpreter &interpreter, + const char *partial_file_name, + int match_start_point, + int max_return_elements, + SearchFilter *searcher, + bool &word_complete, + lldb_private::StringList &matches); //---------------------------------------------------------------------- // The Completer class is a convenient base class for building searchers diff --git a/lldb/include/lldb/Interpreter/Options.h b/lldb/include/lldb/Interpreter/Options.h index 8e12d2f5e528..02ca50b6ac07 100644 --- a/lldb/include/lldb/Interpreter/Options.h +++ b/lldb/include/lldb/Interpreter/Options.h @@ -382,7 +382,7 @@ protected: OptionGroupOptions (CommandInterpreter &interpreter) : Options (interpreter), m_option_defs (), - m_option_groups (), + m_option_infos (), m_did_finalize (false) { } @@ -392,11 +392,32 @@ protected: { } + //---------------------------------------------------------------------- + /// Append options from a OptionGroup class. + /// + /// Append options from \a group that have a usage mask that has any bits + /// in "src_mask" set. After the option definition is copied into the + /// options definitions in this class, set the usage_mask to "dst_mask". + /// + /// @param[in] group + /// A group of options to take option values from and copy their + /// definitions into this class. + /// + /// @param[in] src_mask + /// When copying options from \a group, you might only want some of + /// the options to be appended to this group. This mask allows you + /// to control which options from \a group get added. It also allows + /// you to specify the same options from \a group multiple times + /// for different option sets. + /// + /// @param[in] dst_mask + /// Set the usage mask for any copied options to \a dst_mask after + /// copying the option definition. + //---------------------------------------------------------------------- void - Append (OptionGroup* group); - - void - Append (OptionGroup* group, uint32_t usage_mask); + Append (OptionGroup* group, + uint32_t src_mask, + uint32_t dst_mask); void Finalize (); @@ -417,10 +438,20 @@ protected: assert (m_did_finalize); return &m_option_defs[0]; } - typedef std::vector OptionGroupsType; + struct OptionInfo + { + OptionInfo (OptionGroup* g, uint32_t i) : + option_group (g), + option_index (i) + { + } + OptionGroup* option_group; // The group that this option came from + uint32_t option_index; // The original option index from the OptionGroup + }; + typedef std::vector OptionInfos; std::vector m_option_defs; - OptionGroupsType m_option_groups; + OptionInfos m_option_infos; bool m_did_finalize; }; diff --git a/lldb/include/lldb/Target/Platform.h b/lldb/include/lldb/Target/Platform.h index 0da89f206316..084a21eeb0af 100644 --- a/lldb/include/lldb/Target/Platform.h +++ b/lldb/include/lldb/Target/Platform.h @@ -57,6 +57,9 @@ namespace lldb_private { static lldb::PlatformSP GetDefaultPlatform (); + static const char * + GetHostPlatformName (); + static void SetDefaultPlatform (const lldb::PlatformSP &platform_sp); diff --git a/lldb/include/lldb/lldb-enumerations.h b/lldb/include/lldb/lldb-enumerations.h index 6e055ab751de..7f3b30a374c5 100644 --- a/lldb/include/lldb/lldb-enumerations.h +++ b/lldb/include/lldb/lldb-enumerations.h @@ -387,6 +387,7 @@ namespace lldb { eArgTypeValue, eArgTypeWidth, eArgTypeNone, + eArgTypePlatform, eArgTypeLastArg // Always keep this entry as the last entry in this enumeration!! } CommandArgumentType; diff --git a/lldb/include/lldb/lldb-private-types.h b/lldb/include/lldb/lldb-private-types.h index 653e64753009..50bd3d684753 100644 --- a/lldb/include/lldb/lldb-private-types.h +++ b/lldb/include/lldb/lldb-private-types.h @@ -59,7 +59,7 @@ namespace lldb_private char short_option; // Single character for this option. int option_has_arg; // no_argument, required_argument or optional_argument OptionEnumValueElement *enum_values; // If non-NULL an array of enum values. - uint32_t completionType; // Cookie the option class can use to do define the argument completion. + uint32_t completion_type; // Cookie the option class can use to do define the argument completion. lldb::CommandArgumentType argument_type; // Type of argument this option takes const char * usage_text; // Full text explaining what this options does and what (if any) argument to // pass it. diff --git a/lldb/source/Commands/CommandCompletions.cpp b/lldb/source/Commands/CommandCompletions.cpp index fcfc29b4e88f..e57a8b416858 100644 --- a/lldb/source/Commands/CommandCompletions.cpp +++ b/lldb/source/Commands/CommandCompletions.cpp @@ -20,6 +20,7 @@ // Project includes #include "lldb/Host/FileSpec.h" #include "lldb/Core/FileSpecList.h" +#include "lldb/Core/PluginManager.h" #include "lldb/Interpreter/Args.h" #include "lldb/Interpreter/CommandCompletions.h" #include "lldb/Interpreter/CommandInterpreter.h" @@ -38,6 +39,8 @@ CommandCompletions::g_common_completions[] = {eSymbolCompletion, CommandCompletions::Symbols}, {eModuleCompletion, CommandCompletions::Modules}, {eSettingsNameCompletion, CommandCompletions::SettingsNames}, + {ePlatformPluginCompletion, CommandCompletions::PlatformPluginNames}, + {eArchitectureCompletion, CommandCompletions::ArchitectureNames}, {eNoCompletion, NULL} // This one has to be last in the list. }; @@ -413,6 +416,36 @@ CommandCompletions::SettingsNames (CommandInterpreter &interpreter, //return matches.GetSize(); } + +int +CommandCompletions::PlatformPluginNames (CommandInterpreter &interpreter, + const char *partial_name, + int match_start_point, + int max_return_elements, + SearchFilter *searcher, + bool &word_complete, + lldb_private::StringList &matches) +{ + const uint32_t num_matches = PluginManager::AutoCompletePlatformName(partial_name, matches); + word_complete = num_matches == 1; + return num_matches; +} + +int +CommandCompletions::ArchitectureNames (CommandInterpreter &interpreter, + const char *partial_name, + int match_start_point, + int max_return_elements, + SearchFilter *searcher, + bool &word_complete, + lldb_private::StringList &matches) +{ + const uint32_t num_matches = ArchSpec::AutoComplete (partial_name, matches); + word_complete = num_matches == 1; + return num_matches; +} + + CommandCompletions::Completer::Completer ( CommandInterpreter &interpreter, diff --git a/lldb/source/Commands/CommandObjectFile.cpp b/lldb/source/Commands/CommandObjectFile.cpp index 372baf9e8229..563cbe298dc8 100644 --- a/lldb/source/Commands/CommandObjectFile.cpp +++ b/lldb/source/Commands/CommandObjectFile.cpp @@ -26,7 +26,6 @@ using namespace lldb; using namespace lldb_private; FileOptionGroup::FileOptionGroup() : - m_arch (), m_arch_str () { } @@ -53,6 +52,17 @@ FileOptionGroup::GetDefinitions () return g_file_option_table; } +bool +FileOptionGroup::GetArchitecture (Platform *platform, ArchSpec &arch) +{ + if (m_arch_str.empty()) + arch.Clear(); + else + arch.SetTriple(m_arch_str.c_str(), platform); + return arch.IsValid(); +} + + Error FileOptionGroup::SetOptionValue (CommandInterpreter &interpreter, uint32_t option_idx, @@ -64,17 +74,7 @@ FileOptionGroup::SetOptionValue (CommandInterpreter &interpreter, switch (short_option) { case 'a': - { - // Save the arch value in case we specify a platform after specifying the arch - m_arch_str.assign (option_arg); - // Check to see if we already have a platform? - m_arch_platform_sp = interpreter.GetPlatform (false); - ArchSpec option_arch (option_arg, m_arch_platform_sp.get()); - if (option_arch.IsValid()) - m_arch = option_arch; - else - error.SetErrorStringWithFormat ("Invalid arch string '%s'.\n", option_arg); - } + m_arch_str.assign (option_arg); break; default: @@ -88,26 +88,7 @@ FileOptionGroup::SetOptionValue (CommandInterpreter &interpreter, void FileOptionGroup::OptionParsingStarting (CommandInterpreter &interpreter) { - m_arch.Clear(); -} - -Error -FileOptionGroup::OptionParsingFinished (CommandInterpreter &interpreter) -{ - Error error; - if (m_arch.IsValid()) - { - PlatformSP curr_platform_sp (interpreter.GetPlatform (false)); - if (curr_platform_sp.get() != m_arch_platform_sp.get()) - { - ArchSpec option_arch (m_arch_str.c_str(), curr_platform_sp.get()); - if (option_arch.IsValid()) - m_arch = option_arch; - else - error.SetErrorStringWithFormat ("invalid arch '%s' for platform '%s'", m_arch_str.c_str(), curr_platform_sp->GetName()); - } - } - return error; + m_arch_str.clear(); } //------------------------------------------------------------------------- @@ -136,8 +117,8 @@ CommandObjectFile::CommandObjectFile(CommandInterpreter &interpreter) : // Push the data for the first argument into the m_arguments vector. m_arguments.push_back (arg); - m_option_group.Append (&m_file_options); - m_option_group.Append (&m_platform_options); + m_option_group.Append (&m_file_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); + m_option_group.Append (&m_platform_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); m_option_group.Finalize(); } @@ -164,18 +145,46 @@ CommandObjectFile::Execute if (argc == 1) { FileSpec file_spec (file_path, true); + + bool select = true; + PlatformSP platform_sp; + + Error error; + + if (!m_platform_options.platform_name.empty()) + { + platform_sp = m_platform_options.CreatePlatformWithOptions(m_interpreter, select, error); + if (!platform_sp) + { + result.AppendError(error.AsCString()); + result.SetStatus (eReturnStatusFailed); + return false; + } + } + ArchSpec file_arch; + + if (!m_file_options.m_arch_str.empty()) + { + if (!platform_sp) + platform_sp = m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform(); + if (!m_file_options.GetArchitecture(platform_sp.get(), file_arch)) + { + result.AppendErrorWithFormat("invalid architecture '%s'", m_file_options.m_arch_str.c_str()); + result.SetStatus (eReturnStatusFailed); + return false; + } + } if (! file_spec.Exists() && !file_spec.ResolveExecutableLocation()) { result.AppendErrorWithFormat ("File '%s' does not exist.\n", file_path); result.SetStatus (eReturnStatusFailed); - return result.Succeeded(); + return false; } TargetSP target_sp; - Debugger &debugger = m_interpreter.GetDebugger(); - Error error = debugger.GetTargetList().CreateTarget (debugger, file_spec, m_file_options.m_arch, true, target_sp); + error = debugger.GetTargetList().CreateTarget (debugger, file_spec, file_arch, true, target_sp); if (target_sp) { diff --git a/lldb/source/Commands/CommandObjectFile.h b/lldb/source/Commands/CommandObjectFile.h index 1af88964f526..f3ef2d94a15f 100644 --- a/lldb/source/Commands/CommandObjectFile.h +++ b/lldb/source/Commands/CommandObjectFile.h @@ -26,37 +26,35 @@ namespace lldb_private { // CommandObjectFile //------------------------------------------------------------------------- - class FileOptionGroup : public OptionGroup - { - public: - - FileOptionGroup (); - - virtual - ~FileOptionGroup (); +class FileOptionGroup : public OptionGroup +{ +public: + + FileOptionGroup (); + + virtual + ~FileOptionGroup (); - - virtual uint32_t - GetNumDefinitions (); - - virtual const OptionDefinition* - GetDefinitions (); - - virtual Error - SetOptionValue (CommandInterpreter &interpreter, - uint32_t option_idx, - const char *option_value); - - virtual void - OptionParsingStarting (CommandInterpreter &interpreter); - - virtual Error - OptionParsingFinished (CommandInterpreter &interpreter); - - ArchSpec m_arch; - lldb::PlatformSP m_arch_platform_sp; // The platform that was used to resolve m_arch - std::string m_arch_str; // Save the arch triple in case a platform is specified after the architecture - }; + + virtual uint32_t + GetNumDefinitions (); + + virtual const OptionDefinition* + GetDefinitions (); + + virtual Error + SetOptionValue (CommandInterpreter &interpreter, + uint32_t option_idx, + const char *option_value); + + virtual void + OptionParsingStarting (CommandInterpreter &interpreter); + + bool + GetArchitecture (Platform *platform, ArchSpec &arch); + + std::string m_arch_str; // Save the arch triple in case a platform is specified after the architecture +}; class CommandObjectFile : public CommandObject { diff --git a/lldb/source/Commands/CommandObjectLog.cpp b/lldb/source/Commands/CommandObjectLog.cpp index e38b618bdb32..7dcfabc6617c 100644 --- a/lldb/source/Commands/CommandObjectLog.cpp +++ b/lldb/source/Commands/CommandObjectLog.cpp @@ -42,16 +42,6 @@ using namespace lldb; using namespace lldb_private; -static LogChannelSP -GetLogChannelPluginForChannel (const char *channel) -{ - std::string log_channel_plugin_name(channel); - log_channel_plugin_name += LogChannel::GetPluginSuffix(); - LogChannelSP log_channel_sp (LogChannel::FindPlugin (log_channel_plugin_name.c_str())); - return log_channel_sp; -} - - class CommandObjectLogEnable : public CommandObject { public: @@ -99,6 +89,27 @@ public: return &m_options; } +// int +// HandleArgumentCompletion (Args &input, +// int &cursor_index, +// int &cursor_char_position, +// OptionElementVector &opt_element_vector, +// int match_start_point, +// int max_return_elements, +// bool &word_complete, +// StringList &matches) +// { +// std::string completion_str (input.GetArgumentAtIndex(cursor_index)); +// completion_str.erase (cursor_char_position); +// +// if (cursor_index == 1) +// { +// // +// Log::AutoCompleteChannelName (completion_str.c_str(), matches); +// } +// return matches.GetSize(); +// } +// virtual bool Execute (Args& args, CommandReturnObject &result) @@ -141,7 +152,7 @@ public: } else { - LogChannelSP log_channel_sp (GetLogChannelPluginForChannel(channel.c_str())); + LogChannelSP log_channel_sp (LogChannel::FindPlugin (channel.c_str())); if (log_channel_sp) { if (log_channel_sp->Enable (log_stream_sp, log_options, &result.GetErrorStream(), args)) @@ -314,7 +325,7 @@ public: } else { - LogChannelSP log_channel_sp (GetLogChannelPluginForChannel(channel.c_str())); + LogChannelSP log_channel_sp (LogChannel::FindPlugin(channel.c_str())); if (log_channel_sp) { log_channel_sp->Disable(args, &result.GetErrorStream()); @@ -388,7 +399,7 @@ public: } else { - LogChannelSP log_channel_sp (GetLogChannelPluginForChannel(channel.c_str())); + LogChannelSP log_channel_sp (LogChannel::FindPlugin(channel.c_str())); if (log_channel_sp) { log_channel_sp->ListCategories(&result.GetOutputStream()); diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp index 46a53c7139ef..252865162a03 100644 --- a/lldb/source/Commands/CommandObjectPlatform.cpp +++ b/lldb/source/Commands/CommandObjectPlatform.cpp @@ -29,44 +29,31 @@ using namespace lldb_private; PlatformSP -PlatformOptionGroup::CreatePlatformWithOptions (CommandInterpreter &interpreter, - const char *platform_name, - bool select, - Error& error) +PlatformOptionGroup::CreatePlatformWithOptions (CommandInterpreter &interpreter, bool select, Error& error) { - if (platform_name && platform_name[0]) + PlatformSP platform_sp; + if (!platform_name.empty()) { - if (platform_sp) - { - error.SetErrorString ("platform can't be set more than once in a command"); - return PlatformSP(); - } - - platform_sp = Platform::Create (platform_name, error); + platform_sp = Platform::Create (platform_name.c_str(), error); if (platform_sp) { - interpreter.GetDebugger().GetPlatformList().Append (platform_sp, select); - if (os_version_major != UINT32_MAX) - { - platform_sp->SetOSVersion (os_version_major, - os_version_minor, - os_version_update); - } + interpreter.GetDebugger().GetPlatformList().Append (platform_sp, select); + if (os_version_major != UINT32_MAX) + { + platform_sp->SetOSVersion (os_version_major, + os_version_minor, + os_version_update); + } } } - else - { - error.SetErrorString ("invalid platform name"); - platform_sp.reset(); - } return platform_sp; } void PlatformOptionGroup::OptionParsingStarting (CommandInterpreter &interpreter) { - platform_sp.reset(); + platform_name.clear(); os_version_major = UINT32_MAX; os_version_minor = UINT32_MAX; os_version_update = UINT32_MAX; @@ -75,7 +62,7 @@ PlatformOptionGroup::OptionParsingStarting (CommandInterpreter &interpreter) static OptionDefinition g_option_table[] = { - { LLDB_OPT_SET_ALL, false, "platform" , 'p', required_argument, NULL, 0, eArgTypeNone, "Specify name of the platform to use for this target, creating the platform if necessary."}, + { LLDB_OPT_SET_ALL, false, "platform" , 'p', required_argument, NULL, 0, eArgTypePlatform, "Specify name of the platform to use for this target, creating the platform if necessary."}, { LLDB_OPT_SET_ALL, false, "sdk-version", 'v', required_argument, NULL, 0, eArgTypeNone, "Specify the initial SDK version to use prior to connecting." } }; @@ -112,19 +99,12 @@ PlatformOptionGroup::SetOptionValue (CommandInterpreter &interpreter, switch (short_option) { case 'p': - CreatePlatformWithOptions (interpreter, option_arg, true, error); + platform_name.assign (option_arg); break; case 'v': if (Args::StringToVersion (option_arg, os_version_major, os_version_minor, os_version_update) == option_arg) - { error.SetErrorStringWithFormat ("invalid version string '%s'", option_arg); - } - else - { - if (platform_sp) - platform_sp->SetOSVersion (os_version_major, os_version_minor, os_version_update); - } break; default: @@ -149,7 +129,7 @@ public: m_option_group (interpreter), m_platform_options (false) // Don't include the "--platform" option by passing false { - m_option_group.Append (&m_platform_options); + m_option_group.Append (&m_platform_options, LLDB_OPT_SET_ALL, 1); m_option_group.Finalize(); } @@ -161,16 +141,31 @@ public: virtual bool Execute (Args& args, CommandReturnObject &result) { - Error error; if (args.GetArgumentCount() == 1) { - const bool select = true; - PlatformSP platform_sp (m_platform_options.CreatePlatformWithOptions (m_interpreter, - args.GetArgumentAtIndex (0), - select, - error)); - if (platform_sp) - platform_sp->GetStatus (result.GetOutputStream()); + const char *platform_name = args.GetArgumentAtIndex (0); + if (platform_name && platform_name[0]) + { + const bool select = true; + m_platform_options.platform_name.assign (platform_name); + Error error; + PlatformSP platform_sp (m_platform_options.CreatePlatformWithOptions (m_interpreter, select, error)); + if (platform_sp) + { + platform_sp->GetStatus (result.GetOutputStream()); + result.SetStatus (eReturnStatusSuccessFinishResult); + } + else + { + result.AppendError(error.AsCString()); + result.SetStatus (eReturnStatusFailed); + } + } + else + { + result.AppendError ("invalid platform name"); + result.SetStatus (eReturnStatusFailed); + } } else { diff --git a/lldb/source/Commands/CommandObjectPlatform.h b/lldb/source/Commands/CommandObjectPlatform.h index 255fc3bb911f..00199158666d 100644 --- a/lldb/source/Commands/CommandObjectPlatform.h +++ b/lldb/source/Commands/CommandObjectPlatform.h @@ -49,11 +49,11 @@ class PlatformOptionGroup : public OptionGroup public: PlatformOptionGroup (bool include_platform_option) : - m_include_platform_option (include_platform_option), - platform_sp (), + platform_name (), os_version_major (UINT32_MAX), os_version_minor (UINT32_MAX), - os_version_update (UINT32_MAX) + os_version_update (UINT32_MAX), + m_include_platform_option (include_platform_option) { } @@ -74,17 +74,16 @@ public: const char *option_value); lldb::PlatformSP - CreatePlatformWithOptions (CommandInterpreter &interpreter, - const char *platform_name, - bool select, - Error& error); + CreatePlatformWithOptions (CommandInterpreter &interpreter, + bool select, + Error &error); virtual void OptionParsingStarting (CommandInterpreter &interpreter); // Instance variables to hold the values for command options. - lldb::PlatformSP platform_sp; + std::string platform_name; uint32_t os_version_major; uint32_t os_version_minor; uint32_t os_version_update; diff --git a/lldb/source/Core/ArchSpec.cpp b/lldb/source/Core/ArchSpec.cpp index e573b99fd9cd..45567328e53f 100644 --- a/lldb/source/Core/ArchSpec.cpp +++ b/lldb/source/Core/ArchSpec.cpp @@ -79,11 +79,11 @@ static const CoreDefinition g_core_definitions[ArchSpec::kNumCores] = { eByteOrderLittle, 4, 4, 4, llvm::Triple::sparc , ArchSpec::eCore_sparc_generic , "sparc" }, { eByteOrderLittle, 8, 4, 4, llvm::Triple::sparcv9, ArchSpec::eCore_sparc9_generic , "sparcv9" }, - { eByteOrderLittle, 4, 1, 15, llvm::Triple::x86 , ArchSpec::eCore_x86_32_i386 , "i386" }, - { eByteOrderLittle, 4, 1, 15, llvm::Triple::x86 , ArchSpec::eCore_x86_32_i486 , "i486" }, - { eByteOrderLittle, 4, 1, 15, llvm::Triple::x86 , ArchSpec::eCore_x86_32_i486sx , "i486sx" }, + { eByteOrderLittle, 4, 1, 15, llvm::Triple::x86 , ArchSpec::eCore_x86_32_i386 , "i386" }, + { eByteOrderLittle, 4, 1, 15, llvm::Triple::x86 , ArchSpec::eCore_x86_32_i486 , "i486" }, + { eByteOrderLittle, 4, 1, 15, llvm::Triple::x86 , ArchSpec::eCore_x86_32_i486sx , "i486sx" }, - { eByteOrderLittle, 8, 1, 15, llvm::Triple::x86_64 , ArchSpec::eCore_x86_64_x86_64 , "x86_64" } + { eByteOrderLittle, 8, 1, 15, llvm::Triple::x86_64 , ArchSpec::eCore_x86_64_x86_64 , "x86_64" } }; struct ArchDefinitionEntry @@ -104,6 +104,28 @@ struct ArchDefinition }; +uint32_t +ArchSpec::AutoComplete (const char *name, StringList &matches) +{ + uint32_t i; + if (name && name[0]) + { + for (i = 0; i < ArchSpec::kNumCores; ++i) + { + if (NameMatches(g_core_definitions[i].name, eNameMatchStartsWith, name)) + matches.AppendString (g_core_definitions[i].name); + } + } + else + { + for (i = 0; i < ArchSpec::kNumCores; ++i) + matches.AppendString (g_core_definitions[i].name); + } + return matches.GetSize(); +} + + + #define CPU_ANY (UINT32_MAX) //===----------------------------------------------------------------------===// diff --git a/lldb/source/Core/Log.cpp b/lldb/source/Core/Log.cpp index 1b5c74acf031..f537f1ea2bc5 100644 --- a/lldb/source/Core/Log.cpp +++ b/lldb/source/Core/Log.cpp @@ -381,6 +381,27 @@ Log::EnableAllLogChannels } +void +Log::AutoCompleteChannelName (const char *channel_name, StringList &matches) +{ + LogChannelMap &map = GetChannelMap (); + LogChannelMapIter pos, end = map.end(); + for (pos = map.begin(); pos != end; ++pos) + { + const char *pos_channel_name = pos->first.GetCString(); + if (channel_name && channel_name[0]) + { + if (NameMatches (channel_name, eNameMatchStartsWith, pos_channel_name)) + { + matches.AppendString(pos_channel_name); + } + } + else + matches.AppendString(pos_channel_name); + + } +} + void Log::DisableAllLogChannels (Stream *feedback_strm) { @@ -499,10 +520,4 @@ LogChannel::~LogChannel () { } -const char * -LogChannel::GetPluginSuffix () -{ - return ".log-channel"; -} - diff --git a/lldb/source/Core/PluginManager.cpp b/lldb/source/Core/PluginManager.cpp index ae89c72b9ab5..aff9b2b19736 100644 --- a/lldb/source/Core/PluginManager.cpp +++ b/lldb/source/Core/PluginManager.cpp @@ -19,6 +19,8 @@ #include "lldb/Host/Host.h" #include "lldb/Host/Mutex.h" +#include "llvm/ADT/StringRef.h" + using namespace lldb; using namespace lldb_private; @@ -256,7 +258,7 @@ PluginManager::RegisterPlugin { ABIInstance instance; assert (name && name[0]); - instance.name = name; + instance.name.assign (name); if (description && description[0]) instance.description = description; instance.create_callback = create_callback; @@ -293,7 +295,6 @@ PluginManager::GetABICreateCallbackAtIndex (uint32_t idx) { Mutex::Locker locker (GetABIInstancesMutex ()); ABIInstances &instances = GetABIInstances (); - if (idx < instances.size()) return instances[idx].create_callback; return NULL; @@ -305,13 +306,13 @@ PluginManager::GetABICreateCallbackForPluginName (const char *name) if (name && name[0]) { Mutex::Locker locker (GetABIInstancesMutex ()); - std::string ss_name(name); + llvm::StringRef name_sref(name); ABIInstances &instances = GetABIInstances (); ABIInstances::iterator pos, end = instances.end(); for (pos = instances.begin(); pos != end; ++ pos) { - if (pos->name == ss_name) + if (name_sref.equals (pos->name)) return pos->create_callback; } } @@ -338,50 +339,19 @@ struct DisassemblerInstance typedef std::vector DisassemblerInstances; -static bool -AccessDisassemblerInstances (PluginAction action, DisassemblerInstance &instance, uint32_t index) +static Mutex & +GetDisassemblerMutex () { - static DisassemblerInstances g_plugin_instances; - - switch (action) - { - case ePluginRegisterInstance: - if (instance.create_callback) - { - g_plugin_instances.push_back (instance); - return true; - } - break; - - case ePluginUnregisterInstance: - if (instance.create_callback) - { - DisassemblerInstances::iterator pos, end = g_plugin_instances.end(); - for (pos = g_plugin_instances.begin(); pos != end; ++ pos) - { - if (pos->create_callback == instance.create_callback) - { - g_plugin_instances.erase(pos); - return true; - } - } - } - break; - - case ePluginGetInstanceAtIndex: - if (index < g_plugin_instances.size()) - { - instance = g_plugin_instances[index]; - return true; - } - break; - - default: - break; - } - return false; + static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + return g_instances_mutex; } +static DisassemblerInstances & +GetDisassemblerInstances () +{ + static DisassemblerInstances g_instances; + return g_instances; +} bool PluginManager::RegisterPlugin @@ -399,7 +369,9 @@ PluginManager::RegisterPlugin if (description && description[0]) instance.description = description; instance.create_callback = create_callback; - return AccessDisassemblerInstances (ePluginRegisterInstance, instance, 0); + Mutex::Locker locker (GetDisassemblerMutex ()); + GetDisassemblerInstances ().push_back (instance); + return true; } return false; } @@ -409,9 +381,18 @@ PluginManager::UnregisterPlugin (DisassemblerCreateInstance create_callback) { if (create_callback) { - DisassemblerInstance instance; - instance.create_callback = create_callback; - return AccessDisassemblerInstances (ePluginUnregisterInstance, instance, 0); + Mutex::Locker locker (GetDisassemblerMutex ()); + DisassemblerInstances &instances = GetDisassemblerInstances (); + + DisassemblerInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) + { + if (pos->create_callback == create_callback) + { + instances.erase(pos); + return true; + } + } } return false; } @@ -419,9 +400,10 @@ PluginManager::UnregisterPlugin (DisassemblerCreateInstance create_callback) DisassemblerCreateInstance PluginManager::GetDisassemblerCreateCallbackAtIndex (uint32_t idx) { - DisassemblerInstance instance; - if (AccessDisassemblerInstances (ePluginGetInstanceAtIndex, instance, idx)) - return instance.create_callback; + Mutex::Locker locker (GetDisassemblerMutex ()); + DisassemblerInstances &instances = GetDisassemblerInstances (); + if (idx < instances.size()) + return instances[idx].create_callback; return NULL; } @@ -430,12 +412,15 @@ PluginManager::GetDisassemblerCreateCallbackForPluginName (const char *name) { if (name && name[0]) { - DisassemblerInstance instance; - std::string ss_name(name); - for (uint32_t idx = 0; AccessDisassemblerInstances (ePluginGetInstanceAtIndex, instance, idx); ++idx) + llvm::StringRef name_sref(name); + Mutex::Locker locker (GetDisassemblerMutex ()); + DisassemblerInstances &instances = GetDisassemblerInstances (); + + DisassemblerInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) { - if (instance.name == ss_name) - return instance.create_callback; + if (name_sref.equals (pos->name)) + return pos->create_callback; } } return NULL; @@ -462,48 +447,19 @@ struct DynamicLoaderInstance typedef std::vector DynamicLoaderInstances; -static bool -AccessDynamicLoaderInstances (PluginAction action, DynamicLoaderInstance &instance, uint32_t index) + +static Mutex & +GetDynamicLoaderMutex () { - static DynamicLoaderInstances g_plugin_instances; + static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + return g_instances_mutex; +} - switch (action) - { - case ePluginRegisterInstance: - if (instance.create_callback) - { - g_plugin_instances.push_back (instance); - return true; - } - break; - - case ePluginUnregisterInstance: - if (instance.create_callback) - { - DynamicLoaderInstances::iterator pos, end = g_plugin_instances.end(); - for (pos = g_plugin_instances.begin(); pos != end; ++ pos) - { - if (pos->create_callback == instance.create_callback) - { - g_plugin_instances.erase(pos); - return true; - } - } - } - break; - - case ePluginGetInstanceAtIndex: - if (index < g_plugin_instances.size()) - { - instance = g_plugin_instances[index]; - return true; - } - break; - - default: - break; - } - return false; +static DynamicLoaderInstances & +GetDynamicLoaderInstances () +{ + static DynamicLoaderInstances g_instances; + return g_instances; } @@ -523,7 +479,8 @@ PluginManager::RegisterPlugin if (description && description[0]) instance.description = description; instance.create_callback = create_callback; - return AccessDynamicLoaderInstances (ePluginRegisterInstance, instance, 0); + Mutex::Locker locker (GetDynamicLoaderMutex ()); + GetDynamicLoaderInstances ().push_back (instance); } return false; } @@ -533,9 +490,18 @@ PluginManager::UnregisterPlugin (DynamicLoaderCreateInstance create_callback) { if (create_callback) { - DynamicLoaderInstance instance; - instance.create_callback = create_callback; - return AccessDynamicLoaderInstances (ePluginUnregisterInstance, instance, 0); + Mutex::Locker locker (GetDynamicLoaderMutex ()); + DynamicLoaderInstances &instances = GetDynamicLoaderInstances (); + + DynamicLoaderInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) + { + if (pos->create_callback == create_callback) + { + instances.erase(pos); + return true; + } + } } return false; } @@ -543,9 +509,10 @@ PluginManager::UnregisterPlugin (DynamicLoaderCreateInstance create_callback) DynamicLoaderCreateInstance PluginManager::GetDynamicLoaderCreateCallbackAtIndex (uint32_t idx) { - DynamicLoaderInstance instance; - if (AccessDynamicLoaderInstances (ePluginGetInstanceAtIndex, instance, idx)) - return instance.create_callback; + Mutex::Locker locker (GetDynamicLoaderMutex ()); + DynamicLoaderInstances &instances = GetDynamicLoaderInstances (); + if (idx < instances.size()) + return instances[idx].create_callback; return NULL; } @@ -554,12 +521,15 @@ PluginManager::GetDynamicLoaderCreateCallbackForPluginName (const char *name) { if (name && name[0]) { - DynamicLoaderInstance instance; - std::string ss_name(name); - for (uint32_t idx = 0; AccessDynamicLoaderInstances (ePluginGetInstanceAtIndex, instance, idx); ++idx) + llvm::StringRef name_sref(name); + Mutex::Locker locker (GetDynamicLoaderMutex ()); + DynamicLoaderInstances &instances = GetDynamicLoaderInstances (); + + DynamicLoaderInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) { - if (instance.name == ss_name) - return instance.create_callback; + if (name_sref.equals (pos->name)) + return pos->create_callback; } } return NULL; @@ -584,48 +554,18 @@ struct EmulateInstructionInstance typedef std::vector EmulateInstructionInstances; -static bool -AccessEmulateInstructionInstances (PluginAction action, EmulateInstructionInstance &instance, uint32_t index) +static Mutex & +GetEmulateInstructionMutex () { - static EmulateInstructionInstances g_plugin_instances; - - switch (action) - { - case ePluginRegisterInstance: - if (instance.create_callback) - { - g_plugin_instances.push_back (instance); - return true; - } - break; - - case ePluginUnregisterInstance: - if (instance.create_callback) - { - EmulateInstructionInstances::iterator pos, end = g_plugin_instances.end(); - for (pos = g_plugin_instances.begin(); pos != end; ++ pos) - { - if (pos->create_callback == instance.create_callback) - { - g_plugin_instances.erase(pos); - return true; - } - } - } - break; - - case ePluginGetInstanceAtIndex: - if (index < g_plugin_instances.size()) - { - instance = g_plugin_instances[index]; - return true; - } - break; - - default: - break; - } - return false; + static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + return g_instances_mutex; +} + +static EmulateInstructionInstances & +GetEmulateInstructionInstances () +{ + static EmulateInstructionInstances g_instances; + return g_instances; } @@ -645,7 +585,8 @@ PluginManager::RegisterPlugin if (description && description[0]) instance.description = description; instance.create_callback = create_callback; - return AccessEmulateInstructionInstances (ePluginRegisterInstance, instance, 0); + Mutex::Locker locker (GetEmulateInstructionMutex ()); + GetEmulateInstructionInstances ().push_back (instance); } return false; } @@ -655,9 +596,18 @@ PluginManager::UnregisterPlugin (EmulateInstructionCreateInstance create_callbac { if (create_callback) { - EmulateInstructionInstance instance; - instance.create_callback = create_callback; - return AccessEmulateInstructionInstances (ePluginUnregisterInstance, instance, 0); + Mutex::Locker locker (GetEmulateInstructionMutex ()); + EmulateInstructionInstances &instances = GetEmulateInstructionInstances (); + + EmulateInstructionInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) + { + if (pos->create_callback == create_callback) + { + instances.erase(pos); + return true; + } + } } return false; } @@ -665,9 +615,10 @@ PluginManager::UnregisterPlugin (EmulateInstructionCreateInstance create_callbac EmulateInstructionCreateInstance PluginManager::GetEmulateInstructionCreateCallbackAtIndex (uint32_t idx) { - EmulateInstructionInstance instance; - if (AccessEmulateInstructionInstances (ePluginGetInstanceAtIndex, instance, idx)) - return instance.create_callback; + Mutex::Locker locker (GetEmulateInstructionMutex ()); + EmulateInstructionInstances &instances = GetEmulateInstructionInstances (); + if (idx < instances.size()) + return instances[idx].create_callback; return NULL; } @@ -676,12 +627,15 @@ PluginManager::GetEmulateInstructionCreateCallbackForPluginName (const char *nam { if (name && name[0]) { - EmulateInstructionInstance instance; - std::string ss_name(name); - for (uint32_t idx = 0; AccessEmulateInstructionInstances (ePluginGetInstanceAtIndex, instance, idx); ++idx) + llvm::StringRef name_sref(name); + Mutex::Locker locker (GetEmulateInstructionMutex ()); + EmulateInstructionInstances &instances = GetEmulateInstructionInstances (); + + EmulateInstructionInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) { - if (instance.name == ss_name) - return instance.create_callback; + if (name_sref.equals (pos->name)) + return pos->create_callback; } } return NULL; @@ -707,50 +661,19 @@ struct LanguageRuntimeInstance typedef std::vector LanguageRuntimeInstances; -static bool -AccessLanguageRuntimeInstances (PluginAction action, LanguageRuntimeInstance &instance, uint32_t index) +static Mutex & +GetLanguageRuntimeMutex () { - static LanguageRuntimeInstances g_plugin_instances; - - switch (action) - { - case ePluginRegisterInstance: - if (instance.create_callback) - { - g_plugin_instances.push_back (instance); - return true; - } - break; - - case ePluginUnregisterInstance: - if (instance.create_callback) - { - LanguageRuntimeInstances::iterator pos, end = g_plugin_instances.end(); - for (pos = g_plugin_instances.begin(); pos != end; ++ pos) - { - if (pos->create_callback == instance.create_callback) - { - g_plugin_instances.erase(pos); - return true; - } - } - } - break; - - case ePluginGetInstanceAtIndex: - if (index < g_plugin_instances.size()) - { - instance = g_plugin_instances[index]; - return true; - } - break; - - default: - break; - } - return false; + static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + return g_instances_mutex; } +static LanguageRuntimeInstances & +GetLanguageRuntimeInstances () +{ + static LanguageRuntimeInstances g_instances; + return g_instances; +} bool PluginManager::RegisterPlugin @@ -768,7 +691,8 @@ PluginManager::RegisterPlugin if (description && description[0]) instance.description = description; instance.create_callback = create_callback; - return AccessLanguageRuntimeInstances (ePluginRegisterInstance, instance, 0); + Mutex::Locker locker (GetLanguageRuntimeMutex ()); + GetLanguageRuntimeInstances ().push_back (instance); } return false; } @@ -778,9 +702,18 @@ PluginManager::UnregisterPlugin (LanguageRuntimeCreateInstance create_callback) { if (create_callback) { - LanguageRuntimeInstance instance; - instance.create_callback = create_callback; - return AccessLanguageRuntimeInstances (ePluginUnregisterInstance, instance, 0); + Mutex::Locker locker (GetLanguageRuntimeMutex ()); + LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances (); + + LanguageRuntimeInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) + { + if (pos->create_callback == create_callback) + { + instances.erase(pos); + return true; + } + } } return false; } @@ -788,9 +721,10 @@ PluginManager::UnregisterPlugin (LanguageRuntimeCreateInstance create_callback) LanguageRuntimeCreateInstance PluginManager::GetLanguageRuntimeCreateCallbackAtIndex (uint32_t idx) { - LanguageRuntimeInstance instance; - if (AccessLanguageRuntimeInstances (ePluginGetInstanceAtIndex, instance, idx)) - return instance.create_callback; + Mutex::Locker locker (GetLanguageRuntimeMutex ()); + LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances (); + if (idx < instances.size()) + return instances[idx].create_callback; return NULL; } @@ -799,12 +733,15 @@ PluginManager::GetLanguageRuntimeCreateCallbackForPluginName (const char *name) { if (name && name[0]) { - LanguageRuntimeInstance instance; - std::string ss_name(name); - for (uint32_t idx = 0; AccessLanguageRuntimeInstances (ePluginGetInstanceAtIndex, instance, idx); ++idx) + llvm::StringRef name_sref(name); + Mutex::Locker locker (GetLanguageRuntimeMutex ()); + LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances (); + + LanguageRuntimeInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) { - if (instance.name == ss_name) - return instance.create_callback; + if (name_sref.equals (pos->name)) + return pos->create_callback; } } return NULL; @@ -828,48 +765,18 @@ struct ObjectFileInstance typedef std::vector ObjectFileInstances; -static bool -AccessObjectFileInstances (PluginAction action, ObjectFileInstance &instance, uint32_t index) +static Mutex & +GetObjectFileMutex () { - static ObjectFileInstances g_plugin_instances; + static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + return g_instances_mutex; +} - switch (action) - { - case ePluginRegisterInstance: - if (instance.create_callback) - { - g_plugin_instances.push_back (instance); - return true; - } - break; - - case ePluginUnregisterInstance: - if (instance.create_callback) - { - ObjectFileInstances::iterator pos, end = g_plugin_instances.end(); - for (pos = g_plugin_instances.begin(); pos != end; ++ pos) - { - if (pos->create_callback == instance.create_callback) - { - g_plugin_instances.erase(pos); - return true; - } - } - } - break; - - case ePluginGetInstanceAtIndex: - if (index < g_plugin_instances.size()) - { - instance = g_plugin_instances[index]; - return true; - } - break; - - default: - break; - } - return false; +static ObjectFileInstances & +GetObjectFileInstances () +{ + static ObjectFileInstances g_instances; + return g_instances; } @@ -889,7 +796,8 @@ PluginManager::RegisterPlugin if (description && description[0]) instance.description = description; instance.create_callback = create_callback; - return AccessObjectFileInstances (ePluginRegisterInstance, instance, 0); + Mutex::Locker locker (GetObjectFileMutex ()); + GetObjectFileInstances ().push_back (instance); } return false; } @@ -899,9 +807,18 @@ PluginManager::UnregisterPlugin (ObjectFileCreateInstance create_callback) { if (create_callback) { - ObjectFileInstance instance; - instance.create_callback = create_callback; - return AccessObjectFileInstances (ePluginUnregisterInstance, instance, 0); + Mutex::Locker locker (GetObjectFileMutex ()); + ObjectFileInstances &instances = GetObjectFileInstances (); + + ObjectFileInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) + { + if (pos->create_callback == create_callback) + { + instances.erase(pos); + return true; + } + } } return false; } @@ -909,22 +826,27 @@ PluginManager::UnregisterPlugin (ObjectFileCreateInstance create_callback) ObjectFileCreateInstance PluginManager::GetObjectFileCreateCallbackAtIndex (uint32_t idx) { - ObjectFileInstance instance; - if (AccessObjectFileInstances (ePluginGetInstanceAtIndex, instance, idx)) - return instance.create_callback; + Mutex::Locker locker (GetObjectFileMutex ()); + ObjectFileInstances &instances = GetObjectFileInstances (); + if (idx < instances.size()) + return instances[idx].create_callback; return NULL; } + ObjectFileCreateInstance PluginManager::GetObjectFileCreateCallbackForPluginName (const char *name) { if (name && name[0]) { - ObjectFileInstance instance; - std::string ss_name(name); - for (uint32_t idx = 0; AccessObjectFileInstances (ePluginGetInstanceAtIndex, instance, idx); ++idx) + llvm::StringRef name_sref(name); + Mutex::Locker locker (GetObjectFileMutex ()); + ObjectFileInstances &instances = GetObjectFileInstances (); + + ObjectFileInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) { - if (instance.name == ss_name) - return instance.create_callback; + if (name_sref.equals (pos->name)) + return pos->create_callback; } } return NULL; @@ -950,50 +872,19 @@ struct ObjectContainerInstance typedef std::vector ObjectContainerInstances; -static bool -AccessObjectContainerInstances (PluginAction action, ObjectContainerInstance &instance, uint32_t index) +static Mutex & +GetObjectContainerMutex () { - static ObjectContainerInstances g_plugin_instances; - - switch (action) - { - case ePluginRegisterInstance: - if (instance.create_callback) - { - g_plugin_instances.push_back (instance); - return true; - } - break; - - case ePluginUnregisterInstance: - if (instance.create_callback) - { - ObjectContainerInstances::iterator pos, end = g_plugin_instances.end(); - for (pos = g_plugin_instances.begin(); pos != end; ++ pos) - { - if (pos->create_callback == instance.create_callback) - { - g_plugin_instances.erase(pos); - return true; - } - } - } - break; - - case ePluginGetInstanceAtIndex: - if (index < g_plugin_instances.size()) - { - instance = g_plugin_instances[index]; - return true; - } - break; - - default: - break; - } - return false; + static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + return g_instances_mutex; } +static ObjectContainerInstances & +GetObjectContainerInstances () +{ + static ObjectContainerInstances g_instances; + return g_instances; +} bool PluginManager::RegisterPlugin @@ -1011,7 +902,8 @@ PluginManager::RegisterPlugin if (description && description[0]) instance.description = description; instance.create_callback = create_callback; - return AccessObjectContainerInstances (ePluginRegisterInstance, instance, 0); + Mutex::Locker locker (GetObjectContainerMutex ()); + GetObjectContainerInstances ().push_back (instance); } return false; } @@ -1021,9 +913,18 @@ PluginManager::UnregisterPlugin (ObjectContainerCreateInstance create_callback) { if (create_callback) { - ObjectContainerInstance instance; - instance.create_callback = create_callback; - return AccessObjectContainerInstances (ePluginUnregisterInstance, instance, 0); + Mutex::Locker locker (GetObjectContainerMutex ()); + ObjectContainerInstances &instances = GetObjectContainerInstances (); + + ObjectContainerInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) + { + if (pos->create_callback == create_callback) + { + instances.erase(pos); + return true; + } + } } return false; } @@ -1031,22 +932,27 @@ PluginManager::UnregisterPlugin (ObjectContainerCreateInstance create_callback) ObjectContainerCreateInstance PluginManager::GetObjectContainerCreateCallbackAtIndex (uint32_t idx) { - ObjectContainerInstance instance; - if (AccessObjectContainerInstances (ePluginGetInstanceAtIndex, instance, idx)) - return instance.create_callback; + Mutex::Locker locker (GetObjectContainerMutex ()); + ObjectContainerInstances &instances = GetObjectContainerInstances (); + if (idx < instances.size()) + return instances[idx].create_callback; return NULL; } + ObjectContainerCreateInstance PluginManager::GetObjectContainerCreateCallbackForPluginName (const char *name) { if (name && name[0]) { - ObjectContainerInstance instance; - std::string ss_name(name); - for (uint32_t idx = 0; AccessObjectContainerInstances (ePluginGetInstanceAtIndex, instance, idx); ++idx) + llvm::StringRef name_sref(name); + Mutex::Locker locker (GetObjectContainerMutex ()); + ObjectContainerInstances &instances = GetObjectContainerInstances (); + + ObjectContainerInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) { - if (instance.name == ss_name) - return instance.create_callback; + if (name_sref.equals (pos->name)) + return pos->create_callback; } } return NULL; @@ -1054,9 +960,9 @@ PluginManager::GetObjectContainerCreateCallbackForPluginName (const char *name) #pragma mark LogChannel -struct LogChannelInstance +struct LogInstance { - LogChannelInstance() : + LogInstance() : name(), description(), create_callback(NULL) @@ -1068,52 +974,23 @@ struct LogChannelInstance LogChannelCreateInstance create_callback; }; -typedef std::vector LogChannelInstances; +typedef std::vector LogInstances; -static bool -AccessLogChannelInstances (PluginAction action, LogChannelInstance &instance, uint32_t index) +static Mutex & +GetLogMutex () { - static LogChannelInstances g_plugin_instances; - - switch (action) - { - case ePluginRegisterInstance: - if (instance.create_callback) - { - g_plugin_instances.push_back (instance); - return true; - } - break; - - case ePluginUnregisterInstance: - if (instance.create_callback) - { - LogChannelInstances::iterator pos, end = g_plugin_instances.end(); - for (pos = g_plugin_instances.begin(); pos != end; ++ pos) - { - if (pos->create_callback == instance.create_callback) - { - g_plugin_instances.erase(pos); - return true; - } - } - } - break; - - case ePluginGetInstanceAtIndex: - if (index < g_plugin_instances.size()) - { - instance = g_plugin_instances[index]; - return true; - } - break; - - default: - break; - } - return false; + static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + return g_instances_mutex; } +static LogInstances & +GetLogInstances () +{ + static LogInstances g_instances; + return g_instances; +} + + bool PluginManager::RegisterPlugin @@ -1125,13 +1002,14 @@ PluginManager::RegisterPlugin { if (create_callback) { - LogChannelInstance instance; + LogInstance instance; assert (name && name[0]); instance.name = name; if (description && description[0]) instance.description = description; instance.create_callback = create_callback; - return AccessLogChannelInstances (ePluginRegisterInstance, instance, 0); + Mutex::Locker locker (GetLogMutex ()); + GetLogInstances ().push_back (instance); } return false; } @@ -1141,9 +1019,18 @@ PluginManager::UnregisterPlugin (LogChannelCreateInstance create_callback) { if (create_callback) { - LogChannelInstance instance; - instance.create_callback = create_callback; - return AccessLogChannelInstances (ePluginUnregisterInstance, instance, 0); + Mutex::Locker locker (GetLogMutex ()); + LogInstances &instances = GetLogInstances (); + + LogInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) + { + if (pos->create_callback == create_callback) + { + instances.erase(pos); + return true; + } + } } return false; } @@ -1151,9 +1038,10 @@ PluginManager::UnregisterPlugin (LogChannelCreateInstance create_callback) const char * PluginManager::GetLogChannelCreateNameAtIndex (uint32_t idx) { - LogChannelInstance instance; - if (AccessLogChannelInstances (ePluginGetInstanceAtIndex, instance, idx)) - return instance.name.c_str(); + Mutex::Locker locker (GetLogMutex ()); + LogInstances &instances = GetLogInstances (); + if (idx < instances.size()) + return instances[idx].name.c_str(); return NULL; } @@ -1161,9 +1049,10 @@ PluginManager::GetLogChannelCreateNameAtIndex (uint32_t idx) LogChannelCreateInstance PluginManager::GetLogChannelCreateCallbackAtIndex (uint32_t idx) { - LogChannelInstance instance; - if (AccessLogChannelInstances (ePluginGetInstanceAtIndex, instance, idx)) - return instance.create_callback; + Mutex::Locker locker (GetLogMutex ()); + LogInstances &instances = GetLogInstances (); + if (idx < instances.size()) + return instances[idx].create_callback; return NULL; } @@ -1172,12 +1061,15 @@ PluginManager::GetLogChannelCreateCallbackForPluginName (const char *name) { if (name && name[0]) { - LogChannelInstance instance; - std::string ss_name(name); - for (uint32_t idx = 0; AccessLogChannelInstances (ePluginGetInstanceAtIndex, instance, idx); ++idx) + llvm::StringRef name_sref(name); + Mutex::Locker locker (GetLogMutex ()); + LogInstances &instances = GetLogInstances (); + + LogInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) { - if (instance.name == ss_name) - return instance.create_callback; + if (name_sref.equals (pos->name)) + return pos->create_callback; } } return NULL; @@ -1215,6 +1107,7 @@ GetPlatformInstances () return g_platform_instances; } + bool PluginManager::RegisterPlugin (const char *name, const char *description, @@ -1240,9 +1133,9 @@ const char * PluginManager::GetPlatformPluginNameAtIndex (uint32_t idx) { Mutex::Locker locker (GetPlatformInstancesMutex ()); - PlatformInstances &platform_instances = GetPlatformInstances (); - if (idx < platform_instances.size()) - return platform_instances[idx].name.c_str(); + PlatformInstances &instances = GetPlatformInstances (); + if (idx < instances.size()) + return instances[idx].name.c_str(); return NULL; } @@ -1250,9 +1143,9 @@ const char * PluginManager::GetPlatformPluginDescriptionAtIndex (uint32_t idx) { Mutex::Locker locker (GetPlatformInstancesMutex ()); - PlatformInstances &platform_instances = GetPlatformInstances (); - if (idx < platform_instances.size()) - return platform_instances[idx].description.c_str(); + PlatformInstances &instances = GetPlatformInstances (); + if (idx < instances.size()) + return instances[idx].description.c_str(); return NULL; } @@ -1262,14 +1155,14 @@ PluginManager::UnregisterPlugin (PlatformCreateInstance create_callback) if (create_callback) { Mutex::Locker locker (GetPlatformInstancesMutex ()); - PlatformInstances &platform_instances = GetPlatformInstances (); + PlatformInstances &instances = GetPlatformInstances (); - PlatformInstances::iterator pos, end = platform_instances.end(); - for (pos = platform_instances.begin(); pos != end; ++ pos) + PlatformInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) { if (pos->create_callback == create_callback) { - platform_instances.erase(pos); + instances.erase(pos); return true; } } @@ -1281,9 +1174,9 @@ PlatformCreateInstance PluginManager::GetPlatformCreateCallbackAtIndex (uint32_t idx) { Mutex::Locker locker (GetPlatformInstancesMutex ()); - PlatformInstances &platform_instances = GetPlatformInstances (); - if (idx < platform_instances.size()) - return platform_instances[idx].create_callback; + PlatformInstances &instances = GetPlatformInstances (); + if (idx < instances.size()) + return instances[idx].create_callback; return NULL; } @@ -1293,19 +1186,39 @@ PluginManager::GetPlatformCreateCallbackForPluginName (const char *name) if (name && name[0]) { Mutex::Locker locker (GetPlatformInstancesMutex ()); - std::string ss_name(name); - PlatformInstances &platform_instances = GetPlatformInstances (); + PlatformInstances &instances = GetPlatformInstances (); + llvm::StringRef name_sref(name); - PlatformInstances::iterator pos, end = platform_instances.end(); - for (pos = platform_instances.begin(); pos != end; ++ pos) + PlatformInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) { - if (pos->name == ss_name) + if (name_sref.equals (name)) return pos->create_callback; } } return NULL; } +uint32_t +PluginManager::AutoCompletePlatformName (const char *name, StringList &matches) +{ + if (name && name[0]) + { + Mutex::Locker locker (GetPlatformInstancesMutex ()); + PlatformInstances &instances = GetPlatformInstances (); + llvm::StringRef name_sref(name); + + PlatformInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) + { + const char *plugin_name = pos->name.c_str(); + if (name_sref.startswith(plugin_name)) + matches.AppendString (plugin_name); + } + } + return matches.GetSize(); +} + #pragma mark Process struct ProcessInstance @@ -1324,48 +1237,18 @@ struct ProcessInstance typedef std::vector ProcessInstances; -static bool -AccessProcessInstances (PluginAction action, ProcessInstance &instance, uint32_t index) +static Mutex & +GetProcessMutex () { - static ProcessInstances g_plugin_instances; - - switch (action) - { - case ePluginRegisterInstance: - if (instance.create_callback) - { - g_plugin_instances.push_back (instance); - return true; - } - break; - - case ePluginUnregisterInstance: - if (instance.create_callback) - { - ProcessInstances::iterator pos, end = g_plugin_instances.end(); - for (pos = g_plugin_instances.begin(); pos != end; ++ pos) - { - if (pos->create_callback == instance.create_callback) - { - g_plugin_instances.erase(pos); - return true; - } - } - } - break; - - case ePluginGetInstanceAtIndex: - if (index < g_plugin_instances.size()) - { - instance = g_plugin_instances[index]; - return true; - } - break; - - default: - break; - } - return false; + static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + return g_instances_mutex; +} + +static ProcessInstances & +GetProcessInstances () +{ + static ProcessInstances g_instances; + return g_instances; } @@ -1385,7 +1268,8 @@ PluginManager::RegisterPlugin if (description && description[0]) instance.description = description; instance.create_callback = create_callback; - return AccessProcessInstances (ePluginRegisterInstance, instance, 0); + Mutex::Locker locker (GetProcessMutex ()); + GetProcessInstances ().push_back (instance); } return false; } @@ -1393,18 +1277,20 @@ PluginManager::RegisterPlugin const char * PluginManager::GetProcessPluginNameAtIndex (uint32_t idx) { - ProcessInstance instance; - if (AccessProcessInstances (ePluginGetInstanceAtIndex, instance, idx)) - return instance.name.c_str(); + Mutex::Locker locker (GetProcessMutex ()); + ProcessInstances &instances = GetProcessInstances (); + if (idx < instances.size()) + return instances[idx].name.c_str(); return NULL; } const char * PluginManager::GetProcessPluginDescriptionAtIndex (uint32_t idx) { - ProcessInstance instance; - if (AccessProcessInstances (ePluginGetInstanceAtIndex, instance, idx)) - return instance.description.c_str(); + Mutex::Locker locker (GetProcessMutex ()); + ProcessInstances &instances = GetProcessInstances (); + if (idx < instances.size()) + return instances[idx].description.c_str(); return NULL; } @@ -1413,9 +1299,18 @@ PluginManager::UnregisterPlugin (ProcessCreateInstance create_callback) { if (create_callback) { - ProcessInstance instance; - instance.create_callback = create_callback; - return AccessProcessInstances (ePluginUnregisterInstance, instance, 0); + Mutex::Locker locker (GetProcessMutex ()); + ProcessInstances &instances = GetProcessInstances (); + + ProcessInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) + { + if (pos->create_callback == create_callback) + { + instances.erase(pos); + return true; + } + } } return false; } @@ -1423,23 +1318,28 @@ PluginManager::UnregisterPlugin (ProcessCreateInstance create_callback) ProcessCreateInstance PluginManager::GetProcessCreateCallbackAtIndex (uint32_t idx) { - ProcessInstance instance; - if (AccessProcessInstances (ePluginGetInstanceAtIndex, instance, idx)) - return instance.create_callback; + Mutex::Locker locker (GetProcessMutex ()); + ProcessInstances &instances = GetProcessInstances (); + if (idx < instances.size()) + return instances[idx].create_callback; return NULL; } + ProcessCreateInstance PluginManager::GetProcessCreateCallbackForPluginName (const char *name) { if (name && name[0]) { - ProcessInstance instance; - std::string ss_name(name); - for (uint32_t idx = 0; AccessProcessInstances (ePluginGetInstanceAtIndex, instance, idx); ++idx) + llvm::StringRef name_sref(name); + Mutex::Locker locker (GetProcessMutex ()); + ProcessInstances &instances = GetProcessInstances (); + + ProcessInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) { - if (instance.name == ss_name) - return instance.create_callback; + if (name_sref.equals (pos->name)) + return pos->create_callback; } } return NULL; @@ -1463,48 +1363,18 @@ struct SymbolFileInstance typedef std::vector SymbolFileInstances; -static bool -AccessSymbolFileInstances (PluginAction action, SymbolFileInstance &instance, uint32_t index) +static Mutex & +GetSymbolFileMutex () { - static SymbolFileInstances g_plugin_instances; + static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + return g_instances_mutex; +} - switch (action) - { - case ePluginRegisterInstance: - if (instance.create_callback) - { - g_plugin_instances.push_back (instance); - return true; - } - break; - - case ePluginUnregisterInstance: - if (instance.create_callback) - { - SymbolFileInstances::iterator pos, end = g_plugin_instances.end(); - for (pos = g_plugin_instances.begin(); pos != end; ++ pos) - { - if (pos->create_callback == instance.create_callback) - { - g_plugin_instances.erase(pos); - return true; - } - } - } - break; - - case ePluginGetInstanceAtIndex: - if (index < g_plugin_instances.size()) - { - instance = g_plugin_instances[index]; - return true; - } - break; - - default: - break; - } - return false; +static SymbolFileInstances & +GetSymbolFileInstances () +{ + static SymbolFileInstances g_instances; + return g_instances; } @@ -1524,7 +1394,8 @@ PluginManager::RegisterPlugin if (description && description[0]) instance.description = description; instance.create_callback = create_callback; - return AccessSymbolFileInstances (ePluginRegisterInstance, instance, 0); + Mutex::Locker locker (GetSymbolFileMutex ()); + GetSymbolFileInstances ().push_back (instance); } return false; } @@ -1534,9 +1405,18 @@ PluginManager::UnregisterPlugin (SymbolFileCreateInstance create_callback) { if (create_callback) { - SymbolFileInstance instance; - instance.create_callback = create_callback; - return AccessSymbolFileInstances (ePluginUnregisterInstance, instance, 0); + Mutex::Locker locker (GetSymbolFileMutex ()); + SymbolFileInstances &instances = GetSymbolFileInstances (); + + SymbolFileInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) + { + if (pos->create_callback == create_callback) + { + instances.erase(pos); + return true; + } + } } return false; } @@ -1544,22 +1424,27 @@ PluginManager::UnregisterPlugin (SymbolFileCreateInstance create_callback) SymbolFileCreateInstance PluginManager::GetSymbolFileCreateCallbackAtIndex (uint32_t idx) { - SymbolFileInstance instance; - if (AccessSymbolFileInstances (ePluginGetInstanceAtIndex, instance, idx)) - return instance.create_callback; + Mutex::Locker locker (GetSymbolFileMutex ()); + SymbolFileInstances &instances = GetSymbolFileInstances (); + if (idx < instances.size()) + return instances[idx].create_callback; return NULL; } + SymbolFileCreateInstance PluginManager::GetSymbolFileCreateCallbackForPluginName (const char *name) { if (name && name[0]) { - SymbolFileInstance instance; - std::string ss_name(name); - for (uint32_t idx = 0; AccessSymbolFileInstances (ePluginGetInstanceAtIndex, instance, idx); ++idx) + llvm::StringRef name_sref(name); + Mutex::Locker locker (GetSymbolFileMutex ()); + SymbolFileInstances &instances = GetSymbolFileInstances (); + + SymbolFileInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) { - if (instance.name == ss_name) - return instance.create_callback; + if (name_sref.equals (pos->name)) + return pos->create_callback; } } return NULL; @@ -1585,48 +1470,18 @@ struct SymbolVendorInstance typedef std::vector SymbolVendorInstances; -static bool -AccessSymbolVendorInstances (PluginAction action, SymbolVendorInstance &instance, uint32_t index) +static Mutex & +GetSymbolVendorMutex () { - static SymbolVendorInstances g_plugin_instances; + static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + return g_instances_mutex; +} - switch (action) - { - case ePluginRegisterInstance: - if (instance.create_callback) - { - g_plugin_instances.push_back (instance); - return true; - } - break; - - case ePluginUnregisterInstance: - if (instance.create_callback) - { - SymbolVendorInstances::iterator pos, end = g_plugin_instances.end(); - for (pos = g_plugin_instances.begin(); pos != end; ++ pos) - { - if (pos->create_callback == instance.create_callback) - { - g_plugin_instances.erase(pos); - return true; - } - } - } - break; - - case ePluginGetInstanceAtIndex: - if (index < g_plugin_instances.size()) - { - instance = g_plugin_instances[index]; - return true; - } - break; - - default: - break; - } - return false; +static SymbolVendorInstances & +GetSymbolVendorInstances () +{ + static SymbolVendorInstances g_instances; + return g_instances; } bool @@ -1645,7 +1500,8 @@ PluginManager::RegisterPlugin if (description && description[0]) instance.description = description; instance.create_callback = create_callback; - return AccessSymbolVendorInstances (ePluginRegisterInstance, instance, 0); + Mutex::Locker locker (GetSymbolVendorMutex ()); + GetSymbolVendorInstances ().push_back (instance); } return false; } @@ -1655,9 +1511,18 @@ PluginManager::UnregisterPlugin (SymbolVendorCreateInstance create_callback) { if (create_callback) { - SymbolVendorInstance instance; - instance.create_callback = create_callback; - return AccessSymbolVendorInstances (ePluginUnregisterInstance, instance, 0); + Mutex::Locker locker (GetSymbolVendorMutex ()); + SymbolVendorInstances &instances = GetSymbolVendorInstances (); + + SymbolVendorInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) + { + if (pos->create_callback == create_callback) + { + instances.erase(pos); + return true; + } + } } return false; } @@ -1665,23 +1530,28 @@ PluginManager::UnregisterPlugin (SymbolVendorCreateInstance create_callback) SymbolVendorCreateInstance PluginManager::GetSymbolVendorCreateCallbackAtIndex (uint32_t idx) { - SymbolVendorInstance instance; - if (AccessSymbolVendorInstances (ePluginGetInstanceAtIndex, instance, idx)) - return instance.create_callback; + Mutex::Locker locker (GetSymbolVendorMutex ()); + SymbolVendorInstances &instances = GetSymbolVendorInstances (); + if (idx < instances.size()) + return instances[idx].create_callback; return NULL; } + SymbolVendorCreateInstance PluginManager::GetSymbolVendorCreateCallbackForPluginName (const char *name) { if (name && name[0]) { - SymbolVendorInstance instance; - std::string ss_name(name); - for (uint32_t idx = 0; AccessSymbolVendorInstances (ePluginGetInstanceAtIndex, instance, idx); ++idx) + llvm::StringRef name_sref(name); + Mutex::Locker locker (GetSymbolVendorMutex ()); + SymbolVendorInstances &instances = GetSymbolVendorInstances (); + + SymbolVendorInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) { - if (instance.name == ss_name) - return instance.create_callback; + if (name_sref.equals (pos->name)) + return pos->create_callback; } } return NULL; @@ -1706,48 +1576,18 @@ struct UnwindAssemblyProfilerInstance typedef std::vector UnwindAssemblyProfilerInstances; -static bool -AccessUnwindAssemblyProfilerInstances (PluginAction action, UnwindAssemblyProfilerInstance &instance, uint32_t index) +static Mutex & +GetUnwindAssemblyProfilerMutex () { - static UnwindAssemblyProfilerInstances g_plugin_instances; + static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + return g_instances_mutex; +} - switch (action) - { - case ePluginRegisterInstance: - if (instance.create_callback) - { - g_plugin_instances.push_back (instance); - return true; - } - break; - - case ePluginUnregisterInstance: - if (instance.create_callback) - { - UnwindAssemblyProfilerInstances::iterator pos, end = g_plugin_instances.end(); - for (pos = g_plugin_instances.begin(); pos != end; ++ pos) - { - if (pos->create_callback == instance.create_callback) - { - g_plugin_instances.erase(pos); - return true; - } - } - } - break; - - case ePluginGetInstanceAtIndex: - if (index < g_plugin_instances.size()) - { - instance = g_plugin_instances[index]; - return true; - } - break; - - default: - break; - } - return false; +static UnwindAssemblyProfilerInstances & +GetUnwindAssemblyProfilerInstances () +{ + static UnwindAssemblyProfilerInstances g_instances; + return g_instances; } bool @@ -1766,7 +1606,8 @@ PluginManager::RegisterPlugin if (description && description[0]) instance.description = description; instance.create_callback = create_callback; - return AccessUnwindAssemblyProfilerInstances (ePluginRegisterInstance, instance, 0); + Mutex::Locker locker (GetUnwindAssemblyProfilerMutex ()); + GetUnwindAssemblyProfilerInstances ().push_back (instance); } return false; } @@ -1776,9 +1617,18 @@ PluginManager::UnregisterPlugin (UnwindAssemblyProfilerCreateInstance create_cal { if (create_callback) { - UnwindAssemblyProfilerInstance instance; - instance.create_callback = create_callback; - return AccessUnwindAssemblyProfilerInstances (ePluginUnregisterInstance, instance, 0); + Mutex::Locker locker (GetUnwindAssemblyProfilerMutex ()); + UnwindAssemblyProfilerInstances &instances = GetUnwindAssemblyProfilerInstances (); + + UnwindAssemblyProfilerInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) + { + if (pos->create_callback == create_callback) + { + instances.erase(pos); + return true; + } + } } return false; } @@ -1786,23 +1636,28 @@ PluginManager::UnregisterPlugin (UnwindAssemblyProfilerCreateInstance create_cal UnwindAssemblyProfilerCreateInstance PluginManager::GetUnwindAssemblyProfilerCreateCallbackAtIndex (uint32_t idx) { - UnwindAssemblyProfilerInstance instance; - if (AccessUnwindAssemblyProfilerInstances (ePluginGetInstanceAtIndex, instance, idx)) - return instance.create_callback; + Mutex::Locker locker (GetUnwindAssemblyProfilerMutex ()); + UnwindAssemblyProfilerInstances &instances = GetUnwindAssemblyProfilerInstances (); + if (idx < instances.size()) + return instances[idx].create_callback; return NULL; } + UnwindAssemblyProfilerCreateInstance PluginManager::GetUnwindAssemblyProfilerCreateCallbackForPluginName (const char *name) { if (name && name[0]) { - UnwindAssemblyProfilerInstance instance; - std::string ss_name(name); - for (uint32_t idx = 0; AccessUnwindAssemblyProfilerInstances (ePluginGetInstanceAtIndex, instance, idx); ++idx) + llvm::StringRef name_sref(name); + Mutex::Locker locker (GetUnwindAssemblyProfilerMutex ()); + UnwindAssemblyProfilerInstances &instances = GetUnwindAssemblyProfilerInstances (); + + UnwindAssemblyProfilerInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) { - if (instance.name == ss_name) - return instance.create_callback; + if (name_sref.equals (pos->name)) + return pos->create_callback; } } return NULL; @@ -1826,50 +1681,21 @@ struct ArchDefaultUnwindPlanInstance typedef std::vector ArchDefaultUnwindPlanInstances; -static bool -AccessArchDefaultUnwindPlanInstances (PluginAction action, ArchDefaultUnwindPlanInstance &instance, uint32_t index) +static Mutex & +GetArchDefaultUnwindPlanMutex () { - static ArchDefaultUnwindPlanInstances g_plugin_instances; - - switch (action) - { - case ePluginRegisterInstance: - if (instance.create_callback) - { - g_plugin_instances.push_back (instance); - return true; - } - break; - - case ePluginUnregisterInstance: - if (instance.create_callback) - { - ArchDefaultUnwindPlanInstances::iterator pos, end = g_plugin_instances.end(); - for (pos = g_plugin_instances.begin(); pos != end; ++ pos) - { - if (pos->create_callback == instance.create_callback) - { - g_plugin_instances.erase(pos); - return true; - } - } - } - break; - - case ePluginGetInstanceAtIndex: - if (index < g_plugin_instances.size()) - { - instance = g_plugin_instances[index]; - return true; - } - break; - - default: - break; - } - return false; + static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + return g_instances_mutex; } +static ArchDefaultUnwindPlanInstances & +GetArchDefaultUnwindPlanInstances () +{ + static ArchDefaultUnwindPlanInstances g_instances; + return g_instances; +} + + bool PluginManager::RegisterPlugin ( @@ -1886,7 +1712,8 @@ PluginManager::RegisterPlugin if (description && description[0]) instance.description = description; instance.create_callback = create_callback; - return AccessArchDefaultUnwindPlanInstances (ePluginRegisterInstance, instance, 0); + Mutex::Locker locker (GetArchDefaultUnwindPlanMutex ()); + GetArchDefaultUnwindPlanInstances ().push_back (instance); } return false; } @@ -1896,9 +1723,18 @@ PluginManager::UnregisterPlugin (ArchDefaultUnwindPlanCreateInstance create_call { if (create_callback) { - ArchDefaultUnwindPlanInstance instance; - instance.create_callback = create_callback; - return AccessArchDefaultUnwindPlanInstances (ePluginUnregisterInstance, instance, 0); + Mutex::Locker locker (GetArchDefaultUnwindPlanMutex ()); + ArchDefaultUnwindPlanInstances &instances = GetArchDefaultUnwindPlanInstances (); + + ArchDefaultUnwindPlanInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) + { + if (pos->create_callback == create_callback) + { + instances.erase(pos); + return true; + } + } } return false; } @@ -1906,23 +1742,28 @@ PluginManager::UnregisterPlugin (ArchDefaultUnwindPlanCreateInstance create_call ArchDefaultUnwindPlanCreateInstance PluginManager::GetArchDefaultUnwindPlanCreateCallbackAtIndex (uint32_t idx) { - ArchDefaultUnwindPlanInstance instance; - if (AccessArchDefaultUnwindPlanInstances (ePluginGetInstanceAtIndex, instance, idx)) - return instance.create_callback; + Mutex::Locker locker (GetArchDefaultUnwindPlanMutex ()); + ArchDefaultUnwindPlanInstances &instances = GetArchDefaultUnwindPlanInstances (); + if (idx < instances.size()) + return instances[idx].create_callback; return NULL; } + ArchDefaultUnwindPlanCreateInstance PluginManager::GetArchDefaultUnwindPlanCreateCallbackForPluginName (const char *name) { if (name && name[0]) { - ArchDefaultUnwindPlanInstance instance; - std::string ss_name(name); - for (uint32_t idx = 0; AccessArchDefaultUnwindPlanInstances (ePluginGetInstanceAtIndex, instance, idx); ++idx) + llvm::StringRef name_sref(name); + Mutex::Locker locker (GetArchDefaultUnwindPlanMutex ()); + ArchDefaultUnwindPlanInstances &instances = GetArchDefaultUnwindPlanInstances (); + + ArchDefaultUnwindPlanInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) { - if (instance.name == ss_name) - return instance.create_callback; + if (name_sref.equals (pos->name)) + return pos->create_callback; } } return NULL; @@ -1946,48 +1787,18 @@ struct ArchVolatileRegsInstance typedef std::vector ArchVolatileRegsInstances; -static bool -AccessArchVolatileRegsInstances (PluginAction action, ArchVolatileRegsInstance &instance, uint32_t index) +static Mutex & +GetArchVolatileRegsMutex () { - static ArchVolatileRegsInstances g_plugin_instances; + static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + return g_instances_mutex; +} - switch (action) - { - case ePluginRegisterInstance: - if (instance.create_callback) - { - g_plugin_instances.push_back (instance); - return true; - } - break; - - case ePluginUnregisterInstance: - if (instance.create_callback) - { - ArchVolatileRegsInstances::iterator pos, end = g_plugin_instances.end(); - for (pos = g_plugin_instances.begin(); pos != end; ++ pos) - { - if (pos->create_callback == instance.create_callback) - { - g_plugin_instances.erase(pos); - return true; - } - } - } - break; - - case ePluginGetInstanceAtIndex: - if (index < g_plugin_instances.size()) - { - instance = g_plugin_instances[index]; - return true; - } - break; - - default: - break; - } - return false; +static ArchVolatileRegsInstances & +GetArchVolatileRegsInstances () +{ + static ArchVolatileRegsInstances g_instances; + return g_instances; } bool @@ -2006,7 +1817,8 @@ PluginManager::RegisterPlugin if (description && description[0]) instance.description = description; instance.create_callback = create_callback; - return AccessArchVolatileRegsInstances (ePluginRegisterInstance, instance, 0); + Mutex::Locker locker (GetArchVolatileRegsMutex ()); + GetArchVolatileRegsInstances ().push_back (instance); } return false; } @@ -2016,9 +1828,18 @@ PluginManager::UnregisterPlugin (ArchVolatileRegsCreateInstance create_callback) { if (create_callback) { - ArchVolatileRegsInstance instance; - instance.create_callback = create_callback; - return AccessArchVolatileRegsInstances (ePluginUnregisterInstance, instance, 0); + Mutex::Locker locker (GetArchVolatileRegsMutex ()); + ArchVolatileRegsInstances &instances = GetArchVolatileRegsInstances (); + + ArchVolatileRegsInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) + { + if (pos->create_callback == create_callback) + { + instances.erase(pos); + return true; + } + } } return false; } @@ -2026,9 +1847,10 @@ PluginManager::UnregisterPlugin (ArchVolatileRegsCreateInstance create_callback) ArchVolatileRegsCreateInstance PluginManager::GetArchVolatileRegsCreateCallbackAtIndex (uint32_t idx) { - ArchVolatileRegsInstance instance; - if (AccessArchVolatileRegsInstances (ePluginGetInstanceAtIndex, instance, idx)) - return instance.create_callback; + Mutex::Locker locker (GetArchVolatileRegsMutex ()); + ArchVolatileRegsInstances &instances = GetArchVolatileRegsInstances (); + if (idx < instances.size()) + return instances[idx].create_callback; return NULL; } @@ -2037,12 +1859,15 @@ PluginManager::GetArchVolatileRegsCreateCallbackForPluginName (const char *name) { if (name && name[0]) { - ArchVolatileRegsInstance instance; - std::string ss_name(name); - for (uint32_t idx = 0; AccessArchVolatileRegsInstances (ePluginGetInstanceAtIndex, instance, idx); ++idx) + llvm::StringRef name_sref(name); + Mutex::Locker locker (GetArchVolatileRegsMutex ()); + ArchVolatileRegsInstances &instances = GetArchVolatileRegsInstances (); + + ArchVolatileRegsInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) { - if (instance.name == ss_name) - return instance.create_callback; + if (name_sref.equals (pos->name)) + return pos->create_callback; } } return NULL; diff --git a/lldb/source/Interpreter/CommandObject.cpp b/lldb/source/Interpreter/CommandObject.cpp index baf4fcb37c06..76cee5af5db0 100644 --- a/lldb/source/Interpreter/CommandObject.cpp +++ b/lldb/source/Interpreter/CommandObject.cpp @@ -650,7 +650,7 @@ CommandObject::g_arguments_data[] = { eArgTypeAddress, "address", CommandCompletions::eNoCompletion, NULL, "A valid address in the target program's execution space." }, { eArgTypeAliasName, "alias-name", CommandCompletions::eNoCompletion, NULL, "The name of an abbreviation (alias) for a debugger command." }, { eArgTypeAliasOptions, "options-for-aliased-command", CommandCompletions::eNoCompletion, NULL, "Command options to be used as part of an alias (abbreviation) definition. (See 'help commands alias' for more information.)" }, - { eArgTypeArchitecture, "arch", CommandCompletions::eNoCompletion, NULL, "The architecture name, e.g. i386 or x86_64." }, + { eArgTypeArchitecture, "arch", CommandCompletions::eArchitectureCompletion, NULL, "The architecture name, e.g. i386 or x86_64." }, { eArgTypeBoolean, "boolean", CommandCompletions::eNoCompletion, NULL, "A Boolean value: 'true' or 'false'" }, { eArgTypeBreakpointID, "breakpt-id", CommandCompletions::eNoCompletion, BreakpointIDHelpTextCallback, NULL }, { eArgTypeBreakpointIDRange, "breakpt-id-list", CommandCompletions::eNoCompletion, BreakpointIDRangeHelpTextCallback, NULL }, @@ -707,6 +707,7 @@ CommandObject::g_arguments_data[] = { eArgTypeValue, "value", CommandCompletions::eNoCompletion, NULL, "A value could be anything, depending on where and how it is used." }, { eArgTypeWidth, "width", CommandCompletions::eNoCompletion, NULL, "Help text goes here." }, { eArgTypeNone, "none", CommandCompletions::eNoCompletion, NULL, "No help available for this." }, + { eArgTypePlatform, "platform-name", CommandCompletions::ePlatformPluginCompletion, NULL, "The name of an installed platform plug-in . Type 'platform list' to see a complete list of installed platforms." } }; const CommandObject::ArgumentTableEntry* diff --git a/lldb/source/Interpreter/Options.cpp b/lldb/source/Interpreter/Options.cpp index 8f1e10abaeca..d6b30edeb664 100644 --- a/lldb/source/Interpreter/Options.cpp +++ b/lldb/source/Interpreter/Options.cpp @@ -11,8 +11,9 @@ // C Includes // C++ Includes -#include #include +#include +#include // Other libraries and framework includes // Project includes @@ -853,7 +854,19 @@ Options::HandleOptionArgumentCompletion // for that shared library. // FIXME: Do we want to also have an "OptionType" so we don't have to match string names? - uint32_t completion_mask = opt_defs[opt_defs_index].completionType; + uint32_t completion_mask = opt_defs[opt_defs_index].completion_type; + + if (completion_mask == 0) + { + lldb::CommandArgumentType option_arg_type = opt_defs[opt_defs_index].argument_type; + if (option_arg_type != eArgTypeNone) + { + CommandObject::ArgumentTableEntry *arg_entry = CommandObject::FindArgumentDataByType (opt_defs[opt_defs_index].argument_type); + if (arg_entry) + completion_mask = arg_entry->completion_type; + } + } + if (completion_mask & CommandCompletions::eSourceFileCompletion || completion_mask & CommandCompletions::eSymbolCompletion) { @@ -893,28 +906,21 @@ Options::HandleOptionArgumentCompletion } - - void -OptionGroupOptions::Append (OptionGroup* group) +OptionGroupOptions::Append (OptionGroup* group, + uint32_t src_mask, + uint32_t dst_mask) { - m_option_groups.push_back (group); - const OptionDefinition* group_option_defs = group->GetDefinitions (); - const uint32_t group_option_count = group->GetNumDefinitions(); - for (uint32_t i=0; iGetDefinitions (); const uint32_t group_option_count = group->GetNumDefinitions(); for (uint32_t i=0; iGetNumDefinitions(); - if (option_idx < curr_idx + num_group_definitions) - return (*pos)->SetOptionValue (m_interpreter, option_idx - curr_idx, option_value); - curr_idx += num_group_definitions; - } + assert (m_option_infos.size() + 1 == m_option_defs.size()); Error error; - error.SetErrorString ("invalid option index"); // Shouldn't happen... + if (option_idx < m_option_infos.size()) + { + error = m_option_infos[option_idx].option_group->SetOptionValue (m_interpreter, + m_option_infos[option_idx].option_index, + option_value); + + } + else + { + error.SetErrorString ("invalid option index"); // Shouldn't happen... + } return error; } void OptionGroupOptions::OptionParsingStarting () { - OptionGroupsType::iterator pos, end = m_option_groups.end(); - for (pos = m_option_groups.begin(); pos != end; ++pos) - (*pos)->OptionParsingStarting (m_interpreter); + std::set group_set; + OptionInfos::iterator pos, end = m_option_infos.end(); + for (pos = m_option_infos.begin(); pos != end; ++pos) + { + OptionGroup* group = pos->option_group; + if (group_set.find(group) == group_set.end()) + { + group->OptionParsingStarting (m_interpreter); + group_set.insert(group); + } + } } Error OptionGroupOptions::OptionParsingFinished () { + std::set group_set; Error error; - OptionGroupsType::iterator pos, end = m_option_groups.end(); - for (pos = m_option_groups.begin(); pos != end; ++pos) + OptionInfos::iterator pos, end = m_option_infos.end(); + for (pos = m_option_infos.begin(); pos != end; ++pos) { - error = (*pos)->OptionParsingFinished (m_interpreter); - if (error.Fail()) - return error; + OptionGroup* group = pos->option_group; + if (group_set.find(group) == group_set.end()) + { + error = group->OptionParsingFinished (m_interpreter); + group_set.insert(group); + if (error.Fail()) + return error; + } } return error; } diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp index d86ac4e0e907..225159347e25 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp @@ -80,7 +80,7 @@ const char * PlatformMacOSX::GetShortPluginNameStatic (bool is_host) { if (is_host) - return "local-macosx"; + return Platform::GetHostPlatformName (); else return "remote-macosx"; } diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp index f8b67a312802..66534c3d323f 100644 --- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp +++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp @@ -312,7 +312,7 @@ PlatformRemoteGDBServer::LaunchProcess (ProcessLaunchInfo &launch_info) break; } } - const uint32_t old_packet_timeout = m_gdb_client.SetPacketTimeout (3000); // TODO: lower this to 5 seconds prior to checkin!!! + const uint32_t old_packet_timeout = m_gdb_client.SetPacketTimeout (5); int arg_packet_err = m_gdb_client.SendArgumentsPacket (argv); m_gdb_client.SetPacketTimeout (old_packet_timeout); if (arg_packet_err == 0) diff --git a/lldb/source/Plugins/SymbolFile/DWARF/LogChannelDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/LogChannelDWARF.cpp index 9e9f6442071e..aa43d4fe9330 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/LogChannelDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/LogChannelDWARF.cpp @@ -54,16 +54,9 @@ LogChannelDWARF::CreateInstance () const char * LogChannelDWARF::GetPluginNameStatic() { - static std::string g_plugin_name; - if (g_plugin_name.empty()) - { - g_plugin_name = SymbolFileDWARF::GetPluginNameStatic(); - g_plugin_name += LogChannel::GetPluginSuffix (); - } - return g_plugin_name.c_str(); + return SymbolFileDWARF::GetPluginNameStatic(); } - const char * LogChannelDWARF::GetPluginDescriptionStatic() { diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp index 34c7337979ea..5c38ab33928a 100644 --- a/lldb/source/Target/Platform.cpp +++ b/lldb/source/Target/Platform.cpp @@ -46,6 +46,13 @@ GetConnectedPlatformList () return g_remote_connected_platforms; } + +const char * +Platform::GetHostPlatformName () +{ + return "host"; +} + //------------------------------------------------------------------ /// Get the native host platform plug-in. /// @@ -319,11 +326,8 @@ Platform::GetName () const char * Platform::GetHostname () { - if (IsHost() && m_name.empty()) - { - if (!Host::GetHostname(m_name)) - return "localhost"; - } + if (IsHost()) + return "localhost"; if (m_name.empty()) return NULL; diff --git a/lldb/tools/driver/Driver.cpp b/lldb/tools/driver/Driver.cpp index e29db667c182..a6a40426f93d 100644 --- a/lldb/tools/driver/Driver.cpp +++ b/lldb/tools/driver/Driver.cpp @@ -59,7 +59,7 @@ typedef struct const char * long_option; // Full name for this option. char short_option; // Single character for this option. int option_has_arg; // no_argument, required_argument or optional_argument - uint32_t completionType; // Cookie the option class can use to do define the argument completion. + uint32_t completion_type; // Cookie the option class can use to do define the argument completion. lldb::CommandArgumentType argument_type; // Type of argument this option takes const char * usage_text; // Full text explaining what this options does and what (if any) argument to // pass it.