53 lines · cpp
1//===-- ThreadsRequestHandler.cpp -----------------------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "DAP.h"10#include "EventHelper.h"11#include "Protocol/ProtocolRequests.h"12#include "ProtocolUtils.h"13#include "RequestHandler.h"14#include "lldb/API/SBDebugger.h"15#include "lldb/API/SBDefines.h"16#include "llvm/Support/Error.h"17#include "llvm/Support/raw_ostream.h"18 19using namespace llvm;20using namespace lldb_dap::protocol;21 22namespace lldb_dap {23 24/// The request retrieves a list of all threads.25Expected<ThreadsResponseBody>26ThreadsRequestHandler::Run(const ThreadsArguments &) const {27 lldb::SBProcess process = dap.target.GetProcess();28 std::vector<Thread> threads;29 30 // Client requests the baseline of currently existing threads after31 // a successful launch or attach by sending a 'threads' request32 // right after receiving the configurationDone response.33 // If no thread has reported to the client, it prevents something34 // like the pause request from working in the running state.35 // Return the cache of initial threads as the process might have resumed36 if (!dap.initial_thread_list.empty()) {37 threads = dap.initial_thread_list;38 dap.initial_thread_list.clear();39 } else {40 if (!lldb::SBDebugger::StateIsStoppedState(process.GetState()))41 return make_error<NotStoppedError>();42 43 threads = GetThreads(process, dap.thread_format);44 }45 46 if (threads.size() == 0)47 return make_error<DAPError>("failed to retrieve threads from process");48 49 return ThreadsResponseBody{threads};50}51 52} // namespace lldb_dap53