[Lldb-commits] [lldb] 2207762 - Minor refactor and renaming:
Jakob Johnson via lldb-commits
lldb-commits at lists.llvm.org
Wed Mar 16 15:36:00 PDT 2022
Author: Jakob Johnson
Date: 2022-03-16T15:35:36-07:00
New Revision: 22077627ae20d5a6e50f43337e8ad2e23f1fa3ff
URL: https://github.com/llvm/llvm-project/commit/22077627ae20d5a6e50f43337e8ad2e23f1fa3ff
DIFF: https://github.com/llvm/llvm-project/commit/22077627ae20d5a6e50f43337e8ad2e23f1fa3ff.diff
LOG: 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
Added:
lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp
lldb/source/Plugins/Process/Linux/IntelPTCollector.h
lldb/unittests/Process/Linux/IntelPTCollectorTests.cpp
Modified:
lldb/include/lldb/Target/TraceCursor.h
lldb/include/lldb/lldb-enumerations.h
lldb/source/Plugins/Process/Linux/CMakeLists.txt
lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
lldb/source/Plugins/Process/Linux/NativeProcessLinux.h
lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.h
lldb/source/Target/TraceInstructionDumper.cpp
lldb/unittests/Process/Linux/CMakeLists.txt
Removed:
lldb/source/Plugins/Process/Linux/IntelPTManager.cpp
lldb/source/Plugins/Process/Linux/IntelPTManager.h
lldb/unittests/Process/Linux/IntelPTManagerTests.cpp
################################################################################
diff --git a/lldb/include/lldb/Target/TraceCursor.h b/lldb/include/lldb/Target/TraceCursor.h
index 14fc00d5f95b1..83ab22b367c53 100644
--- a/lldb/include/lldb/Target/TraceCursor.h
+++ b/lldb/include/lldb/Target/TraceCursor.h
@@ -180,14 +180,16 @@ class TraceCursor {
/// 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
diff erent time unit instead of an
- /// actual TSC.
+ /// Get the hardware counter of a given type associated with the current
+ /// instruction. Each architecture might support
diff erent 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
diff --git a/lldb/include/lldb/lldb-enumerations.h b/lldb/include/lldb/lldb-enumerations.h
index 529ab001a761f..294c68d54fd0c 100644
--- a/lldb/include/lldb/lldb-enumerations.h
+++ b/lldb/include/lldb/lldb-enumerations.h
@@ -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
diff --git a/lldb/source/Plugins/Process/Linux/CMakeLists.txt b/lldb/source/Plugins/Process/Linux/CMakeLists.txt
index c4edc57a8a2d8..60958bb913960 100644
--- a/lldb/source/Plugins/Process/Linux/CMakeLists.txt
+++ b/lldb/source/Plugins/Process/Linux/CMakeLists.txt
@@ -1,5 +1,5 @@
add_lldb_library(lldbPluginProcessLinux
- IntelPTManager.cpp
+ IntelPTCollector.cpp
NativeProcessLinux.cpp
NativeRegisterContextLinux.cpp
NativeRegisterContextLinux_arm.cpp
diff --git a/lldb/source/Plugins/Process/Linux/IntelPTManager.cpp b/lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp
similarity index 96%
rename from lldb/source/Plugins/Process/Linux/IntelPTManager.cpp
rename to lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp
index 794689b1d3791..0e65c88a1f765 100644
--- a/lldb/source/Plugins/Process/Linux/IntelPTManager.cpp
+++ b/lldb/source/Plugins/Process/Linux/IntelPTCollector.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();
}
diff --git a/lldb/source/Plugins/Process/Linux/IntelPTManager.h b/lldb/source/Plugins/Process/Linux/IntelPTCollector.h
similarity index 96%
rename from lldb/source/Plugins/Process/Linux/IntelPTManager.h
rename to lldb/source/Plugins/Process/Linux/IntelPTCollector.h
index 38566a221077a..051b1ad285336 100644
--- a/lldb/source/Plugins/Process/Linux/IntelPTManager.h
+++ b/lldb/source/Plugins/Process/Linux/IntelPTCollector.h
@@ -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 @@ class IntelPTProcessTrace {
};
/// 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 @@ class IntelPTManager {
} // namespace process_linux
} // namespace lldb_private
-#endif // liblldb_IntelPTManager_H_
+#endif // liblldb_IntelPTCollector_H_
diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
index 1930af683b63a..4bc5711453939 100644
--- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -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);
}
diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.h b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.h
index 407062ad0b462..368b4a3861ef0 100644
--- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.h
+++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.h
@@ -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 @@ class NativeProcessLinux : public NativeProcessELF,
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,
diff --git a/lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp b/lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
index edefdd0d3486e..f6b26e0231e98 100644
--- a/lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
+++ b/lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
@@ -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
diff --git a/lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.h b/lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.h
index 29d3792bb489e..8ec55941f005f 100644
--- a/lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.h
+++ b/lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.h
@@ -28,7 +28,7 @@ class TraceCursorIntelPT : public TraceCursor {
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;
diff --git a/lldb/source/Target/TraceInstructionDumper.cpp b/lldb/source/Target/TraceInstructionDumper.cpp
index d58d2dff7383a..20b3a4733dd37 100644
--- a/lldb/source/Target/TraceInstructionDumper.cpp
+++ b/lldb/source/Target/TraceInstructionDumper.cpp
@@ -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");
diff --git a/lldb/unittests/Process/Linux/CMakeLists.txt b/lldb/unittests/Process/Linux/CMakeLists.txt
index ae021023cf7f5..81f1e4bc5e7e6 100644
--- a/lldb/unittests/Process/Linux/CMakeLists.txt
+++ b/lldb/unittests/Process/Linux/CMakeLists.txt
@@ -1,5 +1,5 @@
add_lldb_unittest(TraceIntelPTTests
- IntelPTManagerTests.cpp
+ IntelPTCollectorTests.cpp
LINK_LIBS
lldbPluginProcessLinux
diff --git a/lldb/unittests/Process/Linux/IntelPTManagerTests.cpp b/lldb/unittests/Process/Linux/IntelPTCollectorTests.cpp
similarity index 97%
rename from lldb/unittests/Process/Linux/IntelPTManagerTests.cpp
rename to lldb/unittests/Process/Linux/IntelPTCollectorTests.cpp
index 76eb78a51935d..392961b222bf5 100644
--- a/lldb/unittests/Process/Linux/IntelPTManagerTests.cpp
+++ b/lldb/unittests/Process/Linux/IntelPTCollectorTests.cpp
@@ -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"
More information about the lldb-commits
mailing list