Create more useful instance names for target, process and thread instances.

Change default 'set' behavior so that all instance settings for the specified variable will be
updated, unless the "-n" ("--no_override") command options is specified.

llvm-svn: 114808
This commit is contained in:
Caroline Tice 2010-09-27 00:30:10 +00:00
parent c8a4973389
commit 1559a46b3e
10 changed files with 95 additions and 28 deletions

View File

@ -365,6 +365,9 @@ public:
static lldb::UserSettingsControllerSP
GetSettingsController (bool finish = false);
void
UpdateInstanceName ();
//------------------------------------------------------------------
/// Construct with a shared pointer to a target, and the Process listener.
//------------------------------------------------------------------

View File

@ -132,6 +132,9 @@ public:
static void
SetDefaultArchitecture (ArchSpec new_arch);
void
UpdateInstanceName ();
//------------------------------------------------------------------
/// Broadcaster event bits definitions.
//------------------------------------------------------------------

View File

@ -159,6 +159,9 @@ public:
lldb::DataBufferSP m_data_sp;
};
void
UpdateInstanceName ();
static lldb::UserSettingsControllerSP
GetSettingsController (bool finish = false);

View File

@ -581,7 +581,7 @@ SBDebugger::SetInternalVariable (const char *var_name, const char *value, const
{
lldb::UserSettingsControllerSP root_settings_controller = lldb_private::Debugger::GetSettingsController();
Error err = root_settings_controller->SetVariable (var_name, value, lldb::eVarSetOperationAssign, false,
Error err = root_settings_controller->SetVariable (var_name, value, lldb::eVarSetOperationAssign, true,
debugger_instance_name);
SBError sb_error;
sb_error.SetError (err);

View File

@ -194,7 +194,7 @@ CommandObjectSettingsSet::HandleArgumentCompletion (Args &input,
CommandObjectSettingsSet::CommandOptions::CommandOptions () :
Options (),
m_override (false),
m_override (true),
m_reset (false)
{
}
@ -206,7 +206,7 @@ CommandObjectSettingsSet::CommandOptions::~CommandOptions ()
lldb::OptionDefinition
CommandObjectSettingsSet::CommandOptions::g_option_table[] =
{
{ LLDB_OPT_SET_1, false, "override", 'o', no_argument, NULL, NULL, NULL, "Causes already existing instances and pending settings to use this new value. This option only makes sense when setting default values." },
{ LLDB_OPT_SET_1, false, "no_override", 'n', no_argument, NULL, NULL, NULL, "Prevents already existing instances and pending settings from being assigned this new value. Using this option means that only the default or specified instance setting values will be updated." },
{ LLDB_OPT_SET_2, false, "reset", 'r', no_argument, NULL, NULL, NULL, "Causes value to be reset to the original default for this variable. No value needs to be specified when this option is used." },
};
@ -224,8 +224,8 @@ CommandObjectSettingsSet::CommandOptions::SetOptionValue (int option_idx, const
switch (short_option)
{
case 'o':
m_override = true;
case 'n':
m_override = false;
break;
case 'r':
m_reset = true;
@ -243,7 +243,7 @@ CommandObjectSettingsSet::CommandOptions::ResetOptionValues ()
{
Options::ResetOptionValues ();
m_override = false;
m_override = true;
m_reset = false;
}
@ -510,7 +510,7 @@ CommandObjectSettingsRemove::Execute ( Args& command,
Error err = root_settings->SetVariable (var_name_string.c_str(),
NULL,
lldb::eVarSetOperationRemove,
false,
true,
m_interpreter.GetDebugger().GetInstanceName().AsCString(),
index_value_string.c_str());
if (err.Fail ())
@ -622,7 +622,7 @@ CommandObjectSettingsReplace::Execute ( Args& command,
Error err = root_settings->SetVariable (var_name_string.c_str(),
var_value,
lldb::eVarSetOperationReplace,
false,
true,
m_interpreter.GetDebugger().GetInstanceName().AsCString(),
index_value_string.c_str());
if (err.Fail ())
@ -736,7 +736,7 @@ CommandObjectSettingsInsertBefore::Execute ( Args&
Error err = root_settings->SetVariable (var_name_string.c_str(),
var_value,
lldb::eVarSetOperationInsertBefore,
false,
true,
m_interpreter.GetDebugger().GetInstanceName().AsCString(),
index_value_string.c_str());
if (err.Fail ())
@ -851,7 +851,7 @@ CommandObjectSettingsInsertAfter::Execute ( Args& co
Error err = root_settings->SetVariable (var_name_string.c_str(),
var_value,
lldb::eVarSetOperationInsertAfter,
false,
true,
m_interpreter.GetDebugger().GetInstanceName().AsCString(),
index_value_string.c_str());
if (err.Fail ())
@ -911,8 +911,8 @@ CommandObjectSettingsAppend::~CommandObjectSettingsAppend ()
}
bool
CommandObjectSettingsAppend::Execute ( Args& command,
CommandReturnObject &result)
CommandObjectSettingsAppend::Execute (Args& command,
CommandReturnObject &result)
{
UserSettingsControllerSP root_settings = Debugger::GetSettingsController ();
@ -954,7 +954,7 @@ CommandObjectSettingsAppend::Execute ( Args& command,
Error err = root_settings->SetVariable (var_name_string.c_str(),
var_value,
lldb::eVarSetOperationAppend,
false,
true,
m_interpreter.GetDebugger().GetInstanceName().AsCString());
if (err.Fail ())
{

View File

@ -347,14 +347,14 @@ UserSettingsController::SetVariable (const char *full_dot_name,
OverrideAllInstances (const_var_name, value, op, index_value, err);
// Update all pending records as well.
std::map<std::string, lldb::InstanceSettingsSP>::iterator pos, end = m_pending_settings.end();
for (pos = m_pending_settings.begin(); pos != end; end++)
{
const ConstString instance_name (pos->first.c_str());
lldb::InstanceSettingsSP setting_sp = pos->second;
setting_sp->UpdateInstanceSettingsVariable (const_var_name, index_value, value,
instance_name, *entry, op, err, true);
}
// std::map<std::string, lldb::InstanceSettingsSP>::iterator pos, end = m_pending_settings.end();
// for (pos = m_pending_settings.begin(); pos != end; end++)
// {
// const ConstString instance_name (pos->first.c_str());
// lldb::InstanceSettingsSP setting_sp = pos->second;
// setting_sp->UpdateInstanceSettingsVariable (const_var_name, index_value, value,
// instance_name, *entry, op, err, true);
// }
}
}
}
@ -2164,18 +2164,24 @@ UserSettingsController::RenameInstanceSettings (const char *old_name, const char
// list, then this is not a setting that can be renamed.
if ((old_name_key[0] != '[') || (old_name_key[old_name_key.size() -1] != ']'))
{
{
StreamString tmp_str;
tmp_str.Printf ("[%s]", old_name);
old_name_key = tmp_str.GetData();
}
}
if ((new_name_key[0] != '[') || (new_name_key[new_name_key.size() -1] != ']'))
{
{
StreamString tmp_str;
tmp_str.Printf ("[%s]", new_name);
new_name_key = tmp_str.GetData();
}
}
if (old_name_key.compare (new_name_key) == 0)
return;
size_t len = new_name_key.length();
std::string stripped_new_name = new_name_key.substr (1, len-2); // new name without the '[ ]'
std::map<std::string, InstanceSettings *>::iterator pos;
@ -2185,7 +2191,7 @@ UserSettingsController::RenameInstanceSettings (const char *old_name, const char
InstanceSettings *live_settings = pos->second;
// Rename the settings.
live_settings->ChangeInstanceName (new_name_key);
live_settings->ChangeInstanceName (stripped_new_name);
// Now see if there are any pending settings for the new name; if so, copy them into live_settings.
std::map<std::string, lldb::InstanceSettingsSP>::iterator pending_pos;

View File

@ -87,6 +87,8 @@ Process::Process(Target &target, Listener &listener) :
m_objc_object_printer(*this),
m_persistent_vars()
{
UpdateInstanceName();
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT);
if (log)
log->Printf ("%p Process::Process()", this);
@ -1884,6 +1886,20 @@ Process::GetSettingsController (bool finish)
return g_settings_controller;
}
void
Process::UpdateInstanceName ()
{
ModuleSP module_sp = GetTarget().GetExecutableModule();
if (module_sp)
{
StreamString sstr;
sstr.Printf ("%s", module_sp->GetFileSpec().GetFilename().AsCString());
Process::GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(),
sstr.GetData());
}
}
//--------------------------------------------------------------
// class Process::SettingsController
//--------------------------------------------------------------

View File

@ -425,6 +425,8 @@ Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
m_scratch_ast_context_ap.reset (new ClangASTContext(target_triple.GetCString()));
}
}
UpdateInstanceName();
}
@ -792,6 +794,21 @@ Target::SetDefaultArchitecture (ArchSpec new_arch)
lldb::eVarSetOperationAssign, false, "[]");
}
void
Target::UpdateInstanceName ()
{
StreamString sstr;
ModuleSP module_sp = GetExecutableModule();
if (module_sp)
{
sstr.Printf ("%s_%s", module_sp->GetFileSpec().GetFilename().AsCString(),
module_sp->GetArchitecture().AsCString());
Target::GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(),
sstr.GetData());
}
}
//--------------------------------------------------------------
// class Target::SettingsController
//--------------------------------------------------------------
@ -948,9 +965,9 @@ TargetInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
const ConstString
TargetInstanceSettings::CreateInstanceName ()
{
static int instance_count = 1;
StreamString sstr;
static int instance_count = 1;
sstr.Printf ("target_%d", instance_count);
++instance_count;

View File

@ -101,6 +101,9 @@ TargetList::CreateTarget
target_sp->SetExecutableModule (exe_module_sp, get_dependent_files);
}
}
if (target_sp.get())
target_sp->UpdateInstanceName();
if (target_sp.get())
{

View File

@ -62,6 +62,7 @@ Thread::Thread (Process &process, lldb::tid_t tid) :
log->Printf ("%p Thread::Thread(tid = 0x%4.4x)", this, GetID());
QueueFundamentalPlan(true);
UpdateInstanceName();
}
@ -938,6 +939,21 @@ Thread::GetSettingsController (bool finish)
return g_settings_controller;
}
void
Thread::UpdateInstanceName ()
{
StreamString sstr;
const char *name = GetName();
if (name && name[0] != '\0')
sstr.Printf ("%s", name);
else if ((GetIndexID() != 0) || (GetID() != 0))
sstr.Printf ("0x%4.4x", GetIndexID(), GetID());
if (sstr.GetSize() > 0)
Thread::GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), sstr.GetData());
}
//--------------------------------------------------------------
// class Thread::ThreadSettingsController
//--------------------------------------------------------------