
Depends on D90490. The stop command is simple and invokes the new method Trace::StopTracingThread(thread). On the other hand, the start command works by delegating its implementation to a CommandObject provided by the Trace plugin. This is necessary because each trace plugin needs different options for this command. There's even the chance that a Trace plugin can't support live tracing, but instead supports offline decoding and analysis, which means that "thread trace dump instructions" works but "thread trace start" doest. Because of this and a few other reasons, it's better to have each plugin provide this implementation. Besides, I'm using the GetSupportedTraceType method introduced in D90490 to quickly infer what's the trace plug-in that works for the current process. As an implementation note, I moved CommandObjectIterateOverThreads to its header so that I can use it from the IntelPT plugin. Besides, the actual start and stop logic for intel-pt is not part of this diff. Reviewed By: clayborg Differential Revision: https://reviews.llvm.org/D90729
82 lines
2.8 KiB
C++
82 lines
2.8 KiB
C++
//===-- CommandObjectThreadUtil.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.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLDB_SOURCE_COMMANDS_COMMANDOBJECTTHREADUTIL_H
|
|
#define LLDB_SOURCE_COMMANDS_COMMANDOBJECTTHREADUTIL_H
|
|
|
|
#include "lldb/Interpreter/CommandObjectMultiword.h"
|
|
|
|
namespace lldb_private {
|
|
|
|
class CommandObjectIterateOverThreads : public CommandObjectParsed {
|
|
|
|
class UniqueStack {
|
|
public:
|
|
UniqueStack(std::stack<lldb::addr_t> stack_frames, uint32_t thread_index_id)
|
|
: m_stack_frames(stack_frames) {
|
|
m_thread_index_ids.push_back(thread_index_id);
|
|
}
|
|
|
|
void AddThread(uint32_t thread_index_id) const {
|
|
m_thread_index_ids.push_back(thread_index_id);
|
|
}
|
|
|
|
const std::vector<uint32_t> &GetUniqueThreadIndexIDs() const {
|
|
return m_thread_index_ids;
|
|
}
|
|
|
|
lldb::tid_t GetRepresentativeThread() const {
|
|
return m_thread_index_ids.front();
|
|
}
|
|
|
|
friend bool inline operator<(const UniqueStack &lhs,
|
|
const UniqueStack &rhs) {
|
|
return lhs.m_stack_frames < rhs.m_stack_frames;
|
|
}
|
|
|
|
protected:
|
|
// Mark the thread index as mutable, as we don't care about it from a const
|
|
// perspective, we only care about m_stack_frames so we keep our std::set
|
|
// sorted.
|
|
mutable std::vector<uint32_t> m_thread_index_ids;
|
|
std::stack<lldb::addr_t> m_stack_frames;
|
|
};
|
|
|
|
public:
|
|
CommandObjectIterateOverThreads(CommandInterpreter &interpreter,
|
|
const char *name, const char *help,
|
|
const char *syntax, uint32_t flags);
|
|
|
|
~CommandObjectIterateOverThreads() override = default;
|
|
|
|
bool DoExecute(Args &command, CommandReturnObject &result) override;
|
|
|
|
protected:
|
|
// Override this to do whatever you need to do for one thread.
|
|
//
|
|
// If you return false, the iteration will stop, otherwise it will proceed.
|
|
// The result is set to m_success_return (defaults to
|
|
// eReturnStatusSuccessFinishResult) before the iteration, so you only need
|
|
// to set the return status in HandleOneThread if you want to indicate an
|
|
// error. If m_add_return is true, a blank line will be inserted between each
|
|
// of the listings (except the last one.)
|
|
|
|
virtual bool HandleOneThread(lldb::tid_t, CommandReturnObject &result) = 0;
|
|
|
|
bool BucketThread(lldb::tid_t tid, std::set<UniqueStack> &unique_stacks,
|
|
CommandReturnObject &result);
|
|
|
|
lldb::ReturnStatus m_success_return = lldb::eReturnStatusSuccessFinishResult;
|
|
bool m_unique_stacks = false;
|
|
bool m_add_return = true;
|
|
};
|
|
|
|
} // namespace lldb_private
|
|
|
|
#endif // LLDB_SOURCE_COMMANDS_COMMANDOBJECTTHREADUTIL_H
|