From a475fc6de685193b449b5e2e8a1eb9ea6065a195 Mon Sep 17 00:00:00 2001 From: Nat! Date: Tue, 31 Jul 2018 22:55:56 +0200 Subject: [PATCH] * lots of progress for JIT of mulle-objc --- include/lldb/Target/Process.h | 6 +++++ source/Expression/ExpressionSourceCode.cpp | 4 ++-- .../Clang/ClangExpressionParser.cpp | 10 +++++++- .../MulleObjCRuntime/MulleObjCRuntimeV1.cpp | 5 ++-- .../mulle-objc-dangerous-class-storage.inc | 10 ++++++++ .../mulle-objc-dangerous-class-storage.src | 12 ++++++++++ .../mulle-objc-lookup-imp.inc | 14 +++++++++-- .../mulle-objc-lookup-imp.src | 23 ++++++++++++++----- .../mulle-objc-object-checker.inc | 11 +++++++++ .../mulle-objc-object-checker.src | 13 +++++++++++ .../SymbolFile/DWARF/DWARFASTParserClang.cpp | 9 ++++---- source/Symbol/ClangASTContext.cpp | 2 +- source/Symbol/ClangASTImporter.cpp | 2 +- source/Target/Process.cpp | 10 ++++++++ 14 files changed, 112 insertions(+), 19 deletions(-) diff --git a/include/lldb/Target/Process.h b/include/lldb/Target/Process.h index 16f37f4dd5..7929b5da6a 100644 --- a/include/lldb/Target/Process.h +++ b/include/lldb/Target/Process.h @@ -3130,6 +3130,12 @@ class Process : public std::enable_shared_from_this, enum { eCanJITDontKnow = 0, eCanJITYes, eCanJITNo } m_can_jit; +// @mulle-lldb@ avoid failed threadplan calling formatters that execute a threadplan again > +public: + bool isThreadPlanLocked( void); +protected: +// @mulle-lldb@ avoid failed threadplan calling formatters that execute a threadplan again < + size_t RemoveBreakpointOpcodesFromBuffer(lldb::addr_t addr, size_t size, uint8_t *buf) const; diff --git a/source/Expression/ExpressionSourceCode.cpp b/source/Expression/ExpressionSourceCode.cpp index 93e68a54a7..7db4fb9317 100644 --- a/source/Expression/ExpressionSourceCode.cpp +++ b/source/Expression/ExpressionSourceCode.cpp @@ -284,11 +284,11 @@ bool ExpressionSourceCode::GetText(std::string &text, /// @mulle-objc@ hack some mulle-objc-runtime stuff into the expression > /// @mulle-objc@ MUST CHANGE VALUES THIS FOR EACH LLDB RELEASE!! wrap_stream.Printf("\ -static const struct clang_mulle_objc_compiler_info\n\ +static const struct mulle_clang_objccompilerinfo\n\ {\n\ unsigned int load_version;\n\ unsigned int runtime_version;\n\ -} __mulle_objc_compiler_info =\n\ +} __mulle_objc_objccompilerinfo =\n\ {\n\ 12, // load version must match \n\ 0 // 0 to not emit __load_mulle_objc\n\ diff --git a/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp index a8c716ab79..a39477a97f 100644 --- a/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp +++ b/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp @@ -448,8 +448,14 @@ ClangExpressionParser::ClangExpressionParser(ExecutionContextScope *exe_scope, VersionTuple(10, 7)); else /// @mulle-objc@ change to Mulle runtime > + { m_compiler->getLangOpts().ObjCRuntime.set(ObjCRuntime::Mulle, VersionTuple(0, 12)); + // tagged pointers are not good for JIT, but I don't know exactly why yet + m_compiler->getLangOpts().ObjCDisableTaggedPointers = true; + m_compiler->getLangOpts().CPlusPlus = false; + m_compiler->getLangOpts().CPlusPlus11 = false; + } /// @mulle-objc@ change to Mulle runtime < if (process_sp->GetObjCLanguageRuntime()->HasNewLiteralsAndIndexing()) @@ -902,7 +908,9 @@ lldb_private::Status ClangExpressionParser::PrepareForExecution( DiagnosticManager install_diagnostics; if (!dynamic_checkers->Install(install_diagnostics, exe_ctx)) { - if (install_diagnostics.Diagnostics().size()) +/// @mulle-lldb@ fix a bug > + if (! install_diagnostics.Diagnostics().size()) +/// @mulle-lldb@ fix a bug < err.SetErrorString("couldn't install checkers, unknown error"); else err.SetErrorString(install_diagnostics.GetString().c_str()); diff --git a/source/Plugins/LanguageRuntime/ObjC/MulleObjCRuntime/MulleObjCRuntimeV1.cpp b/source/Plugins/LanguageRuntime/ObjC/MulleObjCRuntime/MulleObjCRuntimeV1.cpp index c55c6510c5..9f30de7a6c 100644 --- a/source/Plugins/LanguageRuntime/ObjC/MulleObjCRuntime/MulleObjCRuntimeV1.cpp +++ b/source/Plugins/LanguageRuntime/ObjC/MulleObjCRuntime/MulleObjCRuntimeV1.cpp @@ -135,7 +135,6 @@ struct BufStruct { UtilityFunction *MulleObjCRuntimeV1::CreateObjectChecker(const char *name) { std::unique_ptr buf(new BufStruct); -#ifndef NDEBUG int strformatsize = snprintf(&buf->contents[0], sizeof(buf->contents), "extern \"C\"\n" "{\n" @@ -143,7 +142,6 @@ UtilityFunction *MulleObjCRuntimeV1::CreateObjectChecker(const char *name) { "}", name); assert(strformatsize < (int)sizeof(buf->contents)); -#endif Status error; return GetTargetRef().GetUtilityFunctionForLanguage( @@ -406,6 +404,8 @@ lldb::addr_t MulleObjCRuntimeV1::GetISAHashTablePointer( Process *process) { if (!objc_module_sp) return LLDB_INVALID_ADDRESS; + if( process->isThreadPlanLocked()) + return LLDB_INVALID_ADDRESS; // that pointer is fluctuating! return CallDangerousGetClassTableFunction( process); } @@ -435,6 +435,7 @@ void MulleObjCRuntimeV1::UpdateISAToDescriptorMapIfNeeded() { lldb::addr_t hash_table_ptr = GetISAHashTablePointer( process); if (hash_table_ptr == LLDB_INVALID_ADDRESS) { m_isa_to_descriptor_stop_id = UINT32_MAX; + return; // can't do anything } // Read the mulle_concurrent_hashtable struct: diff --git a/source/Plugins/LanguageRuntime/ObjC/MulleObjCRuntime/mulle-objc-dangerous-class-storage.inc b/source/Plugins/LanguageRuntime/ObjC/MulleObjCRuntime/mulle-objc-dangerous-class-storage.inc index 5fd6f3b5b9..effacd226b 100644 --- a/source/Plugins/LanguageRuntime/ObjC/MulleObjCRuntime/mulle-objc-dangerous-class-storage.inc +++ b/source/Plugins/LanguageRuntime/ObjC/MulleObjCRuntime/mulle-objc-dangerous-class-storage.inc @@ -1,3 +1,13 @@ +"static const \n" +"struct mulle_clang_objccompilerinfo\n" +"{\n" +"unsigned int load_version;\n" +"unsigned int runtime_version;\n" +"} __mulle_objc_objccompilerinfo =\n" +"{\n" +"12, \n" +"0 \n" +"};\n" "void *__lldb_objc_get_dangerous_class_storage( void)\n" "{\n" "extern void *mulle_objc_lldb_get_dangerous_classstorage_pointer( void);\n" diff --git a/source/Plugins/LanguageRuntime/ObjC/MulleObjCRuntime/mulle-objc-dangerous-class-storage.src b/source/Plugins/LanguageRuntime/ObjC/MulleObjCRuntime/mulle-objc-dangerous-class-storage.src index c145c4db15..3a2d2648f6 100644 --- a/source/Plugins/LanguageRuntime/ObjC/MulleObjCRuntime/mulle-objc-dangerous-class-storage.src +++ b/source/Plugins/LanguageRuntime/ObjC/MulleObjCRuntime/mulle-objc-dangerous-class-storage.src @@ -1,3 +1,15 @@ +static const +struct mulle_clang_objccompilerinfo +{ + unsigned int load_version; + unsigned int runtime_version; +} __mulle_objc_objccompilerinfo = +{ + 12, // load version must match + 0 // 0 to not emit __load_mulle_objc +}; + + void *__lldb_objc_get_dangerous_class_storage( void) { extern void *mulle_objc_lldb_get_dangerous_classstorage_pointer( void); diff --git a/source/Plugins/LanguageRuntime/ObjC/MulleObjCRuntime/mulle-objc-lookup-imp.inc b/source/Plugins/LanguageRuntime/ObjC/MulleObjCRuntime/mulle-objc-lookup-imp.inc index b012c21424..a5298c9b8d 100644 --- a/source/Plugins/LanguageRuntime/ObjC/MulleObjCRuntime/mulle-objc-lookup-imp.inc +++ b/source/Plugins/LanguageRuntime/ObjC/MulleObjCRuntime/mulle-objc-lookup-imp.inc @@ -1,3 +1,13 @@ +"static const \n" +"struct mulle_clang_objccompilerinfo\n" +"{\n" +"unsigned int load_version;\n" +"unsigned int runtime_version;\n" +"} __mulle_objc_objccompilerinfo =\n" +"{\n" +"12, \n" +"0 \n" +"};\n" "void *__lldb_objc_find_implementation_for_selector( void *object,\n" "unsigned int methodid,\n" "void *cls_or_classid,\n" @@ -5,7 +15,7 @@ "int is_meta,\n" "int debug)\n" "{\n" -"void *mulle_objc_lldb_lookup_implementation( void *obj,\n" +"extern void *mulle_objc_lldb_lookup_implementation( void *obj,\n" "unsigned int methodid,\n" "void *cls_or_classid,\n" "int is_classid,\n" @@ -17,4 +27,4 @@ "is_classid,\n" "is_meta,\n" "debug));\n" -"}\n" +"}\n" \ No newline at end of file diff --git a/source/Plugins/LanguageRuntime/ObjC/MulleObjCRuntime/mulle-objc-lookup-imp.src b/source/Plugins/LanguageRuntime/ObjC/MulleObjCRuntime/mulle-objc-lookup-imp.src index 667b94d5f9..884ac26b99 100644 --- a/source/Plugins/LanguageRuntime/ObjC/MulleObjCRuntime/mulle-objc-lookup-imp.src +++ b/source/Plugins/LanguageRuntime/ObjC/MulleObjCRuntime/mulle-objc-lookup-imp.src @@ -1,3 +1,14 @@ +static const +struct mulle_clang_objccompilerinfo +{ + unsigned int load_version; + unsigned int runtime_version; +} __mulle_objc_objccompilerinfo = +{ + 12, // load version must match + 0 // 0 to not emit __load_mulle_objc +}; + // // this file is transformed with make-inc.sh into mulle-objc-lookup.inc // which is then included into MulleObjCTrampolineHandler.cpp @@ -13,12 +24,12 @@ void *__lldb_objc_find_implementation_for_selector( void *object, int is_meta, int debug) { - void *mulle_objc_lldb_lookup_implementation( void *obj, - unsigned int methodid, - void *cls_or_classid, - int is_classid, - int is_meta, - int debug); + extern void *mulle_objc_lldb_lookup_implementation( void *obj, + unsigned int methodid, + void *cls_or_classid, + int is_classid, + int is_meta, + int debug); return( mulle_objc_lldb_lookup_implementation( object, methodid, diff --git a/source/Plugins/LanguageRuntime/ObjC/MulleObjCRuntime/mulle-objc-object-checker.inc b/source/Plugins/LanguageRuntime/ObjC/MulleObjCRuntime/mulle-objc-object-checker.inc index 898957f77a..269760d1fb 100644 --- a/source/Plugins/LanguageRuntime/ObjC/MulleObjCRuntime/mulle-objc-object-checker.inc +++ b/source/Plugins/LanguageRuntime/ObjC/MulleObjCRuntime/mulle-objc-object-checker.inc @@ -1,4 +1,15 @@ +"static const \n" +"struct mulle_clang_objccompilerinfo\n" +"{\n" +"unsigned int load_version;\n" +"unsigned int runtime_version;\n" +"} __mulle_objc_objccompilerinfo =\n" +"{\n" +"12, \n" +"0 \n" +"};\n" "void %s( void *$__lldb_obj, unsigned int $__lldb_sel)\n" "{\n" +"extern void mulle_objc_lldb_check_object( void *$__lldb_obj, unsigned int $__lldb_sel);\n" "mulle_objc_lldb_check_object( $__lldb_obj, $__lldb_sel);\n" "}\n" diff --git a/source/Plugins/LanguageRuntime/ObjC/MulleObjCRuntime/mulle-objc-object-checker.src b/source/Plugins/LanguageRuntime/ObjC/MulleObjCRuntime/mulle-objc-object-checker.src index c429c15b31..920cdf1127 100644 --- a/source/Plugins/LanguageRuntime/ObjC/MulleObjCRuntime/mulle-objc-object-checker.src +++ b/source/Plugins/LanguageRuntime/ObjC/MulleObjCRuntime/mulle-objc-object-checker.src @@ -1,4 +1,17 @@ +static const +struct mulle_clang_objccompilerinfo +{ + unsigned int load_version; + unsigned int runtime_version; +} __mulle_objc_objccompilerinfo = +{ + 12, // load version must match + 0 // 0 to not emit __load_mulle_objc +}; + void %s( void *$__lldb_obj, unsigned int $__lldb_sel) { + extern void mulle_objc_lldb_check_object( void *$__lldb_obj, unsigned int $__lldb_sel); + mulle_objc_lldb_check_object( $__lldb_obj, $__lldb_sel); } diff --git a/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp index 6ca25a3f7e..f92a18315b 100644 --- a/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -3369,9 +3369,6 @@ bool DWARFASTParserClang::ParseMulleABIParameters( const DWARFDIE &die, &bit_offset_ptr, &bitfield_bit_size_ptr, &is_bitfield_ptr); - - fprintf( stderr, "#%d _param.%s found\n", (int) i, name.c_str()); - function_param_types.push_back( fieldType); clang::ParmVarDecl *param_var_decl = @@ -3396,6 +3393,8 @@ size_t DWARFASTParserClang::ParseChildParameters( if (!parent_die) return 0; + bool skipRemainingParameters = false; + size_t arg_idx = 0; for (DWARFDIE die = parent_die.GetFirstChild(); die.IsValid(); die = die.GetSibling()) { @@ -3469,7 +3468,8 @@ size_t DWARFASTParserClang::ParseChildParameters( } } - bool skip = false; + bool skip = skipRemainingParameters; + if (skip_artificial) { if (is_artificial) { // In order to determine if a C++ member function is @@ -3550,6 +3550,7 @@ size_t DWARFASTParserClang::ParseChildParameters( function_param_types, function_param_decls, storage); + skipRemainingParameters = true; } break; } diff --git a/source/Symbol/ClangASTContext.cpp b/source/Symbol/ClangASTContext.cpp index 53d4106428..45608b1de0 100644 --- a/source/Symbol/ClangASTContext.cpp +++ b/source/Symbol/ClangASTContext.cpp @@ -8452,7 +8452,7 @@ clang::ObjCMethodDecl *ClangASTContext::AddMethodToObjCObjectType( for (unsigned param_index = 0; param_index < num_args; ++param_index) { /// @mulle-objc@ add this for parameter names > identifier = nullptr; - if( function_param_decls.size() < param_index) + if( param_index < function_param_decls.size()) identifier = function_param_decls[ param_index]->getIdentifier(); /// @mulle-objc@ add this for parameter names < diff --git a/source/Symbol/ClangASTImporter.cpp b/source/Symbol/ClangASTImporter.cpp index 72ccaed43e..d3b4834bf7 100644 --- a/source/Symbol/ClangASTImporter.cpp +++ b/source/Symbol/ClangASTImporter.cpp @@ -956,7 +956,7 @@ clang::Decl *ClangASTImporter::Minion::Imported(clang::Decl *from, from_named_decl->printName(name_stream); name_stream.flush(); - log->Printf(" [ClangASTImporter] Imported (%sDecl*)%p, named %s (from " + log->Printf(" [ClangASTImporter] Imported (%sDecl*)%p, named \"%s\" (from " "(Decl*)%p), metadata 0x%" PRIx64, from->getDeclKindName(), static_cast(to), name_string.c_str(), static_cast(from), user_id); diff --git a/source/Target/Process.cpp b/source/Target/Process.cpp index 8fb149fab0..42467a5b5a 100644 --- a/source/Target/Process.cpp +++ b/source/Target/Process.cpp @@ -4873,6 +4873,16 @@ HandleStoppedEvent(Thread &thread, const ThreadPlanSP &thread_plan_sp, return eExpressionInterrupted; } +// @mulle-lldb@ avoid failed threadplan calling formatters that execute a threadplan again > +bool Process::isThreadPlanLocked( void) +{ + if( ! m_run_thread_plan_lock.try_lock()) + return( true); + m_run_thread_plan_lock.unlock(); + return( false); +} +// @mulle-lldb@ avoid failed threadplan calling formatters that execute a threadplan again < + ExpressionResults Process::RunThreadPlan(ExecutionContext &exe_ctx, lldb::ThreadPlanSP &thread_plan_sp,