Beispiel #1
0
bool CompilerType::ReadFromMemory(lldb_private::ExecutionContext *exe_ctx,
                                  lldb::addr_t addr, AddressType address_type,
                                  lldb_private::DataExtractor &data) {
  if (!IsValid())
    return false;

  // Can't convert a file address to anything valid without more context (which
  // Module it came from)
  if (address_type == eAddressTypeFile)
    return false;

  if (!GetCompleteType())
    return false;

  auto byte_size =
      GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
  if (!byte_size)
    return false;

  if (data.GetByteSize() < *byte_size) {
    lldb::DataBufferSP data_sp(new DataBufferHeap(*byte_size, '\0'));
    data.SetData(data_sp);
  }

  uint8_t *dst = const_cast<uint8_t *>(data.PeekData(0, *byte_size));
  if (dst != nullptr) {
    if (address_type == eAddressTypeHost) {
      if (addr == 0)
        return false;
      // The address is an address in this process, so just copy it
      memcpy(dst, reinterpret_cast<uint8_t *>(addr), *byte_size);
      return true;
    } else {
      Process *process = nullptr;
      if (exe_ctx)
        process = exe_ctx->GetProcessPtr();
      if (process) {
        Status error;
        return process->ReadMemory(addr, dst, *byte_size, error) == *byte_size;
      }
    }
  }
  return false;
}
size_t
ObjectFileJIT::ReadSectionData (const lldb_private::Section *section,
                                lldb_private::DataExtractor& section_data) const
{
    if (section->GetFileSize())
    {
        const void *src = (void *)(uintptr_t)section->GetFileOffset();
    
        DataBufferSP data_sp (new lldb_private::DataBufferHeap(src, section->GetFileSize()));
        if (data_sp)
        {
            section_data.SetData (data_sp, 0, data_sp->GetByteSize());
            section_data.SetByteOrder (GetByteOrder());
            section_data.SetAddressByteSize (GetAddressByteSize());
            return section_data.GetByteSize();
        }
    }
    section_data.Clear();
    return 0;
}