]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/python/lib/gdb/dap/__init__.py
Implement DAP breakpointLocations request
[thirdparty/binutils-gdb.git] / gdb / python / lib / gdb / dap / __init__.py
CommitLineData
14ade916 1# Copyright 2022-2023 Free Software Foundation, Inc.
de7d7cb5
TT
2
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.
7#
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.
12#
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/>.
15
16import os
17import gdb
18
19# This must come before other DAP imports.
20from . import startup
21
22# Load modules that define commands.
23from . import breakpoint
24from . import bt
25from . import disassemble
26from . import evaluate
27from . import launch
3c453cfb 28from . import locations
d466f749 29from . import memory
de7d7cb5
TT
30from . import next
31from . import pause
32from . import scopes
a0b70d99 33from . import sources
de7d7cb5
TT
34from . import threads
35
36from .server import Server
37
38
39def run():
40 """Main entry point for the DAP server.
41 This is called by the GDB DAP interpreter."""
42 startup.exec_and_log("set python print-stack full")
43 startup.exec_and_log("set pagination off")
44
45 # We want to control gdb stdin and stdout entirely, so we dup
46 # them to new file descriptors.
47 saved_out = os.dup(1)
48 saved_in = os.dup(0)
49 # Make sure these are not inheritable. This is already the case
50 # for Unix, but not for Windows.
51 os.set_inheritable(saved_out, False)
52 os.set_inheritable(saved_in, False)
53
54 # The new gdb (and inferior) stdin will just be /dev/null. For
55 # gdb, the "dap" interpreter also rewires the UI so that gdb
56 # doesn't try to read this (and thus see EOF and exit).
57 new_in = os.open(os.devnull, os.O_RDONLY)
58 os.dup2(new_in, 0, True)
59 os.close(new_in)
60
61 # Make the new stdout be a pipe. This way the DAP code can easily
62 # read from the inferior and send OutputEvent to the client.
63 (rfd, wfd) = os.pipe()
64 os.set_inheritable(rfd, False)
65 os.dup2(wfd, 1, True)
66 # Also send stderr this way.
67 os.dup2(wfd, 2, True)
68 os.close(wfd)
69
70 # Note the inferior output is opened in text mode.
71 server = Server(open(saved_in, "rb"), open(saved_out, "wb"), open(rfd, "r"))
72 startup.start_dap(server.main_loop)