testsuite, threads: fix LD_LIBRARY_PATH in 'tls-sepdebug.exp'
[binutils-gdb.git] / gdb / target.h
blobdcf68a6cca0bde5e0d016e702210386bcd1d5a8a
1 /* Interface between GDB and target environments, including files and processes
3 Copyright (C) 1990-2024 Free Software Foundation, Inc.
5 Contributed by Cygnus Support. Written by John Gilmore.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 /* This include file defines the interface between the main part of
23 the debugger, and the part which is target-specific, or specific to
24 the communications interface between us and the target.
26 A TARGET is an interface between the debugger and a particular
27 kind of file or process. Targets can be STACKED in STRATA,
28 so that more than one target can potentially respond to a request.
29 In particular, memory accesses will walk down the stack of targets
30 until they find a target that is interested in handling that particular
31 address. STRATA are artificial boundaries on the stack, within
32 which particular kinds of targets live. Strata exist so that
33 people don't get confused by pushing e.g. a process target and then
34 a file target, and wondering why they can't see the current values
35 of variables any more (the file target is handling them and they
36 never get to the process target). So when you push a file target,
37 it goes into the file stratum, which is always below the process
38 stratum.
40 Note that rather than allow an empty stack, we always have the
41 dummy target at the bottom stratum, so we can call the target
42 methods without checking them. */
44 #if !defined (TARGET_H)
45 #define TARGET_H
47 struct objfile;
48 struct ui_file;
49 struct mem_attrib;
50 struct target_ops;
51 struct bp_location;
52 struct bp_target_info;
53 struct regcache;
54 struct trace_state_variable;
55 struct trace_status;
56 struct uploaded_tsv;
57 struct uploaded_tp;
58 struct static_tracepoint_marker;
59 struct traceframe_info;
60 struct expression;
61 struct dcache_struct;
62 struct inferior;
64 /* Define const gdb_byte using one identifier, to make it easy for
65 make-target-delegates.py to parse. */
66 typedef const gdb_byte const_gdb_byte;
68 #include "infrun.h"
69 #include "breakpoint.h"
70 #include "gdbsupport/scoped_restore.h"
71 #include "gdbsupport/refcounted-object.h"
72 #include "target-section.h"
73 #include "target/target.h"
74 #include "target/resume.h"
75 #include "target/wait.h"
76 #include "target/waitstatus.h"
77 #include "bfd.h"
78 #include "symtab.h"
79 #include "memattr.h"
80 #include "gdbsupport/gdb_signals.h"
81 #include "btrace.h"
82 #include "record.h"
83 #include "command.h"
84 #include "disasm-flags.h"
85 #include "tracepoint.h"
86 #include "gdbsupport/fileio.h"
87 #include "gdbsupport/x86-xstate.h"
89 #include "gdbsupport/break-common.h"
91 enum strata
93 dummy_stratum, /* The lowest of the low */
94 file_stratum, /* Executable files, etc */
95 process_stratum, /* Executing processes or core dump files */
96 thread_stratum, /* Executing threads */
97 record_stratum, /* Support record debugging */
98 arch_stratum, /* Architecture overrides */
99 debug_stratum /* Target debug. Must be last. */
102 enum thread_control_capabilities
104 tc_none = 0, /* Default: can't control thread execution. */
105 tc_schedlock = 1, /* Can lock the thread scheduler. */
108 /* The structure below stores information about a system call.
109 It is basically used in the "catch syscall" command, and in
110 every function that gives information about a system call.
112 It's also good to mention that its fields represent everything
113 that we currently know about a syscall in GDB. */
114 struct syscall
116 /* The syscall number. */
117 int number;
119 /* The syscall name. */
120 const char *name;
123 /* Return a pretty printed form of TARGET_OPTIONS. */
124 extern std::string target_options_to_string (target_wait_flags target_options);
126 /* Possible types of events that the inferior handler will have to
127 deal with. */
128 enum inferior_event_type
130 /* Process a normal inferior event which will result in target_wait
131 being called. */
132 INF_REG_EVENT,
133 /* We are called to do stuff after the inferior stops. */
134 INF_EXEC_COMPLETE,
137 /* Target objects which can be transfered using target_read,
138 target_write, et cetera. */
140 enum target_object
142 /* AVR target specific transfer. See "avr-tdep.c" and "remote.c". */
143 TARGET_OBJECT_AVR,
144 /* Transfer up-to LEN bytes of memory starting at OFFSET. */
145 TARGET_OBJECT_MEMORY,
146 /* Memory, avoiding GDB's data cache and trusting the executable.
147 Target implementations of to_xfer_partial never need to handle
148 this object, and most callers should not use it. */
149 TARGET_OBJECT_RAW_MEMORY,
150 /* Memory known to be part of the target's stack. This is cached even
151 if it is not in a region marked as such, since it is known to be
152 "normal" RAM. */
153 TARGET_OBJECT_STACK_MEMORY,
154 /* Memory known to be part of the target code. This is cached even
155 if it is not in a region marked as such. */
156 TARGET_OBJECT_CODE_MEMORY,
157 /* Kernel Unwind Table. See "ia64-tdep.c". */
158 TARGET_OBJECT_UNWIND_TABLE,
159 /* Transfer auxilliary vector. */
160 TARGET_OBJECT_AUXV,
161 /* StackGhost cookie. See "sparc-tdep.c". */
162 TARGET_OBJECT_WCOOKIE,
163 /* Target memory map in XML format. */
164 TARGET_OBJECT_MEMORY_MAP,
165 /* Flash memory. This object can be used to write contents to
166 a previously erased flash memory. Using it without erasing
167 flash can have unexpected results. Addresses are physical
168 address on target, and not relative to flash start. */
169 TARGET_OBJECT_FLASH,
170 /* Available target-specific features, e.g. registers and coprocessors.
171 See "target-descriptions.c". ANNEX should never be empty. */
172 TARGET_OBJECT_AVAILABLE_FEATURES,
173 /* Currently loaded libraries, in XML format. */
174 TARGET_OBJECT_LIBRARIES,
175 /* Currently loaded libraries specific for SVR4 systems, in XML format. */
176 TARGET_OBJECT_LIBRARIES_SVR4,
177 /* Currently loaded libraries specific to AIX systems, in XML format. */
178 TARGET_OBJECT_LIBRARIES_AIX,
179 /* Get OS specific data. The ANNEX specifies the type (running
180 processes, etc.). The data being transfered is expected to follow
181 the DTD specified in features/osdata.dtd. */
182 TARGET_OBJECT_OSDATA,
183 /* Extra signal info. Usually the contents of `siginfo_t' on unix
184 platforms. */
185 TARGET_OBJECT_SIGNAL_INFO,
186 /* The list of threads that are being debugged. */
187 TARGET_OBJECT_THREADS,
188 /* Collected static trace data. */
189 TARGET_OBJECT_STATIC_TRACE_DATA,
190 /* Traceframe info, in XML format. */
191 TARGET_OBJECT_TRACEFRAME_INFO,
192 /* Load maps for FDPIC systems. */
193 TARGET_OBJECT_FDPIC,
194 /* Darwin dynamic linker info data. */
195 TARGET_OBJECT_DARWIN_DYLD_INFO,
196 /* OpenVMS Unwind Information Block. */
197 TARGET_OBJECT_OPENVMS_UIB,
198 /* Branch trace data, in XML format. */
199 TARGET_OBJECT_BTRACE,
200 /* Branch trace configuration, in XML format. */
201 TARGET_OBJECT_BTRACE_CONF,
202 /* The pathname of the executable file that was run to create
203 a specified process. ANNEX should be a string representation
204 of the process ID of the process in question, in hexadecimal
205 format. */
206 TARGET_OBJECT_EXEC_FILE,
207 /* FreeBSD virtual memory mappings. */
208 TARGET_OBJECT_FREEBSD_VMMAP,
209 /* FreeBSD process strings. */
210 TARGET_OBJECT_FREEBSD_PS_STRINGS,
211 /* Possible future objects: TARGET_OBJECT_FILE, ... */
214 /* Possible values returned by target_xfer_partial, etc. */
216 enum target_xfer_status
218 /* Some bytes are transferred. */
219 TARGET_XFER_OK = 1,
221 /* No further transfer is possible. */
222 TARGET_XFER_EOF = 0,
224 /* The piece of the object requested is unavailable. */
225 TARGET_XFER_UNAVAILABLE = 2,
227 /* Generic I/O error. Note that it's important that this is '-1',
228 as we still have target_xfer-related code returning hardcoded
229 '-1' on error. */
230 TARGET_XFER_E_IO = -1,
232 /* Keep list in sync with target_xfer_status_to_string. */
235 /* Return the string form of STATUS. */
237 extern const char *
238 target_xfer_status_to_string (enum target_xfer_status status);
240 typedef enum target_xfer_status
241 target_xfer_partial_ftype (struct target_ops *ops,
242 enum target_object object,
243 const char *annex,
244 gdb_byte *readbuf,
245 const gdb_byte *writebuf,
246 ULONGEST offset,
247 ULONGEST len,
248 ULONGEST *xfered_len);
250 enum target_xfer_status
251 raw_memory_xfer_partial (struct target_ops *ops, gdb_byte *readbuf,
252 const gdb_byte *writebuf, ULONGEST memaddr,
253 LONGEST len, ULONGEST *xfered_len);
255 /* Request that OPS transfer up to LEN addressable units of the target's
256 OBJECT. When reading from a memory object, the size of an addressable unit
257 is architecture dependent and can be found using
258 gdbarch_addressable_memory_unit_size. Otherwise, an addressable unit is 1
259 byte long. BUF should point to a buffer large enough to hold the read data,
260 taking into account the addressable unit size. The OFFSET, for a seekable
261 object, specifies the starting point. The ANNEX can be used to provide
262 additional data-specific information to the target.
264 Return the number of addressable units actually transferred, or a negative
265 error code (an 'enum target_xfer_error' value) if the transfer is not
266 supported or otherwise fails. Return of a positive value less than
267 LEN indicates that no further transfer is possible. Unlike the raw
268 to_xfer_partial interface, callers of these functions do not need
269 to retry partial transfers. */
271 extern LONGEST target_read (struct target_ops *ops,
272 enum target_object object,
273 const char *annex, gdb_byte *buf,
274 ULONGEST offset, LONGEST len);
276 struct memory_read_result
278 memory_read_result (ULONGEST begin_, ULONGEST end_,
279 gdb::unique_xmalloc_ptr<gdb_byte> &&data_)
280 : begin (begin_),
281 end (end_),
282 data (std::move (data_))
286 ~memory_read_result () = default;
288 memory_read_result (memory_read_result &&other) = default;
290 DISABLE_COPY_AND_ASSIGN (memory_read_result);
292 /* First address that was read. */
293 ULONGEST begin;
294 /* Past-the-end address. */
295 ULONGEST end;
296 /* The data. */
297 gdb::unique_xmalloc_ptr<gdb_byte> data;
300 extern std::vector<memory_read_result> read_memory_robust
301 (struct target_ops *ops, const ULONGEST offset, const LONGEST len);
303 /* Request that OPS transfer up to LEN addressable units from BUF to the
304 target's OBJECT. When writing to a memory object, the addressable unit
305 size is architecture dependent and can be found using
306 gdbarch_addressable_memory_unit_size. Otherwise, an addressable unit is 1
307 byte long. The OFFSET, for a seekable object, specifies the starting point.
308 The ANNEX can be used to provide additional data-specific information to
309 the target.
311 Return the number of addressable units actually transferred, or a negative
312 error code (an 'enum target_xfer_status' value) if the transfer is not
313 supported or otherwise fails. Return of a positive value less than
314 LEN indicates that no further transfer is possible. Unlike the raw
315 to_xfer_partial interface, callers of these functions do not need to
316 retry partial transfers. */
318 extern LONGEST target_write (struct target_ops *ops,
319 enum target_object object,
320 const char *annex, const gdb_byte *buf,
321 ULONGEST offset, LONGEST len);
323 /* Similar to target_write, except that it also calls PROGRESS with
324 the number of bytes written and the opaque BATON after every
325 successful partial write (and before the first write). This is
326 useful for progress reporting and user interaction while writing
327 data. To abort the transfer, the progress callback can throw an
328 exception. */
330 LONGEST target_write_with_progress (struct target_ops *ops,
331 enum target_object object,
332 const char *annex, const gdb_byte *buf,
333 ULONGEST offset, LONGEST len,
334 void (*progress) (ULONGEST, void *),
335 void *baton);
337 /* Wrapper to perform a full read of unknown size. OBJECT/ANNEX will be read
338 using OPS. The return value will be uninstantiated if the transfer fails or
339 is not supported.
341 This method should be used for objects sufficiently small to store
342 in a single xmalloc'd buffer, when no fixed bound on the object's
343 size is known in advance. Don't try to read TARGET_OBJECT_MEMORY
344 through this function. */
346 extern std::optional<gdb::byte_vector> target_read_alloc
347 (struct target_ops *ops, enum target_object object, const char *annex);
349 /* Read OBJECT/ANNEX using OPS. The result is a NUL-terminated character vector
350 (therefore usable as a NUL-terminated string). If an error occurs or the
351 transfer is unsupported, the return value will be uninstantiated. Empty
352 objects are returned as allocated but empty strings. Therefore, on success,
353 the returned vector is guaranteed to have at least one element. A warning is
354 issued if the result contains any embedded NUL bytes. */
356 extern std::optional<gdb::char_vector> target_read_stralloc
357 (struct target_ops *ops, enum target_object object, const char *annex);
359 /* See target_ops->to_xfer_partial. */
360 extern target_xfer_partial_ftype target_xfer_partial;
362 /* Wrappers to target read/write that perform memory transfers. They
363 throw an error if the memory transfer fails.
365 NOTE: cagney/2003-10-23: The naming schema is lifted from
366 "frame.h". The parameter order is lifted from get_frame_memory,
367 which in turn lifted it from read_memory. */
369 extern void get_target_memory (struct target_ops *ops, CORE_ADDR addr,
370 gdb_byte *buf, LONGEST len);
371 extern ULONGEST get_target_memory_unsigned (struct target_ops *ops,
372 CORE_ADDR addr, int len,
373 enum bfd_endian byte_order);
375 struct thread_info; /* fwd decl for parameter list below: */
377 /* The type of the callback to the to_async method. */
379 typedef void async_callback_ftype (enum inferior_event_type event_type,
380 void *context);
382 /* Normally target debug printing is purely type-based. However,
383 sometimes it is necessary to override the debug printing on a
384 per-argument basis. This macro can be used, attribute-style, to
385 name the target debug printing function for a particular method
386 argument. FUNC is the name of the function. The macro's
387 definition is empty because it is only used by the
388 make-target-delegates script. */
390 #define TARGET_DEBUG_PRINTER(FUNC)
392 /* These defines are used to mark target_ops methods. The script
393 make-target-delegates scans these and auto-generates the base
394 method implementations. There are four macros that can be used:
396 1. TARGET_DEFAULT_IGNORE. There is no argument. The base method
397 does nothing. This is only valid if the method return type is
398 'void'.
400 2. TARGET_DEFAULT_NORETURN. The argument is a function call, like
401 'tcomplain ()'. The base method simply makes this call, which is
402 assumed not to return.
404 3. TARGET_DEFAULT_RETURN. The argument is a C expression. The
405 base method returns this expression's value.
407 4. TARGET_DEFAULT_FUNC. The argument is the name of a function.
408 make-target-delegates does not generate a base method in this case,
409 but instead uses the argument function as the base method. */
411 #define TARGET_DEFAULT_IGNORE()
412 #define TARGET_DEFAULT_NORETURN(ARG)
413 #define TARGET_DEFAULT_RETURN(ARG)
414 #define TARGET_DEFAULT_FUNC(ARG)
416 /* Each target that can be activated with "target TARGET_NAME" passes
417 the address of one of these objects to add_target, which uses the
418 object's address as unique identifier, and registers the "target
419 TARGET_NAME" command using SHORTNAME as target name. */
421 struct target_info
423 /* Name of this target. */
424 const char *shortname;
426 /* Name for printing. */
427 const char *longname;
429 /* Documentation. Does not include trailing newline, and starts
430 with a one-line description (probably similar to longname). */
431 const char *doc;
434 /* A GDB target.
436 Each inferior has a stack of these. See overall description at the
437 top.
439 Most target methods traverse the current inferior's target stack;
440 you call the method on the top target (normally via one of the
441 target_foo wrapper free functions), and the implementation of said
442 method does its work and returns, or defers to the same method on
443 the target beneath on the current inferior's target stack. Thus,
444 the inferior you want to call the target method on must be made the
445 current inferior before calling a target method, so that the stack
446 traversal works correctly.
448 Methods that traverse the stack have a TARGET_DEFAULT_XXX marker in
449 their declaration below. See the macros' description above, where
450 they're defined. */
452 struct target_ops
453 : public refcounted_object
455 /* Return this target's stratum. */
456 virtual strata stratum () const = 0;
458 /* To the target under this one. */
459 target_ops *beneath () const;
461 /* Free resources associated with the target. Note that singleton
462 targets, like e.g., native targets, are global objects, not
463 heap allocated, and are thus only deleted on GDB exit. The
464 main teardown entry point is the "close" method, below. */
465 virtual ~target_ops () {}
467 /* Return a reference to this target's unique target_info
468 object. */
469 virtual const target_info &info () const = 0;
471 /* Name this target type. */
472 const char *shortname () const
473 { return info ().shortname; }
475 const char *longname () const
476 { return info ().longname; }
478 /* Close the target. This is where the target can handle
479 teardown. Heap-allocated targets should delete themselves
480 before returning. */
481 virtual void close ();
483 /* Attaches to a process on the target side. Arguments are as
484 passed to the `attach' command by the user. This routine can
485 be called when the target is not on the target-stack, if the
486 target_ops::can_run method returns 1; in that case, it must push
487 itself onto the stack. Upon exit, the target should be ready
488 for normal operations, and should be ready to deliver the
489 status of the process immediately (without waiting) to an
490 upcoming target_wait call. */
491 virtual bool can_attach ();
492 virtual void attach (const char *, int);
493 virtual void post_attach (int)
494 TARGET_DEFAULT_IGNORE ();
496 /* Detaches from the inferior. Note that on targets that support
497 async execution (i.e., targets where it is possible to detach
498 from programs with threads running), the target is responsible
499 for removing breakpoints from the program before the actual
500 detach, otherwise the program dies when it hits one. */
501 virtual void detach (inferior *, int)
502 TARGET_DEFAULT_IGNORE ();
504 virtual void disconnect (const char *, int)
505 TARGET_DEFAULT_NORETURN (tcomplain ());
506 virtual void resume (ptid_t,
507 int TARGET_DEBUG_PRINTER (target_debug_print_step),
508 enum gdb_signal)
509 TARGET_DEFAULT_NORETURN (noprocess ());
511 /* Ensure that all resumed threads are committed to the target.
513 See the description of
514 process_stratum_target::commit_resumed_state for more
515 details. */
516 virtual void commit_resumed ()
517 TARGET_DEFAULT_IGNORE ();
519 /* See target_wait's description. Note that implementations of
520 this method must not assume that inferior_ptid on entry is
521 pointing at the thread or inferior that ends up reporting an
522 event. The reported event could be for some other thread in
523 the current inferior or even for a different process of the
524 current target. inferior_ptid may also be null_ptid on
525 entry. */
526 virtual ptid_t wait (ptid_t, struct target_waitstatus *,
527 target_wait_flags options)
528 TARGET_DEFAULT_FUNC (default_target_wait);
529 virtual void fetch_registers (struct regcache *, int)
530 TARGET_DEFAULT_IGNORE ();
531 virtual void store_registers (struct regcache *, int)
532 TARGET_DEFAULT_NORETURN (noprocess ());
533 virtual void prepare_to_store (struct regcache *)
534 TARGET_DEFAULT_NORETURN (noprocess ());
536 virtual void files_info ()
537 TARGET_DEFAULT_IGNORE ();
538 virtual int insert_breakpoint (struct gdbarch *,
539 struct bp_target_info *)
540 TARGET_DEFAULT_NORETURN (noprocess ());
541 virtual int remove_breakpoint (struct gdbarch *,
542 struct bp_target_info *,
543 enum remove_bp_reason)
544 TARGET_DEFAULT_NORETURN (noprocess ());
546 /* Returns true if the target stopped because it executed a
547 software breakpoint. This is necessary for correct background
548 execution / non-stop mode operation, and for correct PC
549 adjustment on targets where the PC needs to be adjusted when a
550 software breakpoint triggers. In these modes, by the time GDB
551 processes a breakpoint event, the breakpoint may already be
552 done from the target, so GDB needs to be able to tell whether
553 it should ignore the event and whether it should adjust the PC.
554 See adjust_pc_after_break. */
555 virtual bool stopped_by_sw_breakpoint ()
556 TARGET_DEFAULT_RETURN (false);
557 /* Returns true if the above method is supported. */
558 virtual bool supports_stopped_by_sw_breakpoint ()
559 TARGET_DEFAULT_RETURN (false);
561 /* Returns true if the target stopped for a hardware breakpoint.
562 Likewise, if the target supports hardware breakpoints, this
563 method is necessary for correct background execution / non-stop
564 mode operation. Even though hardware breakpoints do not
565 require PC adjustment, GDB needs to be able to tell whether the
566 hardware breakpoint event is a delayed event for a breakpoint
567 that is already gone and should thus be ignored. */
568 virtual bool stopped_by_hw_breakpoint ()
569 TARGET_DEFAULT_RETURN (false);
570 /* Returns true if the above method is supported. */
571 virtual bool supports_stopped_by_hw_breakpoint ()
572 TARGET_DEFAULT_RETURN (false);
574 virtual int can_use_hw_breakpoint (enum bptype, int, int)
575 TARGET_DEFAULT_RETURN (0);
576 virtual int ranged_break_num_registers ()
577 TARGET_DEFAULT_RETURN (-1);
578 virtual int insert_hw_breakpoint (struct gdbarch *,
579 struct bp_target_info *)
580 TARGET_DEFAULT_RETURN (-1);
581 virtual int remove_hw_breakpoint (struct gdbarch *,
582 struct bp_target_info *)
583 TARGET_DEFAULT_RETURN (-1);
585 /* Documentation of what the two routines below are expected to do is
586 provided with the corresponding target_* macros. */
587 virtual int remove_watchpoint (CORE_ADDR, int,
588 enum target_hw_bp_type, struct expression *)
589 TARGET_DEFAULT_RETURN (-1);
590 virtual int insert_watchpoint (CORE_ADDR, int,
591 enum target_hw_bp_type, struct expression *)
592 TARGET_DEFAULT_RETURN (-1);
594 virtual int insert_mask_watchpoint (CORE_ADDR, CORE_ADDR,
595 enum target_hw_bp_type)
596 TARGET_DEFAULT_RETURN (1);
597 virtual int remove_mask_watchpoint (CORE_ADDR, CORE_ADDR,
598 enum target_hw_bp_type)
599 TARGET_DEFAULT_RETURN (1);
600 virtual bool stopped_by_watchpoint ()
601 TARGET_DEFAULT_RETURN (false);
602 virtual bool have_steppable_watchpoint ()
603 TARGET_DEFAULT_RETURN (false);
604 virtual bool stopped_data_address (CORE_ADDR *)
605 TARGET_DEFAULT_RETURN (false);
606 virtual bool watchpoint_addr_within_range (CORE_ADDR, CORE_ADDR, int)
607 TARGET_DEFAULT_FUNC (default_watchpoint_addr_within_range);
609 /* Documentation of this routine is provided with the corresponding
610 target_* macro. */
611 virtual int region_ok_for_hw_watchpoint (CORE_ADDR, int)
612 TARGET_DEFAULT_FUNC (default_region_ok_for_hw_watchpoint);
614 virtual bool can_accel_watchpoint_condition (CORE_ADDR, int, int,
615 struct expression *)
616 TARGET_DEFAULT_RETURN (false);
617 virtual int masked_watch_num_registers (CORE_ADDR, CORE_ADDR)
618 TARGET_DEFAULT_RETURN (-1);
620 /* Return 1 for sure target can do single step. Return -1 for
621 unknown. Return 0 for target can't do. */
622 virtual int can_do_single_step ()
623 TARGET_DEFAULT_RETURN (-1);
625 virtual bool supports_terminal_ours ()
626 TARGET_DEFAULT_RETURN (false);
627 virtual void terminal_init ()
628 TARGET_DEFAULT_IGNORE ();
629 virtual void terminal_inferior ()
630 TARGET_DEFAULT_IGNORE ();
631 virtual void terminal_save_inferior ()
632 TARGET_DEFAULT_IGNORE ();
633 virtual void terminal_ours_for_output ()
634 TARGET_DEFAULT_IGNORE ();
635 virtual void terminal_ours ()
636 TARGET_DEFAULT_IGNORE ();
637 virtual void terminal_info (const char *, int)
638 TARGET_DEFAULT_FUNC (default_terminal_info);
639 virtual void kill ()
640 TARGET_DEFAULT_NORETURN (noprocess ());
641 virtual void load (const char *, int)
642 TARGET_DEFAULT_NORETURN (tcomplain ());
643 /* Start an inferior process and set inferior_ptid to its pid.
644 EXEC_FILE is the file to run.
645 ALLARGS is a string containing the arguments to the program.
646 ENV is the environment vector to pass. Errors reported with error().
647 On VxWorks and various standalone systems, we ignore exec_file. */
648 virtual bool can_create_inferior ();
649 virtual void create_inferior (const char *, const std::string &,
650 char **, int);
651 virtual int insert_fork_catchpoint (int)
652 TARGET_DEFAULT_RETURN (1);
653 virtual int remove_fork_catchpoint (int)
654 TARGET_DEFAULT_RETURN (1);
655 virtual int insert_vfork_catchpoint (int)
656 TARGET_DEFAULT_RETURN (1);
657 virtual int remove_vfork_catchpoint (int)
658 TARGET_DEFAULT_RETURN (1);
659 virtual void follow_fork (inferior *, ptid_t, target_waitkind, bool, bool)
660 TARGET_DEFAULT_FUNC (default_follow_fork);
662 /* Add CHILD_PTID to the thread list, after handling a
663 TARGET_WAITKIND_THREAD_CLONE event for the clone parent. The
664 parent is inferior_ptid. */
665 virtual void follow_clone (ptid_t child_ptid)
666 TARGET_DEFAULT_FUNC (default_follow_clone);
668 virtual int insert_exec_catchpoint (int)
669 TARGET_DEFAULT_RETURN (1);
670 virtual int remove_exec_catchpoint (int)
671 TARGET_DEFAULT_RETURN (1);
672 virtual void follow_exec (inferior *, ptid_t, const char *)
673 TARGET_DEFAULT_IGNORE ();
674 virtual int set_syscall_catchpoint (int, bool, int,
675 gdb::array_view<const int>)
676 TARGET_DEFAULT_RETURN (1);
677 virtual void mourn_inferior ()
678 TARGET_DEFAULT_FUNC (default_mourn_inferior);
680 /* Note that can_run is special and can be invoked on an unpushed
681 target. Targets defining this method must also define
682 to_can_async_p and to_supports_non_stop. */
683 virtual bool can_run ();
685 /* Documentation of this routine is provided with the corresponding
686 target_* macro. */
687 virtual void pass_signals (gdb::array_view<const unsigned char> TARGET_DEBUG_PRINTER (target_debug_print_signals))
688 TARGET_DEFAULT_IGNORE ();
690 /* Documentation of this routine is provided with the
691 corresponding target_* function. */
692 virtual void program_signals (gdb::array_view<const unsigned char> TARGET_DEBUG_PRINTER (target_debug_print_signals))
693 TARGET_DEFAULT_IGNORE ();
695 virtual bool thread_alive (ptid_t ptid)
696 TARGET_DEFAULT_RETURN (false);
697 virtual void update_thread_list ()
698 TARGET_DEFAULT_IGNORE ();
699 virtual std::string pid_to_str (ptid_t)
700 TARGET_DEFAULT_FUNC (default_pid_to_str);
701 virtual const char *extra_thread_info (thread_info *)
702 TARGET_DEFAULT_RETURN (NULL);
703 virtual const char *thread_name (thread_info *)
704 TARGET_DEFAULT_RETURN (NULL);
705 virtual thread_info *thread_handle_to_thread_info (const gdb_byte *,
706 int,
707 inferior *inf)
708 TARGET_DEFAULT_RETURN (NULL);
709 /* See target_thread_info_to_thread_handle. */
710 virtual gdb::array_view<const_gdb_byte> thread_info_to_thread_handle (struct thread_info *)
711 TARGET_DEFAULT_RETURN (gdb::array_view<const gdb_byte> ());
712 virtual void stop (ptid_t)
713 TARGET_DEFAULT_IGNORE ();
714 virtual void interrupt ()
715 TARGET_DEFAULT_IGNORE ();
716 virtual void pass_ctrlc ()
717 TARGET_DEFAULT_FUNC (default_target_pass_ctrlc);
718 virtual void rcmd (const char *command, struct ui_file *output)
719 TARGET_DEFAULT_FUNC (default_rcmd);
720 virtual const char *pid_to_exec_file (int pid)
721 TARGET_DEFAULT_RETURN (NULL);
722 virtual void log_command (const char *)
723 TARGET_DEFAULT_IGNORE ();
724 virtual const std::vector<target_section> *get_section_table ()
725 TARGET_DEFAULT_RETURN (default_get_section_table ());
727 /* Provide default values for all "must have" methods. */
728 virtual bool has_all_memory () { return false; }
729 virtual bool has_memory () { return false; }
730 virtual bool has_stack () { return false; }
731 virtual bool has_registers () { return false; }
732 virtual bool has_execution (inferior *inf) { return false; }
734 /* Control thread execution. */
735 virtual thread_control_capabilities get_thread_control_capabilities ()
736 TARGET_DEFAULT_RETURN (tc_none);
737 virtual bool attach_no_wait ()
738 TARGET_DEFAULT_RETURN (0);
739 /* This method must be implemented in some situations. See the
740 comment on 'can_run'. */
741 virtual bool can_async_p ()
742 TARGET_DEFAULT_RETURN (false);
743 virtual bool is_async_p ()
744 TARGET_DEFAULT_RETURN (false);
745 virtual void async (bool)
746 TARGET_DEFAULT_NORETURN (tcomplain ());
747 virtual int async_wait_fd ()
748 TARGET_DEFAULT_NORETURN (noprocess ());
749 /* Return true if the target has pending events to report to the
750 core. If true, then GDB avoids resuming the target until all
751 pending events are consumed, so that multiple resumptions can
752 be coalesced as an optimization. Most targets can't tell
753 whether they have pending events without calling target_wait,
754 so we default to returning false. The only downside is that a
755 potential optimization is missed. */
756 virtual bool has_pending_events ()
757 TARGET_DEFAULT_RETURN (false);
758 virtual void thread_events (bool)
759 TARGET_DEFAULT_IGNORE ();
760 /* Returns true if the target supports setting thread options
761 OPTIONS, false otherwise. */
762 virtual bool supports_set_thread_options (gdb_thread_options options)
763 TARGET_DEFAULT_RETURN (false);
764 /* This method must be implemented in some situations. See the
765 comment on 'can_run'. */
766 virtual bool supports_non_stop ()
767 TARGET_DEFAULT_RETURN (false);
768 /* Return true if the target operates in non-stop mode even with
769 "set non-stop off". */
770 virtual bool always_non_stop_p ()
771 TARGET_DEFAULT_RETURN (false);
772 /* find_memory_regions support method for gcore */
773 virtual int find_memory_regions (find_memory_region_ftype func, void *data)
774 TARGET_DEFAULT_FUNC (dummy_find_memory_regions);
775 /* make_corefile_notes support method for gcore */
776 virtual gdb::unique_xmalloc_ptr<char> make_corefile_notes (bfd *, int *)
777 TARGET_DEFAULT_FUNC (dummy_make_corefile_notes);
778 /* get_bookmark support method for bookmarks */
779 virtual gdb_byte *get_bookmark (const char *, int)
780 TARGET_DEFAULT_NORETURN (tcomplain ());
781 /* goto_bookmark support method for bookmarks */
782 virtual void goto_bookmark (const gdb_byte *, int)
783 TARGET_DEFAULT_NORETURN (tcomplain ());
784 /* Return the thread-local address at OFFSET in the
785 thread-local storage for the thread PTID and the shared library
786 or executable file given by LOAD_MODULE_ADDR. If that block of
787 thread-local storage hasn't been allocated yet, this function
788 may throw an error. LOAD_MODULE_ADDR may be zero for statically
789 linked multithreaded inferiors. */
790 virtual CORE_ADDR get_thread_local_address (ptid_t ptid,
791 CORE_ADDR load_module_addr,
792 CORE_ADDR offset)
793 TARGET_DEFAULT_NORETURN (generic_tls_error ());
795 /* Request that OPS transfer up to LEN addressable units of the target's
796 OBJECT. When reading from a memory object, the size of an addressable
797 unit is architecture dependent and can be found using
798 gdbarch_addressable_memory_unit_size. Otherwise, an addressable unit is
799 1 byte long. The OFFSET, for a seekable object, specifies the
800 starting point. The ANNEX can be used to provide additional
801 data-specific information to the target.
803 When accessing memory, inferior_ptid indicates which process's
804 memory is to be accessed. This is usually the same process as
805 the current inferior, however it may also be a process that is
806 a fork child of the current inferior, at a moment that the
807 child does not exist in GDB's inferior lists. This happens
808 when we remove software breakpoints from the address space of a
809 fork child process that we're not going to stay attached to.
810 Because the fork child is a clone of the fork parent, we can
811 use the fork parent inferior's stack for target method
812 delegation.
814 Return the transferred status, error or OK (an
815 'enum target_xfer_status' value). Save the number of addressable units
816 actually transferred in *XFERED_LEN if transfer is successful
817 (TARGET_XFER_OK) or the number unavailable units if the requested
818 data is unavailable (TARGET_XFER_UNAVAILABLE). *XFERED_LEN
819 smaller than LEN does not indicate the end of the object, only
820 the end of the transfer; higher level code should continue
821 transferring if desired. This is handled in target.c.
823 The interface does not support a "retry" mechanism. Instead it
824 assumes that at least one addressable unit will be transfered on each
825 successful call.
827 NOTE: cagney/2003-10-17: The current interface can lead to
828 fragmented transfers. Lower target levels should not implement
829 hacks, such as enlarging the transfer, in an attempt to
830 compensate for this. Instead, the target stack should be
831 extended so that it implements supply/collect methods and a
832 look-aside object cache. With that available, the lowest
833 target can safely and freely "push" data up the stack.
835 See target_read and target_write for more information. One,
836 and only one, of readbuf or writebuf must be non-NULL. */
838 virtual enum target_xfer_status xfer_partial (enum target_object object,
839 const char *annex,
840 gdb_byte *readbuf,
841 const gdb_byte *writebuf,
842 ULONGEST offset, ULONGEST len,
843 ULONGEST *xfered_len)
844 TARGET_DEFAULT_RETURN (TARGET_XFER_E_IO);
846 /* Return the limit on the size of any single memory transfer
847 for the target. */
849 virtual ULONGEST get_memory_xfer_limit ()
850 TARGET_DEFAULT_RETURN (ULONGEST_MAX);
852 /* Returns the memory map for the target. A return value of NULL
853 means that no memory map is available. If a memory address
854 does not fall within any returned regions, it's assumed to be
855 RAM. The returned memory regions should not overlap.
857 The order of regions does not matter; target_memory_map will
858 sort regions by starting address. For that reason, this
859 function should not be called directly except via
860 target_memory_map.
862 This method should not cache data; if the memory map could
863 change unexpectedly, it should be invalidated, and higher
864 layers will re-fetch it. */
865 virtual std::vector<mem_region> memory_map ()
866 TARGET_DEFAULT_RETURN (std::vector<mem_region> ());
868 /* Erases the region of flash memory starting at ADDRESS, of
869 length LENGTH.
871 Precondition: both ADDRESS and ADDRESS+LENGTH should be aligned
872 on flash block boundaries, as reported by 'to_memory_map'. */
873 virtual void flash_erase (ULONGEST address, LONGEST length)
874 TARGET_DEFAULT_NORETURN (tcomplain ());
876 /* Finishes a flash memory write sequence. After this operation
877 all flash memory should be available for writing and the result
878 of reading from areas written by 'to_flash_write' should be
879 equal to what was written. */
880 virtual void flash_done ()
881 TARGET_DEFAULT_NORETURN (tcomplain ());
883 /* Describe the architecture-specific features of the current
884 inferior.
886 Returns the description found, or nullptr if no description was
887 available.
889 If some target features differ between threads, the description
890 returned by read_description (and the resulting gdbarch) won't
891 accurately describe all threads. In this case, the
892 thread_architecture method can be used to obtain gdbarches that
893 accurately describe each thread. */
894 virtual const struct target_desc *read_description ()
895 TARGET_DEFAULT_RETURN (NULL);
897 /* Build the PTID of the thread on which a given task is running,
898 based on LWP and THREAD. These values are extracted from the
899 task Private_Data section of the Ada Task Control Block, and
900 their interpretation depends on the target. */
901 virtual ptid_t get_ada_task_ptid (long lwp, ULONGEST thread)
902 TARGET_DEFAULT_FUNC (default_get_ada_task_ptid);
904 /* Read one auxv entry from *READPTR, not reading locations >= ENDPTR.
905 Return 0 if *READPTR is already at the end of the buffer.
906 Return -1 if there is insufficient buffer for a whole entry.
907 Return 1 if an entry was read into *TYPEP and *VALP. */
908 virtual int auxv_parse (const gdb_byte **readptr,
909 const gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
910 TARGET_DEFAULT_FUNC (default_auxv_parse);
912 /* Search SEARCH_SPACE_LEN bytes beginning at START_ADDR for the
913 sequence of bytes in PATTERN with length PATTERN_LEN.
915 The result is 1 if found, 0 if not found, and -1 if there was an error
916 requiring halting of the search (e.g. memory read error).
917 If the pattern is found the address is recorded in FOUND_ADDRP. */
918 virtual int search_memory (CORE_ADDR start_addr, ULONGEST search_space_len,
919 const gdb_byte *pattern, ULONGEST pattern_len,
920 CORE_ADDR *found_addrp)
921 TARGET_DEFAULT_FUNC (default_search_memory);
923 /* Can target execute in reverse? */
924 virtual bool can_execute_reverse ()
925 TARGET_DEFAULT_RETURN (false);
927 /* The direction the target is currently executing. Must be
928 implemented on targets that support reverse execution and async
929 mode. The default simply returns forward execution. */
930 virtual enum exec_direction_kind execution_direction ()
931 TARGET_DEFAULT_FUNC (default_execution_direction);
933 /* Does this target support debugging multiple processes
934 simultaneously? */
935 virtual bool supports_multi_process ()
936 TARGET_DEFAULT_RETURN (false);
938 /* Does this target support enabling and disabling tracepoints while a trace
939 experiment is running? */
940 virtual bool supports_enable_disable_tracepoint ()
941 TARGET_DEFAULT_RETURN (false);
943 /* Does this target support disabling address space randomization? */
944 virtual bool supports_disable_randomization ()
945 TARGET_DEFAULT_FUNC (find_default_supports_disable_randomization);
947 /* Does this target support the tracenz bytecode for string collection? */
948 virtual bool supports_string_tracing ()
949 TARGET_DEFAULT_RETURN (false);
951 /* Does this target support evaluation of breakpoint conditions on its
952 end? */
953 virtual bool supports_evaluation_of_breakpoint_conditions ()
954 TARGET_DEFAULT_RETURN (false);
956 /* Does this target support native dumpcore API? */
957 virtual bool supports_dumpcore ()
958 TARGET_DEFAULT_RETURN (false);
960 /* Generate the core file with native target API. */
961 virtual void dumpcore (const char *filename)
962 TARGET_DEFAULT_IGNORE ();
964 /* Does this target support evaluation of breakpoint commands on its
965 end? */
966 virtual bool can_run_breakpoint_commands ()
967 TARGET_DEFAULT_RETURN (false);
969 /* Determine current architecture of thread PTID.
971 The target is supposed to determine the architecture of the code where
972 the target is currently stopped at. The architecture information is
973 used to perform decr_pc_after_break adjustment, and also to determine
974 the frame architecture of the innermost frame. ptrace operations need to
975 operate according to the current inferior's gdbarch. */
976 virtual struct gdbarch *thread_architecture (ptid_t)
977 TARGET_DEFAULT_RETURN (NULL);
979 /* Target file operations. */
981 /* Return true if the filesystem seen by the current inferior
982 is the local filesystem, false otherwise. */
983 virtual bool filesystem_is_local ()
984 TARGET_DEFAULT_RETURN (true);
986 /* Open FILENAME on the target, in the filesystem as seen by INF,
987 using FLAGS and MODE. If INF is NULL, use the filesystem seen
988 by the debugger (GDB or, for remote targets, the remote stub).
989 If WARN_IF_SLOW is nonzero, print a warning message if the file
990 is being accessed over a link that may be slow. Return a
991 target file descriptor, or -1 if an error occurs (and set
992 *TARGET_ERRNO). */
993 virtual int fileio_open (struct inferior *inf, const char *filename,
994 int flags, int mode, int warn_if_slow,
995 fileio_error *target_errno);
997 /* Write up to LEN bytes from WRITE_BUF to FD on the target.
998 Return the number of bytes written, or -1 if an error occurs
999 (and set *TARGET_ERRNO). */
1000 virtual int fileio_pwrite (int fd, const gdb_byte *write_buf, int len,
1001 ULONGEST offset, fileio_error *target_errno);
1003 /* Read up to LEN bytes FD on the target into READ_BUF.
1004 Return the number of bytes read, or -1 if an error occurs
1005 (and set *TARGET_ERRNO). */
1006 virtual int fileio_pread (int fd, gdb_byte *read_buf, int len,
1007 ULONGEST offset, fileio_error *target_errno);
1009 /* Get information about the file opened as FD and put it in
1010 SB. Return 0 on success, or -1 if an error occurs (and set
1011 *TARGET_ERRNO). */
1012 virtual int fileio_fstat (int fd, struct stat *sb, fileio_error *target_errno);
1014 /* Get information about the file FILENAME and put it in SB. Look for
1015 FILENAME in the filesystem as seen by INF. If INF is NULL, use the
1016 filesystem seen by the debugger (GDB or, for remote targets, the
1017 remote stub). Return 0 on success, or -1 if an error occurs (and
1018 set *TARGET_ERRNO). */
1019 virtual int fileio_stat (struct inferior *inf, const char *filename,
1020 struct stat *sb, fileio_error *target_errno);
1022 /* Close FD on the target. Return 0, or -1 if an error occurs
1023 (and set *TARGET_ERRNO). */
1024 virtual int fileio_close (int fd, fileio_error *target_errno);
1026 /* Unlink FILENAME on the target, in the filesystem as seen by
1027 INF. If INF is NULL, use the filesystem seen by the debugger
1028 (GDB or, for remote targets, the remote stub). Return 0, or
1029 -1 if an error occurs (and set *TARGET_ERRNO). */
1030 virtual int fileio_unlink (struct inferior *inf,
1031 const char *filename,
1032 fileio_error *target_errno);
1034 /* Read value of symbolic link FILENAME on the target, in the
1035 filesystem as seen by INF. If INF is NULL, use the filesystem
1036 seen by the debugger (GDB or, for remote targets, the remote
1037 stub). Return a string, or an empty optional if an error
1038 occurs (and set *TARGET_ERRNO). */
1039 virtual std::optional<std::string> fileio_readlink (struct inferior *inf,
1040 const char *filename,
1041 fileio_error *target_errno);
1043 /* Implement the "info proc" command. Returns true if the target
1044 actually implemented the command, false otherwise. */
1045 virtual bool info_proc (const char *, enum info_proc_what);
1047 /* Tracepoint-related operations. */
1049 /* Prepare the target for a tracing run. */
1050 virtual void trace_init ()
1051 TARGET_DEFAULT_NORETURN (tcomplain ());
1053 /* Send full details of a tracepoint location to the target. */
1054 virtual void download_tracepoint (struct bp_location *location)
1055 TARGET_DEFAULT_NORETURN (tcomplain ());
1057 /* Is the target able to download tracepoint locations in current
1058 state? */
1059 virtual bool can_download_tracepoint ()
1060 TARGET_DEFAULT_RETURN (false);
1062 /* Send full details of a trace state variable to the target. */
1063 virtual void download_trace_state_variable (const trace_state_variable &tsv)
1064 TARGET_DEFAULT_NORETURN (tcomplain ());
1066 /* Enable a tracepoint on the target. */
1067 virtual void enable_tracepoint (struct bp_location *location)
1068 TARGET_DEFAULT_NORETURN (tcomplain ());
1070 /* Disable a tracepoint on the target. */
1071 virtual void disable_tracepoint (struct bp_location *location)
1072 TARGET_DEFAULT_NORETURN (tcomplain ());
1074 /* Inform the target info of memory regions that are readonly
1075 (such as text sections), and so it should return data from
1076 those rather than look in the trace buffer. */
1077 virtual void trace_set_readonly_regions ()
1078 TARGET_DEFAULT_NORETURN (tcomplain ());
1080 /* Start a trace run. */
1081 virtual void trace_start ()
1082 TARGET_DEFAULT_NORETURN (tcomplain ());
1084 /* Get the current status of a tracing run. */
1085 virtual int get_trace_status (struct trace_status *ts)
1086 TARGET_DEFAULT_RETURN (-1);
1088 virtual void get_tracepoint_status (tracepoint *tp,
1089 struct uploaded_tp *utp)
1090 TARGET_DEFAULT_NORETURN (tcomplain ());
1092 /* Stop a trace run. */
1093 virtual void trace_stop ()
1094 TARGET_DEFAULT_NORETURN (tcomplain ());
1096 /* Ask the target to find a trace frame of the given type TYPE,
1097 using NUM, ADDR1, and ADDR2 as search parameters. Returns the
1098 number of the trace frame, and also the tracepoint number at
1099 TPP. If no trace frame matches, return -1. May throw if the
1100 operation fails. */
1101 virtual int trace_find (enum trace_find_type type, int num,
1102 CORE_ADDR addr1, CORE_ADDR addr2, int *tpp)
1103 TARGET_DEFAULT_RETURN (-1);
1105 /* Get the value of the trace state variable number TSV, returning
1106 1 if the value is known and writing the value itself into the
1107 location pointed to by VAL, else returning 0. */
1108 virtual bool get_trace_state_variable_value (int tsv, LONGEST *val)
1109 TARGET_DEFAULT_RETURN (false);
1111 virtual int save_trace_data (const char *filename)
1112 TARGET_DEFAULT_NORETURN (tcomplain ());
1114 virtual int upload_tracepoints (struct uploaded_tp **utpp)
1115 TARGET_DEFAULT_RETURN (0);
1117 virtual int upload_trace_state_variables (struct uploaded_tsv **utsvp)
1118 TARGET_DEFAULT_RETURN (0);
1120 virtual LONGEST get_raw_trace_data (gdb_byte *buf,
1121 ULONGEST offset, LONGEST len)
1122 TARGET_DEFAULT_NORETURN (tcomplain ());
1124 /* Get the minimum length of instruction on which a fast tracepoint
1125 may be set on the target. If this operation is unsupported,
1126 return -1. If for some reason the minimum length cannot be
1127 determined, return 0. */
1128 virtual int get_min_fast_tracepoint_insn_len ()
1129 TARGET_DEFAULT_RETURN (-1);
1131 /* Set the target's tracing behavior in response to unexpected
1132 disconnection - set VAL to 1 to keep tracing, 0 to stop. */
1133 virtual void set_disconnected_tracing (int val)
1134 TARGET_DEFAULT_IGNORE ();
1135 virtual void set_circular_trace_buffer (int val)
1136 TARGET_DEFAULT_IGNORE ();
1137 /* Set the size of trace buffer in the target. */
1138 virtual void set_trace_buffer_size (LONGEST val)
1139 TARGET_DEFAULT_IGNORE ();
1141 /* Add/change textual notes about the trace run, returning true if
1142 successful, false otherwise. */
1143 virtual bool set_trace_notes (const char *user, const char *notes,
1144 const char *stopnotes)
1145 TARGET_DEFAULT_RETURN (false);
1147 /* Return the processor core that thread PTID was last seen on.
1148 This information is updated only when:
1149 - update_thread_list is called
1150 - thread stops
1151 If the core cannot be determined -- either for the specified
1152 thread, or right now, or in this debug session, or for this
1153 target -- return -1. */
1154 virtual int core_of_thread (ptid_t ptid)
1155 TARGET_DEFAULT_RETURN (-1);
1157 /* Verify that the memory in the [MEMADDR, MEMADDR+SIZE) range
1158 matches the contents of [DATA,DATA+SIZE). Returns 1 if there's
1159 a match, 0 if there's a mismatch, and -1 if an error is
1160 encountered while reading memory. */
1161 virtual int verify_memory (const gdb_byte *data,
1162 CORE_ADDR memaddr, ULONGEST size)
1163 TARGET_DEFAULT_FUNC (default_verify_memory);
1165 /* Return the address of the start of the Thread Information Block
1166 a Windows OS specific feature. */
1167 virtual bool get_tib_address (ptid_t ptid, CORE_ADDR *addr)
1168 TARGET_DEFAULT_NORETURN (tcomplain ());
1170 /* Send the new settings of write permission variables. */
1171 virtual void set_permissions ()
1172 TARGET_DEFAULT_IGNORE ();
1174 /* Look for a static tracepoint marker at ADDR, and fill in MARKER
1175 with its details. Return true on success, false on failure. */
1176 virtual bool static_tracepoint_marker_at (CORE_ADDR,
1177 static_tracepoint_marker *marker)
1178 TARGET_DEFAULT_RETURN (false);
1180 /* Return a vector of all tracepoints markers string id ID, or all
1181 markers if ID is NULL. */
1182 virtual std::vector<static_tracepoint_marker>
1183 static_tracepoint_markers_by_strid (const char *id)
1184 TARGET_DEFAULT_NORETURN (tcomplain ());
1186 /* Return a traceframe info object describing the current
1187 traceframe's contents. This method should not cache data;
1188 higher layers take care of caching, invalidating, and
1189 re-fetching when necessary. */
1190 virtual traceframe_info_up traceframe_info ()
1191 TARGET_DEFAULT_NORETURN (tcomplain ());
1193 /* Ask the target to use or not to use agent according to USE.
1194 Return true if successful, false otherwise. */
1195 virtual bool use_agent (bool use)
1196 TARGET_DEFAULT_NORETURN (tcomplain ());
1198 /* Is the target able to use agent in current state? */
1199 virtual bool can_use_agent ()
1200 TARGET_DEFAULT_RETURN (false);
1202 /* Enable branch tracing for TP using CONF configuration.
1203 Return a branch trace target information struct for reading and for
1204 disabling branch trace. */
1205 virtual struct btrace_target_info *enable_btrace (thread_info *tp,
1206 const struct btrace_config *conf)
1207 TARGET_DEFAULT_NORETURN (tcomplain ());
1209 /* Disable branch tracing and deallocate TINFO. */
1210 virtual void disable_btrace (struct btrace_target_info *tinfo)
1211 TARGET_DEFAULT_NORETURN (tcomplain ());
1213 /* Disable branch tracing and deallocate TINFO. This function is similar
1214 to to_disable_btrace, except that it is called during teardown and is
1215 only allowed to perform actions that are safe. A counter-example would
1216 be attempting to talk to a remote target. */
1217 virtual void teardown_btrace (struct btrace_target_info *tinfo)
1218 TARGET_DEFAULT_NORETURN (tcomplain ());
1220 /* Read branch trace data for the thread indicated by BTINFO into DATA.
1221 DATA is cleared before new trace is added. */
1222 virtual enum btrace_error read_btrace (struct btrace_data *data,
1223 struct btrace_target_info *btinfo,
1224 enum btrace_read_type type)
1225 TARGET_DEFAULT_NORETURN (tcomplain ());
1227 /* Get the branch trace configuration. */
1228 virtual const struct btrace_config *btrace_conf (const struct btrace_target_info *)
1229 TARGET_DEFAULT_RETURN (NULL);
1231 /* Current recording method. */
1232 virtual enum record_method record_method (ptid_t ptid)
1233 TARGET_DEFAULT_RETURN (RECORD_METHOD_NONE);
1235 /* Stop trace recording. */
1236 virtual void stop_recording ()
1237 TARGET_DEFAULT_IGNORE ();
1239 /* Print information about the recording. */
1240 virtual void info_record ()
1241 TARGET_DEFAULT_IGNORE ();
1243 /* Save the recorded execution trace into a file. */
1244 virtual void save_record (const char *filename)
1245 TARGET_DEFAULT_NORETURN (tcomplain ());
1247 /* Delete the recorded execution trace from the current position
1248 onwards. */
1249 virtual bool supports_delete_record ()
1250 TARGET_DEFAULT_RETURN (false);
1251 virtual void delete_record ()
1252 TARGET_DEFAULT_NORETURN (tcomplain ());
1254 /* Query if the record target is currently replaying PTID. */
1255 virtual bool record_is_replaying (ptid_t ptid)
1256 TARGET_DEFAULT_RETURN (false);
1258 /* Query if the record target will replay PTID if it were resumed in
1259 execution direction DIR. */
1260 virtual bool record_will_replay (ptid_t ptid, int dir)
1261 TARGET_DEFAULT_RETURN (false);
1263 /* Stop replaying. */
1264 virtual void record_stop_replaying ()
1265 TARGET_DEFAULT_IGNORE ();
1267 /* Go to the begin of the execution trace. */
1268 virtual void goto_record_begin ()
1269 TARGET_DEFAULT_NORETURN (tcomplain ());
1271 /* Go to the end of the execution trace. */
1272 virtual void goto_record_end ()
1273 TARGET_DEFAULT_NORETURN (tcomplain ());
1275 /* Go to a specific location in the recorded execution trace. */
1276 virtual void goto_record (ULONGEST insn)
1277 TARGET_DEFAULT_NORETURN (tcomplain ());
1279 /* Disassemble SIZE instructions in the recorded execution trace from
1280 the current position.
1281 If SIZE < 0, disassemble abs (SIZE) preceding instructions; otherwise,
1282 disassemble SIZE succeeding instructions. */
1283 virtual void insn_history (int size, gdb_disassembly_flags flags)
1284 TARGET_DEFAULT_NORETURN (tcomplain ());
1286 /* Disassemble SIZE instructions in the recorded execution trace around
1287 FROM.
1288 If SIZE < 0, disassemble abs (SIZE) instructions before FROM; otherwise,
1289 disassemble SIZE instructions after FROM. */
1290 virtual void insn_history_from (ULONGEST from, int size,
1291 gdb_disassembly_flags flags)
1292 TARGET_DEFAULT_NORETURN (tcomplain ());
1294 /* Disassemble a section of the recorded execution trace from instruction
1295 BEGIN (inclusive) to instruction END (inclusive). */
1296 virtual void insn_history_range (ULONGEST begin, ULONGEST end,
1297 gdb_disassembly_flags flags)
1298 TARGET_DEFAULT_NORETURN (tcomplain ());
1300 /* Print a function trace of the recorded execution trace.
1301 If SIZE < 0, print abs (SIZE) preceding functions; otherwise, print SIZE
1302 succeeding functions. */
1303 virtual void call_history (int size, record_print_flags flags)
1304 TARGET_DEFAULT_NORETURN (tcomplain ());
1306 /* Print a function trace of the recorded execution trace starting
1307 at function FROM.
1308 If SIZE < 0, print abs (SIZE) functions before FROM; otherwise, print
1309 SIZE functions after FROM. */
1310 virtual void call_history_from (ULONGEST begin, int size, record_print_flags flags)
1311 TARGET_DEFAULT_NORETURN (tcomplain ());
1313 /* Print a function trace of an execution trace section from function BEGIN
1314 (inclusive) to function END (inclusive). */
1315 virtual void call_history_range (ULONGEST begin, ULONGEST end, record_print_flags flags)
1316 TARGET_DEFAULT_NORETURN (tcomplain ());
1318 /* True if TARGET_OBJECT_LIBRARIES_SVR4 may be read with a
1319 non-empty annex. */
1320 virtual bool augmented_libraries_svr4_read ()
1321 TARGET_DEFAULT_RETURN (false);
1323 /* Those unwinders are tried before any other arch unwinders. If
1324 SELF doesn't have unwinders, it should delegate to the
1325 "beneath" target. */
1326 virtual const struct frame_unwind *get_unwinder ()
1327 TARGET_DEFAULT_RETURN (NULL);
1329 virtual const struct frame_unwind *get_tailcall_unwinder ()
1330 TARGET_DEFAULT_RETURN (NULL);
1332 /* Prepare to generate a core file. */
1333 virtual void prepare_to_generate_core ()
1334 TARGET_DEFAULT_IGNORE ();
1336 /* Cleanup after generating a core file. */
1337 virtual void done_generating_core ()
1338 TARGET_DEFAULT_IGNORE ();
1340 /* Returns true if the target supports memory tagging, false otherwise. */
1341 virtual bool supports_memory_tagging ()
1342 TARGET_DEFAULT_RETURN (false);
1344 /* Return the allocated memory tags of type TYPE associated with
1345 [ADDRESS, ADDRESS + LEN) in TAGS.
1347 LEN is the number of bytes in the memory range. TAGS is a vector of
1348 bytes containing the tags found in the above memory range.
1350 It is up to the architecture/target to interpret the bytes in the TAGS
1351 vector and read the tags appropriately.
1353 Returns true if fetching the tags succeeded and false otherwise. */
1354 virtual bool fetch_memtags (CORE_ADDR address, size_t len,
1355 gdb::byte_vector &tags, int type)
1356 TARGET_DEFAULT_NORETURN (tcomplain ());
1358 /* Write the allocation tags of type TYPE contained in TAGS to the memory
1359 range [ADDRESS, ADDRESS + LEN).
1361 LEN is the number of bytes in the memory range. TAGS is a vector of
1362 bytes containing the tags to be stored to the memory range.
1364 It is up to the architecture/target to interpret the bytes in the TAGS
1365 vector and store them appropriately.
1367 Returns true if storing the tags succeeded and false otherwise. */
1368 virtual bool store_memtags (CORE_ADDR address, size_t len,
1369 const gdb::byte_vector &tags, int type)
1370 TARGET_DEFAULT_NORETURN (tcomplain ());
1372 /* Returns true if ADDRESS is tagged, otherwise returns false. */
1373 virtual bool is_address_tagged (gdbarch *gdbarch, CORE_ADDR address)
1374 TARGET_DEFAULT_NORETURN (tcomplain ());
1376 /* Return the x86 XSAVE extended state area layout. */
1377 virtual x86_xsave_layout fetch_x86_xsave_layout ()
1378 TARGET_DEFAULT_RETURN (x86_xsave_layout ());
1381 /* Deleter for std::unique_ptr. See comments in
1382 target_ops::~target_ops and target_ops::close about heap-allocated
1383 targets. */
1384 struct target_ops_deleter
1386 void operator() (target_ops *target)
1388 target->close ();
1392 /* A unique pointer for target_ops. */
1393 typedef std::unique_ptr<target_ops, target_ops_deleter> target_ops_up;
1395 /* A policy class to interface gdb::ref_ptr with target_ops. */
1397 struct target_ops_ref_policy
1399 static void incref (target_ops *t)
1401 t->incref ();
1404 /* Decrement the reference count on T, and, if the reference count
1405 reaches zero, close the target. */
1406 static void decref (target_ops *t);
1409 /* A gdb::ref_ptr pointer to a target_ops. */
1410 typedef gdb::ref_ptr<target_ops, target_ops_ref_policy> target_ops_ref;
1412 /* Native target backends call this once at initialization time to
1413 inform the core about which is the target that can respond to "run"
1414 or "attach". Note: native targets are always singletons. */
1415 extern void set_native_target (target_ops *target);
1417 /* Get the registered native target, if there's one. Otherwise return
1418 NULL. */
1419 extern target_ops *get_native_target ();
1421 /* Type that manages a target stack. See description of target stacks
1422 and strata at the top of the file. */
1424 class target_stack
1426 public:
1427 target_stack () = default;
1428 DISABLE_COPY_AND_ASSIGN (target_stack);
1430 /* Push a new target into the stack of the existing target
1431 accessors, possibly superseding some existing accessor. */
1432 void push (target_ops *t);
1434 /* Remove a target from the stack, wherever it may be. Return true
1435 if it was removed, false otherwise. */
1436 bool unpush (target_ops *t);
1438 /* Returns true if T is pushed on the target stack. */
1439 bool is_pushed (const target_ops *t) const
1440 { return at (t->stratum ()) == t; }
1442 /* Return the target at STRATUM. */
1443 target_ops *at (strata stratum) const { return m_stack[stratum].get (); }
1445 /* Return the target at the top of the stack. */
1446 target_ops *top () const { return at (m_top); }
1448 /* Find the next target down the stack from the specified target. */
1449 target_ops *find_beneath (const target_ops *t) const;
1451 private:
1452 /* The stratum of the top target. */
1453 enum strata m_top {};
1455 /* The stack, represented as an array, with one slot per stratum.
1456 If no target is pushed at some stratum, the corresponding slot is
1457 null. */
1458 std::array<target_ops_ref, (int) debug_stratum + 1> m_stack;
1461 /* Return the dummy target. */
1462 extern target_ops *get_dummy_target ();
1464 /* Define easy words for doing these operations on our current target. */
1466 extern const char *target_shortname ();
1468 /* Find the correct target to use for "attach". If a target on the
1469 current stack supports attaching, then it is returned. Otherwise,
1470 the default run target is returned. */
1472 extern struct target_ops *find_attach_target (void);
1474 /* Find the correct target to use for "run". If a target on the
1475 current stack supports creating a new inferior, then it is
1476 returned. Otherwise, the default run target is returned. */
1478 extern struct target_ops *find_run_target (void);
1480 /* Some targets don't generate traps when attaching to the inferior,
1481 or their target_attach implementation takes care of the waiting.
1482 These targets must set to_attach_no_wait. */
1484 extern bool target_attach_no_wait ();
1486 /* The target_attach operation places a process under debugger control,
1487 and stops the process.
1489 This operation provides a target-specific hook that allows the
1490 necessary bookkeeping to be performed after an attach completes. */
1492 extern void target_post_attach (int pid);
1494 /* Display a message indicating we're about to attach to a given
1495 process. */
1497 extern void target_announce_attach (int from_tty, int pid);
1499 /* Display a message indicating we're about to detach from the current
1500 inferior process. */
1502 extern void target_announce_detach (int from_tty);
1504 /* Takes a program previously attached to and detaches it.
1505 The program may resume execution (some targets do, some don't) and will
1506 no longer stop on signals, etc. We better not have left any breakpoints
1507 in the program or it'll die when it hits one. FROM_TTY says whether to be
1508 verbose or not. */
1510 extern void target_detach (inferior *inf, int from_tty);
1512 /* Disconnect from the current target without resuming it (leaving it
1513 waiting for a debugger). */
1515 extern void target_disconnect (const char *, int);
1517 /* Resume execution (or prepare for execution) of the current thread
1518 (INFERIOR_PTID), while optionally letting other threads of the
1519 current process or all processes run free.
1521 STEP says whether to hardware single-step the current thread or to
1522 let it run free; SIGNAL is the signal to be given to the current
1523 thread, or GDB_SIGNAL_0 for no signal. The caller may not pass
1524 GDB_SIGNAL_DEFAULT.
1526 SCOPE_PTID indicates the resumption scope. I.e., which threads
1527 (other than the current) run free. If resuming a single thread,
1528 SCOPE_PTID is the same thread as the current thread. A wildcard
1529 SCOPE_PTID (all threads, or all threads of process) lets threads
1530 other than the current (for which the wildcard SCOPE_PTID matches)
1531 resume with their 'thread->suspend.stop_signal' signal (usually
1532 GDB_SIGNAL_0) if it is in "pass" state, or with no signal if in "no
1533 pass" state. Note neither STEP nor SIGNAL apply to any thread
1534 other than the current.
1536 In order to efficiently handle batches of resumption requests,
1537 targets may implement this method such that it records the
1538 resumption request, but defers the actual resumption to the
1539 target_commit_resume method implementation. See
1540 target_commit_resume below. */
1541 extern void target_resume (ptid_t scope_ptid,
1542 int step, enum gdb_signal signal);
1544 /* Ensure that all resumed threads are committed to the target.
1546 See the description of process_stratum_target::commit_resumed_state
1547 for more details. */
1548 extern void target_commit_resumed ();
1550 /* For target_read_memory see target/target.h. */
1552 /* The default target_ops::to_wait implementation. */
1554 extern ptid_t default_target_wait (struct target_ops *ops,
1555 ptid_t ptid,
1556 struct target_waitstatus *status,
1557 target_wait_flags options);
1559 /* Return true if the target has pending events to report to the core.
1560 See target_ops::has_pending_events(). */
1562 extern bool target_has_pending_events ();
1564 /* Fetch at least register REGNO, or all regs if regno == -1. No result. */
1566 extern void target_fetch_registers (struct regcache *regcache, int regno);
1568 /* Store at least register REGNO, or all regs if REGNO == -1.
1569 It can store as many registers as it wants to, so target_prepare_to_store
1570 must have been previously called. Calls error() if there are problems. */
1572 extern void target_store_registers (struct regcache *regcache, int regs);
1574 /* Get ready to modify the registers array. On machines which store
1575 individual registers, this doesn't need to do anything. On machines
1576 which store all the registers in one fell swoop, this makes sure
1577 that REGISTERS contains all the registers from the program being
1578 debugged. */
1580 extern void target_prepare_to_store (regcache *regcache);
1582 /* Implement the "info proc" command. This returns one if the request
1583 was handled, and zero otherwise. It can also throw an exception if
1584 an error was encountered while attempting to handle the
1585 request. */
1587 int target_info_proc (const char *, enum info_proc_what);
1589 /* Returns true if this target can disable address space randomization. */
1591 int target_supports_disable_randomization (void);
1593 /* Returns true if this target can enable and disable tracepoints
1594 while a trace experiment is running. */
1596 extern bool target_supports_enable_disable_tracepoint ();
1598 extern bool target_supports_string_tracing ();
1600 /* Returns true if this target can handle breakpoint conditions
1601 on its end. */
1603 extern bool target_supports_evaluation_of_breakpoint_conditions ();
1605 /* Does this target support dumpcore API? */
1607 extern bool target_supports_dumpcore ();
1609 /* Generate the core file with target API. */
1611 extern void target_dumpcore (const char *filename);
1613 /* Returns true if this target can handle breakpoint commands
1614 on its end. */
1616 extern bool target_can_run_breakpoint_commands ();
1618 /* For target_read_memory see target/target.h. */
1620 extern int target_read_raw_memory (CORE_ADDR memaddr, gdb_byte *myaddr,
1621 ssize_t len);
1623 extern int target_read_stack (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len);
1625 extern int target_read_code (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len);
1627 /* For target_write_memory see target/target.h. */
1629 extern int target_write_raw_memory (CORE_ADDR memaddr, const gdb_byte *myaddr,
1630 ssize_t len);
1632 /* Fetches the target's memory map. If one is found it is sorted
1633 and returned, after some consistency checking. Otherwise, NULL
1634 is returned. */
1635 std::vector<mem_region> target_memory_map (void);
1637 /* Erases all flash memory regions on the target. */
1638 void flash_erase_command (const char *cmd, int from_tty);
1640 /* Erase the specified flash region. */
1641 void target_flash_erase (ULONGEST address, LONGEST length);
1643 /* Finish a sequence of flash operations. */
1644 void target_flash_done (void);
1646 /* Describes a request for a memory write operation. */
1647 struct memory_write_request
1649 memory_write_request (ULONGEST begin_, ULONGEST end_,
1650 gdb_byte *data_ = nullptr, void *baton_ = nullptr)
1651 : begin (begin_), end (end_), data (data_), baton (baton_)
1654 /* Begining address that must be written. */
1655 ULONGEST begin;
1656 /* Past-the-end address. */
1657 ULONGEST end;
1658 /* The data to write. */
1659 gdb_byte *data;
1660 /* A callback baton for progress reporting for this request. */
1661 void *baton;
1664 /* Enumeration specifying different flash preservation behaviour. */
1665 enum flash_preserve_mode
1667 flash_preserve,
1668 flash_discard
1671 /* Write several memory blocks at once. This version can be more
1672 efficient than making several calls to target_write_memory, in
1673 particular because it can optimize accesses to flash memory.
1675 Moreover, this is currently the only memory access function in gdb
1676 that supports writing to flash memory, and it should be used for
1677 all cases where access to flash memory is desirable.
1679 REQUESTS is the vector of memory_write_request.
1680 PRESERVE_FLASH_P indicates what to do with blocks which must be
1681 erased, but not completely rewritten.
1682 PROGRESS_CB is a function that will be periodically called to provide
1683 feedback to user. It will be called with the baton corresponding
1684 to the request currently being written. It may also be called
1685 with a NULL baton, when preserved flash sectors are being rewritten.
1687 The function returns 0 on success, and error otherwise. */
1688 int target_write_memory_blocks
1689 (const std::vector<memory_write_request> &requests,
1690 enum flash_preserve_mode preserve_flash_p,
1691 void (*progress_cb) (ULONGEST, void *));
1693 /* Print a line about the current target. */
1695 extern void target_files_info ();
1697 /* Insert a breakpoint at address BP_TGT->placed_address in
1698 the target machine. Returns 0 for success, and returns non-zero or
1699 throws an error (with a detailed failure reason error code and
1700 message) otherwise. */
1702 extern int target_insert_breakpoint (struct gdbarch *gdbarch,
1703 struct bp_target_info *bp_tgt);
1705 /* Remove a breakpoint at address BP_TGT->placed_address in the target
1706 machine. Result is 0 for success, non-zero for error. */
1708 extern int target_remove_breakpoint (struct gdbarch *gdbarch,
1709 struct bp_target_info *bp_tgt,
1710 enum remove_bp_reason reason);
1712 /* Return true if the target stack has a non-default
1713 "terminal_ours" method. */
1715 extern bool target_supports_terminal_ours (void);
1717 /* Kill the inferior process. Make it go away. */
1719 extern void target_kill (void);
1721 /* Load an executable file into the target process. This is expected
1722 to not only bring new code into the target process, but also to
1723 update GDB's symbol tables to match.
1725 ARG contains command-line arguments, to be broken down with
1726 buildargv (). The first non-switch argument is the filename to
1727 load, FILE; the second is a number (as parsed by strtoul (..., ...,
1728 0)), which is an offset to apply to the load addresses of FILE's
1729 sections. The target may define switches, or other non-switch
1730 arguments, as it pleases. */
1732 extern void target_load (const char *arg, int from_tty);
1734 /* On some targets, we can catch an inferior fork or vfork event when
1735 it occurs. These functions insert/remove an already-created
1736 catchpoint for such events. They return 0 for success, 1 if the
1737 catchpoint type is not supported and -1 for failure. */
1739 extern int target_insert_fork_catchpoint (int pid);
1741 extern int target_remove_fork_catchpoint (int pid);
1743 extern int target_insert_vfork_catchpoint (int pid);
1745 extern int target_remove_vfork_catchpoint (int pid);
1747 /* Call the follow_fork method on the current target stack.
1749 This function is called when the inferior forks or vforks, to perform any
1750 bookkeeping and fiddling necessary to continue debugging either the parent,
1751 the child or both. */
1753 void target_follow_fork (inferior *inf, ptid_t child_ptid,
1754 target_waitkind fork_kind, bool follow_child,
1755 bool detach_fork);
1757 /* Handle the target-specific bookkeeping required when the inferior makes an
1758 exec call.
1760 The current inferior at the time of the call is the inferior that did the
1761 exec. FOLLOW_INF is the inferior in which execution continues post-exec.
1762 If "follow-exec-mode" is "same", FOLLOW_INF is the same as the current
1763 inferior, meaning that execution continues with the same inferior. If
1764 "follow-exec-mode" is "new", FOLLOW_INF is a different inferior, meaning
1765 that execution continues in a new inferior.
1767 On exit, the target must leave FOLLOW_INF as the current inferior. */
1769 void target_follow_exec (inferior *follow_inf, ptid_t ptid,
1770 const char *execd_pathname);
1772 /* On some targets, we can catch an inferior exec event when it
1773 occurs. These functions insert/remove an already-created
1774 catchpoint for such events. They return 0 for success, 1 if the
1775 catchpoint type is not supported and -1 for failure. */
1777 extern int target_insert_exec_catchpoint (int pid);
1779 extern int target_remove_exec_catchpoint (int pid);
1781 /* Syscall catch.
1783 NEEDED is true if any syscall catch (of any kind) is requested.
1784 If NEEDED is false, it means the target can disable the mechanism to
1785 catch system calls because there are no more catchpoints of this type.
1787 ANY_COUNT is nonzero if a generic (filter-less) syscall catch is
1788 being requested. In this case, SYSCALL_COUNTS should be ignored.
1790 SYSCALL_COUNTS is an array of ints, indexed by syscall number. An
1791 element in this array is nonzero if that syscall should be caught.
1792 This argument only matters if ANY_COUNT is zero.
1794 Return 0 for success, 1 if syscall catchpoints are not supported or -1
1795 for failure. */
1797 extern int target_set_syscall_catchpoint
1798 (int pid, bool needed, int any_count,
1799 gdb::array_view<const int> syscall_counts);
1801 /* The debugger has completed a blocking wait() call. There is now
1802 some process event that must be processed. This function should
1803 be defined by those targets that require the debugger to perform
1804 cleanup or internal state changes in response to the process event. */
1806 /* For target_mourn_inferior see target/target.h. */
1808 /* Does target have enough data to do a run or attach command? */
1810 extern int target_can_run ();
1812 /* Set list of signals to be handled in the target.
1814 PASS_SIGNALS is an array indexed by target signal number
1815 (enum gdb_signal). For every signal whose entry in this array is
1816 non-zero, the target is allowed -but not required- to skip reporting
1817 arrival of the signal to the GDB core by returning from target_wait,
1818 and to pass the signal directly to the inferior instead.
1820 However, if the target is hardware single-stepping a thread that is
1821 about to receive a signal, it needs to be reported in any case, even
1822 if mentioned in a previous target_pass_signals call. */
1824 extern void target_pass_signals
1825 (gdb::array_view<const unsigned char> pass_signals);
1827 /* Set list of signals the target may pass to the inferior. This
1828 directly maps to the "handle SIGNAL pass/nopass" setting.
1830 PROGRAM_SIGNALS is an array indexed by target signal
1831 number (enum gdb_signal). For every signal whose entry in this
1832 array is non-zero, the target is allowed to pass the signal to the
1833 inferior. Signals not present in the array shall be silently
1834 discarded. This does not influence whether to pass signals to the
1835 inferior as a result of a target_resume call. This is useful in
1836 scenarios where the target needs to decide whether to pass or not a
1837 signal to the inferior without GDB core involvement, such as for
1838 example, when detaching (as threads may have been suspended with
1839 pending signals not reported to GDB). */
1841 extern void target_program_signals
1842 (gdb::array_view<const unsigned char> program_signals);
1844 /* Check to see if a thread is still alive. */
1846 extern int target_thread_alive (ptid_t ptid);
1848 /* Sync the target's threads with GDB's thread list. */
1850 extern void target_update_thread_list (void);
1852 /* Make target stop in a continuable fashion. (For instance, under
1853 Unix, this should act like SIGSTOP). Note that this function is
1854 asynchronous: it does not wait for the target to become stopped
1855 before returning. If this is the behavior you want please use
1856 target_stop_and_wait. */
1858 extern void target_stop (ptid_t ptid);
1860 /* Interrupt the target. Unlike target_stop, this does not specify
1861 which thread/process reports the stop. For most target this acts
1862 like raising a SIGINT, though that's not absolutely required. This
1863 function is asynchronous. */
1865 extern void target_interrupt ();
1867 /* Pass a ^C, as determined to have been pressed by checking the quit
1868 flag, to the target, as if the user had typed the ^C on the
1869 inferior's controlling terminal while the inferior was in the
1870 foreground. Remote targets may take the opportunity to detect the
1871 remote side is not responding and offer to disconnect. */
1873 extern void target_pass_ctrlc (void);
1875 /* The default target_ops::to_pass_ctrlc implementation. Simply calls
1876 target_interrupt. */
1877 extern void default_target_pass_ctrlc (struct target_ops *ops);
1879 /* Send the specified COMMAND to the target's monitor
1880 (shell,interpreter) for execution. The result of the query is
1881 placed in OUTBUF. */
1883 extern void target_rcmd (const char *command, struct ui_file *outbuf);
1885 /* Does the target include memory? (Dummy targets don't.) */
1887 extern int target_has_memory ();
1889 /* Does the target have a stack? (Exec files don't, VxWorks doesn't, until
1890 we start a process.) */
1892 extern int target_has_stack ();
1894 /* Does the target have registers? (Exec files don't.) */
1896 extern int target_has_registers ();
1898 /* Does the target have execution? Can we make it jump (through
1899 hoops), or pop its stack a few times? This means that the current
1900 target is currently executing; for some targets, that's the same as
1901 whether or not the target is capable of execution, but there are
1902 also targets which can be current while not executing. In that
1903 case this will become true after to_create_inferior or
1904 to_attach. INF is the inferior to use; nullptr means to use the
1905 current inferior. */
1907 extern bool target_has_execution (inferior *inf = nullptr);
1909 /* Can the target support the debugger control of thread execution?
1910 Can it lock the thread scheduler? */
1912 extern bool target_can_lock_scheduler ();
1914 /* Controls whether async mode is permitted. */
1915 extern bool target_async_permitted;
1917 /* Can the target support asynchronous execution? */
1918 extern bool target_can_async_p ();
1920 /* An overload of the above that can be called when the target is not yet
1921 pushed, this calls TARGET::can_async_p directly. */
1922 extern bool target_can_async_p (struct target_ops *target);
1924 /* Is the target in asynchronous execution mode? */
1925 extern bool target_is_async_p ();
1927 /* Enables/disabled async target events. */
1928 extern void target_async (bool enable);
1930 /* Enables/disables thread create and exit events. */
1931 extern void target_thread_events (bool enable);
1933 /* Returns true if the target supports setting thread options
1934 OPTIONS. */
1935 extern bool target_supports_set_thread_options (gdb_thread_options options);
1937 /* Whether support for controlling the target backends always in
1938 non-stop mode is enabled. */
1939 extern enum auto_boolean target_non_stop_enabled;
1941 /* Is the target in non-stop mode? Some targets control the inferior
1942 in non-stop mode even with "set non-stop off". Always true if "set
1943 non-stop" is on. */
1944 extern bool target_is_non_stop_p ();
1946 /* Return true if at least one inferior has a non-stop target. */
1947 extern bool exists_non_stop_target ();
1949 extern exec_direction_kind target_execution_direction ();
1951 /* Converts a process id to a string. Usually, the string just contains
1952 `process xyz', but on some systems it may contain
1953 `process xyz thread abc'. */
1955 extern std::string target_pid_to_str (ptid_t ptid);
1957 extern std::string normal_pid_to_str (ptid_t ptid);
1959 /* Return a short string describing extra information about PID,
1960 e.g. "sleeping", "runnable", "running on LWP 3". Null return value
1961 is okay. */
1963 extern const char *target_extra_thread_info (thread_info *tp);
1965 /* Return the thread's name, or NULL if the target is unable to determine it.
1966 The returned value must not be freed by the caller.
1968 You likely don't want to call this function, but use the thread_name
1969 function instead, which prefers the user-given thread name, if set. */
1971 extern const char *target_thread_name (struct thread_info *);
1973 /* Given a pointer to a thread library specific thread handle and
1974 its length, return a pointer to the corresponding thread_info struct. */
1976 extern struct thread_info *target_thread_handle_to_thread_info
1977 (const gdb_byte *thread_handle, int handle_len, struct inferior *inf);
1979 /* Given a thread, return the thread handle, a target-specific sequence of
1980 bytes which serves as a thread identifier within the program being
1981 debugged. */
1982 extern gdb::array_view<const gdb_byte> target_thread_info_to_thread_handle
1983 (struct thread_info *);
1985 /* Attempts to find the pathname of the executable file
1986 that was run to create a specified process.
1988 The process PID must be stopped when this operation is used.
1990 If the executable file cannot be determined, NULL is returned.
1992 Else, a pointer to a character string containing the pathname
1993 is returned. This string should be copied into a buffer by
1994 the client if the string will not be immediately used, or if
1995 it must persist. */
1997 extern const char *target_pid_to_exec_file (int pid);
1999 /* See the to_thread_architecture description in struct target_ops. */
2001 extern gdbarch *target_thread_architecture (ptid_t ptid);
2004 * Iterator function for target memory regions.
2005 * Calls a callback function once for each memory region 'mapped'
2006 * in the child process. Defined as a simple macro rather than
2007 * as a function macro so that it can be tested for nullity.
2010 extern int target_find_memory_regions (find_memory_region_ftype func,
2011 void *data);
2014 * Compose corefile .note section.
2017 extern gdb::unique_xmalloc_ptr<char> target_make_corefile_notes (bfd *bfd,
2018 int *size_p);
2020 /* Bookmark interfaces. */
2021 extern gdb_byte *target_get_bookmark (const char *args, int from_tty);
2023 extern void target_goto_bookmark (const gdb_byte *arg, int from_tty);
2025 /* Hardware watchpoint interfaces. */
2027 /* GDB's current model is that there are three "kinds" of watchpoints,
2028 with respect to when they trigger and how you can move past them.
2030 Those are: continuable, steppable, and non-steppable.
2032 Continuable watchpoints are like x86's -- those trigger after the
2033 memory access's side effects are fully committed to memory. I.e.,
2034 they trap with the PC pointing at the next instruction already.
2035 Continuing past such a watchpoint is doable by just normally
2036 continuing, hence the name.
2038 Both steppable and non-steppable watchpoints trap before the memory
2039 access. I.e, the PC points at the instruction that is accessing
2040 the memory. So GDB needs to single-step once past the current
2041 instruction in order to make the access effective and check whether
2042 the instruction's side effects change the watched expression.
2044 Now, in order to step past that instruction, depending on
2045 architecture and target, you can have two situations:
2047 - steppable watchpoints: you can single-step with the watchpoint
2048 still armed, and the watchpoint won't trigger again.
2050 - non-steppable watchpoints: if you try to single-step with the
2051 watchpoint still armed, you'd trap the watchpoint again and the
2052 thread wouldn't make any progress. So GDB needs to temporarily
2053 remove the watchpoint in order to step past it.
2055 If your target/architecture does not signal that it has either
2056 steppable or non-steppable watchpoints via either
2057 target_have_steppable_watchpoint or
2058 gdbarch_have_nonsteppable_watchpoint, GDB assumes continuable
2059 watchpoints. */
2061 /* Returns true if we were stopped by a hardware watchpoint (memory read or
2062 write). Only the INFERIOR_PTID task is being queried. */
2064 extern bool target_stopped_by_watchpoint ();
2066 /* Returns true if the target stopped because it executed a
2067 software breakpoint instruction. */
2069 extern bool target_stopped_by_sw_breakpoint ();
2071 extern bool target_supports_stopped_by_sw_breakpoint ();
2073 extern bool target_stopped_by_hw_breakpoint ();
2075 extern bool target_supports_stopped_by_hw_breakpoint ();
2077 /* True if we have steppable watchpoints */
2079 extern bool target_have_steppable_watchpoint ();
2081 /* Provide defaults for hardware watchpoint functions. */
2083 /* If the *_hw_breakpoint functions have not been defined
2084 elsewhere use the definitions in the target vector. */
2086 /* Returns positive if we can set a hardware watchpoint of type TYPE.
2087 Returns negative if the target doesn't have enough hardware debug
2088 registers available. Return zero if hardware watchpoint of type
2089 TYPE isn't supported. TYPE is one of bp_hardware_watchpoint,
2090 bp_read_watchpoint, bp_write_watchpoint, or bp_hardware_breakpoint.
2091 CNT is the number of such watchpoints used so far, including this
2092 one. OTHERTYPE is the number of watchpoints of other types than
2093 this one used so far. */
2095 extern int target_can_use_hardware_watchpoint (bptype type, int cnt,
2096 int othertype);
2098 /* Returns the number of debug registers needed to watch the given
2099 memory region, or zero if not supported. */
2101 extern int target_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len);
2103 extern int target_can_do_single_step ();
2105 /* Set/clear a hardware watchpoint starting at ADDR, for LEN bytes.
2106 TYPE is 0 for write, 1 for read, and 2 for read/write accesses.
2107 COND is the expression for its condition, or NULL if there's none.
2108 Returns 0 for success, 1 if the watchpoint type is not supported,
2109 -1 for failure. */
2111 extern int target_insert_watchpoint (CORE_ADDR addr, int len,
2112 target_hw_bp_type type, expression *cond);
2114 extern int target_remove_watchpoint (CORE_ADDR addr, int len,
2115 target_hw_bp_type type, expression *cond);
2117 /* Insert a new masked watchpoint at ADDR using the mask MASK.
2118 RW may be hw_read for a read watchpoint, hw_write for a write watchpoint
2119 or hw_access for an access watchpoint. Returns 0 for success, 1 if
2120 masked watchpoints are not supported, -1 for failure. */
2122 extern int target_insert_mask_watchpoint (CORE_ADDR, CORE_ADDR,
2123 enum target_hw_bp_type);
2125 /* Remove a masked watchpoint at ADDR with the mask MASK.
2126 RW may be hw_read for a read watchpoint, hw_write for a write watchpoint
2127 or hw_access for an access watchpoint. Returns 0 for success, non-zero
2128 for failure. */
2130 extern int target_remove_mask_watchpoint (CORE_ADDR, CORE_ADDR,
2131 enum target_hw_bp_type);
2133 /* Insert a hardware breakpoint at address BP_TGT->placed_address in
2134 the target machine. Returns 0 for success, and returns non-zero or
2135 throws an error (with a detailed failure reason error code and
2136 message) otherwise. */
2138 extern int target_insert_hw_breakpoint (gdbarch *gdbarch,
2139 bp_target_info *bp_tgt);
2141 extern int target_remove_hw_breakpoint (gdbarch *gdbarch,
2142 bp_target_info *bp_tgt);
2144 /* Return number of debug registers needed for a ranged breakpoint,
2145 or -1 if ranged breakpoints are not supported. */
2147 extern int target_ranged_break_num_registers (void);
2149 /* Return non-zero if target knows the data address which triggered this
2150 target_stopped_by_watchpoint, in such case place it to *ADDR_P. Only the
2151 INFERIOR_PTID task is being queried. */
2152 #define target_stopped_data_address(target, addr_p) \
2153 (target)->stopped_data_address (addr_p)
2155 /* Return non-zero if ADDR is within the range of a watchpoint spanning
2156 LENGTH bytes beginning at START. */
2157 #define target_watchpoint_addr_within_range(target, addr, start, length) \
2158 (target)->watchpoint_addr_within_range (addr, start, length)
2160 /* Return non-zero if the target is capable of using hardware to evaluate
2161 the condition expression. In this case, if the condition is false when
2162 the watched memory location changes, execution may continue without the
2163 debugger being notified.
2165 Due to limitations in the hardware implementation, it may be capable of
2166 avoiding triggering the watchpoint in some cases where the condition
2167 expression is false, but may report some false positives as well.
2168 For this reason, GDB will still evaluate the condition expression when
2169 the watchpoint triggers. */
2171 extern bool target_can_accel_watchpoint_condition (CORE_ADDR addr, int len,
2172 int type, expression *cond);
2174 /* Return number of debug registers needed for a masked watchpoint,
2175 -1 if masked watchpoints are not supported or -2 if the given address
2176 and mask combination cannot be used. */
2178 extern int target_masked_watch_num_registers (CORE_ADDR addr, CORE_ADDR mask);
2180 /* Target can execute in reverse? */
2182 extern bool target_can_execute_reverse ();
2184 extern const struct target_desc *target_read_description (struct target_ops *);
2186 extern ptid_t target_get_ada_task_ptid (long lwp, ULONGEST tid);
2188 /* Main entry point for searching memory. */
2189 extern int target_search_memory (CORE_ADDR start_addr,
2190 ULONGEST search_space_len,
2191 const gdb_byte *pattern,
2192 ULONGEST pattern_len,
2193 CORE_ADDR *found_addrp);
2195 /* Target file operations. */
2197 /* Return true if the filesystem seen by the current inferior
2198 is the local filesystem, zero otherwise. */
2200 extern bool target_filesystem_is_local ();
2202 /* Open FILENAME on the target, in the filesystem as seen by INF,
2203 using FLAGS and MODE. If INF is NULL, use the filesystem seen by
2204 the debugger (GDB or, for remote targets, the remote stub). Return
2205 a target file descriptor, or -1 if an error occurs (and set
2206 *TARGET_ERRNO). If WARN_IF_SLOW is true, print a warning message
2207 if the file is being accessed over a link that may be slow. */
2208 extern int target_fileio_open (struct inferior *inf,
2209 const char *filename, int flags,
2210 int mode, bool warn_if_slow,
2211 fileio_error *target_errno);
2213 /* Write up to LEN bytes from WRITE_BUF to FD on the target.
2214 Return the number of bytes written, or -1 if an error occurs
2215 (and set *TARGET_ERRNO). */
2216 extern int target_fileio_pwrite (int fd, const gdb_byte *write_buf, int len,
2217 ULONGEST offset, fileio_error *target_errno);
2219 /* Read up to LEN bytes FD on the target into READ_BUF.
2220 Return the number of bytes read, or -1 if an error occurs
2221 (and set *TARGET_ERRNO). */
2222 extern int target_fileio_pread (int fd, gdb_byte *read_buf, int len,
2223 ULONGEST offset, fileio_error *target_errno);
2225 /* Get information about the file opened as FD on the target
2226 and put it in SB. Return 0 on success, or -1 if an error
2227 occurs (and set *TARGET_ERRNO). */
2228 extern int target_fileio_fstat (int fd, struct stat *sb,
2229 fileio_error *target_errno);
2231 /* Get information about the file at FILENAME on the target and put it in
2232 SB. Look in the filesystem as seen by INF. If INF is NULL, use the
2233 filesystem seen by the debugger (GDB or, for remote targets, the remote
2234 stub). Return 0 on success, or -1 if an error occurs (and set
2235 *TARGET_ERRNO). */
2236 extern int target_fileio_stat (struct inferior *inf, const char *filename,
2237 struct stat *sb, fileio_error *target_errno);
2239 /* Close FD on the target. Return 0, or -1 if an error occurs
2240 (and set *TARGET_ERRNO). */
2241 extern int target_fileio_close (int fd, fileio_error *target_errno);
2243 /* Unlink FILENAME on the target, in the filesystem as seen by INF.
2244 If INF is NULL, use the filesystem seen by the debugger (GDB or,
2245 for remote targets, the remote stub). Return 0, or -1 if an error
2246 occurs (and set *TARGET_ERRNO). */
2247 extern int target_fileio_unlink (struct inferior *inf,
2248 const char *filename,
2249 fileio_error *target_errno);
2251 /* Read value of symbolic link FILENAME on the target, in the
2252 filesystem as seen by INF. If INF is NULL, use the filesystem seen
2253 by the debugger (GDB or, for remote targets, the remote stub).
2254 Return a null-terminated string allocated via xmalloc, or NULL if
2255 an error occurs (and set *TARGET_ERRNO). */
2256 extern std::optional<std::string> target_fileio_readlink
2257 (struct inferior *inf, const char *filename, fileio_error *target_errno);
2259 /* Read target file FILENAME, in the filesystem as seen by INF. If
2260 INF is NULL, use the filesystem seen by the debugger (GDB or, for
2261 remote targets, the remote stub). The return value will be -1 if
2262 the transfer fails or is not supported; 0 if the object is empty;
2263 or the length of the object otherwise. If a positive value is
2264 returned, a sufficiently large buffer will be allocated using
2265 xmalloc and returned in *BUF_P containing the contents of the
2266 object.
2268 This method should be used for objects sufficiently small to store
2269 in a single xmalloc'd buffer, when no fixed bound on the object's
2270 size is known in advance. */
2271 extern LONGEST target_fileio_read_alloc (struct inferior *inf,
2272 const char *filename,
2273 gdb_byte **buf_p);
2275 /* Read target file FILENAME, in the filesystem as seen by INF. If
2276 INF is NULL, use the filesystem seen by the debugger (GDB or, for
2277 remote targets, the remote stub). The result is NUL-terminated and
2278 returned as a string, allocated using xmalloc. If an error occurs
2279 or the transfer is unsupported, NULL is returned. Empty objects
2280 are returned as allocated but empty strings. A warning is issued
2281 if the result contains any embedded NUL bytes. */
2282 extern gdb::unique_xmalloc_ptr<char> target_fileio_read_stralloc
2283 (struct inferior *inf, const char *filename);
2285 /* Invalidate the target associated with open handles that were open
2286 on target TARG, since we're about to close (and maybe destroy) the
2287 target. The handles remain open from the client's perspective, but
2288 trying to do anything with them other than closing them will fail
2289 with EIO. */
2290 extern void fileio_handles_invalidate_target (target_ops *targ);
2292 /* Tracepoint-related operations. */
2294 extern void target_trace_init ();
2296 extern void target_download_tracepoint (bp_location *location);
2298 extern bool target_can_download_tracepoint ();
2300 extern void target_download_trace_state_variable (const trace_state_variable &tsv);
2302 extern void target_enable_tracepoint (bp_location *loc);
2304 extern void target_disable_tracepoint (bp_location *loc);
2306 extern void target_trace_start ();
2308 extern void target_trace_set_readonly_regions ();
2310 extern int target_get_trace_status (trace_status *ts);
2312 extern void target_get_tracepoint_status (tracepoint *tp, uploaded_tp *utp);
2314 extern void target_trace_stop ();
2316 extern int target_trace_find (trace_find_type type, int num, CORE_ADDR addr1,
2317 CORE_ADDR addr2, int *tpp);
2319 extern bool target_get_trace_state_variable_value (int tsv, LONGEST *val);
2321 extern int target_save_trace_data (const char *filename);
2323 extern int target_upload_tracepoints (uploaded_tp **utpp);
2325 extern int target_upload_trace_state_variables (uploaded_tsv **utsvp);
2327 extern LONGEST target_get_raw_trace_data (gdb_byte *buf, ULONGEST offset,
2328 LONGEST len);
2330 extern int target_get_min_fast_tracepoint_insn_len ();
2332 extern void target_set_disconnected_tracing (int val);
2334 extern void target_set_circular_trace_buffer (int val);
2336 extern void target_set_trace_buffer_size (LONGEST val);
2338 extern bool target_set_trace_notes (const char *user, const char *notes,
2339 const char *stopnotes);
2341 extern bool target_get_tib_address (ptid_t ptid, CORE_ADDR *addr);
2343 extern void target_set_permissions ();
2345 extern bool target_static_tracepoint_marker_at
2346 (CORE_ADDR addr, static_tracepoint_marker *marker);
2348 extern std::vector<static_tracepoint_marker>
2349 target_static_tracepoint_markers_by_strid (const char *marker_id);
2351 extern traceframe_info_up target_traceframe_info ();
2353 extern bool target_use_agent (bool use);
2355 extern bool target_can_use_agent ();
2357 extern bool target_augmented_libraries_svr4_read ();
2359 extern bool target_supports_memory_tagging ();
2361 extern bool target_fetch_memtags (CORE_ADDR address, size_t len,
2362 gdb::byte_vector &tags, int type);
2364 extern bool target_store_memtags (CORE_ADDR address, size_t len,
2365 const gdb::byte_vector &tags, int type);
2367 extern bool target_is_address_tagged (gdbarch *gdbarch, CORE_ADDR address);
2369 extern x86_xsave_layout target_fetch_x86_xsave_layout ();
2371 /* Command logging facility. */
2373 extern void target_log_command (const char *p);
2375 extern int target_core_of_thread (ptid_t ptid);
2377 /* See to_get_unwinder in struct target_ops. */
2378 extern const struct frame_unwind *target_get_unwinder (void);
2380 /* See to_get_tailcall_unwinder in struct target_ops. */
2381 extern const struct frame_unwind *target_get_tailcall_unwinder (void);
2383 /* This implements basic memory verification, reading target memory
2384 and performing the comparison here (as opposed to accelerated
2385 verification making use of the qCRC packet, for example). */
2387 extern int simple_verify_memory (struct target_ops* ops,
2388 const gdb_byte *data,
2389 CORE_ADDR memaddr, ULONGEST size);
2391 /* Verify that the memory in the [MEMADDR, MEMADDR+SIZE) range matches
2392 the contents of [DATA,DATA+SIZE). Returns 1 if there's a match, 0
2393 if there's a mismatch, and -1 if an error is encountered while
2394 reading memory. Throws an error if the functionality is found not
2395 to be supported by the current target. */
2396 int target_verify_memory (const gdb_byte *data,
2397 CORE_ADDR memaddr, ULONGEST size);
2399 /* Routines for maintenance of the target structures...
2401 add_target: Add a target to the list of all possible targets.
2402 This only makes sense for targets that should be activated using
2403 the "target TARGET_NAME ..." command.
2405 push_target: Make this target the top of the stack of currently used
2406 targets, within its particular stratum of the stack. Result
2407 is 0 if now atop the stack, nonzero if not on top (maybe
2408 should warn user).
2410 unpush_target: Remove this from the stack of currently used targets,
2411 no matter where it is on the list. Returns 0 if no
2412 change, 1 if removed from stack. */
2414 /* Type of callback called when the user activates a target with
2415 "target TARGET_NAME". The callback routine takes the rest of the
2416 parameters from the command, and (if successful) pushes a new
2417 target onto the stack. */
2418 typedef void target_open_ftype (const char *args, int from_tty);
2420 /* Add the target described by INFO to the list of possible targets
2421 and add a new command 'target $(INFO->shortname)'. Set COMPLETER
2422 as the command's completer if not NULL. */
2424 extern void add_target (const target_info &info,
2425 target_open_ftype *func,
2426 completer_ftype *completer = NULL);
2428 /* Adds a command ALIAS for the target described by INFO and marks it
2429 deprecated. This is useful for maintaining backwards compatibility
2430 when renaming targets. */
2432 extern void add_deprecated_target_alias (const target_info &info,
2433 const char *alias);
2435 /* A unique_ptr helper to unpush a target. */
2437 struct target_unpusher
2439 void operator() (struct target_ops *ops) const;
2442 /* A unique_ptr that unpushes a target on destruction. */
2444 typedef std::unique_ptr<struct target_ops, target_unpusher> target_unpush_up;
2446 extern void target_pre_inferior ();
2448 extern void target_preopen (int);
2450 extern CORE_ADDR target_translate_tls_address (struct objfile *objfile,
2451 CORE_ADDR offset);
2453 /* Return the "section" containing the specified address. */
2454 const struct target_section *target_section_by_addr (struct target_ops *target,
2455 CORE_ADDR addr);
2457 /* Return the target section table this target (or the targets
2458 beneath) currently manipulate. */
2460 extern const std::vector<target_section> *target_get_section_table
2461 (struct target_ops *target);
2463 /* Default implementation of get_section_table for dummy_target. */
2465 extern const std::vector<target_section> *default_get_section_table ();
2467 /* From mem-break.c */
2469 extern int memory_remove_breakpoint (struct target_ops *,
2470 struct gdbarch *, struct bp_target_info *,
2471 enum remove_bp_reason);
2473 extern int memory_insert_breakpoint (struct target_ops *,
2474 struct gdbarch *, struct bp_target_info *);
2476 /* Convenience template use to add memory breakpoints support to a
2477 target. */
2479 template <typename BaseTarget>
2480 struct memory_breakpoint_target : public BaseTarget
2482 int insert_breakpoint (struct gdbarch *gdbarch,
2483 struct bp_target_info *bp_tgt) override
2484 { return memory_insert_breakpoint (this, gdbarch, bp_tgt); }
2486 int remove_breakpoint (struct gdbarch *gdbarch,
2487 struct bp_target_info *bp_tgt,
2488 enum remove_bp_reason reason) override
2489 { return memory_remove_breakpoint (this, gdbarch, bp_tgt, reason); }
2492 /* Check whether the memory at the breakpoint's placed address still
2493 contains the expected breakpoint instruction. */
2495 extern int memory_validate_breakpoint (struct gdbarch *gdbarch,
2496 struct bp_target_info *bp_tgt);
2498 extern int default_memory_remove_breakpoint (struct gdbarch *,
2499 struct bp_target_info *);
2501 extern int default_memory_insert_breakpoint (struct gdbarch *,
2502 struct bp_target_info *);
2505 /* From target.c */
2507 extern void initialize_targets (void);
2509 [[noreturn]] extern void noprocess (void);
2511 extern void target_require_runnable (void);
2513 /* Find the target at STRATUM. If no target is at that stratum,
2514 return NULL. */
2516 struct target_ops *find_target_at (enum strata stratum);
2518 /* Read OS data object of type TYPE from the target, and return it in XML
2519 format. The return value follows the same rules as target_read_stralloc. */
2521 extern std::optional<gdb::char_vector> target_get_osdata (const char *type);
2523 /* Stuff that should be shared among the various remote targets. */
2526 /* Timeout limit for response from target. */
2527 extern int remote_timeout;
2531 /* Set the show memory breakpoints mode to show, and return a
2532 scoped_restore to restore it back to the current value. */
2533 extern scoped_restore_tmpl<int>
2534 make_scoped_restore_show_memory_breakpoints (int show);
2536 /* True if we should trust readonly sections from the
2537 executable when reading memory. */
2538 extern bool trust_readonly;
2540 extern bool may_write_registers;
2541 extern bool may_write_memory;
2542 extern bool may_insert_breakpoints;
2543 extern bool may_insert_tracepoints;
2544 extern bool may_insert_fast_tracepoints;
2545 extern bool may_stop;
2547 extern void update_target_permissions (void);
2550 /* Imported from machine dependent code. */
2552 /* See to_enable_btrace in struct target_ops. */
2553 extern struct btrace_target_info *
2554 target_enable_btrace (thread_info *tp, const struct btrace_config *);
2556 /* See to_disable_btrace in struct target_ops. */
2557 extern void target_disable_btrace (struct btrace_target_info *btinfo);
2559 /* See to_teardown_btrace in struct target_ops. */
2560 extern void target_teardown_btrace (struct btrace_target_info *btinfo);
2562 /* See to_read_btrace in struct target_ops. */
2563 extern enum btrace_error target_read_btrace (struct btrace_data *,
2564 struct btrace_target_info *,
2565 enum btrace_read_type);
2567 /* See to_btrace_conf in struct target_ops. */
2568 extern const struct btrace_config *
2569 target_btrace_conf (const struct btrace_target_info *);
2571 /* See to_stop_recording in struct target_ops. */
2572 extern void target_stop_recording (void);
2574 /* See to_save_record in struct target_ops. */
2575 extern void target_save_record (const char *filename);
2577 /* Query if the target supports deleting the execution log. */
2578 extern int target_supports_delete_record (void);
2580 /* See to_delete_record in struct target_ops. */
2581 extern void target_delete_record (void);
2583 /* See to_record_method. */
2584 extern enum record_method target_record_method (ptid_t ptid);
2586 /* See to_record_is_replaying in struct target_ops. */
2587 extern int target_record_is_replaying (ptid_t ptid);
2589 /* See to_record_will_replay in struct target_ops. */
2590 extern int target_record_will_replay (ptid_t ptid, int dir);
2592 /* See to_record_stop_replaying in struct target_ops. */
2593 extern void target_record_stop_replaying (void);
2595 /* See to_goto_record_begin in struct target_ops. */
2596 extern void target_goto_record_begin (void);
2598 /* See to_goto_record_end in struct target_ops. */
2599 extern void target_goto_record_end (void);
2601 /* See to_goto_record in struct target_ops. */
2602 extern void target_goto_record (ULONGEST insn);
2604 /* See to_insn_history. */
2605 extern void target_insn_history (int size, gdb_disassembly_flags flags);
2607 /* See to_insn_history_from. */
2608 extern void target_insn_history_from (ULONGEST from, int size,
2609 gdb_disassembly_flags flags);
2611 /* See to_insn_history_range. */
2612 extern void target_insn_history_range (ULONGEST begin, ULONGEST end,
2613 gdb_disassembly_flags flags);
2615 /* See to_call_history. */
2616 extern void target_call_history (int size, record_print_flags flags);
2618 /* See to_call_history_from. */
2619 extern void target_call_history_from (ULONGEST begin, int size,
2620 record_print_flags flags);
2622 /* See to_call_history_range. */
2623 extern void target_call_history_range (ULONGEST begin, ULONGEST end,
2624 record_print_flags flags);
2626 /* See to_prepare_to_generate_core. */
2627 extern void target_prepare_to_generate_core (void);
2629 /* See to_done_generating_core. */
2630 extern void target_done_generating_core (void);
2632 #endif /* !defined (TARGET_H) */