diff options
Diffstat (limited to 'source/Expression')
| -rw-r--r-- | source/Expression/ASTResultSynthesizer.cpp | 4 | ||||
| -rw-r--r-- | source/Expression/ASTStructExtractor.cpp | 4 | ||||
| -rw-r--r-- | source/Expression/ClangExpressionParser.cpp | 1 | ||||
| -rw-r--r-- | source/Expression/ClangModulesDeclVendor.cpp | 8 | ||||
| -rw-r--r-- | source/Expression/ExpressionSourceCode.cpp | 6 | ||||
| -rw-r--r-- | source/Expression/IRExecutionUnit.cpp | 165 | ||||
| -rw-r--r-- | source/Expression/IRForTarget.cpp | 6 | ||||
| -rw-r--r-- | source/Expression/Materializer.cpp | 4 | 
8 files changed, 162 insertions, 36 deletions
diff --git a/source/Expression/ASTResultSynthesizer.cpp b/source/Expression/ASTResultSynthesizer.cpp index 2f14721100bc..c3d42cb49ec5 100644 --- a/source/Expression/ASTResultSynthesizer.cpp +++ b/source/Expression/ASTResultSynthesizer.cpp @@ -480,10 +480,10 @@ ASTResultSynthesizer::CompleteTentativeDefinition(VarDecl *D)  }  void -ASTResultSynthesizer::HandleVTable(CXXRecordDecl *RD, bool DefinitionRequired) +ASTResultSynthesizer::HandleVTable(CXXRecordDecl *RD)  {      if (m_passthrough) -        m_passthrough->HandleVTable(RD, DefinitionRequired); +        m_passthrough->HandleVTable(RD);  }  void diff --git a/source/Expression/ASTStructExtractor.cpp b/source/Expression/ASTStructExtractor.cpp index 2a8b7bc7d8ec..98628dbc92be 100644 --- a/source/Expression/ASTStructExtractor.cpp +++ b/source/Expression/ASTStructExtractor.cpp @@ -186,10 +186,10 @@ ASTStructExtractor::CompleteTentativeDefinition(VarDecl *D)  }  void -ASTStructExtractor::HandleVTable(CXXRecordDecl *RD, bool DefinitionRequired) +ASTStructExtractor::HandleVTable(CXXRecordDecl *RD)  {      if (m_passthrough) -        m_passthrough->HandleVTable(RD, DefinitionRequired); +        m_passthrough->HandleVTable(RD);  }  void diff --git a/source/Expression/ClangExpressionParser.cpp b/source/Expression/ClangExpressionParser.cpp index 4906108401af..d05d9b99df07 100644 --- a/source/Expression/ClangExpressionParser.cpp +++ b/source/Expression/ClangExpressionParser.cpp @@ -329,7 +329,6 @@ ClangExpressionParser::ClangExpressionParser (ExecutionContextScope *exe_scope,      m_code_generator.reset(CreateLLVMCodeGen(m_compiler->getDiagnostics(),                                               module_name,                                               m_compiler->getCodeGenOpts(), -                                             m_compiler->getTargetOpts(),                                               *m_llvm_context));  } diff --git a/source/Expression/ClangModulesDeclVendor.cpp b/source/Expression/ClangModulesDeclVendor.cpp index 46adaaff33ce..0800b52e7e99 100644 --- a/source/Expression/ClangModulesDeclVendor.cpp +++ b/source/Expression/ClangModulesDeclVendor.cpp @@ -7,8 +7,11 @@  //  //===----------------------------------------------------------------------===// -#include "lldb/Core/StreamString.h" +#include <mutex> // std::once +  #include "lldb/Expression/ClangModulesDeclVendor.h" + +#include "lldb/Core/StreamString.h"  #include "lldb/Host/FileSpec.h"  #include "lldb/Host/Host.h"  #include "lldb/Host/HostInfo.h" @@ -22,7 +25,6 @@  #include "clang/Sema/Lookup.h"  #include "clang/Serialization/ASTReader.h" -#include <mutex>  using namespace lldb_private; @@ -289,7 +291,7 @@ ClangModulesDeclVendor::Create(Target &target)          "-Werror=non-modular-include-in-framework-module"      }; -    target.GetPlatform()->AddClangModuleCompilationOptions(compiler_invocation_arguments); +    target.GetPlatform()->AddClangModuleCompilationOptions(&target, compiler_invocation_arguments);      compiler_invocation_arguments.push_back(ModuleImportBufferName); diff --git a/source/Expression/ExpressionSourceCode.cpp b/source/Expression/ExpressionSourceCode.cpp index 080562e51e91..b3f335f1b314 100644 --- a/source/Expression/ExpressionSourceCode.cpp +++ b/source/Expression/ExpressionSourceCode.cpp @@ -41,13 +41,17 @@ typedef __UINTPTR_TYPE__ uintptr_t;  typedef __SIZE_TYPE__ size_t;  typedef __PTRDIFF_TYPE__ ptrdiff_t;  typedef unsigned short unichar; +extern "C" +{ +    int printf(const char * __restrict, ...); +}  )";  bool ExpressionSourceCode::GetText (std::string &text, lldb::LanguageType wrapping_language, bool const_object, bool static_method, ExecutionContext &exe_ctx) const  {      const char *target_specific_defines = "typedef signed char BOOL;\n"; -    static ConstString g_platform_ios_simulator ("PlatformiOSSimulator"); +    static ConstString g_platform_ios_simulator ("ios-simulator");      if (Target *target = exe_ctx.GetTargetPtr())      { diff --git a/source/Expression/IRExecutionUnit.cpp b/source/Expression/IRExecutionUnit.cpp index e7cb728778e6..9ca9e25907b6 100644 --- a/source/Expression/IRExecutionUnit.cpp +++ b/source/Expression/IRExecutionUnit.cpp @@ -199,28 +199,8 @@ IRExecutionUnit::DisassembleFunction (Stream &stream,      disassembler_sp->DecodeInstructions (Address (func_remote_addr), extractor, 0, UINT32_MAX, false, false);      InstructionList &instruction_list = disassembler_sp->GetInstructionList(); -    const uint32_t max_opcode_byte_size = instruction_list.GetMaxOpcocdeByteSize(); -    const char *disassemble_format = "${addr-file-or-load}: "; -    if (exe_ctx.HasTargetScope()) -    { -        disassemble_format = exe_ctx.GetTargetRef().GetDebugger().GetDisassemblyFormat(); -    } - -    for (size_t instruction_index = 0, num_instructions = instruction_list.GetSize(); -         instruction_index < num_instructions; -         ++instruction_index) -    { -        Instruction *instruction = instruction_list.GetInstructionAtIndex(instruction_index).get(); -        instruction->Dump (&stream, -                           max_opcode_byte_size, -                           true, -                           true, -                           &exe_ctx, -                           NULL, -                           NULL, -                           disassemble_format); -        stream.PutChar('\n'); -    } +    instruction_list.Dump(&stream, true, true, &exe_ctx); +          // FIXME: The DisassemblerLLVMC has a reference cycle and won't go away if it has any active instructions.      // I'll fix that but for now, just clear the list and it will go away nicely.      disassembler_sp->GetInstructionList().Clear(); @@ -239,6 +219,12 @@ static void ReportInlineAsmError(const llvm::SMDiagnostic &diagnostic, void *Con  }  void +IRExecutionUnit::ReportSymbolLookupError(const ConstString &name) +{ +    m_failed_lookups.push_back(name); +} + +void  IRExecutionUnit::GetRunnableInfo(Error &error,                                   lldb::addr_t &func_addr,                                   lldb::addr_t &func_end) @@ -369,6 +355,33 @@ IRExecutionUnit::GetRunnableInfo(Error &error,      ReportAllocations(*m_execution_engine_ap);      WriteData(process_sp); +    if (m_failed_lookups.size()) +    { +        StreamString ss; +         +        ss.PutCString("Couldn't lookup symbols:\n"); +         +        bool emitNewLine = false; +         +        for (const ConstString &failed_lookup : m_failed_lookups) +        { +            if (emitNewLine) +                ss.PutCString("\n"); +            emitNewLine = true; +            ss.PutCString("  "); +            ss.PutCString(Mangled(failed_lookup).GetDemangledName().AsCString()); +        } +         +        m_failed_lookups.clear(); +         +        error.SetErrorString(ss.GetData()); +         +        return; +    } +     +    m_function_load_addr = LLDB_INVALID_ADDRESS; +    m_function_end_load_addr = LLDB_INVALID_ADDRESS; +      for (JittedFunction &jitted_function : m_jitted_functions)      {          jitted_function.m_remote_addr = GetRemoteAddressForLocal (jitted_function.m_local_addr); @@ -604,6 +617,114 @@ IRExecutionUnit::MemoryManager::allocateDataSection(uintptr_t Size,      return return_value;  } +uint64_t +IRExecutionUnit::MemoryManager::getSymbolAddress(const std::string &Name) +{ +    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); +     +    SymbolContextList sc_list; +     +    ExecutionContextScope *exe_scope = m_parent.GetBestExecutionContextScope(); +     +    lldb::TargetSP target_sp = exe_scope->CalculateTarget(); +     +    const char *name = Name.c_str(); +     +    ConstString bare_name_cs(name); +    ConstString name_cs; +     +    if (name[0] == '_') +        name_cs = ConstString(name + 1); +     +    if (!target_sp) +    { +        if (log) +            log->Printf("IRExecutionUnit::getSymbolAddress(Name=\"%s\") = <no target>", +                        Name.c_str()); +         +        m_parent.ReportSymbolLookupError(name_cs); +         +        return 0xbad0bad0; +    } +     +    uint32_t num_matches = 0; +    lldb::ProcessSP process_sp = exe_scope->CalculateProcess(); +     +    if (!name_cs.IsEmpty()) +    { +        target_sp->GetImages().FindSymbolsWithNameAndType(name_cs, lldb::eSymbolTypeAny, sc_list); +        num_matches = sc_list.GetSize(); +    } +     +    if (!num_matches) +    { +        target_sp->GetImages().FindSymbolsWithNameAndType(bare_name_cs, lldb::eSymbolTypeAny, sc_list); +        num_matches = sc_list.GetSize(); +    } +         +    lldb::addr_t symbol_load_addr = LLDB_INVALID_ADDRESS; +     +    for (uint32_t i=0; i<num_matches && (symbol_load_addr == 0 || symbol_load_addr == LLDB_INVALID_ADDRESS); i++) +    { +        SymbolContext sym_ctx; +        sc_list.GetContextAtIndex(i, sym_ctx); +         +        if (sym_ctx.symbol->GetType() == lldb::eSymbolTypeUndefined) +            continue; +         +        const Address *sym_address = &sym_ctx.symbol->GetAddress(); +         +        if (!sym_address || !sym_address->IsValid()) +            continue; + +        symbol_load_addr = sym_ctx.symbol->ResolveCallableAddress(*target_sp); +         +        if (symbol_load_addr == LLDB_INVALID_ADDRESS) +        { +            symbol_load_addr = sym_ctx.symbol->GetAddress().GetLoadAddress(target_sp.get()); +        } +    } +     +    if (symbol_load_addr == LLDB_INVALID_ADDRESS && process_sp && name_cs) +    { +        // Try the Objective-C language runtime. +         +        ObjCLanguageRuntime *runtime = process_sp->GetObjCLanguageRuntime(); +         +        if (runtime) +            symbol_load_addr = runtime->LookupRuntimeSymbol(name_cs); +    } +     +    if (symbol_load_addr == LLDB_INVALID_ADDRESS) +    { +        if (log) +            log->Printf("IRExecutionUnit::getSymbolAddress(Name=\"%s\") = <not found>", +                        name); +         +        m_parent.ReportSymbolLookupError(bare_name_cs); +         +        return 0xbad0bad0; +    } +     +    if (log) +        log->Printf("IRExecutionUnit::getSymbolAddress(Name=\"%s\") = %" PRIx64, +                    name, +                    symbol_load_addr); +     +    if (symbol_load_addr == 0) +        return 0xbad00add; +     +    return symbol_load_addr; +} + +void * +IRExecutionUnit::MemoryManager::getPointerToNamedFunction(const std::string &Name, +                                                          bool AbortOnFailure) { +    assert (sizeof(void *) == 8); +     +    return (void*)getSymbolAddress(Name); +} +  lldb::addr_t  IRExecutionUnit::GetRemoteAddressForLocal (lldb::addr_t local_address)  { diff --git a/source/Expression/IRForTarget.cpp b/source/Expression/IRForTarget.cpp index 8e75c32183ec..42390b35fdde 100644 --- a/source/Expression/IRForTarget.cpp +++ b/source/Expression/IRForTarget.cpp @@ -590,7 +590,7 @@ IRForTarget::CreateResultVariable (llvm::Function &llvm_function)                                                       &result_decl->getASTContext());      } -    if (m_result_type.GetBitSize() == 0) +    if (m_result_type.GetBitSize(nullptr) == 0)      {          lldb_private::StreamString type_desc_stream;          m_result_type.DumpTypeDescription(&type_desc_stream); @@ -617,7 +617,7 @@ IRForTarget::CreateResultVariable (llvm::Function &llvm_function)      if (log)          log->Printf("Creating a new result global: \"%s\" with size 0x%" PRIx64,                      m_result_name.GetCString(), -                    m_result_type.GetByteSize()); +                    m_result_type.GetByteSize(nullptr));      // Construct a new result global and set up its metadata @@ -1518,7 +1518,7 @@ IRForTarget::MaybeHandleVariable (Value *llvm_value_ptr)              value_type = global_variable->getType();          } -        const uint64_t value_size = clang_type.GetByteSize(); +        const uint64_t value_size = clang_type.GetByteSize(nullptr);          lldb::offset_t value_alignment = (clang_type.GetTypeBitAlign() + 7ull) / 8ull;          if (log) diff --git a/source/Expression/Materializer.cpp b/source/Expression/Materializer.cpp index b11921635e5a..f1f2f99eed5e 100644 --- a/source/Expression/Materializer.cpp +++ b/source/Expression/Materializer.cpp @@ -49,7 +49,7 @@ Materializer::AddStructMember (Entity &entity)  void  Materializer::Entity::SetSizeAndAlignmentFromType (ClangASTType &type)  { -    m_size = type.GetByteSize(); +    m_size = type.GetByteSize(nullptr);      uint32_t bit_alignment = type.GetTypeBitAlign(); @@ -780,7 +780,7 @@ public:              const lldb::addr_t load_addr = process_address + m_offset; -            size_t byte_size = m_type.GetByteSize(); +            size_t byte_size = m_type.GetByteSize(nullptr);              size_t bit_align = m_type.GetTypeBitAlign();              size_t byte_align = (bit_align + 7) / 8;  | 
