Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1 | //===-- 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 | |
| 30 | using namespace lldb; |
| 31 | using namespace lldb_private; |
| 32 | |
| 33 | //---------------------------------------------------------------------- |
| 34 | // GDBRemoteCommunicationServer constructor |
| 35 | //---------------------------------------------------------------------- |
| 36 | GDBRemoteCommunicationServer::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 | //---------------------------------------------------------------------- |
| 46 | GDBRemoteCommunicationServer::~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 | // |
| 74 | bool |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 75 | GDBRemoteCommunicationServer::GetPacketAndSendResponse (const TimeValue* timeout_ptr, |
| 76 | bool &interrupt, |
| 77 | bool &quit) |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 78 | { |
| 79 | StringExtractorGDBRemote packet; |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 80 | if (WaitForPacketNoLock (packet, timeout_ptr)) |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 81 | { |
| 82 | const StringExtractorGDBRemote::ServerPacketType packet_type = packet.GetServerPacketType (); |
| 83 | switch (packet_type) |
| 84 | { |
| 85 | case StringExtractorGDBRemote::eServerPacketType_nack: |
| 86 | case StringExtractorGDBRemote::eServerPacketType_ack: |
| 87 | break; |
| 88 | |
| 89 | case StringExtractorGDBRemote::eServerPacketType_invalid: |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 90 | quit = true; |
| 91 | break; |
| 92 | |
| 93 | case StringExtractorGDBRemote::eServerPacketType_interrupt: |
| 94 | interrupt = true; |
| 95 | break; |
| 96 | |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 97 | case StringExtractorGDBRemote::eServerPacketType_unimplemented: |
| 98 | return SendUnimplementedResponse () > 0; |
| 99 | |
| 100 | case StringExtractorGDBRemote::eServerPacketType_qHostInfo: |
| 101 | return Handle_qHostInfo (); |
| 102 | } |
| 103 | return true; |
| 104 | } |
| 105 | return false; |
| 106 | } |
| 107 | |
| 108 | size_t |
| 109 | GDBRemoteCommunicationServer::SendUnimplementedResponse () |
| 110 | { |
| 111 | return SendPacket (""); |
| 112 | } |
| 113 | |
| 114 | |
| 115 | bool |
| 116 | GDBRemoteCommunicationServer::Handle_qHostInfo () |
| 117 | { |
| 118 | StreamString response; |
| 119 | |
| 120 | // $cputype:16777223;cpusubtype:3;ostype:Darwin;vendor:apple;endian:little;ptrsize:8;#00 |
| 121 | |
| 122 | ArchSpec host_arch (Host::GetArchitecture ()); |
| 123 | |
| 124 | const llvm::Triple &host_triple = host_arch.GetTriple(); |
| 125 | const llvm::StringRef arch_name (host_triple.getArchName()); |
| 126 | const llvm::StringRef vendor_name (host_triple.getOSName()); |
| 127 | const llvm::StringRef os_name (host_triple.getVendorName()); |
| 128 | response.Printf ("arch:%.*s;ostype:%.*s;vendor:%.*s;ptrsize:%u", |
| 129 | (int)arch_name.size(), arch_name.data(), |
| 130 | (int)os_name.size(), os_name.data(), |
| 131 | (int)vendor_name.size(), vendor_name.data(), |
| 132 | host_arch.GetAddressByteSize()); |
| 133 | |
| 134 | switch (lldb::endian::InlHostByteOrder()) |
| 135 | { |
| 136 | case eByteOrderBig: response.PutCString ("endian:big;"); break; |
| 137 | case eByteOrderLittle: response.PutCString ("endian:little;"); break; |
| 138 | case eByteOrderPDP: response.PutCString ("endian:pdp;"); break; |
| 139 | default: response.PutCString ("endian:unknown;"); break; |
| 140 | } |
| 141 | |
| 142 | return SendPacket (response.GetString().c_str(),response.GetString().size()) > 0; |
| 143 | } |