diff options
Diffstat (limited to 'lldb/source')
| -rw-r--r-- | lldb/source/API/SBThread.cpp | 35 | ||||
| -rw-r--r-- | lldb/source/Host/windows/ProcessLauncherWindows.cpp | 17 | ||||
| -rw-r--r-- | lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp | 30 | ||||
| -rw-r--r-- | lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp | 4 | ||||
| -rw-r--r-- | lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h | 1 | ||||
| -rw-r--r-- | lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp | 67 | ||||
| -rw-r--r-- | lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp | 31 | ||||
| -rw-r--r-- | lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h | 3 | ||||
| -rw-r--r-- | lldb/source/Symbol/CompilerType.cpp | 10 | ||||
| -rw-r--r-- | lldb/source/Symbol/Type.cpp | 4 | ||||
| -rw-r--r-- | lldb/source/ValueObject/ValueObject.cpp | 6 | 
11 files changed, 140 insertions, 68 deletions
| diff --git a/lldb/source/API/SBThread.cpp b/lldb/source/API/SBThread.cpp index 4e4aa48..f58a1b5 100644 --- a/lldb/source/API/SBThread.cpp +++ b/lldb/source/API/SBThread.cpp @@ -239,11 +239,34 @@ SBThread::GetStopReasonExtendedBacktraces(InstrumentationRuntimeType type) {    return threads;  } -size_t SBThread::GetStopDescription(char *dst, size_t dst_len) { -  LLDB_INSTRUMENT_VA(this, dst, dst_len); +bool SBThread::GetStopDescription(lldb::SBStream &stream) const { +  LLDB_INSTRUMENT_VA(this, stream); + +  if (!m_opaque_sp) +    return false; + +  llvm::Expected<StoppedExecutionContext> exe_ctx = +      GetStoppedExecutionContext(m_opaque_sp); +  if (!exe_ctx) { +    LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}"); +    return false; +  } + +  if (!exe_ctx->HasThreadScope()) +    return false; + +  Stream &strm = stream.ref(); +  const std::string stop_desc = exe_ctx->GetThreadPtr()->GetStopDescription(); +  strm.PutCString(stop_desc); + +  return true; +} + +size_t SBThread::GetStopDescription(char *dst_or_null, size_t dst_len) { +  LLDB_INSTRUMENT_VA(this, dst_or_null, dst_len); -  if (dst) -    *dst = 0; +  if (dst_or_null) +    *dst_or_null = 0;    llvm::Expected<StoppedExecutionContext> exe_ctx =        GetStoppedExecutionContext(m_opaque_sp); @@ -259,8 +282,8 @@ size_t SBThread::GetStopDescription(char *dst, size_t dst_len) {    if (thread_stop_desc.empty())      return 0; -  if (dst) -    return ::snprintf(dst, dst_len, "%s", thread_stop_desc.c_str()) + 1; +  if (dst_or_null) +    return ::snprintf(dst_or_null, dst_len, "%s", thread_stop_desc.c_str()) + 1;    // NULL dst passed in, return the length needed to contain the    // description. diff --git a/lldb/source/Host/windows/ProcessLauncherWindows.cpp b/lldb/source/Host/windows/ProcessLauncherWindows.cpp index e1b4b7e..f5adada 100644 --- a/lldb/source/Host/windows/ProcessLauncherWindows.cpp +++ b/lldb/source/Host/windows/ProcessLauncherWindows.cpp @@ -16,7 +16,6 @@  #include "llvm/Support/Program.h"  #include <string> -#include <unordered_set>  #include <vector>  using namespace lldb; @@ -92,13 +91,13 @@ ProcessLauncherWindows::LaunchProcess(const ProcessLaunchInfo &launch_info,    startupinfo.hStdOutput =        stdout_handle ? stdout_handle : ::GetStdHandle(STD_OUTPUT_HANDLE); -  std::unordered_set<HANDLE> inherited_handles; +  std::vector<HANDLE> inherited_handles;    if (startupinfo.hStdError) -    inherited_handles.insert(startupinfo.hStdError); +    inherited_handles.push_back(startupinfo.hStdError);    if (startupinfo.hStdInput) -    inherited_handles.insert(startupinfo.hStdInput); +    inherited_handles.push_back(startupinfo.hStdInput);    if (startupinfo.hStdOutput) -    inherited_handles.insert(startupinfo.hStdOutput); +    inherited_handles.push_back(startupinfo.hStdOutput);    SIZE_T attributelist_size = 0;    InitializeProcThreadAttributeList(/*lpAttributeList=*/nullptr, @@ -121,15 +120,13 @@ ProcessLauncherWindows::LaunchProcess(const ProcessLaunchInfo &launch_info,      const FileAction *act = launch_info.GetFileActionAtIndex(i);      if (act->GetAction() == FileAction::eFileActionDuplicate &&          act->GetFD() == act->GetActionArgument()) -      inherited_handles.insert(reinterpret_cast<HANDLE>(act->GetFD())); +      inherited_handles.push_back(reinterpret_cast<HANDLE>(act->GetFD()));    }    if (!inherited_handles.empty()) { -    std::vector<HANDLE> handles(inherited_handles.begin(), -                                inherited_handles.end());      if (!UpdateProcThreadAttribute(              startupinfoex.lpAttributeList, /*dwFlags=*/0, -            PROC_THREAD_ATTRIBUTE_HANDLE_LIST, handles.data(), -            handles.size() * sizeof(HANDLE), +            PROC_THREAD_ATTRIBUTE_HANDLE_LIST, inherited_handles.data(), +            inherited_handles.size() * sizeof(HANDLE),              /*lpPreviousValue=*/nullptr, /*lpReturnSize=*/nullptr)) {        error = Status(::GetLastError(), eErrorTypeWin32);        return HostProcess(); diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index 9cdb846..c8e520d 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -1674,6 +1674,10 @@ void ObjectFileMachO::ProcessSegmentCommand(    uint32_t segment_sect_idx;    const lldb::user_id_t first_segment_sectID = context.NextSectionIdx + 1; +  // 64 bit mach-o files have sections with 32 bit file offsets. If any section +  // data end will exceed UINT32_MAX, then we need to do some bookkeeping to +  // ensure we can access this data correctly. +  uint64_t section_offset_adjust = 0;    const uint32_t num_u32s = load_cmd.cmd == LC_SEGMENT ? 7 : 8;    for (segment_sect_idx = 0; segment_sect_idx < load_cmd.nsects;         ++segment_sect_idx) { @@ -1697,6 +1701,16 @@ void ObjectFileMachO::ProcessSegmentCommand(      // isn't stored in the abstracted Sections.      m_mach_sections.push_back(sect64); +    // Make sure we can load sections in mach-o files where some sections cross +    // a 4GB boundary. llvm::MachO::section_64 have only 32 bit file offsets +    // for the file offset of the section contents, so we need to track and +    // sections that overflow and adjust the offsets accordingly. +    const uint64_t section_file_offset = +        (uint64_t)sect64.offset + section_offset_adjust; +    const uint64_t end_section_offset = (uint64_t)sect64.offset + sect64.size; +    if (end_section_offset >= UINT32_MAX) +      section_offset_adjust += end_section_offset & 0xFFFFFFFF00000000ull; +      if (add_section) {        ConstString section_name(            sect64.sectname, strnlen(sect64.sectname, sizeof(sect64.sectname))); @@ -1736,13 +1750,13 @@ void ObjectFileMachO::ProcessSegmentCommand(            }            // Grow the section size as needed. -          if (sect64.offset) { +          if (section_file_offset) {              const lldb::addr_t segment_min_file_offset =                  segment->GetFileOffset();              const lldb::addr_t segment_max_file_offset =                  segment_min_file_offset + segment->GetFileSize(); -            const lldb::addr_t section_min_file_offset = sect64.offset; +            const lldb::addr_t section_min_file_offset = section_file_offset;              const lldb::addr_t section_max_file_offset =                  section_min_file_offset + sect64.size;              const lldb::addr_t new_file_offset = @@ -1769,10 +1783,10 @@ void ObjectFileMachO::ProcessSegmentCommand(                // other sections.                sect64.addr, // File VM address == addresses as they are                // found in the object file -              sect64.size,   // VM size in bytes of this section -              sect64.offset, // Offset to the data for this section in +              sect64.size,         // VM size in bytes of this section +              section_file_offset, // Offset to the data for this section in                // the file -              sect64.offset ? sect64.size : 0, // Size in bytes of +              section_file_offset ? sect64.size : 0, // Size in bytes of                // this section as                // found in the file                sect64.align, @@ -1792,14 +1806,14 @@ void ObjectFileMachO::ProcessSegmentCommand(        SectionSP section_sp(new Section(            segment_sp, module_sp, this, ++context.NextSectionIdx, section_name,            sect_type, sect64.addr - segment_sp->GetFileAddress(), sect64.size, -          sect64.offset, sect64.offset == 0 ? 0 : sect64.size, sect64.align, -          sect64.flags)); +          section_file_offset, section_file_offset == 0 ? 0 : sect64.size, +          sect64.align, sect64.flags));        // Set the section to be encrypted to match the segment        bool section_is_encrypted = false;        if (!segment_is_encrypted && load_cmd.filesize != 0)          section_is_encrypted = context.EncryptedRanges.FindEntryThatContains( -                                   sect64.offset) != nullptr; +                                   section_file_offset) != nullptr;        section_sp->SetIsEncrypted(segment_is_encrypted || section_is_encrypted);        section_sp->SetPermissions(segment_permissions); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp index 36bc176..c049829 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -450,6 +450,10 @@ ParsedDWARFTypeAttributes::ParsedDWARFTypeAttributes(const DWARFDIE &die) {        byte_size = form_value.Unsigned();        break; +    case DW_AT_bit_size: +      data_bit_size = form_value.Unsigned(); +      break; +      case DW_AT_alignment:        alignment = form_value.Unsigned();        break; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h index da58f4c..f5f7071 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h @@ -574,6 +574,7 @@ struct ParsedDWARFTypeAttributes {    lldb_private::plugin::dwarf::DWARFFormValue type;    lldb::LanguageType class_language = lldb::eLanguageTypeUnknown;    std::optional<uint64_t> byte_size; +  std::optional<uint64_t> data_bit_size;    std::optional<uint64_t> alignment;    size_t calling_convention = llvm::dwarf::DW_CC_normal;    uint32_t bit_stride = 0; diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp index e76b7a3..aaec160 100644 --- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp +++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp @@ -1130,7 +1130,35 @@ void SymbolFileNativePDB::AddSymbols(Symtab &symtab) {    if (!section_list)      return; -  for (auto pid : m_index->publics().getPublicsTable()) { +  PublicSym32 last_sym; +  size_t last_sym_idx = 0; +  lldb::SectionSP section_sp; + +  // To estimate the size of a symbol, we use the difference to the next symbol. +  // If there's no next symbol or the section/segment changed, the symbol will +  // take the remaining space. The estimate can be too high in case there's +  // padding between symbols. This similar to the algorithm used by the DIA +  // SDK. +  auto finish_last_symbol = [&](const PublicSym32 *next) { +    if (!section_sp) +      return; +    Symbol *last = symtab.SymbolAtIndex(last_sym_idx); +    if (!last) +      return; + +    if (next && last_sym.Segment == next->Segment) { +      assert(last_sym.Offset <= next->Offset); +      last->SetByteSize(next->Offset - last_sym.Offset); +    } else { +      // the last symbol was the last in its section +      assert(section_sp->GetByteSize() >= last_sym.Offset); +      assert(!next || next->Segment > last_sym.Segment); +      last->SetByteSize(section_sp->GetByteSize() - last_sym.Offset); +    } +  }; + +  // The address map is sorted by the address of a symbol. +  for (auto pid : m_index->publics().getAddressMap()) {      PdbGlobalSymId global{pid, true};      CVSymbol sym = m_index->ReadSymbolRecord(global);      auto kind = sym.kind(); @@ -1138,8 +1166,11 @@ void SymbolFileNativePDB::AddSymbols(Symtab &symtab) {        continue;      PublicSym32 pub =          llvm::cantFail(SymbolDeserializer::deserializeAs<PublicSym32>(sym)); +    finish_last_symbol(&pub); + +    if (!section_sp || last_sym.Segment != pub.Segment) +      section_sp = section_list->FindSectionByID(pub.Segment); -    auto section_sp = section_list->FindSectionByID(pub.Segment);      if (!section_sp)        continue; @@ -1148,20 +1179,24 @@ void SymbolFileNativePDB::AddSymbols(Symtab &symtab) {          (pub.Flags & PublicSymFlags::Code) != PublicSymFlags::None)        type = eSymbolTypeCode; -    symtab.AddSymbol(Symbol(/*symID=*/pid, -                            /*name=*/pub.Name, -                            /*type=*/type, -                            /*external=*/true, -                            /*is_debug=*/true, -                            /*is_trampoline=*/false, -                            /*is_artificial=*/false, -                            /*section_sp=*/section_sp, -                            /*value=*/pub.Offset, -                            /*size=*/0, -                            /*size_is_valid=*/false, -                            /*contains_linker_annotations=*/false, -                            /*flags=*/0)); -  } +    last_sym_idx = +        symtab.AddSymbol(Symbol(/*symID=*/pid, +                                /*name=*/pub.Name, +                                /*type=*/type, +                                /*external=*/true, +                                /*is_debug=*/true, +                                /*is_trampoline=*/false, +                                /*is_artificial=*/false, +                                /*section_sp=*/section_sp, +                                /*value=*/pub.Offset, +                                /*size=*/0, +                                /*size_is_valid=*/false, +                                /*contains_linker_annotations=*/false, +                                /*flags=*/0)); +    last_sym = pub; +  } + +  finish_last_symbol(nullptr);  }  size_t SymbolFileNativePDB::ParseFunctions(CompileUnit &comp_unit) { diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp index 6ec054d..4ec987c 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -3965,9 +3965,9 @@ TypeSystemClang::GetTypeInfo(lldb::opaque_compiler_type_t type,      if (complex_type) {        clang::QualType complex_element_type(complex_type->getElementType());        if (complex_element_type->isIntegerType()) -        complex_type_flags |= eTypeIsFloat; -      else if (complex_element_type->isFloatingType())          complex_type_flags |= eTypeIsInteger; +      else if (complex_element_type->isFloatingType()) +        complex_type_flags |= eTypeIsFloat;      }      return complex_type_flags;    } break; @@ -4062,12 +4062,17 @@ TypeSystemClang::GetTypeInfo(lldb::opaque_compiler_type_t type,      uint32_t vector_type_flags = eTypeHasChildren | eTypeIsVector;      const clang::VectorType *vector_type = llvm::dyn_cast<clang::VectorType>(          qual_type->getCanonicalTypeInternal()); -    if (vector_type) { -      if (vector_type->isIntegerType()) -        vector_type_flags |= eTypeIsFloat; -      else if (vector_type->isFloatingType()) -        vector_type_flags |= eTypeIsInteger; -    } +    if (!vector_type) +      return 0; + +    QualType element_type = vector_type->getElementType(); +    if (element_type.isNull()) +      return 0; + +    if (element_type->isIntegerType()) +      vector_type_flags |= eTypeIsInteger; +    else if (element_type->isFloatingType()) +      vector_type_flags |= eTypeIsFloat;      return vector_type_flags;    }    default: @@ -4864,12 +4869,10 @@ TypeSystemClang::GetTypeBitAlign(lldb::opaque_compiler_type_t type,    return {};  } -lldb::Encoding TypeSystemClang::GetEncoding(lldb::opaque_compiler_type_t type, -                                            uint64_t &count) { +lldb::Encoding TypeSystemClang::GetEncoding(lldb::opaque_compiler_type_t type) {    if (!type)      return lldb::eEncodingInvalid; -  count = 1;    clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));    switch (qual_type->getTypeClass()) { @@ -4903,7 +4906,6 @@ lldb::Encoding TypeSystemClang::GetEncoding(lldb::opaque_compiler_type_t type,    case clang::Type::DependentVector:    case clang::Type::ExtVector:    case clang::Type::Vector: -    // TODO: Set this to more than one???      break;    case clang::Type::BitInt: @@ -5104,11 +5106,10 @@ lldb::Encoding TypeSystemClang::GetEncoding(lldb::opaque_compiler_type_t type,        const clang::ComplexType *complex_type =            qual_type->getAsComplexIntegerType();        if (complex_type) -        encoding = GetType(complex_type->getElementType()).GetEncoding(count); +        encoding = GetType(complex_type->getElementType()).GetEncoding();        else          encoding = lldb::eEncodingSint;      } -    count = 2;      return encoding;    } @@ -5165,7 +5166,7 @@ lldb::Encoding TypeSystemClang::GetEncoding(lldb::opaque_compiler_type_t type,    case clang::Type::SubstBuiltinTemplatePack:      break;    } -  count = 0; +    return lldb::eEncodingInvalid;  } diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h index 9e0a542..11107c0 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h @@ -837,8 +837,7 @@ public:    GetBitSize(lldb::opaque_compiler_type_t type,               ExecutionContextScope *exe_scope) override; -  lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type, -                             uint64_t &count) override; +  lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type) override;    lldb::Format GetFormat(lldb::opaque_compiler_type_t type) override; diff --git a/lldb/source/Symbol/CompilerType.cpp b/lldb/source/Symbol/CompilerType.cpp index 62c0ddf..73da312 100644 --- a/lldb/source/Symbol/CompilerType.cpp +++ b/lldb/source/Symbol/CompilerType.cpp @@ -793,10 +793,10 @@ CompilerType::GetTypeBitAlign(ExecutionContextScope *exe_scope) const {    return {};  } -lldb::Encoding CompilerType::GetEncoding(uint64_t &count) const { +lldb::Encoding CompilerType::GetEncoding() const {    if (IsValid())      if (auto type_system_sp = GetTypeSystem()) -      return type_system_sp->GetEncoding(m_type, count); +      return type_system_sp->GetEncoding(m_type);    return lldb::eEncodingInvalid;  } @@ -1093,10 +1093,10 @@ bool CompilerType::GetValueAsScalar(const lldb_private::DataExtractor &data,    if (IsAggregateType()) {      return false; // Aggregate types don't have scalar values    } else { -    uint64_t count = 0; -    lldb::Encoding encoding = GetEncoding(count); +    // FIXME: check that type is scalar instead of checking encoding? +    lldb::Encoding encoding = GetEncoding(); -    if (encoding == lldb::eEncodingInvalid || count != 1) +    if (encoding == lldb::eEncodingInvalid || (GetTypeInfo() & eTypeIsComplex))        return false;      auto byte_size_or_err = GetByteSize(exe_scope); diff --git a/lldb/source/Symbol/Type.cpp b/lldb/source/Symbol/Type.cpp index 952b2bd..0c3246d 100644 --- a/lldb/source/Symbol/Type.cpp +++ b/lldb/source/Symbol/Type.cpp @@ -531,9 +531,9 @@ lldb::TypeSP Type::GetTypedefType() {  lldb::Format Type::GetFormat() { return GetForwardCompilerType().GetFormat(); } -lldb::Encoding Type::GetEncoding(uint64_t &count) { +lldb::Encoding Type::GetEncoding() {    // Make sure we resolve our type if it already hasn't been. -  return GetForwardCompilerType().GetEncoding(count); +  return GetForwardCompilerType().GetEncoding();  }  bool Type::ReadFromMemory(ExecutionContext *exe_ctx, lldb::addr_t addr, diff --git a/lldb/source/ValueObject/ValueObject.cpp b/lldb/source/ValueObject/ValueObject.cpp index 38b9f77..aeea32f 100644 --- a/lldb/source/ValueObject/ValueObject.cpp +++ b/lldb/source/ValueObject/ValueObject.cpp @@ -790,8 +790,7 @@ bool ValueObject::SetData(DataExtractor &data, Status &error) {      return false;    } -  uint64_t count = 0; -  const Encoding encoding = GetCompilerType().GetEncoding(count); +  const Encoding encoding = GetCompilerType().GetEncoding();    const size_t byte_size = llvm::expectedToOptional(GetByteSize()).value_or(0); @@ -1669,8 +1668,7 @@ bool ValueObject::SetValueFromCString(const char *value_str, Status &error) {      return false;    } -  uint64_t count = 0; -  const Encoding encoding = GetCompilerType().GetEncoding(count); +  const Encoding encoding = GetCompilerType().GetEncoding();    const size_t byte_size = llvm::expectedToOptional(GetByteSize()).value_or(0); | 
