<rdar://problem/12560257>

Fixed zero sized arrays to work correctly. This will only happen once we get a clang that emits correct debug info for zero sized arrays. For now I have marked the TestStructTypes.py as an expected failure.

llvm-svn: 169465
This commit is contained in:
Greg Clayton 2012-12-06 02:33:54 +00:00
parent 16846051db
commit 4ef877f5e9
10 changed files with 468 additions and 397 deletions

View File

@ -786,8 +786,7 @@ public:
lldb::clang_type_t
CreateArrayType (lldb::clang_type_t element_type,
size_t element_count,
uint32_t bit_stride);
size_t element_count);
//------------------------------------------------------------------
// Tag Declarations
@ -887,15 +886,17 @@ public:
static lldb::clang_type_t
GetAsArrayType (lldb::clang_type_t clang_type,
lldb::clang_type_t *member_type = NULL,
uint64_t *size = NULL);
lldb::clang_type_t *member_type,
uint64_t *size,
bool *is_incomplete);
static bool
IsArrayType (lldb::clang_type_t clang_type,
lldb::clang_type_t *member_type = NULL,
uint64_t *size = NULL)
lldb::clang_type_t *member_type,
uint64_t *size,
bool *is_incomplete)
{
return GetAsArrayType(clang_type, member_type, size) != 0;
return GetAsArrayType(clang_type, member_type, size, is_incomplete) != 0;
}
//------------------------------------------------------------------

View File

@ -1551,7 +1551,7 @@ Debugger::FormatPrompt
}
// TODO use flags for these
bool is_array = ClangASTContext::IsArrayType(target->GetClangType());
bool is_array = ClangASTContext::IsArrayType(target->GetClangType(), NULL, NULL, NULL);
bool is_pointer = ClangASTContext::IsPointerType(target->GetClangType());
bool is_aggregate = ClangASTContext::IsAggregateType(target->GetClangType());

View File

@ -202,7 +202,6 @@ Value::GetValueByteSize (clang::ASTContext *ast_context, Error *error_ptr)
byte_size = GetRegisterInfo()->byte_size;
else if (error_ptr)
error_ptr->SetErrorString ("Can't determine byte size with NULL RegisterInfo *.");
break;
case eContextTypeLLDBType: // Type *

View File

