]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/python/lib/gdb/dap/next.py
1 # Copyright 2022-2024 Free Software Foundation, Inc.
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.
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.
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/>.
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
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.
29 def _handle_thread_step(thread_id
, single_thread
, select
=False):
30 # Ensure we're going to step the correct thread.
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)
45 # Other DAP code may select a frame, and the "finish" command uses
48 gdb
.newest_frame().select()
52 @request("next", response
=False)
54 *, threadId
: int, singleThread
: bool = False, granularity
: str = "statement", **args
56 _handle_thread_step(threadId
, singleThread
)
58 if granularity
== "instruction":
60 exec_and_expect_stop(cmd
)
63 @capability("supportsSteppingGranularity")
64 @capability("supportsSingleThreadExecutionRequests")
65 @request("stepIn", response
=False)
67 *, threadId
: int, singleThread
: bool = False, granularity
: str = "statement", **args
69 _handle_thread_step(threadId
, singleThread
)
71 if granularity
== "instruction":
73 exec_and_expect_stop(cmd
)
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")
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
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
}