]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - 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
CommitLineData
1d506c26 1# Copyright 2022-2024 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
fc2d72af
TT
16import gdb
17
7729e7c0 18from .events import exec_and_expect_stop
de7d7cb5 19from .server import capability, request
fc2d72af 20from .startup import in_gdb_thread, send_gdb, send_gdb_with_response
de7d7cb5
TT
21from .state import set_thread
22
23
fc2d72af
TT
24# Helper function to set the current thread and the scheduler-locking
25# mode. Returns True if scheduler-locking was successfully set to
91c7233d
TT
26# 'on', False in all other cases, including error. When SELECT is
27# True, also select that thread's newest frame.
fc2d72af 28@in_gdb_thread
91c7233d 29def _handle_thread_step(thread_id, single_thread, select=False):
de7d7cb5 30 # Ensure we're going to step the correct thread.
fc2d72af
TT
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
91c7233d
TT
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()
fc2d72af 49 return result
de7d7cb5
TT
50
51
c98921b2 52@request("next", response=False)
51058658
TT
53def next(
54 *, threadId: int, singleThread: bool = False, granularity: str = "statement", **args
55):
c98921b2 56 _handle_thread_step(threadId, singleThread)
de7d7cb5
TT
57 cmd = "next"
58 if granularity == "instruction":
59 cmd += "i"
7729e7c0 60 exec_and_expect_stop(cmd)
de7d7cb5
TT
61
62
63@capability("supportsSteppingGranularity")
fc2d72af 64@capability("supportsSingleThreadExecutionRequests")
c98921b2 65@request("stepIn", response=False)
51058658
TT
66def step_in(
67 *, threadId: int, singleThread: bool = False, granularity: str = "statement", **args
68):
c98921b2 69 _handle_thread_step(threadId, singleThread)
de7d7cb5
TT
70 cmd = "step"
71 if granularity == "instruction":
72 cmd += "i"
7729e7c0 73 exec_and_expect_stop(cmd)
de7d7cb5
TT
74
75
c98921b2 76@request("stepOut", response=False)
d2266b23 77def step_out(*, threadId: int, singleThread: bool = False, **args):
c98921b2 78 _handle_thread_step(threadId, singleThread, True)
7729e7c0 79 exec_and_expect_stop("finish")
3eb64586
TT
80
81
c98921b2
TT
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)
51058658 88def continue_request(*, threadId: int, singleThread: bool = False, **args):
fc2d72af 89 locked = send_gdb_with_response(lambda: _handle_thread_step(threadId, singleThread))
7729e7c0 90 send_gdb(lambda: exec_and_expect_stop("continue"))
fc2d72af 91 return {"allThreadsContinued": not locked}