GDB (xrefs)
Loading...
Searching...
No Matches
launch.py
Go to the documentation of this file.
1# Copyright 2022-2023 Free Software Foundation, Inc.
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 gdb
17
18# These are deprecated in 3.9, but required in older versions.
19from typing import Mapping, Optional, Sequence
20
21from .events import exec_and_expect_stop
22from .server import request, capability
23from .startup import in_gdb_thread, exec_and_log
24
25
26# The program being launched, or None. This should only be accessed
27# from the gdb thread.
28_program = None
29
30
31@in_gdb_thread
32def _launch_setup(program, cwd, args, env, stopAtBeginningOfMainSubprogram):
33 if cwd is not None:
34 exec_and_log("cd " + cwd)
35 if program is not None:
36 exec_and_log("file " + program)
37 inf = gdb.selected_inferior()
38 if stopAtBeginningOfMainSubprogram:
39 main = inf.main_name
40 if main is not None:
41 exec_and_log("tbreak " + main)
42 inf.arguments = args
43 if env is not None:
44 inf.clear_env()
45 for name, value in env.items():
46 inf.set_env(name, value)
47
48
49# Any parameters here are necessarily extensions -- DAP requires this
50# from implementations. Any additions or changes here should be
51# documented in the gdb manual.
52@request("launch", response=False)
53def launch(
54 *,
55 program: Optional[str] = None,
56 cwd: Optional[str] = None,
57 args: Sequence[str] = (),
58 env: Optional[Mapping[str, str]] = None,
59 stopAtBeginningOfMainSubprogram: bool = False,
60 **extra,
61):
62 global _program
63 _program = program
64 _launch_setup(program, cwd, args, env, stopAtBeginningOfMainSubprogram)
65
66
67@request("attach")
68def attach(*, pid: Optional[int] = None, target: Optional[str] = None, **args):
69 # Ensure configurationDone does not try to run.
70 global _program
71 _program = None
72 if pid is not None:
73 cmd = "attach " + str(pid)
74 elif target is not None:
75 cmd = "target remote " + target
76 else:
77 raise Exception("attach requires either 'pid' or 'target'")
78 exec_and_log(cmd)
79
80
81@capability("supportsConfigurationDoneRequest")
82@request("configurationDone", response=False)
83def config_done(**args):
84 global _program
85 if _program is not None:
86 # Suppress the continue event, but don't set any particular
87 # expected stop.
88 exec_and_expect_stop("run", None)
attach(*Optional[int] pid=None, Optional[str] target=None, **args)
Definition launch.py:68
config_done(**args)
Definition launch.py:83
_launch_setup(program, cwd, args, env, stopAtBeginningOfMainSubprogram)
Definition launch.py:32