]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/python/lib/gdb/dap/next.py
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / python / lib / gdb / dap / next.py
1 # Copyright 2022-2024 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
16 import gdb
17
18 from .events import exec_and_expect_stop
19 from .server import capability, request
20 from .startup import in_gdb_thread, send_gdb, send_gdb_with_response
21 from .state import set_thread
22
23
24 # Helper function to set the current thread and the scheduler-locking
25 # mode. Returns True if scheduler-locking was successfully set to
26 # 'on', False in all other cases, including error. When SELECT is
27 # True, also select that thread's newest frame.
28 @in_gdb_thread
29 def _handle_thread_step(thread_id, single_thread, select=False):
30 # Ensure we're going to step the correct thread.
31 set_thread(thread_id)
32 if single_thread:
33 result = True
34 arg = "on"
35 else:
36 result = False
37 arg = "off"
38 try:
39 # This can fail, depending on the target, so catch the error
40 # and report to our caller. We can't use exec_and_log because
41 # that does not propagate exceptions.
42 gdb.execute("set scheduler-locking " + arg, from_tty=True, to_string=True)
43 except gdb.error:
44 result = False
45 # Other DAP code may select a frame, and the "finish" command uses
46 # the selected frame.
47 if select:
48 gdb.newest_frame().select()
49 return result
50
51
52 @request("next", response=False)
53 def next(
54 *, threadId: int, singleThread: bool = False, granularity: str = "statement", **args
55 ):
56 _handle_thread_step(threadId, singleThread)
57 cmd = "next"
58 if granularity == "instruction":
59 cmd += "i"
60 exec_and_expect_stop(cmd)
61
62
63 @capability("supportsSteppingGranularity")
64 @capability("supportsSingleThreadExecutionRequests")
65 @request("stepIn", response=False)
66 def step_in(
67 *, threadId: int, singleThread: bool = False, granularity: str = "statement", **args
68 ):
69 _handle_thread_step(threadId, singleThread)
70 cmd = "step"
71 if granularity == "instruction":
72 cmd += "i"
73 exec_and_expect_stop(cmd)
74
75
76 @request("stepOut", response=False)
77 def step_out(*, threadId: int, singleThread: bool = False, **args):
78 _handle_thread_step(threadId, singleThread, True)
79 exec_and_expect_stop("finish")
80
81
82 # This is a server-side request because it is funny: it wants to
83 # 'continue' but also return a result, which precludes using
84 # response=False. Using 'continue &' would mostly work ok, but this
85 # yields races when a stop occurs before the response is sent back to
86 # the client.
87 @request("continue", on_dap_thread=True)
88 def continue_request(*, threadId: int, singleThread: bool = False, **args):
89 locked = send_gdb_with_response(lambda: _handle_thread_step(threadId, singleThread))
90 send_gdb(lambda: exec_and_expect_stop("continue"))
91 return {"allThreadsContinued": not locked}