diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:06:29 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:06:29 +0000 |
commit | 94994d372d014ce4c8758b9605d63fae651bd8aa (patch) | |
tree | 51c0b708bd59f205d6b35cb2a8c24d62f0c33d77 /source/Plugins/LanguageRuntime | |
parent | 39be7ce23363d12ae3e49aeb1fdb2bfeb892e836 (diff) |
Notes
Diffstat (limited to 'source/Plugins/LanguageRuntime')
29 files changed, 389 insertions, 767 deletions
diff --git a/source/Plugins/LanguageRuntime/CMakeLists.txt b/source/Plugins/LanguageRuntime/CMakeLists.txt index 2cf579212ec16..c62791445a9a2 100644 --- a/source/Plugins/LanguageRuntime/CMakeLists.txt +++ b/source/Plugins/LanguageRuntime/CMakeLists.txt @@ -1,5 +1,3 @@ add_subdirectory(CPlusPlus) add_subdirectory(ObjC) -add_subdirectory(Go) -add_subdirectory(Java) add_subdirectory(RenderScript) diff --git a/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp b/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp index fc661bbbf2c9b..49a3d40d7b371 100644 --- a/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp +++ b/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp @@ -14,9 +14,11 @@ #include "lldb/Core/Mangled.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/Scalar.h" #include "lldb/Core/ValueObject.h" #include "lldb/Core/ValueObjectMemory.h" +#include "lldb/DataFormatters/FormattersHelpers.h" +#include "lldb/Expression/DiagnosticManager.h" +#include "lldb/Expression/FunctionCaller.h" #include "lldb/Interpreter/CommandObject.h" #include "lldb/Interpreter/CommandObjectMultiword.h" #include "lldb/Interpreter/CommandReturnObject.h" @@ -32,6 +34,7 @@ #include "lldb/Target/Thread.h" #include "lldb/Utility/ConstString.h" #include "lldb/Utility/Log.h" +#include "lldb/Utility/Scalar.h" #include "lldb/Utility/Status.h" #include <vector> @@ -98,7 +101,7 @@ TypeAndOrName ItaniumABILanguageRuntime::GetTypeInfoFromVTableAddress( llvm::DenseSet<SymbolFile *> searched_symbol_files; if (sc.module_sp) { num_matches = sc.module_sp->FindTypes( - sc, ConstString(lookup_name), exact_match, 1, + ConstString(lookup_name), exact_match, 1, searched_symbol_files, class_types); } @@ -106,7 +109,7 @@ TypeAndOrName ItaniumABILanguageRuntime::GetTypeInfoFromVTableAddress( // list in the target and get as many unique matches as possible if (num_matches == 0) { num_matches = target.GetImages().FindTypes( - sc, ConstString(lookup_name), exact_match, UINT32_MAX, + nullptr, ConstString(lookup_name), exact_match, UINT32_MAX, searched_symbol_files, class_types); } @@ -204,71 +207,71 @@ bool ItaniumABILanguageRuntime::GetDynamicTypeAndAddress( // Only a pointer or reference type can have a different dynamic and static // type: - if (CouldHaveDynamicValue(in_value)) { - // First job, pull out the address at 0 offset from the object. - AddressType address_type; - lldb::addr_t original_ptr = in_value.GetPointerValue(&address_type); - if (original_ptr == LLDB_INVALID_ADDRESS) - return false; + if (!CouldHaveDynamicValue(in_value)) + return false; - ExecutionContext exe_ctx(in_value.GetExecutionContextRef()); + // First job, pull out the address at 0 offset from the object. + AddressType address_type; + lldb::addr_t original_ptr = in_value.GetPointerValue(&address_type); + if (original_ptr == LLDB_INVALID_ADDRESS) + return false; - Process *process = exe_ctx.GetProcessPtr(); + ExecutionContext exe_ctx(in_value.GetExecutionContextRef()); - if (process == nullptr) - return false; + Process *process = exe_ctx.GetProcessPtr(); - Status error; - const lldb::addr_t vtable_address_point = - process->ReadPointerFromMemory(original_ptr, error); + if (process == nullptr) + return false; - if (!error.Success() || vtable_address_point == LLDB_INVALID_ADDRESS) { - return false; - } + Status error; + const lldb::addr_t vtable_address_point = + process->ReadPointerFromMemory(original_ptr, error); - class_type_or_name = GetTypeInfoFromVTableAddress(in_value, original_ptr, - vtable_address_point); - - if (class_type_or_name) { - TypeSP type_sp = class_type_or_name.GetTypeSP(); - // There can only be one type with a given name, so we've just found - // duplicate definitions, and this one will do as well as any other. We - // don't consider something to have a dynamic type if it is the same as - // the static type. So compare against the value we were handed. - if (type_sp) { - if (ClangASTContext::AreTypesSame(in_value.GetCompilerType(), - type_sp->GetForwardCompilerType())) { - // The dynamic type we found was the same type, so we don't have a - // dynamic type here... - return false; - } + if (!error.Success() || vtable_address_point == LLDB_INVALID_ADDRESS) + return false; - // The offset_to_top is two pointers above the vtable pointer. - const uint32_t addr_byte_size = process->GetAddressByteSize(); - const lldb::addr_t offset_to_top_location = - vtable_address_point - 2 * addr_byte_size; - // Watch for underflow, offset_to_top_location should be less than - // vtable_address_point - if (offset_to_top_location >= vtable_address_point) - return false; - const int64_t offset_to_top = process->ReadSignedIntegerFromMemory( - offset_to_top_location, addr_byte_size, INT64_MIN, error); - - if (offset_to_top == INT64_MIN) - return false; - // So the dynamic type is a value that starts at offset_to_top above - // the original address. - lldb::addr_t dynamic_addr = original_ptr + offset_to_top; - if (!process->GetTarget().GetSectionLoadList().ResolveLoadAddress( - dynamic_addr, dynamic_address)) { - dynamic_address.SetRawAddress(dynamic_addr); - } - return true; - } - } + class_type_or_name = GetTypeInfoFromVTableAddress(in_value, original_ptr, + vtable_address_point); + + if (!class_type_or_name) + return false; + + TypeSP type_sp = class_type_or_name.GetTypeSP(); + // There can only be one type with a given name, so we've just found + // duplicate definitions, and this one will do as well as any other. We + // don't consider something to have a dynamic type if it is the same as + // the static type. So compare against the value we were handed. + if (!type_sp) + return true; + + if (ClangASTContext::AreTypesSame(in_value.GetCompilerType(), + type_sp->GetForwardCompilerType())) { + // The dynamic type we found was the same type, so we don't have a + // dynamic type here... + return false; } - return class_type_or_name.IsEmpty() == false; + // The offset_to_top is two pointers above the vtable pointer. + const uint32_t addr_byte_size = process->GetAddressByteSize(); + const lldb::addr_t offset_to_top_location = + vtable_address_point - 2 * addr_byte_size; + // Watch for underflow, offset_to_top_location should be less than + // vtable_address_point + if (offset_to_top_location >= vtable_address_point) + return false; + const int64_t offset_to_top = process->ReadSignedIntegerFromMemory( + offset_to_top_location, addr_byte_size, INT64_MIN, error); + + if (offset_to_top == INT64_MIN) + return false; + // So the dynamic type is a value that starts at offset_to_top above + // the original address. + lldb::addr_t dynamic_addr = original_ptr + offset_to_top; + if (!process->GetTarget().GetSectionLoadList().ResolveLoadAddress( + dynamic_addr, dynamic_address)) { + dynamic_address.SetRawAddress(dynamic_addr); + } + return true; } TypeAndOrName ItaniumABILanguageRuntime::FixUpDynamicType( @@ -309,10 +312,7 @@ bool ItaniumABILanguageRuntime::IsVTableName(const char *name) { return false; // Can we maybe ask Clang about this? - if (strstr(name, "_vptr$") == name) - return true; - else - return false; + return strstr(name, "_vptr$") == name; } //------------------------------------------------------------------ @@ -483,8 +483,8 @@ lldb::SearchFilterSP ItaniumABILanguageRuntime::CreateExceptionSearchFilter() { // Limit the number of modules that are searched for these breakpoints for // Apple binaries. FileSpecList filter_modules; - filter_modules.Append(FileSpec("libc++abi.dylib", false)); - filter_modules.Append(FileSpec("libSystem.B.dylib", false)); + filter_modules.Append(FileSpec("libc++abi.dylib")); + filter_modules.Append(FileSpec("libSystem.B.dylib")); return target.GetSearchFilterForModuleList(&filter_modules); } else { return LanguageRuntime::CreateExceptionSearchFilter(); @@ -552,6 +552,64 @@ bool ItaniumABILanguageRuntime::ExceptionBreakpointsExplainStop( break_site_id, m_cxx_exception_bp_sp->GetID()); } +ValueObjectSP ItaniumABILanguageRuntime::GetExceptionObjectForThread( + ThreadSP thread_sp) { + if (!thread_sp->SafeToCallFunctions()) + return {}; + + ClangASTContext *clang_ast_context = + m_process->GetTarget().GetScratchClangASTContext(); + CompilerType voidstar = + clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); + + DiagnosticManager diagnostics; + ExecutionContext exe_ctx; + EvaluateExpressionOptions options; + + options.SetUnwindOnError(true); + options.SetIgnoreBreakpoints(true); + options.SetStopOthers(true); + options.SetTimeout(std::chrono::milliseconds(500)); + options.SetTryAllThreads(false); + thread_sp->CalculateExecutionContext(exe_ctx); + + const ModuleList &modules = m_process->GetTarget().GetImages(); + SymbolContextList contexts; + SymbolContext context; + + modules.FindSymbolsWithNameAndType( + ConstString("__cxa_current_exception_type"), eSymbolTypeCode, contexts); + contexts.GetContextAtIndex(0, context); + Address addr = context.symbol->GetAddress(); + + Status error; + FunctionCaller *function_caller = + m_process->GetTarget().GetFunctionCallerForLanguage( + eLanguageTypeC, voidstar, addr, ValueList(), "caller", error); + + ExpressionResults func_call_ret; + Value results; + func_call_ret = function_caller->ExecuteFunction(exe_ctx, nullptr, options, + diagnostics, results); + if (func_call_ret != eExpressionCompleted || !error.Success()) { + return ValueObjectSP(); + } + + size_t ptr_size = m_process->GetAddressByteSize(); + addr_t result_ptr = results.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); + addr_t exception_addr = + m_process->ReadPointerFromMemory(result_ptr - ptr_size, error); + + lldb_private::formatters::InferiorSizedWord exception_isw(exception_addr, + *m_process); + ValueObjectSP exception = ValueObject::CreateValueObjectFromData( + "exception", exception_isw.GetAsData(m_process->GetByteOrder()), exe_ctx, + voidstar); + exception = exception->GetDynamicValue(eDynamicDontRunTarget); + + return exception; +} + TypeAndOrName ItaniumABILanguageRuntime::GetDynamicTypeInfo( const lldb_private::Address &vtable_addr) { std::lock_guard<std::mutex> locker(m_dynamic_type_map_mutex); diff --git a/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h b/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h index 480c32691c8b1..abed3706c6b8b 100644 --- a/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h +++ b/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h @@ -10,14 +10,10 @@ #ifndef liblldb_ItaniumABILanguageRuntime_h_ #define liblldb_ItaniumABILanguageRuntime_h_ -// C Includes -// C++ Includes #include <map> #include <mutex> #include <vector> -// Other libraries and framework includes -// Project includes #include "lldb/Breakpoint/BreakpointResolver.h" #include "lldb/Core/Value.h" #include "lldb/Symbol/Type.h" @@ -69,6 +65,9 @@ public: bool throw_bp) override; lldb::SearchFilterSP CreateExceptionSearchFilter() override; + + lldb::ValueObjectSP GetExceptionObjectForThread( + lldb::ThreadSP thread_sp) override; //------------------------------------------------------------------ // PluginInterface protocol diff --git a/source/Plugins/LanguageRuntime/Go/CMakeLists.txt b/source/Plugins/LanguageRuntime/Go/CMakeLists.txt index 16756d5c985ae..62418def58f63 100644 --- a/source/Plugins/LanguageRuntime/Go/CMakeLists.txt +++ b/source/Plugins/LanguageRuntime/Go/CMakeLists.txt @@ -1,8 +1,6 @@ set(LLVM_NO_RTTI 1) add_lldb_library(lldbPluginLanguageRuntimeGo PLUGIN - GoLanguageRuntime.cpp - LINK_LIBS lldbBreakpoint lldbCore diff --git a/source/Plugins/LanguageRuntime/Go/GoLanguageRuntime.cpp b/source/Plugins/LanguageRuntime/Go/GoLanguageRuntime.cpp deleted file mode 100644 index 6670f89dde5fa..0000000000000 --- a/source/Plugins/LanguageRuntime/Go/GoLanguageRuntime.cpp +++ /dev/null @@ -1,215 +0,0 @@ -//===-- GoLanguageRuntime.cpp --------------------------------------*- C++ -//-*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "GoLanguageRuntime.h" - -#include "lldb/Breakpoint/BreakpointLocation.h" -#include "lldb/Core/Module.h" -#include "lldb/Core/PluginManager.h" -#include "lldb/Core/Scalar.h" -#include "lldb/Core/ValueObject.h" -#include "lldb/Core/ValueObjectMemory.h" -#include "lldb/Symbol/GoASTContext.h" -#include "lldb/Symbol/Symbol.h" -#include "lldb/Symbol/SymbolFile.h" -#include "lldb/Symbol/TypeList.h" -#include "lldb/Target/Process.h" -#include "lldb/Target/RegisterContext.h" -#include "lldb/Target/SectionLoadList.h" -#include "lldb/Target/StopInfo.h" -#include "lldb/Target/Target.h" -#include "lldb/Target/Thread.h" -#include "lldb/Utility/ConstString.h" -#include "lldb/Utility/Log.h" -#include "lldb/Utility/Status.h" -#include "llvm/ADT/Twine.h" - -#include <vector> - -using namespace lldb; -using namespace lldb_private; - -namespace { -ValueObjectSP GetChild(ValueObject &obj, const char *name, - bool dereference = true) { - ConstString name_const_str(name); - ValueObjectSP result = obj.GetChildMemberWithName(name_const_str, true); - if (dereference && result && result->IsPointerType()) { - Status err; - result = result->Dereference(err); - if (err.Fail()) - result.reset(); - } - return result; -} - -ConstString ReadString(ValueObject &str, Process *process) { - ConstString result; - ValueObjectSP data = GetChild(str, "str", false); - ValueObjectSP len = GetChild(str, "len"); - if (len && data) { - Status err; - lldb::addr_t addr = data->GetPointerValue(); - if (addr == LLDB_INVALID_ADDRESS) - return result; - uint64_t byte_size = len->GetValueAsUnsigned(0); - char *buf = new char[byte_size + 1]; - buf[byte_size] = 0; - size_t bytes_read = process->ReadMemory(addr, buf, byte_size, err); - if (!(err.Fail() || bytes_read != byte_size)) - result = ConstString(buf, bytes_read); - delete[] buf; - } - return result; -} - -ConstString ReadTypeName(ValueObjectSP type, Process *process) { - if (ValueObjectSP uncommon = GetChild(*type, "x")) { - ValueObjectSP name = GetChild(*uncommon, "name"); - ValueObjectSP package = GetChild(*uncommon, "pkgpath"); - if (name && name->GetPointerValue() != 0 && package && - package->GetPointerValue() != 0) { - ConstString package_const_str = ReadString(*package, process); - ConstString name_const_str = ReadString(*name, process); - if (package_const_str.GetLength() == 0) - return name_const_str; - return ConstString((package_const_str.GetStringRef() + "." + - name_const_str.GetStringRef()) - .str()); - } - } - ValueObjectSP name = GetChild(*type, "_string"); - if (name) - return ReadString(*name, process); - return ConstString(""); -} - -CompilerType LookupRuntimeType(ValueObjectSP type, ExecutionContext *exe_ctx, - bool *is_direct) { - uint8_t kind = GetChild(*type, "kind")->GetValueAsUnsigned(0); - *is_direct = GoASTContext::IsDirectIface(kind); - if (GoASTContext::IsPointerKind(kind)) { - CompilerType type_ptr = type->GetCompilerType().GetPointerType(); - Status err; - ValueObjectSP elem = - type->CreateValueObjectFromAddress("elem", type->GetAddressOf() + - type->GetByteSize(), - *exe_ctx, type_ptr) - ->Dereference(err); - if (err.Fail()) - return CompilerType(); - bool tmp_direct; - return LookupRuntimeType(elem, exe_ctx, &tmp_direct).GetPointerType(); - } - Target *target = exe_ctx->GetTargetPtr(); - Process *process = exe_ctx->GetProcessPtr(); - - ConstString const_typename = ReadTypeName(type, process); - if (const_typename.GetLength() == 0) - return CompilerType(); - - SymbolContext sc; - TypeList type_list; - llvm::DenseSet<SymbolFile *> searched_symbol_files; - uint32_t num_matches = target->GetImages().FindTypes( - sc, const_typename, false, 2, searched_symbol_files, type_list); - if (num_matches > 0) { - return type_list.GetTypeAtIndex(0)->GetFullCompilerType(); - } - return CompilerType(); -} -} - -bool GoLanguageRuntime::CouldHaveDynamicValue(ValueObject &in_value) { - return GoASTContext::IsGoInterface(in_value.GetCompilerType()); -} - -bool GoLanguageRuntime::GetDynamicTypeAndAddress( - ValueObject &in_value, lldb::DynamicValueType use_dynamic, - TypeAndOrName &class_type_or_name, Address &dynamic_address, - Value::ValueType &value_type) { - value_type = Value::eValueTypeScalar; - class_type_or_name.Clear(); - if (CouldHaveDynamicValue(in_value)) { - Status err; - ValueObjectSP iface = in_value.GetStaticValue(); - ValueObjectSP data_sp = GetChild(*iface, "data", false); - if (!data_sp) - return false; - - if (ValueObjectSP tab = GetChild(*iface, "tab")) - iface = tab; - ValueObjectSP type = GetChild(*iface, "_type"); - if (!type) { - return false; - } - - bool direct; - ExecutionContext exe_ctx(in_value.GetExecutionContextRef()); - CompilerType final_type = LookupRuntimeType(type, &exe_ctx, &direct); - if (!final_type) - return false; - if (direct) { - class_type_or_name.SetCompilerType(final_type); - } else { - // TODO: implement reference types or fix caller to support dynamic types - // that aren't pointers - // so we don't have to introduce this extra pointer. - class_type_or_name.SetCompilerType(final_type.GetPointerType()); - } - - dynamic_address.SetLoadAddress(data_sp->GetPointerValue(), - exe_ctx.GetTargetPtr()); - - return true; - } - return false; -} - -TypeAndOrName -GoLanguageRuntime::FixUpDynamicType(const TypeAndOrName &type_and_or_name, - ValueObject &static_value) { - return type_and_or_name; -} - -//------------------------------------------------------------------ -// Static Functions -//------------------------------------------------------------------ -LanguageRuntime * -GoLanguageRuntime::CreateInstance(Process *process, - lldb::LanguageType language) { - if (language == eLanguageTypeGo) - return new GoLanguageRuntime(process); - else - return NULL; -} - -void GoLanguageRuntime::Initialize() { - PluginManager::RegisterPlugin(GetPluginNameStatic(), "Go Language Runtime", - CreateInstance); -} - -void GoLanguageRuntime::Terminate() { - PluginManager::UnregisterPlugin(CreateInstance); -} - -lldb_private::ConstString GoLanguageRuntime::GetPluginNameStatic() { - static ConstString g_name("golang"); - return g_name; -} - -//------------------------------------------------------------------ -// PluginInterface protocol -//------------------------------------------------------------------ -lldb_private::ConstString GoLanguageRuntime::GetPluginName() { - return GetPluginNameStatic(); -} - -uint32_t GoLanguageRuntime::GetPluginVersion() { return 1; } diff --git a/source/Plugins/LanguageRuntime/Go/GoLanguageRuntime.h b/source/Plugins/LanguageRuntime/Go/GoLanguageRuntime.h deleted file mode 100644 index 9c2ee15cff65f..0000000000000 --- a/source/Plugins/LanguageRuntime/Go/GoLanguageRuntime.h +++ /dev/null @@ -1,86 +0,0 @@ -//===-- GoLanguageRuntime.h -------------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef liblldb_GoLanguageRuntime_h_ -#define liblldb_GoLanguageRuntime_h_ - -// C Includes -// C++ Includes -// Other libraries and framework includes -// Project includes -#include "lldb/Breakpoint/BreakpointResolver.h" -#include "lldb/Core/Value.h" -#include "lldb/Target/LanguageRuntime.h" -#include "lldb/lldb-private.h" - -namespace lldb_private { - -class GoLanguageRuntime : public lldb_private::LanguageRuntime { -public: - ~GoLanguageRuntime() override = default; - - //------------------------------------------------------------------ - // Static Functions - //------------------------------------------------------------------ - static void Initialize(); - - static void Terminate(); - - static lldb_private::LanguageRuntime * - CreateInstance(Process *process, lldb::LanguageType language); - - static lldb_private::ConstString GetPluginNameStatic(); - - lldb::LanguageType GetLanguageType() const override { - return lldb::eLanguageTypeGo; - } - - bool GetObjectDescription(Stream &str, ValueObject &object) override { - // TODO(ribrdb): Maybe call String() method? - return false; - } - - bool GetObjectDescription(Stream &str, Value &value, - ExecutionContextScope *exe_scope) override { - return false; - } - - bool GetDynamicTypeAndAddress(ValueObject &in_value, - lldb::DynamicValueType use_dynamic, - TypeAndOrName &class_type_or_name, - Address &address, - Value::ValueType &value_type) override; - - bool CouldHaveDynamicValue(ValueObject &in_value) override; - - lldb::BreakpointResolverSP CreateExceptionResolver(Breakpoint *bkpt, - bool catch_bp, - bool throw_bp) override { - return lldb::BreakpointResolverSP(); - } - - TypeAndOrName FixUpDynamicType(const TypeAndOrName &type_and_or_name, - ValueObject &static_value) override; - - //------------------------------------------------------------------ - // PluginInterface protocol - //------------------------------------------------------------------ - lldb_private::ConstString GetPluginName() override; - - uint32_t GetPluginVersion() override; - -private: - GoLanguageRuntime(Process *process) - : lldb_private::LanguageRuntime(process) { - } // Call CreateInstance instead. -}; - -} // namespace lldb_private - -#endif // liblldb_GoLanguageRuntime_h_ diff --git a/source/Plugins/LanguageRuntime/Java/CMakeLists.txt b/source/Plugins/LanguageRuntime/Java/CMakeLists.txt deleted file mode 100644 index ec87718752e73..0000000000000 --- a/source/Plugins/LanguageRuntime/Java/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -add_lldb_library(lldbPluginLanguageRuntimeJava PLUGIN - JavaLanguageRuntime.cpp - - LINK_LIBS - lldbCore - lldbSymbol - lldbTarget - LINK_COMPONENTS - Support - ) diff --git a/source/Plugins/LanguageRuntime/Java/JavaLanguageRuntime.cpp b/source/Plugins/LanguageRuntime/Java/JavaLanguageRuntime.cpp deleted file mode 100644 index 36c30a99ff878..0000000000000 --- a/source/Plugins/LanguageRuntime/Java/JavaLanguageRuntime.cpp +++ /dev/null @@ -1,157 +0,0 @@ -//===-- JavaLanguageRuntime.cpp ---------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "JavaLanguageRuntime.h" - -#include "lldb/Core/PluginManager.h" -#include "lldb/Symbol/JavaASTContext.h" -#include "lldb/Symbol/Symbol.h" -#include "lldb/Symbol/SymbolContext.h" -#include "lldb/Symbol/SymbolFile.h" -#include "lldb/Symbol/Type.h" -#include "lldb/Symbol/TypeList.h" -#include "lldb/Target/SectionLoadList.h" -#include "lldb/Target/Target.h" -#include "llvm/ADT/StringRef.h" - -using namespace lldb; -using namespace lldb_private; - -JavaLanguageRuntime::JavaLanguageRuntime(Process *process) - : LanguageRuntime(process) {} - -LanguageRuntime * -JavaLanguageRuntime::CreateInstance(Process *process, - lldb::LanguageType language) { - if (language == eLanguageTypeJava) - return new JavaLanguageRuntime(process); - return nullptr; -} - -void JavaLanguageRuntime::Initialize() { - PluginManager::RegisterPlugin(GetPluginNameStatic(), "Java language runtime", - CreateInstance); -} - -void JavaLanguageRuntime::Terminate() { - PluginManager::UnregisterPlugin(CreateInstance); -} - -lldb_private::ConstString JavaLanguageRuntime::GetPluginNameStatic() { - static ConstString g_name("java"); - return g_name; -} - -lldb_private::ConstString JavaLanguageRuntime::GetPluginName() { - return GetPluginNameStatic(); -} - -uint32_t JavaLanguageRuntime::GetPluginVersion() { return 1; } - -bool JavaLanguageRuntime::CouldHaveDynamicValue(ValueObject &in_value) { - return true; -} - -static ConstString GetDynamicTypeId(ExecutionContext *exe_ctx, Target *target, - ValueObject &in_value) { - SymbolContext sc; - TypeList class_types; - llvm::DenseSet<SymbolFile *> searched_symbol_files; - size_t num_matches = target->GetImages().FindTypes( - sc, ConstString("Object"), - true, // name_is_fully_qualified - UINT32_MAX, searched_symbol_files, class_types); - for (size_t i = 0; i < num_matches; ++i) { - TypeSP type_sp = class_types.GetTypeAtIndex(i); - CompilerType compiler_type = type_sp->GetFullCompilerType(); - - if (compiler_type.GetMinimumLanguage() != eLanguageTypeJava || - compiler_type.GetTypeName() != ConstString("java::lang::Object")) - continue; - - if (compiler_type.GetCompleteType() && compiler_type.IsCompleteType()) { - uint64_t type_id = JavaASTContext::CalculateDynamicTypeId( - exe_ctx, compiler_type, in_value); - if (type_id != UINT64_MAX) { - char id[32]; - snprintf(id, sizeof(id), "0x%" PRIX64, type_id); - return ConstString(id); - } - } - } - return ConstString(); -} - -bool JavaLanguageRuntime::GetDynamicTypeAndAddress( - ValueObject &in_value, lldb::DynamicValueType use_dynamic, - TypeAndOrName &class_type_or_name, Address &dynamic_address, - Value::ValueType &value_type) { - class_type_or_name.Clear(); - - // null references don't have a dynamic type - if (in_value.IsNilReference()) - return false; - - ExecutionContext exe_ctx(in_value.GetExecutionContextRef()); - Target *target = exe_ctx.GetTargetPtr(); - if (!target) - return false; - - ConstString linkage_name; - CompilerType in_type = in_value.GetCompilerType(); - if (in_type.IsPossibleDynamicType(nullptr, false, false)) - linkage_name = GetDynamicTypeId(&exe_ctx, target, in_value); - else - linkage_name = JavaASTContext::GetLinkageName(in_type); - - if (!linkage_name) - return false; - - class_type_or_name.SetName(in_type.GetNonReferenceType().GetTypeName()); - - SymbolContext sc; - TypeList class_types; - llvm::DenseSet<SymbolFile *> searched_symbol_files; - size_t num_matches = target->GetImages().FindTypes( - sc, linkage_name, - true, // name_is_fully_qualified - UINT32_MAX, searched_symbol_files, class_types); - - for (size_t i = 0; i < num_matches; ++i) { - TypeSP type_sp = class_types.GetTypeAtIndex(i); - CompilerType compiler_type = type_sp->GetFullCompilerType(); - - if (compiler_type.GetMinimumLanguage() != eLanguageTypeJava) - continue; - - if (compiler_type.GetCompleteType() && compiler_type.IsCompleteType()) { - class_type_or_name.SetTypeSP(type_sp); - - Value &value = in_value.GetValue(); - value_type = value.GetValueType(); - dynamic_address.SetRawAddress(value.GetScalar().ULongLong(0)); - return true; - } - } - return false; -} - -TypeAndOrName -JavaLanguageRuntime::FixUpDynamicType(const TypeAndOrName &type_and_or_name, - ValueObject &static_value) { - CompilerType static_type(static_value.GetCompilerType()); - - TypeAndOrName ret(type_and_or_name); - if (type_and_or_name.HasType()) { - CompilerType orig_type = type_and_or_name.GetCompilerType(); - if (static_type.IsReferenceType()) - ret.SetCompilerType(orig_type.GetLValueReferenceType()); - } - return ret; -} diff --git a/source/Plugins/LanguageRuntime/Java/JavaLanguageRuntime.h b/source/Plugins/LanguageRuntime/Java/JavaLanguageRuntime.h deleted file mode 100644 index 6eeb4041572ad..0000000000000 --- a/source/Plugins/LanguageRuntime/Java/JavaLanguageRuntime.h +++ /dev/null @@ -1,78 +0,0 @@ -//===-- JavaLanguageRuntime.h -----------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef liblldb_JavaLanguageRuntime_h_ -#define liblldb_JavaLanguageRuntime_h_ - -// C Includes -// C++ Includes -#include <vector> -// Other libraries and framework includes -// Project includes -#include "lldb/Core/PluginInterface.h" -#include "lldb/Target/LanguageRuntime.h" -#include "lldb/lldb-private.h" - -namespace lldb_private { - -class JavaLanguageRuntime : public LanguageRuntime { -public: - static void Initialize(); - - static void Terminate(); - - static lldb_private::LanguageRuntime * - CreateInstance(Process *process, lldb::LanguageType language); - - static lldb_private::ConstString GetPluginNameStatic(); - - lldb_private::ConstString GetPluginName() override; - - uint32_t GetPluginVersion() override; - - lldb::LanguageType GetLanguageType() const override { - return lldb::eLanguageTypeJava; - } - - bool GetObjectDescription(Stream &str, ValueObject &object) override { - return false; - } - - bool GetObjectDescription(Stream &str, Value &value, - ExecutionContextScope *exe_scope) override { - return false; - } - - lldb::BreakpointResolverSP CreateExceptionResolver(Breakpoint *bkpt, - bool catch_bp, - bool throw_bp) override { - return nullptr; - } - - TypeAndOrName FixUpDynamicType(const TypeAndOrName &type_and_or_name, - ValueObject &static_value) override; - - bool CouldHaveDynamicValue(ValueObject &in_value) override; - - bool GetDynamicTypeAndAddress(ValueObject &in_value, - lldb::DynamicValueType use_dynamic, - TypeAndOrName &class_type_or_name, - Address &address, - Value::ValueType &value_type) override; - -protected: - JavaLanguageRuntime(Process *process); - -private: - DISALLOW_COPY_AND_ASSIGN(JavaLanguageRuntime); -}; - -} // namespace lldb_private - -#endif // liblldb_JavaLanguageRuntime_h_ diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp index edb29e735ca9a..679c3c850e5b5 100644 --- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp +++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp @@ -264,11 +264,7 @@ bool ClassDescriptorV2::method_t::Read(Process *process, lldb::addr_t addr) { } process->ReadCStringFromMemory(m_types_ptr, m_types, error); - if (error.Fail()) { - return false; - } - - return true; + return !error.Fail(); } bool ClassDescriptorV2::ivar_list_t::Read(Process *process, lldb::addr_t addr) { @@ -323,11 +319,7 @@ bool ClassDescriptorV2::ivar_t::Read(Process *process, lldb::addr_t addr) { } process->ReadCStringFromMemory(m_type_ptr, m_type, error); - if (error.Fail()) { - return false; - } - - return true; + return !error.Fail(); } bool ClassDescriptorV2::Describe( @@ -524,7 +516,8 @@ void ClassDescriptorV2::iVarsStorage::fill(AppleObjCRuntimeV2 &runtime, LLDB_LOGV(log, "name = {0}, encoding = {1}, offset_ptr = {2:x}, size = " "{3}, type_size = {4}", - name, type, offset_ptr, size, ivar_type.GetByteSize(nullptr)); + name, type, offset_ptr, size, + ivar_type.GetByteSize(nullptr).getValueOr(0)); Scalar offset_scalar; Status error; const int offset_ptr_size = 4; diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h index 787423b54766a..308ff1426fb26 100644 --- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h +++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h @@ -10,12 +10,8 @@ #ifndef liblldb_AppleObjCClassDescriptorV2_h_ #define liblldb_AppleObjCClassDescriptorV2_h_ -// C Includes -// C++ Includes #include <mutex> -// Other libraries and framework includes -// Project includes #include "AppleObjCRuntimeV2.h" #include "lldb/Target/ObjCLanguageRuntime.h" #include "lldb/lldb-private.h" diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp index 105c088b9e913..4fc340b23c2c7 100644 --- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp +++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp @@ -558,7 +558,7 @@ AppleObjCDeclVendor::FindDecls(const ConstString &name, bool append, LIBLLDB_LOG_EXPRESSIONS)); // FIXME - a more appropriate log channel? if (log) - log->Printf("AppleObjCDeclVendor::FindTypes [%u] ('%s', %s, %u, )", + log->Printf("AppleObjCDeclVendor::FindDecls [%u] ('%s', %s, %u, )", current_id, (const char *)name.AsCString(), append ? "true" : "false", max_matches); diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.h b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.h index 2f087da16bc18..7f5c0bf3eb632 100644 --- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.h +++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.h @@ -10,10 +10,6 @@ #ifndef liblldb_AppleObjCDeclVendor_h_ #define liblldb_AppleObjCDeclVendor_h_ -// C Includes -// C++ Includes -// Other libraries and framework includes -// Project includes #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Symbol/DeclVendor.h" #include "lldb/Target/ObjCLanguageRuntime.h" diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp index fef42c78b24ff..ed47b481a810a 100644 --- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp +++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp @@ -17,13 +17,15 @@ #include "lldb/Core/Module.h" #include "lldb/Core/ModuleList.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/Scalar.h" #include "lldb/Core/Section.h" #include "lldb/Core/ValueObject.h" +#include "lldb/Core/ValueObjectConstResult.h" +#include "lldb/DataFormatters/FormattersHelpers.h" #include "lldb/Expression/DiagnosticManager.h" #include "lldb/Expression/FunctionCaller.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Symbol/ObjectFile.h" +#include "lldb/Target/CPPLanguageRuntime.h" #include "lldb/Target/ExecutionContext.h" #include "lldb/Target/Process.h" #include "lldb/Target/RegisterContext.h" @@ -32,9 +34,13 @@ #include "lldb/Target/Thread.h" #include "lldb/Utility/ConstString.h" #include "lldb/Utility/Log.h" +#include "lldb/Utility/Scalar.h" #include "lldb/Utility/Status.h" #include "lldb/Utility/StreamString.h" +#include "Plugins/Process/Utility/HistoryThread.h" +#include "Plugins/Language/ObjC/NSString.h" + #include <vector> using namespace lldb; @@ -167,6 +173,7 @@ bool AppleObjCRuntime::GetObjectDescription(Stream &strm, Value &value, options.SetStopOthers(true); options.SetIgnoreBreakpoints(true); options.SetTimeout(g_po_function_timeout); + options.SetIsForUtilityExpr(true); ExpressionResults results = m_print_object_caller_up->ExecuteFunction( exe_ctx, &wrapper_struct_addr, options, diagnostics, ret); @@ -440,13 +447,10 @@ bool AppleObjCRuntime::CalculateHasNewLiteralsAndIndexing() { SymbolContextList sc_list; - if (target.GetImages().FindSymbolsWithNameAndType(s_method_signature, - eSymbolTypeCode, sc_list) || - target.GetImages().FindSymbolsWithNameAndType(s_arclite_method_signature, - eSymbolTypeCode, sc_list)) - return true; - else - return false; + return target.GetImages().FindSymbolsWithNameAndType( + s_method_signature, eSymbolTypeCode, sc_list) || + target.GetImages().FindSymbolsWithNameAndType( + s_arclite_method_signature, eSymbolTypeCode, sc_list); } lldb::SearchFilterSP AppleObjCRuntime::CreateExceptionSearchFilter() { @@ -454,13 +458,115 @@ lldb::SearchFilterSP AppleObjCRuntime::CreateExceptionSearchFilter() { if (target.GetArchitecture().GetTriple().getVendor() == llvm::Triple::Apple) { FileSpecList filter_modules; - filter_modules.Append(FileSpec("libobjc.A.dylib", false)); + filter_modules.Append(std::get<0>(GetExceptionThrowLocation())); return target.GetSearchFilterForModuleList(&filter_modules); } else { return LanguageRuntime::CreateExceptionSearchFilter(); } } +ValueObjectSP AppleObjCRuntime::GetExceptionObjectForThread( + ThreadSP thread_sp) { + auto cpp_runtime = m_process->GetCPPLanguageRuntime(); + if (!cpp_runtime) return ValueObjectSP(); + auto cpp_exception = cpp_runtime->GetExceptionObjectForThread(thread_sp); + if (!cpp_exception) return ValueObjectSP(); + + auto descriptor = GetClassDescriptor(*cpp_exception.get()); + if (!descriptor || !descriptor->IsValid()) return ValueObjectSP(); + + while (descriptor) { + ConstString class_name(descriptor->GetClassName()); + if (class_name == ConstString("NSException")) return cpp_exception; + descriptor = descriptor->GetSuperclass(); + } + + return ValueObjectSP(); +} + +ThreadSP AppleObjCRuntime::GetBacktraceThreadFromException( + lldb::ValueObjectSP exception_sp) { + ValueObjectSP reserved_dict = + exception_sp->GetChildMemberWithName(ConstString("reserved"), true); + if (!reserved_dict) return ThreadSP(); + + reserved_dict = reserved_dict->GetSyntheticValue(); + if (!reserved_dict) return ThreadSP(); + + CompilerType objc_id = + exception_sp->GetTargetSP()->GetScratchClangASTContext()->GetBasicType( + lldb::eBasicTypeObjCID); + ValueObjectSP return_addresses; + + auto objc_object_from_address = [&exception_sp, &objc_id](uint64_t addr, + const char *name) { + Value value(addr); + value.SetCompilerType(objc_id); + auto object = ValueObjectConstResult::Create( + exception_sp->GetTargetSP().get(), value, ConstString(name)); + object = object->GetDynamicValue(eDynamicDontRunTarget); + return object; + }; + + for (size_t idx = 0; idx < reserved_dict->GetNumChildren(); idx++) { + ValueObjectSP dict_entry = reserved_dict->GetChildAtIndex(idx, true); + + DataExtractor data; + data.SetAddressByteSize(dict_entry->GetProcessSP()->GetAddressByteSize()); + Status error; + dict_entry->GetData(data, error); + if (error.Fail()) return ThreadSP(); + + lldb::offset_t data_offset = 0; + auto dict_entry_key = data.GetPointer(&data_offset); + auto dict_entry_value = data.GetPointer(&data_offset); + + auto key_nsstring = objc_object_from_address(dict_entry_key, "key"); + StreamString key_summary; + if (lldb_private::formatters::NSStringSummaryProvider( + *key_nsstring, key_summary, TypeSummaryOptions()) && + !key_summary.Empty()) { + if (key_summary.GetString() == "\"callStackReturnAddresses\"") { + return_addresses = objc_object_from_address(dict_entry_value, + "callStackReturnAddresses"); + break; + } + } + } + + if (!return_addresses) return ThreadSP(); + auto frames_value = + return_addresses->GetChildMemberWithName(ConstString("_frames"), true); + addr_t frames_addr = frames_value->GetValueAsUnsigned(0); + auto count_value = + return_addresses->GetChildMemberWithName(ConstString("_cnt"), true); + size_t count = count_value->GetValueAsUnsigned(0); + auto ignore_value = + return_addresses->GetChildMemberWithName(ConstString("_ignore"), true); + size_t ignore = ignore_value->GetValueAsUnsigned(0); + + size_t ptr_size = m_process->GetAddressByteSize(); + std::vector<lldb::addr_t> pcs; + for (size_t idx = 0; idx < count; idx++) { + Status error; + addr_t pc = m_process->ReadPointerFromMemory( + frames_addr + (ignore + idx) * ptr_size, error); + pcs.push_back(pc); + } + + if (pcs.empty()) return ThreadSP(); + + ThreadSP new_thread_sp(new HistoryThread(*m_process, 0, pcs, 0, false)); + m_process->GetExtendedThreadList().AddThread(new_thread_sp); + return new_thread_sp; +} + +std::tuple<FileSpec, ConstString> +AppleObjCRuntime::GetExceptionThrowLocation() { + return std::make_tuple( + FileSpec("libobjc.A.dylib"), ConstString("objc_exception_throw")); +} + void AppleObjCRuntime::ReadObjCLibraryIfNeeded(const ModuleList &module_list) { if (!HasReadObjCLibrary()) { std::lock_guard<std::recursive_mutex> guard(module_list.GetMutex()); diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h index 1b22ee4c3be17..8660646001497 100644 --- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h +++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h @@ -10,12 +10,8 @@ #ifndef liblldb_AppleObjCRuntime_h_ #define liblldb_AppleObjCRuntime_h_ -// C Includes -// C++ Includes -// Other libraries and framework includes #include "llvm/ADT/Optional.h" -// Project includes #include "AppleObjCTrampolineHandler.h" #include "AppleThreadPlanStepThroughObjCTrampoline.h" #include "lldb/Target/LanguageRuntime.h" @@ -90,6 +86,14 @@ public: bool ExceptionBreakpointsExplainStop(lldb::StopInfoSP stop_reason) override; lldb::SearchFilterSP CreateExceptionSearchFilter() override; + + static std::tuple<FileSpec, ConstString> GetExceptionThrowLocation(); + + lldb::ValueObjectSP GetExceptionObjectForThread( + lldb::ThreadSP thread_sp) override; + + lldb::ThreadSP GetBacktraceThreadFromException( + lldb::ValueObjectSP thread_sp) override; uint32_t GetFoundationVersion(); diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp index 5001c0461b3b4..1cfc7a1a022b5 100644 --- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp +++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp @@ -17,7 +17,6 @@ #include "lldb/Breakpoint/BreakpointLocation.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/Scalar.h" #include "lldb/Expression/FunctionCaller.h" #include "lldb/Expression/UtilityFunction.h" #include "lldb/Symbol/ClangASTContext.h" @@ -29,6 +28,7 @@ #include "lldb/Target/Thread.h" #include "lldb/Utility/ConstString.h" #include "lldb/Utility/Log.h" +#include "lldb/Utility/Scalar.h" #include "lldb/Utility/Status.h" #include "lldb/Utility/StreamString.h" @@ -58,7 +58,7 @@ bool AppleObjCRuntimeV1::GetDynamicTypeAndAddress( class_type_or_name.SetName(class_descriptor->GetClassName()); } } - return class_type_or_name.IsEmpty() == false; + return !class_type_or_name.IsEmpty(); } //------------------------------------------------------------------ @@ -113,8 +113,9 @@ AppleObjCRuntimeV1::CreateExceptionResolver(Breakpoint *bkpt, bool catch_bp, if (throw_bp) resolver_sp.reset(new BreakpointResolverName( - bkpt, "objc_exception_throw", eFunctionNameTypeBase, - eLanguageTypeUnknown, Breakpoint::Exact, 0, eLazyBoolNo)); + bkpt, std::get<1>(GetExceptionThrowLocation()).AsCString(), + eFunctionNameTypeBase, eLanguageTypeUnknown, Breakpoint::Exact, 0, + eLazyBoolNo)); // FIXME: don't do catch yet. return resolver_sp; } diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h index 52eec0f692fb3..442a3a1fb5e1e 100644 --- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h +++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h @@ -10,10 +10,6 @@ #ifndef liblldb_AppleObjCRuntimeV1_h_ #define liblldb_AppleObjCRuntimeV1_h_ -// C Includes -// C++ Includes -// Other libraries and framework includes -// Project includes #include "AppleObjCRuntime.h" #include "lldb/Target/ObjCLanguageRuntime.h" #include "lldb/lldb-private.h" diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp index d217ed3ff3258..b6ed2fe376d35 100644 --- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp +++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp @@ -7,18 +7,14 @@ // //===----------------------------------------------------------------------===// -// C Includes #include <stdint.h> -// C++ Includes #include <string> #include <vector> -// Other libraries and framework includes #include "clang/AST/ASTContext.h" #include "clang/AST/DeclObjC.h" -// Project includes #include "lldb/Core/ClangForward.h" #include "lldb/Host/OptionParser.h" #include "lldb/Symbol/CompilerType.h" @@ -28,8 +24,8 @@ #include "lldb/Core/Debugger.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/Scalar.h" #include "lldb/Core/Section.h" +#include "lldb/Core/ValueObjectConstResult.h" #include "lldb/Core/ValueObjectVariable.h" #include "lldb/Expression/DiagnosticManager.h" #include "lldb/Expression/FunctionCaller.h" @@ -44,14 +40,17 @@ #include "lldb/Symbol/Symbol.h" #include "lldb/Symbol/TypeList.h" #include "lldb/Symbol/VariableList.h" +#include "lldb/Target/ABI.h" #include "lldb/Target/ExecutionContext.h" #include "lldb/Target/Platform.h" #include "lldb/Target/Process.h" #include "lldb/Target/RegisterContext.h" +#include "lldb/Target/StackFrameRecognizer.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" #include "lldb/Utility/ConstString.h" #include "lldb/Utility/Log.h" +#include "lldb/Utility/Scalar.h" #include "lldb/Utility/Status.h" #include "lldb/Utility/Stream.h" #include "lldb/Utility/StreamString.h" @@ -377,6 +376,8 @@ ExtractRuntimeGlobalSymbol(Process *process, ConstString name, } } +static void RegisterObjCExceptionRecognizer(); + AppleObjCRuntimeV2::AppleObjCRuntimeV2(Process *process, const ModuleSP &objc_module_sp) : AppleObjCRuntime(process), m_get_class_info_code(), @@ -397,6 +398,7 @@ AppleObjCRuntimeV2::AppleObjCRuntimeV2(Process *process, static const ConstString g_gdb_object_getClass("gdb_object_getClass"); m_has_object_getClass = (objc_module_sp->FindFirstSymbolWithNameAndType( g_gdb_object_getClass, eSymbolTypeCode) != NULL); + RegisterObjCExceptionRecognizer(); } bool AppleObjCRuntimeV2::GetDynamicTypeAndAddress( @@ -452,7 +454,7 @@ bool AppleObjCRuntimeV2::GetDynamicTypeAndAddress( } } } - return class_type_or_name.IsEmpty() == false; + return !class_type_or_name.IsEmpty(); } //------------------------------------------------------------------ @@ -475,9 +477,9 @@ LanguageRuntime *AppleObjCRuntimeV2::CreateInstance(Process *process, return NULL; } -static OptionDefinition g_objc_classtable_dump_options[] = { +static constexpr OptionDefinition g_objc_classtable_dump_options[] = { {LLDB_OPT_SET_ALL, false, "verbose", 'v', OptionParser::eNoArgument, - nullptr, nullptr, 0, eArgTypeNone, + nullptr, {}, 0, eArgTypeNone, "Print ivar and method information in detail"}}; class CommandObjectObjC_ClassTable_Dump : public CommandObjectParsed { @@ -803,8 +805,9 @@ AppleObjCRuntimeV2::CreateExceptionResolver(Breakpoint *bkpt, bool catch_bp, if (throw_bp) resolver_sp.reset(new BreakpointResolverName( - bkpt, "objc_exception_throw", eFunctionNameTypeBase, - eLanguageTypeUnknown, Breakpoint::Exact, 0, eLazyBoolNo)); + bkpt, std::get<1>(GetExceptionThrowLocation()).AsCString(), + eFunctionNameTypeBase, eLanguageTypeUnknown, Breakpoint::Exact, 0, + eLazyBoolNo)); // FIXME: We don't do catch breakpoints for ObjC yet. // Should there be some way for the runtime to specify what it can do in this // regard? @@ -1409,6 +1412,7 @@ AppleObjCRuntimeV2::UpdateISAToDescriptorMapDynamic( options.SetStopOthers(true); options.SetIgnoreBreakpoints(true); options.SetTimeout(g_utility_function_timeout); + options.SetIsForUtilityExpr(true); Value return_value; return_value.SetValueType(Value::eValueTypeScalar); @@ -1659,6 +1663,7 @@ AppleObjCRuntimeV2::UpdateISAToDescriptorMapSharedCache() { options.SetStopOthers(true); options.SetIgnoreBreakpoints(true); options.SetTimeout(g_utility_function_timeout); + options.SetIsForUtilityExpr(true); Value return_value; return_value.SetValueType(Value::eValueTypeScalar); @@ -1847,8 +1852,8 @@ void AppleObjCRuntimeV2::UpdateISAToDescriptorMapIfNeeded() { // warn if: // - we could not run either expression // - we found fewer than num_classes_to_warn_at classes total - if ((false == shared_cache_update_result.m_update_ran) || - (false == dynamic_update_result.m_update_ran)) + if ((!shared_cache_update_result.m_update_ran) || + (!dynamic_update_result.m_update_ran)) WarnIfNoClassesCached( SharedCacheWarningReason::eExpressionExecutionFailure); else if (dynamic_update_result.m_num_found + @@ -2423,7 +2428,7 @@ AppleObjCRuntimeV2::NonPointerISACache::NonPointerISACache( ObjCLanguageRuntime::ClassDescriptorSP AppleObjCRuntimeV2::NonPointerISACache::GetClassDescriptor(ObjCISA isa) { ObjCISA real_isa = 0; - if (EvaluateNonPointerISA(isa, real_isa) == false) + if (!EvaluateNonPointerISA(isa, real_isa)) return ObjCLanguageRuntime::ClassDescriptorSP(); auto cache_iter = m_cache.find(real_isa); if (cache_iter != m_cache.end()) @@ -2447,7 +2452,7 @@ bool AppleObjCRuntimeV2::NonPointerISACache::EvaluateNonPointerISA( // If all of the indexed ISA variables are set, then its possible that this // ISA is indexed, and we should first try to get its value using the index. - // Note, we check these varaibles first as the ObjC runtime will set at least + // Note, we check these variables first as the ObjC runtime will set at least // one of their values to 0 if they aren't needed. if (m_objc_debug_indexed_isa_magic_mask && m_objc_debug_indexed_isa_magic_value && @@ -2534,7 +2539,7 @@ bool AppleObjCRuntimeV2::NonPointerISACache::EvaluateNonPointerISA( return false; } - // Definately not an indexed ISA, so try to use a mask to extract the pointer + // Definitely not an indexed ISA, so try to use a mask to extract the pointer // from the ISA. if ((isa & m_objc_debug_isa_magic_mask) == m_objc_debug_isa_magic_value) { ret_isa = isa & m_objc_debug_isa_class_mask; @@ -2594,3 +2599,62 @@ void AppleObjCRuntimeV2::GetValuesForGlobalCFBooleans(lldb::addr_t &cf_true, } else this->AppleObjCRuntime::GetValuesForGlobalCFBooleans(cf_true, cf_false); } + +#pragma mark Frame recognizers + +class ObjCExceptionRecognizedStackFrame : public RecognizedStackFrame { + public: + ObjCExceptionRecognizedStackFrame(StackFrameSP frame_sp) { + ThreadSP thread_sp = frame_sp->GetThread(); + ProcessSP process_sp = thread_sp->GetProcess(); + + const lldb::ABISP &abi = process_sp->GetABI(); + if (!abi) return; + + CompilerType voidstar = process_sp->GetTarget() + .GetScratchClangASTContext() + ->GetBasicType(lldb::eBasicTypeVoid) + .GetPointerType(); + + ValueList args; + Value input_value; + input_value.SetCompilerType(voidstar); + args.PushValue(input_value); + + if (!abi->GetArgumentValues(*thread_sp, args)) return; + + addr_t exception_addr = args.GetValueAtIndex(0)->GetScalar().ULongLong(); + + Value value(exception_addr); + value.SetCompilerType(voidstar); + exception = ValueObjectConstResult::Create(frame_sp.get(), value, + ConstString("exception")); + exception = exception->GetDynamicValue(eDynamicDontRunTarget); + + m_arguments = ValueObjectListSP(new ValueObjectList()); + m_arguments->Append(exception); + } + + ValueObjectSP exception; + + lldb::ValueObjectSP GetExceptionObject() override { return exception; } +}; + +class ObjCExceptionThrowFrameRecognizer : public StackFrameRecognizer { + lldb::RecognizedStackFrameSP RecognizeFrame(lldb::StackFrameSP frame) { + return lldb::RecognizedStackFrameSP( + new ObjCExceptionRecognizedStackFrame(frame)); + }; +}; + +static void RegisterObjCExceptionRecognizer() { + static llvm::once_flag g_once_flag; + llvm::call_once(g_once_flag, []() { + FileSpec module; + ConstString function; + std::tie(module, function) = AppleObjCRuntime::GetExceptionThrowLocation(); + StackFrameRecognizerManager::AddRecognizer( + StackFrameRecognizerSP(new ObjCExceptionThrowFrameRecognizer()), + module.GetFilename(), function, /*first_instruction_only*/ true); + }); +} diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h index 487b67ca6271c..aa91f857219b2 100644 --- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h +++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h @@ -10,14 +10,10 @@ #ifndef liblldb_AppleObjCRuntimeV2_h_ #define liblldb_AppleObjCRuntimeV2_h_ -// C Includes -// C++ Includes #include <map> #include <memory> #include <mutex> -// Other libraries and framework includes -// Project includes #include "AppleObjCRuntime.h" #include "lldb/Target/ObjCLanguageRuntime.h" #include "lldb/lldb-private.h" diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp index c75fa71ba131a..e9182c5909773 100644 --- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp +++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp @@ -10,10 +10,6 @@ #include "AppleObjCTrampolineHandler.h" -// C Includes -// C++ Includes -// Other libraries and framework includes -// Project includes #include "AppleThreadPlanStepThroughObjCTrampoline.h" #include "lldb/Breakpoint/StoppointCallbackContext.h" @@ -80,7 +76,7 @@ extern \"C\" void * __lldb_objc_find_implementation_for_selector ( \n\ void *super_ptr; \n\ }; \n\ struct __lldb_objc_super { \n\ - void *reciever; \n\ + void *receiver; \n\ struct __lldb_objc_class *class_ptr; \n\ }; \n\ struct __lldb_msg_ref { \n\ @@ -202,7 +198,7 @@ extern \"C\" void * __lldb_objc_find_implementation_for_selector (void *object, void *super_ptr; \n\ }; \n\ struct __lldb_objc_super { \n\ - void *reciever; \n\ + void *receiver; \n\ struct __lldb_objc_class *class_ptr; \n\ }; \n\ struct __lldb_msg_ref { \n\ diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.h b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.h index dc58a8bc1eb63..fe3390757d080 100644 --- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.h +++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.h @@ -10,14 +10,10 @@ #ifndef lldb_AppleObjCTrampolineHandler_h_ #define lldb_AppleObjCTrampolineHandler_h_ -// C Includes -// C++ Includes #include <map> #include <mutex> #include <vector> -// Other libraries and framework includes -// Project includes #include "lldb/Expression/UtilityFunction.h" #include "lldb/lldb-public.h" diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.h b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.h index 4da84dd92c3ff..fac564e331653 100644 --- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.h +++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.h @@ -10,12 +10,8 @@ #ifndef liblldb_AppleObjCTypeEncodingParser_h_ #define liblldb_AppleObjCTypeEncodingParser_h_ -// C Includes -// C++ Includes -// Other libraries and framework includes #include "clang/AST/ASTContext.h" -// Project includes #include "lldb/Target/ObjCLanguageRuntime.h" #include "lldb/lldb-private.h" diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp index 75b6707394279..2b54d0a542d95 100644 --- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp +++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp @@ -8,10 +8,6 @@ // //===----------------------------------------------------------------------===// -// C Includes -// C++ Includes -// Other libraries and framework includes -// Project includes #include "AppleThreadPlanStepThroughObjCTrampoline.h" #include "AppleObjCTrampolineHandler.h" #include "lldb/Expression/DiagnosticManager.h" @@ -161,13 +157,15 @@ bool AppleThreadPlanStepThroughObjCTrampoline::ShouldStop(Event *event_ptr) { SymbolContext sc = m_thread.GetStackFrameAtIndex(0)->GetSymbolContext( eSymbolContextEverything); + Status status; const bool abort_other_plans = false; const bool first_insn = true; const uint32_t frame_idx = 0; m_run_to_sp = m_thread.QueueThreadPlanForStepOutNoShouldStop( abort_other_plans, &sc, first_insn, m_stop_others, eVoteNoOpinion, - eVoteNoOpinion, frame_idx); - m_run_to_sp->SetPrivate(true); + eVoteNoOpinion, frame_idx, status); + if (m_run_to_sp && status.Success()) + m_run_to_sp->SetPrivate(true); return false; } @@ -202,10 +200,7 @@ bool AppleThreadPlanStepThroughObjCTrampoline::ShouldStop(Event *event_ptr) { // The base class MischiefManaged does some cleanup - so you have to call it in // your MischiefManaged derived class. bool AppleThreadPlanStepThroughObjCTrampoline::MischiefManaged() { - if (IsPlanComplete()) - return true; - else - return false; + return IsPlanComplete(); } bool AppleThreadPlanStepThroughObjCTrampoline::WillStop() { return true; } diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.h b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.h index 60c8b92d9cc7c..5758e19f83ca8 100644 --- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.h +++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.h @@ -10,10 +10,6 @@ #ifndef lldb_AppleThreadPlanStepThroughObjCTrampoline_h_ #define lldb_AppleThreadPlanStepThroughObjCTrampoline_h_ -// C Includes -// C++ Includes -// Other libraries and framework includes -// Project includes #include "AppleObjCTrampolineHandler.h" #include "lldb/Core/Value.h" #include "lldb/Target/ThreadPlan.h" diff --git a/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptExpressionOpts.cpp b/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptExpressionOpts.cpp index cbbc35f1c08a8..2c12cf9af6370 100644 --- a/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptExpressionOpts.cpp +++ b/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptExpressionOpts.cpp @@ -7,11 +7,8 @@ // //===----------------------------------------------------------------------===// -// C Includes -// C++ Includes #include <string> -// Other libraries and framework includes #include "llvm/ADT/None.h" #include "llvm/ADT/StringRef.h" #include "llvm/IR/Instruction.h" @@ -24,7 +21,6 @@ #include "clang/Basic/TargetOptions.h" -// Project includes #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" #include "lldb/Utility/Log.h" diff --git a/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptExpressionOpts.h b/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptExpressionOpts.h index f45ff83c5a2bd..647558171d1c6 100644 --- a/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptExpressionOpts.h +++ b/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptExpressionOpts.h @@ -10,15 +10,11 @@ #ifndef LLDB_RENDERSCRIPT_EXPROPTS_H #define LLDB_RENDERSCRIPT_EXPROPTS_H -// C Includes -// C++ Includes -// Other libraries and framework includes #include "llvm/IR/Module.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetOptions.h" -// Project includes #include "lldb/Target/LanguageRuntime.h" #include "lldb/Target/Process.h" #include "lldb/lldb-private.h" diff --git a/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp b/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp index 4eb15369aa1eb..fa775d9bfa94a 100644 --- a/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp +++ b/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp @@ -7,12 +7,8 @@ // //===----------------------------------------------------------------------===// -// C Includes -// C++ Includes -// Other libraries and framework includes #include "llvm/ADT/StringSwitch.h" -// Project includes #include "RenderScriptRuntime.h" #include "RenderScriptScriptGroup.h" @@ -20,7 +16,6 @@ #include "lldb/Core/Debugger.h" #include "lldb/Core/DumpDataExtractor.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/RegisterValue.h" #include "lldb/Core/ValueObjectVariable.h" #include "lldb/DataFormatters/DumpValueObjectOptions.h" #include "lldb/Expression/UserExpression.h" @@ -41,8 +36,8 @@ #include "lldb/Target/Thread.h" #include "lldb/Utility/Args.h" #include "lldb/Utility/ConstString.h" -#include "lldb/Utility/DataBufferLLVM.h" #include "lldb/Utility/Log.h" +#include "lldb/Utility/RegisterValue.h" #include "lldb/Utility/RegularExpression.h" #include "lldb/Utility/Status.h" @@ -2079,10 +2074,8 @@ bool RenderScriptRuntime::JITElementPacked(Element &elem, // If this Element has subelements then JIT rsaElementGetSubElements() for // details about its fields - if (*elem.field_count.get() > 0 && !JITSubelements(elem, context, frame_ptr)) - return false; - - return true; + return !(*elem.field_count.get() > 0 && + !JITSubelements(elem, context, frame_ptr)); } // JITs the RS runtime for information about the subelements/fields of a struct @@ -2305,10 +2298,7 @@ bool RenderScriptRuntime::RefreshAllocation(AllocationDetails *alloc, SetElementSize(alloc->element); // Use GetOffsetPointer() to infer size of the allocation - if (!JITAllocationSize(alloc, frame_ptr)) - return false; - - return true; + return JITAllocationSize(alloc, frame_ptr); } // Function attempts to set the type_name member of the paramaterised Element @@ -2529,21 +2519,22 @@ bool RenderScriptRuntime::LoadAllocation(Stream &strm, const uint32_t alloc_id, "Allocation information not available"); // Check we can read from file - FileSpec file(path, true); - if (!file.Exists()) { + FileSpec file(path); + FileSystem::Instance().Resolve(file); + if (!FileSystem::Instance().Exists(file)) { strm.Printf("Error: File %s does not exist", path); strm.EOL(); return false; } - if (!file.Readable()) { + if (!FileSystem::Instance().Readable(file)) { strm.Printf("Error: File %s does not have readable permissions", path); strm.EOL(); return false; } // Read file into data buffer - auto data_sp = DataBufferLLVM::CreateFromPath(file.GetPath()); + auto data_sp = FileSystem::Instance().CreateDataBuffer(file.GetPath()); // Cast start of buffer to FileHeader and use pointer to read metadata void *file_buf = data_sp->GetBytes(); @@ -2753,9 +2744,14 @@ bool RenderScriptRuntime::SaveAllocation(Stream &strm, const uint32_t alloc_id, "Allocation information not available"); // Check we can create writable file - FileSpec file_spec(path, true); - File file(file_spec, File::eOpenOptionWrite | File::eOpenOptionCanCreate | - File::eOpenOptionTruncate); + FileSpec file_spec(path); + FileSystem::Instance().Resolve(file_spec); + File file; + FileSystem::Instance().Open(file, file_spec, + File::eOpenOptionWrite | + File::eOpenOptionCanCreate | + File::eOpenOptionTruncate); + if (!file) { strm.Printf("Error: Failed to open '%s' for writing", path); strm.EOL(); @@ -3079,7 +3075,8 @@ bool RSModuleDescriptor::ParseRSInfo() { const addr_t size = info_sym->GetByteSize(); const FileSpec fs = m_module->GetFileSpec(); - auto buffer = DataBufferLLVM::CreateSliceFromPath(fs.GetPath(), size, addr); + auto buffer = + FileSystem::Instance().CreateDataBuffer(fs.GetPath(), size, addr); if (!buffer) return false; @@ -3718,7 +3715,8 @@ bool RenderScriptRuntime::GetKernelCoordinate(RSCoordinate &coord, continue; // Find the function name - const SymbolContext sym_ctx = frame_sp->GetSymbolContext(false); + const SymbolContext sym_ctx = + frame_sp->GetSymbolContext(eSymbolContextFunction); const ConstString func_name = sym_ctx.GetFunctionName(); if (!func_name) continue; @@ -4171,13 +4169,13 @@ public: } }; -static OptionDefinition g_renderscript_reduction_bp_set_options[] = { +static constexpr OptionDefinition g_renderscript_reduction_bp_set_options[] = { {LLDB_OPT_SET_1, false, "function-role", 't', - OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeOneLiner, + OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeOneLiner, "Break on a comma separated set of reduction kernel types " "(accumulator,outcoverter,combiner,initializer"}, {LLDB_OPT_SET_1, false, "coordinate", 'c', OptionParser::eRequiredArgument, - nullptr, nullptr, 0, eArgTypeValue, + nullptr, {}, 0, eArgTypeValue, "Set a breakpoint on a single invocation of the kernel with specified " "coordinate.\n" "Coordinate takes the form 'x[,y][,z] where x,y,z are positive " @@ -4330,9 +4328,9 @@ private: CommandOptions m_options; }; -static OptionDefinition g_renderscript_kernel_bp_set_options[] = { +static constexpr OptionDefinition g_renderscript_kernel_bp_set_options[] = { {LLDB_OPT_SET_1, false, "coordinate", 'c', OptionParser::eRequiredArgument, - nullptr, nullptr, 0, eArgTypeValue, + nullptr, {}, 0, eArgTypeValue, "Set a breakpoint on a single invocation of the kernel with specified " "coordinate.\n" "Coordinate takes the form 'x[,y][,z] where x,y,z are positive " @@ -4602,9 +4600,9 @@ public: } }; -static OptionDefinition g_renderscript_runtime_alloc_dump_options[] = { +static constexpr OptionDefinition g_renderscript_runtime_alloc_dump_options[] = { {LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, - nullptr, nullptr, 0, eArgTypeFilename, + nullptr, {}, 0, eArgTypeFilename, "Print results to specified file instead of command line."}}; class CommandObjectRenderScriptRuntimeContext : public CommandObjectMultiword { @@ -4650,8 +4648,9 @@ public: switch (short_option) { case 'f': - m_outfile.SetFile(option_arg, true, FileSpec::Style::native); - if (m_outfile.Exists()) { + m_outfile.SetFile(option_arg, FileSpec::Style::native); + FileSystem::Instance().Resolve(m_outfile); + if (FileSystem::Instance().Exists(m_outfile)) { m_outfile.Clear(); err.SetErrorStringWithFormat("file already exists: '%s'", option_arg.str().c_str()); @@ -4706,16 +4705,17 @@ public: m_options.m_outfile; // Dump allocation to file instead if (outfile_spec) { // Open output file - char path[256]; - outfile_spec.GetPath(path, sizeof(path)); - if (outfile_stream.GetFile() - .Open(path, File::eOpenOptionWrite | File::eOpenOptionCanCreate) - .Success()) { + std::string path = outfile_spec.GetPath(); + auto error = FileSystem::Instance().Open( + outfile_stream.GetFile(), outfile_spec, + File::eOpenOptionWrite | File::eOpenOptionCanCreate); + if (error.Success()) { output_strm = &outfile_stream; - result.GetOutputStream().Printf("Results written to '%s'", path); + result.GetOutputStream().Printf("Results written to '%s'", + path.c_str()); result.GetOutputStream().EOL(); } else { - result.AppendErrorWithFormat("Couldn't open file '%s'", path); + result.AppendErrorWithFormat("Couldn't open file '%s'", path.c_str()); result.SetStatus(eReturnStatusFailed); return false; } @@ -4738,9 +4738,9 @@ private: CommandOptions m_options; }; -static OptionDefinition g_renderscript_runtime_alloc_list_options[] = { +static constexpr OptionDefinition g_renderscript_runtime_alloc_list_options[] = { {LLDB_OPT_SET_1, false, "id", 'i', OptionParser::eRequiredArgument, nullptr, - nullptr, 0, eArgTypeIndex, + {}, 0, eArgTypeIndex, "Only show details of a single allocation with specified id."}}; class CommandObjectRenderScriptRuntimeAllocationList diff --git a/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h b/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h index 0fe9134ce9e42..31714dd4a4539 100644 --- a/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h +++ b/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h @@ -10,18 +10,14 @@ #ifndef liblldb_RenderScriptRuntime_h_ #define liblldb_RenderScriptRuntime_h_ -// C Includes -// C++ Includes #include <array> #include <map> #include <memory> #include <string> #include <vector> -// Other libraries and framework includes #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" -// Project includes #include "lldb/Core/Module.h" #include "lldb/Expression/LLVMUserExpression.h" #include "lldb/Target/CPPLanguageRuntime.h" @@ -74,7 +70,7 @@ public: SymbolContext &context, Address *addr, bool containing) override; - Searcher::Depth GetDepth() override { return Searcher::eDepthModule; } + lldb::SearchDepth GetDepth() override { return lldb::eSearchDepthModule; } lldb::BreakpointResolverSP CopyForBreakpoint(Breakpoint &breakpoint) override { @@ -124,7 +120,7 @@ public: SymbolContext &context, Address *addr, bool containing) override; - Searcher::Depth GetDepth() override { return Searcher::eDepthModule; } + lldb::SearchDepth GetDepth() override { return lldb::eSearchDepthModule; } lldb::BreakpointResolverSP CopyForBreakpoint(Breakpoint &breakpoint) override { @@ -269,7 +265,7 @@ public: SymbolContext &context, Address *addr, bool containing) override; - Searcher::Depth GetDepth() override { return Searcher::eDepthModule; } + lldb::SearchDepth GetDepth() override { return lldb::eSearchDepthModule; } lldb::BreakpointResolverSP CopyForBreakpoint(Breakpoint &breakpoint) override { diff --git a/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptx86ABIFixups.cpp b/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptx86ABIFixups.cpp index e1f8ea6484145..0b298c90a50b1 100644 --- a/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptx86ABIFixups.cpp +++ b/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptx86ABIFixups.cpp @@ -7,11 +7,8 @@ // //===----------------------------------------------------------------------===// -// C Includes -// C++ Includes #include <set> -// Other libraries and framework includes #include "llvm/ADT/StringRef.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/CallSite.h" @@ -23,7 +20,6 @@ #include "llvm/IRReader/IRReader.h" #include "llvm/Pass.h" -// Project includes #include "lldb/Target/Process.h" #include "lldb/Utility/Log.h" |