1 /* General python/gdb code
3 Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
21 #include "arch-utils.h"
24 #include "cli/cli-script.h"
26 #include "progspace.h"
30 #include "exceptions.h"
31 #include "event-loop.h"
35 /* True if we should print the stack when catching a Python error,
37 static int gdbpy_should_print_stack
= 1;
42 #include "libiberty.h"
43 #include "cli/cli-decode.h"
47 #include "python-internal.h"
52 #include "gdbthread.h"
54 static PyMethodDef GdbMethods
[];
58 /* Some string constants we may wish to use. */
59 PyObject
*gdbpy_to_string_cst
;
60 PyObject
*gdbpy_children_cst
;
61 PyObject
*gdbpy_display_hint_cst
;
62 PyObject
*gdbpy_doc_cst
;
63 PyObject
*gdbpy_enabled_cst
;
65 /* The GdbError exception. */
66 PyObject
*gdbpy_gdberror_exc
;
68 /* Architecture and language to be used in callbacks from
69 the Python interpreter. */
70 struct gdbarch
*python_gdbarch
;
71 const struct language_defn
*python_language
;
73 /* Restore global language and architecture and Python GIL state
74 when leaving the Python interpreter. */
78 PyGILState_STATE state
;
79 struct gdbarch
*gdbarch
;
80 const struct language_defn
*language
;
84 restore_python_env (void *p
)
86 struct python_env
*env
= (struct python_env
*)p
;
88 PyGILState_Release (env
->state
);
89 python_gdbarch
= env
->gdbarch
;
90 python_language
= env
->language
;
94 /* Called before entering the Python interpreter to install the
95 current language and architecture to be used for Python values. */
98 ensure_python_env (struct gdbarch
*gdbarch
,
99 const struct language_defn
*language
)
101 struct python_env
*env
= xmalloc (sizeof *env
);
103 env
->state
= PyGILState_Ensure ();
104 env
->gdbarch
= python_gdbarch
;
105 env
->language
= python_language
;
107 python_gdbarch
= gdbarch
;
108 python_language
= language
;
110 return make_cleanup (restore_python_env
, env
);
114 /* Given a command_line, return a command string suitable for passing
115 to Python. Lines in the string are separated by newlines. The
116 return value is allocated using xmalloc and the caller is
117 responsible for freeing it. */
120 compute_python_string (struct command_line
*l
)
122 struct command_line
*iter
;
127 for (iter
= l
; iter
; iter
= iter
->next
)
128 size
+= strlen (iter
->line
) + 1;
130 script
= xmalloc (size
+ 1);
132 for (iter
= l
; iter
; iter
= iter
->next
)
134 int len
= strlen (iter
->line
);
136 strcpy (&script
[here
], iter
->line
);
138 script
[here
++] = '\n';
144 /* Take a command line structure representing a 'python' command, and
145 evaluate its body using the Python interpreter. */
148 eval_python_from_control_command (struct command_line
*cmd
)
152 struct cleanup
*cleanup
;
154 if (cmd
->body_count
!= 1)
155 error (_("Invalid \"python\" block structure."));
157 cleanup
= ensure_python_env (get_current_arch (), current_language
);
159 script
= compute_python_string (cmd
->body_list
[0]);
160 ret
= PyRun_SimpleString (script
);
164 gdbpy_print_stack ();
165 error (_("Error while executing Python code."));
168 do_cleanups (cleanup
);
171 /* Implementation of the gdb "python" command. */
174 python_command (char *arg
, int from_tty
)
176 struct cleanup
*cleanup
;
178 cleanup
= ensure_python_env (get_current_arch (), current_language
);
179 while (arg
&& *arg
&& isspace (*arg
))
183 if (PyRun_SimpleString (arg
))
185 gdbpy_print_stack ();
186 error (_("Error while executing Python code."));
191 struct command_line
*l
= get_command_line (python_control
, "");
193 make_cleanup_free_command_lines (&l
);
194 execute_control_command_untraced (l
);
197 do_cleanups (cleanup
);
202 /* Transform a gdb parameters's value into a Python value. May return
203 NULL (and set a Python exception) on error. Helper function for
206 gdbpy_parameter_value (enum var_types type
, void *var
)
211 case var_string_noescape
:
212 case var_optional_filename
:
216 char *str
= * (char **) var
;
220 return PyString_Decode (str
, strlen (str
), host_charset (), NULL
);
231 case var_auto_boolean
:
233 enum auto_boolean ab
= * (enum auto_boolean
*) var
;
235 if (ab
== AUTO_BOOLEAN_TRUE
)
237 else if (ab
== AUTO_BOOLEAN_FALSE
)
244 if ((* (int *) var
) == INT_MAX
)
248 return PyLong_FromLong (* (int *) var
);
252 unsigned int val
= * (unsigned int *) var
;
256 return PyLong_FromUnsignedLong (val
);
260 return PyErr_Format (PyExc_RuntimeError
,
261 _("Programmer error: unhandled type."));
264 /* A Python function which returns a gdb parameter's value as a Python
268 gdbpy_parameter (PyObject
*self
, PyObject
*args
)
270 struct cmd_list_element
*alias
, *prefix
, *cmd
;
273 volatile struct gdb_exception except
;
275 if (! PyArg_ParseTuple (args
, "s", &arg
))
278 newarg
= concat ("show ", arg
, (char *) NULL
);
280 TRY_CATCH (except
, RETURN_MASK_ALL
)
282 found
= lookup_cmd_composition (newarg
, &alias
, &prefix
, &cmd
);
285 GDB_PY_HANDLE_EXCEPTION (except
);
287 return PyErr_Format (PyExc_RuntimeError
,
288 _("Could not find parameter `%s'."), arg
);
291 return PyErr_Format (PyExc_RuntimeError
,
292 _("`%s' is not a parameter."), arg
);
293 return gdbpy_parameter_value (cmd
->var_type
, cmd
->var
);
296 /* Wrapper for target_charset. */
299 gdbpy_target_charset (PyObject
*self
, PyObject
*args
)
301 const char *cset
= target_charset (python_gdbarch
);
303 return PyUnicode_Decode (cset
, strlen (cset
), host_charset (), NULL
);
306 /* Wrapper for target_wide_charset. */
309 gdbpy_target_wide_charset (PyObject
*self
, PyObject
*args
)
311 const char *cset
= target_wide_charset (python_gdbarch
);
313 return PyUnicode_Decode (cset
, strlen (cset
), host_charset (), NULL
);
316 /* A Python function which evaluates a string using the gdb CLI. */
319 execute_gdb_command (PyObject
*self
, PyObject
*args
, PyObject
*kw
)
322 PyObject
*from_tty_obj
= NULL
, *to_string_obj
= NULL
;
323 int from_tty
, to_string
;
324 volatile struct gdb_exception except
;
325 static char *keywords
[] = {"command", "from_tty", "to_string", NULL
};
328 if (! PyArg_ParseTupleAndKeywords (args
, kw
, "s|O!O!", keywords
, &arg
,
329 &PyBool_Type
, &from_tty_obj
,
330 &PyBool_Type
, &to_string_obj
))
336 int cmp
= PyObject_IsTrue (from_tty_obj
);
345 int cmp
= PyObject_IsTrue (to_string_obj
);
351 TRY_CATCH (except
, RETURN_MASK_ALL
)
353 /* Copy the argument text in case the command modifies it. */
354 char *copy
= xstrdup (arg
);
355 struct cleanup
*cleanup
= make_cleanup (xfree
, copy
);
358 result
= execute_command_to_string (copy
, from_tty
);
362 execute_command (copy
, from_tty
);
365 do_cleanups (cleanup
);
367 GDB_PY_HANDLE_EXCEPTION (except
);
369 /* Do any commands attached to breakpoint we stopped at. */
370 bpstat_do_actions ();
374 PyObject
*r
= PyString_FromString (result
);
381 /* Implementation of gdb.solib_name (Long) -> String.
382 Returns the name of the shared library holding a given address, or None. */
385 gdbpy_solib_name (PyObject
*self
, PyObject
*args
)
390 unsigned PY_LONG_LONG pc
;
391 const char *format
= "K";
394 const char *format
= "k";
397 if (!PyArg_ParseTuple (args
, format
, &pc
))
400 soname
= solib_name_from_address (current_program_space
, pc
);
402 str_obj
= PyString_Decode (soname
, strlen (soname
), host_charset (), NULL
);
412 /* A Python function which is a wrapper for decode_line_1. */
415 gdbpy_decode_line (PyObject
*self
, PyObject
*args
)
417 struct symtabs_and_lines sals
= { NULL
, 0 }; /* Initialize to appease gcc. */
418 struct symtab_and_line sal
;
421 struct cleanup
*cleanups
;
422 PyObject
*result
= NULL
;
423 PyObject
*return_result
= NULL
;
424 PyObject
*unparsed
= NULL
;
425 volatile struct gdb_exception except
;
427 if (! PyArg_ParseTuple (args
, "|s", &arg
))
430 cleanups
= ensure_python_env (get_current_arch (), current_language
);
432 TRY_CATCH (except
, RETURN_MASK_ALL
)
437 make_cleanup (xfree
, arg
);
439 sals
= decode_line_1 (©
, 0, 0, 0, 0, 0);
440 make_cleanup (xfree
, sals
.sals
);
444 set_default_source_symtab_and_line ();
445 sal
= get_current_source_symtab_and_line ();
450 if (except
.reason
< 0)
452 do_cleanups (cleanups
);
453 /* We know this will always throw. */
454 GDB_PY_HANDLE_EXCEPTION (except
);
461 result
= PyTuple_New (sals
.nelts
);
464 for (i
= 0; i
< sals
.nelts
; ++i
)
469 obj
= symtab_and_line_to_sal_object (sals
.sals
[i
]);
476 PyTuple_SetItem (result
, i
, obj
);
485 return_result
= PyTuple_New (2);
492 if (copy
&& strlen (copy
) > 0)
493 unparsed
= PyString_FromString (copy
);
500 PyTuple_SetItem (return_result
, 0, unparsed
);
501 PyTuple_SetItem (return_result
, 1, result
);
503 do_cleanups (cleanups
);
505 return return_result
;
508 do_cleanups (cleanups
);
512 /* Parse a string and evaluate it as an expression. */
514 gdbpy_parse_and_eval (PyObject
*self
, PyObject
*args
)
517 struct value
*result
= NULL
;
518 volatile struct gdb_exception except
;
520 if (!PyArg_ParseTuple (args
, "s", &expr_str
))
523 TRY_CATCH (except
, RETURN_MASK_ALL
)
525 result
= parse_and_eval (expr_str
);
527 GDB_PY_HANDLE_EXCEPTION (except
);
529 return value_to_value_object (result
);
532 /* Read a file as Python code. STREAM is the input file; FILE is the
534 STREAM is not closed, that is the caller's responsibility. */
537 source_python_script (FILE *stream
, const char *file
)
539 struct cleanup
*cleanup
;
541 cleanup
= ensure_python_env (get_current_arch (), current_language
);
543 /* Note: If an exception occurs python will print the traceback and
544 clear the error indicator. */
545 PyRun_SimpleFile (stream
, file
);
547 do_cleanups (cleanup
);
552 /* Posting and handling events. */
554 /* A single event. */
557 /* The Python event. This is just a callable object. */
559 /* The next event. */
560 struct gdbpy_event
*next
;
563 /* All pending events. */
564 static struct gdbpy_event
*gdbpy_event_list
;
565 /* The final link of the event list. */
566 static struct gdbpy_event
**gdbpy_event_list_end
;
568 /* We use a file handler, and not an async handler, so that we can
569 wake up the main thread even when it is blocked in poll(). */
570 static int gdbpy_event_fds
[2];
572 /* The file handler callback. This reads from the internal pipe, and
573 then processes the Python event queue. This will always be run in
574 the main gdb thread. */
576 gdbpy_run_events (int err
, gdb_client_data ignore
)
578 struct cleanup
*cleanup
;
582 cleanup
= ensure_python_env (get_current_arch (), current_language
);
584 /* Just read whatever is available on the fd. It is relatively
585 harmless if there are any bytes left over. */
586 r
= read (gdbpy_event_fds
[0], buffer
, sizeof (buffer
));
588 while (gdbpy_event_list
)
590 /* Dispatching the event might push a new element onto the event
591 loop, so we update here "atomically enough". */
592 struct gdbpy_event
*item
= gdbpy_event_list
;
593 gdbpy_event_list
= gdbpy_event_list
->next
;
594 if (gdbpy_event_list
== NULL
)
595 gdbpy_event_list_end
= &gdbpy_event_list
;
598 if (PyObject_CallObject (item
->event
, NULL
) == NULL
)
601 Py_DECREF (item
->event
);
605 do_cleanups (cleanup
);
608 /* Submit an event to the gdb thread. */
610 gdbpy_post_event (PyObject
*self
, PyObject
*args
)
612 struct gdbpy_event
*event
;
616 if (!PyArg_ParseTuple (args
, "O", &func
))
619 if (!PyCallable_Check (func
))
621 PyErr_SetString (PyExc_RuntimeError
,
622 _("Posted event is not callable"));
628 /* From here until the end of the function, we have the GIL, so we
629 can operate on our global data structures without worrying. */
630 wakeup
= gdbpy_event_list
== NULL
;
632 event
= XNEW (struct gdbpy_event
);
635 *gdbpy_event_list_end
= event
;
636 gdbpy_event_list_end
= &event
->next
;
638 /* Wake up gdb when needed. */
641 char c
= 'q'; /* Anything. */
642 if (write (gdbpy_event_fds
[1], &c
, 1) != 1)
643 return PyErr_SetFromErrno (PyExc_IOError
);
649 /* Initialize the Python event handler. */
651 gdbpy_initialize_events (void)
653 if (!pipe (gdbpy_event_fds
))
655 gdbpy_event_list_end
= &gdbpy_event_list
;
656 add_file_handler (gdbpy_event_fds
[0], gdbpy_run_events
, NULL
);
662 /* A python function to write a single string using gdb's filtered
665 gdbpy_write (PyObject
*self
, PyObject
*args
)
669 if (! PyArg_ParseTuple (args
, "s", &arg
))
671 printf_filtered ("%s", arg
);
675 /* A python function to flush gdb's filtered output stream. */
677 gdbpy_flush (PyObject
*self
, PyObject
*args
)
679 gdb_flush (gdb_stdout
);
683 /* Print a python exception trace, or print nothing and clear the
684 python exception, depending on gdbpy_should_print_stack. Only call
685 this if a python exception is set. */
687 gdbpy_print_stack (void)
689 if (gdbpy_should_print_stack
)
692 /* PyErr_Print doesn't necessarily end output with a newline.
693 This works because Python's stdout/stderr is fed through
703 /* Return the current Progspace.
704 There always is one. */
707 gdbpy_get_current_progspace (PyObject
*unused1
, PyObject
*unused2
)
711 result
= pspace_to_pspace_object (current_program_space
);
717 /* Return a sequence holding all the Progspaces. */
720 gdbpy_progspaces (PyObject
*unused1
, PyObject
*unused2
)
722 struct program_space
*ps
;
725 list
= PyList_New (0);
731 PyObject
*item
= pspace_to_pspace_object (ps
);
733 if (!item
|| PyList_Append (list
, item
) == -1)
745 /* The "current" objfile. This is set when gdb detects that a new
746 objfile has been loaded. It is only set for the duration of a call to
747 source_python_script_for_objfile; it is NULL at other times. */
748 static struct objfile
*gdbpy_current_objfile
;
750 /* Set the current objfile to OBJFILE and then read STREAM,FILE as
754 source_python_script_for_objfile (struct objfile
*objfile
,
755 FILE *stream
, const char *file
)
757 struct cleanup
*cleanups
;
759 cleanups
= ensure_python_env (get_objfile_arch (objfile
), current_language
);
760 gdbpy_current_objfile
= objfile
;
762 /* Note: If an exception occurs python will print the traceback and
763 clear the error indicator. */
764 PyRun_SimpleFile (stream
, file
);
766 do_cleanups (cleanups
);
767 gdbpy_current_objfile
= NULL
;
770 /* Return the current Objfile, or None if there isn't one. */
773 gdbpy_get_current_objfile (PyObject
*unused1
, PyObject
*unused2
)
777 if (! gdbpy_current_objfile
)
780 result
= objfile_to_objfile_object (gdbpy_current_objfile
);
786 /* Return a sequence holding all the Objfiles. */
789 gdbpy_objfiles (PyObject
*unused1
, PyObject
*unused2
)
791 struct objfile
*objf
;
794 list
= PyList_New (0);
800 PyObject
*item
= objfile_to_objfile_object (objf
);
802 if (!item
|| PyList_Append (list
, item
) == -1)
812 #else /* HAVE_PYTHON */
814 /* Dummy implementation of the gdb "python" command. */
817 python_command (char *arg
, int from_tty
)
819 while (arg
&& *arg
&& isspace (*arg
))
822 error (_("Python scripting is not supported in this copy of GDB."));
825 struct command_line
*l
= get_command_line (python_control
, "");
826 struct cleanup
*cleanups
= make_cleanup_free_command_lines (&l
);
828 execute_control_command_untraced (l
);
829 do_cleanups (cleanups
);
834 eval_python_from_control_command (struct command_line
*cmd
)
836 error (_("Python scripting is not supported in this copy of GDB."));
840 source_python_script (FILE *stream
, const char *file
)
842 throw_error (UNSUPPORTED_ERROR
,
843 _("Python scripting is not supported in this copy of GDB."));
846 #endif /* HAVE_PYTHON */
850 /* Lists for 'maint set python' commands. */
852 struct cmd_list_element
*set_python_list
;
853 struct cmd_list_element
*show_python_list
;
855 /* Function for use by 'maint set python' prefix command. */
858 set_python (char *args
, int from_tty
)
860 help_list (set_python_list
, "maintenance set python ", -1, gdb_stdout
);
863 /* Function for use by 'maint show python' prefix command. */
866 show_python (char *args
, int from_tty
)
868 cmd_show_list (show_python_list
, from_tty
, "");
871 /* Initialize the Python code. */
873 /* Provide a prototype to silence -Wmissing-prototypes. */
874 extern initialize_file_ftype _initialize_python
;
877 _initialize_python (void)
879 add_com ("python", class_obscure
, python_command
,
882 Evaluate a Python command.\n\
884 The command can be given as an argument, for instance:\n\
888 If no argument is given, the following lines are read and used\n\
889 as the Python commands. Type a line containing \"end\" to indicate\n\
890 the end of the command.")
891 #else /* HAVE_PYTHON */
893 Evaluate a Python command.\n\
895 Python scripting is not supported in this copy of GDB.\n\
896 This command is only a placeholder.")
897 #endif /* HAVE_PYTHON */
900 add_prefix_cmd ("python", no_class
, show_python
,
901 _("Prefix command for python maintenance settings."),
902 &show_python_list
, "maintenance show python ", 0,
903 &maintenance_show_cmdlist
);
904 add_prefix_cmd ("python", no_class
, set_python
,
905 _("Prefix command for python maintenance settings."),
906 &set_python_list
, "maintenance set python ", 0,
907 &maintenance_set_cmdlist
);
909 add_setshow_boolean_cmd ("print-stack", class_maintenance
,
910 &gdbpy_should_print_stack
, _("\
911 Enable or disable printing of Python stack dump on error."), _("\
912 Show whether Python stack will be printed on error."), _("\
913 Enables or disables printing of Python stack traces."),
919 #ifdef WITH_PYTHON_PATH
920 /* Work around problem where python gets confused about where it is,
921 and then can't find its libraries, etc.
922 NOTE: Python assumes the following layout:
924 /foo/lib/pythonX.Y/...
925 This must be done before calling Py_Initialize. */
926 Py_SetProgramName (concat (ldirname (python_libdir
), SLASH_STRING
, "bin",
927 SLASH_STRING
, "python", NULL
));
931 PyEval_InitThreads ();
933 gdb_module
= Py_InitModule ("gdb", GdbMethods
);
935 /* The casts to (char*) are for python 2.4. */
936 PyModule_AddStringConstant (gdb_module
, "VERSION", (char*) version
);
937 PyModule_AddStringConstant (gdb_module
, "HOST_CONFIG", (char*) host_name
);
938 PyModule_AddStringConstant (gdb_module
, "TARGET_CONFIG", (char*) target_name
);
942 gdb_pythondir
= concat (gdb_datadir
, SLASH_STRING
, "python", NULL
);
943 PyModule_AddStringConstant (gdb_module
, "PYTHONDIR", gdb_pythondir
);
944 xfree (gdb_pythondir
);
947 gdbpy_gdberror_exc
= PyErr_NewException ("gdb.GdbError", NULL
, NULL
);
948 PyModule_AddObject (gdb_module
, "GdbError", gdbpy_gdberror_exc
);
950 gdbpy_initialize_auto_load ();
951 gdbpy_initialize_values ();
952 gdbpy_initialize_frames ();
953 gdbpy_initialize_commands ();
954 gdbpy_initialize_symbols ();
955 gdbpy_initialize_symtabs ();
956 gdbpy_initialize_blocks ();
957 gdbpy_initialize_functions ();
958 gdbpy_initialize_parameters ();
959 gdbpy_initialize_types ();
960 gdbpy_initialize_pspace ();
961 gdbpy_initialize_objfile ();
962 gdbpy_initialize_breakpoints ();
963 gdbpy_initialize_lazy_string ();
964 gdbpy_initialize_thread ();
965 gdbpy_initialize_inferior ();
966 gdbpy_initialize_events ();
968 PyRun_SimpleString ("import gdb");
969 PyRun_SimpleString ("gdb.pretty_printers = []");
971 gdbpy_to_string_cst
= PyString_FromString ("to_string");
972 gdbpy_children_cst
= PyString_FromString ("children");
973 gdbpy_display_hint_cst
= PyString_FromString ("display_hint");
974 gdbpy_doc_cst
= PyString_FromString ("__doc__");
975 gdbpy_enabled_cst
= PyString_FromString ("enabled");
977 /* Create a couple objects which are used for Python's stdout and
979 PyRun_SimpleString ("\
981 class GdbOutputFile:\n\
989 def write(self, s):\n\
992 def writelines(self, iterable):\n\
993 for line in iterable:\n\
999 sys.stderr = GdbOutputFile()\n\
1000 sys.stdout = GdbOutputFile()\n\
1002 # GDB's python scripts are stored inside gdb.PYTHONDIR. So insert\n\
1003 # that directory name at the start of sys.path to allow the Python\n\
1004 # interpreter to find them.\n\
1005 sys.path.insert(0, gdb.PYTHONDIR)\n\
1007 # The gdb module is implemented in C rather than in Python. As a result,\n\
1008 # the associated __init.py__ script is not not executed by default when\n\
1009 # the gdb module gets imported. Execute that script manually if it exists.\n\
1010 gdb.__path__ = [gdb.PYTHONDIR + '/gdb']\n\
1011 from os.path import exists\n\
1012 ipy = gdb.PYTHONDIR + '/gdb/__init__.py'\n\
1017 /* Release the GIL while gdb runs. */
1018 PyThreadState_Swap (NULL
);
1019 PyEval_ReleaseLock ();
1021 #endif /* HAVE_PYTHON */
1028 static PyMethodDef GdbMethods
[] =
1030 { "history", gdbpy_history
, METH_VARARGS
,
1031 "Get a value from history" },
1032 { "execute", (PyCFunction
) execute_gdb_command
, METH_VARARGS
| METH_KEYWORDS
,
1033 "Execute a gdb command" },
1034 { "parameter", gdbpy_parameter
, METH_VARARGS
,
1035 "Return a gdb parameter's value" },
1037 { "breakpoints", gdbpy_breakpoints
, METH_NOARGS
,
1038 "Return a tuple of all breakpoint objects" },
1040 { "default_visualizer", gdbpy_default_visualizer
, METH_VARARGS
,
1041 "Find the default visualizer for a Value." },
1043 { "current_progspace", gdbpy_get_current_progspace
, METH_NOARGS
,
1044 "Return the current Progspace." },
1045 { "progspaces", gdbpy_progspaces
, METH_NOARGS
,
1046 "Return a sequence of all progspaces." },
1048 { "current_objfile", gdbpy_get_current_objfile
, METH_NOARGS
,
1049 "Return the current Objfile being loaded, or None." },
1050 { "objfiles", gdbpy_objfiles
, METH_NOARGS
,
1051 "Return a sequence of all loaded objfiles." },
1053 { "selected_frame", gdbpy_selected_frame
, METH_NOARGS
,
1054 "selected_frame () -> gdb.Frame.\n\
1055 Return the selected frame object." },
1056 { "frame_stop_reason_string", gdbpy_frame_stop_reason_string
, METH_VARARGS
,
1057 "stop_reason_string (Integer) -> String.\n\
1058 Return a string explaining unwind stop reason." },
1060 { "lookup_type", (PyCFunction
) gdbpy_lookup_type
,
1061 METH_VARARGS
| METH_KEYWORDS
,
1062 "lookup_type (name [, block]) -> type\n\
1063 Return a Type corresponding to the given name." },
1064 { "lookup_symbol", (PyCFunction
) gdbpy_lookup_symbol
,
1065 METH_VARARGS
| METH_KEYWORDS
,
1066 "lookup_symbol (name [, block] [, domain]) -> (symbol, is_field_of_this)\n\
1067 Return a tuple with the symbol corresponding to the given name (or None) and\n\
1068 a boolean indicating if name is a field of the current implied argument\n\
1069 `this' (when the current language is object-oriented)." },
1070 { "block_for_pc", gdbpy_block_for_pc
, METH_VARARGS
,
1071 "Return the block containing the given pc value, or None." },
1072 { "solib_name", gdbpy_solib_name
, METH_VARARGS
,
1073 "solib_name (Long) -> String.\n\
1074 Return the name of the shared library holding a given address, or None." },
1075 { "decode_line", gdbpy_decode_line
, METH_VARARGS
,
1076 "decode_line (String) -> Tuple. Decode a string argument the way\n\
1077 that 'break' or 'edit' does. Return a tuple containing two elements.\n\
1078 The first element contains any unparsed portion of the String parameter\n\
1079 (or None if the string was fully parsed). The second element contains\n\
1080 a tuple that contains all the locations that match, represented as\n\
1081 gdb.Symtab_and_line objects (or None)."},
1082 { "parse_and_eval", gdbpy_parse_and_eval
, METH_VARARGS
,
1083 "parse_and_eval (String) -> Value.\n\
1084 Parse String as an expression, evaluate it, and return the result as a Value."
1087 { "post_event", gdbpy_post_event
, METH_VARARGS
,
1088 "Post an event into gdb's event loop." },
1090 { "target_charset", gdbpy_target_charset
, METH_NOARGS
,
1091 "target_charset () -> string.\n\
1092 Return the name of the current target charset." },
1093 { "target_wide_charset", gdbpy_target_wide_charset
, METH_NOARGS
,
1094 "target_wide_charset () -> string.\n\
1095 Return the name of the current target wide charset." },
1097 { "string_to_argv", gdbpy_string_to_argv
, METH_VARARGS
,
1098 "string_to_argv (String) -> Array.\n\
1099 Parse String and return an argv-like array.\n\
1100 Arguments are separate by spaces and may be quoted."
1103 { "write", gdbpy_write
, METH_VARARGS
,
1104 "Write a string using gdb's filtered stream." },
1105 { "flush", gdbpy_flush
, METH_NOARGS
,
1106 "Flush gdb's filtered stdout stream." },
1107 { "selected_thread", gdbpy_selected_thread
, METH_NOARGS
,
1108 "selected_thread () -> gdb.InferiorThread.\n\
1109 Return the selected thread object." },
1110 { "inferiors", gdbpy_inferiors
, METH_NOARGS
,
1111 "inferiors () -> (gdb.Inferior, ...).\n\
1112 Return a tuple containing all inferiors." },
1113 {NULL
, NULL
, 0, NULL
}
1116 #endif /* HAVE_PYTHON */