2017-04-26 16:48:50 +08:00
|
|
|
//===-- SBTrace.cpp ---------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2017-04-26 16:48:50 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Target/Process.h"
|
2017-05-26 19:46:27 +08:00
|
|
|
#include "lldb/Utility/Log.h"
|
2017-04-26 16:48:50 +08:00
|
|
|
|
|
|
|
#include "lldb/API/SBTrace.h"
|
|
|
|
#include "lldb/API/SBTraceOptions.h"
|
|
|
|
|
2019-02-12 07:13:08 +08:00
|
|
|
#include <memory>
|
|
|
|
|
2017-04-26 16:48:50 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
class TraceImpl {
|
|
|
|
public:
|
|
|
|
lldb::user_id_t uid;
|
|
|
|
};
|
|
|
|
|
|
|
|
lldb::ProcessSP SBTrace::GetSP() const { return m_opaque_wp.lock(); }
|
|
|
|
|
|
|
|
size_t SBTrace::GetTraceData(SBError &error, void *buf, size_t size,
|
|
|
|
size_t offset, lldb::tid_t thread_id) {
|
|
|
|
ProcessSP process_sp(GetSP());
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
|
2017-05-26 19:46:27 +08:00
|
|
|
llvm::MutableArrayRef<uint8_t> buffer(static_cast<uint8_t *>(buf), size);
|
2017-04-26 16:48:50 +08:00
|
|
|
error.Clear();
|
|
|
|
|
|
|
|
if (!process_sp) {
|
|
|
|
error.SetErrorString("invalid process");
|
|
|
|
} else {
|
2017-05-26 19:46:27 +08:00
|
|
|
error.SetError(
|
|
|
|
process_sp->GetData(GetTraceUID(), thread_id, buffer, offset));
|
|
|
|
LLDB_LOG(log, "SBTrace::bytes_read - {0}", buffer.size());
|
2017-04-26 16:48:50 +08:00
|
|
|
}
|
2017-05-26 19:46:27 +08:00
|
|
|
return buffer.size();
|
2017-04-26 16:48:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t SBTrace::GetMetaData(SBError &error, void *buf, size_t size,
|
|
|
|
size_t offset, lldb::tid_t thread_id) {
|
|
|
|
ProcessSP process_sp(GetSP());
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
|
2017-05-26 19:46:27 +08:00
|
|
|
llvm::MutableArrayRef<uint8_t> buffer(static_cast<uint8_t *>(buf), size);
|
2017-04-26 16:48:50 +08:00
|
|
|
error.Clear();
|
|
|
|
|
|
|
|
if (!process_sp) {
|
|
|
|
error.SetErrorString("invalid process");
|
|
|
|
} else {
|
|
|
|
|
2017-05-26 19:46:27 +08:00
|
|
|
error.SetError(
|
|
|
|
process_sp->GetMetaData(GetTraceUID(), thread_id, buffer, offset));
|
|
|
|
LLDB_LOG(log, "SBTrace::bytes_read - {0}", buffer.size());
|
2017-04-26 16:48:50 +08:00
|
|
|
}
|
2017-05-26 19:46:27 +08:00
|
|
|
return buffer.size();
|
2017-04-26 16:48:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SBTrace::StopTrace(SBError &error, lldb::tid_t thread_id) {
|
|
|
|
ProcessSP process_sp(GetSP());
|
|
|
|
error.Clear();
|
|
|
|
|
|
|
|
if (!process_sp) {
|
|
|
|
error.SetErrorString("invalid process");
|
|
|
|
return;
|
|
|
|
}
|
2017-05-26 19:46:27 +08:00
|
|
|
error.SetError(process_sp->StopTrace(GetTraceUID(), thread_id));
|
2017-04-26 16:48:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SBTrace::GetTraceConfig(SBTraceOptions &options, SBError &error) {
|
|
|
|
ProcessSP process_sp(GetSP());
|
|
|
|
error.Clear();
|
|
|
|
|
|
|
|
if (!process_sp) {
|
|
|
|
error.SetErrorString("invalid process");
|
|
|
|
} else {
|
2017-05-26 19:46:27 +08:00
|
|
|
error.SetError(process_sp->GetTraceConfig(GetTraceUID(),
|
|
|
|
*(options.m_traceoptions_sp)));
|
2017-04-26 16:48:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::user_id_t SBTrace::GetTraceUID() {
|
|
|
|
if (m_trace_impl_sp)
|
|
|
|
return m_trace_impl_sp->uid;
|
|
|
|
return LLDB_INVALID_UID;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SBTrace::SetTraceUID(lldb::user_id_t uid) {
|
|
|
|
if (m_trace_impl_sp)
|
|
|
|
m_trace_impl_sp->uid = uid;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBTrace::SBTrace() {
|
2019-02-12 07:13:08 +08:00
|
|
|
m_trace_impl_sp = std::make_shared<TraceImpl>();
|
2017-04-26 16:48:50 +08:00
|
|
|
if (m_trace_impl_sp)
|
|
|
|
m_trace_impl_sp->uid = LLDB_INVALID_UID;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SBTrace::SetSP(const ProcessSP &process_sp) { m_opaque_wp = process_sp; }
|
|
|
|
|
|
|
|
bool SBTrace::IsValid() {
|
|
|
|
if (!m_trace_impl_sp)
|
|
|
|
return false;
|
|
|
|
if (!GetSP())
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|