SystemRuntimeMacOSX::ItemInfo SystemRuntimeMacOSX::ExtractItemInfoFromBuffer (lldb_private::DataExtractor &extractor) { ItemInfo item; offset_t offset = 0; item.item_that_enqueued_this = extractor.GetPointer (&offset); item.function_or_block = extractor.GetPointer (&offset); item.enqueuing_thread_id = extractor.GetU64 (&offset); item.enqueuing_queue_serialnum = extractor.GetU64 (&offset); item.target_queue_serialnum = extractor.GetU64 (&offset); item.enqueuing_callstack_frame_count = extractor.GetU32 (&offset); item.stop_id = extractor.GetU32 (&offset); offset = m_lib_backtrace_recording_info.item_info_data_offset; for (uint32_t i = 0; i < item.enqueuing_callstack_frame_count; i++) { item.enqueuing_callstack.push_back (extractor.GetPointer (&offset)); } item.enqueuing_thread_label = extractor.GetCStr (&offset); item.enqueuing_queue_label = extractor.GetCStr (&offset); item.target_queue_label = extractor.GetCStr (&offset); return item; }
bool ELFSymbol::Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset) { const unsigned byte_size = data.GetAddressByteSize(); const bool parsing_32 = byte_size == 4; // Read st_name. if (data.GetU32(offset, &st_name, 1) == NULL) return false; if (parsing_32) { // Read st_value and st_size. if (GetMaxU64(data, offset, &st_value, byte_size, 2) == false) return false; // Read st_info and st_other. if (data.GetU8(offset, &st_info, 2) == NULL) return false; // Read st_shndx. if (data.GetU16(offset, &st_shndx, 1) == NULL) return false; } else { // Read st_info and st_other. if (data.GetU8(offset, &st_info, 2) == NULL) return false; // Read st_shndx. if (data.GetU16(offset, &st_shndx, 1) == NULL) return false; // Read st_value and st_size. if (data.GetU64(offset, &st_value, 2) == NULL) return false; } return true; }
virtual size_t Decode (const lldb_private::Disassembler &disassembler, const lldb_private::DataExtractor &data, lldb::offset_t data_offset) { // All we have to do is read the opcode which can be easy for some // architectures bool got_op = false; DisassemblerLLVMC &llvm_disasm = GetDisassemblerLLVMC(); const ArchSpec &arch = llvm_disasm.GetArchitecture(); const lldb::ByteOrder byte_order = data.GetByteOrder(); const uint32_t min_op_byte_size = arch.GetMinimumOpcodeByteSize(); const uint32_t max_op_byte_size = arch.GetMaximumOpcodeByteSize(); if (min_op_byte_size == max_op_byte_size) { // Fixed size instructions, just read that amount of data. if (!data.ValidOffsetForDataOfSize(data_offset, min_op_byte_size)) return false; switch (min_op_byte_size) { case 1: m_opcode.SetOpcode8 (data.GetU8 (&data_offset), byte_order); got_op = true; break; case 2: m_opcode.SetOpcode16 (data.GetU16 (&data_offset), byte_order); got_op = true; break; case 4: m_opcode.SetOpcode32 (data.GetU32 (&data_offset), byte_order); got_op = true; break; case 8: m_opcode.SetOpcode64 (data.GetU64 (&data_offset), byte_order); got_op = true; break; default: m_opcode.SetOpcodeBytes(data.PeekData(data_offset, min_op_byte_size), min_op_byte_size); got_op = true; break; } } if (!got_op) { bool is_alternate_isa = false; DisassemblerLLVMC::LLVMCDisassembler *mc_disasm_ptr = GetDisasmToUse (is_alternate_isa); const llvm::Triple::ArchType machine = arch.GetMachine(); if (machine == llvm::Triple::arm || machine == llvm::Triple::thumb) { if (machine == llvm::Triple::thumb || is_alternate_isa) { uint32_t thumb_opcode = data.GetU16(&data_offset); if ((thumb_opcode & 0xe000) != 0xe000 || ((thumb_opcode & 0x1800u) == 0)) { m_opcode.SetOpcode16 (thumb_opcode, byte_order); m_is_valid = true; } else { thumb_opcode <<= 16; thumb_opcode |= data.GetU16(&data_offset); m_opcode.SetOpcode16_2 (thumb_opcode, byte_order); m_is_valid = true; } } else { m_opcode.SetOpcode32 (data.GetU32(&data_offset), byte_order); m_is_valid = true; } } else { // The opcode isn't evenly sized, so we need to actually use the llvm // disassembler to parse it and get the size. uint8_t *opcode_data = const_cast<uint8_t *>(data.PeekData (data_offset, 1)); const size_t opcode_data_len = data.BytesLeft(data_offset); const addr_t pc = m_address.GetFileAddress(); llvm::MCInst inst; llvm_disasm.Lock(this, NULL); const size_t inst_size = mc_disasm_ptr->GetMCInst(opcode_data, opcode_data_len, pc, inst); llvm_disasm.Unlock(); if (inst_size == 0) m_opcode.Clear(); else { m_opcode.SetOpcodeBytes(opcode_data, inst_size); m_is_valid = true; } } } return m_opcode.GetByteSize(); }
virtual size_t Decode (const lldb_private::Disassembler &disassembler, const lldb_private::DataExtractor &data, uint32_t data_offset) { // All we have to do is read the opcode which can be easy for some // architetures bool got_op = false; const ArchSpec &arch = m_disasm.GetArchitecture(); const uint32_t min_op_byte_size = arch.GetMinimumOpcodeByteSize(); const uint32_t max_op_byte_size = arch.GetMaximumOpcodeByteSize(); if (min_op_byte_size == max_op_byte_size) { // Fixed size instructions, just read that amount of data. if (!data.ValidOffsetForDataOfSize(data_offset, min_op_byte_size)) return false; switch (min_op_byte_size) { case 1: m_opcode.SetOpcode8 (data.GetU8 (&data_offset)); got_op = true; break; case 2: m_opcode.SetOpcode16 (data.GetU16 (&data_offset)); got_op = true; break; case 4: m_opcode.SetOpcode32 (data.GetU32 (&data_offset)); got_op = true; break; case 8: m_opcode.SetOpcode64 (data.GetU64 (&data_offset)); got_op = true; break; default: m_opcode.SetOpcodeBytes(data.PeekData(data_offset, min_op_byte_size), min_op_byte_size); got_op = true; break; } } if (!got_op) { ::LLVMDisasmContextRef disasm_context = m_disasm.m_disasm_context; bool is_altnernate_isa = false; if (m_disasm.m_alternate_disasm_context) { const AddressClass address_class = GetAddressClass (); if (address_class == eAddressClassCodeAlternateISA) { disasm_context = m_disasm.m_alternate_disasm_context; is_altnernate_isa = true; } } const llvm::Triple::ArchType machine = arch.GetMachine(); if (machine == llvm::Triple::arm || machine == llvm::Triple::thumb) { if (machine == llvm::Triple::thumb || is_altnernate_isa) { uint32_t thumb_opcode = data.GetU16(&data_offset); if ((thumb_opcode & 0xe000) != 0xe000 || ((thumb_opcode & 0x1800u) == 0)) { m_opcode.SetOpcode16 (thumb_opcode); } else { thumb_opcode <<= 16; thumb_opcode |= data.GetU16(&data_offset); m_opcode.SetOpcode32 (thumb_opcode); m_is_valid = true; } } else { m_opcode.SetOpcode32 (data.GetU32(&data_offset)); } } else { // The opcode isn't evenly sized, so we need to actually use the llvm // disassembler to parse it and get the size. char out_string[512]; m_disasm.Lock(this, NULL); uint8_t *opcode_data = const_cast<uint8_t *>(data.PeekData (data_offset, 1)); const size_t opcode_data_len = data.GetByteSize() - data_offset; const addr_t pc = m_address.GetFileAddress(); const size_t inst_size = ::LLVMDisasmInstruction (disasm_context, opcode_data, opcode_data_len, pc, // PC value out_string, sizeof(out_string)); // The address lookup function could have caused us to fill in our comment m_comment.clear(); m_disasm.Unlock(); if (inst_size == 0) m_opcode.Clear(); else { m_opcode.SetOpcodeBytes(opcode_data, inst_size); m_is_valid = true; } } } return m_opcode.GetByteSize(); }
bool CompilerType::GetValueAsScalar (const lldb_private::DataExtractor &data, lldb::offset_t data_byte_offset, size_t data_byte_size, Scalar &value) const { if (!IsValid()) return false; if (0 == (GetTypeInfo() & eTypeHasValue)) { return false; // Aggregate types don't have scalar values } else { uint64_t count = 0; lldb::Encoding encoding = GetEncoding (count); if (encoding == lldb::eEncodingInvalid || count != 1) return false; const uint64_t byte_size = GetByteSize(nullptr); lldb::offset_t offset = data_byte_offset; switch (encoding) { case lldb::eEncodingInvalid: break; case lldb::eEncodingVector: break; case lldb::eEncodingUint: if (byte_size <= sizeof(unsigned long long)) { uint64_t uval64 = data.GetMaxU64 (&offset, byte_size); if (byte_size <= sizeof(unsigned int)) { value = (unsigned int)uval64; return true; } else if (byte_size <= sizeof(unsigned long)) { value = (unsigned long)uval64; return true; } else if (byte_size <= sizeof(unsigned long long)) { value = (unsigned long long )uval64; return true; } else value.Clear(); } break; case lldb::eEncodingSint: if (byte_size <= sizeof(long long)) { int64_t sval64 = data.GetMaxS64 (&offset, byte_size); if (byte_size <= sizeof(int)) { value = (int)sval64; return true; } else if (byte_size <= sizeof(long)) { value = (long)sval64; return true; } else if (byte_size <= sizeof(long long)) { value = (long long )sval64; return true; } else value.Clear(); } break; case lldb::eEncodingIEEE754: if (byte_size <= sizeof(long double)) { uint32_t u32; uint64_t u64; if (byte_size == sizeof(float)) { if (sizeof(float) == sizeof(uint32_t)) { u32 = data.GetU32(&offset); value = *((float *)&u32); return true; } else if (sizeof(float) == sizeof(uint64_t)) { u64 = data.GetU64(&offset); value = *((float *)&u64); return true; } } else if (byte_size == sizeof(double)) { if (sizeof(double) == sizeof(uint32_t)) { u32 = data.GetU32(&offset); value = *((double *)&u32); return true; } else if (sizeof(double) == sizeof(uint64_t)) { u64 = data.GetU64(&offset); value = *((double *)&u64); return true; } } else if (byte_size == sizeof(long double)) { if (sizeof(long double) == sizeof(uint32_t)) { u32 = data.GetU32(&offset); value = *((long double *)&u32); return true; } else if (sizeof(long double) == sizeof(uint64_t)) { u64 = data.GetU64(&offset); value = *((long double *)&u64); return true; } } } break; } } return false; }