* python/py-inferior.c: Update comments of infpy_read_memory
[deliverable/binutils-gdb.git] / gdb / python / python.c
1 /* General python/gdb code
2
3 Copyright (C) 2008-2012 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 "arch-utils.h"
22 #include "command.h"
23 #include "ui-out.h"
24 #include "cli/cli-script.h"
25 #include "gdbcmd.h"
26 #include "progspace.h"
27 #include "objfiles.h"
28 #include "value.h"
29 #include "language.h"
30 #include "exceptions.h"
31 #include "event-loop.h"
32 #include "serial.h"
33 #include "readline/tilde.h"
34 #include "python.h"
35
36 #include <ctype.h>
37
38 /* Declared constants and enum for python stack printing. */
39 static const char python_excp_none[] = "none";
40 static const char python_excp_full[] = "full";
41 static const char python_excp_message[] = "message";
42
43 /* "set python print-stack" choices. */
44 static const char *const python_excp_enums[] =
45 {
46 python_excp_none,
47 python_excp_full,
48 python_excp_message,
49 NULL
50 };
51
52 /* The exception printing variable. 'full' if we want to print the
53 error message and stack, 'none' if we want to print nothing, and
54 'message' if we only want to print the error message. 'message' is
55 the default. */
56 static const char *gdbpy_should_print_stack = python_excp_message;
57
58 #ifdef HAVE_PYTHON
59
60 #include "libiberty.h"
61 #include "cli/cli-decode.h"
62 #include "charset.h"
63 #include "top.h"
64 #include "solib.h"
65 #include "python-internal.h"
66 #include "linespec.h"
67 #include "source.h"
68 #include "version.h"
69 #include "target.h"
70 #include "gdbthread.h"
71 #include "observer.h"
72 #include "interps.h"
73
74 static PyMethodDef GdbMethods[];
75
76 PyObject *gdb_module;
77
78 /* Some string constants we may wish to use. */
79 PyObject *gdbpy_to_string_cst;
80 PyObject *gdbpy_children_cst;
81 PyObject *gdbpy_display_hint_cst;
82 PyObject *gdbpy_doc_cst;
83 PyObject *gdbpy_enabled_cst;
84 PyObject *gdbpy_value_cst;
85
86 /* The GdbError exception. */
87 PyObject *gdbpy_gdberror_exc;
88
89 /* The `gdb.error' base class. */
90 PyObject *gdbpy_gdb_error;
91
92 /* The `gdb.MemoryError' exception. */
93 PyObject *gdbpy_gdb_memory_error;
94
95 /* Architecture and language to be used in callbacks from
96 the Python interpreter. */
97 struct gdbarch *python_gdbarch;
98 const struct language_defn *python_language;
99
100 /* Restore global language and architecture and Python GIL state
101 when leaving the Python interpreter. */
102
103 struct python_env
104 {
105 PyGILState_STATE state;
106 struct gdbarch *gdbarch;
107 const struct language_defn *language;
108 PyObject *error_type, *error_value, *error_traceback;
109 };
110
111 static void
112 restore_python_env (void *p)
113 {
114 struct python_env *env = (struct python_env *)p;
115
116 /* Leftover Python error is forbidden by Python Exception Handling. */
117 if (PyErr_Occurred ())
118 {
119 /* This order is similar to the one calling error afterwards. */
120 gdbpy_print_stack ();
121 warning (_("internal error: Unhandled Python exception"));
122 }
123
124 PyErr_Restore (env->error_type, env->error_value, env->error_traceback);
125
126 PyGILState_Release (env->state);
127 python_gdbarch = env->gdbarch;
128 python_language = env->language;
129 xfree (env);
130 }
131
132 /* Called before entering the Python interpreter to install the
133 current language and architecture to be used for Python values. */
134
135 struct cleanup *
136 ensure_python_env (struct gdbarch *gdbarch,
137 const struct language_defn *language)
138 {
139 struct python_env *env = xmalloc (sizeof *env);
140
141 env->state = PyGILState_Ensure ();
142 env->gdbarch = python_gdbarch;
143 env->language = python_language;
144
145 python_gdbarch = gdbarch;
146 python_language = language;
147
148 /* Save it and ensure ! PyErr_Occurred () afterwards. */
149 PyErr_Fetch (&env->error_type, &env->error_value, &env->error_traceback);
150
151 return make_cleanup (restore_python_env, env);
152 }
153
154 /* A wrapper around PyRun_SimpleFile. FILE is the Python script to run
155 named FILENAME.
156
157 On Windows hosts few users would build Python themselves (this is no
158 trivial task on this platform), and thus use binaries built by
159 someone else instead. There may happen situation where the Python
160 library and GDB are using two different versions of the C runtime
161 library. Python, being built with VC, would use one version of the
162 msvcr DLL (Eg. msvcr100.dll), while MinGW uses msvcrt.dll.
163 A FILE * from one runtime does not necessarily operate correctly in
164 the other runtime.
165
166 To work around this potential issue, we create on Windows hosts the
167 FILE object using Python routines, thus making sure that it is
168 compatible with the Python library. */
169
170 static void
171 python_run_simple_file (FILE *file, const char *filename)
172 {
173 #ifndef _WIN32
174
175 PyRun_SimpleFile (file, filename);
176
177 #else /* _WIN32 */
178
179 char *full_path;
180 PyObject *python_file;
181 struct cleanup *cleanup;
182
183 /* Because we have a string for a filename, and are using Python to
184 open the file, we need to expand any tilde in the path first. */
185 full_path = tilde_expand (filename);
186 cleanup = make_cleanup (xfree, full_path);
187 python_file = PyFile_FromString (full_path, "r");
188 if (! python_file)
189 {
190 do_cleanups (cleanup);
191 gdbpy_print_stack ();
192 error (_("Error while opening file: %s"), full_path);
193 }
194
195 make_cleanup_py_decref (python_file);
196 PyRun_SimpleFile (PyFile_AsFile (python_file), filename);
197 do_cleanups (cleanup);
198
199 #endif /* _WIN32 */
200 }
201
202 /* Given a command_line, return a command string suitable for passing
203 to Python. Lines in the string are separated by newlines. The
204 return value is allocated using xmalloc and the caller is
205 responsible for freeing it. */
206
207 static char *
208 compute_python_string (struct command_line *l)
209 {
210 struct command_line *iter;
211 char *script = NULL;
212 int size = 0;
213 int here;
214
215 for (iter = l; iter; iter = iter->next)
216 size += strlen (iter->line) + 1;
217
218 script = xmalloc (size + 1);
219 here = 0;
220 for (iter = l; iter; iter = iter->next)
221 {
222 int len = strlen (iter->line);
223
224 strcpy (&script[here], iter->line);
225 here += len;
226 script[here++] = '\n';
227 }
228 script[here] = '\0';
229 return script;
230 }
231
232 /* Take a command line structure representing a 'python' command, and
233 evaluate its body using the Python interpreter. */
234
235 void
236 eval_python_from_control_command (struct command_line *cmd)
237 {
238 int ret;
239 char *script;
240 struct cleanup *cleanup;
241
242 if (cmd->body_count != 1)
243 error (_("Invalid \"python\" block structure."));
244
245 cleanup = ensure_python_env (get_current_arch (), current_language);
246
247 script = compute_python_string (cmd->body_list[0]);
248 ret = PyRun_SimpleString (script);
249 xfree (script);
250 if (ret)
251 error (_("Error while executing Python code."));
252
253 do_cleanups (cleanup);
254 }
255
256 /* Implementation of the gdb "python" command. */
257
258 static void
259 python_command (char *arg, int from_tty)
260 {
261 struct cleanup *cleanup;
262
263 cleanup = ensure_python_env (get_current_arch (), current_language);
264
265 make_cleanup_restore_integer (&interpreter_async);
266 interpreter_async = 0;
267
268 while (arg && *arg && isspace (*arg))
269 ++arg;
270 if (arg && *arg)
271 {
272 if (PyRun_SimpleString (arg))
273 error (_("Error while executing Python code."));
274 }
275 else
276 {
277 struct command_line *l = get_command_line (python_control, "");
278
279 make_cleanup_free_command_lines (&l);
280 execute_control_command_untraced (l);
281 }
282
283 do_cleanups (cleanup);
284 }
285
286 \f
287
288 /* Transform a gdb parameters's value into a Python value. May return
289 NULL (and set a Python exception) on error. Helper function for
290 get_parameter. */
291 PyObject *
292 gdbpy_parameter_value (enum var_types type, void *var)
293 {
294 switch (type)
295 {
296 case var_string:
297 case var_string_noescape:
298 case var_optional_filename:
299 case var_filename:
300 case var_enum:
301 {
302 char *str = * (char **) var;
303
304 if (! str)
305 str = "";
306 return PyString_Decode (str, strlen (str), host_charset (), NULL);
307 }
308
309 case var_boolean:
310 {
311 if (* (int *) var)
312 Py_RETURN_TRUE;
313 else
314 Py_RETURN_FALSE;
315 }
316
317 case var_auto_boolean:
318 {
319 enum auto_boolean ab = * (enum auto_boolean *) var;
320
321 if (ab == AUTO_BOOLEAN_TRUE)
322 Py_RETURN_TRUE;
323 else if (ab == AUTO_BOOLEAN_FALSE)
324 Py_RETURN_FALSE;
325 else
326 Py_RETURN_NONE;
327 }
328
329 case var_integer:
330 if ((* (int *) var) == INT_MAX)
331 Py_RETURN_NONE;
332 /* Fall through. */
333 case var_zinteger:
334 return PyLong_FromLong (* (int *) var);
335
336 case var_uinteger:
337 {
338 unsigned int val = * (unsigned int *) var;
339
340 if (val == UINT_MAX)
341 Py_RETURN_NONE;
342 return PyLong_FromUnsignedLong (val);
343 }
344 }
345
346 return PyErr_Format (PyExc_RuntimeError,
347 _("Programmer error: unhandled type."));
348 }
349
350 /* A Python function which returns a gdb parameter's value as a Python
351 value. */
352
353 PyObject *
354 gdbpy_parameter (PyObject *self, PyObject *args)
355 {
356 struct cmd_list_element *alias, *prefix, *cmd;
357 const char *arg;
358 char *newarg;
359 int found = -1;
360 volatile struct gdb_exception except;
361
362 if (! PyArg_ParseTuple (args, "s", &arg))
363 return NULL;
364
365 newarg = concat ("show ", arg, (char *) NULL);
366
367 TRY_CATCH (except, RETURN_MASK_ALL)
368 {
369 found = lookup_cmd_composition (newarg, &alias, &prefix, &cmd);
370 }
371 xfree (newarg);
372 GDB_PY_HANDLE_EXCEPTION (except);
373 if (!found)
374 return PyErr_Format (PyExc_RuntimeError,
375 _("Could not find parameter `%s'."), arg);
376
377 if (! cmd->var)
378 return PyErr_Format (PyExc_RuntimeError,
379 _("`%s' is not a parameter."), arg);
380 return gdbpy_parameter_value (cmd->var_type, cmd->var);
381 }
382
383 /* Wrapper for target_charset. */
384
385 static PyObject *
386 gdbpy_target_charset (PyObject *self, PyObject *args)
387 {
388 const char *cset = target_charset (python_gdbarch);
389
390 return PyUnicode_Decode (cset, strlen (cset), host_charset (), NULL);
391 }
392
393 /* Wrapper for target_wide_charset. */
394
395 static PyObject *
396 gdbpy_target_wide_charset (PyObject *self, PyObject *args)
397 {
398 const char *cset = target_wide_charset (python_gdbarch);
399
400 return PyUnicode_Decode (cset, strlen (cset), host_charset (), NULL);
401 }
402
403 /* A Python function which evaluates a string using the gdb CLI. */
404
405 static PyObject *
406 execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
407 {
408 const char *arg;
409 PyObject *from_tty_obj = NULL, *to_string_obj = NULL;
410 int from_tty, to_string;
411 volatile struct gdb_exception except;
412 static char *keywords[] = {"command", "from_tty", "to_string", NULL };
413 char *result = NULL;
414
415 if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!O!", keywords, &arg,
416 &PyBool_Type, &from_tty_obj,
417 &PyBool_Type, &to_string_obj))
418 return NULL;
419
420 from_tty = 0;
421 if (from_tty_obj)
422 {
423 int cmp = PyObject_IsTrue (from_tty_obj);
424 if (cmp < 0)
425 return NULL;
426 from_tty = cmp;
427 }
428
429 to_string = 0;
430 if (to_string_obj)
431 {
432 int cmp = PyObject_IsTrue (to_string_obj);
433 if (cmp < 0)
434 return NULL;
435 to_string = cmp;
436 }
437
438 TRY_CATCH (except, RETURN_MASK_ALL)
439 {
440 /* Copy the argument text in case the command modifies it. */
441 char *copy = xstrdup (arg);
442 struct cleanup *cleanup = make_cleanup (xfree, copy);
443
444 make_cleanup_restore_integer (&interpreter_async);
445 interpreter_async = 0;
446
447 prevent_dont_repeat ();
448 if (to_string)
449 result = execute_command_to_string (copy, from_tty);
450 else
451 {
452 result = NULL;
453 execute_command (copy, from_tty);
454 }
455
456 do_cleanups (cleanup);
457 }
458 GDB_PY_HANDLE_EXCEPTION (except);
459
460 /* Do any commands attached to breakpoint we stopped at. */
461 bpstat_do_actions ();
462
463 if (result)
464 {
465 PyObject *r = PyString_FromString (result);
466 xfree (result);
467 return r;
468 }
469 Py_RETURN_NONE;
470 }
471
472 /* Implementation of gdb.solib_name (Long) -> String.
473 Returns the name of the shared library holding a given address, or None. */
474
475 static PyObject *
476 gdbpy_solib_name (PyObject *self, PyObject *args)
477 {
478 char *soname;
479 PyObject *str_obj;
480 gdb_py_longest pc;
481
482 if (!PyArg_ParseTuple (args, GDB_PY_LL_ARG, &pc))
483 return NULL;
484
485 soname = solib_name_from_address (current_program_space, pc);
486 if (soname)
487 str_obj = PyString_Decode (soname, strlen (soname), host_charset (), NULL);
488 else
489 {
490 str_obj = Py_None;
491 Py_INCREF (Py_None);
492 }
493
494 return str_obj;
495 }
496
497 /* A Python function which is a wrapper for decode_line_1. */
498
499 static PyObject *
500 gdbpy_decode_line (PyObject *self, PyObject *args)
501 {
502 struct symtabs_and_lines sals = { NULL, 0 }; /* Initialize to
503 appease gcc. */
504 struct symtab_and_line sal;
505 const char *arg = NULL;
506 char *copy_to_free = NULL, *copy = NULL;
507 struct cleanup *cleanups;
508 PyObject *result = NULL;
509 PyObject *return_result = NULL;
510 PyObject *unparsed = NULL;
511 volatile struct gdb_exception except;
512
513 if (! PyArg_ParseTuple (args, "|s", &arg))
514 return NULL;
515
516 cleanups = make_cleanup (null_cleanup, NULL);
517
518 sals.sals = NULL;
519 TRY_CATCH (except, RETURN_MASK_ALL)
520 {
521 if (arg)
522 {
523 copy = xstrdup (arg);
524 copy_to_free = copy;
525 sals = decode_line_1 (&copy, 0, 0, 0);
526 }
527 else
528 {
529 set_default_source_symtab_and_line ();
530 sal = get_current_source_symtab_and_line ();
531 sals.sals = &sal;
532 sals.nelts = 1;
533 }
534 }
535
536 if (sals.sals != NULL && sals.sals != &sal)
537 {
538 make_cleanup (xfree, copy_to_free);
539 make_cleanup (xfree, sals.sals);
540 }
541
542 if (except.reason < 0)
543 {
544 do_cleanups (cleanups);
545 /* We know this will always throw. */
546 GDB_PY_HANDLE_EXCEPTION (except);
547 }
548
549 if (sals.nelts)
550 {
551 int i;
552
553 result = PyTuple_New (sals.nelts);
554 if (! result)
555 goto error;
556 for (i = 0; i < sals.nelts; ++i)
557 {
558 PyObject *obj;
559
560 obj = symtab_and_line_to_sal_object (sals.sals[i]);
561 if (! obj)
562 {
563 Py_DECREF (result);
564 goto error;
565 }
566
567 PyTuple_SetItem (result, i, obj);
568 }
569 }
570 else
571 {
572 result = Py_None;
573 Py_INCREF (Py_None);
574 }
575
576 return_result = PyTuple_New (2);
577 if (! return_result)
578 {
579 Py_DECREF (result);
580 goto error;
581 }
582
583 if (copy && strlen (copy) > 0)
584 {
585 unparsed = PyString_FromString (copy);
586 if (unparsed == NULL)
587 {
588 Py_DECREF (result);
589 Py_DECREF (return_result);
590 return_result = NULL;
591 goto error;
592 }
593 }
594 else
595 {
596 unparsed = Py_None;
597 Py_INCREF (Py_None);
598 }
599
600 PyTuple_SetItem (return_result, 0, unparsed);
601 PyTuple_SetItem (return_result, 1, result);
602
603 error:
604 do_cleanups (cleanups);
605
606 return return_result;
607 }
608
609 /* Parse a string and evaluate it as an expression. */
610 static PyObject *
611 gdbpy_parse_and_eval (PyObject *self, PyObject *args)
612 {
613 const char *expr_str;
614 struct value *result = NULL;
615 volatile struct gdb_exception except;
616
617 if (!PyArg_ParseTuple (args, "s", &expr_str))
618 return NULL;
619
620 TRY_CATCH (except, RETURN_MASK_ALL)
621 {
622 char *copy = xstrdup (expr_str);
623 struct cleanup *cleanup = make_cleanup (xfree, copy);
624
625 result = parse_and_eval (copy);
626 do_cleanups (cleanup);
627 }
628 GDB_PY_HANDLE_EXCEPTION (except);
629
630 return value_to_value_object (result);
631 }
632
633 /* Implementation of gdb.find_pc_line function.
634 Returns the gdb.Symtab_and_line object corresponding to a PC value. */
635
636 static PyObject *
637 gdbpy_find_pc_line (PyObject *self, PyObject *args)
638 {
639 struct symtab_and_line sal;
640 CORE_ADDR pc;
641 gdb_py_ulongest pc_llu;
642
643 if (!PyArg_ParseTuple (args, GDB_PY_LLU_ARG, &pc_llu))
644 return NULL;
645
646 pc = (CORE_ADDR) pc_llu;
647 sal = find_pc_line (pc, 0);
648 return symtab_and_line_to_sal_object (sal);
649 }
650
651 /* Read a file as Python code.
652 FILE is the file to run. FILENAME is name of the file FILE.
653 This does not throw any errors. If an exception occurs python will print
654 the traceback and clear the error indicator. */
655
656 void
657 source_python_script (FILE *file, const char *filename)
658 {
659 struct cleanup *cleanup;
660
661 cleanup = ensure_python_env (get_current_arch (), current_language);
662 python_run_simple_file (file, filename);
663 do_cleanups (cleanup);
664 }
665
666 \f
667
668 /* Posting and handling events. */
669
670 /* A single event. */
671 struct gdbpy_event
672 {
673 /* The Python event. This is just a callable object. */
674 PyObject *event;
675 /* The next event. */
676 struct gdbpy_event *next;
677 };
678
679 /* All pending events. */
680 static struct gdbpy_event *gdbpy_event_list;
681 /* The final link of the event list. */
682 static struct gdbpy_event **gdbpy_event_list_end;
683
684 /* We use a file handler, and not an async handler, so that we can
685 wake up the main thread even when it is blocked in poll(). */
686 static struct serial *gdbpy_event_fds[2];
687
688 /* The file handler callback. This reads from the internal pipe, and
689 then processes the Python event queue. This will always be run in
690 the main gdb thread. */
691
692 static void
693 gdbpy_run_events (struct serial *scb, void *context)
694 {
695 struct cleanup *cleanup;
696
697 cleanup = ensure_python_env (get_current_arch (), current_language);
698
699 /* Flush the fd. Do this before flushing the events list, so that
700 any new event post afterwards is sure to re-awake the event
701 loop. */
702 while (serial_readchar (gdbpy_event_fds[0], 0) >= 0)
703 ;
704
705 while (gdbpy_event_list)
706 {
707 /* Dispatching the event might push a new element onto the event
708 loop, so we update here "atomically enough". */
709 struct gdbpy_event *item = gdbpy_event_list;
710 gdbpy_event_list = gdbpy_event_list->next;
711 if (gdbpy_event_list == NULL)
712 gdbpy_event_list_end = &gdbpy_event_list;
713
714 /* Ignore errors. */
715 if (PyObject_CallObject (item->event, NULL) == NULL)
716 PyErr_Clear ();
717
718 Py_DECREF (item->event);
719 xfree (item);
720 }
721
722 do_cleanups (cleanup);
723 }
724
725 /* Submit an event to the gdb thread. */
726 static PyObject *
727 gdbpy_post_event (PyObject *self, PyObject *args)
728 {
729 struct gdbpy_event *event;
730 PyObject *func;
731 int wakeup;
732
733 if (!PyArg_ParseTuple (args, "O", &func))
734 return NULL;
735
736 if (!PyCallable_Check (func))
737 {
738 PyErr_SetString (PyExc_RuntimeError,
739 _("Posted event is not callable"));
740 return NULL;
741 }
742
743 Py_INCREF (func);
744
745 /* From here until the end of the function, we have the GIL, so we
746 can operate on our global data structures without worrying. */
747 wakeup = gdbpy_event_list == NULL;
748
749 event = XNEW (struct gdbpy_event);
750 event->event = func;
751 event->next = NULL;
752 *gdbpy_event_list_end = event;
753 gdbpy_event_list_end = &event->next;
754
755 /* Wake up gdb when needed. */
756 if (wakeup)
757 {
758 char c = 'q'; /* Anything. */
759
760 if (serial_write (gdbpy_event_fds[1], &c, 1))
761 return PyErr_SetFromErrno (PyExc_IOError);
762 }
763
764 Py_RETURN_NONE;
765 }
766
767 /* Initialize the Python event handler. */
768 static void
769 gdbpy_initialize_events (void)
770 {
771 if (serial_pipe (gdbpy_event_fds) == 0)
772 {
773 gdbpy_event_list_end = &gdbpy_event_list;
774 serial_async (gdbpy_event_fds[0], gdbpy_run_events, NULL);
775 }
776 }
777
778 \f
779
780 static void
781 before_prompt_hook (const char *current_gdb_prompt)
782 {
783 struct cleanup *cleanup;
784 char *prompt = NULL;
785
786 cleanup = ensure_python_env (get_current_arch (), current_language);
787
788 if (PyObject_HasAttrString (gdb_module, "prompt_hook"))
789 {
790 PyObject *hook;
791
792 hook = PyObject_GetAttrString (gdb_module, "prompt_hook");
793 if (hook == NULL)
794 goto fail;
795
796 if (PyCallable_Check (hook))
797 {
798 PyObject *result;
799 PyObject *current_prompt;
800
801 current_prompt = PyString_FromString (current_gdb_prompt);
802 if (current_prompt == NULL)
803 goto fail;
804
805 result = PyObject_CallFunctionObjArgs (hook, current_prompt, NULL);
806
807 Py_DECREF (current_prompt);
808
809 if (result == NULL)
810 goto fail;
811
812 make_cleanup_py_decref (result);
813
814 /* Return type should be None, or a String. If it is None,
815 fall through, we will not set a prompt. If it is a
816 string, set PROMPT. Anything else, set an exception. */
817 if (result != Py_None && ! PyString_Check (result))
818 {
819 PyErr_Format (PyExc_RuntimeError,
820 _("Return from prompt_hook must " \
821 "be either a Python string, or None"));
822 goto fail;
823 }
824
825 if (result != Py_None)
826 {
827 prompt = python_string_to_host_string (result);
828
829 if (prompt == NULL)
830 goto fail;
831 else
832 make_cleanup (xfree, prompt);
833 }
834 }
835 }
836
837 /* If a prompt has been set, PROMPT will not be NULL. If it is
838 NULL, do not set the prompt. */
839 if (prompt != NULL)
840 set_prompt (prompt);
841
842 do_cleanups (cleanup);
843 return;
844
845 fail:
846 gdbpy_print_stack ();
847 do_cleanups (cleanup);
848 return;
849 }
850
851 \f
852
853 /* Printing. */
854
855 /* A python function to write a single string using gdb's filtered
856 output stream . The optional keyword STREAM can be used to write
857 to a particular stream. The default stream is to gdb_stdout. */
858
859 static PyObject *
860 gdbpy_write (PyObject *self, PyObject *args, PyObject *kw)
861 {
862 const char *arg;
863 static char *keywords[] = {"text", "stream", NULL };
864 int stream_type = 0;
865
866 if (! PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &arg,
867 &stream_type))
868 return NULL;
869
870 switch (stream_type)
871 {
872 case 1:
873 {
874 fprintf_filtered (gdb_stderr, "%s", arg);
875 break;
876 }
877 case 2:
878 {
879 fprintf_filtered (gdb_stdlog, "%s", arg);
880 break;
881 }
882 default:
883 fprintf_filtered (gdb_stdout, "%s", arg);
884 }
885
886 Py_RETURN_NONE;
887 }
888
889 /* A python function to flush a gdb stream. The optional keyword
890 STREAM can be used to flush a particular stream. The default stream
891 is gdb_stdout. */
892
893 static PyObject *
894 gdbpy_flush (PyObject *self, PyObject *args, PyObject *kw)
895 {
896 static char *keywords[] = {"stream", NULL };
897 int stream_type = 0;
898
899 if (! PyArg_ParseTupleAndKeywords (args, kw, "|i", keywords,
900 &stream_type))
901 return NULL;
902
903 switch (stream_type)
904 {
905 case 1:
906 {
907 gdb_flush (gdb_stderr);
908 break;
909 }
910 case 2:
911 {
912 gdb_flush (gdb_stdlog);
913 break;
914 }
915 default:
916 gdb_flush (gdb_stdout);
917 }
918
919 Py_RETURN_NONE;
920 }
921
922 /* Print a python exception trace, print just a message, or print
923 nothing and clear the python exception, depending on
924 gdbpy_should_print_stack. Only call this if a python exception is
925 set. */
926 void
927 gdbpy_print_stack (void)
928 {
929 /* Print "none", just clear exception. */
930 if (gdbpy_should_print_stack == python_excp_none)
931 {
932 PyErr_Clear ();
933 }
934 /* Print "full" message and backtrace. */
935 else if (gdbpy_should_print_stack == python_excp_full)
936 {
937 PyErr_Print ();
938 /* PyErr_Print doesn't necessarily end output with a newline.
939 This works because Python's stdout/stderr is fed through
940 printf_filtered. */
941 begin_line ();
942 }
943 /* Print "message", just error print message. */
944 else
945 {
946 PyObject *ptype, *pvalue, *ptraceback;
947 char *msg = NULL, *type = NULL;
948
949 PyErr_Fetch (&ptype, &pvalue, &ptraceback);
950
951 /* Fetch the error message contained within ptype, pvalue. */
952 msg = gdbpy_exception_to_string (ptype, pvalue);
953 type = gdbpy_obj_to_string (ptype);
954 if (msg == NULL)
955 {
956 /* An error occurred computing the string representation of the
957 error message. */
958 fprintf_filtered (gdb_stderr,
959 _("Error occurred computing Python error" \
960 "message.\n"));
961 }
962 else
963 fprintf_filtered (gdb_stderr, "Python Exception %s %s: \n",
964 type, msg);
965
966 Py_XDECREF (ptype);
967 Py_XDECREF (pvalue);
968 Py_XDECREF (ptraceback);
969 xfree (msg);
970 }
971 }
972
973 \f
974
975 /* Return the current Progspace.
976 There always is one. */
977
978 static PyObject *
979 gdbpy_get_current_progspace (PyObject *unused1, PyObject *unused2)
980 {
981 PyObject *result;
982
983 result = pspace_to_pspace_object (current_program_space);
984 if (result)
985 Py_INCREF (result);
986 return result;
987 }
988
989 /* Return a sequence holding all the Progspaces. */
990
991 static PyObject *
992 gdbpy_progspaces (PyObject *unused1, PyObject *unused2)
993 {
994 struct program_space *ps;
995 PyObject *list;
996
997 list = PyList_New (0);
998 if (!list)
999 return NULL;
1000
1001 ALL_PSPACES (ps)
1002 {
1003 PyObject *item = pspace_to_pspace_object (ps);
1004
1005 if (!item || PyList_Append (list, item) == -1)
1006 {
1007 Py_DECREF (list);
1008 return NULL;
1009 }
1010 }
1011
1012 return list;
1013 }
1014
1015 \f
1016
1017 /* The "current" objfile. This is set when gdb detects that a new
1018 objfile has been loaded. It is only set for the duration of a call to
1019 source_python_script_for_objfile; it is NULL at other times. */
1020 static struct objfile *gdbpy_current_objfile;
1021
1022 /* Set the current objfile to OBJFILE and then read FILE named FILENAME
1023 as Python code. This does not throw any errors. If an exception
1024 occurs python will print the traceback and clear the error indicator. */
1025
1026 void
1027 source_python_script_for_objfile (struct objfile *objfile, FILE *file,
1028 const char *filename)
1029 {
1030 struct cleanup *cleanups;
1031
1032 cleanups = ensure_python_env (get_objfile_arch (objfile), current_language);
1033 gdbpy_current_objfile = objfile;
1034
1035 python_run_simple_file (file, filename);
1036
1037 do_cleanups (cleanups);
1038 gdbpy_current_objfile = NULL;
1039 }
1040
1041 /* Return the current Objfile, or None if there isn't one. */
1042
1043 static PyObject *
1044 gdbpy_get_current_objfile (PyObject *unused1, PyObject *unused2)
1045 {
1046 PyObject *result;
1047
1048 if (! gdbpy_current_objfile)
1049 Py_RETURN_NONE;
1050
1051 result = objfile_to_objfile_object (gdbpy_current_objfile);
1052 if (result)
1053 Py_INCREF (result);
1054 return result;
1055 }
1056
1057 /* Return a sequence holding all the Objfiles. */
1058
1059 static PyObject *
1060 gdbpy_objfiles (PyObject *unused1, PyObject *unused2)
1061 {
1062 struct objfile *objf;
1063 PyObject *list;
1064
1065 list = PyList_New (0);
1066 if (!list)
1067 return NULL;
1068
1069 ALL_OBJFILES (objf)
1070 {
1071 PyObject *item = objfile_to_objfile_object (objf);
1072
1073 if (!item || PyList_Append (list, item) == -1)
1074 {
1075 Py_DECREF (list);
1076 return NULL;
1077 }
1078 }
1079
1080 return list;
1081 }
1082
1083 #else /* HAVE_PYTHON */
1084
1085 /* Dummy implementation of the gdb "python" command. */
1086
1087 static void
1088 python_command (char *arg, int from_tty)
1089 {
1090 while (arg && *arg && isspace (*arg))
1091 ++arg;
1092 if (arg && *arg)
1093 error (_("Python scripting is not supported in this copy of GDB."));
1094 else
1095 {
1096 struct command_line *l = get_command_line (python_control, "");
1097 struct cleanup *cleanups = make_cleanup_free_command_lines (&l);
1098
1099 execute_control_command_untraced (l);
1100 do_cleanups (cleanups);
1101 }
1102 }
1103
1104 void
1105 eval_python_from_control_command (struct command_line *cmd)
1106 {
1107 error (_("Python scripting is not supported in this copy of GDB."));
1108 }
1109
1110 void
1111 source_python_script (FILE *file, const char *filename)
1112 {
1113 throw_error (UNSUPPORTED_ERROR,
1114 _("Python scripting is not supported in this copy of GDB."));
1115 }
1116
1117 int
1118 gdbpy_should_stop (struct breakpoint_object *bp_obj)
1119 {
1120 internal_error (__FILE__, __LINE__,
1121 _("gdbpy_should_stop called when Python scripting is " \
1122 "not supported."));
1123 }
1124
1125 int
1126 gdbpy_breakpoint_has_py_cond (struct breakpoint_object *bp_obj)
1127 {
1128 internal_error (__FILE__, __LINE__,
1129 _("gdbpy_breakpoint_has_py_cond called when Python " \
1130 "scripting is not supported."));
1131 }
1132
1133 #endif /* HAVE_PYTHON */
1134
1135 \f
1136
1137 /* Lists for 'set python' commands. */
1138
1139 static struct cmd_list_element *user_set_python_list;
1140 static struct cmd_list_element *user_show_python_list;
1141
1142 /* Function for use by 'set python' prefix command. */
1143
1144 static void
1145 user_set_python (char *args, int from_tty)
1146 {
1147 help_list (user_set_python_list, "set python ", all_commands,
1148 gdb_stdout);
1149 }
1150
1151 /* Function for use by 'show python' prefix command. */
1152
1153 static void
1154 user_show_python (char *args, int from_tty)
1155 {
1156 cmd_show_list (user_show_python_list, from_tty, "");
1157 }
1158
1159 /* Initialize the Python code. */
1160
1161 /* Provide a prototype to silence -Wmissing-prototypes. */
1162 extern initialize_file_ftype _initialize_python;
1163
1164 void
1165 _initialize_python (void)
1166 {
1167 char *cmd_name;
1168 struct cmd_list_element *cmd;
1169
1170 add_com ("python", class_obscure, python_command,
1171 #ifdef HAVE_PYTHON
1172 _("\
1173 Evaluate a Python command.\n\
1174 \n\
1175 The command can be given as an argument, for instance:\n\
1176 \n\
1177 python print 23\n\
1178 \n\
1179 If no argument is given, the following lines are read and used\n\
1180 as the Python commands. Type a line containing \"end\" to indicate\n\
1181 the end of the command.")
1182 #else /* HAVE_PYTHON */
1183 _("\
1184 Evaluate a Python command.\n\
1185 \n\
1186 Python scripting is not supported in this copy of GDB.\n\
1187 This command is only a placeholder.")
1188 #endif /* HAVE_PYTHON */
1189 );
1190
1191 /* Add set/show python print-stack. */
1192 add_prefix_cmd ("python", no_class, user_show_python,
1193 _("Prefix command for python preference settings."),
1194 &user_show_python_list, "show python ", 0,
1195 &showlist);
1196
1197 add_prefix_cmd ("python", no_class, user_set_python,
1198 _("Prefix command for python preference settings."),
1199 &user_set_python_list, "set python ", 0,
1200 &setlist);
1201
1202 add_setshow_enum_cmd ("print-stack", no_class, python_excp_enums,
1203 &gdbpy_should_print_stack, _("\
1204 Set mode for Python stack dump on error."), _("\
1205 Show the mode of Python stack printing on error."), _("\
1206 none == no stack or message will be printed.\n\
1207 full == a message and a stack will be printed.\n\
1208 message == an error message without a stack will be printed."),
1209 NULL, NULL,
1210 &user_set_python_list,
1211 &user_show_python_list);
1212
1213 #ifdef HAVE_PYTHON
1214 #ifdef WITH_PYTHON_PATH
1215 /* Work around problem where python gets confused about where it is,
1216 and then can't find its libraries, etc.
1217 NOTE: Python assumes the following layout:
1218 /foo/bin/python
1219 /foo/lib/pythonX.Y/...
1220 This must be done before calling Py_Initialize. */
1221 Py_SetProgramName (concat (ldirname (python_libdir), SLASH_STRING, "bin",
1222 SLASH_STRING, "python", NULL));
1223 #endif
1224
1225 Py_Initialize ();
1226 PyEval_InitThreads ();
1227
1228 gdb_module = Py_InitModule ("gdb", GdbMethods);
1229
1230 /* The casts to (char*) are for python 2.4. */
1231 PyModule_AddStringConstant (gdb_module, "VERSION", (char*) version);
1232 PyModule_AddStringConstant (gdb_module, "HOST_CONFIG", (char*) host_name);
1233 PyModule_AddStringConstant (gdb_module, "TARGET_CONFIG",
1234 (char*) target_name);
1235
1236 /* Add stream constants. */
1237 PyModule_AddIntConstant (gdb_module, "STDOUT", 0);
1238 PyModule_AddIntConstant (gdb_module, "STDERR", 1);
1239 PyModule_AddIntConstant (gdb_module, "STDLOG", 2);
1240
1241 /* gdb.parameter ("data-directory") doesn't necessarily exist when the python
1242 script below is run (depending on order of _initialize_* functions).
1243 Define the initial value of gdb.PYTHONDIR here. */
1244 {
1245 char *gdb_pythondir;
1246
1247 gdb_pythondir = concat (gdb_datadir, SLASH_STRING, "python", NULL);
1248 PyModule_AddStringConstant (gdb_module, "PYTHONDIR", gdb_pythondir);
1249 xfree (gdb_pythondir);
1250 }
1251
1252 gdbpy_gdb_error = PyErr_NewException ("gdb.error", PyExc_RuntimeError, NULL);
1253 PyModule_AddObject (gdb_module, "error", gdbpy_gdb_error);
1254
1255 gdbpy_gdb_memory_error = PyErr_NewException ("gdb.MemoryError",
1256 gdbpy_gdb_error, NULL);
1257 PyModule_AddObject (gdb_module, "MemoryError", gdbpy_gdb_memory_error);
1258
1259 gdbpy_gdberror_exc = PyErr_NewException ("gdb.GdbError", NULL, NULL);
1260 PyModule_AddObject (gdb_module, "GdbError", gdbpy_gdberror_exc);
1261
1262 gdbpy_initialize_auto_load ();
1263 gdbpy_initialize_values ();
1264 gdbpy_initialize_frames ();
1265 gdbpy_initialize_commands ();
1266 gdbpy_initialize_symbols ();
1267 gdbpy_initialize_symtabs ();
1268 gdbpy_initialize_blocks ();
1269 gdbpy_initialize_functions ();
1270 gdbpy_initialize_parameters ();
1271 gdbpy_initialize_types ();
1272 gdbpy_initialize_pspace ();
1273 gdbpy_initialize_objfile ();
1274 gdbpy_initialize_breakpoints ();
1275 gdbpy_initialize_finishbreakpoints ();
1276 gdbpy_initialize_lazy_string ();
1277 gdbpy_initialize_thread ();
1278 gdbpy_initialize_inferior ();
1279 gdbpy_initialize_events ();
1280
1281 gdbpy_initialize_eventregistry ();
1282 gdbpy_initialize_py_events ();
1283 gdbpy_initialize_event ();
1284 gdbpy_initialize_stop_event ();
1285 gdbpy_initialize_signal_event ();
1286 gdbpy_initialize_breakpoint_event ();
1287 gdbpy_initialize_continue_event ();
1288 gdbpy_initialize_exited_event ();
1289 gdbpy_initialize_thread_event ();
1290 gdbpy_initialize_new_objfile_event () ;
1291
1292 observer_attach_before_prompt (before_prompt_hook);
1293
1294 PyRun_SimpleString ("import gdb");
1295 PyRun_SimpleString ("gdb.pretty_printers = []");
1296
1297 gdbpy_to_string_cst = PyString_FromString ("to_string");
1298 gdbpy_children_cst = PyString_FromString ("children");
1299 gdbpy_display_hint_cst = PyString_FromString ("display_hint");
1300 gdbpy_doc_cst = PyString_FromString ("__doc__");
1301 gdbpy_enabled_cst = PyString_FromString ("enabled");
1302 gdbpy_value_cst = PyString_FromString ("value");
1303
1304 /* Release the GIL while gdb runs. */
1305 PyThreadState_Swap (NULL);
1306 PyEval_ReleaseLock ();
1307
1308 #endif /* HAVE_PYTHON */
1309 }
1310
1311 #ifdef HAVE_PYTHON
1312
1313 /* Perform the remaining python initializations.
1314 These must be done after GDB is at least mostly initialized.
1315 E.g., The "info pretty-printer" command needs the "info" prefix
1316 command installed. */
1317
1318 void
1319 finish_python_initialization (void)
1320 {
1321 struct cleanup *cleanup;
1322
1323 cleanup = ensure_python_env (get_current_arch (), current_language);
1324
1325 PyRun_SimpleString ("\
1326 import os\n\
1327 import sys\n\
1328 \n\
1329 class GdbOutputFile:\n\
1330 def close(self):\n\
1331 # Do nothing.\n\
1332 return None\n\
1333 \n\
1334 def isatty(self):\n\
1335 return False\n\
1336 \n\
1337 def write(self, s):\n\
1338 gdb.write(s, stream=gdb.STDOUT)\n \
1339 \n\
1340 def writelines(self, iterable):\n\
1341 for line in iterable:\n\
1342 self.write(line)\n\
1343 \n\
1344 def flush(self):\n\
1345 gdb.flush()\n\
1346 \n\
1347 sys.stdout = GdbOutputFile()\n\
1348 \n\
1349 class GdbOutputErrorFile:\n\
1350 def close(self):\n\
1351 # Do nothing.\n\
1352 return None\n\
1353 \n\
1354 def isatty(self):\n\
1355 return False\n\
1356 \n\
1357 def write(self, s):\n\
1358 gdb.write(s, stream=gdb.STDERR)\n \
1359 \n\
1360 def writelines(self, iterable):\n\
1361 for line in iterable:\n\
1362 self.write(line)\n \
1363 \n\
1364 def flush(self):\n\
1365 gdb.flush()\n\
1366 \n\
1367 sys.stderr = GdbOutputErrorFile()\n\
1368 \n\
1369 # Ideally this would live in the gdb module, but it's intentionally written\n\
1370 # in python, and we need this to bootstrap the gdb module.\n\
1371 \n\
1372 def GdbSetPythonDirectory (dir):\n\
1373 \"Set gdb.PYTHONDIR and update sys.path,etc.\"\n\
1374 old_dir = gdb.PYTHONDIR\n\
1375 gdb.PYTHONDIR = dir\n\
1376 # GDB's python scripts are stored inside gdb.PYTHONDIR. So insert\n\
1377 # that directory name at the start of sys.path to allow the Python\n\
1378 # interpreter to find them.\n\
1379 if old_dir in sys.path:\n\
1380 sys.path.remove (old_dir)\n\
1381 sys.path.insert (0, gdb.PYTHONDIR)\n\
1382 \n\
1383 # Tell python where to find submodules of gdb.\n\
1384 gdb.__path__ = [os.path.join (gdb.PYTHONDIR, 'gdb')]\n\
1385 \n\
1386 # The gdb module is implemented in C rather than in Python. As a result,\n\
1387 # the associated __init.py__ script is not not executed by default when\n\
1388 # the gdb module gets imported. Execute that script manually if it\n\
1389 # exists.\n\
1390 ipy = os.path.join (gdb.PYTHONDIR, 'gdb', '__init__.py')\n\
1391 if os.path.exists (ipy):\n\
1392 execfile (ipy)\n\
1393 \n\
1394 # Install the default gdb.PYTHONDIR.\n\
1395 GdbSetPythonDirectory (gdb.PYTHONDIR)\n\
1396 # Default prompt hook does nothing.\n\
1397 prompt_hook = None\n\
1398 # Ensure that sys.argv is set to something.\n\
1399 # We do not use PySys_SetArgvEx because it did not appear until 2.6.6.\n\
1400 sys.argv = ['']\n\
1401 ");
1402
1403 do_cleanups (cleanup);
1404 }
1405
1406 #endif /* HAVE_PYTHON */
1407
1408 \f
1409
1410 #ifdef HAVE_PYTHON
1411
1412 static PyMethodDef GdbMethods[] =
1413 {
1414 { "history", gdbpy_history, METH_VARARGS,
1415 "Get a value from history" },
1416 { "execute", (PyCFunction) execute_gdb_command, METH_VARARGS | METH_KEYWORDS,
1417 "Execute a gdb command" },
1418 { "parameter", gdbpy_parameter, METH_VARARGS,
1419 "Return a gdb parameter's value" },
1420
1421 { "breakpoints", gdbpy_breakpoints, METH_NOARGS,
1422 "Return a tuple of all breakpoint objects" },
1423
1424 { "default_visualizer", gdbpy_default_visualizer, METH_VARARGS,
1425 "Find the default visualizer for a Value." },
1426
1427 { "current_progspace", gdbpy_get_current_progspace, METH_NOARGS,
1428 "Return the current Progspace." },
1429 { "progspaces", gdbpy_progspaces, METH_NOARGS,
1430 "Return a sequence of all progspaces." },
1431
1432 { "current_objfile", gdbpy_get_current_objfile, METH_NOARGS,
1433 "Return the current Objfile being loaded, or None." },
1434 { "objfiles", gdbpy_objfiles, METH_NOARGS,
1435 "Return a sequence of all loaded objfiles." },
1436
1437 { "newest_frame", gdbpy_newest_frame, METH_NOARGS,
1438 "newest_frame () -> gdb.Frame.\n\
1439 Return the newest frame object." },
1440 { "selected_frame", gdbpy_selected_frame, METH_NOARGS,
1441 "selected_frame () -> gdb.Frame.\n\
1442 Return the selected frame object." },
1443 { "frame_stop_reason_string", gdbpy_frame_stop_reason_string, METH_VARARGS,
1444 "stop_reason_string (Integer) -> String.\n\
1445 Return a string explaining unwind stop reason." },
1446
1447 { "lookup_type", (PyCFunction) gdbpy_lookup_type,
1448 METH_VARARGS | METH_KEYWORDS,
1449 "lookup_type (name [, block]) -> type\n\
1450 Return a Type corresponding to the given name." },
1451 { "lookup_symbol", (PyCFunction) gdbpy_lookup_symbol,
1452 METH_VARARGS | METH_KEYWORDS,
1453 "lookup_symbol (name [, block] [, domain]) -> (symbol, is_field_of_this)\n\
1454 Return a tuple with the symbol corresponding to the given name (or None) and\n\
1455 a boolean indicating if name is a field of the current implied argument\n\
1456 `this' (when the current language is object-oriented)." },
1457 { "lookup_global_symbol", (PyCFunction) gdbpy_lookup_global_symbol,
1458 METH_VARARGS | METH_KEYWORDS,
1459 "lookup_global_symbol (name [, domain]) -> symbol\n\
1460 Return the symbol corresponding to the given name (or None)." },
1461 { "block_for_pc", gdbpy_block_for_pc, METH_VARARGS,
1462 "Return the block containing the given pc value, or None." },
1463 { "solib_name", gdbpy_solib_name, METH_VARARGS,
1464 "solib_name (Long) -> String.\n\
1465 Return the name of the shared library holding a given address, or None." },
1466 { "decode_line", gdbpy_decode_line, METH_VARARGS,
1467 "decode_line (String) -> Tuple. Decode a string argument the way\n\
1468 that 'break' or 'edit' does. Return a tuple containing two elements.\n\
1469 The first element contains any unparsed portion of the String parameter\n\
1470 (or None if the string was fully parsed). The second element contains\n\
1471 a tuple that contains all the locations that match, represented as\n\
1472 gdb.Symtab_and_line objects (or None)."},
1473 { "parse_and_eval", gdbpy_parse_and_eval, METH_VARARGS,
1474 "parse_and_eval (String) -> Value.\n\
1475 Parse String as an expression, evaluate it, and return the result as a Value."
1476 },
1477 { "find_pc_line", gdbpy_find_pc_line, METH_VARARGS,
1478 "find_pc_line (pc) -> Symtab_and_line.\n\
1479 Return the gdb.Symtab_and_line object corresponding to the pc value." },
1480
1481 { "post_event", gdbpy_post_event, METH_VARARGS,
1482 "Post an event into gdb's event loop." },
1483
1484 { "target_charset", gdbpy_target_charset, METH_NOARGS,
1485 "target_charset () -> string.\n\
1486 Return the name of the current target charset." },
1487 { "target_wide_charset", gdbpy_target_wide_charset, METH_NOARGS,
1488 "target_wide_charset () -> string.\n\
1489 Return the name of the current target wide charset." },
1490
1491 { "string_to_argv", gdbpy_string_to_argv, METH_VARARGS,
1492 "string_to_argv (String) -> Array.\n\
1493 Parse String and return an argv-like array.\n\
1494 Arguments are separate by spaces and may be quoted."
1495 },
1496 { "write", (PyCFunction)gdbpy_write, METH_VARARGS | METH_KEYWORDS,
1497 "Write a string using gdb's filtered stream." },
1498 { "flush", (PyCFunction)gdbpy_flush, METH_VARARGS | METH_KEYWORDS,
1499 "Flush gdb's filtered stdout stream." },
1500 { "selected_thread", gdbpy_selected_thread, METH_NOARGS,
1501 "selected_thread () -> gdb.InferiorThread.\n\
1502 Return the selected thread object." },
1503 { "selected_inferior", gdbpy_selected_inferior, METH_NOARGS,
1504 "selected_inferior () -> gdb.Inferior.\n\
1505 Return the selected inferior object." },
1506 { "inferiors", gdbpy_inferiors, METH_NOARGS,
1507 "inferiors () -> (gdb.Inferior, ...).\n\
1508 Return a tuple containing all inferiors." },
1509 {NULL, NULL, 0, NULL}
1510 };
1511
1512 #endif /* HAVE_PYTHON */
This page took 0.060264 seconds and 4 git commands to generate.