2013-08-29 Phil Muldoon <pmuldoon@redhat.com>
[deliverable/binutils-gdb.git] / gdb / python / py-inferior.c
1 /* Python interface to inferiors.
2
3 Copyright (C) 2009-2013 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "exceptions.h"
22 #include "gdbcore.h"
23 #include "gdbthread.h"
24 #include "inferior.h"
25 #include "objfiles.h"
26 #include "observer.h"
27 #include "python-internal.h"
28 #include "arch-utils.h"
29 #include "language.h"
30 #include "gdb_signals.h"
31 #include "py-event.h"
32 #include "py-stopevent.h"
33
34 struct threadlist_entry {
35 thread_object *thread_obj;
36 struct threadlist_entry *next;
37 };
38
39 typedef struct
40 {
41 PyObject_HEAD
42
43 /* The inferior we represent. */
44 struct inferior *inferior;
45
46 /* thread_object instances under this inferior. This list owns a
47 reference to each object it contains. */
48 struct threadlist_entry *threads;
49
50 /* Number of threads in the list. */
51 int nthreads;
52 } inferior_object;
53
54 static PyTypeObject inferior_object_type
55 CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("inferior_object");
56
57 static const struct inferior_data *infpy_inf_data_key;
58
59 typedef struct {
60 PyObject_HEAD
61 void *buffer;
62
63 /* These are kept just for mbpy_str. */
64 CORE_ADDR addr;
65 CORE_ADDR length;
66 } membuf_object;
67
68 static PyTypeObject membuf_object_type
69 CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("membuf_object");
70
71 /* Require that INFERIOR be a valid inferior ID. */
72 #define INFPY_REQUIRE_VALID(Inferior) \
73 do { \
74 if (!Inferior->inferior) \
75 { \
76 PyErr_SetString (PyExc_RuntimeError, \
77 _("Inferior no longer exists.")); \
78 return NULL; \
79 } \
80 } while (0)
81
82 static void
83 python_on_normal_stop (struct bpstats *bs, int print_frame)
84 {
85 struct cleanup *cleanup;
86 enum gdb_signal stop_signal;
87
88 if (!gdb_python_initialized)
89 return;
90
91 if (!find_thread_ptid (inferior_ptid))
92 return;
93
94 stop_signal = inferior_thread ()->suspend.stop_signal;
95
96 cleanup = ensure_python_env (get_current_arch (), current_language);
97
98 if (emit_stop_event (bs, stop_signal) < 0)
99 gdbpy_print_stack ();
100
101 do_cleanups (cleanup);
102 }
103
104 static void
105 python_on_resume (ptid_t ptid)
106 {
107 struct cleanup *cleanup;
108
109 if (!gdb_python_initialized)
110 return;
111
112 cleanup = ensure_python_env (target_gdbarch (), current_language);
113
114 if (emit_continue_event (ptid) < 0)
115 gdbpy_print_stack ();
116
117 do_cleanups (cleanup);
118 }
119
120 static void
121 python_inferior_exit (struct inferior *inf)
122 {
123 struct cleanup *cleanup;
124 const LONGEST *exit_code = NULL;
125
126 if (!gdb_python_initialized)
127 return;
128
129 cleanup = ensure_python_env (target_gdbarch (), current_language);
130
131 if (inf->has_exit_code)
132 exit_code = &inf->exit_code;
133
134 if (emit_exited_event (exit_code, inf) < 0)
135 gdbpy_print_stack ();
136
137 do_cleanups (cleanup);
138 }
139
140 /* Callback used to notify Python listeners about new objfiles loaded in the
141 inferior. */
142
143 static void
144 python_new_objfile (struct objfile *objfile)
145 {
146 struct cleanup *cleanup;
147
148 if (objfile == NULL)
149 return;
150
151 if (!gdb_python_initialized)
152 return;
153
154 cleanup = ensure_python_env (get_objfile_arch (objfile), current_language);
155
156 if (emit_new_objfile_event (objfile) < 0)
157 gdbpy_print_stack ();
158
159 do_cleanups (cleanup);
160 }
161
162 /* Return a reference to the Python object of type Inferior
163 representing INFERIOR. If the object has already been created,
164 return it and increment the reference count, otherwise, create it.
165 Return NULL on failure. */
166 PyObject *
167 inferior_to_inferior_object (struct inferior *inferior)
168 {
169 inferior_object *inf_obj;
170
171 inf_obj = inferior_data (inferior, infpy_inf_data_key);
172 if (!inf_obj)
173 {
174 inf_obj = PyObject_New (inferior_object, &inferior_object_type);
175 if (!inf_obj)
176 return NULL;
177
178 inf_obj->inferior = inferior;
179 inf_obj->threads = NULL;
180 inf_obj->nthreads = 0;
181
182 set_inferior_data (inferior, infpy_inf_data_key, inf_obj);
183
184 }
185 else
186 Py_INCREF ((PyObject *)inf_obj);
187
188 return (PyObject *) inf_obj;
189 }
190
191 /* Finds the Python Inferior object for the given PID. Returns a
192 reference, or NULL if PID does not match any inferior object. */
193
194 PyObject *
195 find_inferior_object (int pid)
196 {
197 struct inferior *inf = find_inferior_pid (pid);
198
199 if (inf)
200 return inferior_to_inferior_object (inf);
201
202 return NULL;
203 }
204
205 thread_object *
206 find_thread_object (ptid_t ptid)
207 {
208 int pid;
209 struct threadlist_entry *thread;
210 PyObject *inf_obj;
211 thread_object *found = NULL;
212
213 pid = PIDGET (ptid);
214 if (pid == 0)
215 return NULL;
216
217 inf_obj = find_inferior_object (pid);
218
219 if (! inf_obj)
220 return NULL;
221
222 for (thread = ((inferior_object *)inf_obj)->threads; thread;
223 thread = thread->next)
224 if (ptid_equal (thread->thread_obj->thread->ptid, ptid))
225 {
226 found = thread->thread_obj;
227 break;
228 }
229
230 Py_DECREF (inf_obj);
231
232 if (found)
233 return found;
234
235 return NULL;
236 }
237
238 static void
239 add_thread_object (struct thread_info *tp)
240 {
241 struct cleanup *cleanup;
242 thread_object *thread_obj;
243 inferior_object *inf_obj;
244 struct threadlist_entry *entry;
245
246 if (!gdb_python_initialized)
247 return;
248
249 cleanup = ensure_python_env (python_gdbarch, python_language);
250
251 thread_obj = create_thread_object (tp);
252 if (!thread_obj)
253 {
254 gdbpy_print_stack ();
255 do_cleanups (cleanup);
256 return;
257 }
258
259 inf_obj = (inferior_object *) thread_obj->inf_obj;
260
261 entry = xmalloc (sizeof (struct threadlist_entry));
262 entry->thread_obj = thread_obj;
263 entry->next = inf_obj->threads;
264
265 inf_obj->threads = entry;
266 inf_obj->nthreads++;
267
268 do_cleanups (cleanup);
269 }
270
271 static void
272 delete_thread_object (struct thread_info *tp, int ignore)
273 {
274 struct cleanup *cleanup;
275 inferior_object *inf_obj;
276 struct threadlist_entry **entry, *tmp;
277
278 if (!gdb_python_initialized)
279 return;
280
281 cleanup = ensure_python_env (python_gdbarch, python_language);
282
283 inf_obj = (inferior_object *) find_inferior_object (PIDGET(tp->ptid));
284 if (!inf_obj)
285 {
286 do_cleanups (cleanup);
287 return;
288 }
289
290 /* Find thread entry in its inferior's thread_list. */
291 for (entry = &inf_obj->threads; *entry != NULL; entry =
292 &(*entry)->next)
293 if ((*entry)->thread_obj->thread == tp)
294 break;
295
296 if (!*entry)
297 {
298 Py_DECREF (inf_obj);
299 do_cleanups (cleanup);
300 return;
301 }
302
303 tmp = *entry;
304 tmp->thread_obj->thread = NULL;
305
306 *entry = (*entry)->next;
307 inf_obj->nthreads--;
308
309 Py_DECREF (tmp->thread_obj);
310 Py_DECREF (inf_obj);
311 xfree (tmp);
312
313 do_cleanups (cleanup);
314 }
315
316 static PyObject *
317 infpy_threads (PyObject *self, PyObject *args)
318 {
319 int i;
320 struct threadlist_entry *entry;
321 inferior_object *inf_obj = (inferior_object *) self;
322 PyObject *tuple;
323 volatile struct gdb_exception except;
324
325 INFPY_REQUIRE_VALID (inf_obj);
326
327 TRY_CATCH (except, RETURN_MASK_ALL)
328 update_thread_list ();
329 GDB_PY_HANDLE_EXCEPTION (except);
330
331 tuple = PyTuple_New (inf_obj->nthreads);
332 if (!tuple)
333 return NULL;
334
335 for (i = 0, entry = inf_obj->threads; i < inf_obj->nthreads;
336 i++, entry = entry->next)
337 {
338 Py_INCREF (entry->thread_obj);
339 PyTuple_SET_ITEM (tuple, i, (PyObject *) entry->thread_obj);
340 }
341
342 return tuple;
343 }
344
345 static PyObject *
346 infpy_get_num (PyObject *self, void *closure)
347 {
348 inferior_object *inf = (inferior_object *) self;
349
350 INFPY_REQUIRE_VALID (inf);
351
352 return PyLong_FromLong (inf->inferior->num);
353 }
354
355 static PyObject *
356 infpy_get_pid (PyObject *self, void *closure)
357 {
358 inferior_object *inf = (inferior_object *) self;
359
360 INFPY_REQUIRE_VALID (inf);
361
362 return PyLong_FromLong (inf->inferior->pid);
363 }
364
365 static PyObject *
366 infpy_get_was_attached (PyObject *self, void *closure)
367 {
368 inferior_object *inf = (inferior_object *) self;
369
370 INFPY_REQUIRE_VALID (inf);
371 if (inf->inferior->attach_flag)
372 Py_RETURN_TRUE;
373 Py_RETURN_FALSE;
374 }
375
376 static int
377 build_inferior_list (struct inferior *inf, void *arg)
378 {
379 PyObject *list = arg;
380 PyObject *inferior = inferior_to_inferior_object (inf);
381 int success = 0;
382
383 if (! inferior)
384 return 0;
385
386 success = PyList_Append (list, inferior);
387 Py_DECREF (inferior);
388
389 if (success)
390 return 1;
391
392 return 0;
393 }
394
395 /* Implementation of gdb.inferiors () -> (gdb.Inferior, ...).
396 Returns a tuple of all inferiors. */
397 PyObject *
398 gdbpy_inferiors (PyObject *unused, PyObject *unused2)
399 {
400 PyObject *list, *tuple;
401
402 list = PyList_New (0);
403 if (!list)
404 return NULL;
405
406 if (iterate_over_inferiors (build_inferior_list, list))
407 {
408 Py_DECREF (list);
409 return NULL;
410 }
411
412 tuple = PyList_AsTuple (list);
413 Py_DECREF (list);
414
415 return tuple;
416 }
417
418 /* Membuf and memory manipulation. */
419
420 /* Implementation of Inferior.read_memory (address, length).
421 Returns a Python buffer object with LENGTH bytes of the inferior's
422 memory at ADDRESS. Both arguments are integers. Returns NULL on error,
423 with a python exception set. */
424 static PyObject *
425 infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
426 {
427 CORE_ADDR addr, length;
428 void *buffer = NULL;
429 membuf_object *membuf_obj;
430 PyObject *addr_obj, *length_obj, *result;
431 volatile struct gdb_exception except;
432 static char *keywords[] = { "address", "length", NULL };
433
434 if (! PyArg_ParseTupleAndKeywords (args, kw, "OO", keywords,
435 &addr_obj, &length_obj))
436 return NULL;
437
438 if (get_addr_from_python (addr_obj, &addr) < 0
439 || get_addr_from_python (length_obj, &length) < 0)
440 return NULL;
441
442 TRY_CATCH (except, RETURN_MASK_ALL)
443 {
444 buffer = xmalloc (length);
445
446 read_memory (addr, buffer, length);
447 }
448 if (except.reason < 0)
449 {
450 xfree (buffer);
451 GDB_PY_HANDLE_EXCEPTION (except);
452 }
453
454 membuf_obj = PyObject_New (membuf_object, &membuf_object_type);
455 if (membuf_obj == NULL)
456 {
457 xfree (buffer);
458 return NULL;
459 }
460
461 membuf_obj->buffer = buffer;
462 membuf_obj->addr = addr;
463 membuf_obj->length = length;
464
465 #ifdef IS_PY3K
466 result = PyMemoryView_FromObject ((PyObject *) membuf_obj);
467 #else
468 result = PyBuffer_FromReadWriteObject ((PyObject *) membuf_obj, 0,
469 Py_END_OF_BUFFER);
470 #endif
471 Py_DECREF (membuf_obj);
472
473 return result;
474 }
475
476 /* Implementation of Inferior.write_memory (address, buffer [, length]).
477 Writes the contents of BUFFER (a Python object supporting the read
478 buffer protocol) at ADDRESS in the inferior's memory. Write LENGTH
479 bytes from BUFFER, or its entire contents if the argument is not
480 provided. The function returns nothing. Returns NULL on error, with
481 a python exception set. */
482 static PyObject *
483 infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw)
484 {
485 Py_ssize_t buf_len;
486 const char *buffer;
487 CORE_ADDR addr, length;
488 PyObject *addr_obj, *length_obj = NULL;
489 volatile struct gdb_exception except;
490 static char *keywords[] = { "address", "buffer", "length", NULL };
491 #ifdef IS_PY3K
492 Py_buffer pybuf;
493
494 if (! PyArg_ParseTupleAndKeywords (args, kw, "Os*|O", keywords,
495 &addr_obj, &pybuf,
496 &length_obj))
497 return NULL;
498
499 buffer = pybuf.buf;
500 buf_len = pybuf.len;
501 #else
502 if (! PyArg_ParseTupleAndKeywords (args, kw, "Os#|O", keywords,
503 &addr_obj, &buffer, &buf_len,
504 &length_obj))
505 return NULL;
506 #endif
507
508 if (get_addr_from_python (addr_obj, &addr) < 0)
509 goto fail;
510
511 if (!length_obj)
512 length = buf_len;
513 else if (get_addr_from_python (length_obj, &length) < 0)
514 goto fail;
515
516 TRY_CATCH (except, RETURN_MASK_ALL)
517 {
518 write_memory_with_notification (addr, (gdb_byte *) buffer, length);
519 }
520 #ifdef IS_PY3K
521 PyBuffer_Release (&pybuf);
522 #endif
523 GDB_PY_HANDLE_EXCEPTION (except);
524
525 Py_RETURN_NONE;
526
527 fail:
528 #ifdef IS_PY3K
529 PyBuffer_Release (&pybuf);
530 #endif
531 return NULL;
532 }
533
534 /* Destructor of Membuf objects. */
535 static void
536 mbpy_dealloc (PyObject *self)
537 {
538 xfree (((membuf_object *) self)->buffer);
539 Py_TYPE (self)->tp_free (self);
540 }
541
542 /* Return a description of the Membuf object. */
543 static PyObject *
544 mbpy_str (PyObject *self)
545 {
546 membuf_object *membuf_obj = (membuf_object *) self;
547
548 return PyString_FromFormat (_("Memory buffer for address %s, \
549 which is %s bytes long."),
550 paddress (python_gdbarch, membuf_obj->addr),
551 pulongest (membuf_obj->length));
552 }
553
554 #ifdef IS_PY3K
555
556 static int
557 get_buffer (PyObject *self, Py_buffer *buf, int flags)
558 {
559 membuf_object *membuf_obj = (membuf_object *) self;
560 int ret;
561
562 ret = PyBuffer_FillInfo (buf, self, membuf_obj->buffer,
563 membuf_obj->length, 0,
564 PyBUF_CONTIG);
565 buf->format = "c";
566
567 return ret;
568 }
569
570 #else
571
572 static Py_ssize_t
573 get_read_buffer (PyObject *self, Py_ssize_t segment, void **ptrptr)
574 {
575 membuf_object *membuf_obj = (membuf_object *) self;
576
577 if (segment)
578 {
579 PyErr_SetString (PyExc_SystemError,
580 _("The memory buffer supports only one segment."));
581 return -1;
582 }
583
584 *ptrptr = membuf_obj->buffer;
585
586 return membuf_obj->length;
587 }
588
589 static Py_ssize_t
590 get_write_buffer (PyObject *self, Py_ssize_t segment, void **ptrptr)
591 {
592 return get_read_buffer (self, segment, ptrptr);
593 }
594
595 static Py_ssize_t
596 get_seg_count (PyObject *self, Py_ssize_t *lenp)
597 {
598 if (lenp)
599 *lenp = ((membuf_object *) self)->length;
600
601 return 1;
602 }
603
604 static Py_ssize_t
605 get_char_buffer (PyObject *self, Py_ssize_t segment, char **ptrptr)
606 {
607 void *ptr = NULL;
608 Py_ssize_t ret;
609
610 ret = get_read_buffer (self, segment, &ptr);
611 *ptrptr = (char *) ptr;
612
613 return ret;
614 }
615
616 #endif /* IS_PY3K */
617
618 /* Implementation of
619 gdb.search_memory (address, length, pattern). ADDRESS is the
620 address to start the search. LENGTH specifies the scope of the
621 search from ADDRESS. PATTERN is the pattern to search for (and
622 must be a Python object supporting the buffer protocol).
623 Returns a Python Long object holding the address where the pattern
624 was located, or if the pattern was not found, returns None. Returns NULL
625 on error, with a python exception set. */
626 static PyObject *
627 infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
628 {
629 CORE_ADDR start_addr, length;
630 static char *keywords[] = { "address", "length", "pattern", NULL };
631 PyObject *start_addr_obj, *length_obj;
632 volatile struct gdb_exception except;
633 Py_ssize_t pattern_size;
634 const void *buffer;
635 CORE_ADDR found_addr;
636 int found = 0;
637 #ifdef IS_PY3K
638 Py_buffer pybuf;
639
640 if (! PyArg_ParseTupleAndKeywords (args, kw, "OOs*", keywords,
641 &start_addr_obj, &length_obj,
642 &pybuf))
643 return NULL;
644
645 buffer = pybuf.buf;
646 pattern_size = pybuf.len;
647 #else
648 PyObject *pattern;
649
650 if (! PyArg_ParseTupleAndKeywords (args, kw, "OOO", keywords,
651 &start_addr_obj, &length_obj,
652 &pattern))
653 return NULL;
654
655 if (!PyObject_CheckReadBuffer (pattern))
656 {
657 PyErr_SetString (PyExc_RuntimeError,
658 _("The pattern is not a Python buffer."));
659
660 return NULL;
661 }
662
663 if (PyObject_AsReadBuffer (pattern, &buffer, &pattern_size) == -1)
664 return NULL;
665 #endif
666
667 if (get_addr_from_python (start_addr_obj, &start_addr) < 0)
668 goto fail;
669
670 if (get_addr_from_python (length_obj, &length) < 0)
671 goto fail;
672
673 if (!length)
674 {
675 PyErr_SetString (PyExc_ValueError,
676 _("Search range is empty."));
677 goto fail;
678 }
679 /* Watch for overflows. */
680 else if (length > CORE_ADDR_MAX
681 || (start_addr + length - 1) < start_addr)
682 {
683 PyErr_SetString (PyExc_ValueError,
684 _("The search range is too large."));
685 goto fail;
686 }
687
688 TRY_CATCH (except, RETURN_MASK_ALL)
689 {
690 found = target_search_memory (start_addr, length,
691 buffer, pattern_size,
692 &found_addr);
693 }
694 #ifdef IS_PY3K
695 PyBuffer_Release (&pybuf);
696 #endif
697 GDB_PY_HANDLE_EXCEPTION (except);
698
699 if (found)
700 return PyLong_FromLong (found_addr);
701 else
702 Py_RETURN_NONE;
703
704 fail:
705 #ifdef IS_PY3K
706 PyBuffer_Release (&pybuf);
707 #endif
708 return NULL;
709 }
710
711 /* Implementation of gdb.Inferior.is_valid (self) -> Boolean.
712 Returns True if this inferior object still exists in GDB. */
713
714 static PyObject *
715 infpy_is_valid (PyObject *self, PyObject *args)
716 {
717 inferior_object *inf = (inferior_object *) self;
718
719 if (! inf->inferior)
720 Py_RETURN_FALSE;
721
722 Py_RETURN_TRUE;
723 }
724
725 static void
726 infpy_dealloc (PyObject *obj)
727 {
728 inferior_object *inf_obj = (inferior_object *) obj;
729 struct inferior *inf = inf_obj->inferior;
730
731 if (! inf)
732 return;
733
734 set_inferior_data (inf, infpy_inf_data_key, NULL);
735 }
736
737 /* Clear the INFERIOR pointer in an Inferior object and clear the
738 thread list. */
739 static void
740 py_free_inferior (struct inferior *inf, void *datum)
741 {
742
743 struct cleanup *cleanup;
744 inferior_object *inf_obj = datum;
745 struct threadlist_entry *th_entry, *th_tmp;
746
747 if (!gdb_python_initialized)
748 return;
749
750 cleanup = ensure_python_env (python_gdbarch, python_language);
751
752 inf_obj->inferior = NULL;
753
754 /* Deallocate threads list. */
755 for (th_entry = inf_obj->threads; th_entry != NULL;)
756 {
757 Py_DECREF (th_entry->thread_obj);
758
759 th_tmp = th_entry;
760 th_entry = th_entry->next;
761 xfree (th_tmp);
762 }
763
764 inf_obj->nthreads = 0;
765
766 Py_DECREF ((PyObject *) inf_obj);
767 do_cleanups (cleanup);
768 }
769
770 /* Implementation of gdb.selected_inferior() -> gdb.Inferior.
771 Returns the current inferior object. */
772
773 PyObject *
774 gdbpy_selected_inferior (PyObject *self, PyObject *args)
775 {
776 return inferior_to_inferior_object (current_inferior ());
777 }
778
779 int
780 gdbpy_initialize_inferior (void)
781 {
782 if (PyType_Ready (&inferior_object_type) < 0)
783 return -1;
784
785 if (gdb_pymodule_addobject (gdb_module, "Inferior",
786 (PyObject *) &inferior_object_type) < 0)
787 return -1;
788
789 infpy_inf_data_key =
790 register_inferior_data_with_cleanup (NULL, py_free_inferior);
791
792 observer_attach_new_thread (add_thread_object);
793 observer_attach_thread_exit (delete_thread_object);
794 observer_attach_normal_stop (python_on_normal_stop);
795 observer_attach_target_resumed (python_on_resume);
796 observer_attach_inferior_exit (python_inferior_exit);
797 observer_attach_new_objfile (python_new_objfile);
798
799 membuf_object_type.tp_new = PyType_GenericNew;
800 if (PyType_Ready (&membuf_object_type) < 0)
801 return -1;
802
803 return gdb_pymodule_addobject (gdb_module, "Membuf", (PyObject *)
804 &membuf_object_type);
805 }
806
807 static PyGetSetDef inferior_object_getset[] =
808 {
809 { "num", infpy_get_num, NULL, "ID of inferior, as assigned by GDB.", NULL },
810 { "pid", infpy_get_pid, NULL, "PID of inferior, as assigned by the OS.",
811 NULL },
812 { "was_attached", infpy_get_was_attached, NULL,
813 "True if the inferior was created using 'attach'.", NULL },
814 { NULL }
815 };
816
817 static PyMethodDef inferior_object_methods[] =
818 {
819 { "is_valid", infpy_is_valid, METH_NOARGS,
820 "is_valid () -> Boolean.\n\
821 Return true if this inferior is valid, false if not." },
822 { "threads", infpy_threads, METH_NOARGS,
823 "Return all the threads of this inferior." },
824 { "read_memory", (PyCFunction) infpy_read_memory,
825 METH_VARARGS | METH_KEYWORDS,
826 "read_memory (address, length) -> buffer\n\
827 Return a buffer object for reading from the inferior's memory." },
828 { "write_memory", (PyCFunction) infpy_write_memory,
829 METH_VARARGS | METH_KEYWORDS,
830 "write_memory (address, buffer [, length])\n\
831 Write the given buffer object to the inferior's memory." },
832 { "search_memory", (PyCFunction) infpy_search_memory,
833 METH_VARARGS | METH_KEYWORDS,
834 "search_memory (address, length, pattern) -> long\n\
835 Return a long with the address of a match, or None." },
836 { NULL }
837 };
838
839 static PyTypeObject inferior_object_type =
840 {
841 PyVarObject_HEAD_INIT (NULL, 0)
842 "gdb.Inferior", /* tp_name */
843 sizeof (inferior_object), /* tp_basicsize */
844 0, /* tp_itemsize */
845 infpy_dealloc, /* tp_dealloc */
846 0, /* tp_print */
847 0, /* tp_getattr */
848 0, /* tp_setattr */
849 0, /* tp_compare */
850 0, /* tp_repr */
851 0, /* tp_as_number */
852 0, /* tp_as_sequence */
853 0, /* tp_as_mapping */
854 0, /* tp_hash */
855 0, /* tp_call */
856 0, /* tp_str */
857 0, /* tp_getattro */
858 0, /* tp_setattro */
859 0, /* tp_as_buffer */
860 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER, /* tp_flags */
861 "GDB inferior object", /* tp_doc */
862 0, /* tp_traverse */
863 0, /* tp_clear */
864 0, /* tp_richcompare */
865 0, /* tp_weaklistoffset */
866 0, /* tp_iter */
867 0, /* tp_iternext */
868 inferior_object_methods, /* tp_methods */
869 0, /* tp_members */
870 inferior_object_getset, /* tp_getset */
871 0, /* tp_base */
872 0, /* tp_dict */
873 0, /* tp_descr_get */
874 0, /* tp_descr_set */
875 0, /* tp_dictoffset */
876 0, /* tp_init */
877 0 /* tp_alloc */
878 };
879
880 #ifdef IS_PY3K
881
882 static PyBufferProcs buffer_procs =
883 {
884 get_buffer
885 };
886
887 #else
888
889 /* Python doesn't provide a decent way to get compatibility here. */
890 #if HAVE_LIBPYTHON2_4
891 #define CHARBUFFERPROC_NAME getcharbufferproc
892 #else
893 #define CHARBUFFERPROC_NAME charbufferproc
894 #endif
895
896 static PyBufferProcs buffer_procs = {
897 get_read_buffer,
898 get_write_buffer,
899 get_seg_count,
900 /* The cast here works around a difference between Python 2.4 and
901 Python 2.5. */
902 (CHARBUFFERPROC_NAME) get_char_buffer
903 };
904 #endif /* IS_PY3K */
905
906 static PyTypeObject membuf_object_type = {
907 PyVarObject_HEAD_INIT (NULL, 0)
908 "gdb.Membuf", /*tp_name*/
909 sizeof (membuf_object), /*tp_basicsize*/
910 0, /*tp_itemsize*/
911 mbpy_dealloc, /*tp_dealloc*/
912 0, /*tp_print*/
913 0, /*tp_getattr*/
914 0, /*tp_setattr*/
915 0, /*tp_compare*/
916 0, /*tp_repr*/
917 0, /*tp_as_number*/
918 0, /*tp_as_sequence*/
919 0, /*tp_as_mapping*/
920 0, /*tp_hash */
921 0, /*tp_call*/
922 mbpy_str, /*tp_str*/
923 0, /*tp_getattro*/
924 0, /*tp_setattro*/
925 &buffer_procs, /*tp_as_buffer*/
926 Py_TPFLAGS_DEFAULT, /*tp_flags*/
927 "GDB memory buffer object", /*tp_doc*/
928 0, /* tp_traverse */
929 0, /* tp_clear */
930 0, /* tp_richcompare */
931 0, /* tp_weaklistoffset */
932 0, /* tp_iter */
933 0, /* tp_iternext */
934 0, /* tp_methods */
935 0, /* tp_members */
936 0, /* tp_getset */
937 0, /* tp_base */
938 0, /* tp_dict */
939 0, /* tp_descr_get */
940 0, /* tp_descr_set */
941 0, /* tp_dictoffset */
942 0, /* tp_init */
943 0, /* tp_alloc */
944 };
This page took 0.048591 seconds and 4 git commands to generate.