diff options
20 files changed, 490 insertions, 138 deletions
diff --git a/lldb/include/lldb/API/SBDebugger.h b/lldb/include/lldb/API/SBDebugger.h index 3f119073e5d..bef4cad1439 100644 --- a/lldb/include/lldb/API/SBDebugger.h +++ b/lldb/include/lldb/API/SBDebugger.h @@ -113,7 +113,7 @@ public: SetUseExternalEditor (bool input); bool - UseExternalEditor (); + GetUseExternalEditor (); bool GetDefaultArchitecture (char *arch_name, size_t arch_name_len); diff --git a/lldb/include/lldb/Core/Debugger.h b/lldb/include/lldb/Core/Debugger.h index 9f0d2b7eba4..e5c424bf5c8 100644 --- a/lldb/include/lldb/Core/Debugger.h +++ b/lldb/include/lldb/Core/Debugger.h @@ -63,7 +63,8 @@ public: void GetInstanceSettingsValue (const SettingEntry &entry, const ConstString &var_name, - StringList &value); + StringList &value, + Error &err); uint32_t GetTerminalWidth () const @@ -90,6 +91,7 @@ public: m_prompt.assign (p); else m_prompt.assign ("(lldb) "); + BroadcastPromptChange (m_instance_name, m_prompt.c_str()); } lldb::ScriptLanguage @@ -104,6 +106,20 @@ public: m_script_lang = script_lang; } + bool + GetUseExternalEditor () const + { + return m_use_external_editor; + } + + bool + SetUseExternalEditor (bool use_external_editor_p) + { + bool old_value = m_use_external_editor; + m_use_external_editor = use_external_editor_p; + return old_value; + } + protected: void @@ -128,11 +144,15 @@ protected: static const ConstString & TermWidthVarName (); + static const ConstString & + UseExternalEditorVarName (); + private: uint32_t m_term_width; std::string m_prompt; lldb::ScriptLanguage m_script_lang; + bool m_use_external_editor; }; @@ -275,20 +295,6 @@ public: static lldb::DebuggerSP FindDebuggerWithID (lldb::user_id_t id); - bool - SetUseExternalEditor (bool value) - { - bool old_value = m_use_external_editor; - m_use_external_editor = value; - return old_value; - } - - bool - UseExternalEditor () - { - return m_use_external_editor; - } - static lldb::DebuggerSP FindDebuggerWithInstanceName (const ConstString &instance_name); diff --git a/lldb/include/lldb/Core/UserSettingsController.h b/lldb/include/lldb/Core/UserSettingsController.h index b49ee5cf556..a6af4bf53d3 100644 --- a/lldb/include/lldb/Core/UserSettingsController.h +++ b/lldb/include/lldb/Core/UserSettingsController.h @@ -74,13 +74,15 @@ public: virtual bool GetGlobalVariable (const ConstString &var_name, - StringList &value); + StringList &value, + Error &err); // End of pure virtual functions. StringList GetVariable (const char *full_dot_name, lldb::SettableVariableType &var_type, - const char *debugger_instance_name); + const char *debugger_instance_name, + Error &err); Error SetVariable (const char *full_dot_name, @@ -371,7 +373,8 @@ public: virtual void GetInstanceSettingsValue (const SettingEntry &entry, const ConstString &var_name, - StringList &value) = 0; + StringList &value, + Error &err) = 0; virtual void CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h index 4ea7dfa21f3..e27ce0b2817 100644 --- a/lldb/include/lldb/Target/Process.h +++ b/lldb/include/lldb/Target/Process.h @@ -72,7 +72,8 @@ public: void GetInstanceSettingsValue (const SettingEntry &entry, const ConstString &var_name, - StringList &value); + StringList &value, + Error &err); const Args & diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index 17ce8e496c1..c16f29ec708 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -21,6 +21,7 @@ #include "lldb/Core/Broadcaster.h" #include "lldb/Core/Event.h" #include "lldb/Core/ModuleList.h" +#include "lldb/Core/UserSettingsController.h" #include "lldb/Symbol/SymbolContext.h" #include "lldb/Target/ABI.h" #include "lldb/Target/ExecutionContextScope.h" @@ -31,13 +32,106 @@ namespace lldb_private { +class TargetInstanceSettings : public InstanceSettings +{ +public: + + TargetInstanceSettings (UserSettingsController &owner, bool live_instance = true, const char *name = NULL); + + TargetInstanceSettings (const TargetInstanceSettings &rhs); + + virtual + ~TargetInstanceSettings (); + + TargetInstanceSettings& + operator= (const TargetInstanceSettings &rhs); + + void + UpdateInstanceSettingsVariable (const ConstString &var_name, + const char *index_value, + const char *value, + const ConstString &instance_name, + const SettingEntry &entry, + lldb::VarSetOperationType op, + Error &err, + bool pending); + + void + GetInstanceSettingsValue (const SettingEntry &entry, + const ConstString &var_name, + StringList &value, + Error &err); + +protected: + + void + CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, + bool pending); + + const ConstString + CreateInstanceName (); + +private: + +}; + class Target : public Broadcaster, - public ExecutionContextScope + public ExecutionContextScope, + public TargetInstanceSettings { public: friend class TargetList; + class SettingsController : public UserSettingsController + { + public: + SettingsController (); + + virtual + ~SettingsController (); + + bool + SetGlobalVariable (const ConstString &var_name, + const char *index_value, + const char *value, + const SettingEntry &entry, + const lldb::VarSetOperationType op, + Error&err); + + bool + GetGlobalVariable (const ConstString &var_name, + StringList &value, + Error &err); + + static SettingEntry global_settings_table[]; + static SettingEntry instance_settings_table[]; + + protected: + + lldb::InstanceSettingsSP + CreateInstanceSettings (const char *instance_name); + + static const ConstString & + DefArchVarName (); + + private: + + // Class-wide settings. + ArchSpec m_default_architecture; + + DISALLOW_COPY_AND_ASSIGN (SettingsController); + }; + + static lldb::UserSettingsControllerSP + GetSettingsController (bool finish = false); + + static ArchSpec + GetDefaultArchitecture (); + + static void + SetDefaultArchitecture (ArchSpec new_arch); + //------------------------------------------------------------------ /// Broadcaster event bits definitions. //------------------------------------------------------------------ diff --git a/lldb/include/lldb/Target/Thread.h b/lldb/include/lldb/Target/Thread.h index a0163fa9115..77a892fa9e7 100644 --- a/lldb/include/lldb/Target/Thread.h +++ b/lldb/include/lldb/Target/Thread.h @@ -53,7 +53,8 @@ public: void GetInstanceSettingsValue (const SettingEntry &entry, const ConstString &var_name, - StringList &value); + StringList &value, + Error &err); RegularExpression * GetSymbolsToAvoidRegexp() diff --git a/lldb/include/lldb/lldb-private.h b/lldb/include/lldb/lldb-private.h index 73f7da6f109..fd5def81d6f 100644 --- a/lldb/include/lldb/lldb-private.h +++ b/lldb/include/lldb/lldb-private.h @@ -67,11 +67,6 @@ GetVersion (); const char * GetVoteAsCString (lldb::Vote vote); - -// The function below can be moved into lldb::Debugger when/if we get one -ArchSpec & -GetDefaultArchitecture (); - } // namespace lldb_private diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp index acf98dd8fa1..0a48e69cb79 100644 --- a/lldb/source/API/SBDebugger.cpp +++ b/lldb/source/API/SBDebugger.cpp @@ -303,7 +303,8 @@ SBDebugger::GetDefaultArchitecture (char *arch_name, size_t arch_name_len) { if (arch_name && arch_name_len) { - ArchSpec &default_arch = lldb_private::GetDefaultArchitecture (); + ArchSpec default_arch = lldb_private::Target::GetDefaultArchitecture (); + if (default_arch.IsValid()) { ::snprintf (arch_name, arch_name_len, "%s", default_arch.AsCString()); @@ -324,7 +325,7 @@ SBDebugger::SetDefaultArchitecture (const char *arch_name) ArchSpec arch (arch_name); if (arch.IsValid()) { - lldb_private::GetDefaultArchitecture () = arch; + lldb_private::Target::SetDefaultArchitecture (arch); return true; } } @@ -388,7 +389,7 @@ SBDebugger::CreateTargetWithFileAndArch (const char *filename, const char *archn if (m_opaque_sp) { FileSpec file (filename); - ArchSpec arch = lldb_private::GetDefaultArchitecture(); + ArchSpec arch = lldb_private::Target::GetDefaultArchitecture (); TargetSP target_sp; Error error; @@ -431,7 +432,7 @@ SBDebugger::CreateTarget (const char *filename) if (m_opaque_sp) { FileSpec file (filename); - ArchSpec arch = lldb_private::GetDefaultArchitecture(); + ArchSpec arch = lldb_private::Target::GetDefaultArchitecture (); TargetSP target_sp; Error error; @@ -593,12 +594,22 @@ SBDebugger::GetInternalVariableValue (const char *var_name, const char *debugger { SBStringList ret_value; lldb::SettableVariableType var_type; + lldb_private:Error err; lldb::UserSettingsControllerSP root_settings_controller = lldb_private::Debugger::GetSettingsController(); - StringList value = root_settings_controller->GetVariable (var_name, var_type, debugger_instance_name); - for (unsigned i = 0; i != value.GetSize(); ++i) - ret_value.AppendString (value.GetStringAtIndex(i)); + StringList value = root_settings_controller->GetVariable (var_name, var_type, debugger_instance_name, err); + + if (err.Success()) + { + for (unsigned i = 0; i != value.GetSize(); ++i) + ret_value.AppendString (value.GetStringAtIndex(i)); + } + else + { + ret_value.AppendString (err.AsCString()); + } + return ret_value; } @@ -662,10 +673,10 @@ SBDebugger::SetUseExternalEditor (bool value) } bool -SBDebugger::UseExternalEditor () +SBDebugger::GetUseExternalEditor () { if (m_opaque_sp) - return m_opaque_sp->UseExternalEditor (); + return m_opaque_sp->GetUseExternalEditor (); else return false; } diff --git a/lldb/source/Commands/CommandObjectFrame.cpp b/lldb/source/Commands/CommandObjectFrame.cpp index a8835e72572..5250ab5e51b 100644 --- a/lldb/source/Commands/CommandObjectFrame.cpp +++ b/lldb/source/Commands/CommandObjectFrame.cpp @@ -129,7 +129,7 @@ public: { bool already_shown = false; SymbolContext frame_sc(exe_ctx.frame->GetSymbolContext(eSymbolContextLineEntry)); - if (m_interpreter.GetDebugger().UseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0) + if (m_interpreter.GetDebugger().GetUseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0) { already_shown = Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line); } diff --git a/lldb/source/Commands/CommandObjectSettings.cpp b/lldb/source/Commands/CommandObjectSettings.cpp index b1bdaaa1b0d..f74bb70ad4b 100644 --- a/lldb/source/Commands/CommandObjectSettings.cpp +++ b/lldb/source/Commands/CommandObjectSettings.cpp @@ -272,7 +272,7 @@ CommandObjectSettingsShow::~CommandObjectSettingsShow() bool -CommandObjectSettingsShow::Execute ( Args& command, +CommandObjectSettingsShow::Execute (Args& command, CommandReturnObject &result) { UserSettingsControllerSP root_settings = Debugger::GetSettingsController (); @@ -285,13 +285,13 @@ CommandObjectSettingsShow::Execute ( Args& command, // The user requested to see the value of a particular variable. lldb::SettableVariableType var_type; const char *variable_name = command.GetArgumentAtIndex (0); - StringList value = root_settings->GetVariable (variable_name, var_type, - m_interpreter.GetDebugger().GetInstanceName().AsCString()); + StringList value = root_settings->GetVariable (variable_name, var_type, + m_interpreter.GetDebugger().GetInstanceName().AsCString(), + err); - if (value.GetSize() == 0) + if (err.Fail ()) { - result.AppendErrorWithFormat ("Unable to find variable named '%s'. " - "Try 'show' to see all variable values.\n", variable_name); + result.AppendError (err.AsCString()); result.SetStatus (eReturnStatusFailed); } @@ -304,8 +304,10 @@ CommandObjectSettingsShow::Execute ( Args& command, tmp_str.Printf (" (%s)", UserSettingsController::GetTypeString (var_type)); type_name = (char *) tmp_str.GetData(); } - - if (value.GetSize() == 1) + + if (value.GetSize() == 0) + result.AppendMessageWithFormat ("%s%s = ''\n", variable_name, type_name); + else if (value.GetSize() == 1) result.AppendMessageWithFormat ("%s%s = '%s'\n", variable_name, type_name, value.GetStringAtIndex (0)); else { diff --git a/lldb/source/Commands/CommandObjectThread.cpp b/lldb/source/Commands/CommandObjectThread.cpp index ee411e5f952..081707ae08f 100644 --- a/lldb/source/Commands/CommandObjectThread.cpp +++ b/lldb/source/Commands/CommandObjectThread.cpp @@ -63,7 +63,7 @@ lldb_private::DisplayThreadInfo bool already_shown = false; StackFrameSP frame_sp = thread->GetStackFrameAtIndex(0); SymbolContext frame_sc(frame_sp->GetSymbolContext (eSymbolContextLineEntry)); - if (interpreter.GetDebugger().UseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0) + if (interpreter.GetDebugger().GetUseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0) { already_shown = Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line); } diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp index 6eb237afd54..6bce57ae103 100644 --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -1248,7 +1248,8 @@ DebuggerInstanceSettings::DebuggerInstanceSettings InstanceSettings (owner, (name == NULL ? InstanceSettings::InvalidName().AsCString() : name), live_instance), m_term_width (80), m_prompt (), - m_script_lang () + m_script_lang (), + m_use_external_editor (false) { // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called // until the vtables for DebuggerInstanceSettings are properly set up, i.e. AFTER all the initializers. @@ -1272,7 +1273,8 @@ DebuggerInstanceSettings::DebuggerInstanceSettings DebuggerInstanceSettings::DebuggerInstanceSettings (const DebuggerInstanceSettings &rhs) : InstanceSettings (*(Debugger::GetSettingsController().get()), CreateInstanceName ().AsCString()), m_prompt (rhs.m_prompt), - m_script_lang (rhs.m_script_lang) + m_script_lang (rhs.m_script_lang), + m_use_external_editor (rhs.m_use_external_editor) { const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name); CopyInstanceSettings (pending_settings, false); @@ -1291,6 +1293,7 @@ DebuggerInstanceSettings::operator= (const DebuggerInstanceSettings &rhs) m_term_width = rhs.m_term_width; m_prompt = rhs.m_prompt; m_script_lang = rhs.m_script_lang; + m_use_external_editor = rhs.m_use_external_editor; } return *this; @@ -1366,12 +1369,17 @@ DebuggerInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var m_term_width = ::strtoul (value, NULL, 0); } } + else if (var_name == UseExternalEditorVarName ()) + { + UserSettingsController::UpdateBooleanVariable (op, m_use_external_editor, value, err); + } } void DebuggerInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry, const ConstString &var_name, - StringList &value) + StringList &value, + Error &err) { if (var_name == PromptVarName()) { @@ -1388,6 +1396,15 @@ DebuggerInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry, width_str.Printf ("%d", m_term_width); value.AppendString (width_str.GetData()); } + else if (var_name == UseExternalEditorVarName()) + { + if (m_use_external_editor) + value.AppendString ("true"); + else + value.AppendString ("false"); + } + else + err.SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString()); } void @@ -1414,7 +1431,9 @@ DebuggerInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP & BroadcastPromptChange (new_name, m_prompt.c_str()); } + m_term_width = new_debugger_settings->m_term_width; m_script_lang = new_debugger_settings->m_script_lang; + m_use_external_editor = new_debugger_settings->m_use_external_editor; } @@ -1492,6 +1511,14 @@ DebuggerInstanceSettings::TermWidthVarName () return term_width_var_name; } +const ConstString & +DebuggerInstanceSettings::UseExternalEditorVarName () +{ + static ConstString use_external_editor_var_name ("use-external-editor"); + + return use_external_editor_var_name; +} + //-------------------------------------------------- // SettingsController Variable Tables //-------------------------------------------------- @@ -1515,5 +1542,6 @@ Debugger::SettingsController::instance_settings_table[] = { "term-width" , eSetVarTypeInt, "80" , NULL, false , false , "The maximum number of columns to use for displaying text." }, { "script-lang" , eSetVarTypeString, "python", NULL, false, false, "The script language to be used for evaluating user-written scripts." }, { "prompt" , eSetVarTypeString, "(lldb)", NULL, false, false, "The debugger command line prompt displayed for the user." }, + { "use-external-editor", eSetVarTypeBool, "false", NULL, false, false, "Whether to use an external editor or not." }, { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL } }; diff --git a/lldb/source/Core/UserSettingsController.cpp b/lldb/source/Core/UserSettingsController.cpp index f6ecc1b22f9..82a58aad5c4 100644 --- a/lldb/source/Core/UserSettingsController.cpp +++ b/lldb/source/Core/UserSettingsController.cpp @@ -57,7 +57,8 @@ bool UserSettingsController::GetGlobalVariable ( const ConstString &var_name, - StringList &value + StringList &value, + Error &err ) { return false; @@ -92,38 +93,33 @@ UserSettingsController::FinalizeSettingsController (lldb::UserSettingsController void UserSettingsController::InitializeGlobalVariables () { - static bool global_initialized = false; int num_entries; const char *prefix = GetLevelName().AsCString(); - if (! global_initialized) + num_entries = m_settings.global_settings.size(); + for (int i = 0; i < num_entries; ++i) { - num_entries = m_settings.global_settings.size(); - for (int i = 0; i < num_entries; ++i) + SettingEntry &entry = m_settings.global_settings[i]; + if (entry.default_value != NULL) { - SettingEntry &entry = m_settings.global_settings[i]; - if (entry.default_value != NULL) - { - StreamString full_name; - if (prefix[0] != '\0') - full_name.Printf ("%s.%s", prefix, entry.var_name); - else - full_name.Printf ("%s", entry.var_name); - SetVariable (full_name.GetData(), entry.default_value, lldb::eVarSetOperationAssign, false, ""); - } - else if ((entry.var_type == lldb::eSetVarTypeEnum) - && (entry.enum_values != NULL)) - { - StreamString full_name; - if (prefix[0] != '\0') - full_name.Printf ("%s.%s", prefix, entry.var_name); - else - full_name.Printf ("%s", entry.var_name); - SetVariable (full_name.GetData(), entry.enum_values[0].string_value, lldb::eVarSetOperationAssign, - false, ""); - } + StreamString full_name; + if (prefix[0] != '\0') + full_name.Printf ("%s.%s", prefix, entry.var_name); + else + full_name.Printf ("%s", entry.var_name); + SetVariable (full_name.GetData(), entry.default_value, lldb::eVarSetOperationAssign, false, ""); + } + else if ((entry.var_type == lldb::eSetVarTypeEnum) + && (entry.enum_values != NULL)) + { + StreamString full_name; + if (prefix[0] != '\0') + full_name.Printf ("%s.%s", prefix, entry.var_name); + else + full_name.Printf ("%s", entry.var_name); + SetVariable (full_name.GetData(), entry.enum_values[0].string_value, lldb::eVarSetOperationAssign, + false, ""); } - global_initialized = true; } } @@ -501,7 +497,8 @@ UserSettingsController::GetVariable ( const char *full_dot_name, lldb::SettableVariableType &var_type, - const char *debugger_instance_name + const char *debugger_instance_name, + Error &err ) { Args names = UserSettingsController::BreakNameIntoPieces (full_dot_name); @@ -519,7 +516,7 @@ UserSettingsController::GetVariable if ((prefix != m_settings.level_name) && (m_settings.level_name.GetLength () > 0)) { - value.AppendString ("Invalid variable name"); + err.SetErrorString ("Invalid variable name"); return value; } @@ -548,7 +545,7 @@ UserSettingsController::GetVariable new_name += '.'; new_name += names.GetArgumentAtIndex (j); } - return child->GetVariable (new_name.c_str(), var_type, debugger_instance_name); + return child->GetVariable (new_name.c_str(), var_type, debugger_instance_name, err); } } @@ -565,7 +562,7 @@ UserSettingsController::GetVariable if (current_settings != NULL) { - current_settings->GetInstanceSettingsValue (*instance_entry, const_var_name, value); + current_settings->GetInstanceSettingsValue (*instance_entry, const_var_name, value, err); } else { @@ -578,14 +575,14 @@ UserSettingsController::GetVariable if (pos != m_pending_settings.end()) { lldb::InstanceSettingsSP settings_sp = pos->second; - settings_sp->GetInstanceSettingsValue (*instance_entry, const_var_name, value); + settings_sp->GetInstanceSettingsValue (*instance_entry, const_var_name, value, err); } else { if (m_settings.level_name.GetLength() > 0) { // No valid instance name; assume they want the default settings. - m_default_settings->GetInstanceSettingsValue (*instance_entry, const_var_name, value); + m_default_settings->GetInstanceSettingsValue (*instance_entry, const_var_name, value, err); } else { @@ -598,13 +595,13 @@ UserSettingsController::GetVariable ConstString dbg_name (debugger_instance_name); InstanceSettings *dbg_settings = FindSettingsForInstance (dbg_name); if (dbg_settings) - dbg_settings->GetInstanceSettingsValue (*instance_entry, const_var_name, value); + dbg_settings->GetInstanceSettingsValue (*instance_entry, const_var_name, value, err); } } } } else - value.AppendString ("Invalid variable name"); + err.SetErrorString ("Invalid variable name"); } } else @@ -613,18 +610,18 @@ UserSettingsController::GetVariable if ((global_entry == NULL) && (instance_entry == NULL)) { - value.AppendString ("Invalid variable name"); + err.SetErrorString ("Invalid variable name"); } else if (global_entry) { var_type = global_entry->var_type; - GetGlobalVariable (const_var_name, value); + GetGlobalVariable (const_var_name, value, err); } else if (instance_entry) { var_type = instance_entry->var_type; if (m_settings.level_name.GetLength() > 0) - m_default_settings->GetInstanceSettingsValue (*instance_entry, const_var_name, value); + m_default_settings->GetInstanceSettingsValue (*instance_entry, const_var_name, value, err); else { // We're at the Debugger level; use the debugger's instance settings. @@ -636,7 +633,7 @@ UserSettingsController::GetVariable ConstString dbg_name (tmp_name.GetData()); InstanceSettings *dbg_settings = FindSettingsForInstance (dbg_name); if (dbg_settings) - dbg_settings->GetInstanceSettingsValue (*instance_entry, const_var_name, value); + dbg_settings->GetInstanceSettingsValue (*instance_entry, const_var_name, value, err); } } } @@ -719,7 +716,7 @@ UserSettingsController::CopyDefaultSettings (const lldb::InstanceSettingsSP &act SettingEntry &entry = m_settings.instance_settings[i]; ConstString var_name (entry.var_name); StringList value; - m_default_settings->GetInstanceSettingsValue (entry, var_name, value); + m_default_settings->GetInstanceSettingsValue (entry, var_name, value, err); std::string value_str; if (value.GetSize() == 1) @@ -780,7 +777,8 @@ UserSettingsController::GetAllDefaultSettingValues (StreamString &result_stream) SettingEntry &entry = m_settings.instance_settings[i]; ConstString var_name (entry.var_name); StringList tmp_value; - m_default_settings->GetInstanceSettingsValue (entry, var_name, tmp_value); + Error err; + m_default_settings->GetInstanceSettingsValue (entry, var_name, tmp_value, err); StreamString value_string; @@ -819,7 +817,8 @@ UserSettingsController::GetAllPendingSettingValues (StreamString &result_stream) SettingEntry &entry = m_settings.instance_settings[i]; ConstString var_name (entry.var_name); StringList tmp_value; - settings_sp->GetInstanceSettingsValue (entry, var_name, tmp_value); + Error err; + settings_sp->GetInstanceSettingsValue (entry, var_name, tmp_value, err); StreamString value_str; @@ -885,7 +884,8 @@ UserSettingsController::GetAllInstanceVariableValues (CommandInterpreter &interp SettingEntry &entry = m_settings.instance_settings[i]; const ConstString var_name (entry.var_name); StringList tmp_value; - settings->GetInstanceSettingsValue (entry, var_name, tmp_value); + Error err; + settings->GetInstanceSettingsValue (entry, var_name, tmp_value, err); StreamString tmp_value_str; if (tmp_value.GetSize() == 0) @@ -1362,7 +1362,7 @@ UserSettingsController::GetAllVariableValues (CommandInterpreter &interpreter, else full_var_name.Printf ("%s", entry.var_name); StringList value = root->GetVariable (full_var_name.GetData(), var_type, - interpreter.GetDebugger().GetInstanceName().AsCString()); + interpreter.GetDebugger().GetInstanceName().AsCString(), err); description.Clear(); if (value.GetSize() == 1) description.Printf ("%s (%s) = '%s'", full_var_name.GetData(), GetTypeString (entry.var_type), diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index 48176f76b28..7b742c8ff1f 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -138,16 +138,7 @@ CommandInterpreter::LoadCommandDictionary () // Non-CommandObjectCrossref commands can now be created. - lldb::ScriptLanguage script_language; - lldb::SettableVariableType var_type = lldb::eSetVarTypeString; - StringList value; - const char *dbg_name = GetDebugger().GetInstanceName().AsCString(); - StreamString var_name; - var_name.Printf ("[%s].script-lang", dbg_name); - value = Debugger::GetSettingsController()->GetVariable (var_name.GetData(), var_type, - m_debugger.GetInstanceName().AsCString()); - bool success; - script_language = Args::StringToScriptLanguage (value.GetStringAtIndex(0), lldb::eScriptLanguageDefault, &success); + lldb::ScriptLanguage script_language = m_debugger.GetScriptLanguage(); m_command_dict["apropos"] = CommandObjectSP (new CommandObjectApropos (*this)); m_command_dict["breakpoint"]= CommandObjectSP (new CommandObjectMultiwordBreakpoint (*this)); @@ -778,21 +769,13 @@ CommandInterpreter::~CommandInterpreter () const char * CommandInterpreter::GetPrompt () { - lldb::SettableVariableType var_type; - const char *instance_name = GetDebugger().GetInstanceName().AsCString(); - StreamString var_name; - var_name.Printf ("[%s].prompt", instance_name); - return Debugger::GetSettingsController()->GetVariable (var_name.GetData(), var_type, instance_name).GetStringAtIndex(0); + return m_debugger.GetPrompt(); } void CommandInterpreter::SetPrompt (const char *new_prompt) { - const char *instance_name = GetDebugger().GetInstanceName().AsCString(); - StreamString name_str; - name_str.Printf ("[%s].prompt", instance_name); - Debugger::GetSettingsController()->SetVariable (name_str.GetData(), new_prompt, lldb::eVarSetOperationAssign, - false, m_debugger.GetInstanceName().AsCString()); + m_debugger.SetPrompt (new_prompt); } void diff --git a/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp b/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp index 3a6860fe6de..789a2a3ec1b 100644 --- a/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp +++ b/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp @@ -13,6 +13,7 @@ #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" #include "lldb/Symbol/ObjectFile.h" +#include "lldb/Target/Target.h" using namespace lldb; using namespace lldb_private; @@ -204,7 +205,7 @@ ObjectContainerUniversalMachO::GetObjectFile (const FileSpec *file) // architecture: if (!m_module->GetArchitecture().IsValid()) { - arch = lldb_private::GetDefaultArchitecture (); + arch = Target::GetDefaultArchitecture (); if (!arch.IsValid()) arch = LLDB_ARCH_DEFAULT; } diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 9a5452be053..2f676ca31d7 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -1851,7 +1851,7 @@ Process::GetSettingsController (bool finish) //-------------------------------------------------------------- Process::SettingsController::SettingsController () : - UserSettingsController ("process", Debugger::GetSettingsController()) + UserSettingsController ("process", Target::GetSettingsController()) { m_default_settings.reset (new ProcessInstanceSettings (*this, false, InstanceSettings::GetDefaultName().AsCString())); @@ -1991,7 +1991,8 @@ ProcessInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &n void ProcessInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry, const ConstString &var_name, - StringList &value) + StringList &value, + Error &err) { if (var_name == RunArgsVarName()) { @@ -2038,7 +2039,7 @@ ProcessInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry, value.AppendString ("false"); } else - value.AppendString ("unrecognized variable name"); + err.SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString()); } const ConstString diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 7d91f1e5186..f67c8cef692 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -35,6 +35,7 @@ using namespace lldb_private; //---------------------------------------------------------------------- Target::Target(Debugger &debugger) : Broadcaster("Target"), + TargetInstanceSettings (*(Target::GetSettingsController().get())), m_debugger (debugger), m_images(), m_section_load_list (), @@ -743,3 +744,233 @@ Target::GetScratchClangASTContext() { return m_scratch_ast_context_ap.get(); } + +lldb::UserSettingsControllerSP +Target::GetSettingsController (bool finish) +{ + static lldb::UserSettingsControllerSP g_settings_controller (new SettingsController); + static bool initialized = false; + + if (!initialized) + { + initialized = UserSettingsController::InitializeSettingsController (g_settings_controller, + Target::SettingsController::global_settings_table, + Target::SettingsController::instance_settings_table); + } + + if (finish) + { + UserSettingsController::FinalizeSettingsController (g_settings_controller); + g_settings_controller.reset(); + initialized = false; + } + + return g_settings_controller; +} + +ArchSpec +Target::GetDefaultArchitecture () +{ + lldb::UserSettingsControllerSP settings_controller = Target::GetSettingsController(); + lldb::SettableVariableType var_type; + Error err; + StringList result = settings_controller->GetVariable ("target.default-arch", var_type, "[]", err); + + const char *default_name = ""; + if (result.GetSize() == 1 && err.Success()) + default_name = result.GetStringAtIndex (0); + + ArchSpec default_arch (default_name); + return default_arch; +} + +void +Target::SetDefaultArchitecture (ArchSpec new_arch) +{ + if (new_arch.IsValid()) + Target::GetSettingsController ()->SetVariable ("target.default-arch", new_arch.AsCString(), + lldb::eVarSetOperationAssign, false, "[]"); +} + +//-------------------------------------------------------------- +// class Target::SettingsController +//-------------------------------------------------------------- + +Target::SettingsController::SettingsController () : + UserSettingsController ("target", Debugger::GetSettingsController()), + m_default_architecture () +{ + m_default_settings.reset (new TargetInstanceSettings (*this, false, + InstanceSettings::GetDefaultName().AsCString())); +} + +Target::SettingsController::~SettingsController () +{ +} + +lldb::InstanceSettingsSP +Target::SettingsController::CreateInstanceSettings (const char *instance_name) +{ + TargetInstanceSettings *new_settings = new TargetInstanceSettings (*(Target::GetSettingsController().get()), + false, instance_name); + lldb::InstanceSettingsSP new_settings_sp (new_settings); + return new_settings_sp; +} + +const ConstString & +Target::SettingsController::DefArchVarName () +{ + static ConstString def_arch_var_name ("default-arch"); + + return def_arch_var_name; +} + +bool +Target::SettingsController::SetGlobalVariable (const ConstString &var_name, + const char *index_value, + const char *value, + const SettingEntry &entry, + const lldb::VarSetOperationType op, + Error&err) +{ + if (var_name == DefArchVarName()) + { + ArchSpec tmp_spec (value); + if (tmp_spec.IsValid()) + m_default_architecture = tmp_spec; + else + err.SetErrorStringWithFormat ("'%s' is not a valid architecture.", value); + } + return true; +} + + +bool +Target::SettingsController::GetGlobalVariable (const ConstString &var_name, + StringList &value, + Error &err) +{ + if (var_name == DefArchVarName()) + { + value.AppendString (m_default_architecture.AsCString()); + return true; + } + else + err.SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString()); + + return false; +} + +//-------------------------------------------------------------- +// class TargetInstanceSettings +//-------------------------------------------------------------- + +TargetInstanceSettings::TargetInstanceSettings (UserSettingsController &owner, bool live_instance, + const char *name) : + InstanceSettings (owner, (name == NULL ? InstanceSettings::InvalidName().AsCString() : name), live_instance) +{ + // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called + // until the vtables for TargetInstanceSettings are properly set up, i.e. AFTER all the initializers. + // For this reason it has to be called here, rather than in the initializer or in the parent constructor. + // This is true for CreateInstanceName() too. + + if (GetInstanceName () == InstanceSettings::InvalidName()) + { + ChangeInstanceName (std::string (CreateInstanceName().AsCString())); + m_owner.RegisterInstanceSettings (this); + } + + if (live_instance) + { + const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name); + CopyInstanceSettings (pending_settings,false); + //m_owner.RemovePendingSettings (m_instance_name); + } +} + +TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rhs) : + InstanceSettings (*(Target::GetSettingsController().get()), CreateInstanceName().AsCString()) +{ + if (m_instance_name != InstanceSettings::GetDefaultName()) + { + const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name); + CopyInstanceSettings (pending_settings,false); + //m_owner.RemovePendingSettings (m_instance_name); + } +} + +TargetInstanceSettings::~TargetInstanceSettings () +{ +} + +TargetInstanceSettings& +TargetInstanceSettings::operator= (const TargetInstanceSettings &rhs) +{ + if (this != &rhs) + { + } + + return *this; +} + + +void +TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name, + const char *index_value, + const char *value, + const ConstString &instance_name, + const SettingEntry &entry, + lldb::VarSetOperationType op, + Error &err, + bool pending) +{ + // Currently 'target' does not have any instance settings. +} + +void +TargetInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, + bool pending) +{ + // Currently 'target' does not have any instance settings. +} + +void +TargetInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry, + const ConstString &var_name, + StringList &value, + Error &err) +{ + // Currently 'target' does not have any instance settings. +} + +const ConstString +TargetInstanceSettings::CreateInstanceName () +{ + static int instance_count = 1; + StreamString sstr; + + sstr.Printf ("target_%d", instance_count); + ++instance_count; + + const ConstString ret_val (sstr.GetData()); + return ret_val; +} + +//-------------------------------------------------- +// Target::SettingsController Variable Tables +//-------------------------------------------------- + +SettingEntry +Target::SettingsController::global_settings_table[] = +{ + //{ "var-name", var-type , "default", enum-table, init'd, hidden, "help-text"}, + { "default-arch", eSetVarTypeString, "x86_64", NULL, false, false, "Default architecture to choose, when there's a choice." }, + { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL } +}; + +SettingEntry +Target::SettingsController::instance_settings_table[] = +{ + //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"}, + { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL } +}; diff --git a/lldb/source/Target/Thread.cpp b/lldb/source/Target/Thread.cpp index a729b398563..21eb2d4b77b 100644 --- a/lldb/source/Target/Thread.cpp +++ b/lldb/source/Target/Thread.cpp @@ -1064,8 +1064,9 @@ ThreadInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &ne void ThreadInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry, - const ConstString &var_name, - StringList &value) + const ConstString &var_name, + StringList &value, + Error &err) { if (var_name == StepAvoidRegexpVarName()) { @@ -1076,10 +1077,10 @@ ThreadInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry, regexp_text.append ("\""); value.AppendString (regexp_text.c_str()); } - + } else - value.AppendString ("unrecognized variable name"); + err.SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString()); } const ConstString diff --git a/lldb/source/lldb.cpp b/lldb/source/lldb.cpp index 068d9ba664f..f3fa18f2fe2 100644 --- a/lldb/source/lldb.cpp +++ b/lldb/source/lldb.cpp @@ -79,8 +79,9 @@ lldb_private::Initialize () SymbolVendorMacOSX::Initialize(); #endif Debugger::GetSettingsController (false); + Target::GetSettingsController (false); Process::GetSettingsController (false); - Thread::GetSettingsController (false); + Thread::GetSettingsController (false); #ifdef __linux__ ProcessLinux::Initialize(); #endif @@ -115,9 +116,10 @@ lldb_private::Terminate () SymbolVendorMacOSX::Terminate(); #endif + Thread::GetSettingsController (true); Process::GetSettingsController (true); + Target::GetSettingsController (true); Debugger::GetSettingsController (true); - Thread::GetSettingsController (true); #ifdef __linux__ ProcessLinux::Terminate(); @@ -135,14 +137,6 @@ lldb_private::GetVersion () return g_version_string; } -ArchSpec & -lldb_private::GetDefaultArchitecture () -{ - static ArchSpec g_default_arch; - return g_default_arch; -} - - const char * lldb_private::GetVoteAsCString (lldb::Vote vote) { diff --git a/lldb/test/settings/TestSettings.py b/lldb/test/settings/TestSettings.py index 04e4ad0d288..9a43f122791 100644 --- a/lldb/test/settings/TestSettings.py +++ b/lldb/test/settings/TestSettings.py @@ -61,8 +61,8 @@ class SettingsCommandTestCase(TestBase): self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # Set the run-args and the env-vars. - self.runCmd('settings set process.run-args A B C') - self.runCmd('settings set process.env-vars ["MY_ENV_VAR"]=YES') + self.runCmd('settings set target.process.run-args A B C') + self.runCmd('settings set target.process.env-vars ["MY_ENV_VAR"]=YES') self.runCmd("run", RUN_SUCCEEDED) @@ -76,18 +76,18 @@ class SettingsCommandTestCase(TestBase): @unittest2.expectedFailure # rdar://problem/8435794 - # settings set process.output-path does not seem to work + # settings set target.process.output-path does not seem to work def test_set_output_path(self): - """Test that setting process.output-path for the launched process works.""" + """Test that setting target.process.output-path for the launched process works.""" self.buildDefault() exe = os.path.join(os.getcwd(), "a.out") self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # Set the output-path and verify it is set. - self.runCmd("settings set process.output-path 'stdout.txt'") - self.expect("settings show process.output-path", - startstr = "process.output-path (string) = 'stdout.txt'") + self.runCmd("settings set target.process.output-path 'stdout.txt'") + self.expect("settings show target.process.output-path", + startstr = "target.process.output-path (string) = 'stdout.txt'") self.runCmd("run", RUN_SUCCEEDED) |