@ -675,7 +675,7 @@ ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int3
child_bitfield_bit_offset,
child_is_base_class,
child_is_deref_of_parent);
if (child_clang_type && child_byte_size)
if (child_clang_type)
{
if (synthetic_index)
child_byte_offset += child_byte_size * synthetic_index;
@ -1798,7 +1798,7 @@ ValueObject::IsPointerType ()
bool
ValueObject::IsArrayType ()
{
return ClangASTContext::IsArrayType (GetClangType());
return ClangASTContext::IsArrayType (GetClangType(), NULL, NULL, NULL);
}
bool

View File

@ -4218,6 +4218,7 @@ SymbolFileDWARF::ParseChildArrayInfo
uint64_t num_elements = 0;
uint64_t lower_bound = 0;
uint64_t upper_bound = 0;
bool upper_bound_valid = false;
uint32_t i;
for (i=0; i<num_child_attributes; ++i)
{
@ -4247,6 +4248,7 @@ SymbolFileDWARF::ParseChildArrayInfo
break;
case DW_AT_upper_bound:
upper_bound_valid = true;
upper_bound = form_value.Unsigned();
break;
@ -4269,7 +4271,7 @@ SymbolFileDWARF::ParseChildArrayInfo
if (num_elements == 0)
{
if (upper_bound >= lower_bound)
if (upper_bound_valid && upper_bound >= lower_bound)
num_elements = upper_bound - lower_bound + 1;
}
@ -6534,10 +6536,9 @@ SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu,
{
num_elements = *pos;
clang_type = ast.CreateArrayType (array_element_type,
num_elements,
num_elements * array_element_bit_stride);
num_elements);
array_element_type = clang_type;
array_element_bit_stride = array_element_bit_stride * num_elements;
array_element_bit_stride = num_elements ? array_element_bit_stride * num_elements : array_element_bit_stride;
}
ConstString empty_name;
type_sp.reset( new Type (MakeUserID(die->GetOffset()),

View File

@ -2046,14 +2046,14 @@ ClangASTContext::BuildIndirectFields (clang::ASTContext *ast,
typedef llvm::SmallVector <IndirectFieldDecl *, 1> IndirectFieldVector;
IndirectFieldVector indirect_fields;
for (RecordDecl::field_iterator fi = record_decl->field_begin(), fe = record_decl->field_end();
fi != fe;
++fi)
RecordDecl::field_iterator field_pos;
RecordDecl::field_iterator field_end_pos = record_decl->field_end();
RecordDecl::field_iterator last_field_pos = field_end_pos;
for (field_pos = record_decl->field_begin(); field_pos != field_end_pos; last_field_pos = field_pos++)
{
if (fi->isAnonymousStructOrUnion())
if (field_pos->isAnonymousStructOrUnion())
{
QualType field_qual_type = fi->getType();
QualType field_qual_type = field_pos->getType();
const RecordType *field_record_type = field_qual_type->getAs<RecordType>();
@ -2072,7 +2072,7 @@ ClangASTContext::BuildIndirectFields (clang::ASTContext *ast,
if (FieldDecl *nested_field_decl = dyn_cast<FieldDecl>(*di))
{
NamedDecl **chain = new (*ast) NamedDecl*[2];
chain[0] = *fi;
chain[0] = *field_pos;
chain[1] = nested_field_decl;
IndirectFieldDecl *indirect_field = IndirectFieldDecl::Create(*ast,
record_decl,
@ -2082,7 +2082,7 @@ ClangASTContext::BuildIndirectFields (clang::ASTContext *ast,
chain,
2);
indirect_field->setAccess(UnifyAccessSpecifiers(fi->getAccess(),
indirect_field->setAccess(UnifyAccessSpecifiers(field_pos->getAccess(),
nested_field_decl->getAccess()));
indirect_fields.push_back(indirect_field);
@ -2091,7 +2091,7 @@ ClangASTContext::BuildIndirectFields (clang::ASTContext *ast,
{
int nested_chain_size = nested_indirect_field_decl->getChainingSize();
NamedDecl **chain = new (*ast) NamedDecl*[nested_chain_size + 1];
chain[0] = *fi;
chain[0] = *field_pos;
int chain_index = 1;
for (IndirectFieldDecl::chain_iterator nci = nested_indirect_field_decl->chain_begin(),
@ -2111,7 +2111,7 @@ ClangASTContext::BuildIndirectFields (clang::ASTContext *ast,
chain,
nested_chain_size + 1);
indirect_field->setAccess(UnifyAccessSpecifiers(fi->getAccess(),
indirect_field->setAccess(UnifyAccessSpecifiers(field_pos->getAccess(),
nested_indirect_field_decl->getAccess()));
indirect_fields.push_back(indirect_field);
@ -2120,6 +2120,14 @@ ClangASTContext::BuildIndirectFields (clang::ASTContext *ast,
}
}
// Check the last field to see if it has an incomplete array type as its
// last member and if it does, the tell the record decl about it
if (last_field_pos != field_end_pos)
{
if (last_field_pos->getType()->isIncompleteArrayType())
record_decl->hasFlexibleArrayMember();
}
for (IndirectFieldVector::iterator ifi = indirect_fields.begin(), ife = indirect_fields.end();
ifi < ife;
++ifi)
@ -3864,17 +3872,19 @@ ClangASTContext::GetChildClangTypeAtIndex
if (parent_clang_type == NULL)
return NULL;
if (idx < ClangASTContext::GetNumChildren (ast, parent_clang_type, omit_empty_base_classes))
{
uint32_t bit_offset;
QualType parent_qual_type(QualType::getFromOpaquePtr(parent_clang_type));
const clang::Type::TypeClass parent_type_class = parent_qual_type->getTypeClass();
child_bitfield_bit_size = 0;
child_bitfield_bit_offset = 0;
child_is_base_class = false;
QualType parent_qual_type(QualType::getFromOpaquePtr(parent_clang_type));
const clang::Type::TypeClass parent_type_class = parent_qual_type->getTypeClass();
const bool idx_is_valid = idx < ClangASTContext::GetNumChildren (ast, parent_clang_type, omit_empty_base_classes);
uint32_t bit_offset;
switch (parent_type_class)
{
case clang::Type::Builtin:
if (idx_is_valid)
{
switch (cast<clang::BuiltinType>(parent_qual_type)->getKind())
{
case clang::BuiltinType::ObjCId:
@ -3886,10 +3896,11 @@ ClangASTContext::GetChildClangTypeAtIndex
default:
break;
}
}
break;
case clang::Type::Record:
if (GetCompleteQualType (ast, parent_qual_type))
if (idx_is_valid && GetCompleteQualType (ast, parent_qual_type))
{
const RecordType *record_type = cast<RecordType>(parent_qual_type.getTypePtr());
const RecordDecl *record_decl = record_type->getDecl();
@ -3977,7 +3988,7 @@ ClangASTContext::GetChildClangTypeAtIndex
case clang::Type::ObjCObject:
case clang::Type::ObjCInterface:
if (GetCompleteQualType (ast, parent_qual_type))
if (idx_is_valid && GetCompleteQualType (ast, parent_qual_type))
{
const ObjCObjectType *objc_class_type = dyn_cast<ObjCObjectType>(parent_qual_type.getTypePtr());
assert (objc_class_type);
@ -4090,6 +4101,7 @@ ClangASTContext::GetChildClangTypeAtIndex
break;
case clang::Type::ObjCObjectPointer:
if (idx_is_valid)
{
const ObjCObjectPointerType *pointer_type = cast<ObjCObjectPointerType>(parent_qual_type.getTypePtr());
QualType pointee_type = pointer_type->getPointeeType();
@ -4137,11 +4149,11 @@ ClangASTContext::GetChildClangTypeAtIndex
break;
case clang::Type::ConstantArray:
case clang::Type::IncompleteArray:
if (ignore_array_bounds || idx_is_valid)
{
const ConstantArrayType *array = cast<ConstantArrayType>(parent_qual_type.getTypePtr());
const uint64_t element_count = array->getSize().getLimitedValue();
if (ignore_array_bounds || idx < element_count)
const ArrayType *array = cast<ArrayType>(parent_qual_type.getTypePtr());
if (array)
{
if (GetCompleteQualType (ast, array->getElementType()))
{
@ -4160,7 +4172,9 @@ ClangASTContext::GetChildClangTypeAtIndex
}
break;
case clang::Type::Pointer:
if (idx_is_valid)
{
const PointerType *pointer_type = cast<PointerType>(parent_qual_type.getTypePtr());
QualType pointee_type = pointer_type->getPointeeType();
@ -4214,6 +4228,7 @@ ClangASTContext::GetChildClangTypeAtIndex
case clang::Type::LValueReference:
case clang::Type::RValueReference:
if (idx_is_valid)
{
const ReferenceType *reference_type = cast<ReferenceType>(parent_qual_type.getTypePtr());
QualType pointee_type(reference_type->getPointeeType());
@ -4297,7 +4312,6 @@ ClangASTContext::GetChildClangTypeAtIndex
default:
break;
}
}
return NULL;
}
@ -5250,18 +5264,28 @@ ClangASTContext::SetFunctionParameters (FunctionDecl *function_decl, ParmVarDecl
#pragma mark Array Types
clang_type_t
ClangASTContext::CreateArrayType (clang_type_t element_type, size_t element_count, uint32_t bit_stride)
ClangASTContext::CreateArrayType (clang_type_t element_type, size_t element_count)
{
if (element_type)
{
ASTContext *ast = getASTContext();
assert (ast != NULL);
llvm::APInt ap_element_count (64, element_count);
if (element_count == 0)
{
return ast->getIncompleteArrayType(QualType::getFromOpaquePtr(element_type),
ArrayType::Normal,
0).getAsOpaquePtr();
}
else
{
return ast->getConstantArrayType(QualType::getFromOpaquePtr(element_type),
ap_element_count,
ArrayType::Normal,
0).getAsOpaquePtr(); // ElemQuals
}
}
return NULL;
}
@ -5931,7 +5955,7 @@ ClangASTContext::IsPointerToScalarType (lldb::clang_type_t clang_type)
bool
ClangASTContext::IsArrayOfScalarType (lldb::clang_type_t clang_type)
{
clang_type = GetAsArrayType(clang_type);
clang_type = GetAsArrayType(clang_type, NULL, NULL, NULL);
if (clang_type == 0)
return false;
@ -6151,8 +6175,10 @@ ClangASTContext::GetArraySize (clang_type_t clang_type)
}
clang_type_t
ClangASTContext::GetAsArrayType (clang_type_t clang_type, clang_type_t*member_type, uint64_t *size)
ClangASTContext::GetAsArrayType (clang_type_t clang_type, clang_type_t*member_type, uint64_t *size, bool *is_incomplete)
{
if (is_incomplete)
*is_incomplete = false;
if (!clang_type)
return 0;
@ -6176,6 +6202,8 @@ ClangASTContext::GetAsArrayType (clang_type_t clang_type, clang_type_t*member_ty
*member_type = cast<IncompleteArrayType>(qual_type)->getElementType().getAsOpaquePtr();
if (size)
*size = 0;
if (is_incomplete)
*is_incomplete = true;
return clang_type;
case clang::Type::VariableArray:
@ -6195,12 +6223,14 @@ ClangASTContext::GetAsArrayType (clang_type_t clang_type, clang_type_t*member_ty
case clang::Type::Typedef:
return ClangASTContext::GetAsArrayType (cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(),
member_type,
size);
size,
is_incomplete);
case clang::Type::Elaborated:
return ClangASTContext::GetAsArrayType (cast<ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(),
member_type,
size);
size,
is_incomplete);
}
return 0;
}

View File

@ -1178,7 +1178,13 @@ ClangASTType::GetClangTypeBitWidth (clang::ASTContext *ast_context, clang_type_t
if (ClangASTContext::GetCompleteType (ast_context, clang_type))
{
clang::QualType qual_type(clang::QualType::getFromOpaquePtr(clang_type));
return ast_context->getTypeSize (qual_type);
const uint32_t bit_size = ast_context->getTypeSize (qual_type);
if (bit_size == 0)
{
if (qual_type->isIncompleteArrayType())
return ast_context->getTypeSize (qual_type->getArrayElementTypeNoTypeQual()->getCanonicalTypeUnqualified());
}
return bit_size;
}
return 0;
}

View File

@ -792,6 +792,7 @@ StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr,
deref = false;
}
bool is_incomplete_array = false;
if (valobj_sp->IsPointerType ())
{
bool is_objc_pointer = true;
@ -855,11 +856,14 @@ StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr,
}
}
}
else if (ClangASTContext::IsArrayType (valobj_sp->GetClangType(), NULL, NULL))
else if (ClangASTContext::IsArrayType (valobj_sp->GetClangType(), NULL, NULL, &is_incomplete_array))
{
// Pass false to dynamic_value here so we can tell the difference between
// no dynamic value and no member of this type...
child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true);
if (!child_valobj_sp && (is_incomplete_array || no_synth_child == false))
child_valobj_sp = valobj_sp->GetSyntheticArrayMember (child_index, true);
if (!child_valobj_sp)
{
valobj_sp->GetExpressionPath (var_expr_path_strm, false);

View File

@ -14,6 +14,8 @@ class StructTypesTestCase(TestBase):
mydir = os.path.join("lang", "c", "struct_types")
# rdar://problem/12566646
@unittest2.expectedFailure
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
@dsym_test
def test_with_dsym(self):
@ -31,19 +33,31 @@ class StructTypesTestCase(TestBase):
# Call super's setUp().
TestBase.setUp(self)
# Find the line number to break for main.c.
self.line = line_number('main.c', '// Set break point at this line.')
self.first_executable_line = line_number('main.c',
self.source = 'main.c'
self.line = line_number(self.source, '// Set break point at this line.')
self.first_executable_line = line_number(self.source,
'// This is the first executable statement.')
self.return_line = line_number(self.source, '// This is the return statement.')
def struct_types(self):
"""Test that break on a struct declaration has no effect."""
"""Test that break on a struct declaration has no effect and test structure access for zero sized arrays."""
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
# Create a target by the debugger.
target = self.dbg.CreateTarget(exe)
self.assertTrue(target, VALID_TARGET)
# Break on the struct declration statement in main.c.
lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line, num_expected_locations=1, loc_exact=False)
lldbutil.run_break_set_by_file_and_line (self, "main.c", self.return_line, num_expected_locations=1, loc_exact=True)
self.runCmd("run", RUN_SUCCEEDED)
# Now launch the process, and do not stop at entry point.
process = target.LaunchSimple(None, None, os.getcwd())
if not process:
self.fail("SBTarget.Launch() failed")
thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
# We should be stopped on the first executable statement within the
# function where the original breakpoint was attempted.
@ -55,10 +69,26 @@ class StructTypesTestCase(TestBase):
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
substrs = [' resolved, hit count = 1'])
process.Continue()
thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
# Test zero length array access and make sure it succeeds with "frame variable"
self.expect("frame variable pt.padding[0]",
DATA_TYPES_DISPLAYED_CORRECTLY,
substrs = ["pt.padding[0] = '"])
self.expect("frame variable pt.padding[1]",
DATA_TYPES_DISPLAYED_CORRECTLY,
substrs = ["pt.padding[1] = '"])
# Test zero length array access and make sure it succeeds with "expression"
self.expect("expression -- pt.padding[0]",
DATA_TYPES_DISPLAYED_CORRECTLY,
substrs = ["(char)", " = '"])
# The padding should be an array of size 0
self.expect("image lookup -t point_tag",
DATA_TYPES_DISPLAYED_CORRECTLY,
substrs = ['padding[0]'])
substrs = ['padding[]']) # Once rdar://problem/12566646 is fixed, this should display correctly
if __name__ == '__main__':

View File

@ -20,5 +20,5 @@ int main (int argc, char const *argv[])
};
struct point_tag pt = { 2, 3, {} }; // This is the first executable statement.
struct rect_tag rect = {{1, 2, {}}, {3, 4, {}}};
return 0;
return 0; // This is the return statement.
}