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