blob: 2e4ff70cf2d947e3bb9150dfecc55d1810d92343 [file] [log] [blame]
Greg Clayton61d043b2011-03-22 04:00:09 +00001//===-- GDBRemoteCommunicationServer.cpp ------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10
11#include "GDBRemoteCommunicationServer.h"
12
13// C Includes
14// C++ Includes
15// Other libraries and framework includes
16#include "llvm/ADT/Triple.h"
17#include "lldb/Interpreter/Args.h"
18#include "lldb/Core/ConnectionFileDescriptor.h"
19#include "lldb/Core/Log.h"
20#include "lldb/Core/State.h"
21#include "lldb/Core/StreamString.h"
22#include "lldb/Host/Host.h"
23#include "lldb/Host/TimeValue.h"
24
25// Project includes
26#include "Utility/StringExtractorGDBRemote.h"
27#include "ProcessGDBRemote.h"
28#include "ProcessGDBRemoteLog.h"
29
30using namespace lldb;
31using namespace lldb_private;
32
33//----------------------------------------------------------------------
34// GDBRemoteCommunicationServer constructor
35//----------------------------------------------------------------------
36GDBRemoteCommunicationServer::GDBRemoteCommunicationServer() :
37 GDBRemoteCommunication ("gdb-remote.server", "gdb-remote.server.rx_packet"),
38 m_async_thread (LLDB_INVALID_HOST_THREAD),
39 m_send_acks (true)
40{
41}
42
43//----------------------------------------------------------------------
44// Destructor
45//----------------------------------------------------------------------
46GDBRemoteCommunicationServer::~GDBRemoteCommunicationServer()
47{
48}
49
50
51//void *
52//GDBRemoteCommunicationServer::AsyncThread (void *arg)
53//{
54// GDBRemoteCommunicationServer *server = (GDBRemoteCommunicationServer*) arg;
55//
56// LogSP log;// (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS));
57// if (log)
58// log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %i) thread starting...", __FUNCTION__, arg, process->GetID());
59//
60// StringExtractorGDBRemote packet;
61//
62// while ()
63// {
64// if (packet.
65// }
66//
67// if (log)
68// log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %i) thread exiting...", __FUNCTION__, arg, process->GetID());
69//
70// process->m_async_thread = LLDB_INVALID_HOST_THREAD;
71// return NULL;
72//}
73//
74bool
75GDBRemoteCommunicationServer::GetPacketAndSendResponse (const TimeValue* timeout_time_ptr)
76{
77 StringExtractorGDBRemote packet;
78 if (WaitForPacketNoLock (packet, timeout_time_ptr))
79 {
80 const StringExtractorGDBRemote::ServerPacketType packet_type = packet.GetServerPacketType ();
81 switch (packet_type)
82 {
83 case StringExtractorGDBRemote::eServerPacketType_nack:
84 case StringExtractorGDBRemote::eServerPacketType_ack:
85 break;
86
87 case StringExtractorGDBRemote::eServerPacketType_invalid:
88 case StringExtractorGDBRemote::eServerPacketType_unimplemented:
89 return SendUnimplementedResponse () > 0;
90
91 case StringExtractorGDBRemote::eServerPacketType_qHostInfo:
92 return Handle_qHostInfo ();
93 }
94 return true;
95 }
96 return false;
97}
98
99size_t
100GDBRemoteCommunicationServer::SendUnimplementedResponse ()
101{
102 return SendPacket ("");
103}
104
105
106bool
107GDBRemoteCommunicationServer::Handle_qHostInfo ()
108{
109 StreamString response;
110
111 // $cputype:16777223;cpusubtype:3;ostype:Darwin;vendor:apple;endian:little;ptrsize:8;#00
112
113 ArchSpec host_arch (Host::GetArchitecture ());
114
115 const llvm::Triple &host_triple = host_arch.GetTriple();
116 const llvm::StringRef arch_name (host_triple.getArchName());
117 const llvm::StringRef vendor_name (host_triple.getOSName());
118 const llvm::StringRef os_name (host_triple.getVendorName());
119 response.Printf ("arch:%.*s;ostype:%.*s;vendor:%.*s;ptrsize:%u",
120 (int)arch_name.size(), arch_name.data(),
121 (int)os_name.size(), os_name.data(),
122 (int)vendor_name.size(), vendor_name.data(),
123 host_arch.GetAddressByteSize());
124
125 switch (lldb::endian::InlHostByteOrder())
126 {
127 case eByteOrderBig: response.PutCString ("endian:big;"); break;
128 case eByteOrderLittle: response.PutCString ("endian:little;"); break;
129 case eByteOrderPDP: response.PutCString ("endian:pdp;"); break;
130 default: response.PutCString ("endian:unknown;"); break;
131 }
132
133 return SendPacket (response.GetString().c_str(),response.GetString().size()) > 0;
134}