1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
//===-- PTDecoder.cpp -------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "PTDecoder.h"
#include "Decoder.h"
using namespace ptdecoder;
using namespace ptdecoder_private;
// PTInstruction class member functions definitions
PTInstruction::PTInstruction(
const std::shared_ptr<ptdecoder_private::Instruction> &ptr)
: m_opaque_sp(ptr) {}
PTInstruction::~PTInstruction() {}
uint64_t PTInstruction::GetInsnAddress() const {
return (m_opaque_sp ? m_opaque_sp->GetInsnAddress() : 0);
}
size_t PTInstruction::GetRawBytes(void *buf, size_t size) const {
return (m_opaque_sp ? m_opaque_sp->GetRawBytes(buf, size) : 0);
}
std::string PTInstruction::GetError() const {
return (m_opaque_sp ? m_opaque_sp->GetError() : "null pointer");
}
bool PTInstruction::GetSpeculative() const {
return (m_opaque_sp ? m_opaque_sp->GetSpeculative() : 0);
}
// PTInstructionList class member functions definitions
size_t PTInstructionList::GetSize() const {
return (m_opaque_sp ? m_opaque_sp->GetSize() : 0);
}
PTInstruction PTInstructionList::GetInstructionAtIndex(uint32_t idx) {
if (m_opaque_sp)
return PTInstruction(std::shared_ptr<ptdecoder_private::Instruction>(
new Instruction(m_opaque_sp->GetInstructionAtIndex(idx))));
return PTInstruction(std::shared_ptr<ptdecoder_private::Instruction>(
new Instruction("invalid instruction")));
}
void PTInstructionList::SetSP(
const std::shared_ptr<ptdecoder_private::InstructionList> &ptr) {
m_opaque_sp = ptr;
}
void PTInstructionList::Clear() {
if (!m_opaque_sp)
return;
m_opaque_sp.reset();
}
// PTTraceOptions class member functions definitions
lldb::TraceType PTTraceOptions::GetType() const {
return (m_opaque_sp ? m_opaque_sp->getType()
: lldb::TraceType::eTraceTypeNone);
}
uint64_t PTTraceOptions::GetTraceBufferSize() const {
return (m_opaque_sp ? m_opaque_sp->getTraceBufferSize() : 0);
}
uint64_t PTTraceOptions::GetMetaDataBufferSize() const {
return (m_opaque_sp ? m_opaque_sp->getMetaDataBufferSize() : 0);
}
lldb::SBStructuredData PTTraceOptions::GetTraceParams(lldb::SBError &error) {
if (!m_opaque_sp)
error.SetErrorString("null pointer");
return (m_opaque_sp ? m_opaque_sp->getTraceParams(error)
: lldb::SBStructuredData());
}
void PTTraceOptions::SetSP(
const std::shared_ptr<ptdecoder_private::TraceOptions> &ptr) {
m_opaque_sp = ptr;
}
// PTDecoder class member functions definitions
PTDecoder::PTDecoder(lldb::SBDebugger &sbdebugger)
: m_opaque_sp(new ptdecoder_private::Decoder(sbdebugger)) {}
void PTDecoder::StartProcessorTrace(lldb::SBProcess &sbprocess,
lldb::SBTraceOptions &sbtraceoptions,
lldb::SBError &sberror) {
if (m_opaque_sp == nullptr) {
sberror.SetErrorStringWithFormat("invalid PTDecoder instance");
return;
}
m_opaque_sp->StartProcessorTrace(sbprocess, sbtraceoptions, sberror);
}
void PTDecoder::StopProcessorTrace(lldb::SBProcess &sbprocess,
lldb::SBError &sberror, lldb::tid_t tid) {
if (m_opaque_sp == nullptr) {
sberror.SetErrorStringWithFormat("invalid PTDecoder instance");
return;
}
m_opaque_sp->StopProcessorTrace(sbprocess, sberror, tid);
}
void PTDecoder::GetInstructionLogAtOffset(lldb::SBProcess &sbprocess,
lldb::tid_t tid, uint32_t offset,
uint32_t count,
PTInstructionList &result_list,
lldb::SBError &sberror) {
if (m_opaque_sp == nullptr) {
sberror.SetErrorStringWithFormat("invalid PTDecoder instance");
return;
}
std::shared_ptr<ptdecoder_private::InstructionList> insn_list_ptr(
new InstructionList());
m_opaque_sp->GetInstructionLogAtOffset(sbprocess, tid, offset, count,
*insn_list_ptr, sberror);
if (!sberror.Success())
return;
result_list.SetSP(insn_list_ptr);
}
void PTDecoder::GetProcessorTraceInfo(lldb::SBProcess &sbprocess,
lldb::tid_t tid, PTTraceOptions &options,
lldb::SBError &sberror) {
if (m_opaque_sp == nullptr) {
sberror.SetErrorStringWithFormat("invalid PTDecoder instance");
return;
}
std::shared_ptr<ptdecoder_private::TraceOptions> trace_options_ptr(
new TraceOptions());
m_opaque_sp->GetProcessorTraceInfo(sbprocess, tid, *trace_options_ptr,
sberror);
if (!sberror.Success())
return;
options.SetSP(trace_options_ptr);
}
|