[Lldb-commits] [lldb] r268098 - Make sure LLDB can deal with forward declarations to enums without crashing or asserting.
Greg Clayton via lldb-commits
lldb-commits at lists.llvm.org
Fri Apr 29 13:48:39 PDT 2016
Author: gclayton
Date: Fri Apr 29 15:48:39 2016
New Revision: 268098
URL: http://llvm.org/viewvc/llvm-project?rev=268098&view=rev
Log:
Make sure LLDB can deal with forward declarations to enums without crashing or asserting.
<rdar://problem/23776428>
Modified:
lldb/trunk/packages/Python/lldbsuite/test/lang/c/enum_types/TestEnumTypes.py
lldb/trunk/packages/Python/lldbsuite/test/lang/c/enum_types/main.c
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
lldb/trunk/source/Symbol/ClangASTContext.cpp
Modified: lldb/trunk/packages/Python/lldbsuite/test/lang/c/enum_types/TestEnumTypes.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/c/enum_types/TestEnumTypes.py?rev=268098&r1=268097&r2=268098&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/c/enum_types/TestEnumTypes.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/c/enum_types/TestEnumTypes.py Fri Apr 29 15:48:39 2016
@@ -63,7 +63,14 @@ class EnumTypesTestCase(TestBase):
'Sunday',
'kNumDays',
'5'];
-
+
+ # Make sure a pointer to an anonymous enum type does crash LLDB and displays correctly using
+ # frame variable and expression commands
+ self.expect('frame variable f.op', DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ['ops *', 'f.op', '0x0000000000000000'])
+ self.expect('frame variable *f.op', DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ['ops', '*f.op', '<parent is NULL>'])
+ self.expect('expr f.op', DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ['ops *', '$', '0x0000000000000000'])
+ self.expect('expr *f.op', DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ['error:'], error = True)
+
bkpt = self.target().FindBreakpointByID(bkpt_id)
for enum_value in enum_values:
self.expect("frame variable day", 'check for valid enumeration value',
Modified: lldb/trunk/packages/Python/lldbsuite/test/lang/c/enum_types/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/c/enum_types/main.c?rev=268098&r1=268097&r2=268098&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/c/enum_types/main.c (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/c/enum_types/main.c Fri Apr 29 15:48:39 2016
@@ -8,6 +8,15 @@
//===----------------------------------------------------------------------===//
#include <stdio.h>
+#include <stdio.h>
+
+// Forward declare an enumeration (only works in C, not C++)
+typedef enum ops ops;
+
+struct foo {
+ ops *op;
+};
+
int main (int argc, char const *argv[])
{
enum days {
@@ -21,6 +30,8 @@ int main (int argc, char const *argv[])
kNumDays
};
enum days day;
+ struct foo f;
+ f.op = NULL;
for (day = Monday - 1; day <= kNumDays + 1; day++)
{
printf("day as int is %i\n", (int)day); // Set break point at this line.
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp?rev=268098&r1=268097&r2=268098&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp Fri Apr 29 15:48:39 2016
@@ -1011,9 +1011,18 @@ DWARFASTParserClang::ParseTypeFromDWARF
}
if (!enumerator_clang_type)
- enumerator_clang_type = m_ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
- DW_ATE_signed,
- byte_size * 8);
+ {
+ if (byte_size > 0)
+ {
+ enumerator_clang_type = m_ast.GetBuiltinTypeForDWARFEncodingAndBitSize(NULL,
+ DW_ATE_signed,
+ byte_size * 8);
+ }
+ else
+ {
+ enumerator_clang_type = m_ast.GetBasicType(eBasicTypeInt);
+ }
+ }
clang_type = m_ast.CreateEnumerationType (type_name_cstr,
GetClangDeclContextContainingDIE (die, nullptr),
Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=268098&r1=268097&r2=268098&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Fri Apr 29 15:48:39 2016
@@ -8545,24 +8545,28 @@ ClangASTContext::CompleteTagDeclarationD
clang::ASTContext *ast = lldb_ast->getASTContext();
/// TODO This really needs to be fixed.
-
- unsigned NumPositiveBits = 1;
- unsigned NumNegativeBits = 0;
-
- clang::QualType promotion_qual_type;
- // If the enum integer type is less than an integer in bit width,
- // then we must promote it to an integer size.
- if (ast->getTypeSize(enum_decl->getIntegerType()) < ast->getTypeSize(ast->IntTy))
+
+ QualType integer_type(enum_decl->getIntegerType());
+ if (!integer_type.isNull())
{
- if (enum_decl->getIntegerType()->isSignedIntegerType())
- promotion_qual_type = ast->IntTy;
+ unsigned NumPositiveBits = 1;
+ unsigned NumNegativeBits = 0;
+
+ clang::QualType promotion_qual_type;
+ // If the enum integer type is less than an integer in bit width,
+ // then we must promote it to an integer size.
+ if (ast->getTypeSize(enum_decl->getIntegerType()) < ast->getTypeSize(ast->IntTy))
+ {
+ if (enum_decl->getIntegerType()->isSignedIntegerType())
+ promotion_qual_type = ast->IntTy;
+ else
+ promotion_qual_type = ast->UnsignedIntTy;
+ }
else
- promotion_qual_type = ast->UnsignedIntTy;
+ promotion_qual_type = enum_decl->getIntegerType();
+
+ enum_decl->completeDefinition(enum_decl->getIntegerType(), promotion_qual_type, NumPositiveBits, NumNegativeBits);
}
- else
- promotion_qual_type = enum_decl->getIntegerType();
-
- enum_decl->completeDefinition(enum_decl->getIntegerType(), promotion_qual_type, NumPositiveBits, NumNegativeBits);
}
return true;
}
More information about the lldb-commits
mailing list