/src/CMake/Source/cmDebuggerThreadManager.cxx
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | |
4 | | #include "cmDebuggerThreadManager.h" |
5 | | |
6 | | #include <algorithm> |
7 | | |
8 | | #include <cm/optional> |
9 | | |
10 | | #include <cm3p/cppdap/optional.h> |
11 | | #include <cm3p/cppdap/protocol.h> |
12 | | #include <cm3p/cppdap/types.h> |
13 | | |
14 | | #include "cmDebuggerThread.h" |
15 | | |
16 | | namespace cmDebugger { |
17 | | |
18 | | std::atomic<int64_t> cmDebuggerThreadManager::NextThreadId(1); |
19 | | |
20 | | std::shared_ptr<cmDebuggerThread> cmDebuggerThreadManager::StartThread( |
21 | | std::string const& name) |
22 | 0 | { |
23 | 0 | std::shared_ptr<cmDebuggerThread> thread = |
24 | 0 | std::make_shared<cmDebuggerThread>( |
25 | 0 | cmDebuggerThreadManager::NextThreadId.fetch_add(1), name); |
26 | 0 | Threads.emplace_back(thread); |
27 | 0 | return thread; |
28 | 0 | } |
29 | | |
30 | | void cmDebuggerThreadManager::EndThread( |
31 | | std::shared_ptr<cmDebuggerThread> const& thread) |
32 | 0 | { |
33 | 0 | Threads.remove(thread); |
34 | 0 | } |
35 | | |
36 | | cm::optional<dap::StackTraceResponse> |
37 | | cmDebuggerThreadManager::GetThreadStackTraceResponse( |
38 | | dap::StackTraceRequest const& request) |
39 | 0 | { |
40 | 0 | auto it = find_if(Threads.begin(), Threads.end(), |
41 | 0 | [&](std::shared_ptr<cmDebuggerThread> const& t) { |
42 | 0 | return t->GetId() == request.threadId; |
43 | 0 | }); |
44 | |
|
45 | 0 | if (it == Threads.end()) { |
46 | 0 | return {}; |
47 | 0 | } |
48 | | |
49 | 0 | return GetStackTraceResponse(*it, request.format); |
50 | 0 | } |
51 | | |
52 | | } // namespace cmDebugger |