Add UserSettings to Target class, making Target settings
the parent of Process settings; add 'default-arch' as a
class-wide setting for Target. Replace lldb::GetDefaultArchitecture
with Target::GetDefaultArchitecture & Target::SetDefaultArchitecture.
Add 'use-external-editor' as user setting to Debugger class & update
code appropriately.
Add Error parameter to methods that get user settings, for easier
reporting of bad requests.
Fix various other minor related bugs.
Fix test cases to work with new changes.
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@114352 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/API/SBDebugger.cpp b/source/API/SBDebugger.cpp
index acf98dd..0a48e69 100644
--- a/source/API/SBDebugger.cpp
+++ b/source/API/SBDebugger.cpp
@@ -303,7 +303,8 @@
{
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 @@
ArchSpec arch (arch_name);
if (arch.IsValid())
{
- lldb_private::GetDefaultArchitecture () = arch;
+ lldb_private::Target::SetDefaultArchitecture (arch);
return true;
}
}
@@ -388,7 +389,7 @@
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 @@
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 @@
{
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 @@
}
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/source/Commands/CommandObjectFrame.cpp b/source/Commands/CommandObjectFrame.cpp
index a8835e7..5250ab5 100644
--- a/source/Commands/CommandObjectFrame.cpp
+++ b/source/Commands/CommandObjectFrame.cpp
@@ -129,7 +129,7 @@
{
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/source/Commands/CommandObjectSettings.cpp b/source/Commands/CommandObjectSettings.cpp
index b1bdaaa..f74bb70 100644
--- a/source/Commands/CommandObjectSettings.cpp
+++ b/source/Commands/CommandObjectSettings.cpp
@@ -272,7 +272,7 @@
bool
-CommandObjectSettingsShow::Execute ( Args& command,
+CommandObjectSettingsShow::Execute (Args& command,
CommandReturnObject &result)
{
UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
@@ -285,13 +285,13 @@
// 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 @@
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/source/Commands/CommandObjectThread.cpp b/source/Commands/CommandObjectThread.cpp
index ee411e5..081707a 100644
--- a/source/Commands/CommandObjectThread.cpp
+++ b/source/Commands/CommandObjectThread.cpp
@@ -63,7 +63,7 @@
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/source/Core/Debugger.cpp b/source/Core/Debugger.cpp
index 6eb237a..6bce57a 100644
--- a/source/Core/Debugger.cpp
+++ b/source/Core/Debugger.cpp
@@ -1248,7 +1248,8 @@
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 (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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
{ "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/source/Core/UserSettingsController.cpp b/source/Core/UserSettingsController.cpp
index f6ecc1b..82a58aa 100644
--- a/source/Core/UserSettingsController.cpp
+++ b/source/Core/UserSettingsController.cpp
@@ -57,7 +57,8 @@
UserSettingsController::GetGlobalVariable
(
const ConstString &var_name,
- StringList &value
+ StringList &value,
+ Error &err
)
{
return false;
@@ -92,38 +93,33 @@
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, "");
}
- global_initialized = true;
+ 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, "");
+ }
}
}
@@ -501,7 +497,8 @@
(
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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/source/Interpreter/CommandInterpreter.cpp b/source/Interpreter/CommandInterpreter.cpp
index 48176f7..7b742c8 100644
--- a/source/Interpreter/CommandInterpreter.cpp
+++ b/source/Interpreter/CommandInterpreter.cpp
@@ -138,16 +138,7 @@
// 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 @@
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/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp b/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp
index 3a6860f..789a2a3 100644
--- a/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp
+++ b/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 @@
// architecture:
if (!m_module->GetArchitecture().IsValid())
{
- arch = lldb_private::GetDefaultArchitecture ();
+ arch = Target::GetDefaultArchitecture ();
if (!arch.IsValid())
arch = LLDB_ARCH_DEFAULT;
}
diff --git a/source/Target/Process.cpp b/source/Target/Process.cpp
index 9a5452b..2f676ca 100644
--- a/source/Target/Process.cpp
+++ b/source/Target/Process.cpp
@@ -1851,7 +1851,7 @@
//--------------------------------------------------------------
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 @@
void
ProcessInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
const ConstString &var_name,
- StringList &value)
+ StringList &value,
+ Error &err)
{
if (var_name == RunArgsVarName())
{
@@ -2038,7 +2039,7 @@
value.AppendString ("false");
}
else
- value.AppendString ("unrecognized variable name");
+ err.SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
}
const ConstString
diff --git a/source/Target/Target.cpp b/source/Target/Target.cpp
index 7d91f1e..f67c8ce 100644
--- a/source/Target/Target.cpp
+++ b/source/Target/Target.cpp
@@ -35,6 +35,7 @@
//----------------------------------------------------------------------
Target::Target(Debugger &debugger) :
Broadcaster("Target"),
+ TargetInstanceSettings (*(Target::GetSettingsController().get())),
m_debugger (debugger),
m_images(),
m_section_load_list (),
@@ -743,3 +744,233 @@
{
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/source/Target/Thread.cpp b/source/Target/Thread.cpp
index a729b39..21eb2d4 100644
--- a/source/Target/Thread.cpp
+++ b/source/Target/Thread.cpp
@@ -1064,8 +1064,9 @@
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 @@
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/source/lldb.cpp b/source/lldb.cpp
index 068d9ba..f3fa18f 100644
--- a/source/lldb.cpp
+++ b/source/lldb.cpp
@@ -79,8 +79,9 @@
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 @@
SymbolVendorMacOSX::Terminate();
#endif
- Process::GetSettingsController (true);
- Debugger::GetSettingsController (true);
Thread::GetSettingsController (true);
+ Process::GetSettingsController (true);
+ Target::GetSettingsController (true);
+ Debugger::GetSettingsController (true);
#ifdef __linux__
ProcessLinux::Terminate();
@@ -135,14 +137,6 @@
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)
{