Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(492)

Side by Side Diff: gdb/python/py-inferior.c

Issue 11969036: Merge GDB 7.5.1 (Closed) Base URL: http://git.chromium.org/native_client/nacl-gdb.git@master
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gdb/python/py-frame.c ('k') | gdb/python/py-infthread.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Python interface to inferiors. 1 /* Python interface to inferiors.
2 2
3 Copyright (C) 2009-2012 Free Software Foundation, Inc. 3 Copyright (C) 2009-2012 Free Software Foundation, Inc.
4 4
5 This file is part of GDB. 5 This file is part of GDB.
6 6
7 This program is free software; you can redistribute it and/or modify 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 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 9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version. 10 (at your option) any later version.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 PyErr_SetString (PyExc_RuntimeError, \ 74 PyErr_SetString (PyExc_RuntimeError, \
75 _("Inferior no longer exists.")); \ 75 _("Inferior no longer exists.")); \
76 return NULL; \ 76 return NULL; \
77 } \ 77 } \
78 } while (0) 78 } while (0)
79 79
80 static void 80 static void
81 python_on_normal_stop (struct bpstats *bs, int print_frame) 81 python_on_normal_stop (struct bpstats *bs, int print_frame)
82 { 82 {
83 struct cleanup *cleanup; 83 struct cleanup *cleanup;
84 enum target_signal stop_signal; 84 enum gdb_signal stop_signal;
85 85
86 if (!find_thread_ptid (inferior_ptid)) 86 if (!find_thread_ptid (inferior_ptid))
87 return; 87 return;
88 88
89 stop_signal = inferior_thread ()->suspend.stop_signal; 89 stop_signal = inferior_thread ()->suspend.stop_signal;
90 90
91 cleanup = ensure_python_env (get_current_arch (), current_language); 91 cleanup = ensure_python_env (get_current_arch (), current_language);
92 92
93 if (emit_stop_event (bs, stop_signal) < 0) 93 if (emit_stop_event (bs, stop_signal) < 0)
94 gdbpy_print_stack (); 94 gdbpy_print_stack ();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 173
174 return (PyObject *) inf_obj; 174 return (PyObject *) inf_obj;
175 } 175 }
176 176
177 /* Finds the Python Inferior object for the given PID. Returns a 177 /* Finds the Python Inferior object for the given PID. Returns a
178 reference, or NULL if PID does not match any inferior object. */ 178 reference, or NULL if PID does not match any inferior object. */
179 179
180 PyObject * 180 PyObject *
181 find_inferior_object (int pid) 181 find_inferior_object (int pid)
182 { 182 {
183 struct inflist_entry *p;
184 struct inferior *inf = find_inferior_pid (pid); 183 struct inferior *inf = find_inferior_pid (pid);
185 184
186 if (inf) 185 if (inf)
187 return inferior_to_inferior_object (inf); 186 return inferior_to_inferior_object (inf);
188 187
189 return NULL; 188 return NULL;
190 } 189 }
191 190
192 thread_object * 191 thread_object *
193 find_thread_object (ptid_t ptid) 192 find_thread_object (ptid_t ptid)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 inf_obj->nthreads++; 249 inf_obj->nthreads++;
251 250
252 do_cleanups (cleanup); 251 do_cleanups (cleanup);
253 } 252 }
254 253
255 static void 254 static void
256 delete_thread_object (struct thread_info *tp, int ignore) 255 delete_thread_object (struct thread_info *tp, int ignore)
257 { 256 {
258 struct cleanup *cleanup; 257 struct cleanup *cleanup;
259 inferior_object *inf_obj; 258 inferior_object *inf_obj;
260 thread_object *thread_obj;
261 struct threadlist_entry **entry, *tmp; 259 struct threadlist_entry **entry, *tmp;
262 260
263 cleanup = ensure_python_env (python_gdbarch, python_language); 261 cleanup = ensure_python_env (python_gdbarch, python_language);
264 262
265 inf_obj = (inferior_object *) find_inferior_object (PIDGET(tp->ptid)); 263 inf_obj = (inferior_object *) find_inferior_object (PIDGET(tp->ptid));
266 if (!inf_obj) 264 if (!inf_obj)
267 { 265 {
268 do_cleanups (cleanup); 266 do_cleanups (cleanup);
269 return; 267 return;
270 } 268 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 } 385 }
388 386
389 tuple = PyList_AsTuple (list); 387 tuple = PyList_AsTuple (list);
390 Py_DECREF (list); 388 Py_DECREF (list);
391 389
392 return tuple; 390 return tuple;
393 } 391 }
394 392
395 /* Membuf and memory manipulation. */ 393 /* Membuf and memory manipulation. */
396 394
397 /* Implementation of gdb.read_memory (address, length). 395 /* Implementation of Inferior.read_memory (address, length).
398 Returns a Python buffer object with LENGTH bytes of the inferior's 396 Returns a Python buffer object with LENGTH bytes of the inferior's
399 memory at ADDRESS. Both arguments are integers. Returns NULL on error, 397 memory at ADDRESS. Both arguments are integers. Returns NULL on error,
400 with a python exception set. */ 398 with a python exception set. */
401 static PyObject * 399 static PyObject *
402 infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw) 400 infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
403 { 401 {
404 int error = 0; 402 int error = 0;
405 CORE_ADDR addr, length; 403 CORE_ADDR addr, length;
406 void *buffer = NULL; 404 void *buffer = NULL;
407 membuf_object *membuf_obj; 405 membuf_object *membuf_obj;
408 PyObject *addr_obj, *length_obj; 406 PyObject *addr_obj, *length_obj, *result;
409 struct cleanup *cleanups;
410 volatile struct gdb_exception except; 407 volatile struct gdb_exception except;
411 static char *keywords[] = { "address", "length", NULL }; 408 static char *keywords[] = { "address", "length", NULL };
412 409
413 if (! PyArg_ParseTupleAndKeywords (args, kw, "OO", keywords, 410 if (! PyArg_ParseTupleAndKeywords (args, kw, "OO", keywords,
414 &addr_obj, &length_obj)) 411 &addr_obj, &length_obj))
415 return NULL; 412 return NULL;
416 413
417 cleanups = make_cleanup (null_cleanup, NULL);
418
419 TRY_CATCH (except, RETURN_MASK_ALL) 414 TRY_CATCH (except, RETURN_MASK_ALL)
420 { 415 {
421 if (!get_addr_from_python (addr_obj, &addr) 416 if (!get_addr_from_python (addr_obj, &addr)
422 || !get_addr_from_python (length_obj, &length)) 417 || !get_addr_from_python (length_obj, &length))
423 { 418 {
424 error = 1; 419 error = 1;
425 break; 420 break;
426 } 421 }
427 422
428 buffer = xmalloc (length); 423 buffer = xmalloc (length);
429 make_cleanup (xfree, buffer);
430 424
431 read_memory (addr, buffer, length); 425 read_memory (addr, buffer, length);
432 } 426 }
433 if (except.reason < 0) 427 if (except.reason < 0)
434 { 428 {
435 do_cleanups (cleanups); 429 xfree (buffer);
436 GDB_PY_HANDLE_EXCEPTION (except); 430 GDB_PY_HANDLE_EXCEPTION (except);
437 } 431 }
438 432
439 if (error) 433 if (error)
440 { 434 {
441 do_cleanups (cleanups); 435 xfree (buffer);
442 return NULL; 436 return NULL;
443 } 437 }
444 438
445 membuf_obj = PyObject_New (membuf_object, &membuf_object_type); 439 membuf_obj = PyObject_New (membuf_object, &membuf_object_type);
446 if (membuf_obj == NULL) 440 if (membuf_obj == NULL)
447 { 441 {
442 xfree (buffer);
448 PyErr_SetString (PyExc_MemoryError, 443 PyErr_SetString (PyExc_MemoryError,
449 _("Could not allocate memory buffer object.")); 444 _("Could not allocate memory buffer object."));
450 do_cleanups (cleanups);
451 return NULL; 445 return NULL;
452 } 446 }
453 447
454 discard_cleanups (cleanups);
455
456 membuf_obj->buffer = buffer; 448 membuf_obj->buffer = buffer;
457 membuf_obj->addr = addr; 449 membuf_obj->addr = addr;
458 membuf_obj->length = length; 450 membuf_obj->length = length;
459 451
460 return PyBuffer_FromReadWriteObject ((PyObject *) membuf_obj, 0, 452 result = PyBuffer_FromReadWriteObject ((PyObject *) membuf_obj, 0,
461 » » » » Py_END_OF_BUFFER); 453 » » » » » Py_END_OF_BUFFER);
454 Py_DECREF (membuf_obj);
455 return result;
462 } 456 }
463 457
464 /* Implementation of gdb.write_memory (address, buffer [, length]). 458 /* Implementation of Inferior.write_memory (address, buffer [, length]).
465 Writes the contents of BUFFER (a Python object supporting the read 459 Writes the contents of BUFFER (a Python object supporting the read
466 buffer protocol) at ADDRESS in the inferior's memory. Write LENGTH 460 buffer protocol) at ADDRESS in the inferior's memory. Write LENGTH
467 bytes from BUFFER, or its entire contents if the argument is not 461 bytes from BUFFER, or its entire contents if the argument is not
468 provided. The function returns nothing. Returns NULL on error, with 462 provided. The function returns nothing. Returns NULL on error, with
469 a python exception set. */ 463 a python exception set. */
470 static PyObject * 464 static PyObject *
471 infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw) 465 infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw)
472 { 466 {
473 Py_ssize_t buf_len; 467 Py_ssize_t buf_len;
474 int error = 0; 468 int error = 0;
(...skipping 17 matching lines...) Expand all
492 break; 486 break;
493 } 487 }
494 488
495 if (!length_obj) 489 if (!length_obj)
496 length = buf_len; 490 length = buf_len;
497 else if (!get_addr_from_python (length_obj, &length)) 491 else if (!get_addr_from_python (length_obj, &length))
498 { 492 {
499 error = 1; 493 error = 1;
500 break; 494 break;
501 } 495 }
502 write_memory (addr, buffer, length); 496 write_memory_with_notification (addr, buffer, length);
503 } 497 }
504 GDB_PY_HANDLE_EXCEPTION (except); 498 GDB_PY_HANDLE_EXCEPTION (except);
505 499
506 if (error) 500 if (error)
507 return NULL; 501 return NULL;
508 502
509 Py_RETURN_NONE; 503 Py_RETURN_NONE;
510 } 504 }
511 505
512 /* Destructor of Membuf objects. */ 506 /* Destructor of Membuf objects. */
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 0, /* tp_members */ 861 0, /* tp_members */
868 0, /* tp_getset */ 862 0, /* tp_getset */
869 0, /* tp_base */ 863 0, /* tp_base */
870 0, /* tp_dict */ 864 0, /* tp_dict */
871 0, /* tp_descr_get */ 865 0, /* tp_descr_get */
872 0, /* tp_descr_set */ 866 0, /* tp_descr_set */
873 0, /* tp_dictoffset */ 867 0, /* tp_dictoffset */
874 0, /* tp_init */ 868 0, /* tp_init */
875 0, /* tp_alloc */ 869 0, /* tp_alloc */
876 }; 870 };
OLDNEW
« no previous file with comments | « gdb/python/py-frame.c ('k') | gdb/python/py-infthread.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698