Fixed a problem where the target didn't use a

NULL-terminated C string to store the contents
of the expression prefix file.  This meant that
expressions, when printing the contents of the
prefix into the expression's text, would
invariably put in bad data after the end of the
expression.

Now, instead, we store the prefix contents in a
std::string, which handles null-termination
correctly.

llvm-svn: 144760
This commit is contained in:
Sean Callanan 2011-11-16 01:54:57 +00:00
parent 415e8aa84a
commit 6d6acc89ad
2 changed files with 13 additions and 11 deletions

View File

@ -221,7 +221,7 @@ protected:
CreateInstanceName ();
OptionValueFileSpec m_expr_prefix_file;
lldb::DataBufferSP m_expr_prefix_contents_sp;
std::string m_expr_prefix_contents;
int m_prefer_dynamic_value;
OptionValueBoolean m_skip_prologue;
PathMappingList m_source_map;

View File

@ -1430,8 +1430,8 @@ Target::UpdateInstanceName ()
const char *
Target::GetExpressionPrefixContentsAsCString ()
{
if (m_expr_prefix_contents_sp)
return (const char *)m_expr_prefix_contents_sp->GetBytes();
if (!m_expr_prefix_contents.empty())
return m_expr_prefix_contents.c_str();
return NULL;
}
@ -2160,7 +2160,7 @@ TargetInstanceSettings::TargetInstanceSettings
) :
InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
m_expr_prefix_file (),
m_expr_prefix_contents_sp (),
m_expr_prefix_contents (),
m_prefer_dynamic_value (2),
m_skip_prologue (true, true),
m_source_map (NULL, NULL),
@ -2198,7 +2198,7 @@ TargetInstanceSettings::TargetInstanceSettings
TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rhs) :
InstanceSettings (*Target::GetSettingsController(), CreateInstanceName().AsCString()),
m_expr_prefix_file (rhs.m_expr_prefix_file),
m_expr_prefix_contents_sp (rhs.m_expr_prefix_contents_sp),
m_expr_prefix_contents (rhs.m_expr_prefix_contents),
m_prefer_dynamic_value (rhs.m_prefer_dynamic_value),
m_skip_prologue (rhs.m_skip_prologue),
m_source_map (rhs.m_source_map),
@ -2231,7 +2231,7 @@ TargetInstanceSettings::operator= (const TargetInstanceSettings &rhs)
if (this != &rhs)
{
m_expr_prefix_file = rhs.m_expr_prefix_file;
m_expr_prefix_contents_sp = rhs.m_expr_prefix_contents_sp;
m_expr_prefix_contents = rhs.m_expr_prefix_contents;
m_prefer_dynamic_value = rhs.m_prefer_dynamic_value;
m_skip_prologue = rhs.m_skip_prologue;
m_source_map = rhs.m_source_map;
@ -2280,17 +2280,19 @@ TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_n
return;
}
m_expr_prefix_contents_sp = m_expr_prefix_file.GetCurrentValue().ReadFileContents();
if (!m_expr_prefix_contents_sp && m_expr_prefix_contents_sp->GetByteSize() == 0)
DataBufferSP file_contents = m_expr_prefix_file.GetCurrentValue().ReadFileContents();
if (!file_contents && file_contents->GetByteSize() == 0)
{
err.SetErrorStringWithFormat ("couldn't read data from '%s'", value);
m_expr_prefix_contents_sp.reset();
m_expr_prefix_contents.clear();
}
m_expr_prefix_contents.assign((const char*)file_contents->GetBytes(), file_contents->GetByteSize());
}
break;
case eVarSetOperationClear:
m_expr_prefix_contents_sp.reset();
m_expr_prefix_contents.clear();
}
}
}