1 | //===-- ProtocolUtils.h ---------------------------------------------------===// |
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 | // This file contains Utility function for protocol objects. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #ifndef LLDB_TOOLS_LLDB_DAP_PROTOCOL_PROTOCOL_UTILS_H |
14 | #define LLDB_TOOLS_LLDB_DAP_PROTOCOL_PROTOCOL_UTILS_H |
15 | |
16 | #include "Protocol/ProtocolTypes.h" |
17 | |
18 | #include "lldb/API/SBAddress.h" |
19 | |
20 | namespace lldb_dap { |
21 | |
22 | /// Create a "Source" JSON object as described in the debug adapter definition. |
23 | /// |
24 | /// \param[in] file |
25 | /// The SBFileSpec to use when populating out the "Source" object |
26 | /// |
27 | /// \return |
28 | /// A "Source" JSON object that follows the formal JSON |
29 | /// definition outlined by Microsoft. |
30 | protocol::Source CreateSource(const lldb::SBFileSpec &file); |
31 | |
32 | /// Create a "Source" JSON object as described in the debug adapter definition. |
33 | /// |
34 | /// \param[in] address |
35 | /// The address to use when populating out the "Source" object. |
36 | /// |
37 | /// \param[in] target |
38 | /// The target that has the address. |
39 | /// |
40 | /// \return |
41 | /// A "Source" JSON object that follows the formal JSON |
42 | /// definition outlined by Microsoft. |
43 | protocol::Source CreateSource(lldb::SBAddress address, lldb::SBTarget &target); |
44 | |
45 | /// Checks if the given source is for assembly code. |
46 | bool IsAssemblySource(const protocol::Source &source); |
47 | |
48 | /// Get the address as a 16-digit hex string, e.g. "0x0000000000012345" |
49 | std::string GetLoadAddressString(const lldb::addr_t addr); |
50 | |
51 | /// Create a "Thread" object for a LLDB thread object. |
52 | /// |
53 | /// This function will fill in the following keys in the returned |
54 | /// object: |
55 | /// "id" - the thread ID as an integer |
56 | /// "name" - the thread name as a string which combines the LLDB |
57 | /// thread index ID along with the string name of the thread |
58 | /// from the OS if it has a name. |
59 | /// |
60 | /// \param[in] thread |
61 | /// The LLDB thread to use when populating out the "Thread" |
62 | /// object. |
63 | /// |
64 | /// \param[in] format |
65 | /// The LLDB format to use when populating out the "Thread" |
66 | /// object. |
67 | /// |
68 | /// \return |
69 | /// A "Thread" JSON object with that follows the formal JSON |
70 | /// definition outlined by Microsoft. |
71 | protocol::Thread CreateThread(lldb::SBThread &thread, lldb::SBFormat &format); |
72 | |
73 | /// Returns the set of threads associated with the process. |
74 | std::vector<protocol::Thread> GetThreads(lldb::SBProcess process, |
75 | lldb::SBFormat &format); |
76 | |
77 | } // namespace lldb_dap |
78 | |
79 | #endif |
80 | |