mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-04-01 12:43:47 +00:00
Minor refactor and renaming:
- Rename IntelPTManager class and files to IntelPTCollector - Change GetTimestampCounter API to general trace counter API, GetCounter Differential Revision: https://reviews.llvm.org/D121711
This commit is contained in:
parent
5aab45f430
commit
22077627ae
@ -180,14 +180,16 @@ public:
|
||||
/// LLDB_INVALID_ADDRESS.
|
||||
virtual lldb::addr_t GetLoadAddress() = 0;
|
||||
|
||||
/// Get the timestamp counter associated with the current instruction.
|
||||
/// Modern Intel, ARM and AMD processors support this counter. However, a
|
||||
/// trace plugin might decide to use a different time unit instead of an
|
||||
/// actual TSC.
|
||||
/// Get the hardware counter of a given type associated with the current
|
||||
/// instruction. Each architecture might support different counters. It might
|
||||
/// happen that only some instructions of an entire trace have a given counter
|
||||
/// associated with them.
|
||||
///
|
||||
/// \param[in] counter_type
|
||||
/// The counter type.
|
||||
/// \return
|
||||
/// The timestamp or \b llvm::None if not available.
|
||||
virtual llvm::Optional<uint64_t> GetTimestampCounter() = 0;
|
||||
/// The value of the counter or \b llvm::None if not available.
|
||||
virtual llvm::Optional<uint64_t> GetCounter(lldb::TraceCounter counter_type) = 0;
|
||||
|
||||
/// \return
|
||||
/// The \a lldb::TraceInstructionControlFlowType categories the
|
||||
|
@ -1141,6 +1141,12 @@ enum SaveCoreStyle {
|
||||
eSaveCoreStackOnly = 3,
|
||||
};
|
||||
|
||||
// Type of counter values associated with instructions in a trace.
|
||||
enum TraceCounter {
|
||||
// Timestamp counter, like the one offered by Intel CPUs (TSC).
|
||||
eTraceCounterTSC,
|
||||
};
|
||||
|
||||
} // namespace lldb
|
||||
|
||||
#endif // LLDB_LLDB_ENUMERATIONS_H
|
||||
|
@ -1,5 +1,5 @@
|
||||
add_lldb_library(lldbPluginProcessLinux
|
||||
IntelPTManager.cpp
|
||||
IntelPTCollector.cpp
|
||||
NativeProcessLinux.cpp
|
||||
NativeRegisterContextLinux.cpp
|
||||
NativeRegisterContextLinux_arm.cpp
|
||||
|
@ -1,4 +1,4 @@
|
||||
//===-- IntelPTManager.cpp ------------------------------------------------===//
|
||||
//===-- IntelPTCollector.cpp ------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
@ -14,7 +14,7 @@
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Support/MathExtras.h"
|
||||
|
||||
#include "IntelPTManager.h"
|
||||
#include "IntelPTCollector.h"
|
||||
#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
|
||||
#include "lldb/Host/linux/Support.h"
|
||||
#include "lldb/Utility/StreamString.h"
|
||||
@ -564,15 +564,15 @@ IntelPTProcessTrace::GetThreadTraces() const {
|
||||
return m_thread_traces;
|
||||
}
|
||||
|
||||
/// IntelPTManager
|
||||
/// IntelPTCollector
|
||||
|
||||
Error IntelPTManager::TraceStop(lldb::tid_t tid) {
|
||||
Error IntelPTCollector::TraceStop(lldb::tid_t tid) {
|
||||
if (IsProcessTracingEnabled() && m_process_trace->TracesThread(tid))
|
||||
return m_process_trace->TraceStop(tid);
|
||||
return m_thread_traces.TraceStop(tid);
|
||||
}
|
||||
|
||||
Error IntelPTManager::TraceStop(const TraceStopRequest &request) {
|
||||
Error IntelPTCollector::TraceStop(const TraceStopRequest &request) {
|
||||
if (request.IsProcessTracing()) {
|
||||
Clear();
|
||||
return Error::success();
|
||||
@ -585,7 +585,7 @@ Error IntelPTManager::TraceStop(const TraceStopRequest &request) {
|
||||
}
|
||||
}
|
||||
|
||||
Error IntelPTManager::TraceStart(
|
||||
Error IntelPTCollector::TraceStart(
|
||||
const TraceIntelPTStartRequest &request,
|
||||
const std::vector<lldb::tid_t> &process_threads) {
|
||||
if (request.IsProcessTracing()) {
|
||||
@ -609,13 +609,13 @@ Error IntelPTManager::TraceStart(
|
||||
}
|
||||
}
|
||||
|
||||
Error IntelPTManager::OnThreadCreated(lldb::tid_t tid) {
|
||||
Error IntelPTCollector::OnThreadCreated(lldb::tid_t tid) {
|
||||
if (!IsProcessTracingEnabled())
|
||||
return Error::success();
|
||||
return m_process_trace->TraceStart(tid);
|
||||
}
|
||||
|
||||
Error IntelPTManager::OnThreadDestroyed(lldb::tid_t tid) {
|
||||
Error IntelPTCollector::OnThreadDestroyed(lldb::tid_t tid) {
|
||||
if (IsProcessTracingEnabled() && m_process_trace->TracesThread(tid))
|
||||
return m_process_trace->TraceStop(tid);
|
||||
else if (m_thread_traces.TracesThread(tid))
|
||||
@ -623,7 +623,7 @@ Error IntelPTManager::OnThreadDestroyed(lldb::tid_t tid) {
|
||||
return Error::success();
|
||||
}
|
||||
|
||||
Expected<json::Value> IntelPTManager::GetState() const {
|
||||
Expected<json::Value> IntelPTCollector::GetState() const {
|
||||
Expected<ArrayRef<uint8_t>> cpu_info = IntelPTThreadTrace::GetCPUInfo();
|
||||
if (!cpu_info)
|
||||
return cpu_info.takeError();
|
||||
@ -646,14 +646,14 @@ Expected<json::Value> IntelPTManager::GetState() const {
|
||||
}
|
||||
|
||||
Expected<const IntelPTThreadTrace &>
|
||||
IntelPTManager::GetTracedThread(lldb::tid_t tid) const {
|
||||
IntelPTCollector::GetTracedThread(lldb::tid_t tid) const {
|
||||
if (IsProcessTracingEnabled() && m_process_trace->TracesThread(tid))
|
||||
return m_process_trace->GetThreadTraces().GetTracedThread(tid);
|
||||
return m_thread_traces.GetTracedThread(tid);
|
||||
}
|
||||
|
||||
Expected<std::vector<uint8_t>>
|
||||
IntelPTManager::GetBinaryData(const TraceGetBinaryDataRequest &request) const {
|
||||
IntelPTCollector::GetBinaryData(const TraceGetBinaryDataRequest &request) const {
|
||||
if (request.kind == "threadTraceBuffer") {
|
||||
if (Expected<const IntelPTThreadTrace &> trace =
|
||||
GetTracedThread(*request.tid))
|
||||
@ -668,9 +668,9 @@ IntelPTManager::GetBinaryData(const TraceGetBinaryDataRequest &request) const {
|
||||
request.kind.c_str());
|
||||
}
|
||||
|
||||
void IntelPTManager::ClearProcessTracing() { m_process_trace = None; }
|
||||
void IntelPTCollector::ClearProcessTracing() { m_process_trace = None; }
|
||||
|
||||
bool IntelPTManager::IsSupported() {
|
||||
bool IntelPTCollector::IsSupported() {
|
||||
Expected<uint32_t> intel_pt_type = GetOSEventType();
|
||||
if (!intel_pt_type) {
|
||||
llvm::consumeError(intel_pt_type.takeError());
|
||||
@ -679,11 +679,11 @@ bool IntelPTManager::IsSupported() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IntelPTManager::IsProcessTracingEnabled() const {
|
||||
bool IntelPTCollector::IsProcessTracingEnabled() const {
|
||||
return (bool)m_process_trace;
|
||||
}
|
||||
|
||||
void IntelPTManager::Clear() {
|
||||
void IntelPTCollector::Clear() {
|
||||
ClearProcessTracing();
|
||||
m_thread_traces.Clear();
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
//===-- IntelPTManager.h -------------------------------------- -*- C++ -*-===//
|
||||
//===-- IntelPTCollector.h -------------------------------------- -*- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
@ -6,8 +6,8 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef liblldb_IntelPTManager_H_
|
||||
#define liblldb_IntelPTManager_H_
|
||||
#ifndef liblldb_IntelPTCollector_H_
|
||||
#define liblldb_IntelPTCollector_H_
|
||||
|
||||
#include "lldb/Utility/Status.h"
|
||||
#include "lldb/Utility/TraceIntelPTGDBRemotePackets.h"
|
||||
@ -203,9 +203,9 @@ private:
|
||||
};
|
||||
|
||||
/// Main class that manages intel-pt process and thread tracing.
|
||||
class IntelPTManager {
|
||||
class IntelPTCollector {
|
||||
public:
|
||||
IntelPTManager(lldb::pid_t pid) : m_pid(pid), m_thread_traces(pid) {}
|
||||
IntelPTCollector(lldb::pid_t pid) : m_pid(pid), m_thread_traces(pid) {}
|
||||
|
||||
static bool IsSupported();
|
||||
|
||||
@ -260,4 +260,4 @@ private:
|
||||
} // namespace process_linux
|
||||
} // namespace lldb_private
|
||||
|
||||
#endif // liblldb_IntelPTManager_H_
|
||||
#endif // liblldb_IntelPTCollector_H_
|
@ -312,7 +312,7 @@ NativeProcessLinux::NativeProcessLinux(::pid_t pid, int terminal_fd,
|
||||
const ArchSpec &arch, MainLoop &mainloop,
|
||||
llvm::ArrayRef<::pid_t> tids)
|
||||
: NativeProcessELF(pid, terminal_fd, delegate), m_arch(arch),
|
||||
m_main_loop(mainloop), m_intel_pt_manager(pid) {
|
||||
m_main_loop(mainloop), m_intel_pt_collector(pid) {
|
||||
if (m_terminal_fd != -1) {
|
||||
Status status = EnsureFDFlags(m_terminal_fd, O_NONBLOCK);
|
||||
assert(status.Success());
|
||||
@ -983,7 +983,7 @@ Status NativeProcessLinux::Detach() {
|
||||
e; // Save the error, but still attempt to detach from other threads.
|
||||
}
|
||||
|
||||
m_intel_pt_manager.Clear();
|
||||
m_intel_pt_collector.Clear();
|
||||
|
||||
return error;
|
||||
}
|
||||
@ -1666,7 +1666,7 @@ void NativeProcessLinux::StopTrackingThread(NativeThreadLinux &thread) {
|
||||
|
||||
Status NativeProcessLinux::NotifyTracersOfNewThread(lldb::tid_t tid) {
|
||||
Log *log = GetLog(POSIXLog::Thread);
|
||||
Status error(m_intel_pt_manager.OnThreadCreated(tid));
|
||||
Status error(m_intel_pt_collector.OnThreadCreated(tid));
|
||||
if (error.Fail())
|
||||
LLDB_LOG(log, "Failed to trace a new thread with intel-pt, tid = {0}. {1}",
|
||||
tid, error.AsCString());
|
||||
@ -1675,7 +1675,7 @@ Status NativeProcessLinux::NotifyTracersOfNewThread(lldb::tid_t tid) {
|
||||
|
||||
Status NativeProcessLinux::NotifyTracersOfThreadDestroyed(lldb::tid_t tid) {
|
||||
Log *log = GetLog(POSIXLog::Thread);
|
||||
Status error(m_intel_pt_manager.OnThreadDestroyed(tid));
|
||||
Status error(m_intel_pt_collector.OnThreadDestroyed(tid));
|
||||
if (error.Fail())
|
||||
LLDB_LOG(log,
|
||||
"Failed to stop a destroyed thread with intel-pt, tid = {0}. {1}",
|
||||
@ -1938,7 +1938,7 @@ Status NativeProcessLinux::PtraceWrapper(int req, lldb::pid_t pid, void *addr,
|
||||
}
|
||||
|
||||
llvm::Expected<TraceSupportedResponse> NativeProcessLinux::TraceSupported() {
|
||||
if (IntelPTManager::IsSupported())
|
||||
if (IntelPTCollector::IsSupported())
|
||||
return TraceSupportedResponse{"intel-pt", "Intel Processor Trace"};
|
||||
return NativeProcessProtocol::TraceSupported();
|
||||
}
|
||||
@ -1951,7 +1951,7 @@ Error NativeProcessLinux::TraceStart(StringRef json_request, StringRef type) {
|
||||
std::vector<lldb::tid_t> process_threads;
|
||||
for (auto &thread : m_threads)
|
||||
process_threads.push_back(thread->GetID());
|
||||
return m_intel_pt_manager.TraceStart(*request, process_threads);
|
||||
return m_intel_pt_collector.TraceStart(*request, process_threads);
|
||||
} else
|
||||
return request.takeError();
|
||||
}
|
||||
@ -1961,19 +1961,19 @@ Error NativeProcessLinux::TraceStart(StringRef json_request, StringRef type) {
|
||||
|
||||
Error NativeProcessLinux::TraceStop(const TraceStopRequest &request) {
|
||||
if (request.type == "intel-pt")
|
||||
return m_intel_pt_manager.TraceStop(request);
|
||||
return m_intel_pt_collector.TraceStop(request);
|
||||
return NativeProcessProtocol::TraceStop(request);
|
||||
}
|
||||
|
||||
Expected<json::Value> NativeProcessLinux::TraceGetState(StringRef type) {
|
||||
if (type == "intel-pt")
|
||||
return m_intel_pt_manager.GetState();
|
||||
return m_intel_pt_collector.GetState();
|
||||
return NativeProcessProtocol::TraceGetState(type);
|
||||
}
|
||||
|
||||
Expected<std::vector<uint8_t>> NativeProcessLinux::TraceGetBinaryData(
|
||||
const TraceGetBinaryDataRequest &request) {
|
||||
if (request.type == "intel-pt")
|
||||
return m_intel_pt_manager.GetBinaryData(request);
|
||||
return m_intel_pt_collector.GetBinaryData(request);
|
||||
return NativeProcessProtocol::TraceGetBinaryData(request);
|
||||
}
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include "lldb/Utility/FileSpec.h"
|
||||
#include "lldb/lldb-types.h"
|
||||
|
||||
#include "IntelPTManager.h"
|
||||
#include "IntelPTCollector.h"
|
||||
#include "NativeThreadLinux.h"
|
||||
#include "Plugins/Process/POSIX/NativeProcessELF.h"
|
||||
#include "Plugins/Process/Utility/NativeProcessSoftwareSingleStep.h"
|
||||
@ -241,7 +241,7 @@ private:
|
||||
Status PopulateMemoryRegionCache();
|
||||
|
||||
/// Manages Intel PT process and thread traces.
|
||||
IntelPTManager m_intel_pt_manager;
|
||||
IntelPTCollector m_intel_pt_collector;
|
||||
|
||||
// Handle a clone()-like event.
|
||||
bool MonitorClone(NativeThreadLinux &parent, lldb::pid_t child_pid,
|
||||
|
@ -85,8 +85,11 @@ lldb::addr_t TraceCursorIntelPT::GetLoadAddress() {
|
||||
return m_decoded_thread_sp->GetInstructions()[m_pos].GetLoadAddress();
|
||||
}
|
||||
|
||||
Optional<uint64_t> TraceCursorIntelPT::GetTimestampCounter() {
|
||||
return m_decoded_thread_sp->GetInstructions()[m_pos].GetTimestampCounter();
|
||||
Optional<uint64_t> TraceCursorIntelPT::GetCounter(lldb::TraceCounter counter_type) {
|
||||
switch (counter_type) {
|
||||
case lldb::eTraceCounterTSC:
|
||||
return m_decoded_thread_sp->GetInstructions()[m_pos].GetTimestampCounter();
|
||||
}
|
||||
}
|
||||
|
||||
TraceInstructionControlFlowType
|
||||
|
@ -28,7 +28,7 @@ public:
|
||||
|
||||
lldb::addr_t GetLoadAddress() override;
|
||||
|
||||
llvm::Optional<uint64_t> GetTimestampCounter() override;
|
||||
llvm::Optional<uint64_t> GetCounter(lldb::TraceCounter counter_type) override;
|
||||
|
||||
lldb::TraceInstructionControlFlowType
|
||||
GetInstructionControlFlowType() override;
|
||||
|
@ -183,7 +183,7 @@ void TraceInstructionDumper::DumpInstructions(Stream &s, size_t count) {
|
||||
if (m_show_tsc) {
|
||||
s.Printf("[tsc=");
|
||||
|
||||
if (Optional<uint64_t> timestamp = m_cursor_up->GetTimestampCounter())
|
||||
if (Optional<uint64_t> timestamp = m_cursor_up->GetCounter(lldb::eTraceCounterTSC))
|
||||
s.Printf("0x%016" PRIx64, *timestamp);
|
||||
else
|
||||
s.Printf("unavailable");
|
||||
|
@ -1,5 +1,5 @@
|
||||
add_lldb_unittest(TraceIntelPTTests
|
||||
IntelPTManagerTests.cpp
|
||||
IntelPTCollectorTests.cpp
|
||||
|
||||
LINK_LIBS
|
||||
lldbPluginProcessLinux
|
||||
|
@ -1,4 +1,4 @@
|
||||
//===-- IntelPTManagerTests.cpp -------------------------------------------===//
|
||||
//===-- IntelPTCollectorTests.cpp -------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "IntelPTManager.h"
|
||||
#include "IntelPTCollector.h"
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user