Regenerate AArch64 opcodes files
[binutils-gdb.git] / gdb / python / py-dap.c
blob9a00130fe907d1541062aecdba47ec68d4ec08e9
1 /* Python DAP interpreter
3 Copyright (C) 2022-2024 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/>. */
20 #include "defs.h"
21 #include "python-internal.h"
22 #include "interps.h"
23 #include "cli-out.h"
24 #include "ui.h"
26 class dap_interp final : public interp
28 public:
30 explicit dap_interp (const char *name)
31 : interp (name),
32 m_ui_out (new cli_ui_out (gdb_stdout))
36 ~dap_interp () override = default;
38 void init (bool top_level) override;
40 void suspend () override
44 void resume () override
48 void exec (const char *command) override
50 /* Just ignore it. */
53 void set_logging (ui_file_up logfile, bool logging_redirect,
54 bool debug_redirect) override
56 /* Just ignore it. */
59 ui_out *interp_ui_out () override
61 return m_ui_out.get ();
64 void pre_command_loop () override;
66 private:
68 std::unique_ptr<ui_out> m_ui_out;
72 /* Call function FN_NAME from module gdb.dap. */
74 static void
75 call_dap_fn (const char *fn_name)
77 gdbpy_enter enter_py;
79 gdbpy_ref<> dap_module (PyImport_ImportModule ("gdb.dap"));
80 if (dap_module == nullptr)
81 gdbpy_handle_exception ();
83 gdbpy_ref<> func (PyObject_GetAttrString (dap_module.get (), fn_name));
84 if (func == nullptr)
85 gdbpy_handle_exception ();
87 gdbpy_ref<> result_obj (PyObject_CallObject (func.get (), nullptr));
88 if (result_obj == nullptr)
89 gdbpy_handle_exception ();
92 void
93 dap_interp::init (bool top_level)
95 #if CXX_STD_THREAD
96 call_dap_fn ("run");
98 current_ui->input_fd = -1;
99 current_ui->m_input_interactive_p = false;
100 #else
101 error (_("GDB was compiled without threading, which DAP requires"));
102 #endif
105 void
106 dap_interp::pre_command_loop ()
108 call_dap_fn ("pre_command_loop");
111 void _initialize_py_interp ();
112 void
113 _initialize_py_interp ()
115 /* The dap code uses module typing, available starting python 3.5. */
116 #if PY_VERSION_HEX >= 0x03050000
117 interp_factory_register ("dap", [] (const char *name) -> interp *
119 return new dap_interp (name);
121 #endif