LLDB mainline
CommandObjectThreadUtil.h
Go to the documentation of this file.
1//===-- CommandObjectThreadUtil.h -------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SOURCE_COMMANDS_COMMANDOBJECTTHREADUTIL_H
10#define LLDB_SOURCE_COMMANDS_COMMANDOBJECTTHREADUTIL_H
11
13
14namespace lldb_private {
15
17
19 public:
20 UniqueStack(std::stack<lldb::addr_t> stack_frames, uint32_t thread_index_id)
21 : m_stack_frames(stack_frames) {
22 m_thread_index_ids.push_back(thread_index_id);
23 }
24
25 void AddThread(uint32_t thread_index_id) const {
26 m_thread_index_ids.push_back(thread_index_id);
27 }
28
29 const std::vector<uint32_t> &GetUniqueThreadIndexIDs() const {
30 return m_thread_index_ids;
31 }
32
34 return m_thread_index_ids.front();
35 }
36
37 friend bool inline operator<(const UniqueStack &lhs,
38 const UniqueStack &rhs) {
39 return lhs.m_stack_frames < rhs.m_stack_frames;
40 }
41
42 protected:
43 // Mark the thread index as mutable, as we don't care about it from a const
44 // perspective, we only care about m_stack_frames so we keep our std::set
45 // sorted.
46 mutable std::vector<uint32_t> m_thread_index_ids;
47 std::stack<lldb::addr_t> m_stack_frames;
48 };
49
50public:
52 const char *name, const char *help,
53 const char *syntax, uint32_t flags);
54
56
57 void DoExecute(Args &command, CommandReturnObject &result) override;
58
59protected:
60 // Override this to do whatever you need to do for one thread.
61 //
62 // If you return false, the iteration will stop, otherwise it will proceed.
63 // The result is set to m_success_return (defaults to
64 // eReturnStatusSuccessFinishResult) before the iteration, so you only need
65 // to set the return status in HandleOneThread if you want to indicate an
66 // error. If m_add_return is true, a blank line will be inserted between each
67 // of the listings (except the last one.)
68
70
71 bool BucketThread(lldb::tid_t tid, std::set<UniqueStack> &unique_stacks,
72 CommandReturnObject &result);
73
75 bool m_unique_stacks = false;
76 bool m_add_return = true;
77};
78
79/// Class similar to \a CommandObjectIterateOverThreads, but which performs
80/// an action on multiple threads at once instead of iterating over each thread.
82public:
84 const char *name, const char *help,
85 const char *syntax, uint32_t flags);
86
87 void DoExecute(Args &command, CommandReturnObject &result) override;
88
89protected:
90 /// Method that handles the command after the main arguments have been parsed.
91 ///
92 /// \param[in] tids
93 /// The thread ids passed as arguments.
94 ///
95 /// \return
96 /// A boolean result similar to the one expected from \a DoExecute.
97 virtual bool DoExecuteOnThreads(Args &command, CommandReturnObject &result,
98 llvm::ArrayRef<lldb::tid_t> tids) = 0;
99};
100
101} // namespace lldb_private
102
103#endif // LLDB_SOURCE_COMMANDS_COMMANDOBJECTTHREADUTIL_H
A command line argument class.
Definition: Args.h:33
UniqueStack(std::stack< lldb::addr_t > stack_frames, uint32_t thread_index_id)
friend bool operator<(const UniqueStack &lhs, const UniqueStack &rhs)
const std::vector< uint32_t > & GetUniqueThreadIndexIDs() const
bool BucketThread(lldb::tid_t tid, std::set< UniqueStack > &unique_stacks, CommandReturnObject &result)
virtual bool HandleOneThread(lldb::tid_t, CommandReturnObject &result)=0
void DoExecute(Args &command, CommandReturnObject &result) override
Class similar to CommandObjectIterateOverThreads, but which performs an action on multiple threads at...
virtual bool DoExecuteOnThreads(Args &command, CommandReturnObject &result, llvm::ArrayRef< lldb::tid_t > tids)=0
Method that handles the command after the main arguments have been parsed.
void DoExecute(Args &command, CommandReturnObject &result) override
A class that represents a running process on the host machine.
ReturnStatus
Command Return Status Types.
@ eReturnStatusSuccessFinishResult
uint64_t tid_t
Definition: lldb-types.h:84