1 /* Target operations for the remote server for GDB.
2 Copyright (C) 2002-2022 Free Software Foundation, Inc.
4 Contributed by MontaVista Software.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "tracepoint.h"
23 #include "gdbsupport/byte-vector.h"
27 #include <sys/types.h>
30 process_stratum_target
*the_target
;
35 client_state
&cs
= get_client_state ();
36 thread_info
*found
= find_thread_ptid (cs
.general_thread
);
38 switch_to_thread (found
);
39 return (current_thread
!= NULL
);
43 read_inferior_memory (CORE_ADDR memaddr
, unsigned char *myaddr
, int len
)
45 /* At the time of writing, GDB only sends write packets with LEN==0,
46 not read packets (see comment in target_write_memory), but it
47 doesn't hurt to prevent problems if it ever does, or we're
48 connected to some client other than GDB that does. */
52 int res
= the_target
->read_memory (memaddr
, myaddr
, len
);
53 check_mem_read (memaddr
, myaddr
, len
);
57 /* See target/target.h. */
60 target_read_memory (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ssize_t len
)
62 return read_inferior_memory (memaddr
, myaddr
, len
);
65 /* See target/target.h. */
68 target_read_uint32 (CORE_ADDR memaddr
, uint32_t *result
)
70 return read_inferior_memory (memaddr
, (gdb_byte
*) result
, sizeof (*result
));
73 /* See target/target.h. */
76 target_write_memory (CORE_ADDR memaddr
, const unsigned char *myaddr
,
79 /* GDB may send X packets with LEN==0, for probing packet support.
80 If we let such a request go through, then buffer.data() below may
81 return NULL, which may confuse target implementations. Handle it
82 here to avoid lower levels having to care about this case. */
86 /* Make a copy of the data because check_mem_write may need to
88 gdb::byte_vector
buffer (myaddr
, myaddr
+ len
);
89 check_mem_write (memaddr
, buffer
.data (), myaddr
, len
);
90 return the_target
->write_memory (memaddr
, buffer
.data (), len
);
94 mywait (ptid_t ptid
, struct target_waitstatus
*ourstatus
,
95 target_wait_flags options
, int connected_wait
)
102 ret
= target_wait (ptid
, ourstatus
, options
);
104 /* We don't expose _LOADED events to gdbserver core. See the
105 `dlls_changed' global. */
106 if (ourstatus
->kind () == TARGET_WAITKIND_LOADED
)
107 ourstatus
->set_stopped (GDB_SIGNAL_0
);
109 /* If GDB is connected through TCP/serial, then GDBserver will most
110 probably be running on its own terminal/console, so it's nice to
111 print there why is GDBserver exiting. If however, GDB is
112 connected through stdio, then there's no need to spam the GDB
113 console with this -- the user will already see the exit through
114 regular GDB output, in that same terminal. */
115 if (!remote_connection_is_stdio ())
117 if (ourstatus
->kind () == TARGET_WAITKIND_EXITED
)
119 "\nChild exited with status %d\n", ourstatus
->exit_status ());
120 else if (ourstatus
->kind () == TARGET_WAITKIND_SIGNALLED
)
121 fprintf (stderr
, "\nChild terminated with signal = 0x%x (%s)\n",
122 gdb_signal_to_host (ourstatus
->sig ()),
123 gdb_signal_to_name (ourstatus
->sig ()));
132 /* See target/target.h. */
135 target_stop_and_wait (ptid_t ptid
)
137 struct target_waitstatus status
;
138 bool was_non_stop
= non_stop
;
139 struct thread_resume resume_info
;
141 resume_info
.thread
= ptid
;
142 resume_info
.kind
= resume_stop
;
143 resume_info
.sig
= GDB_SIGNAL_0
;
144 the_target
->resume (&resume_info
, 1);
147 mywait (ptid
, &status
, 0, 0);
148 non_stop
= was_non_stop
;
151 /* See target/target.h. */
154 target_wait (ptid_t ptid
, struct target_waitstatus
*status
,
155 target_wait_flags options
)
157 return the_target
->wait (ptid
, status
, options
);
160 /* See target/target.h. */
163 target_mourn_inferior (ptid_t ptid
)
165 the_target
->mourn (find_process_pid (ptid
.pid ()));
168 /* See target/target.h. */
171 target_continue_no_signal (ptid_t ptid
)
173 struct thread_resume resume_info
;
175 resume_info
.thread
= ptid
;
176 resume_info
.kind
= resume_continue
;
177 resume_info
.sig
= GDB_SIGNAL_0
;
178 the_target
->resume (&resume_info
, 1);
181 /* See target/target.h. */
184 target_continue (ptid_t ptid
, enum gdb_signal signal
)
186 struct thread_resume resume_info
;
188 resume_info
.thread
= ptid
;
189 resume_info
.kind
= resume_continue
;
190 resume_info
.sig
= gdb_signal_to_host (signal
);
191 the_target
->resume (&resume_info
, 1);
194 /* See target/target.h. */
197 target_supports_multi_process (void)
199 return the_target
->supports_multi_process ();
203 set_target_ops (process_stratum_target
*target
)
208 /* Convert pid to printable format. */
211 target_pid_to_str (ptid_t ptid
)
213 if (ptid
== minus_one_ptid
)
214 return string_printf("<all threads>");
215 else if (ptid
== null_ptid
)
216 return string_printf("<null thread>");
217 else if (ptid
.tid () != 0)
218 return string_printf("Thread %d.0x%s",
220 phex_nz (ptid
.tid (), sizeof (ULONGEST
)));
221 else if (ptid
.lwp () != 0)
222 return string_printf("LWP %d.%ld",
223 ptid
.pid (), ptid
.lwp ());
225 return string_printf("Process %d",
230 kill_inferior (process_info
*proc
)
232 gdb_agent_about_to_close (proc
->pid
);
234 return the_target
->kill (proc
);
239 target_terminal_state
target_terminal::m_terminal_state
240 = target_terminal_state::is_ours
;
242 /* See target/target.h. */
245 target_terminal::init ()
247 /* Placeholder needed because of fork_inferior. Not necessary on
251 /* See target/target.h. */
254 target_terminal::inferior ()
256 /* Placeholder needed because of fork_inferior. Not necessary on
260 /* See target/target.h. */
263 target_terminal::ours ()
265 /* Placeholder needed because of fork_inferior. Not necessary on
269 /* See target/target.h. */
272 target_terminal::ours_for_output (void)
277 /* See target/target.h. */
280 target_terminal::info (const char *arg
, int from_tty
)
285 /* Default implementations of target ops.
286 See target.h for definitions. */
289 process_stratum_target::post_create_inferior ()
295 process_stratum_target::look_up_symbols ()
301 process_stratum_target::supports_read_auxv ()
307 process_stratum_target::read_auxv (CORE_ADDR offset
, unsigned char *myaddr
,
310 gdb_assert_not_reached ("target op read_auxv not supported");
314 process_stratum_target::supports_z_point_type (char z_type
)
320 process_stratum_target::insert_point (enum raw_bkpt_type type
,
322 int size
, raw_breakpoint
*bp
)
328 process_stratum_target::remove_point (enum raw_bkpt_type type
,
330 int size
, raw_breakpoint
*bp
)
336 process_stratum_target::stopped_by_sw_breakpoint ()
342 process_stratum_target::supports_stopped_by_sw_breakpoint ()
348 process_stratum_target::stopped_by_hw_breakpoint ()
354 process_stratum_target::supports_stopped_by_hw_breakpoint ()
360 process_stratum_target::supports_hardware_single_step ()
366 process_stratum_target::stopped_by_watchpoint ()
372 process_stratum_target::stopped_data_address ()
378 process_stratum_target::supports_read_offsets ()
384 process_stratum_target::supports_memory_tagging ()
390 process_stratum_target::fetch_memtags (CORE_ADDR address
, size_t len
,
391 gdb::byte_vector
&tags
, int type
)
393 gdb_assert_not_reached ("target op fetch_memtags not supported");
397 process_stratum_target::store_memtags (CORE_ADDR address
, size_t len
,
398 const gdb::byte_vector
&tags
, int type
)
400 gdb_assert_not_reached ("target op store_memtags not supported");
404 process_stratum_target::read_offsets (CORE_ADDR
*text
, CORE_ADDR
*data
)
406 gdb_assert_not_reached ("target op read_offsets not supported");
410 process_stratum_target::supports_get_tls_address ()
416 process_stratum_target::get_tls_address (thread_info
*thread
,
418 CORE_ADDR load_module
,
421 gdb_assert_not_reached ("target op get_tls_address not supported");
425 process_stratum_target::supports_qxfer_osdata ()
431 process_stratum_target::qxfer_osdata (const char *annex
,
432 unsigned char *readbuf
,
433 unsigned const char *writebuf
,
434 CORE_ADDR offset
, int len
)
436 gdb_assert_not_reached ("target op qxfer_osdata not supported");
440 process_stratum_target::supports_qxfer_siginfo ()
446 process_stratum_target::qxfer_siginfo (const char *annex
,
447 unsigned char *readbuf
,
448 unsigned const char *writebuf
,
449 CORE_ADDR offset
, int len
)
451 gdb_assert_not_reached ("target op qxfer_siginfo not supported");
455 process_stratum_target::supports_non_stop ()
461 process_stratum_target::async (bool enable
)
467 process_stratum_target::start_non_stop (bool enable
)
476 process_stratum_target::supports_multi_process ()
482 process_stratum_target::supports_fork_events ()
488 process_stratum_target::supports_vfork_events ()
494 process_stratum_target::supports_exec_events ()
500 process_stratum_target::handle_new_gdb_connection ()
506 process_stratum_target::handle_monitor_command (char *mon
)
512 process_stratum_target::core_of_thread (ptid_t ptid
)
518 process_stratum_target::supports_read_loadmap ()
524 process_stratum_target::read_loadmap (const char *annex
,
526 unsigned char *myaddr
,
529 gdb_assert_not_reached ("target op read_loadmap not supported");
533 process_stratum_target::process_qsupported
534 (gdb::array_view
<const char * const> features
)
540 process_stratum_target::supports_tracepoints ()
546 process_stratum_target::read_pc (regcache
*regcache
)
548 gdb_assert_not_reached ("process_target::read_pc: Unable to find PC");
552 process_stratum_target::write_pc (regcache
*regcache
, CORE_ADDR pc
)
554 gdb_assert_not_reached ("process_target::write_pc: Unable to update PC");
558 process_stratum_target::supports_thread_stopped ()
564 process_stratum_target::thread_stopped (thread_info
*thread
)
566 gdb_assert_not_reached ("target op thread_stopped not supported");
570 process_stratum_target::supports_get_tib_address ()
576 process_stratum_target::get_tib_address (ptid_t ptid
, CORE_ADDR
*address
)
578 gdb_assert_not_reached ("target op get_tib_address not supported");
582 process_stratum_target::pause_all (bool freeze
)
588 process_stratum_target::unpause_all (bool unfreeze
)
594 process_stratum_target::stabilize_threads ()
600 process_stratum_target::supports_fast_tracepoints ()
606 process_stratum_target::install_fast_tracepoint_jump_pad
607 (CORE_ADDR tpoint
, CORE_ADDR tpaddr
, CORE_ADDR collector
,
608 CORE_ADDR lockaddr
, ULONGEST orig_size
, CORE_ADDR
*jump_entry
,
609 CORE_ADDR
*trampoline
, ULONGEST
*trampoline_size
,
610 unsigned char *jjump_pad_insn
, ULONGEST
*jjump_pad_insn_size
,
611 CORE_ADDR
*adjusted_insn_addr
, CORE_ADDR
*adjusted_insn_addr_end
,
614 gdb_assert_not_reached ("target op install_fast_tracepoint_jump_pad "
619 process_stratum_target::get_min_fast_tracepoint_insn_len ()
625 process_stratum_target::emit_ops ()
631 process_stratum_target::supports_disable_randomization ()
637 process_stratum_target::supports_qxfer_libraries_svr4 ()
643 process_stratum_target::qxfer_libraries_svr4 (const char *annex
,
644 unsigned char *readbuf
,
645 unsigned const char *writebuf
,
646 CORE_ADDR offset
, int len
)
648 gdb_assert_not_reached ("target op qxfer_libraries_svr4 not supported");
652 process_stratum_target::supports_agent ()
658 process_stratum_target::enable_btrace (thread_info
*tp
,
659 const btrace_config
*conf
)
661 error (_("Target does not support branch tracing."));
665 process_stratum_target::disable_btrace (btrace_target_info
*tinfo
)
667 error (_("Target does not support branch tracing."));
671 process_stratum_target::read_btrace (btrace_target_info
*tinfo
,
673 enum btrace_read_type type
)
675 error (_("Target does not support branch tracing."));
679 process_stratum_target::read_btrace_conf (const btrace_target_info
*tinfo
,
682 error (_("Target does not support branch tracing."));
686 process_stratum_target::supports_range_stepping ()
692 process_stratum_target::supports_pid_to_exec_file ()
698 process_stratum_target::pid_to_exec_file (int pid
)
700 gdb_assert_not_reached ("target op pid_to_exec_file not supported");
704 process_stratum_target::supports_multifs ()
710 process_stratum_target::multifs_open (int pid
, const char *filename
,
711 int flags
, mode_t mode
)
713 return open (filename
, flags
, mode
);
717 process_stratum_target::multifs_unlink (int pid
, const char *filename
)
719 return unlink (filename
);
723 process_stratum_target::multifs_readlink (int pid
, const char *filename
,
724 char *buf
, size_t bufsiz
)
726 return readlink (filename
, buf
, bufsiz
);
730 process_stratum_target::breakpoint_kind_from_pc (CORE_ADDR
*pcptr
)
732 /* The default behavior is to use the size of a breakpoint as the
735 sw_breakpoint_from_kind (0, &size
);
740 process_stratum_target::breakpoint_kind_from_current_state (CORE_ADDR
*pcptr
)
742 return breakpoint_kind_from_pc (pcptr
);
746 process_stratum_target::thread_name (ptid_t thread
)
752 process_stratum_target::thread_handle (ptid_t ptid
, gdb_byte
**handle
,
759 process_stratum_target::thread_pending_parent (thread_info
*thread
)
765 process_stratum_target::thread_pending_child (thread_info
*thread
)
771 process_stratum_target::supports_software_single_step ()
777 process_stratum_target::supports_catch_syscall ()
783 process_stratum_target::get_ipa_tdesc_idx ()