]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame_incremental - gdb/python/lib/gdb/dap/next.py
[gdb/testsuite] Fix gdb.arch/amd64-disp-step-avx.exp on x86_64-freebsd
[thirdparty/binutils-gdb.git] / gdb / python / lib / gdb / dap / next.py
... / ...
CommitLineData
1# Copyright 2022-2025 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
18from .events import exec_and_expect_stop
19from .server import capability, request
20from .startup import in_gdb_thread
21from .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
29def _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)
53def 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)
66def 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")
77def step_out(*, threadId: int, singleThread: bool = False, **args):
78 _handle_thread_step(threadId, singleThread, True)
79 exec_and_expect_stop("finish &", propagate_exception=True)
80
81
82@request("continue")
83def continue_request(*, threadId: int, singleThread: bool = False, **args):
84 locked = _handle_thread_step(threadId, singleThread)
85 exec_and_expect_stop("continue &")
86 return {"allThreadsContinued": not locked}