]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/python/lib/gdb/dap/__init__.py
689c2049eec18d44a82937aab1119031c73969b1
1 # Copyright 2022-2023 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # This must come before other DAP imports.
22 # Load modules that define commands.
23 from . import breakpoint
25 from . import disassemble
26 from . import evaluate
28 from . import locations
37 from .server
import Server
41 """Main entry point for the DAP server.
42 This is called by the GDB DAP interpreter."""
43 startup
.exec_and_log("set python print-stack full")
44 startup
.exec_and_log("set pagination off")
46 # We want to control gdb stdin and stdout entirely, so we dup
47 # them to new file descriptors.
50 # Make sure these are not inheritable. This is already the case
51 # for Unix, but not for Windows.
52 os
.set_inheritable(saved_out
, False)
53 os
.set_inheritable(saved_in
, False)
55 # The new gdb (and inferior) stdin will just be /dev/null. For
56 # gdb, the "dap" interpreter also rewires the UI so that gdb
57 # doesn't try to read this (and thus see EOF and exit).
58 new_in
= os
.open(os
.devnull
, os
.O_RDONLY
)
59 os
.dup2(new_in
, 0, True)
62 # Make the new stdout be a pipe. This way the DAP code can easily
63 # read from the inferior and send OutputEvent to the client.
64 (rfd
, wfd
) = os
.pipe()
65 os
.set_inheritable(rfd
, False)
67 # Also send stderr this way.
71 # Note the inferior output is opened in text mode.
72 server
= Server(open(saved_in
, "rb"), open(saved_out
, "wb"), open(rfd
, "r"))
73 startup
.start_dap(server
.main_loop
)