** GDB now supports the "cancel" request.
+ ** The "attach" request now supports specifying the program.
+
* New remote packets
New stop reason: clone
@end table
@value{GDBN} defines some parameters that can be passed to the
-@code{attach} request. One of these must be specified.
+@code{attach} request. Either @code{pid} or @code{target} must be
+specified, but if both are specified then @code{target} will be
+ignored.
@table @code
@item pid
The process ID to which @value{GDBN} should attach. @xref{Attach}.
+@item program
+If provided, this is a string that specifies the program to use. This
+corresponds to the @code{file} command. @xref{Files}. In some cases,
+@value{GDBN} can automatically determine which program is running.
+However, for many remote targets, this is not the case, and so this
+should be supplied.
+
@item target
The target to which @value{GDBN} should connect. This is a string and
is passed to the @code{target remote} command. @xref{Connecting}.
_program = None
+# True if the program was attached, False otherwise. This should only
+# be accessed from the gdb thread.
+_attach = False
+
+
# Any parameters here are necessarily extensions -- DAP requires this
# from implementations. Any additions or changes here should be
# documented in the gdb manual.
):
global _program
_program = program
+ global _attach
+ _attach = False
if cwd is not None:
exec_and_log("cd " + cwd)
if program is not None:
@request("attach")
-def attach(*, pid: Optional[int] = None, target: Optional[str] = None, **args):
+def attach(
+ *,
+ program: Optional[str] = None,
+ pid: Optional[int] = None,
+ target: Optional[str] = None,
+ **args,
+):
# Ensure configurationDone does not try to run.
+ global _attach
+ _attach = True
global _program
- _program = None
+ _program = program
+ if program is not None:
+ exec_and_log("file " + program)
if pid is not None:
cmd = "attach " + str(pid)
elif target is not None:
@capability("supportsConfigurationDoneRequest")
@request("configurationDone", response=False)
def config_done(**args):
- global _program
- if _program is not None:
+ global _attach
+ if not _attach:
expect_process("process")
exec_and_expect_stop("run")
set testpid [spawn_id_get_pid $test_spawn_id]
# We just want to test that attaching works at all.
-if {[dap_attach $testpid] != ""} {
+if {[dap_attach $testpid $binfile] != ""} {
dap_shutdown true
}
# Start gdb, send a DAP initialize request, and then an attach request
# specifying PID as the inferior process ID. Returns the empty string
# on failure, or the response object from the attach request.
-proc dap_attach {pid} {
+proc dap_attach {pid {prog ""}} {
if {[_dap_initialize "startup - initialize"] == ""} {
return ""
}
- return [dap_check_request_and_response "startup - attach" attach \
- [format {o pid [i %s]} $pid]]
+
+ set args [format {o pid [i %s]} $pid]
+ if {$prog != ""} {
+ append args [format { program [s %s]} $prog]
+ }
+
+ return [dap_check_request_and_response "startup - attach" attach $args]
}
# Start gdb, send a DAP initialize request, and then an attach request