aboutsummaryrefslogtreecommitdiff
path: root/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h
blob: d2fd70042ccc95a6b27d1239e326fc4f9d99dac2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//===-- GDBRemoteCommunicationServerCommon.h --------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef liblldb_GDBRemoteCommunicationServerCommon_h_
#define liblldb_GDBRemoteCommunicationServerCommon_h_

// C Includes
// C++ Includes
#include <string>

// Other libraries and framework includes
// Project includes
#include "lldb/lldb-private-forward.h"
#include "lldb/Target/Process.h"

#include "GDBRemoteCommunicationServer.h"
#include "GDBRemoteCommunicationServerCommon.h"

class StringExtractorGDBRemote;

namespace lldb_private {
namespace process_gdb_remote {

class ProcessGDBRemote;

class GDBRemoteCommunicationServerCommon :
    public GDBRemoteCommunicationServer
{
public:
    GDBRemoteCommunicationServerCommon(const char *comm_name, const char *listener_name);

    ~GDBRemoteCommunicationServerCommon() override;

protected:
    ProcessLaunchInfo m_process_launch_info;
    Error m_process_launch_error;
    ProcessInstanceInfoList m_proc_infos;
    uint32_t m_proc_infos_index;
    bool m_thread_suffix_supported;
    bool m_list_threads_in_stop_reply;

    PacketResult
    Handle_A (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_qHostInfo (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_qProcessInfoPID (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_qfProcessInfo (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_qsProcessInfo (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_qUserName (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_qGroupName (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_qSpeedTest (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_vFile_Open (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_vFile_Close (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_vFile_pRead (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_vFile_pWrite (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_vFile_Size (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_vFile_Mode (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_vFile_Exists (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_vFile_symlink (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_vFile_unlink (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_vFile_Stat (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_vFile_MD5 (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_qEcho (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_qModuleInfo (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_qPlatform_shell (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_qPlatform_mkdir (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_qPlatform_chmod (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_qSupported (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_QThreadSuffixSupported (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_QListThreadsInStopReply (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_QSetDetachOnError (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_QStartNoAckMode (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_QSetSTDIN (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_QSetSTDOUT (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_QSetSTDERR (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_qLaunchSuccess (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_QEnvironment (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_QEnvironmentHexEncoded (StringExtractorGDBRemote &packet);

    PacketResult
    Handle_QLaunchArch (StringExtractorGDBRemote &packet);

    static void
    CreateProcessInfoResponse (const ProcessInstanceInfo &proc_info,
                               StreamString &response);

    static void
    CreateProcessInfoResponse_DebugServerStyle (const ProcessInstanceInfo &proc_info,
                                                StreamString &response);

    template <typename T>
    void
    RegisterMemberFunctionHandler (StringExtractorGDBRemote::ServerPacketType packet_type,
                                   PacketResult (T::*handler) (StringExtractorGDBRemote& packet))
    {
        RegisterPacketHandler(packet_type,
                              [this, handler] (StringExtractorGDBRemote packet,
                                               Error &error,
                                               bool &interrupt,
                                               bool &quit)
                              {
                                  return (static_cast<T*>(this)->*handler) (packet);
                              });
    }

    bool
    GetThreadSuffixSupported () override
    {
        return true;
    }

    //------------------------------------------------------------------
    /// Launch a process with the current launch settings.
    ///
    /// This method supports running an lldb-gdbserver or similar
    /// server in a situation where the startup code has been provided
    /// with all the information for a child process to be launched.
    ///
    /// @return
    ///     An Error object indicating the success or failure of the
    ///     launch.
    //------------------------------------------------------------------
    virtual Error
    LaunchProcess () = 0;

    virtual FileSpec
    FindModuleFile (const std::string& module_path, const ArchSpec& arch);
};

} // namespace process_gdb_remote
} // namespace lldb_private

#endif // liblldb_GDBRemoteCommunicationServerCommon_h_