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/include/lldb/API/SBDebugger.h b/include/lldb/API/SBDebugger.h
index 3f11907..bef4cad 100644
--- a/include/lldb/API/SBDebugger.h
+++ b/include/lldb/API/SBDebugger.h
@@ -113,7 +113,7 @@
SetUseExternalEditor (bool input);
bool
- UseExternalEditor ();
+ GetUseExternalEditor ();
bool
GetDefaultArchitecture (char *arch_name, size_t arch_name_len);
diff --git a/include/lldb/Core/Debugger.h b/include/lldb/Core/Debugger.h
index 9f0d2b7..e5c424b 100644
--- a/include/lldb/Core/Debugger.h
+++ b/include/lldb/Core/Debugger.h
@@ -63,7 +63,8 @@
void
GetInstanceSettingsValue (const SettingEntry &entry,
const ConstString &var_name,
- StringList &value);
+ StringList &value,
+ Error &err);
uint32_t
GetTerminalWidth () const
@@ -90,6 +91,7 @@
m_prompt.assign (p);
else
m_prompt.assign ("(lldb) ");
+ BroadcastPromptChange (m_instance_name, m_prompt.c_str());
}
lldb::ScriptLanguage
@@ -104,6 +106,20 @@
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 @@
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 @@
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/include/lldb/Core/UserSettingsController.h b/include/lldb/Core/UserSettingsController.h
index b49ee5c..a6af4bf 100644
--- a/include/lldb/Core/UserSettingsController.h
+++ b/include/lldb/Core/UserSettingsController.h
@@ -74,13 +74,15 @@
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 @@
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/include/lldb/Target/Process.h b/include/lldb/Target/Process.h
index 4ea7dfa..e27ce0b 100644
--- a/include/lldb/Target/Process.h
+++ b/include/lldb/Target/Process.h
@@ -72,7 +72,8 @@
void
GetInstanceSettingsValue (const SettingEntry &entry,
const ConstString &var_name,
- StringList &value);
+ StringList &value,
+ Error &err);
const Args &
diff --git a/include/lldb/Target/Target.h b/include/lldb/Target/Target.h
index 17ce8e4..c16f29e 100644
--- a/include/lldb/Target/Target.h
+++ b/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/include/lldb/Target/Thread.h b/include/lldb/Target/Thread.h
index a0163fa..77a892f 100644
--- a/include/lldb/Target/Thread.h
+++ b/include/lldb/Target/Thread.h
@@ -53,7 +53,8 @@
void
GetInstanceSettingsValue (const SettingEntry &entry,
const ConstString &var_name,
- StringList &value);
+ StringList &value,
+ Error &err);
RegularExpression *
GetSymbolsToAvoidRegexp()
diff --git a/include/lldb/lldb-private.h b/include/lldb/lldb-private.h
index 73f7da6..fd5def8 100644
--- a/include/lldb/lldb-private.h
+++ b/include/lldb/lldb-private.h
@@ -67,11 +67,6 @@
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/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)
{
diff --git a/test/settings/TestSettings.py b/test/settings/TestSettings.py
index 04e4ad0..9a43f12 100644
--- a/test/settings/TestSettings.py
+++ b/test/settings/TestSettings.py
@@ -61,8 +61,8 @@
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 @@
@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)