diff options
Diffstat (limited to 'source/Core/ValueObject.cpp')
| -rw-r--r-- | source/Core/ValueObject.cpp | 230 |
1 files changed, 109 insertions, 121 deletions
diff --git a/source/Core/ValueObject.cpp b/source/Core/ValueObject.cpp index c09139fe2b09..244ea2936fb4 100644 --- a/source/Core/ValueObject.cpp +++ b/source/Core/ValueObject.cpp @@ -19,6 +19,7 @@ #include "lldb/Core/ValueObjectMemory.h" #include "lldb/Core/ValueObjectSyntheticFilter.h" #include "lldb/DataFormatters/DataVisualization.h" +#include "lldb/DataFormatters/DumpValueObjectOptions.h" // for DumpValueObj... #include "lldb/DataFormatters/FormatManager.h" // for FormatManager #include "lldb/DataFormatters/StringPrinter.h" #include "lldb/DataFormatters/TypeFormat.h" // for TypeFormatImpl_F... @@ -146,16 +147,15 @@ bool ValueObject::UpdateValueIfNeeded(bool update_format) { if (update_format) did_change_formats = UpdateFormatsIfNeeded(); - // If this is a constant value, then our success is predicated on whether - // we have an error or not + // If this is a constant value, then our success is predicated on whether we + // have an error or not if (GetIsConstant()) { // if you are constant, things might still have changed behind your back // (e.g. you are a frozen object and things have changed deeper than you - // cared to freeze-dry yourself) - // in this case, your value has not changed, but "computed" entries might - // have, so you might now have - // a different summary, or a different object description. clear these so we - // will recompute them + // cared to freeze-dry yourself) in this case, your value has not changed, + // but "computed" entries might have, so you might now have a different + // summary, or a different object description. clear these so we will + // recompute them if (update_format && !did_change_formats) ClearUserVisibleData(eClearUserVisibleDataItemsSummary | eClearUserVisibleDataItemsDescription); @@ -167,8 +167,8 @@ bool ValueObject::UpdateValueIfNeeded(bool update_format) { if (NeedsUpdating()) { m_update_point.SetUpdated(); - // Save the old value using swap to avoid a string copy which - // also will clear our m_value_str + // Save the old value using swap to avoid a string copy which also will + // clear our m_value_str if (m_value_str.empty()) { m_old_value_valid = false; } else { @@ -215,8 +215,8 @@ bool ValueObject::UpdateValueIfNeeded(bool update_format) { if (first_update) SetValueDidChange(false); else if (!m_value_did_change && success == false) { - // The value wasn't gotten successfully, so we mark this - // as changed if the value used to be valid and now isn't + // The value wasn't gotten successfully, so we mark this as changed if + // the value used to be valid and now isn't SetValueDidChange(value_was_valid); } else if (need_compare_checksums) { SetValueDidChange(memcmp(&old_checksum[0], &m_value_checksum[0], @@ -261,8 +261,7 @@ bool ValueObject::UpdateFormatsIfNeeded() { void ValueObject::SetNeedsUpdate() { m_update_point.SetNeedsUpdate(); // We have to clear the value string here so ConstResult children will notice - // if their values are - // changed by hand (i.e. with SetValueAsCString). + // if their values are changed by hand (i.e. with SetValueAsCString). ClearUserVisibleData(eClearUserVisibleDataItemsValue); } @@ -556,9 +555,9 @@ size_t ValueObject::GetIndexOfChildWithName(const ConstString &name) { ValueObjectSP ValueObject::GetChildMemberWithName(const ConstString &name, bool can_create) { - // when getting a child by name, it could be buried inside some base - // classes (which really aren't part of the expression path), so we - // need a vector of indexes that can get us down to the correct child + // when getting a child by name, it could be buried inside some base classes + // (which really aren't part of the expression path), so we need a vector of + // indexes that can get us down to the correct child ValueObjectSP child_sp; // We may need to update our value if we are dynamic @@ -682,8 +681,8 @@ bool ValueObject::GetSummaryAsCString(TypeSummaryImpl *summary_ptr, const TypeSummaryOptions &options) { destination.clear(); - // ideally we would like to bail out if passing NULL, but if we do so - // we end up not providing the summary for function pointers anymore + // ideally we would like to bail out if passing NULL, but if we do so we end + // up not providing the summary for function pointers anymore if (/*summary_ptr == NULL ||*/ m_is_getting_summary) return false; @@ -695,9 +694,8 @@ bool ValueObject::GetSummaryAsCString(TypeSummaryImpl *summary_ptr, actual_options.SetLanguage(GetPreferredDisplayLanguage()); // this is a hot path in code and we prefer to avoid setting this string all - // too often also clearing out other - // information that we might care to see in a crash log. might be useful in - // very specific situations though. + // too often also clearing out other information that we might care to see in + // a crash log. might be useful in very specific situations though. /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s", GetTypeName().GetCString(), @@ -925,7 +923,8 @@ bool ValueObject::SetData(DataExtractor &data, Status &error) { break; } - // If we have reached this point, then we have successfully changed the value. + // If we have reached this point, then we have successfully changed the + // value. SetNeedsUpdate(); return true; } @@ -1010,9 +1009,9 @@ ValueObject::ReadPointedString(lldb::DataBufferSP &buffer_sp, Status &error, DataExtractor data; if (cstr_len > 0 && honor_array) { // I am using GetPointeeData() here to abstract the fact that some - // ValueObjects are actually frozen pointers in the host - // but the pointed-to data lives in the debuggee, and GetPointeeData() - // automatically takes care of this + // ValueObjects are actually frozen pointers in the host but the pointed- + // to data lives in the debuggee, and GetPointeeData() automatically + // takes care of this GetPointeeData(data, 0, cstr_len); if ((bytes_read = data.GetByteSize()) > 0) { @@ -1031,9 +1030,9 @@ ValueObject::ReadPointedString(lldb::DataBufferSP &buffer_sp, Status &error, int cstr_len_displayed = -1; bool capped_cstr = false; // I am using GetPointeeData() here to abstract the fact that some - // ValueObjects are actually frozen pointers in the host - // but the pointed-to data lives in the debuggee, and GetPointeeData() - // automatically takes care of this + // ValueObjects are actually frozen pointers in the host but the pointed- + // to data lives in the debuggee, and GetPointeeData() automatically + // takes care of this while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0) { total_bytes_read += bytes_read; const char *cstr = data.PeekCStr(0); @@ -1175,8 +1174,8 @@ const char *ValueObject::GetValueAsCString() { format_sp.reset(new TypeFormatImpl_Format(my_format)); if (GetValueAsCString(*format_sp.get(), m_value_str)) { if (!m_value_did_change && m_old_value_valid) { - // The value was gotten successfully, so we consider the - // value as changed if the value string differs + // The value was gotten successfully, so we consider the value as + // changed if the value string differs SetValueDidChange(m_old_value_str != m_value_str); } } @@ -1187,8 +1186,8 @@ const char *ValueObject::GetValueAsCString() { return m_value_str.c_str(); } -// if > 8bytes, 0 is returned. this method should mostly be used -// to read address values out of pointers +// if > 8bytes, 0 is returned. this method should mostly be used to read +// address values out of pointers uint64_t ValueObject::GetValueAsUnsigned(uint64_t fail_value, bool *success) { // If our byte size is zero this is an aggregate type that has children if (CanProvideValue()) { @@ -1224,10 +1223,9 @@ int64_t ValueObject::GetValueAsSigned(int64_t fail_value, bool *success) { } // if any more "special cases" are added to -// ValueObject::DumpPrintableRepresentation() please keep -// this call up to date by returning true for your new special cases. We will -// eventually move -// to checking this call result before trying to display special cases +// ValueObject::DumpPrintableRepresentation() please keep this call up to date +// by returning true for your new special cases. We will eventually move to +// checking this call result before trying to display special cases bool ValueObject::HasSpecialPrintableRepresentation( ValueObjectRepresentationStyle val_obj_display, Format custom_format) { Flags flags(GetTypeInfo()); @@ -1276,8 +1274,7 @@ bool ValueObject::DumpPrintableRepresentation( if (flags.AnySet(eTypeIsArray | eTypeIsPointer) && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue) { // when being asked to get a printable display an array or pointer type - // directly, - // try to "do the right thing" + // directly, try to "do the right thing" if (IsCStringContainer(true) && (custom_format == eFormatCString || @@ -1309,8 +1306,8 @@ bool ValueObject::DumpPrintableRepresentation( if (custom_format == eFormatEnum) return false; - // this only works for arrays, because I have no way to know when - // the pointed memory ends, and no special \0 end of data marker + // this only works for arrays, because I have no way to know when the + // pointed memory ends, and no special \0 end of data marker if (flags.Test(eTypeIsArray)) { if ((custom_format == eFormatBytes) || (custom_format == eFormatBytesWithASCII)) { @@ -1406,8 +1403,8 @@ bool ValueObject::DumpPrintableRepresentation( llvm::StringRef str; // this is a local stream that we are using to ensure that the data pointed - // to by cstr survives long enough for us to copy it to its destination - it - // is necessary to have this temporary storage area for cases where our + // to by cstr survives long enough for us to copy it to its destination - + // it is necessary to have this temporary storage area for cases where our // desired output is not backed by some other longer-term storage StreamString strm; @@ -1485,9 +1482,9 @@ bool ValueObject::DumpPrintableRepresentation( s.PutCString("<no printable representation>"); } - // we should only return false here if we could not do *anything* - // even if we have an error message as output, that's a success - // from our callers' perspective, so return true + // we should only return false here if we could not do *anything* even if + // we have an error message as output, that's a success from our callers' + // perspective, so return true var_success = true; if (custom_format != eFormatInvalid) @@ -1590,9 +1587,8 @@ bool ValueObject::SetValueFromCString(const char *value_str, Status &error) { switch (value_type) { case Value::eValueTypeLoadAddress: { // If it is a load address, then the scalar value is the storage - // location - // of the data, and we have to shove this value down to that load - // location. + // location of the data, and we have to shove this value down to that + // load location. ExecutionContext exe_ctx(GetExecutionContextRef()); Process *process = exe_ctx.GetProcessPtr(); if (process) { @@ -1639,7 +1635,8 @@ bool ValueObject::SetValueFromCString(const char *value_str, Status &error) { return false; } - // If we have reached this point, then we have successfully changed the value. + // If we have reached this point, then we have successfully changed the + // value. SetNeedsUpdate(); return true; } @@ -1734,16 +1731,14 @@ bool ValueObject::IsUninitializedReference() { return false; } -// This allows you to create an array member using and index -// that doesn't not fall in the normal bounds of the array. -// Many times structure can be defined as: -// struct Collection -// { +// This allows you to create an array member using and index that doesn't not +// fall in the normal bounds of the array. Many times structure can be defined +// as: struct Collection { // uint32_t item_count; // Item item_array[0]; // }; -// The size of the "item_array" is 1, but many times in practice -// there are more items in "item_array". +// The size of the "item_array" is 1, but many times in practice there are more +// items in "item_array". ValueObjectSP ValueObject::GetSyntheticArrayMember(size_t index, bool can_create) { @@ -1752,13 +1747,13 @@ ValueObjectSP ValueObject::GetSyntheticArrayMember(size_t index, char index_str[64]; snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index); ConstString index_const_str(index_str); - // Check if we have already created a synthetic array member in this - // valid object. If we have we will re-use it. + // Check if we have already created a synthetic array member in this valid + // object. If we have we will re-use it. synthetic_child_sp = GetSyntheticChild(index_const_str); if (!synthetic_child_sp) { ValueObject *synthetic_child; - // We haven't made a synthetic array member for INDEX yet, so - // lets make one and cache it for any future reference. + // We haven't made a synthetic array member for INDEX yet, so lets make + // one and cache it for any future reference. synthetic_child = CreateChildAtIndex(0, true, index); // Cache the value if we got one back... @@ -1780,8 +1775,8 @@ ValueObjectSP ValueObject::GetSyntheticBitFieldChild(uint32_t from, uint32_t to, char index_str[64]; snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to); ConstString index_const_str(index_str); - // Check if we have already created a synthetic array member in this - // valid object. If we have we will re-use it. + // Check if we have already created a synthetic array member in this valid + // object. If we have we will re-use it. synthetic_child_sp = GetSyntheticChild(index_const_str); if (!synthetic_child_sp) { uint32_t bit_field_size = to - from + 1; @@ -1789,8 +1784,8 @@ ValueObjectSP ValueObject::GetSyntheticBitFieldChild(uint32_t from, uint32_t to, if (GetDataExtractor().GetByteOrder() == eByteOrderBig) bit_field_offset = GetByteSize() * 8 - bit_field_size - bit_field_offset; - // We haven't made a synthetic array member for INDEX yet, so - // lets make one and cache it for any future reference. + // We haven't made a synthetic array member for INDEX yet, so lets make + // one and cache it for any future reference. ValueObjectChild *synthetic_child = new ValueObjectChild( *this, GetCompilerType(), index_const_str, GetByteSize(), 0, bit_field_size, bit_field_offset, false, false, eAddressTypeInvalid, @@ -1820,8 +1815,8 @@ ValueObjectSP ValueObject::GetSyntheticChildAtOffset( name_const_str.SetCString(name_str); } - // Check if we have already created a synthetic array member in this - // valid object. If we have we will re-use it. + // Check if we have already created a synthetic array member in this valid + // object. If we have we will re-use it. synthetic_child_sp = GetSyntheticChild(name_const_str); if (synthetic_child_sp.get()) @@ -1858,8 +1853,8 @@ ValueObjectSP ValueObject::GetSyntheticBase(uint32_t offset, name_const_str.SetCString(name_str); } - // Check if we have already created a synthetic array member in this - // valid object. If we have we will re-use it. + // Check if we have already created a synthetic array member in this valid + // object. If we have we will re-use it. synthetic_child_sp = GetSyntheticChild(name_const_str); if (synthetic_child_sp.get()) @@ -1884,11 +1879,10 @@ ValueObjectSP ValueObject::GetSyntheticBase(uint32_t offset, return synthetic_child_sp; } -// your expression path needs to have a leading . or -> -// (unless it somehow "looks like" an array, in which case it has -// a leading [ symbol). while the [ is meaningful and should be shown -// to the user, . and -> are just parser design, but by no means -// added information for the user.. strip them off +// your expression path needs to have a leading . or -> (unless it somehow +// "looks like" an array, in which case it has a leading [ symbol). while the [ +// is meaningful and should be shown to the user, . and -> are just parser +// design, but by no means added information for the user.. strip them off static const char *SkipLeadingExpressionPathSeparators(const char *expression) { if (!expression || !expression[0]) return expression; @@ -1904,12 +1898,12 @@ ValueObject::GetSyntheticExpressionPathChild(const char *expression, bool can_create) { ValueObjectSP synthetic_child_sp; ConstString name_const_string(expression); - // Check if we have already created a synthetic array member in this - // valid object. If we have we will re-use it. + // Check if we have already created a synthetic array member in this valid + // object. If we have we will re-use it. synthetic_child_sp = GetSyntheticChild(name_const_string); if (!synthetic_child_sp) { - // We haven't made a synthetic array member for expression yet, so - // lets make one and cache it for any future reference. + // We haven't made a synthetic array member for expression yet, so lets + // make one and cache it for any future reference. synthetic_child_sp = GetValueForExpressionPath( expression, NULL, NULL, GetValueForExpressionPathOptions().SetSyntheticChildrenTraversal( @@ -2055,10 +2049,9 @@ bool ValueObject::IsBaseClass(uint32_t &depth) { void ValueObject::GetExpressionPath(Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat) { // synthetic children do not actually "exist" as part of the hierarchy, and - // sometimes they are consed up in ways - // that don't make sense from an underlying language/API standpoint. So, use a - // special code path here to return - // something that can hopefully be used in expression + // sometimes they are consed up in ways that don't make sense from an + // underlying language/API standpoint. So, use a special code path here to + // return something that can hopefully be used in expression if (m_is_synthetic_children_generated) { UpdateValueIfNeeded(); @@ -2092,11 +2085,10 @@ void ValueObject::GetExpressionPath(Stream &s, bool qualify_cxx_base_classes, if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers) { // this is the original format of GetExpressionPath() producing code like - // *(a_ptr).memberName, which is entirely - // fine, until you put this into + // *(a_ptr).memberName, which is entirely fine, until you put this into // StackFrame::GetValueForVariableExpressionPath() which prefers to see - // a_ptr->memberName. - // the eHonorPointers mode is meant to produce strings in this latter format + // a_ptr->memberName. the eHonorPointers mode is meant to produce strings + // in this latter format s.PutCString("*("); } @@ -2105,9 +2097,9 @@ void ValueObject::GetExpressionPath(Stream &s, bool qualify_cxx_base_classes, if (parent) parent->GetExpressionPath(s, qualify_cxx_base_classes, epformat); - // if we are a deref_of_parent just because we are synthetic array - // members made up to allow ptr[%d] syntax to work in variable - // printing, then add our name ([%d]) to the expression path + // if we are a deref_of_parent just because we are synthetic array members + // made up to allow ptr[%d] syntax to work in variable printing, then add our + // name ([%d]) to the expression path if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers) s.PutCString(m_name.AsCString()); @@ -2355,8 +2347,8 @@ ValueObjectSP ValueObject::GetValueForExpressionPath_Impl( } // if we are here and options.m_no_synthetic_children is true, - // child_valobj_sp is going to be a NULL SP, - // so we hit the "else" branch, and return an error + // child_valobj_sp is going to be a NULL SP, so we hit the "else" + // branch, and return an error if (child_valobj_sp.get()) // if it worked, just return { *reason_to_stop = @@ -2424,8 +2416,8 @@ ValueObjectSP ValueObject::GetValueForExpressionPath_Impl( } // if we are here and options.m_no_synthetic_children is true, - // child_valobj_sp is going to be a NULL SP, - // so we hit the "else" branch, and return an error + // child_valobj_sp is going to be a NULL SP, so we hit the "else" + // branch, and return an error if (child_valobj_sp.get()) // if it worked, move on { root = child_valobj_sp; @@ -2506,8 +2498,8 @@ ValueObjectSP ValueObject::GetValueForExpressionPath_Impl( assert(!bracket_expr.empty()); if (!bracket_expr.contains('-')) { - // if no separator, this is of the form [N]. Note that this cannot - // be an unbounded range of the form [], because that case was handled + // if no separator, this is of the form [N]. Note that this cannot be + // an unbounded range of the form [], because that case was handled // above with an unconditional return. unsigned long index = 0; if (bracket_expr.getAsInteger(0, index)) { @@ -2631,8 +2623,8 @@ ValueObjectSP ValueObject::GetValueForExpressionPath_Impl( *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; return nullptr; } - // if we are here, then root itself is a synthetic VO.. should be good - // to go + // if we are here, then root itself is a synthetic VO.. should be + // good to go if (!root) { *reason_to_stop = @@ -3031,20 +3023,17 @@ ValueObject::EvaluationPoint::EvaluationPoint( ValueObject::EvaluationPoint::~EvaluationPoint() {} // This function checks the EvaluationPoint against the current process state. -// If the current -// state matches the evaluation point, or the evaluation point is already -// invalid, then we return -// false, meaning "no change". If the current state is different, we update our -// state, and return -// true meaning "yes, change". If we did see a change, we also set -// m_needs_update to true, so -// future calls to NeedsUpdate will return true. -// exe_scope will be set to the current execution context scope. +// If the current state matches the evaluation point, or the evaluation point +// is already invalid, then we return false, meaning "no change". If the +// current state is different, we update our state, and return true meaning +// "yes, change". If we did see a change, we also set m_needs_update to true, +// so future calls to NeedsUpdate will return true. exe_scope will be set to +// the current execution context scope. bool ValueObject::EvaluationPoint::SyncWithProcessState( bool accept_invalid_exe_ctx) { - // Start with the target, if it is NULL, then we're obviously not going to get - // any further: + // Start with the target, if it is NULL, then we're obviously not going to + // get any further: const bool thread_and_frame_only_if_stopped = true; ExecutionContext exe_ctx( m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped)); @@ -3061,8 +3050,8 @@ bool ValueObject::EvaluationPoint::SyncWithProcessState( ProcessModID current_mod_id = process->GetModID(); // If the current stop id is 0, either we haven't run yet, or the process - // state has been cleared. - // In either case, we aren't going to be able to sync with the process state. + // state has been cleared. In either case, we aren't going to be able to sync + // with the process state. if (current_mod_id.GetStopID() == 0) return false; @@ -3070,8 +3059,8 @@ bool ValueObject::EvaluationPoint::SyncWithProcessState( const bool was_valid = m_mod_id.IsValid(); if (was_valid) { if (m_mod_id == current_mod_id) { - // Everything is already up to date in this object, no need to - // update the execution context scope. + // Everything is already up to date in this object, no need to update the + // execution context scope. changed = false; } else { m_mod_id = current_mod_id; @@ -3081,10 +3070,9 @@ bool ValueObject::EvaluationPoint::SyncWithProcessState( } // Now re-look up the thread and frame in case the underlying objects have - // gone away & been recreated. - // That way we'll be sure to return a valid exe_scope. - // If we used to have a thread or a frame but can't find it anymore, then mark - // ourselves as invalid. + // gone away & been recreated. That way we'll be sure to return a valid + // exe_scope. If we used to have a thread or a frame but can't find it + // anymore, then mark ourselves as invalid. if (!accept_invalid_exe_ctx) { if (m_exe_ctx_ref.HasThreadRef()) { @@ -3299,11 +3287,9 @@ void ValueObject::SetPreferredDisplayLanguageIfNeeded(lldb::LanguageType lt) { } bool ValueObject::CanProvideValue() { - // we need to support invalid types as providers of values because some - // bare-board - // debugging scenarios have no notion of types, but still manage to have raw - // numeric - // values for things like registers. sigh. + // we need to support invalid types as providers of values because some bare- + // board debugging scenarios have no notion of types, but still manage to + // have raw numeric values for things like registers. sigh. const CompilerType &type(GetCompilerType()); return (false == type.IsValid()) || (0 != (type.GetTypeInfo() & eTypeHasValue)); @@ -3326,7 +3312,9 @@ ValueObjectSP ValueObject::Persist() { if (!persistent_state) return nullptr; - ConstString name(persistent_state->GetNextPersistentVariableName()); + auto prefix = persistent_state->GetPersistentVariablePrefix(); + ConstString name = + persistent_state->GetNextPersistentVariableName(*target_sp, prefix); ValueObjectSP const_result_sp = ValueObjectConstResult::Create(target_sp.get(), GetValue(), name); |
