30#include "gdbsupport/event-loop.h"
31#include "readline/tilde.h"
38#include "gdbsupport/selftest.h"
70#include "gdbsupport/version.h"
82extern PyMethodDef python_GdbMethods[];
109static void gdbpy_eval_from_control_command
122static gdb::optional<std::string> gdbpy_colorize
123 (
const std::string &filename,
const std::string &contents);
124static gdb::optional<std::string> gdbpy_colorize_disasm
132 gdbpy_source_objfile_script,
133 gdbpy_execute_objfile_script,
144 gdbpy_eval_from_control_command,
146 gdbpy_start_type_printers,
147 gdbpy_apply_type_printers,
148 gdbpy_free_type_printers,
160 gdbpy_check_quit_flag,
162 gdbpy_before_prompt_hook,
168 gdbpy_colorize_disasm,
189 &python_extension_script_ops,
190 &python_extension_ops
205: m_gdbarch (python_gdbarch),
210 error (_(
"Python not initialized"));
227 if (PyErr_Occurred ())
231 warning (_(
"internal error: Unhandled Python exception"));
275 DISABLE_COPY_AND_ASSIGN (gdbpy_gil);
279 PyGILState_STATE m_state;
287 PyErr_SetInterrupt ();
299 return PyOS_InterruptOccurred ();
307eval_python_command (
const char *command)
311 m = PyImport_AddModule (
"__main__");
315 d = PyModule_GetDict (m);
318 gdbpy_ref<> v (PyRun_StringFlags (command, Py_single_input, d, d, NULL));
333 scoped_restore save_async = make_scoped_restore (&
current_ui->
async, 0);
335 arg = skip_spaces (arg);
341 std::string script = std::string (arg) +
"\n";
342 err = eval_python_command (script.c_str ());
353 error (_(
"Error while executing Python code."));
373python_run_simple_file (FILE *file,
const char *filename)
377 PyRun_SimpleFile (file, filename);
383 gdb::unique_xmalloc_ptr<char> full_path (tilde_expand (filename));
387 error (_(
"Installation error: gdb._execute_file function is missing"));
392 if (return_value ==
nullptr)
411 for (iter = l; iter; iter = iter->
next)
413 script += iter->
line;
429 error (_(
"Invalid \"python\" block structure."));
433 std::string script = compute_python_string (cmd->
body_list_0.get ());
434 ret = PyRun_SimpleString (script.c_str ());
436 error (_(
"Error while executing Python code."));
446 scoped_restore save_async = make_scoped_restore (&
current_ui->
async, 0);
448 arg = skip_spaces (arg);
451 if (PyRun_SimpleString (arg))
452 error (_(
"Error while executing Python code."));
480 str = var.
get<
const char *> ();
482 str = var.
get<std::string> ().c_str ();
489 if (var.
get<
bool> ())
517 unsigned int val = var.
get<
unsigned int> ();
526 unsigned int val = var.
get<
unsigned int> ();
531 return PyErr_Format (PyExc_RuntimeError,
532 _(
"Programmer error: unhandled type."));
545 if (! PyArg_ParseTuple (args,
"s", &arg))
548 std::string newarg = std::string (
"show ") + arg;
554 catch (
const gdb_exception &ex)
560 return PyErr_Format (PyExc_RuntimeError,
561 _(
"Could not find parameter `%s'."), arg);
563 if (!cmd->
var.has_value ())
564 return PyErr_Format (PyExc_RuntimeError,
565 _(
"`%s' is not a parameter."), arg);
577 return PyUnicode_Decode (cset, strlen (cset),
host_charset (), NULL);
587 return PyUnicode_Decode (cset, strlen (cset),
host_charset (), NULL);
597 return PyUnicode_Decode (cset, strlen (cset),
host_charset (), NULL);
606 PyObject *from_tty_obj = NULL, *to_string_obj = NULL;
607 int from_tty, to_string;
608 static const char *keywords[] = {
"command",
"from_tty",
"to_string", NULL };
611 &PyBool_Type, &from_tty_obj,
612 &PyBool_Type, &to_string_obj))
618 int cmp = PyObject_IsTrue (from_tty_obj);
627 int cmp = PyObject_IsTrue (to_string_obj);
633 std::string to_string_res;
643 std::string arg_copy = arg;
645 char *save_ptr =
nullptr;
647 = [&] (std::string &buffer)
649 const char *result = strtok_r (first ? &arg_copy[0] : nullptr,
661 scoped_restore save_uiout = make_scoped_restore (&
current_uiout);
678 catch (
const gdb_exception &except)
690 return PyUnicode_FromString (to_string_res.c_str ());
711 std::vector<symbol_search> symbols;
712 unsigned long count = 0;
716 unsigned int throttle = 0;
717 static const char *keywords[] = {
"regex",
"minsyms",
"throttle",
721 ®ex, &PyBool_Type,
722 &minsyms_p_obj, &throttle,
727 if (minsyms_p_obj != NULL)
729 int cmp = PyObject_IsTrue (minsyms_p_obj);
737 for (
const char *elem : spec.filenames)
738 xfree ((void *) elem);
750 if (symtab_list != NULL)
763 if (PyErr_Occurred ())
771 if (obj_name == NULL)
775 if (obj_name == Py_None)
778 gdb::unique_xmalloc_ptr<char> filename =
781 if (filename == NULL)
786 spec.filenames.push_back (
nullptr);
787 spec.filenames.back () = filename.release ();
792 symbols = spec.search ();
801 if (p.msymbol.minsym != NULL)
805 if (p.symbol != NULL)
810 if (throttle != 0 && count > throttle)
812 PyErr_SetString (PyExc_RuntimeError,
813 _(
"Number of breakpoints exceeds throttled maximum."));
819 if (return_list == NULL)
827 std::string symbol_name;
831 if (p.msymbol.minsym != NULL)
834 if (p.msymbol.minsym == NULL)
841 symbol_name += p.symbol->linkage_name ();
844 symbol_name = p.msymbol.minsym->linkage_name ();
846 gdbpy_ref<> argList (Py_BuildValue(
"(s)", symbol_name.c_str ()));
856 if (PyList_Append (
return_list.get (), obj.get ()) == -1)
868 const char *arg = NULL;
873 if (! PyArg_ParseTuple (args,
"|s", &arg))
880 arg = skip_spaces (arg);
889 std::vector<symtab_and_line> decoded_sals;
891 gdb::array_view<symtab_and_line> sals;
896 decoded_sals =
decode_line_1 (locspec.get (), 0, NULL, NULL, 0);
906 catch (
const gdb_exception &ex)
915 result.reset (PyTuple_New (sals.size ()));
918 for (
size_t i = 0; i < sals.size (); ++i)
924 PyTuple_SetItem (result.get (), i, obj);
931 if (return_result == NULL)
934 if (arg != NULL && strlen (arg) > 0)
936 unparsed.reset (PyUnicode_FromString (arg));
937 if (unparsed == NULL)
943 PyTuple_SetItem (return_result.get (), 0, unparsed.release ());
944 PyTuple_SetItem (return_result.get (), 1, result.release ());
946 return return_result.release ();
953 const char *expr_str;
954 struct value *result = NULL;
956 if (!PyArg_ParseTuple (args,
"s", &expr_str))
964 catch (
const gdb_exception &except)
989 FILE *file,
const char *filename)
992 python_run_simple_file (file, filename);
1003 : m_func (
func.release ())
1007 gdbpy_event (gdbpy_event &&other) noexcept
1008 : m_func (other.m_func)
1010 other.m_func =
nullptr;
1013 gdbpy_event (
const gdbpy_event &other)
1014 : m_func (other.m_func)
1017 Py_XINCREF (m_func);
1023 Py_XDECREF (m_func);
1026 gdbpy_event &operator= (
const gdbpy_event &other) =
delete;
1032 gdbpy_ref<> call_result (PyObject_CallObject (m_func, NULL));
1033 if (call_result == NULL)
1051 if (!PyArg_ParseTuple (args,
"O", &
func))
1054 if (!PyCallable_Check (
func))
1056 PyErr_SetString (PyExc_RuntimeError,
1057 _(
"Posted event is not callable"));
1062 gdbpy_event event (std::move (func_ref));
1074 const char *current_gdb_prompt)
1096 if (PyCallable_Check (hook.get ()))
1098 gdbpy_ref<> current_prompt (PyUnicode_FromString (current_gdb_prompt));
1099 if (current_prompt == NULL)
1106 (PyObject_CallFunctionObjArgs (hook.get (), current_prompt.get (),
1117 if (result != Py_None && !PyUnicode_Check (result.get ()))
1119 PyErr_Format (PyExc_RuntimeError,
1120 _(
"Return from prompt_hook must " \
1121 "be either a Python string, or None"));
1126 if (result != Py_None)
1128 gdb::unique_xmalloc_ptr<char>
1148static gdb::optional<std::string>
1149gdbpy_colorize (
const std::string &filename,
const std::string &contents)
1156 gdbpy_ref<> module (PyImport_ImportModule (
"gdb.styling"));
1157 if (module ==
nullptr)
1163 if (!PyObject_HasAttrString (module.get (),
"colorize"))
1166 gdbpy_ref<> hook (PyObject_GetAttrString (module.get (),
"colorize"));
1167 if (hook ==
nullptr)
1173 if (!PyCallable_Check (hook.get ()))
1176 gdbpy_ref<> fname_arg (PyUnicode_FromString (filename.c_str ()));
1177 if (fname_arg ==
nullptr)
1188 gdbpy_ref<> contents_arg (PyBytes_FromStringAndSize (contents.c_str (),
1190 if (contents_arg ==
nullptr)
1200 gdbpy_ref<> result (PyObject_CallFunctionObjArgs (hook.get (),
1202 contents_arg.get (),
1204 if (result ==
nullptr)
1210 if (result == Py_None)
1212 else if (!PyBytes_Check (result.get ()))
1214 PyErr_SetString (PyExc_TypeError,
1215 _(
"Return value from gdb.colorize should be a bytes object or None."));
1220 return std::string (PyBytes_AsString (result.get ()));
1225static gdb::optional<std::string>
1226gdbpy_colorize_disasm (
const std::string &content,
gdbarch *
gdbarch)
1233 gdbpy_ref<> module (PyImport_ImportModule (
"gdb.styling"));
1234 if (module ==
nullptr)
1240 if (!PyObject_HasAttrString (module.get (),
"colorize_disasm"))
1243 gdbpy_ref<> hook (PyObject_GetAttrString (module.get (),
1244 "colorize_disasm"));
1245 if (hook ==
nullptr)
1251 if (!PyCallable_Check (hook.get ()))
1254 gdbpy_ref<> content_arg (PyBytes_FromString (content.c_str ()));
1255 if (content_arg ==
nullptr)
1262 if (gdbarch_arg ==
nullptr)
1268 gdbpy_ref<> result (PyObject_CallFunctionObjArgs (hook.get (),
1272 if (result ==
nullptr)
1278 if (result == Py_None)
1281 if (!PyBytes_Check (result.get ()))
1283 PyErr_SetString (PyExc_TypeError,
1284 _(
"Return value from gdb.colorize_disasm should be a bytes object or None."));
1289 return std::string (PyBytes_AsString (result.get ()));
1301 static const char *keywords[] =
1303 "address",
"progspace",
"architecture",
nullptr
1305 PyObject *addr_obj =
nullptr, *pspace_obj =
nullptr, *arch_obj =
nullptr;
1311 &addr_obj, &pspace_obj, &arch_obj))
1322 if (pspace_obj == Py_None)
1323 pspace_obj =
nullptr;
1324 if (arch_obj == Py_None)
1327 if (pspace_obj ==
nullptr && arch_obj ==
nullptr)
1334 else if (arch_obj ==
nullptr || pspace_obj ==
nullptr)
1341 PyErr_SetString (PyExc_ValueError,
1342 _(
"The architecture and progspace arguments must both be supplied"));
1351 PyErr_SetString (PyExc_TypeError,
1352 _(
"The progspace argument is not a gdb.Progspace object"));
1357 if (pspace ==
nullptr)
1359 PyErr_SetString (PyExc_ValueError,
1360 _(
"The progspace argument is not valid"));
1366 PyErr_SetString (PyExc_TypeError,
1367 _(
"The architecture argument is not a gdb.Architecture object"));
1374 gdb_assert (
gdbarch !=
nullptr);
1379 gdb_assert (pspace !=
nullptr);
1380 gdb_assert (
gdbarch !=
nullptr);
1390 return PyUnicode_FromString (buf.
c_str ());
1405 static const char *keywords[] = {
"text",
"stream", NULL };
1406 int stream_type = 0;
1414 switch (stream_type)
1430 catch (
const gdb_exception &except)
1445 static const char *keywords[] = {
"stream", NULL };
1446 int stream_type = 0;
1452 switch (stream_type)
1503 catch (
const gdb_exception &except)
1512 gdb::unique_xmalloc_ptr<char> msg = fetched_error.
to_string ();
1513 gdb::unique_xmalloc_ptr<char>
type;
1521 if (msg == NULL ||
type == NULL)
1526 _(
"Error occurred computing Python error" \
1532 type.get (), msg.get ());
1534 catch (
const gdb_exception &except)
1546 if (PyErr_ExceptionMatches (PyExc_KeyboardInterrupt))
1549 throw_quit (
"Quit");
1569 if (item == NULL || PyList_Append (list.get (), item.get ()) == -1)
1573 return list.release ();
1598 const char *filename)
1604 scoped_restore restire_current_objfile
1607 python_run_simple_file (file, filename);
1625 scoped_restore restire_current_objfile
1628 PyRun_SimpleString (script);
1658 gdbpy_ref<> type_module (PyImport_ImportModule (
"gdb.types"));
1659 if (type_module == NULL)
1666 "get_type_recognizers"));
1673 printers_obj = PyObject_CallFunctionObjArgs (
func.get (), (
char *) NULL);
1674 if (printers_obj == NULL)
1690 struct type *
type,
char **prettied_type)
1693 gdb::unique_xmalloc_ptr<char> result;
1695 if (printers_obj == NULL)
1704 if (type_obj == NULL)
1710 gdbpy_ref<> type_module (PyImport_ImportModule (
"gdb.types"));
1711 if (type_module == NULL)
1718 "apply_type_recognizers"));
1729 if (result_obj == NULL)
1735 if (result_obj == Py_None)
1745 *prettied_type = result.release ();
1758 if (printers == NULL)
1765 Py_DECREF (printers);
1776 arg = skip_spaces (arg);
1778 error (_(
"Python scripting is not supported in this copy of GDB."));
1806 gdb_printf (file, _(
"Python's ignore-environment setting is %s.\n"),
1824#if PY_VERSION_HEX < 0x030a0000
1842 const char *auto_string
1844 || getenv (
"PYTHONDONTWRITEBYTECODE") ==
nullptr) ?
"off" :
"on";
1847 _(
"Python's dont-write-bytecode setting is %s (currently %s).\n"),
1848 value, auto_string);
1851 gdb_printf (file, _(
"Python's dont-write-bytecode setting is %s.\n"),
1861python_write_bytecode ()
1871 const char *pdwbc = getenv (
"PYTHONDONTWRITEBYTECODE");
1872 wbc = (pdwbc ==
nullptr || pdwbc[0] ==
'\0') ? 1 : 0;
1896#if PY_VERSION_HEX < 0x030a0000
1897 Py_DontWriteBytecodeFlag = !python_write_bytecode ();
1917finalize_python (
void *ignore)
1942static struct PyModuleDef python_GdbModuleDef =
1944 PyModuleDef_HEAD_INIT,
1958PyMODINIT_FUNC init__gdb_module (
void);
1960init__gdb_module (
void)
1962 return PyModule_Create (&python_GdbModuleDef);
1969emit_exiting_event (
int exit_code)
1975 if (event_obj ==
nullptr)
1989gdbpy_gdb_exiting (
int exit_code)
1996 if (emit_exiting_event (exit_code) < 0)
2001do_start_initialization ()
2005 struct _inittab mods[] =
2007 {
"_gdb", init__gdb_module },
2009 {
nullptr,
nullptr }
2012 if (PyImport_ExtendInittab (mods) < 0)
2015#ifdef WITH_PYTHON_PATH
2022 gdb::unique_xmalloc_ptr<char> progname
2024 SLASH_STRING,
"python", (
char *) NULL));
2032 static wchar_t *progname_copy;
2034 std::string oldloc = setlocale (LC_ALL, NULL);
2035 setlocale (LC_ALL,
"");
2036 size_t progsize = strlen (progname.get ());
2037 progname_copy = XNEWVEC (
wchar_t, progsize + 1);
2038 size_t count = mbstowcs (progname_copy, progname.get (), progsize + 1);
2039 if (count == (
size_t) -1)
2041 fprintf (stderr,
"Could not convert python path to string\n");
2044 setlocale (LC_ALL, oldloc.c_str ());
2048#if PY_VERSION_HEX < 0x030a0000
2052 Py_SetProgramName (progname_copy);
2057 PyConfig_InitPythonConfig (&config);
2058 PyStatus
status = PyConfig_SetString (&config, &config.program_name,
2060 if (PyStatus_Exception (
status))
2063 config.write_bytecode = python_write_bytecode ();
2066 status = PyConfig_Read (&config);
2067 if (PyStatus_Exception (
status))
2070 status = Py_InitializeFromConfig (&config);
2073 PyConfig_Clear (&config);
2074 if (PyStatus_Exception (
status))
2081#if PY_VERSION_HEX < 0x03090000
2094 || PyModule_AddStringConstant (
gdb_module,
"TARGET_CONFIG",
2099 if (PyModule_AddIntConstant (
gdb_module,
"STDOUT", 0) < 0
2100 || PyModule_AddIntConstant (
gdb_module,
"STDERR", 1) < 0
2101 || PyModule_AddIntConstant (
gdb_module,
"STDLOG", 2) < 0)
2159#define GDB_PY_DEFINE_EVENT_TYPE(name, py_name, doc, base) \
2160 if (gdbpy_initialize_event_generic (&name##_event_object_type, py_name) < 0) \
2162#include "py-event-types.def"
2163#undef GDB_PY_DEFINE_EVENT_TYPE
2187 PyEval_SaveThread ();
2189 make_final_cleanup (finalize_python, NULL);
2204#define CMD(S) execute_command_to_string (S, "python print(5)", 0, true)
2209 SELF_CHECK (output ==
"5\n");
2212 bool saw_exception =
false;
2214 scoped_restore reset_gdb_python_initialized
2220 catch (
const gdb_exception &e)
2222 saw_exception =
true;
2223 SELF_CHECK (e.reason == RETURN_ERROR);
2224 SELF_CHECK (e.error == GENERIC_ERROR);
2225 SELF_CHECK (*e.message ==
"Python not initialized");
2227 SELF_CHECK (saw_exception);
2228 SELF_CHECK (output.empty ());
2231 saw_exception =
false;
2233 scoped_restore save_hook
2234 = make_scoped_restore (&hook_set_active_ext_lang,
2235 []() { raise (SIGINT); });
2240 catch (
const gdb_exception &e)
2242 saw_exception =
true;
2243 SELF_CHECK (e.reason == RETURN_ERROR);
2244 SELF_CHECK (e.error == GENERIC_ERROR);
2245 SELF_CHECK (*e.message ==
"Error while executing Python code.");
2247 SELF_CHECK (saw_exception);
2248 std::string ref_output_0 (
"Traceback (most recent call last):\n"
2249 " File \"<string>\", line 0, in <module>\n"
2250 "KeyboardInterrupt\n");
2251 std::string ref_output_1 (
"Traceback (most recent call last):\n"
2252 " File \"<string>\", line 1, in <module>\n"
2253 "KeyboardInterrupt\n");
2254 SELF_CHECK (output == ref_output_0 || output == ref_output_1);
2279Start an interactive Python prompt.\n\
2281To return to GDB, type the EOF character (e.g., Ctrl-D on an empty\n\
2284Alternatively, a single-line Python command can be given as an\n\
2285argument, and if the command is an expression, the result will be\n\
2286printed. For example:\n\
2288 (gdb) python-interactive 2 + 3\n\
2292Start a Python interactive prompt.\n\
2294Python scripting is not supported in this copy of GDB.\n\
2295This command is only a placeholder.")
2303Evaluate a Python command.\n\
2305The command can be given as an argument, for instance:\n\
2307 python print (23)\n\
2309If no argument is given, the following lines are read and used\n\
2310as the Python commands. Type a line containing \"end\" to indicate\n\
2311the end of the command.")
2314Evaluate a Python command.\n\
2316Python scripting is not supported in this copy of GDB.\n\
2317This command is only a placeholder.")
2324 _(
"Prefix command for python preference settings."),
2325 _(
"Prefix command for python preference settings."),
2331Set mode for Python stack dump on error."), _(
"\
2332Show the mode of Python stack printing on error."), _(
"\
2333none == no stack or message will be printed.\n\
2334full == a message and a stack will be printed.\n\
2335message == an error message without a stack will be printed."),
2342Set whether the Python interpreter should ignore environment variables."), _(
" \
2343Show whether the Python interpreter showlist ignore environment variables."), _(
" \
2344When enabled GDB's Python interpreter will ignore any Python related\n \
2345flags in the environment. This is equivalent to passing `-E' to a\n \
2346python executable."),
2354Set whether the Python interpreter should avoid byte-compiling python modules."), _(
"\
2355Show whether the Python interpreter should avoid byte-compiling python modules."), _(
"\
2356When enabled, GDB's embedded Python interpreter won't byte-compile python\n\
2357modules. In order to take effect, this setting must be enabled in an early\n\
2358initialization file, i.e. those run via the --early-init-eval-command or\n\
2359-eix command line options. A 'set python dont-write-bytecode on' command\n\
2360can also be issued directly from the GDB command line via the\n\
2361--early-init-eval-command or -eiex command line options.\n\
2363This setting defaults to 'auto'. In this mode, provided the 'python\n\
2364ignore-environment' setting is 'off', the environment variable\n\
2365PYTHONDONTWRITEBYTECODE is examined to determine whether or not to\n\
2366byte-compile python modules. PYTHONDONTWRITEBYTECODE is considered to be\n\
2367off/disabled either when set to the empty string or when the\n\
2368environment variable doesn't exist. All other settings, including those\n\
2369which don't seem to make sense, indicate that it's on/enabled."),
2377 selftests::register_test (
"python", selftests::test_python);
2396 std::string gdb_pythondir = (std::string (
gdb_datadir) + SLASH_STRING
2410#if PY_VERSION_HEX < 0x030a0000
2412 if (!(sys_path && PyList_Check (sys_path)))
2418 if (sys_path && PyList_Check (sys_path))
2420 gdbpy_ref<> pythondir (PyUnicode_FromString (gdb_pythondir.c_str ()));
2421 if (pythondir == NULL || PyList_Insert (sys_path, 0, pythondir.get ()))
2429 m = PyImport_AddModule (
"__main__");
2442 "Could not load the Python gdb module from `%s'.\n"
2443 "Limited Python support is available from the _gdb module.\n"
2444 "Suggest passing --data-directory=/path/to/gdb/data-directory."),
2445 gdb_pythondir.c_str ());
2461 if (!do_start_initialization () && PyErr_Occurred ())
2466 if (!do_initialize (extlang))
2469 warning (_(
"internal error: Unhandled Python exception"));
2482PyMethodDef python_GdbMethods[] =
2485 "Get a value from history" },
2487 "Add a value to the value history list" },
2489 "Return an integer, the number of values in GDB's value history" },
2490 {
"execute", (PyCFunction) execute_gdb_command, METH_VARARGS | METH_KEYWORDS,
2491 "execute (command [, from_tty] [, to_string]) -> [String]\n\
2492Evaluate command, a string, as a gdb CLI command. Optionally returns\n\
2493a Python String containing the output of the command if to_string is\n\
2495 {
"parameter", gdbpy_parameter, METH_VARARGS,
2496 "Return a gdb parameter's value" },
2499 "Return a tuple of all breakpoint objects" },
2502 "Find the default visualizer for a Value." },
2504 {
"progspaces", gdbpy_progspaces, METH_NOARGS,
2505 "Return a sequence of all progspaces." },
2507 {
"current_objfile", gdbpy_get_current_objfile, METH_NOARGS,
2508 "Return the current Objfile being loaded, or None." },
2511 "newest_frame () -> gdb.Frame.\n\
2512Return the newest frame object." },
2514 "selected_frame () -> gdb.Frame.\n\
2515Return the selected frame object." },
2517 "stop_reason_string (Integer) -> String.\n\
2518Return a string explaining unwind stop reason." },
2521 "start_recording ([method] [, format]) -> gdb.Record.\n\
2522Start recording with the given method. If no method is given, will fall back\n\
2523to the system default method. If no format is given, will fall back to the\n\
2524default format for the given method."},
2526 "current_recording () -> gdb.Record.\n\
2527Return current recording object." },
2529 "stop_recording () -> None.\n\
2530Stop current recording." },
2533 METH_VARARGS | METH_KEYWORDS,
2534 "lookup_type (name [, block]) -> type\n\
2535Return a Type corresponding to the given name." },
2537 METH_VARARGS | METH_KEYWORDS,
2538 "lookup_symbol (name [, block] [, domain]) -> (symbol, is_field_of_this)\n\
2539Return a tuple with the symbol corresponding to the given name (or None) and\n\
2540a boolean indicating if name is a field of the current implied argument\n\
2541`this' (when the current language is object-oriented)." },
2543 METH_VARARGS | METH_KEYWORDS,
2544 "lookup_global_symbol (name [, domain]) -> symbol\n\
2545Return the symbol corresponding to the given name (or None)." },
2547 METH_VARARGS | METH_KEYWORDS,
2548 "lookup_static_symbol (name [, domain]) -> symbol\n\
2549Return the static-linkage symbol corresponding to the given name (or None)." },
2551 METH_VARARGS | METH_KEYWORDS,
2552 "lookup_static_symbols (name [, domain]) -> symbol\n\
2553Return a list of all static-linkage symbols corresponding to the given name." },
2556 METH_VARARGS | METH_KEYWORDS,
2557 "lookup_objfile (name, [by_build_id]) -> objfile\n\
2558Look up the specified objfile.\n\
2559If by_build_id is True, the objfile is looked up by using name\n\
2562 {
"decode_line", gdbpy_decode_line, METH_VARARGS,
2563 "decode_line (String) -> Tuple. Decode a string argument the way\n\
2564that 'break' or 'edit' does. Return a tuple containing two elements.\n\
2565The first element contains any unparsed portion of the String parameter\n\
2566(or None if the string was fully parsed). The second element contains\n\
2567a tuple that contains all the locations that match, represented as\n\
2568gdb.Symtab_and_line objects (or None)."},
2569 {
"parse_and_eval", gdbpy_parse_and_eval, METH_VARARGS,
2570 "parse_and_eval (String) -> Value.\n\
2571Parse String as an expression, evaluate it, and return the result as a Value."
2574 {
"post_event", gdbpy_post_event, METH_VARARGS,
2575 "Post an event into gdb's event loop." },
2577 {
"target_charset", gdbpy_target_charset, METH_NOARGS,
2578 "target_charset () -> string.\n\
2579Return the name of the current target charset." },
2580 {
"target_wide_charset", gdbpy_target_wide_charset, METH_NOARGS,
2581 "target_wide_charset () -> string.\n\
2582Return the name of the current target wide charset." },
2583 {
"host_charset", gdbpy_host_charset, METH_NOARGS,
2584 "host_charset () -> string.\n\
2585Return the name of the current host charset." },
2586 {
"rbreak", (PyCFunction) gdbpy_rbreak, METH_VARARGS | METH_KEYWORDS,
2587 "rbreak (Regex) -> List.\n\
2588Return a Tuple containing gdb.Breakpoint objects that match the given Regex." },
2590 "string_to_argv (String) -> Array.\n\
2591Parse String and return an argv-like array.\n\
2592Arguments are separate by spaces and may be quoted."
2594 {
"write", (PyCFunction)gdbpy_write, METH_VARARGS | METH_KEYWORDS,
2595 "Write a string using gdb's filtered stream." },
2596 {
"flush", (PyCFunction)gdbpy_flush, METH_VARARGS | METH_KEYWORDS,
2597 "Flush gdb's filtered stdout stream." },
2599 "selected_thread () -> gdb.InferiorThread.\n\
2600Return the selected thread object." },
2602 "selected_inferior () -> gdb.Inferior.\n\
2603Return the selected inferior object." },
2605 "inferiors () -> (gdb.Inferior, ...).\n\
2606Return a tuple containing all inferiors." },
2608 {
"invalidate_cached_frames", gdbpy_invalidate_cached_frames, METH_NOARGS,
2609 "invalidate_cached_frames () -> None.\n\
2610Invalidate any cached frame objects in gdb.\n\
2611Intended for internal use only." },
2614 "convenience_variable (NAME) -> value.\n\
2615Return the value of the convenience variable $NAME,\n\
2616or None if not set." },
2618 "convenience_variable (NAME, VALUE) -> None.\n\
2619Set the value of the convenience variable $NAME." },
2623 METH_VARARGS | METH_KEYWORDS,
2624 "register_window_type (NAME, CONSTRUCSTOR) -> None\n\
2625Register a TUI window constructor." },
2629 "architecture_names () -> List.\n\
2630Return a list of all the architecture names GDB understands." },
2633 "connections () -> List.\n\
2634Return a list of gdb.TargetConnection objects." },
2636 {
"format_address", (PyCFunction) gdbpy_format_address,
2637 METH_VARARGS | METH_KEYWORDS,
2638 "format_address (ADDRESS, PROG_SPACE, ARCH) -> String.\n\
2639Format ADDRESS, an address within PROG_SPACE, a gdb.Progspace, using\n\
2640ARCH, a gdb.Architecture to determine the address size. The format of\n\
2641the returned string is 'ADDRESS <SYMBOL+OFFSET>' without the quotes." },
2643 {
"current_language", gdbpy_current_language, METH_NOARGS,
2644 "current_language () -> string\n\
2645Return the name of the currently selected language." },
2648 "print_options () -> dict\n\
2649Return the current print options." },
2651 {NULL, NULL, 0, NULL}
2655#define GDB_PY_DEFINE_EVENT_TYPE(name, py_name, doc, base) \
2656 PyTypeObject name##_event_object_type \
2657 CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object") \
2659 PyVarObject_HEAD_INIT (NULL, 0) \
2661 sizeof (event_object), \
2678 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, \
2697#include "py-event-types.def"
2698#undef GDB_PY_DEFINE_EVENT_TYPE
struct gdbarch * get_current_arch(void)
struct gdbarch * target_gdbarch(void)
void bpstat_do_actions(void)
const char * target_wide_charset(struct gdbarch *gdbarch)
const char * host_charset(void)
const char * target_charset(struct gdbarch *gdbarch)
static struct gdbarch * python_gdbarch
const struct language_defn * m_language
gdb::optional< gdbpy_err_fetch > m_error
static struct gdbarch * get_gdbarch()
gdbpy_enter(struct gdbarch *gdbarch=nullptr, const struct language_defn *language=nullptr)
struct gdbarch * m_gdbarch
struct active_ext_lang_state * m_previous_active
gdb::unique_xmalloc_ptr< char > type_to_string() const
gdb::unique_xmalloc_ptr< char > to_string() const
struct program_space * pspace
virtual ui_out * interp_ui_out()=0
const char * c_str() const
struct cmd_list_element * showlist
struct cmd_list_element * setlist
cmd_list_element * add_com_alias(const char *name, cmd_list_element *target, command_class theclass, int abbrev_flag)
struct cmd_list_element * add_com(const char *name, enum command_class theclass, cmd_simple_func_ftype *fun, const char *doc)
set_show_commands add_setshow_enum_cmd(const char *name, enum command_class theclass, const char *const *enumlist, const char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
set_show_commands add_setshow_prefix_cmd(const char *name, command_class theclass, const char *set_doc, const char *show_doc, cmd_list_element **set_subcommands_list, cmd_list_element **show_subcommands_list, cmd_list_element **set_list, cmd_list_element **show_list)
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
set_show_commands add_setshow_auto_boolean_cmd(const char *name, enum command_class theclass, enum auto_boolean *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
int lookup_cmd_composition(const char *text, struct cmd_list_element **alias, struct cmd_list_element **prefix_cmd, struct cmd_list_element **cmd)
counted_command_line read_command_lines_1(read_next_line_ftype read_next_line_func, int parse_commands, gdb::function_view< void(const char *)> validator)
void execute_control_commands(struct command_line *cmdlines, int from_tty)
counted_command_line get_command_line(enum command_control_type type, const char *arg)
enum command_control_type execute_control_command_untraced(struct command_line *cmd)
std::string execute_control_commands_to_string(struct command_line *commands, int from_tty)
std::shared_ptr< command_line > counted_command_line
scoped_restore_tmpl< int > prevent_dont_repeat(void)
@ var_zuinteger_unlimited
std::string python_libdir
void print_address(struct gdbarch *, CORE_ADDR, struct ui_file *)
struct value * parse_and_eval(const char *exp)
void async_enable_stdin(void)
struct active_ext_lang_state * set_active_ext_lang(const struct extension_language_defn *)
void restore_active_ext_lang(struct active_ext_lang_state *previous)
void script_sourcer_func(const struct extension_language_defn *, FILE *stream, const char *filename)
void objfile_script_sourcer_func(const struct extension_language_defn *, struct objfile *, FILE *stream, const char *filename)
void objfile_script_executor_func(const struct extension_language_defn *, struct objfile *, const char *name, const char *script)
void reinit_frame_cache(void)
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t err
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int status
struct inferior * current_inferior(void)
struct interp * interp_lookup(struct ui *ui, const char *name)
const struct language_defn * current_language
enum language set_language(enum language lang)
std::vector< symtab_and_line > decode_line_1(const location_spec *locspec, int flags, struct program_space *search_pspace, struct symtab *default_symtab, int default_line)
location_spec_up string_to_location_spec_basic(const char **stringp, const struct language_defn *language, symbol_name_match_type match_type)
std::unique_ptr< location_spec > location_spec_up
observable< int > gdb_exiting
#define prefix(a, b, R, do)
void set_current_program_space(struct program_space *pspace)
std::vector< struct program_space * > program_spaces
PyObject * gdbpy_all_architecture_names(PyObject *self, PyObject *args)
bool gdbpy_is_architecture(PyObject *obj)
struct gdbarch * arch_object_to_gdbarch(PyObject *obj)
int gdbpy_initialize_arch(void)
PyObject * gdbarch_to_arch_object(struct gdbarch *gdbarch)
int gdbpy_initialize_auto_load(void)
bool gdbpy_auto_load_enabled(const struct extension_language_defn *extlang)
int gdbpy_initialize_blocks(void)
PyObject * gdbpy_breakpoints(PyObject *self, PyObject *args)
PyTypeObject breakpoint_object_type
int gdbpy_breakpoint_has_cond(const struct extension_language_defn *extlang, struct breakpoint *b)
enum ext_lang_bp_stop gdbpy_breakpoint_cond_says_stop(const struct extension_language_defn *extlang, struct breakpoint *b)
int gdbpy_initialize_breakpoint_locations()
int gdbpy_initialize_breakpoints(void)
PyObject * gdbpy_string_to_argv(PyObject *self, PyObject *args)
int gdbpy_initialize_commands(void)
int gdbpy_initialize_connection(void)
PyObject * gdbpy_connections(PyObject *self, PyObject *args)
gdb::optional< int > gdbpy_print_insn(struct gdbarch *gdbarch, CORE_ADDR memaddr, disassemble_info *info)
int gdbpy_initialize_disasm()
gdbpy_ref create_event_object(PyTypeObject *py_type)
int evpy_add_attribute(PyObject *event, const char *name, PyObject *attr)
int evpy_emit_event(PyObject *event, eventregistry_object *registry)
int gdbpy_initialize_event(void)
events_object gdb_py_events
bool evregpy_no_listeners_p(eventregistry_object *registry)
int gdbpy_initialize_eventregistry(void)
PyMODINIT_FUNC gdbpy_events_mod_func()
int gdbpy_initialize_finishbreakpoints(void)
PyObject * gdbpy_frame_stop_reason_string(PyObject *self, PyObject *args)
int gdbpy_initialize_frames(void)
PyObject * gdbpy_selected_frame(PyObject *self, PyObject *args)
PyObject * gdbpy_newest_frame(PyObject *self, PyObject *args)
enum ext_lang_bt_status gdbpy_apply_frame_filter(const struct extension_language_defn *extlang, frame_info_ptr frame, frame_filter_flags flags, enum ext_lang_frame_args args_type, struct ui_out *out, int frame_low, int frame_high)
int gdbpy_initialize_functions(void)
void gdbpy_initialize_gdb_readline(void)
PyObject * gdbpy_selected_inferior(PyObject *self, PyObject *args)
PyObject * gdbpy_inferiors(PyObject *unused, PyObject *unused2)
int gdbpy_initialize_inferior(void)
PyObject * gdbpy_selected_thread(PyObject *self, PyObject *args)
int gdbpy_initialize_thread(void)
int gdbpy_initialize_instruction(void)
int gdbpy_initialize_lazy_string(void)
int gdbpy_initialize_linetable(void)
int gdbpy_initialize_membuf(void)
int gdbpy_initialize_micommands()
void gdbpy_finalize_micommands()
gdbpy_ref objfile_to_objfile_object(struct objfile *objfile)
PyObject * gdbpy_lookup_objfile(PyObject *self, PyObject *args, PyObject *kw)
int gdbpy_initialize_objfile(void)
int gdbpy_initialize_parameters(void)
PyObject * gdbpy_default_visualizer(PyObject *self, PyObject *args)
PyObject * gdbpy_print_options(PyObject *unused1, PyObject *unused2)
enum ext_lang_rc gdbpy_apply_val_pretty_printer(const struct extension_language_defn *extlang, struct value *value, struct ui_file *stream, int recurse, const struct value_print_options *options, const struct language_defn *language)
bool gdbpy_is_progspace(PyObject *obj)
gdbpy_ref pspace_to_pspace_object(struct program_space *pspace)
struct program_space * progspace_object_to_program_space(PyObject *obj)
int gdbpy_initialize_pspace(void)
int gdbpy_initialize_btrace(void)
PyObject * gdbpy_stop_recording(PyObject *self, PyObject *args)
PyObject * gdbpy_start_recording(PyObject *self, PyObject *args)
PyObject * gdbpy_current_recording(PyObject *self, PyObject *args)
int gdbpy_initialize_record(void)
gdb::ref_ptr< T, gdbpy_ref_policy< T > > gdbpy_ref
int gdbpy_initialize_registers()
int gdbpy_initialize_symbols(void)
PyObject * gdbpy_lookup_static_symbol(PyObject *self, PyObject *args, PyObject *kw)
PyObject * gdbpy_lookup_global_symbol(PyObject *self, PyObject *args, PyObject *kw)
PyObject * gdbpy_lookup_symbol(PyObject *self, PyObject *args, PyObject *kw)
PyObject * gdbpy_lookup_static_symbols(PyObject *self, PyObject *args, PyObject *kw)
PyObject * symtab_and_line_to_sal_object(struct symtab_and_line sal)
int gdbpy_initialize_symtabs(void)
int gdbpy_initialize_tui()
PyObject * type_to_type_object(struct type *type)
int gdbpy_initialize_types(void)
PyObject * gdbpy_lookup_type(PyObject *self, PyObject *args, PyObject *kw)
int gdbpy_initialize_unwind(void)
gdbpy_ref host_string_to_python_string(const char *str)
gdb::unique_xmalloc_ptr< char > python_string_to_target_string(PyObject *obj)
gdbpy_ref gdb_py_object_from_longest(LONGEST l)
int get_addr_from_python(PyObject *obj, CORE_ADDR *addr)
void gdbpy_convert_exception(const struct gdb_exception &exception)
int gdb_pymodule_addobject(PyObject *module, const char *name, PyObject *object)
gdb::unique_xmalloc_ptr< char > python_string_to_host_string(PyObject *obj)
gdbpy_ref gdb_py_object_from_ulongest(ULONGEST l)
PyObject * value_to_value_object(struct value *val)
PyObject * gdbpy_add_history(PyObject *self, PyObject *args)
PyObject * gdbpy_history_count(PyObject *self, PyObject *args)
int gdbpy_initialize_values(void)
PyObject * gdbpy_history(PyObject *self, PyObject *args)
PyObject * gdbpy_set_convenience_variable(PyObject *self, PyObject *args)
void gdbpy_preserve_values(const struct extension_language_defn *extlang, struct objfile *objfile, htab_t copied_types)
PyObject * gdbpy_convenience_variable(PyObject *self, PyObject *args)
int gdbpy_initialize_xmethods(void)
enum ext_lang_rc gdbpy_get_matching_xmethod_workers(const struct extension_language_defn *extlang, struct type *obj_type, const char *method_name, std::vector< xmethod_worker_up > *dm_vec)
void gdbpy_print_stack(void)
#define PyObject_CallMethod
int gdbpy_print_python_errors_p(void)
int gdb_python_initialized
PyObject * gdbpy_register_tui_window(PyObject *self, PyObject *args, PyObject *kw)
PyObject * gdbpy_children_cst
void gdbpy_print_stack_or_quit()
#define PyEval_InitThreads()
PyObject * gdbpy_gdb_memory_error
PyObject * gdbpy_display_hint_cst
PyObject * gdbpy_parameter_value(const setting &var)
#define PyGILState_Release(ARG)
#define PyGILState_Ensure()
PyObject * gdbpy_gdb_error
PyObject * gdbpy_enabled_cst
PyObject * gdbpy_to_string_cst
PyObject * gdb_python_module
PyObject * gdbpy_value_cst
#define PyErr_NewException
PyObject * gdbpy_gdberror_exc
#define GDB_PY_HANDLE_EXCEPTION(Exception)
static int gdb_PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, const char **keywords,...)
static enum auto_boolean python_dont_write_bytecode
static struct cmd_list_element * user_show_python_list
static const char *const python_excp_enums[]
static void set_python_ignore_environment(const char *args, int from_tty, struct cmd_list_element *c)
static const char python_excp_none[]
static void python_command(const char *arg, int from_tty)
const struct extension_language_defn extension_language_python
static const char python_excp_message[]
static struct cmd_list_element * user_set_python_list
cmd_list_element * python_cmd_element
void _initialize_python()
static void python_interactive_command(const char *arg, int from_tty)
static const char * gdbpy_should_print_stack
static void show_python_ignore_environment(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static const char python_excp_full[]
static bool python_ignore_environment
static void show_python_dont_write_bytecode(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static void set_python_dont_write_bytecode(const char *args, int from_tty, struct cmd_list_element *c)
struct objfile * gdbpy_current_objfile
void(* func)(remote_target *remote, char *)
void run_on_main_thread(std::function< void()> &&func)
const char * symtab_to_fullname(struct symtab *s)
struct symtab_and_line get_current_source_symtab_and_line(void)
void set_default_source_symtab_and_line(void)
gdb::optional< setting > var
counted_command_line body_list_0
counted_command_line body_list_1
struct command_line * next
enum language la_language
virtual const char * name() const =0
struct gdbarch * arch() const
setting_func_types< T >::type get() const
void set_prompt(const char *s)
std::string ldirname(const char *filename)
void gdb_printf(struct ui_file *stream, const char *format,...)
void gdb_flush(struct ui_file *stream)