summaryrefslogtreecommitdiffstats
path: root/lldb/source
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2011-01-14 04:54:56 +0000
committerGreg Clayton <gclayton@apple.com>2011-01-14 04:54:56 +0000
commitca512b397c460e47e53efd98408a3ef274e436e7 (patch)
treedf7edcd194fc9aea4bea9fb52cd2fbbddb405176 /lldb/source
parent5ca139100383cdfb929d053099ffadb4ada12626 (diff)
downloadbcm5719-llvm-ca512b397c460e47e53efd98408a3ef274e436e7.tar.gz
bcm5719-llvm-ca512b397c460e47e53efd98408a3ef274e436e7.zip
Fixed an error in the type map for "char **" that was a bad memory smasher.
Anytime we had a valid python list that was trying to go from Python down into our C++ API, it was allocating too little memory and it ended up smashing whatever was next to the allocated memory. Added typemap conversions for "void *, size_t" so we can get SBProcess::ReadMemory() working. Also added a typemap for "const void *, size_t" so we can get SBProcess::WriteMemory() to work. Fixed an issue in the DWARF parser where we weren't correctly calculating the DeclContext for all types and classes. We now should be a lot more accurate. Fixes include: enums should now be setting their parent decl context correctly. We saw a lot of examples where enums in classes were not being properly namespace scoped. Also, classes within classes now get properly scoped. Fixed the objective C runtime pointer checkers to let "nil" pointers through since these are accepted by compiled code. We also now don't call "abort()" when a pointer doesn't validate correctly since this was wreaking havoc on the process due to the way abort() works. We now just dereference memory which should give us an exception from which we can easily and reliably recover. llvm-svn: 123428
Diffstat (limited to 'lldb/source')
-rw-r--r--lldb/source/Core/Error.cpp15
-rw-r--r--lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp55
-rw-r--r--lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp117
-rw-r--r--lldb/source/Symbol/ClangASTContext.cpp10
4 files changed, 142 insertions, 55 deletions
diff --git a/lldb/source/Core/Error.cpp b/lldb/source/Core/Error.cpp
index 104dfc6d693..ee7d6f21cda 100644
--- a/lldb/source/Core/Error.cpp
+++ b/lldb/source/Core/Error.cpp
@@ -27,6 +27,13 @@
using namespace lldb;
using namespace lldb_private;
+Error::Error ():
+ m_code (0),
+ m_type (eErrorTypeInvalid),
+ m_string ()
+{
+}
+
//----------------------------------------------------------------------
// Default constructor
//----------------------------------------------------------------------
@@ -36,6 +43,14 @@ Error::Error(ValueType err, ErrorType type) :
m_string ()
{
}
+
+Error::Error (const Error &rhs) :
+ m_code (rhs.m_code),
+ m_type (rhs.m_type),
+ m_string (rhs.m_string)
+{
+}
+
//----------------------------------------------------------------------
// Assignment operator
//----------------------------------------------------------------------
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
index 0125a0373e8..c1e958e2941 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -124,40 +124,45 @@ AppleObjCRuntimeV2::SetExceptionBreakpoints ()
}
}
-struct BufStruct {
- char contents[1024];
-};
-
ClangUtilityFunction *
AppleObjCRuntimeV2::CreateObjectChecker(const char *name)
{
- std::auto_ptr<BufStruct> buf(new BufStruct);
+ char check_function_code[1024];
+ int len = 0;
if (m_has_object_getClass)
{
- assert(snprintf(&buf->contents[0], sizeof(buf->contents),
- "extern \"C\" void *gdb_object_getClass(void *); \n"
- "extern \"C\" void \n"
- "%s(void *$__lldb_arg_obj) \n"
- "{ \n"
- " if (!gdb_object_getClass($__lldb_arg_obj)) \n"
- " abort(); \n"
- "} \n",
- name) < sizeof(buf->contents));
+ len = ::snprintf (check_function_code,
+ sizeof(check_function_code),
+ "extern \"C\" void *gdb_object_getClass(void *); \n"
+ "extern \"C\" void \n"
+ "%s(void *$__lldb_arg_obj) \n"
+ "{ \n"
+ " if ($__lldb_arg_obj == (void *)0) \n"
+ " return; // nil is ok \n"
+ " if (!gdb_object_getClass($__lldb_arg_obj)) \n"
+ " *((volatile int *)0) = 'ocgc'; \n"
+ "} \n",
+ name);
}
else
{
- assert(snprintf(&buf->contents[0], sizeof(buf->contents),
- "extern \"C\" void *gdb_class_getClass(void *); \n"
- "extern \"C\" void \n"
- "%s(void *$__lldb_arg_obj) \n"
- "{ \n"
- " void **$isa_ptr = (void **)$__lldb_arg_obj; \n"
- " if (!$isa_ptr || !gdb_class_getClass(*$isa_ptr)) \n"
- " abort(); \n"
- "} \n",
- name) < sizeof(buf->contents));
+ len = ::snprintf (check_function_code,
+ sizeof(check_function_code),
+ "extern \"C\" void *gdb_class_getClass(void *); \n"
+ "extern \"C\" void \n"
+ "%s(void *$__lldb_arg_obj) \n"
+ "{ \n"
+ " if ($__lldb_arg_obj == (void *)0) \n"
+ " return; // nil is ok \n"
+ " void **$isa_ptr = (void **)$__lldb_arg_obj; \n"
+ " if (!gdb_class_getClass(*$isa_ptr)) \n"
+ " *((volatile int *)0) = 'ocgc'; \n"
+ "} \n",
+ name);
}
- return new ClangUtilityFunction(buf->contents, name);
+ assert (len < sizeof(check_function_code));
+
+ return new ClangUtilityFunction(check_function_code, name);
}
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index f40ad156a3d..ed916cc78ea 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -1300,7 +1300,21 @@ SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
DWARFCompileUnitSP cu_sp;
const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
if (type_die != NULL)
+ {
+ // We might be coming in in the middle of a type tree (a class
+ // withing a class, an enum within a class), so parse any needed
+ // parent DIEs before we get to this one...
+ const DWARFDebugInfoEntry* parent_die = type_die->GetParent();
+ switch (parent_die->Tag())
+ {
+ case DW_TAG_structure_type:
+ case DW_TAG_union_type:
+ case DW_TAG_class_type:
+ ResolveType(cu_sp.get(), parent_die);
+ break;
+ }
return ResolveType (cu_sp.get(), type_die);
+ }
}
return NULL;
}
@@ -2651,7 +2665,9 @@ SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoE
Type *type_ptr = m_die_to_type.lookup (die);
if (type_ptr == NULL)
{
- SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu));
+ CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(curr_cu);
+ assert (lldb_cu);
+ SymbolContext sc(lldb_cu);
type_sp = ParseType(sc, curr_cu, die, NULL);
}
else if (type_ptr != DIE_IS_BEING_PARSED)
@@ -2698,45 +2714,89 @@ SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *curr_cu, const DWARFDebu
clang::DeclContext *
SymbolFileDWARF::GetClangDeclContextForDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die)
{
- DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die);
- if (pos != m_die_to_decl_ctx.end())
- return pos->second;
+ if (m_clang_tu_decl == NULL)
+ m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
+ //printf ("SymbolFileDWARF::GetClangDeclContextForDIE ( die = 0x%8.8x )\n", die->GetOffset());
+ const DWARFDebugInfoEntry * const decl_die = die;
while (die != NULL)
{
- switch (die->Tag())
+ // If this is the original DIE that we are searching for a declaration
+ // for, then don't look in the cache as we don't want our own decl
+ // context to be our decl context...
+ if (decl_die != die)
{
- case DW_TAG_namespace:
+ DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die);
+ if (pos != m_die_to_decl_ctx.end())
{
- const char *namespace_name = die->GetAttributeValueAsString(this, curr_cu, DW_AT_name, NULL);
- if (namespace_name)
+ //printf ("SymbolFileDWARF::GetClangDeclContextForDIE ( die = 0x%8.8x ) => 0x%8.8x\n", decl_die->GetOffset(), die->GetOffset());
+ return pos->second;
+ }
+
+ //printf ("SymbolFileDWARF::GetClangDeclContextForDIE ( die = 0x%8.8x ) checking parent 0x%8.8x\n", decl_die->GetOffset(), die->GetOffset());
+
+ switch (die->Tag())
+ {
+ case DW_TAG_namespace:
{
- Declaration decl; // TODO: fill in the decl object
- clang::NamespaceDecl *namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, decl, GetClangDeclContextForDIE (curr_cu, die->GetParent()));
- if (namespace_decl)
- m_die_to_decl_ctx[die] = (clang::DeclContext*)namespace_decl;
- return namespace_decl;
+ const char *namespace_name = die->GetAttributeValueAsString(this, curr_cu, DW_AT_name, NULL);
+ if (namespace_name)
+ {
+ Declaration decl; // TODO: fill in the decl object
+ clang::NamespaceDecl *namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, decl, GetClangDeclContextForDIE (curr_cu, die->GetParent()));
+ if (namespace_decl)
+ {
+ //printf ("SymbolFileDWARF::GetClangDeclContextForDIE ( die = 0x%8.8x ) => 0x%8.8x\n", decl_die->GetOffset(), die->GetOffset());
+ m_die_to_decl_ctx[die] = (clang::DeclContext*)namespace_decl;
+ }
+ return namespace_decl;
+ }
}
- }
- break;
+ break;
- default:
- break;
+ case DW_TAG_structure_type:
+ case DW_TAG_union_type:
+ case DW_TAG_class_type:
+ {
+ ResolveType (curr_cu, die);
+ pos = m_die_to_decl_ctx.find(die);
+ assert (pos != m_die_to_decl_ctx.end());
+ if (pos != m_die_to_decl_ctx.end())
+ {
+ //printf ("SymbolFileDWARF::GetClangDeclContextForDIE ( die = 0x%8.8x ) => 0x%8.8x\n", decl_die->GetOffset(), die->GetOffset());
+ return pos->second;
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
}
+
clang::DeclContext *decl_ctx;
- decl_ctx = GetClangDeclContextForDIEOffset (die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_specification, DW_INVALID_OFFSET));
- if (decl_ctx)
- return decl_ctx;
+ dw_offset_t die_offset = die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_specification, DW_INVALID_OFFSET);
+ if (die_offset != DW_INVALID_OFFSET)
+ {
+ //printf ("SymbolFileDWARF::GetClangDeclContextForDIE ( die = 0x%8.8x ) check DW_AT_specification 0x%8.8x\n", decl_die->GetOffset(), die_offset);
+ decl_ctx = GetClangDeclContextForDIEOffset (die_offset);
+ if (decl_ctx != m_clang_tu_decl)
+ return decl_ctx;
+ }
- decl_ctx = GetClangDeclContextForDIEOffset (die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET));
- if (decl_ctx)
- return decl_ctx;
+ die_offset = die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
+ if (die_offset != DW_INVALID_OFFSET)
+ {
+ //printf ("SymbolFileDWARF::GetClangDeclContextForDIE ( die = 0x%8.8x ) check DW_AT_abstract_origin 0x%8.8x\n", decl_die->GetOffset(), die_offset);
+ decl_ctx = GetClangDeclContextForDIEOffset (die_offset);
+ if (decl_ctx != m_clang_tu_decl)
+ return decl_ctx;
+ }
die = die->GetParent();
}
// Right now we have only one translation unit per module...
- if (m_clang_tu_decl == NULL)
- m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
+ //printf ("SymbolFileDWARF::GetClangDeclContextForDIE ( die = 0x%8.8x ) => 0x%8.8x\n", decl_die->GetOffset(), curr_cu->GetFirstDIEOffset());
return m_clang_tu_decl;
}
@@ -3051,7 +3111,7 @@ SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu,
}
- if (is_forward_declaration)
+ if (is_forward_declaration && die->HasChildren() == false)
{
// We have a forward declaration to a type and we need
// to try and find a full declaration. We look in the
@@ -3183,8 +3243,9 @@ SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu,
enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
DW_ATE_signed,
byte_size * 8);
- clang_type = ast.CreateEnumerationType (decl,
- type_name_cstr,
+ clang_type = ast.CreateEnumerationType (type_name_cstr,
+ GetClangDeclContextForDIE (dwarf_cu, die->GetParent()),
+ decl,
enumerator_clang_type);
}
else
diff --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp
index 19dbd887a3f..e7e948bb802 100644
--- a/lldb/source/Symbol/ClangASTContext.cpp
+++ b/lldb/source/Symbol/ClangASTContext.cpp
@@ -3487,7 +3487,13 @@ ClangASTContext::CompleteTagDeclarationDefinition (clang_type_t clang_type)
#pragma mark Enumeration Types
clang_type_t
-ClangASTContext::CreateEnumerationType (const Declaration &decl, const char *name, clang_type_t integer_qual_type)
+ClangASTContext::CreateEnumerationType
+(
+ const char *name,
+ DeclContext *decl_ctx,
+ const Declaration &decl,
+ clang_type_t integer_qual_type
+)
{
// TODO: Do something intelligent with the Declaration object passed in
// like maybe filling in the SourceLocation with it...
@@ -3499,7 +3505,7 @@ ClangASTContext::CreateEnumerationType (const Declaration &decl, const char *nam
// const bool IsFixed = false;
EnumDecl *enum_decl = EnumDecl::Create (*ast_context,
- ast_context->getTranslationUnitDecl(),
+ decl_ctx,
SourceLocation(),
name && name[0] ? &ast_context->Idents.get(name) : NULL,
SourceLocation(),
OpenPOWER on IntegriCloud