GDB (xrefs)
Loading...
Searching...
No Matches
py-dap.c
Go to the documentation of this file.
1/* Python DAP interpreter
2
3 Copyright (C) 2022, 2023 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 "python-internal.h"
22#include "interps.h"
23#include "cli-out.h"
24#include "ui.h"
25
26class dap_interp final : public interp
27{
28public:
29
30 explicit dap_interp (const char *name)
31 : interp (name),
33 {
34 }
35
36 ~dap_interp () override = default;
37
38 void init (bool top_level) override;
39
40 void suspend () override
41 {
42 }
43
44 void resume () override
45 {
46 }
47
48 void exec (const char *command) override
49 {
50 /* Just ignore it. */
51 }
52
54 bool debug_redirect) override
55 {
56 /* Just ignore it. */
57 }
58
59 ui_out *interp_ui_out () override
60 {
61 return m_ui_out.get ();
62 }
63
64private:
65
66 std::unique_ptr<ui_out> m_ui_out;
67};
68
69void
70dap_interp::init (bool top_level)
71{
72 gdbpy_enter enter_py;
73
74 gdbpy_ref<> dap_module (PyImport_ImportModule ("gdb.dap"));
75 if (dap_module == nullptr)
77
78 gdbpy_ref<> func (PyObject_GetAttrString (dap_module.get (), "run"));
79 if (func == nullptr)
81
82 gdbpy_ref<> result_obj (PyObject_CallObject (func.get (), nullptr));
83 if (result_obj == nullptr)
85
86 current_ui->input_fd = -1;
88}
89
91void
93{
94 /* The dap code uses module typing, available starting python 3.5. */
95#if PY_VERSION_HEX >= 0x03050000
96 interp_factory_register ("dap", [] (const char *name) -> interp *
97 {
98 return new dap_interp (name);
99 });
100#endif
101}
const char *const name
void suspend() override
Definition py-dap.c:40
std::unique_ptr< ui_out > m_ui_out
Definition py-dap.c:66
void resume() override
Definition py-dap.c:44
void set_logging(ui_file_up logfile, bool logging_redirect, bool debug_redirect) override
Definition py-dap.c:53
dap_interp(const char *name)
Definition py-dap.c:30
void exec(const char *command) override
Definition py-dap.c:48
ui_out * interp_ui_out() override
Definition py-dap.c:59
void init(bool top_level) override
Definition py-dap.c:70
~dap_interp() override=default
const char * name() const
Definition interps.h:87
static bool debug_redirect
Definition cli-logging.c:67
static bool logging_redirect
Definition cli-logging.c:66
void interp_factory_register(const char *name, interp_factory_func func)
Definition interps.c:78
void _initialize_py_interp()
Definition py-dap.c:92
gdb::ref_ptr< T, gdbpy_ref_policy< T > > gdbpy_ref
Definition py-ref.h:42
void gdbpy_handle_exception()
Definition py-utils.c:369
void(* func)(remote_target *remote, char *)
int input_fd
Definition ui.h:128
bool m_input_interactive_p
Definition ui.h:133
std::unique_ptr< ui_file > ui_file_up
Definition ui-file.h:150
struct ui * current_ui
Definition ui.c:35
#define gdb_stdout
Definition utils.h:182