[Lldb-commits] [lldb] r134846 - in /lldb/trunk: include/lldb/Core/ValueObject.h include/lldb/Symbol/ClangASTContext.h source/API/SBType.cpp source/Commands/CommandObjectTarget.cpp source/Core/ValueObject.cpp source/Symbol/ClangASTContext.cpp source/Symbol/Variable.cpp

Greg Clayton gclayton at apple.com
Sat Jul 9 13:12:33 PDT 2011


Author: gclayton
Date: Sat Jul  9 15:12:33 2011
New Revision: 134846

URL: http://llvm.org/viewvc/llvm-project?rev=134846&view=rev
Log:
Fixed the global and static variables to always be in scope.

Made it so that you can create synthetic children of array
value objects. This is for creating array members when the
array index is out of range. This comes in handy when you have
a structure definition like:

struct Collection
{
    uint32_t count;
    Item array[0];
};
"array" has 1 item, but many times in practice there are more
items in "item_array".

This allows you to do:

(lldb) target variable g_collection.array[3]

To implement this, the get child at index has been modified
to have a "ignore_array_bounds" boolean that can be set to true.




Modified:
    lldb/trunk/include/lldb/Core/ValueObject.h
    lldb/trunk/include/lldb/Symbol/ClangASTContext.h
    lldb/trunk/source/API/SBType.cpp
    lldb/trunk/source/Commands/CommandObjectTarget.cpp
    lldb/trunk/source/Core/ValueObject.cpp
    lldb/trunk/source/Symbol/ClangASTContext.cpp
    lldb/trunk/source/Symbol/Variable.cpp

Modified: lldb/trunk/include/lldb/Core/ValueObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObject.h?rev=134846&r1=134845&r2=134846&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObject.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObject.h Sat Jul  9 15:12:33 2011
@@ -349,6 +349,9 @@
     IsPointerType ();
     
     virtual bool
+    IsArrayType ();
+    
+    virtual bool
     IsScalarType ();
 
     virtual bool
@@ -524,6 +527,9 @@
     GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create);
     
     lldb::ValueObjectSP
+    GetSyntheticArrayMemberFromArray (int32_t index, bool can_create);
+    
+    lldb::ValueObjectSP
     GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create);
     
     lldb::ValueObjectSP

Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=134846&r1=134845&r2=134846&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Sat Jul  9 15:12:33 2011
@@ -415,6 +415,7 @@
                               uint32_t idx,
                               bool transparent_pointers,
                               bool omit_empty_base_classes,
+                              bool ignore_array_bounds,
                               std::string& child_name,
                               uint32_t &child_byte_size,
                               int32_t &child_byte_offset,
@@ -431,6 +432,7 @@
                               uint32_t idx,
                               bool transparent_pointers,
                               bool omit_empty_base_classes,
+                              bool ignore_array_bounds,
                               std::string& child_name,
                               uint32_t &child_byte_size,
                               int32_t &child_byte_offset,

