From gclayton at apple.com Wed Dec 28 16:24:05 2011 From: gclayton at apple.com (Greg Clayton) Date: Wed, 28 Dec 2011 22:24:05 -0000 Subject: [Lldb-commits] [lldb] r147324 - in /lldb/trunk: include/lldb/Symbol/Symbol.h include/lldb/Symbol/Variable.h source/Symbol/Symbol.cpp source/Symbol/Symtab.cpp Message-ID: <20111228222405.9C49C2A6C12C@llvm.org> Author: gclayton Date: Wed Dec 28 16:24:04 2011 New Revision: 147324 URL: http://llvm.org/viewvc/llvm-project?rev=147324&view=rev Log: Save a little bit of memory that was being reserved in a UniqueCStringMap vector that can be sized to fit. Modified: lldb/trunk/include/lldb/Symbol/Symbol.h lldb/trunk/include/lldb/Symbol/Variable.h lldb/trunk/source/Symbol/Symbol.cpp lldb/trunk/source/Symbol/Symtab.cpp Modified: lldb/trunk/include/lldb/Symbol/Symbol.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Symbol.h?rev=147324&r1=147323&r2=147324&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/Symbol.h (original) +++ lldb/trunk/include/lldb/Symbol/Symbol.h Wed Dec 28 16:24:04 2011 @@ -211,7 +211,6 @@ m_is_external:1, // non-zero if this symbol is globally visible m_size_is_sibling:1, // m_size contains the index of this symbol's sibling m_size_is_synthesized:1,// non-zero if this symbol's size was calculated using a delta between this symbol and the next - m_searched_for_function:1,// non-zero if we have looked for the function associated with this symbol already. m_type:8; uint32_t m_flags; // A copy of the flags from the original symbol table, the ObjectFile plug-in can interpret these AddressRange m_addr_range; // Contains the value, or the section offset address when the value is an address in a section, and the size (if any) Modified: lldb/trunk/include/lldb/Symbol/Variable.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Variable.h?rev=147324&r1=147323&r2=147324&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/Variable.h (original) +++ lldb/trunk/include/lldb/Symbol/Variable.h Wed Dec 28 16:24:04 2011 @@ -159,7 +159,7 @@ protected: ConstString m_name; // The basename of the variable (no namespaces) - Mangled m_mangled; // The mangled name of hte variable + Mangled m_mangled; // The mangled name of the variable lldb::SymbolFileTypeSP m_symfile_type_sp; // The type pointer of the variable (int, struct, class, etc) lldb::ValueType m_scope; // global, parameter, local SymbolContextScope *m_owner_scope; // The symbol file scope that this variable was defined in Modified: lldb/trunk/source/Symbol/Symbol.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Symbol.cpp?rev=147324&r1=147323&r2=147324&view=diff ============================================================================== --- lldb/trunk/source/Symbol/Symbol.cpp (original) +++ lldb/trunk/source/Symbol/Symbol.cpp Wed Dec 28 16:24:04 2011 @@ -30,7 +30,6 @@ m_is_external (false), m_size_is_sibling (false), m_size_is_synthesized (false), - m_searched_for_function (false), m_type (eSymbolTypeInvalid), m_flags (), m_addr_range () @@ -62,7 +61,6 @@ m_is_external (external), m_size_is_sibling (false), m_size_is_synthesized (false), - m_searched_for_function (false), m_type (type), m_flags (flags), m_addr_range (section, offset, size) @@ -92,7 +90,6 @@ m_is_external (external), m_size_is_sibling (false), m_size_is_synthesized (false), - m_searched_for_function (false), m_type (type), m_flags (flags), m_addr_range (range) @@ -110,7 +107,6 @@ m_is_external (rhs.m_is_external), m_size_is_sibling (rhs.m_size_is_sibling), m_size_is_synthesized (false), - m_searched_for_function (false), m_type (rhs.m_type), m_flags (rhs.m_flags), m_addr_range (rhs.m_addr_range) @@ -132,7 +128,6 @@ m_is_external = rhs.m_is_external; m_size_is_sibling = rhs.m_size_is_sibling; m_size_is_synthesized = rhs.m_size_is_sibling; - m_searched_for_function = rhs.m_searched_for_function; m_type = rhs.m_type; m_flags = rhs.m_flags; m_addr_range = rhs.m_addr_range; @@ -152,7 +147,6 @@ m_is_external = false; m_size_is_sibling = false; m_size_is_synthesized = false; - m_searched_for_function = false; m_type = eSymbolTypeInvalid; m_flags = 0; m_addr_range.Clear(); Modified: lldb/trunk/source/Symbol/Symtab.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Symtab.cpp?rev=147324&r1=147323&r2=147324&view=diff ============================================================================== --- lldb/trunk/source/Symbol/Symtab.cpp (original) +++ lldb/trunk/source/Symbol/Symtab.cpp Wed Dec 28 16:24:04 2011 @@ -322,6 +322,7 @@ } m_name_to_index.Sort(); + m_name_to_index.SizeToFit(); } } From gclayton at apple.com Wed Dec 28 16:34:32 2011 From: gclayton at apple.com (Greg Clayton) Date: Wed, 28 Dec 2011 22:34:32 -0000 Subject: [Lldb-commits] [lldb] r147325 - /lldb/trunk/scripts/build-lldb-llvm-clang Message-ID: <20111228223432.F181A2A6C12C@llvm.org> Author: gclayton Date: Wed Dec 28 16:34:32 2011 New Revision: 147325 URL: http://llvm.org/viewvc/llvm-project?rev=147325&view=rev Log: Cleaned up the usage to show the BuildAndIntegration configuration. Modified: lldb/trunk/scripts/build-lldb-llvm-clang Modified: lldb/trunk/scripts/build-lldb-llvm-clang URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/build-lldb-llvm-clang?rev=147325&r1=147324&r2=147325&view=diff ============================================================================== --- lldb/trunk/scripts/build-lldb-llvm-clang (original) +++ lldb/trunk/scripts/build-lldb-llvm-clang Wed Dec 28 16:34:32 2011 @@ -1,15 +1,15 @@ #!/bin/sh -x # Usage: -# build-lldb-llvm-clang [Debug|Release] -# build-lldb-llvm-clang [Debug|Release] +# build-lldb-llvm-clang [Debug|Release|BuildAndIntegration] +# build-lldb-llvm-clang [Debug|Release|BuildAndIntegration] LLVM_REVISION=$1 CLANG_REVISION=$2 LLVM_CONFIGURATION=$3 if [ "$LLVM_REVISION" = "" ]; then - echo "Usage:\n build-lldb-llvm-clang [ Debug|Release]" + echo "Usage:\n build-lldb-llvm-clang [ Debug|Release||BuildAndIntegration]" exit 1 fi From gclayton at apple.com Wed Dec 28 18:05:27 2011 From: gclayton at apple.com (Greg Clayton) Date: Thu, 29 Dec 2011 00:05:27 -0000 Subject: [Lldb-commits] [lldb] r147330 - in /lldb/trunk: include/lldb/Symbol/DWARFCallFrameInfo.h source/Symbol/DWARFCallFrameInfo.cpp Message-ID: <20111229000527.2E3032A6C12C@llvm.org> Author: gclayton Date: Wed Dec 28 18:05:26 2011 New Revision: 147330 URL: http://llvm.org/viewvc/llvm-project?rev=147330&view=rev Log: Centralize the code the reads the CFI so that we always log. Modified: lldb/trunk/include/lldb/Symbol/DWARFCallFrameInfo.h lldb/trunk/source/Symbol/DWARFCallFrameInfo.cpp Modified: lldb/trunk/include/lldb/Symbol/DWARFCallFrameInfo.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/DWARFCallFrameInfo.h?rev=147330&r1=147329&r2=147330&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/DWARFCallFrameInfo.h (original) +++ lldb/trunk/include/lldb/Symbol/DWARFCallFrameInfo.h Wed Dec 28 18:05:26 2011 @@ -113,6 +113,9 @@ const CIE* GetCIE(dw_offset_t cie_offset); + + void + GetCFIData(); ObjectFile& m_objfile; lldb::SectionSP m_section; Modified: lldb/trunk/source/Symbol/DWARFCallFrameInfo.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/DWARFCallFrameInfo.cpp?rev=147330&r1=147329&r2=147330&view=diff ============================================================================== --- lldb/trunk/source/Symbol/DWARFCallFrameInfo.cpp (original) +++ lldb/trunk/source/Symbol/DWARFCallFrameInfo.cpp Wed Dec 28 18:05:26 2011 @@ -118,10 +118,7 @@ CIESP cie_sp(new CIE(cie_offset)); dw_offset_t offset = cie_offset; if (m_cfi_data_initialized == false) - { - m_section->ReadSectionDataFromObjectFile (&m_objfile, m_cfi_data); - m_cfi_data_initialized = true; - } + GetCFIData(); const uint32_t length = m_cfi_data.GetU32(&offset); const dw_offset_t cie_id = m_cfi_data.GetU32(&offset); const dw_offset_t end_offset = cie_offset + length + 4; @@ -274,6 +271,18 @@ return cie_sp; } +void +DWARFCallFrameInfo::GetCFIData() +{ + if (m_cfi_data_initialized == false) + { + LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND)); + if (log) + m_objfile.GetModule()->LogMessage(log.get(), "Reading EH frame info"); + m_section->ReadSectionDataFromObjectFile (&m_objfile, m_cfi_data); + m_cfi_data_initialized = true; + } +} // Scan through the eh_frame or debug_frame section looking for FDEs and noting the start/end addresses // of the functions and a pointer back to the function's FDE for later expansion. // Internalize CIEs as we come across them. @@ -289,15 +298,7 @@ dw_offset_t offset = 0; if (m_cfi_data_initialized == false) - { - LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND)); - if (log) - { - log->Printf ("Reading eh_frame information for %s", m_objfile.GetFileSpec().GetFilename().GetCString()); - } - m_section->ReadSectionDataFromObjectFile (&m_objfile, m_cfi_data); - m_cfi_data_initialized = true; - } + GetCFIData(); while (m_cfi_data.ValidOffsetForDataOfSize (offset, 8)) { const dw_offset_t current_entry = offset; @@ -350,10 +351,7 @@ return false; if (m_cfi_data_initialized == false) - { - m_section->ReadSectionDataFromObjectFile (&m_objfile, m_cfi_data); - m_cfi_data_initialized = true; - } + GetCFIData(); uint32_t length = m_cfi_data.GetU32 (&offset); dw_offset_t cie_offset = m_cfi_data.GetU32 (&offset); From gclayton at apple.com Wed Dec 28 19:26:57 2011 From: gclayton at apple.com (Greg Clayton) Date: Thu, 29 Dec 2011 01:26:57 -0000 Subject: [Lldb-commits] [lldb] r147332 - in /lldb/trunk: include/lldb/Core/Scalar.h source/Core/Scalar.cpp source/Core/ValueObject.cpp test/lang/objc/objc-ivar-offsets/TestObjCIvarOffsets.py Message-ID: <20111229012657.3BD722A6C12C@llvm.org> Author: gclayton Date: Wed Dec 28 19:26:56 2011 New Revision: 147332 URL: http://llvm.org/viewvc/llvm-project?rev=147332&view=rev Log: Fixed SBValue::GetValueAsUnsigned() and SBValue::GetValueAsSigned() calls to work for bitfields. Modified: lldb/trunk/include/lldb/Core/Scalar.h lldb/trunk/source/Core/Scalar.cpp lldb/trunk/source/Core/ValueObject.cpp lldb/trunk/test/lang/objc/objc-ivar-offsets/TestObjCIvarOffsets.py Modified: lldb/trunk/include/lldb/Core/Scalar.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Scalar.h?rev=147332&r1=147331&r2=147332&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/Scalar.h (original) +++ lldb/trunk/include/lldb/Core/Scalar.h Wed Dec 28 19:26:56 2011 @@ -57,6 +57,10 @@ bool SignExtend (uint32_t bit_pos); + bool + ExtractBitfield (uint32_t bit_size, + uint32_t bit_offset); + size_t GetByteSize() const; Modified: lldb/trunk/source/Core/Scalar.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Scalar.cpp?rev=147332&r1=147331&r2=147332&view=diff ============================================================================== --- lldb/trunk/source/Core/Scalar.cpp (original) +++ lldb/trunk/source/Core/Scalar.cpp Wed Dec 28 19:26:56 2011 @@ -17,6 +17,8 @@ #include "lldb/Core/DataExtractor.h" #include "lldb/Host/Endian.h" +#include "Plugins/Process/Utility/InstructionUtils.h" + using namespace lldb; using namespace lldb_private; @@ -2018,6 +2020,85 @@ } bool +Scalar::ExtractBitfield (uint32_t bit_size, + uint32_t bit_offset) +{ + if (bit_size == 0) + return true; + + uint32_t msbit = bit_offset + bit_size - 1; + uint32_t lsbit = bit_offset; + switch (m_type) + { + default: + case Scalar::e_void: + break; + + case e_float: + if (sizeof(m_data.flt) == sizeof(int)) + m_data.sint = SignedBits (m_data.sint, msbit, lsbit); + else if (sizeof(m_data.flt) == sizeof(unsigned long)) + m_data.slong = SignedBits (m_data.slong, msbit, lsbit); + else if (sizeof(m_data.flt) == sizeof(unsigned long long)) + m_data.slonglong = SignedBits (m_data.slonglong, msbit, lsbit); + else + return false; + return true; + + case e_double: + if (sizeof(m_data.dbl) == sizeof(int)) + m_data.sint = SignedBits (m_data.sint, msbit, lsbit); + else if (sizeof(m_data.dbl) == sizeof(unsigned long)) + m_data.slong = SignedBits (m_data.slong, msbit, lsbit); + else if (sizeof(m_data.dbl) == sizeof(unsigned long long)) + m_data.slonglong = SignedBits (m_data.slonglong, msbit, lsbit); + else + return false; + return true; + + case e_long_double: + if (sizeof(m_data.ldbl) == sizeof(int)) + m_data.sint = SignedBits (m_data.sint, msbit, lsbit); + else if (sizeof(m_data.ldbl) == sizeof(unsigned long)) + m_data.slong = SignedBits (m_data.slong, msbit, lsbit); + else if (sizeof(m_data.ldbl) == sizeof(unsigned long long)) + m_data.slonglong = SignedBits (m_data.slonglong, msbit, lsbit); + else + return false; + return true; + + case Scalar::e_sint: + m_data.sint = SignedBits (m_data.sint, msbit, lsbit); + return true; + + case Scalar::e_uint: + m_data.uint = UnsignedBits (m_data.uint, msbit, lsbit); + return true; + + case Scalar::e_slong: + m_data.slong = SignedBits (m_data.slong, msbit, lsbit); + return true; + + case Scalar::e_ulong: + m_data.ulong = SignedBits (m_data.ulong, msbit, lsbit); + return true; + + case Scalar::e_slonglong: + m_data.slonglong = SignedBits (m_data.slonglong, msbit, lsbit); + return true; + + case Scalar::e_ulonglong: + m_data.ulonglong = SignedBits (m_data.ulonglong, msbit, lsbit); + return true; + } + return false; +} + + + + + +bool lldb_private::operator== (const Scalar& lhs, const Scalar& rhs) { // If either entry is void then we can just compare the types Modified: lldb/trunk/source/Core/ValueObject.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=147332&r1=147331&r2=147332&view=diff ============================================================================== --- lldb/trunk/source/Core/ValueObject.cpp (original) +++ lldb/trunk/source/Core/ValueObject.cpp Wed Dec 28 19:26:56 2011 @@ -359,10 +359,15 @@ exe_scope->CalculateExecutionContext(exe_ctx); Value tmp_value(m_value); scalar = tmp_value.ResolveValue(&exe_ctx, GetClangAST ()); - return scalar.IsValid(); + if (scalar.IsValid()) + { + const uint32_t bitfield_bit_size = GetBitfieldBitSize(); + if (bitfield_bit_size) + return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset()); + return true; + } } - else - return false; + return false; } bool Modified: lldb/trunk/test/lang/objc/objc-ivar-offsets/TestObjCIvarOffsets.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/objc/objc-ivar-offsets/TestObjCIvarOffsets.py?rev=147332&r1=147331&r2=147332&view=diff ============================================================================== --- lldb/trunk/test/lang/objc/objc-ivar-offsets/TestObjCIvarOffsets.py (original) +++ lldb/trunk/test/lang/objc/objc-ivar-offsets/TestObjCIvarOffsets.py Wed Dec 28 19:26:56 2011 @@ -80,9 +80,9 @@ self.assertTrue (flag2_value == 7) # GetValueAsUnsigned fails for bit-fields: -# flag2_value = mine_flag2.GetValueAsUnsigned (error) -# self.assertTrue (error.Success()) -# self.assertTrue (flag2_value == 7) + flag2_value = mine_flag2.GetValueAsUnsigned (error) + self.assertTrue (error.Success()) + self.assertTrue (flag2_value == 7) if __name__ == '__main__': import atexit From gclayton at apple.com Wed Dec 28 20:58:31 2011 From: gclayton at apple.com (Greg Clayton) Date: Thu, 29 Dec 2011 02:58:31 -0000 Subject: [Lldb-commits] [lldb] r147334 - /lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h Message-ID: <20111229025831.9E6C92A6C12C@llvm.org> Author: gclayton Date: Wed Dec 28 20:58:31 2011 New Revision: 147334 URL: http://llvm.org/viewvc/llvm-project?rev=147334&view=rev Log: Fixed an issue where our new accelerator tables could cause a crash when we got a full 32 bit hash match, yet a C string mismatch. We had a member variable in DWARFMappedHash::Prologue named "min_hash_data_byte_size" the would compute the byte size of HashData so we could skip hash data efficiently. It started out with a byte size value of 4. When we read the table in from disk, we would clear the atom array and read it from disk, and the byte size would still be set to 4. We would then, as we read each atom from disk, increment this count. So the byte size of the HashData was off, which means when we get a lookup whose 32 bit hash does matches, but the C string does NOT match (which is very very rare), then we try and skip the data for that hash and we would add an incorrect offset and get off in our parsing of the hash data and cause this crash. To fix this I added a few safeguards: 1 - I now correctly clear the hash data size when we reset the atom array using the new DWARFMappedHash::Prologue::ClearAtoms() function. 2 - I now correctly always let the AppendAtom() calculate the byte size of the hash (before we were doing things manually some times, which was correct, but not good) 3 - I also track if the size of each HashData is a fixed byte size or not, and "do the right thing" when we need to skip the data. 4 - If we do get off in the weeds, then I make sure to return an error and stop any further parsing from happening. Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h?rev=147334&r1=147333&r2=147334&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h Wed Dec 28 20:58:31 2011 @@ -146,28 +146,37 @@ dw_offset_t die_base_offset; AtomArray atoms; size_t min_hash_data_byte_size; + bool hash_data_has_fixed_byte_size; Prologue (dw_offset_t _die_base_offset = 0) : die_base_offset (_die_base_offset), atoms(), - min_hash_data_byte_size(0) + min_hash_data_byte_size(0), + hash_data_has_fixed_byte_size(true) { // Define an array of DIE offsets by first defining an array, // and then define the atom type for the array, in this case // we have an array of DIE offsets AppendAtom (eAtomTypeDIEOffset, DW_FORM_data4); - min_hash_data_byte_size = 4; } virtual ~Prologue() { } + void + ClearAtoms () + { + hash_data_has_fixed_byte_size = true; + min_hash_data_byte_size = 0; + atoms.clear(); + } + virtual void Clear () { die_base_offset = 0; - atoms.clear(); + ClearAtoms (); } void @@ -186,21 +195,29 @@ case DW_FORM_string: case DW_FORM_block: case DW_FORM_block1: + case DW_FORM_sdata: + case DW_FORM_udata: + case DW_FORM_ref_udata: + hash_data_has_fixed_byte_size = false; + // Fall through to the cases below... case DW_FORM_flag: case DW_FORM_data1: case DW_FORM_ref1: - case DW_FORM_sdata: - case DW_FORM_udata: case DW_FORM_sec_offset: - case DW_FORM_ref_udata: min_hash_data_byte_size += 1; break; + case DW_FORM_block2: + hash_data_has_fixed_byte_size = false; + // Fall through to the cases below... case DW_FORM_data2: case DW_FORM_ref2: min_hash_data_byte_size += 2; break; + case DW_FORM_block4: + hash_data_has_fixed_byte_size = false; + // Fall through to the cases below... case DW_FORM_data4: case DW_FORM_ref4: case DW_FORM_addr: @@ -208,6 +225,7 @@ case DW_FORM_strp: min_hash_data_byte_size += 4; break; + case DW_FORM_data8: case DW_FORM_ref8: min_hash_data_byte_size += 8; @@ -222,7 +240,7 @@ uint32_t Read (const lldb_private::DataExtractor &data, uint32_t offset) { - atoms.clear(); + ClearAtoms (); die_base_offset = data.GetU32 (&offset); @@ -233,7 +251,7 @@ while (data.GetU32(&offset)) /* do nothing */; - // Hardcode to the only know value for now. + // Hardcode to the only known value for now. AppendAtom (eAtomTypeDIEOffset, DW_FORM_data4); } else @@ -260,11 +278,16 @@ } size_t - GetHashDataByteSize () const + GetMinumumHashDataByteSize () const { return min_hash_data_byte_size; } + bool + HashDataHasFixedByteSize() const + { + return hash_data_has_fixed_byte_size; + } }; struct Header : public MappedHash::Header @@ -283,13 +306,7 @@ { return header_data.GetByteSize(); } - - size_t - GetHashDataByteSize () - { - return header_data.GetHashDataByteSize(); - } - + // virtual void // Dump (std::ostream* ostrm_ptr); // @@ -481,6 +498,8 @@ Pair &pair) const { pair.key = m_data.GetU32 (hash_data_offset_ptr); + pair.value.clear(); + // If the key is zero, this terminates our chain of HashData objects // for this hash value. if (pair.key == 0) @@ -490,31 +509,59 @@ // there isn't, there is something wrong, return and error const char *strp_cstr = m_string_table.PeekCStr (pair.key); if (strp_cstr == NULL) + { + *hash_data_offset_ptr = UINT32_MAX; return eResultError; + } const uint32_t count = m_data.GetU32 (hash_data_offset_ptr); - const uint32_t data_size = count * m_header.header_data.GetHashDataByteSize(); - if (count > 0 && m_data.ValidOffsetForDataOfSize (*hash_data_offset_ptr, data_size)) + const uint32_t min_total_hash_data_size = count * m_header.header_data.GetMinumumHashDataByteSize(); + if (count > 0 && m_data.ValidOffsetForDataOfSize (*hash_data_offset_ptr, min_total_hash_data_size)) { - if (strcmp (name, strp_cstr) == 0) + // We have at least one HashData entry, and we have enough + // data to parse at leats "count" HashData enties. + + // First make sure the entire C string matches... + const bool match = strcmp (name, strp_cstr) == 0; + + if (!match && m_header.header_data.HashDataHasFixedByteSize()) { - pair.value.clear(); + // If the string doesn't match and we have fixed size data, + // we can just add the total byte size of all HashData objects + // to the hash data offset and be done... + *hash_data_offset_ptr += min_total_hash_data_size; + } + else + { + // If the string does match, or we don't have fixed size data + // then we need to read the hash data as a stream. If the + // string matches we also append all HashData objects to the + // value array. for (uint32_t i=0; i 0 && m_data.ValidOffsetForDataOfSize (*hash_data_offset_ptr, data_size)) + const uint32_t min_total_hash_data_size = count * m_header.header_data.GetMinumumHashDataByteSize(); + if (count > 0 && m_data.ValidOffsetForDataOfSize (*hash_data_offset_ptr, min_total_hash_data_size)) { - if (regex.Execute(strp_cstr)) + const bool match = regex.Execute(strp_cstr); + + if (!match && m_header.header_data.HashDataHasFixedByteSize()) + { + // If the regex doesn't match and we have fixed size data, + // we can just add the total byte size of all HashData objects + // to the hash data offset and be done... + *hash_data_offset_ptr += min_total_hash_data_size; + } + else { + // If the string does match, or we don't have fixed size data + // then we need to read the hash data as a stream. If the + // string matches we also append all HashData objects to the + // value array. for (uint32_t i=0; i Author: gclayton Date: Thu Dec 29 13:47:20 2011 New Revision: 147350 URL: http://llvm.org/viewvc/llvm-project?rev=147350&view=rev Log: Fixed a crasher that can occur when parsing invalid DWARF. Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h?rev=147350&r1=147349&r2=147350&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h Thu Dec 29 13:47:20 2011 @@ -150,6 +150,12 @@ const DWARFDebugAranges & GetFunctionAranges (); + SymbolFileDWARF* + GetSymbolFileDWARF () const + { + return m_dwarf2Data; + } + protected: SymbolFileDWARF* m_dwarf2Data; const DWARFAbbreviationDeclarationSet *m_abbrevs; Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp?rev=147350&r1=147349&r2=147350&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp Thu Dec 29 13:47:20 2011 @@ -124,11 +124,11 @@ m_parent_idx = 0; m_sibling_idx = 0; m_empty_children = false; - uint64_t abbr_idx = debug_info_data.GetULEB128 (offset_ptr); + const uint64_t abbr_idx = debug_info_data.GetULEB128 (offset_ptr); assert (abbr_idx < (1 << DIE_ABBR_IDX_BITSIZE)); m_abbr_idx = abbr_idx; - assert (fixed_form_sizes); // For best performance this should be specified! + //assert (fixed_form_sizes); // For best performance this should be specified! if (m_abbr_idx) { @@ -136,6 +136,15 @@ const DWARFAbbreviationDeclaration *abbrevDecl = cu->GetAbbreviations()->GetAbbreviationDeclaration(m_abbr_idx); + if (abbrevDecl == NULL) + { + cu->GetSymbolFileDWARF ()->ReportError ("{0x%8.8x}: invalid abbreviation code %u, please file a bug and attach the file at the start of this error message", + m_offset, + (unsigned)abbr_idx); + // WE can't parse anymore if the DWARF is borked... + *offset_ptr = UINT32_MAX; + return false; + } m_tag = abbrevDecl->Tag(); m_has_children = abbrevDecl->HasChildren(); // Skip all data in the .debug_info for the attributes From gclayton at apple.com Thu Dec 29 18:32:24 2011 From: gclayton at apple.com (Greg Clayton) Date: Fri, 30 Dec 2011 00:32:24 -0000 Subject: [Lldb-commits] [lldb] r147358 - in /lldb/trunk: include/lldb/Core/DataExtractor.h source/Core/DataExtractor.cpp source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp Message-ID: <20111230003224.736992A6C12C@llvm.org> Author: gclayton Date: Thu Dec 29 18:32:24 2011 New Revision: 147358 URL: http://llvm.org/viewvc/llvm-project?rev=147358&view=rev Log: Watch for empty symbol tables by doing a lot more error checking on all mach-o symbol table load command values and data that is obtained. This avoids a crash that was happening when there was no string table. Modified: lldb/trunk/include/lldb/Core/DataExtractor.h lldb/trunk/source/Core/DataExtractor.cpp lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp Modified: lldb/trunk/include/lldb/Core/DataExtractor.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/DataExtractor.h?rev=147358&r1=147357&r2=147358&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/DataExtractor.h (original) +++ lldb/trunk/include/lldb/Core/DataExtractor.h Thu Dec 29 18:32:24 2011 @@ -354,6 +354,9 @@ //------------------------------------------------------------------ uint64_t GetAddress (uint32_t *offset_ptr) const; + + uint64_t + GetAddress_unchecked (uint32_t *offset_ptr) const; //------------------------------------------------------------------ /// Get the current address size. @@ -629,6 +632,9 @@ uint64_t GetMaxU64 (uint32_t *offset_ptr, uint32_t byte_size) const; + uint64_t + GetMaxU64_unchecked (uint32_t *offset_ptr, uint32_t byte_size) const; + //------------------------------------------------------------------ /// Extract an signed integer of size \a byte_size from \a *offset_ptr. /// Modified: lldb/trunk/source/Core/DataExtractor.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/DataExtractor.cpp?rev=147358&r1=147357&r2=147358&view=diff ============================================================================== --- lldb/trunk/source/Core/DataExtractor.cpp (original) +++ lldb/trunk/source/Core/DataExtractor.cpp Thu Dec 29 18:32:24 2011 @@ -659,6 +659,22 @@ return 0; } +uint64_t +DataExtractor::GetMaxU64_unchecked (uint32_t *offset_ptr, uint32_t size) const +{ + switch (size) + { + case 1: return GetU8_unchecked (offset_ptr); break; + case 2: return GetU16_unchecked (offset_ptr); break; + case 4: return GetU32_unchecked (offset_ptr); break; + case 8: return GetU64_unchecked (offset_ptr); break; + default: + assert(!"GetMax64 unhandled case!"); + break; + } + return 0; +} + int64_t DataExtractor::GetMaxS64 (uint32_t *offset_ptr, uint32_t size) const { @@ -803,6 +819,12 @@ return GetMaxU64 (offset_ptr, m_addr_size); } +uint64_t +DataExtractor::GetAddress_unchecked (uint32_t *offset_ptr) const +{ + return GetMaxU64_unchecked (offset_ptr, m_addr_size); +} + //------------------------------------------------------------------ // Extract a single pointer from the data and update the offset // pointed to by "offset_ptr". The size of the extracted pointer Modified: lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp?rev=147358&r1=147357&r2=147358&view=diff ============================================================================== --- lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (original) +++ lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp Thu Dec 29 18:32:24 2011 @@ -752,6 +752,9 @@ struct symtab_command symtab_load_command; uint32_t offset = MachHeaderSizeFromMagic(m_header.magic); uint32_t i; + + LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_SYMBOLS)); + for (i=0; iLogMessage(log.get(), "LC_SYMTAB.symoff == 0"); + return 0; + } + + if (symtab_load_command.stroff == 0) + { + if (log) + GetModule()->LogMessage(log.get(), "LC_SYMTAB.stroff == 0"); + return 0; + } + + if (symtab_load_command.nsyms == 0) + { + if (log) + GetModule()->LogMessage(log.get(), "LC_SYMTAB.nsyms == 0"); + return 0; + } + + if (symtab_load_command.strsize == 0) + { + if (log) + GetModule()->LogMessage(log.get(), "LC_SYMTAB.strsize == 0"); + return 0; + } + Symtab *symtab = m_symtab_ap.get(); SectionList *section_list = GetSectionList(); - assert(section_list); - const size_t addr_size = m_data.GetAddressByteSize(); - const ByteOrder endian = m_data.GetByteOrder(); - bool bit_width_32 = addr_size == 4; - const size_t nlist_size = bit_width_32 ? sizeof(struct nlist) : sizeof(struct nlist_64); + if (section_list == NULL) + return 0; + + const size_t addr_byte_size = m_data.GetAddressByteSize(); + const ByteOrder byte_order = m_data.GetByteOrder(); + bool bit_width_32 = addr_byte_size == 4; + const size_t nlist_byte_size = bit_width_32 ? sizeof(struct nlist) : sizeof(struct nlist_64); + + DataBufferSP symtab_data_sp(m_file.ReadFileContents (m_offset + symtab_load_command.symoff, + symtab_load_command.nsyms * nlist_byte_size)); + + if (symtab_data_sp.get() == NULL || + symtab_data_sp->GetBytes() == NULL || + symtab_data_sp->GetByteSize() == 0) + { + if (log) + GetModule()->LogMessage(log.get(), "failed to read nlist data"); + return 0; + } + + DataBufferSP strtab_data_sp(m_file.ReadFileContents (m_offset + symtab_load_command.stroff, + symtab_load_command.strsize)); - DataBufferSP symtab_data_sp(m_file.ReadFileContents(m_offset + symtab_load_command.symoff, symtab_load_command.nsyms * nlist_size)); - DataBufferSP strtab_data_sp(m_file.ReadFileContents(m_offset + symtab_load_command.stroff, symtab_load_command.strsize)); + if (strtab_data_sp.get() == NULL || + strtab_data_sp->GetBytes() == NULL || + strtab_data_sp->GetByteSize() == 0) + { + if (log) + GetModule()->LogMessage(log.get(), "failed to read strtab data"); + return 0; + } const char *strtab_data = (const char *)strtab_data_sp->GetBytes(); const size_t strtab_data_len = strtab_data_sp->GetByteSize(); @@ -793,15 +847,11 @@ uint8_t TEXT_eh_frame_sectID = eh_frame_section_sp.get() ? eh_frame_section_sp->GetID() : NListSectionNoSection; //uint32_t symtab_offset = 0; - const uint8_t* nlist_data = symtab_data_sp->GetBytes(); - assert (symtab_data_sp->GetByteSize()/nlist_size >= symtab_load_command.nsyms); + assert (symtab_data_sp->GetByteSize()/nlist_byte_size >= symtab_load_command.nsyms); + uint32_t nlist_data_offset = 0; + DataExtractor nlist_data (symtab_data_sp, byte_order, addr_byte_size); - if (endian != lldb::endian::InlHostByteOrder()) - { - // ... - assert (!"UNIMPLEMENTED: Swap all nlist entries"); - } uint32_t N_SO_index = UINT32_MAX; MachSymtabSectionInfo section_info (section_list); @@ -828,19 +878,14 @@ for (nlist_idx = 0; nlist_idx < symtab_load_command.nsyms; ++nlist_idx) { struct nlist_64 nlist; - if (bit_width_32) - { - struct nlist* nlist32_ptr = (struct nlist*)(nlist_data + (nlist_idx * nlist_size)); - nlist.n_strx = nlist32_ptr->n_strx; - nlist.n_type = nlist32_ptr->n_type; - nlist.n_sect = nlist32_ptr->n_sect; - nlist.n_desc = nlist32_ptr->n_desc; - nlist.n_value = nlist32_ptr->n_value; - } - else - { - nlist = *((struct nlist_64*)(nlist_data + (nlist_idx * nlist_size))); - } + if (!nlist_data.ValidOffsetForDataOfSize(nlist_data_offset, nlist_byte_size)) + break; + + nlist.n_strx = nlist_data.GetU32_unchecked(&nlist_data_offset); + nlist.n_type = nlist_data.GetU8_unchecked (&nlist_data_offset); + nlist.n_sect = nlist_data.GetU8_unchecked (&nlist_data_offset); + nlist.n_desc = nlist_data.GetU16_unchecked (&nlist_data_offset); + nlist.n_value = nlist_data.GetAddress_unchecked (&nlist_data_offset); SymbolType type = eSymbolTypeInvalid; if (nlist.n_strx >= strtab_data_len) @@ -1556,9 +1601,6 @@ } } } - - - return symtab->GetNumSymbols(); } }