1*6881a400Schristos /* Python interface to inferiors. 2*6881a400Schristos 3*6881a400Schristos Copyright (C) 2009-2023 Free Software Foundation, Inc. 4*6881a400Schristos 5*6881a400Schristos This file is part of GDB. 6*6881a400Schristos 7*6881a400Schristos This program is free software; you can redistribute it and/or modify 8*6881a400Schristos it under the terms of the GNU General Public License as published by 9*6881a400Schristos the Free Software Foundation; either version 3 of the License, or 10*6881a400Schristos (at your option) any later version. 11*6881a400Schristos 12*6881a400Schristos This program is distributed in the hope that it will be useful, 13*6881a400Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 14*6881a400Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*6881a400Schristos GNU General Public License for more details. 16*6881a400Schristos 17*6881a400Schristos You should have received a copy of the GNU General Public License 18*6881a400Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19*6881a400Schristos 20*6881a400Schristos #include "defs.h" 21*6881a400Schristos #include "python-internal.h" 22*6881a400Schristos #include "process-stratum-target.h" 23*6881a400Schristos #include "inferior.h" 24*6881a400Schristos #include "observable.h" 25*6881a400Schristos #include "target-connection.h" 26*6881a400Schristos #include "py-events.h" 27*6881a400Schristos #include "py-event.h" 28*6881a400Schristos #include "arch-utils.h" 29*6881a400Schristos #include "remote.h" 30*6881a400Schristos #include "charset.h" 31*6881a400Schristos 32*6881a400Schristos #include <map> 33*6881a400Schristos 34*6881a400Schristos /* The Python object that represents a connection. */ 35*6881a400Schristos 36*6881a400Schristos struct connection_object 37*6881a400Schristos { 38*6881a400Schristos PyObject_HEAD 39*6881a400Schristos 40*6881a400Schristos /* The process target that represents this connection. When a 41*6881a400Schristos connection_object is created this field will always point at a valid 42*6881a400Schristos target. Later, if GDB stops using this target (the target is popped 43*6881a400Schristos from all target stacks) then this field is set to nullptr, which 44*6881a400Schristos indicates that this Python object is now in the invalid state (see 45*6881a400Schristos the is_valid() method below). */ 46*6881a400Schristos struct process_stratum_target *target; 47*6881a400Schristos }; 48*6881a400Schristos 49*6881a400Schristos extern PyTypeObject connection_object_type 50*6881a400Schristos CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("connection_object"); 51*6881a400Schristos 52*6881a400Schristos extern PyTypeObject remote_connection_object_type 53*6881a400Schristos CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("remote_connection_object"); 54*6881a400Schristos 55*6881a400Schristos /* Require that CONNECTION be valid. */ 56*6881a400Schristos #define CONNPY_REQUIRE_VALID(connection) \ 57*6881a400Schristos do { \ 58*6881a400Schristos if (connection->target == nullptr) \ 59*6881a400Schristos { \ 60*6881a400Schristos PyErr_SetString (PyExc_RuntimeError, \ 61*6881a400Schristos _("Connection no longer exists.")); \ 62*6881a400Schristos return nullptr; \ 63*6881a400Schristos } \ 64*6881a400Schristos } while (0) 65*6881a400Schristos 66*6881a400Schristos /* A map between process_stratum targets and the Python object representing 67*6881a400Schristos them. We actually hold a gdbpy_ref around the Python object so that 68*6881a400Schristos reference counts are handled correctly when entries are deleted. */ 69*6881a400Schristos static std::map<process_stratum_target *, 70*6881a400Schristos gdbpy_ref<connection_object>> all_connection_objects; 71*6881a400Schristos 72*6881a400Schristos /* Return a reference to a gdb.TargetConnection object for TARGET. If 73*6881a400Schristos TARGET is nullptr then a reference to None is returned. 74*6881a400Schristos 75*6881a400Schristos Previously created gdb.TargetConnection objects are cached, and 76*6881a400Schristos additional references to the same connection object can be returned with 77*6881a400Schristos later calls to this function. */ 78*6881a400Schristos 79*6881a400Schristos gdbpy_ref<> 80*6881a400Schristos target_to_connection_object (process_stratum_target *target) 81*6881a400Schristos { 82*6881a400Schristos if (target == nullptr) 83*6881a400Schristos return gdbpy_ref<>::new_reference (Py_None); 84*6881a400Schristos 85*6881a400Schristos gdbpy_ref <connection_object> conn_obj; 86*6881a400Schristos auto conn_obj_iter = all_connection_objects.find (target); 87*6881a400Schristos if (conn_obj_iter == all_connection_objects.end ()) 88*6881a400Schristos { 89*6881a400Schristos PyTypeObject *type; 90*6881a400Schristos 91*6881a400Schristos if (is_remote_target (target)) 92*6881a400Schristos type = &remote_connection_object_type; 93*6881a400Schristos else 94*6881a400Schristos type = &connection_object_type; 95*6881a400Schristos 96*6881a400Schristos conn_obj.reset (PyObject_New (connection_object, type)); 97*6881a400Schristos if (conn_obj == nullptr) 98*6881a400Schristos return nullptr; 99*6881a400Schristos conn_obj->target = target; 100*6881a400Schristos all_connection_objects.emplace (target, conn_obj); 101*6881a400Schristos } 102*6881a400Schristos else 103*6881a400Schristos conn_obj = conn_obj_iter->second; 104*6881a400Schristos 105*6881a400Schristos gdb_assert (conn_obj != nullptr); 106*6881a400Schristos 107*6881a400Schristos /* Repackage the result as a PyObject reference. */ 108*6881a400Schristos return gdbpy_ref<> ((PyObject *) conn_obj.release ()); 109*6881a400Schristos } 110*6881a400Schristos 111*6881a400Schristos /* Return a list of gdb.TargetConnection objects, one for each currently 112*6881a400Schristos active connection. The returned list is in no particular order. */ 113*6881a400Schristos 114*6881a400Schristos PyObject * 115*6881a400Schristos gdbpy_connections (PyObject *self, PyObject *args) 116*6881a400Schristos { 117*6881a400Schristos gdbpy_ref<> list (PyList_New (0)); 118*6881a400Schristos if (list == nullptr) 119*6881a400Schristos return nullptr; 120*6881a400Schristos 121*6881a400Schristos for (process_stratum_target *target : all_non_exited_process_targets ()) 122*6881a400Schristos { 123*6881a400Schristos gdb_assert (target != nullptr); 124*6881a400Schristos 125*6881a400Schristos gdbpy_ref<> conn = target_to_connection_object (target); 126*6881a400Schristos if (conn == nullptr) 127*6881a400Schristos return nullptr; 128*6881a400Schristos gdb_assert (conn.get () != Py_None); 129*6881a400Schristos 130*6881a400Schristos if (PyList_Append (list.get (), conn.get ()) < 0) 131*6881a400Schristos return nullptr; 132*6881a400Schristos } 133*6881a400Schristos 134*6881a400Schristos return list.release (); 135*6881a400Schristos } 136*6881a400Schristos 137*6881a400Schristos /* Emit a connection event for TARGET to REGISTRY. Return 0 on success, or 138*6881a400Schristos a negative value on error. */ 139*6881a400Schristos 140*6881a400Schristos static int 141*6881a400Schristos emit_connection_event (process_stratum_target *target, 142*6881a400Schristos eventregistry_object *registry) 143*6881a400Schristos { 144*6881a400Schristos gdbpy_ref<> event_obj 145*6881a400Schristos = create_event_object (&connection_event_object_type); 146*6881a400Schristos if (event_obj == nullptr) 147*6881a400Schristos return -1; 148*6881a400Schristos 149*6881a400Schristos gdbpy_ref<> conn = target_to_connection_object (target); 150*6881a400Schristos if (evpy_add_attribute (event_obj.get (), "connection", conn.get ()) < 0) 151*6881a400Schristos return -1; 152*6881a400Schristos 153*6881a400Schristos return evpy_emit_event (event_obj.get (), registry); 154*6881a400Schristos } 155*6881a400Schristos 156*6881a400Schristos /* Callback for the connection_removed observer. */ 157*6881a400Schristos 158*6881a400Schristos static void 159*6881a400Schristos connpy_connection_removed (process_stratum_target *target) 160*6881a400Schristos { 161*6881a400Schristos if (!gdb_python_initialized) 162*6881a400Schristos return; 163*6881a400Schristos 164*6881a400Schristos gdbpy_enter enter_py; 165*6881a400Schristos 166*6881a400Schristos if (!evregpy_no_listeners_p (gdb_py_events.connection_removed)) 167*6881a400Schristos if (emit_connection_event (target, gdb_py_events.connection_removed) < 0) 168*6881a400Schristos gdbpy_print_stack (); 169*6881a400Schristos 170*6881a400Schristos auto conn_obj_iter = all_connection_objects.find (target); 171*6881a400Schristos if (conn_obj_iter != all_connection_objects.end ()) 172*6881a400Schristos { 173*6881a400Schristos gdbpy_ref <connection_object> conn_obj = conn_obj_iter->second; 174*6881a400Schristos conn_obj->target = nullptr; 175*6881a400Schristos all_connection_objects.erase (target); 176*6881a400Schristos } 177*6881a400Schristos } 178*6881a400Schristos 179*6881a400Schristos /* Called when a gdb.TargetConnection object is deallocated. */ 180*6881a400Schristos 181*6881a400Schristos static void 182*6881a400Schristos connpy_connection_dealloc (PyObject *obj) 183*6881a400Schristos { 184*6881a400Schristos connection_object *conn_obj = (connection_object *) obj; 185*6881a400Schristos 186*6881a400Schristos /* As the all_connection_objects map holds a reference to each connection 187*6881a400Schristos object we can only enter the dealloc function when the reference in 188*6881a400Schristos all_connection_objects has been erased. 189*6881a400Schristos 190*6881a400Schristos As we always set the target pointer back to nullptr before we erase 191*6881a400Schristos items from all_connection_objects then, when we get here, the target 192*6881a400Schristos pointer must be nullptr. */ 193*6881a400Schristos gdb_assert (conn_obj->target == nullptr); 194*6881a400Schristos 195*6881a400Schristos Py_TYPE (obj)->tp_free (obj); 196*6881a400Schristos } 197*6881a400Schristos 198*6881a400Schristos /* Implement repr() for gdb.TargetConnection. */ 199*6881a400Schristos 200*6881a400Schristos static PyObject * 201*6881a400Schristos connpy_repr (PyObject *obj) 202*6881a400Schristos { 203*6881a400Schristos connection_object *self = (connection_object *) obj; 204*6881a400Schristos process_stratum_target *target = self->target; 205*6881a400Schristos 206*6881a400Schristos if (target == nullptr) 207*6881a400Schristos return PyUnicode_FromFormat ("<%s (invalid)>", Py_TYPE (obj)->tp_name); 208*6881a400Schristos 209*6881a400Schristos return PyUnicode_FromFormat ("<%s num=%d, what=\"%s\">", 210*6881a400Schristos Py_TYPE (obj)->tp_name, 211*6881a400Schristos target->connection_number, 212*6881a400Schristos make_target_connection_string (target).c_str ()); 213*6881a400Schristos } 214*6881a400Schristos 215*6881a400Schristos /* Implementation of gdb.TargetConnection.is_valid() -> Boolean. Returns 216*6881a400Schristos True if this connection object is still associated with a 217*6881a400Schristos process_stratum_target, otherwise, returns False. */ 218*6881a400Schristos 219*6881a400Schristos static PyObject * 220*6881a400Schristos connpy_is_valid (PyObject *self, PyObject *args) 221*6881a400Schristos { 222*6881a400Schristos connection_object *conn = (connection_object *) self; 223*6881a400Schristos 224*6881a400Schristos if (conn->target == nullptr) 225*6881a400Schristos Py_RETURN_FALSE; 226*6881a400Schristos 227*6881a400Schristos Py_RETURN_TRUE; 228*6881a400Schristos } 229*6881a400Schristos 230*6881a400Schristos /* Return the id number of this connection. */ 231*6881a400Schristos 232*6881a400Schristos static PyObject * 233*6881a400Schristos connpy_get_connection_num (PyObject *self, void *closure) 234*6881a400Schristos { 235*6881a400Schristos connection_object *conn = (connection_object *) self; 236*6881a400Schristos 237*6881a400Schristos CONNPY_REQUIRE_VALID (conn); 238*6881a400Schristos 239*6881a400Schristos auto num = conn->target->connection_number; 240*6881a400Schristos return gdb_py_object_from_longest (num).release (); 241*6881a400Schristos } 242*6881a400Schristos 243*6881a400Schristos /* Return a string that gives the short name for this connection type. */ 244*6881a400Schristos 245*6881a400Schristos static PyObject * 246*6881a400Schristos connpy_get_connection_type (PyObject *self, void *closure) 247*6881a400Schristos { 248*6881a400Schristos connection_object *conn = (connection_object *) self; 249*6881a400Schristos 250*6881a400Schristos CONNPY_REQUIRE_VALID (conn); 251*6881a400Schristos 252*6881a400Schristos const char *shortname = conn->target->shortname (); 253*6881a400Schristos return host_string_to_python_string (shortname).release (); 254*6881a400Schristos } 255*6881a400Schristos 256*6881a400Schristos /* Return a string that gives a longer description of this connection type. */ 257*6881a400Schristos 258*6881a400Schristos static PyObject * 259*6881a400Schristos connpy_get_description (PyObject *self, void *closure) 260*6881a400Schristos { 261*6881a400Schristos connection_object *conn = (connection_object *) self; 262*6881a400Schristos 263*6881a400Schristos CONNPY_REQUIRE_VALID (conn); 264*6881a400Schristos 265*6881a400Schristos const char *longname = conn->target->longname (); 266*6881a400Schristos return host_string_to_python_string (longname).release (); 267*6881a400Schristos } 268*6881a400Schristos 269*6881a400Schristos /* Return a string that gives additional details about this connection, or 270*6881a400Schristos None, if there are no additional details for this connection type. */ 271*6881a400Schristos 272*6881a400Schristos static PyObject * 273*6881a400Schristos connpy_get_connection_details (PyObject *self, void *closure) 274*6881a400Schristos { 275*6881a400Schristos connection_object *conn = (connection_object *) self; 276*6881a400Schristos 277*6881a400Schristos CONNPY_REQUIRE_VALID (conn); 278*6881a400Schristos 279*6881a400Schristos const char *details = conn->target->connection_string (); 280*6881a400Schristos if (details != nullptr) 281*6881a400Schristos return host_string_to_python_string (details).release (); 282*6881a400Schristos else 283*6881a400Schristos Py_RETURN_NONE; 284*6881a400Schristos } 285*6881a400Schristos 286*6881a400Schristos /* Python specific initialization for this file. */ 287*6881a400Schristos 288*6881a400Schristos int 289*6881a400Schristos gdbpy_initialize_connection (void) 290*6881a400Schristos { 291*6881a400Schristos if (PyType_Ready (&connection_object_type) < 0) 292*6881a400Schristos return -1; 293*6881a400Schristos 294*6881a400Schristos if (gdb_pymodule_addobject (gdb_module, "TargetConnection", 295*6881a400Schristos (PyObject *) &connection_object_type) < 0) 296*6881a400Schristos return -1; 297*6881a400Schristos 298*6881a400Schristos if (PyType_Ready (&remote_connection_object_type) < 0) 299*6881a400Schristos return -1; 300*6881a400Schristos 301*6881a400Schristos if (gdb_pymodule_addobject (gdb_module, "RemoteTargetConnection", 302*6881a400Schristos (PyObject *) &remote_connection_object_type) < 0) 303*6881a400Schristos return -1; 304*6881a400Schristos 305*6881a400Schristos return 0; 306*6881a400Schristos } 307*6881a400Schristos 308*6881a400Schristos /* Set of callbacks used to implement gdb.send_packet. */ 309*6881a400Schristos 310*6881a400Schristos struct py_send_packet_callbacks : public send_remote_packet_callbacks 311*6881a400Schristos { 312*6881a400Schristos /* Constructor, initialise the result to nullptr. It is invalid to try 313*6881a400Schristos and read the result before sending a packet and processing the 314*6881a400Schristos reply. */ 315*6881a400Schristos 316*6881a400Schristos py_send_packet_callbacks () 317*6881a400Schristos : m_result (nullptr) 318*6881a400Schristos { /* Nothing. */ } 319*6881a400Schristos 320*6881a400Schristos /* There's nothing to do when the packet is sent. */ 321*6881a400Schristos 322*6881a400Schristos void sending (gdb::array_view<const char> &buf) override 323*6881a400Schristos { /* Nothing. */ } 324*6881a400Schristos 325*6881a400Schristos /* When the result is returned create a Python object and assign this 326*6881a400Schristos into M_RESULT. If for any reason we can't create a Python object to 327*6881a400Schristos represent the result then M_RESULT is set to nullptr, and Python's 328*6881a400Schristos internal error flags will be set. If the result we got back from the 329*6881a400Schristos remote is empty then set the result to None. */ 330*6881a400Schristos 331*6881a400Schristos void received (gdb::array_view<const char> &buf) override 332*6881a400Schristos { 333*6881a400Schristos if (buf.size () > 0 && buf.data ()[0] != '\0') 334*6881a400Schristos m_result.reset (PyBytes_FromStringAndSize (buf.data (), buf.size ())); 335*6881a400Schristos else 336*6881a400Schristos { 337*6881a400Schristos /* We didn't get back any result data; set the result to None. */ 338*6881a400Schristos Py_INCREF (Py_None); 339*6881a400Schristos m_result.reset (Py_None); 340*6881a400Schristos } 341*6881a400Schristos } 342*6881a400Schristos 343*6881a400Schristos /* Get a reference to the result as a Python object. It is invalid to 344*6881a400Schristos call this before sending a packet to the remote and processing the 345*6881a400Schristos reply. 346*6881a400Schristos 347*6881a400Schristos The result value is setup in the RECEIVED call above. If the RECEIVED 348*6881a400Schristos call causes an error then the result value will be set to nullptr, 349*6881a400Schristos and the error reason is left stored in Python's global error state. 350*6881a400Schristos 351*6881a400Schristos It is important that the result is inspected immediately after sending 352*6881a400Schristos a packet to the remote, and any error fetched, calling any other 353*6881a400Schristos Python functions that might clear the error state, or rely on an error 354*6881a400Schristos not being set will cause undefined behaviour. */ 355*6881a400Schristos 356*6881a400Schristos gdbpy_ref<> result () const 357*6881a400Schristos { 358*6881a400Schristos return m_result; 359*6881a400Schristos } 360*6881a400Schristos 361*6881a400Schristos private: 362*6881a400Schristos 363*6881a400Schristos /* A reference to the result value. */ 364*6881a400Schristos 365*6881a400Schristos gdbpy_ref<> m_result; 366*6881a400Schristos }; 367*6881a400Schristos 368*6881a400Schristos /* Implement RemoteTargetConnection.send_packet function. Send a packet to 369*6881a400Schristos the target identified by SELF. The connection must still be valid, and 370*6881a400Schristos the packet to be sent must be non-empty, otherwise an exception will be 371*6881a400Schristos thrown. */ 372*6881a400Schristos 373*6881a400Schristos static PyObject * 374*6881a400Schristos connpy_send_packet (PyObject *self, PyObject *args, PyObject *kw) 375*6881a400Schristos { 376*6881a400Schristos connection_object *conn = (connection_object *) self; 377*6881a400Schristos 378*6881a400Schristos CONNPY_REQUIRE_VALID (conn); 379*6881a400Schristos 380*6881a400Schristos static const char *keywords[] = {"packet", nullptr}; 381*6881a400Schristos PyObject *packet_obj; 382*6881a400Schristos 383*6881a400Schristos if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "O", keywords, 384*6881a400Schristos &packet_obj)) 385*6881a400Schristos return nullptr; 386*6881a400Schristos 387*6881a400Schristos /* If the packet is a unicode string then convert it to a bytes object. */ 388*6881a400Schristos if (PyUnicode_Check (packet_obj)) 389*6881a400Schristos { 390*6881a400Schristos /* We encode the string to bytes using the ascii codec, if this fails 391*6881a400Schristos then a suitable error will have been set. */ 392*6881a400Schristos packet_obj = PyUnicode_AsASCIIString (packet_obj); 393*6881a400Schristos if (packet_obj == nullptr) 394*6881a400Schristos return nullptr; 395*6881a400Schristos } 396*6881a400Schristos 397*6881a400Schristos /* Check the packet is now a bytes object. */ 398*6881a400Schristos if (!PyBytes_Check (packet_obj)) 399*6881a400Schristos { 400*6881a400Schristos PyErr_SetString (PyExc_TypeError, _("Packet is not a bytes object")); 401*6881a400Schristos return nullptr; 402*6881a400Schristos } 403*6881a400Schristos 404*6881a400Schristos Py_ssize_t packet_len = 0; 405*6881a400Schristos char *packet_str_nonconst = nullptr; 406*6881a400Schristos if (PyBytes_AsStringAndSize (packet_obj, &packet_str_nonconst, 407*6881a400Schristos &packet_len) < 0) 408*6881a400Schristos return nullptr; 409*6881a400Schristos const char *packet_str = packet_str_nonconst; 410*6881a400Schristos gdb_assert (packet_str != nullptr); 411*6881a400Schristos 412*6881a400Schristos if (packet_len == 0) 413*6881a400Schristos { 414*6881a400Schristos PyErr_SetString (PyExc_ValueError, _("Packet must not be empty")); 415*6881a400Schristos return nullptr; 416*6881a400Schristos } 417*6881a400Schristos 418*6881a400Schristos try 419*6881a400Schristos { 420*6881a400Schristos scoped_restore_current_thread restore_thread; 421*6881a400Schristos switch_to_target_no_thread (conn->target); 422*6881a400Schristos 423*6881a400Schristos gdb::array_view<const char> view (packet_str, packet_len); 424*6881a400Schristos py_send_packet_callbacks callbacks; 425*6881a400Schristos send_remote_packet (view, &callbacks); 426*6881a400Schristos PyObject *result = callbacks.result ().release (); 427*6881a400Schristos /* If we encountered an error converting the reply to a Python 428*6881a400Schristos object, then the result here can be nullptr. In that case, Python 429*6881a400Schristos should be aware that an error occurred. */ 430*6881a400Schristos gdb_assert ((result == nullptr) == (PyErr_Occurred () != nullptr)); 431*6881a400Schristos return result; 432*6881a400Schristos } 433*6881a400Schristos catch (const gdb_exception &except) 434*6881a400Schristos { 435*6881a400Schristos gdbpy_convert_exception (except); 436*6881a400Schristos return nullptr; 437*6881a400Schristos } 438*6881a400Schristos } 439*6881a400Schristos 440*6881a400Schristos /* Global initialization for this file. */ 441*6881a400Schristos 442*6881a400Schristos void _initialize_py_connection (); 443*6881a400Schristos void 444*6881a400Schristos _initialize_py_connection () 445*6881a400Schristos { 446*6881a400Schristos gdb::observers::connection_removed.attach (connpy_connection_removed, 447*6881a400Schristos "py-connection"); 448*6881a400Schristos } 449*6881a400Schristos 450*6881a400Schristos /* Methods for the gdb.TargetConnection object type. */ 451*6881a400Schristos 452*6881a400Schristos static PyMethodDef connection_object_methods[] = 453*6881a400Schristos { 454*6881a400Schristos { "is_valid", connpy_is_valid, METH_NOARGS, 455*6881a400Schristos "is_valid () -> Boolean.\n\ 456*6881a400Schristos Return true if this TargetConnection is valid, false if not." }, 457*6881a400Schristos { NULL } 458*6881a400Schristos }; 459*6881a400Schristos 460*6881a400Schristos /* Methods for the gdb.RemoteTargetConnection object type. */ 461*6881a400Schristos 462*6881a400Schristos static PyMethodDef remote_connection_object_methods[] = 463*6881a400Schristos { 464*6881a400Schristos { "send_packet", (PyCFunction) connpy_send_packet, 465*6881a400Schristos METH_VARARGS | METH_KEYWORDS, 466*6881a400Schristos "send_packet (PACKET) -> Bytes\n\ 467*6881a400Schristos Send PACKET to a remote target, return the reply as a bytes array." }, 468*6881a400Schristos { NULL } 469*6881a400Schristos }; 470*6881a400Schristos 471*6881a400Schristos /* Attributes for the gdb.TargetConnection object type. */ 472*6881a400Schristos 473*6881a400Schristos static gdb_PyGetSetDef connection_object_getset[] = 474*6881a400Schristos { 475*6881a400Schristos { "num", connpy_get_connection_num, NULL, 476*6881a400Schristos "ID number of this connection, as assigned by GDB.", NULL }, 477*6881a400Schristos { "type", connpy_get_connection_type, NULL, 478*6881a400Schristos "A short string that is the name for this connection type.", NULL }, 479*6881a400Schristos { "description", connpy_get_description, NULL, 480*6881a400Schristos "A longer string describing this connection type.", NULL }, 481*6881a400Schristos { "details", connpy_get_connection_details, NULL, 482*6881a400Schristos "A string containing additional connection details.", NULL }, 483*6881a400Schristos { NULL } 484*6881a400Schristos }; 485*6881a400Schristos 486*6881a400Schristos /* Define the gdb.TargetConnection object type. */ 487*6881a400Schristos 488*6881a400Schristos PyTypeObject connection_object_type = 489*6881a400Schristos { 490*6881a400Schristos PyVarObject_HEAD_INIT (NULL, 0) 491*6881a400Schristos "gdb.TargetConnection", /* tp_name */ 492*6881a400Schristos sizeof (connection_object), /* tp_basicsize */ 493*6881a400Schristos 0, /* tp_itemsize */ 494*6881a400Schristos connpy_connection_dealloc, /* tp_dealloc */ 495*6881a400Schristos 0, /* tp_print */ 496*6881a400Schristos 0, /* tp_getattr */ 497*6881a400Schristos 0, /* tp_setattr */ 498*6881a400Schristos 0, /* tp_compare */ 499*6881a400Schristos connpy_repr, /* tp_repr */ 500*6881a400Schristos 0, /* tp_as_number */ 501*6881a400Schristos 0, /* tp_as_sequence */ 502*6881a400Schristos 0, /* tp_as_mapping */ 503*6881a400Schristos 0, /* tp_hash */ 504*6881a400Schristos 0, /* tp_call */ 505*6881a400Schristos 0, /* tp_str */ 506*6881a400Schristos 0, /* tp_getattro */ 507*6881a400Schristos 0, /* tp_setattro */ 508*6881a400Schristos 0, /* tp_as_buffer */ 509*6881a400Schristos Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ 510*6881a400Schristos "GDB target connection object", /* tp_doc */ 511*6881a400Schristos 0, /* tp_traverse */ 512*6881a400Schristos 0, /* tp_clear */ 513*6881a400Schristos 0, /* tp_richcompare */ 514*6881a400Schristos 0, /* tp_weaklistoffset */ 515*6881a400Schristos 0, /* tp_iter */ 516*6881a400Schristos 0, /* tp_iternext */ 517*6881a400Schristos connection_object_methods, /* tp_methods */ 518*6881a400Schristos 0, /* tp_members */ 519*6881a400Schristos connection_object_getset, /* tp_getset */ 520*6881a400Schristos 0, /* tp_base */ 521*6881a400Schristos 0, /* tp_dict */ 522*6881a400Schristos 0, /* tp_descr_get */ 523*6881a400Schristos 0, /* tp_descr_set */ 524*6881a400Schristos 0, /* tp_dictoffset */ 525*6881a400Schristos 0, /* tp_init */ 526*6881a400Schristos 0 /* tp_alloc */ 527*6881a400Schristos }; 528*6881a400Schristos 529*6881a400Schristos /* Define the gdb.RemoteTargetConnection object type. */ 530*6881a400Schristos 531*6881a400Schristos PyTypeObject remote_connection_object_type = 532*6881a400Schristos { 533*6881a400Schristos PyVarObject_HEAD_INIT (NULL, 0) 534*6881a400Schristos "gdb.RemoteTargetConnection", /* tp_name */ 535*6881a400Schristos sizeof (connection_object), /* tp_basicsize */ 536*6881a400Schristos 0, /* tp_itemsize */ 537*6881a400Schristos connpy_connection_dealloc, /* tp_dealloc */ 538*6881a400Schristos 0, /* tp_print */ 539*6881a400Schristos 0, /* tp_getattr */ 540*6881a400Schristos 0, /* tp_setattr */ 541*6881a400Schristos 0, /* tp_compare */ 542*6881a400Schristos connpy_repr, /* tp_repr */ 543*6881a400Schristos 0, /* tp_as_number */ 544*6881a400Schristos 0, /* tp_as_sequence */ 545*6881a400Schristos 0, /* tp_as_mapping */ 546*6881a400Schristos 0, /* tp_hash */ 547*6881a400Schristos 0, /* tp_call */ 548*6881a400Schristos 0, /* tp_str */ 549*6881a400Schristos 0, /* tp_getattro */ 550*6881a400Schristos 0, /* tp_setattro */ 551*6881a400Schristos 0, /* tp_as_buffer */ 552*6881a400Schristos Py_TPFLAGS_DEFAULT, /* tp_flags */ 553*6881a400Schristos "GDB remote target connection object", /* tp_doc */ 554*6881a400Schristos 0, /* tp_traverse */ 555*6881a400Schristos 0, /* tp_clear */ 556*6881a400Schristos 0, /* tp_richcompare */ 557*6881a400Schristos 0, /* tp_weaklistoffset */ 558*6881a400Schristos 0, /* tp_iter */ 559*6881a400Schristos 0, /* tp_iternext */ 560*6881a400Schristos remote_connection_object_methods, /* tp_methods */ 561*6881a400Schristos 0, /* tp_members */ 562*6881a400Schristos 0, /* tp_getset */ 563*6881a400Schristos &connection_object_type, /* tp_base */ 564*6881a400Schristos 0, /* tp_dict */ 565*6881a400Schristos 0, /* tp_descr_get */ 566*6881a400Schristos 0, /* tp_descr_set */ 567*6881a400Schristos 0, /* tp_dictoffset */ 568*6881a400Schristos 0, /* tp_init */ 569*6881a400Schristos 0 /* tp_alloc */ 570*6881a400Schristos }; 571