Modified: lldb/trunk/source/API/SBType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBType.cpp?rev=134846&r1=134845&r2=134846&view=diff
==============================================================================
--- lldb/trunk/source/API/SBType.cpp (original)
+++ lldb/trunk/source/API/SBType.cpp Sat Jul  9 15:12:33 2011
@@ -107,6 +107,7 @@
 SBType::GetChildAtIndex (bool omit_empty_base_classes, uint32_t idx, SBTypeMember &member)
 {
     void *child_clang_type = NULL;
+    bool ignore_array_bounds = false;
     std::string child_name;
     uint32_t child_byte_size = 0;
     int32_t child_byte_offset = 0;
@@ -125,6 +126,7 @@
                                                                       idx,
                                                                       false, // transparent pointers
                                                                       omit_empty_base_classes,
+                                                                      ignore_array_bounds,
                                                                       child_name,
                                                                       child_byte_size,
                                                                       child_byte_offset,

Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=134846&r1=134845&r2=134846&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Sat Jul  9 15:12:33 2011
@@ -545,7 +545,7 @@
                     else
                     {
                         Error error (Variable::GetValuesForVariableExpressionPath (arg,
-                                                                                   exe_ctx.target,
+                                                                                   exe_ctx.GetBestExecutionContextScope(),
                                                                                    GetVariableCallback,
                                                                                    exe_ctx.target,
                                                                                    variable_list,

Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=134846&r1=134845&r2=134846&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Sat Jul  9 15:12:33 2011
@@ -430,7 +430,7 @@
     ValueObject *valobj = NULL;
     
     bool omit_empty_base_classes = true;
-
+    bool ignore_array_bounds = synthetic_array_member;
     std::string child_name_str;
     uint32_t child_byte_size = 0;
     int32_t child_byte_offset = 0;
@@ -454,6 +454,7 @@
                                                                   idx,
                                                                   transparent_pointers,
                                                                   omit_empty_base_classes,
+                                                                  ignore_array_bounds,
                                                                   child_name_str,
                                                                   child_byte_size,
                                                                   child_byte_offset,
@@ -499,7 +500,9 @@
                 StreamString s;
                 ExecutionContext exe_ctx;
                 this->GetExecutionContextScope()->CalculateExecutionContext(exe_ctx);
-                SymbolContext sc = exe_ctx.frame->GetSymbolContext(eSymbolContextEverything);
+                SymbolContext sc;
+                if (exe_ctx.frame)
+                    sc = exe_ctx.frame->GetSymbolContext(eSymbolContextEverything);
                 
                 if (m_last_summary_format->m_show_members_oneliner)
                 {
@@ -1110,6 +1113,12 @@
 }
 
 bool
+ValueObject::IsArrayType ()
+{
+    return ClangASTContext::IsArrayType (GetClangType());
+}
+
+bool
 ValueObject::IsScalarType ()
 {
     return ClangASTContext::IsScalarType (GetClangType());
@@ -1171,6 +1180,49 @@
     return synthetic_child_sp;
 }
 
+// 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".
+
+ValueObjectSP
+ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
+{
+    ValueObjectSP synthetic_child_sp;
+    if (IsArrayType ())
+    {
+        char index_str[64];
+        snprintf(index_str, sizeof(index_str), "[%i]", 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.
+        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.
+            synthetic_child = CreateChildAtIndex(0, true, index);
+            
+            // Cache the value if we got one back...
+            if (synthetic_child)
+            {
+                AddSyntheticChild(index_const_str, synthetic_child);
+                synthetic_child_sp = synthetic_child->GetSP();
+                synthetic_child_sp->SetName(index_str);
+                synthetic_child_sp->m_is_array_item_for_pointer = true;
+            }
+        }
+    }
+    return synthetic_child_sp;
+}
+
 ValueObjectSP
 ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
 {
@@ -1628,20 +1680,23 @@
                     // from here on we do have a valid index
                     if (ClangASTContext::IsArrayType(root_clang_type))
                     {
-                        root = root->GetChildAtIndex(index, true);
-                        if (!root.get())
+                        ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
+                        if (!child_valobj_sp)
+                            child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
+                        if (child_valobj_sp)
+                        {
+                            root = child_valobj_sp;
+                            *first_unparsed = end+1; // skip ]
+                            *final_result = ValueObject::ePlain;
+                            continue;
+                        }
+                        else
                         {
                             *first_unparsed = expression_cstr;
                             *reason_to_stop = ValueObject::eNoSuchChild;
                             *final_result = ValueObject::eInvalid;
                             return ValueObjectSP();
                         }
-                        else
-                        {
-                            *first_unparsed = end+1; // skip ]
-                            *final_result = ValueObject::ePlain;
-                            continue;
-                        }
                     }
                     else if (ClangASTContext::IsPointerType(root_clang_type))
                     {
@@ -2057,6 +2112,7 @@
     if (is_pointer_type)
     {
         bool omit_empty_base_classes = true;
+        bool ignore_array_bounds = false;
 
         std::string child_name_str;
         uint32_t child_byte_size = 0;
@@ -2080,6 +2136,7 @@
                                                                       0,
                                                                       transparent_pointers,
                                                                       omit_empty_base_classes,
+                                                                      ignore_array_bounds,
                                                                       child_name_str,
                                                                       child_byte_size,
                                                                       child_byte_offset,

Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=134846&r1=134845&r2=134846&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Sat Jul  9 15:12:33 2011
@@ -2460,6 +2460,7 @@
     uint32_t idx,
     bool transparent_pointers,
     bool omit_empty_base_classes,
+    bool ignore_array_bounds,
     std::string& child_name,
     uint32_t &child_byte_size,
     int32_t &child_byte_offset,
@@ -2478,6 +2479,7 @@
                                          idx,
                                          transparent_pointers,
                                          omit_empty_base_classes,
+                                         ignore_array_bounds,
                                          child_name,
                                          child_byte_size,
                                          child_byte_offset,
@@ -2498,6 +2500,7 @@
     uint32_t idx,
     bool transparent_pointers,
     bool omit_empty_base_classes,
+    bool ignore_array_bounds,
     std::string& child_name,
     uint32_t &child_byte_size,
     int32_t &child_byte_offset,
@@ -2736,6 +2739,7 @@
                                                      idx,
                                                      transparent_pointers,
                                                      omit_empty_base_classes,
+                                                     ignore_array_bounds,
                                                      child_name,
                                                      child_byte_size,
                                                      child_byte_offset,
@@ -2771,7 +2775,7 @@
                 const ConstantArrayType *array = cast<ConstantArrayType>(parent_qual_type.getTypePtr());
                 const uint64_t element_count = array->getSize().getLimitedValue();
 
-                if (idx < element_count)
+                if (ignore_array_bounds || idx < element_count)
                 {
                     if (GetCompleteQualType (ast, array->getElementType()))
                     {
@@ -2783,7 +2787,7 @@
                         child_name.assign(element_name);
                         assert(field_type_info.first % 8 == 0);
                         child_byte_size = field_type_info.first / 8;
-                        child_byte_offset = idx * child_byte_size;
+                        child_byte_offset = (int32_t)idx * (int32_t)child_byte_size;
                         return array->getElementType().getAsOpaquePtr();
                     }
                 }
@@ -2810,6 +2814,7 @@
                                                      idx,
                                                      transparent_pointers,
                                                      omit_empty_base_classes,
+                                                     ignore_array_bounds,
                                                      child_name,
                                                      child_byte_size,
                                                      child_byte_offset,
@@ -2858,6 +2863,7 @@
                                                      idx,
                                                      transparent_pointers,
                                                      omit_empty_base_classes,
+                                                     ignore_array_bounds,
                                                      child_name,
                                                      child_byte_size,
                                                      child_byte_offset,
@@ -2895,6 +2901,7 @@
                                              idx,
                                              transparent_pointers,
                                              omit_empty_base_classes,
+                                             ignore_array_bounds,
                                              child_name,
                                              child_byte_size,
                                              child_byte_offset,

Modified: lldb/trunk/source/Symbol/Variable.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Variable.cpp?rev=134846&r1=134845&r2=134846&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/Variable.cpp (original)
+++ lldb/trunk/source/Symbol/Variable.cpp Sat Jul  9 15:12:33 2011
@@ -199,10 +199,10 @@
         return frame != NULL;
 
     case eValueTypeConstResult:
-        return true;
-
     case eValueTypeVariableGlobal:
     case eValueTypeVariableStatic:
+        return true;
+
     case eValueTypeVariableArgument:
     case eValueTypeVariableLocal:
         if (frame)





More information about the lldb-commits mailing list