[Lldb-commits] [lldb] r118271 - in /lldb/trunk/source: Expression/ClangUserExpression.cpp Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
Sean Callanan
scallanan at apple.com
Thu Nov 4 17:57:06 PDT 2010
Author: spyffe
Date: Thu Nov 4 19:57:06 2010
New Revision: 118271
URL: http://llvm.org/viewvc/llvm-project?rev=118271&view=rev
Log:
Fixed error handling when the utility functions
that check pointer validity fail to parse. Now
lldb does not crash in that case. Also added
support for checking Objective-C class validity
in the Version 1 runtime as well as Version 2
runtimes with varying levels of available debug
support.
Modified:
lldb/trunk/source/Expression/ClangUserExpression.cpp
lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h
lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp
lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
Modified: lldb/trunk/source/Expression/ClangUserExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUserExpression.cpp?rev=118271&r1=118270&r2=118271&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangUserExpression.cpp (original)
+++ lldb/trunk/source/Expression/ClangUserExpression.cpp Thu Nov 4 19:57:06 2010
@@ -449,8 +449,16 @@
StreamString install_errors;
if (!dynamic_checkers->Install(install_errors, exe_ctx))
+ {
+ if (install_errors.GetString().empty())
+ error.SetErrorString ("couldn't install checkers, unknown error");
+ else
+ error.SetErrorString (install_errors.GetString().c_str());
+
+ result_valobj_sp.reset (new ValueObjectConstResult (error));
return result_valobj_sp;
-
+ }
+
exe_ctx.process->SetDynamicCheckers(dynamic_checkers);
}
Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp?rev=118271&r1=118270&r2=118271&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp Thu Nov 4 19:57:06 2010
@@ -231,7 +231,7 @@
// Static Functions
//------------------------------------------------------------------
enum AppleObjCRuntime::RuntimeVersions
-AppleObjCRuntime::GetObjCVersion (Process *process)
+AppleObjCRuntime::GetObjCVersion (Process *process, ModuleSP &objc_module_sp)
{
ModuleList &images = process->GetTarget().GetImages();
size_t num_images = images.GetSize();
@@ -240,6 +240,7 @@
ModuleSP module_sp = images.GetModuleAtIndex(i);
if (AppleIsModuleObjCLibrary (module_sp))
{
+ objc_module_sp = module_sp;
ObjectFile *ofile = module_sp->GetObjectFile();
if (!ofile)
return eObjC_VersionUnknown;
Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h?rev=118271&r1=118270&r2=118271&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h Thu Nov 4 19:57:06 2010
@@ -74,7 +74,7 @@
AppleIsModuleObjCLibrary (const lldb::ModuleSP &module_sp);
static enum AppleObjCRuntime::RuntimeVersions
- GetObjCVersion (Process *process);
+ GetObjCVersion (Process *process, ModuleSP &objc_module_sp);
//------------------------------------------------------------------
// PluginInterface protocol
Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp?rev=118271&r1=118270&r2=118271&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp Thu Nov 4 19:57:06 2010
@@ -172,7 +172,9 @@
// sure we aren't using the V1 runtime.
if (language == eLanguageTypeObjC)
{
- if (AppleObjCRuntime::GetObjCVersion (process) == AppleObjCRuntime::eObjC_V1)
+ ModuleSP objc_module_sp;
+
+ if (AppleObjCRuntime::GetObjCVersion (process, objc_module_sp) == AppleObjCRuntime::eObjC_V1)
return new AppleObjCRuntimeV1 (process);
else
return NULL;
@@ -231,22 +233,36 @@
}
}
+struct BufStruct {
+ char contents[2048];
+};
+
ClangUtilityFunction *
AppleObjCRuntimeV1::CreateObjectChecker(const char *name)
{
-// char buf[256];
-//
-// assert(snprintf(&buf[0], sizeof(buf),
-// "extern \"C\" int gdb_object_getClass(void *);"
-// "extern \"C\" void "
-// "%s(void *$__lldb_arg_obj)"
-// "{"
-// " void **isa_ptr = (void **)$__lldb_arg_obj;"
-// " if (!isa_ptr || !gdb_class_getClass(*isa_ptr))"
-// " abort();"
-// "}",
-// name) < sizeof(buf));
-//
-// return new ClangUtilityFunction(buf, name);
- return NULL;
+ std::auto_ptr<BufStruct> buf(new BufStruct);
+
+ assert(snprintf(&buf->contents[0], sizeof(buf->contents),
+ "struct __objc_class \n"
+ "{ \n"
+ " struct __objc_class *isa; \n"
+ " struct __objc_class *super_class; \n"
+ " const char *name; \n"
+ " // rest of struct elided because unused \n"
+ "}; \n"
+ " \n"
+ "struct __objc_object \n"
+ "{ \n"
+ " struct __objc_class *isa; \n"
+ "}; \n"
+ " \n"
+ "extern \"C\" void \n"
+ "%s(void *$__lldb_arg_obj) \n"
+ "{ \n"
+ " struct __objc_object *obj = (struct __objc_object*)$__lldb_arg_obj; \n"
+ " strlen(obj->isa->name); \n"
+ "} \n",
+ name) < sizeof(buf->contents));
+
+ return new ClangUtilityFunction(buf->contents, name);
}
Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp?rev=118271&r1=118270&r2=118271&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp Thu Nov 4 19:57:06 2010
@@ -40,6 +40,12 @@
static const char *pluginDesc = "Apple Objective C Language Runtime - Version 2";
static const char *pluginShort = "language.apple.objc.v2";
+AppleObjCRuntimeV2::AppleObjCRuntimeV2 (Process *process, ModuleSP &objc_module_sp) :
+ lldb_private::AppleObjCRuntime (process)
+{
+ m_has_object_getClass = (objc_module_sp->FindFirstSymbolWithNameAndType(ConstString("gdb_object_getClass")) != NULL);
+}
+
bool
AppleObjCRuntimeV2::GetObjectDescription (Stream &str, ValueObject &object, ExecutionContextScope *exe_scope)
{
@@ -172,8 +178,10 @@
// sure we aren't using the V1 runtime.
if (language == eLanguageTypeObjC)
{
- if (AppleObjCRuntime::GetObjCVersion (process) == AppleObjCRuntime::eObjC_V2)
- return new AppleObjCRuntimeV2 (process);
+ ModuleSP objc_module_sp;
+
+ if (AppleObjCRuntime::GetObjCVersion (process, objc_module_sp) == AppleObjCRuntime::eObjC_V2)
+ return new AppleObjCRuntimeV2 (process, objc_module_sp);
else
return NULL;
}
@@ -231,21 +239,40 @@
}
}
+struct BufStruct {
+ char contents[1024];
+};
+
ClangUtilityFunction *
AppleObjCRuntimeV2::CreateObjectChecker(const char *name)
{
- char buf[256];
+ std::auto_ptr<BufStruct> buf(new BufStruct);
- assert(snprintf(&buf[0], sizeof(buf),
- "extern \"C\" int gdb_object_getClass(void *);"
- "extern \"C\" void "
- "%s(void *$__lldb_arg_obj)"
- "{"
- " void **isa_ptr = (void **)$__lldb_arg_obj;"
- " if (!isa_ptr || !gdb_class_getClass(*isa_ptr))"
- " abort();"
- "}",
- name) < sizeof(buf));
-
- return new ClangUtilityFunction(buf, name);
+ if (m_has_object_getClass)
+ {
+ assert(snprintf(&buf->contents[0], sizeof(buf->contents),
+ "extern \"C\" int 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));
+ }
+ else
+ {
+ assert(snprintf(&buf->contents[0], sizeof(buf->contents),
+ "extern \"C\" int 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));
+ }
+
+ return new ClangUtilityFunction(buf->contents, name);
}
Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h?rev=118271&r1=118270&r2=118271&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h Thu Nov 4 19:57:06 2010
@@ -74,9 +74,9 @@
protected:
private:
- AppleObjCRuntimeV2(Process *process) :
- lldb_private::AppleObjCRuntime (process)
- { } // Call CreateInstance instead.
+ AppleObjCRuntimeV2(Process *process, ModuleSP &objc_module_sp);
+
+ bool m_has_object_getClass;
};
} // namespace lldb_private
More information about the lldb-commits
mailing list