1 /* Interface between GDB and target environments, including files and processes
2 
3    Copyright (C) 1990-2024 Free Software Foundation, Inc.
4 
5    Contributed by Cygnus Support.  Written by John Gilmore.
6 
7    This file is part of GDB.
8 
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.
13 
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.
18 
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/>.  */
21 
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.
25 
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.
39 
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.  */
43 
44 #if !defined (TARGET_H)
45 #define TARGET_H
46 
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;
63 
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;
67 
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"
88 
89 #include "gdbsupport/break-common.h"
90 
91 enum strata
92   {
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.  */
100   };
101 
102 enum thread_control_capabilities
103   {
104     tc_none = 0,              /* Default: can't control thread execution.  */
105     tc_schedlock = 1,                   /* Can lock the thread scheduler.  */
106   };
107 
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.
111 
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
115   {
116     /* The syscall number.  */
117     int number;
118 
119     /* The syscall name.  */
120     const char *name;
121   };
122 
123 /* Return a pretty printed form of TARGET_OPTIONS.  */
124 extern std::string target_options_to_string (target_wait_flags target_options);
125 
126 /* Possible types of events that the inferior handler will have to
127    deal with.  */
128 enum inferior_event_type
129   {
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,
135   };
136 
137 /* Target objects which can be transfered using target_read,
138    target_write, et cetera.  */
139 
140 enum target_object
141 {
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, ...  */
212 };
213 
214 /* Possible values returned by target_xfer_partial, etc.  */
215 
216 enum target_xfer_status
217 {
218   /* Some bytes are transferred.  */
219   TARGET_XFER_OK = 1,
220 
221   /* No further transfer is possible.  */
222   TARGET_XFER_EOF = 0,
223 
224   /* The piece of the object requested is unavailable.  */
225   TARGET_XFER_UNAVAILABLE = 2,
226 
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,
231 
232   /* Keep list in sync with target_xfer_status_to_string.  */
233 };
234 
235 /* Return the string form of STATUS.  */
236 
237 extern const char *
238   target_xfer_status_to_string (enum target_xfer_status status);
239 
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);
249 
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);
254 
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.
263 
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.  */
270 
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);
275 
276 struct memory_read_result
277 {
memory_read_resultmemory_read_result278   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_))
283   {
284   }
285 
286   ~memory_read_result () = default;
287 
288   memory_read_result (memory_read_result &&other) = default;
289 
290   DISABLE_COPY_AND_ASSIGN (memory_read_result);
291 
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;
298 };
299 
300 extern std::vector<memory_read_result> read_memory_robust
301     (struct target_ops *ops, const ULONGEST offset, const LONGEST len);
302 
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.
310 
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.  */
317 
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);
322 
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.  */
329 
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);
336 
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.
340 
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.  */
345 
346 extern std::optional<gdb::byte_vector> target_read_alloc
347     (struct target_ops *ops, enum target_object object, const char *annex);
348 
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.  */
355 
356 extern std::optional<gdb::char_vector> target_read_stralloc
357     (struct target_ops *ops, enum target_object object, const char *annex);
358 
359 /* See target_ops->to_xfer_partial.  */
360 extern target_xfer_partial_ftype target_xfer_partial;
361 
362 /* Wrappers to target read/write that perform memory transfers.  They
363    throw an error if the memory transfer fails.
364 
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.  */
368 
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);
374 
375 struct thread_info;           /* fwd decl for parameter list below: */
376 
377 /* The type of the callback to the to_async method.  */
378 
379 typedef void async_callback_ftype (enum inferior_event_type event_type,
380                                            void *context);
381 
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.  */
389 
390 #define TARGET_DEBUG_PRINTER(FUNC)
391 
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:
395 
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'.
399 
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.
403 
404    3. TARGET_DEFAULT_RETURN.  The argument is a C expression.  The
405    base method returns this expression's value.
406 
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.  */
410 
411 #define TARGET_DEFAULT_IGNORE()
412 #define TARGET_DEFAULT_NORETURN(ARG)
413 #define TARGET_DEFAULT_RETURN(ARG)
414 #define TARGET_DEFAULT_FUNC(ARG)
415 
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.  */
420 
421 struct target_info
422 {
423   /* Name of this target.  */
424   const char *shortname;
425 
426   /* Name for printing.  */
427   const char *longname;
428 
429   /* Documentation.  Does not include trailing newline, and starts
430      with a one-line description (probably similar to longname).  */
431   const char *doc;
432 };
433 
434 /* A GDB target.
435 
436    Each inferior has a stack of these.  See overall description at the
437    top.
438 
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.
447 
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.  */
451 
452 struct target_ops
453   : public refcounted_object
454   {
455     /* Return this target's stratum.  */
456     virtual strata stratum () const = 0;
457 
458     /* To the target under this one.  */
459     target_ops *beneath () const;
460 
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.  */
~target_opstarget_ops465     virtual ~target_ops () {}
466 
467     /* Return a reference to this target's unique target_info
468        object.  */
469     virtual const target_info &info () const = 0;
470 
471     /* Name this target type.  */
shortnametarget_ops472     const char *shortname () const
473     { return info ().shortname; }
474 
longnametarget_ops475     const char *longname () const
476     { return info ().longname; }
477 
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 ();
482 
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 ();
495 
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 ();
503 
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 ());
510 
511     /* Ensure that all resumed threads are committed to the target.
512 
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 ();
518 
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 ());
535 
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 ());
545 
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);
560 
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);
573 
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);
584 
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);
593 
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);
608 
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);
613 
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);
619 
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);
624 
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);
661 
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);
667 
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);
679 
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 ();
684 
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 ();
689 
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 ();
694 
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 ());
726 
727     /* Provide default values for all "must have" methods.  */
has_all_memorytarget_ops728     virtual bool has_all_memory () { return false; }
has_memorytarget_ops729     virtual bool has_memory () { return false; }
has_stacktarget_ops730     virtual bool has_stack () { return false; }
has_registerstarget_ops731     virtual bool has_registers () { return false; }
has_executiontarget_ops732     virtual bool has_execution (inferior *inf) { return false; }
733 
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 (int)
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 ());
794 
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.
802 
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.
813 
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.
822 
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.
826 
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.
834 
835        See target_read and target_write for more information.  One,
836        and only one, of readbuf or writebuf must be non-NULL.  */
837 
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);
845 
846     /* Return the limit on the size of any single memory transfer
847        for the target.  */
848 
849     virtual ULONGEST get_memory_xfer_limit ()
850       TARGET_DEFAULT_RETURN (ULONGEST_MAX);
851 
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.
856 
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.
861 
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> ());
867 
868     /* Erases the region of flash memory starting at ADDRESS, of
869        length LENGTH.
870 
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 ());
875 
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 ());
882 
883     /* Describe the architecture-specific features of the current
884        inferior.
885 
886        Returns the description found, or nullptr if no description was
887        available.
888 
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);
896 
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);
903 
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);
911 
912     /* Search SEARCH_SPACE_LEN bytes beginning at START_ADDR for the
913        sequence of bytes in PATTERN with length PATTERN_LEN.
914 
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);
922 
923     /* Can target execute in reverse?  */
924     virtual bool can_execute_reverse ()
925       TARGET_DEFAULT_RETURN (false);
926 
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);
932 
933     /* Does this target support debugging multiple processes
934        simultaneously?  */
935     virtual bool supports_multi_process ()
936       TARGET_DEFAULT_RETURN (false);
937 
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);
942 
943     /* Does this target support disabling address space randomization?  */
944     virtual bool supports_disable_randomization ()
945       TARGET_DEFAULT_FUNC (find_default_supports_disable_randomization);
946 
947     /* Does this target support the tracenz bytecode for string collection?  */
948     virtual bool supports_string_tracing ()
949       TARGET_DEFAULT_RETURN (false);
950 
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);
955 
956     /* Does this target support native dumpcore API?  */
957     virtual bool supports_dumpcore ()
958       TARGET_DEFAULT_RETURN (false);
959 
960     /* Generate the core file with native target API.  */
961     virtual void dumpcore (const char *filename)
962       TARGET_DEFAULT_IGNORE ();
963 
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);
968 
969     /* Determine current architecture of thread PTID.
970 
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);
978 
979     /* Target file operations.  */
980 
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);
985 
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);
996 
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);
1002 
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);
1008 
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);
1013 
1014     /* Close FD on the target.  Return 0, or -1 if an error occurs
1015        (and set *TARGET_ERRNO).  */
1016     virtual int fileio_close (int fd, fileio_error *target_errno);
1017 
1018     /* Unlink FILENAME on the target, in the filesystem as seen by
1019        INF.  If INF is NULL, use the filesystem seen by the debugger
1020        (GDB or, for remote targets, the remote stub).  Return 0, or
1021        -1 if an error occurs (and set *TARGET_ERRNO).  */
1022     virtual int fileio_unlink (struct inferior *inf,
1023                                      const char *filename,
1024                                      fileio_error *target_errno);
1025 
1026     /* Read value of symbolic link FILENAME on the target, in the
1027        filesystem as seen by INF.  If INF is NULL, use the filesystem
1028        seen by the debugger (GDB or, for remote targets, the remote
1029        stub).  Return a string, or an empty optional if an error
1030        occurs (and set *TARGET_ERRNO).  */
1031     virtual std::optional<std::string> fileio_readlink (struct inferior *inf,
1032                                                                       const char *filename,
1033                                                                       fileio_error *target_errno);
1034 
1035     /* Implement the "info proc" command.  Returns true if the target
1036        actually implemented the command, false otherwise.  */
1037     virtual bool info_proc (const char *, enum info_proc_what);
1038 
1039     /* Tracepoint-related operations.  */
1040 
1041     /* Prepare the target for a tracing run.  */
1042     virtual void trace_init ()
1043       TARGET_DEFAULT_NORETURN (tcomplain ());
1044 
1045     /* Send full details of a tracepoint location to the target.  */
1046     virtual void download_tracepoint (struct bp_location *location)
1047       TARGET_DEFAULT_NORETURN (tcomplain ());
1048 
1049     /* Is the target able to download tracepoint locations in current
1050        state?  */
1051     virtual bool can_download_tracepoint ()
1052       TARGET_DEFAULT_RETURN (false);
1053 
1054     /* Send full details of a trace state variable to the target.  */
1055     virtual void download_trace_state_variable (const trace_state_variable &tsv)
1056       TARGET_DEFAULT_NORETURN (tcomplain ());
1057 
1058     /* Enable a tracepoint on the target.  */
1059     virtual void enable_tracepoint (struct bp_location *location)
1060       TARGET_DEFAULT_NORETURN (tcomplain ());
1061 
1062     /* Disable a tracepoint on the target.  */
1063     virtual void disable_tracepoint (struct bp_location *location)
1064       TARGET_DEFAULT_NORETURN (tcomplain ());
1065 
1066     /* Inform the target info of memory regions that are readonly
1067        (such as text sections), and so it should return data from
1068        those rather than look in the trace buffer.  */
1069     virtual void trace_set_readonly_regions ()
1070       TARGET_DEFAULT_NORETURN (tcomplain ());
1071 
1072     /* Start a trace run.  */
1073     virtual void trace_start ()
1074       TARGET_DEFAULT_NORETURN (tcomplain ());
1075 
1076     /* Get the current status of a tracing run.  */
1077     virtual int get_trace_status (struct trace_status *ts)
1078       TARGET_DEFAULT_RETURN (-1);
1079 
1080     virtual void get_tracepoint_status (tracepoint *tp,
1081                                                   struct uploaded_tp *utp)
1082       TARGET_DEFAULT_NORETURN (tcomplain ());
1083 
1084     /* Stop a trace run.  */
1085     virtual void trace_stop ()
1086       TARGET_DEFAULT_NORETURN (tcomplain ());
1087 
1088    /* Ask the target to find a trace frame of the given type TYPE,
1089       using NUM, ADDR1, and ADDR2 as search parameters.  Returns the
1090       number of the trace frame, and also the tracepoint number at
1091       TPP.  If no trace frame matches, return -1.  May throw if the
1092       operation fails.  */
1093     virtual int trace_find (enum trace_find_type type, int num,
1094                                   CORE_ADDR addr1, CORE_ADDR addr2, int *tpp)
1095       TARGET_DEFAULT_RETURN (-1);
1096 
1097     /* Get the value of the trace state variable number TSV, returning
1098        1 if the value is known and writing the value itself into the
1099        location pointed to by VAL, else returning 0.  */
1100     virtual bool get_trace_state_variable_value (int tsv, LONGEST *val)
1101       TARGET_DEFAULT_RETURN (false);
1102 
1103     virtual int save_trace_data (const char *filename)
1104       TARGET_DEFAULT_NORETURN (tcomplain ());
1105 
1106     virtual int upload_tracepoints (struct uploaded_tp **utpp)
1107       TARGET_DEFAULT_RETURN (0);
1108 
1109     virtual int upload_trace_state_variables (struct uploaded_tsv **utsvp)
1110       TARGET_DEFAULT_RETURN (0);
1111 
1112     virtual LONGEST get_raw_trace_data (gdb_byte *buf,
1113                                                   ULONGEST offset, LONGEST len)
1114       TARGET_DEFAULT_NORETURN (tcomplain ());
1115 
1116     /* Get the minimum length of instruction on which a fast tracepoint
1117        may be set on the target.  If this operation is unsupported,
1118        return -1.  If for some reason the minimum length cannot be
1119        determined, return 0.  */
1120     virtual int get_min_fast_tracepoint_insn_len ()
1121       TARGET_DEFAULT_RETURN (-1);
1122 
1123     /* Set the target's tracing behavior in response to unexpected
1124        disconnection - set VAL to 1 to keep tracing, 0 to stop.  */
1125     virtual void set_disconnected_tracing (int val)
1126       TARGET_DEFAULT_IGNORE ();
1127     virtual void set_circular_trace_buffer (int val)
1128       TARGET_DEFAULT_IGNORE ();
1129     /* Set the size of trace buffer in the target.  */
1130     virtual void set_trace_buffer_size (LONGEST val)
1131       TARGET_DEFAULT_IGNORE ();
1132 
1133     /* Add/change textual notes about the trace run, returning true if
1134        successful, false otherwise.  */
1135     virtual bool set_trace_notes (const char *user, const char *notes,
1136                                           const char *stopnotes)
1137       TARGET_DEFAULT_RETURN (false);
1138 
1139     /* Return the processor core that thread PTID was last seen on.
1140        This information is updated only when:
1141        - update_thread_list is called
1142        - thread stops
1143        If the core cannot be determined -- either for the specified
1144        thread, or right now, or in this debug session, or for this
1145        target -- return -1.  */
1146     virtual int core_of_thread (ptid_t ptid)
1147       TARGET_DEFAULT_RETURN (-1);
1148 
1149     /* Verify that the memory in the [MEMADDR, MEMADDR+SIZE) range
1150        matches the contents of [DATA,DATA+SIZE).  Returns 1 if there's
1151        a match, 0 if there's a mismatch, and -1 if an error is
1152        encountered while reading memory.  */
1153     virtual int verify_memory (const gdb_byte *data,
1154                                      CORE_ADDR memaddr, ULONGEST size)
1155       TARGET_DEFAULT_FUNC (default_verify_memory);
1156 
1157     /* Return the address of the start of the Thread Information Block
1158        a Windows OS specific feature.  */
1159     virtual bool get_tib_address (ptid_t ptid, CORE_ADDR *addr)
1160       TARGET_DEFAULT_NORETURN (tcomplain ());
1161 
1162     /* Send the new settings of write permission variables.  */
1163     virtual void set_permissions ()
1164       TARGET_DEFAULT_IGNORE ();
1165 
1166     /* Look for a static tracepoint marker at ADDR, and fill in MARKER
1167        with its details.  Return true on success, false on failure.  */
1168     virtual bool static_tracepoint_marker_at (CORE_ADDR,
1169                                                         static_tracepoint_marker *marker)
1170       TARGET_DEFAULT_RETURN (false);
1171 
1172     /* Return a vector of all tracepoints markers string id ID, or all
1173        markers if ID is NULL.  */
1174     virtual std::vector<static_tracepoint_marker>
1175       static_tracepoint_markers_by_strid (const char *id)
1176       TARGET_DEFAULT_NORETURN (tcomplain ());
1177 
1178     /* Return a traceframe info object describing the current
1179        traceframe's contents.  This method should not cache data;
1180        higher layers take care of caching, invalidating, and
1181        re-fetching when necessary.  */
1182     virtual traceframe_info_up traceframe_info ()
1183       TARGET_DEFAULT_NORETURN (tcomplain ());
1184 
1185     /* Ask the target to use or not to use agent according to USE.
1186        Return true if successful, false otherwise.  */
1187     virtual bool use_agent (bool use)
1188       TARGET_DEFAULT_NORETURN (tcomplain ());
1189 
1190     /* Is the target able to use agent in current state?  */
1191     virtual bool can_use_agent ()
1192       TARGET_DEFAULT_RETURN (false);
1193 
1194     /* Enable branch tracing for TP using CONF configuration.
1195        Return a branch trace target information struct for reading and for
1196        disabling branch trace.  */
1197     virtual struct btrace_target_info *enable_btrace (thread_info *tp,
1198                                                                   const struct btrace_config *conf)
1199       TARGET_DEFAULT_NORETURN (tcomplain ());
1200 
1201     /* Disable branch tracing and deallocate TINFO.  */
1202     virtual void disable_btrace (struct btrace_target_info *tinfo)
1203       TARGET_DEFAULT_NORETURN (tcomplain ());
1204 
1205     /* Disable branch tracing and deallocate TINFO.  This function is similar
1206        to to_disable_btrace, except that it is called during teardown and is
1207        only allowed to perform actions that are safe.  A counter-example would
1208        be attempting to talk to a remote target.  */
1209     virtual void teardown_btrace (struct btrace_target_info *tinfo)
1210       TARGET_DEFAULT_NORETURN (tcomplain ());
1211 
1212     /* Read branch trace data for the thread indicated by BTINFO into DATA.
1213        DATA is cleared before new trace is added.  */
1214     virtual enum btrace_error read_btrace (struct btrace_data *data,
1215                                                      struct btrace_target_info *btinfo,
1216                                                      enum btrace_read_type type)
1217       TARGET_DEFAULT_NORETURN (tcomplain ());
1218 
1219     /* Get the branch trace configuration.  */
1220     virtual const struct btrace_config *btrace_conf (const struct btrace_target_info *)
1221       TARGET_DEFAULT_RETURN (NULL);
1222 
1223     /* Current recording method.  */
1224     virtual enum record_method record_method (ptid_t ptid)
1225       TARGET_DEFAULT_RETURN (RECORD_METHOD_NONE);
1226 
1227     /* Stop trace recording.  */
1228     virtual void stop_recording ()
1229       TARGET_DEFAULT_IGNORE ();
1230 
1231     /* Print information about the recording.  */
1232     virtual void info_record ()
1233       TARGET_DEFAULT_IGNORE ();
1234 
1235     /* Save the recorded execution trace into a file.  */
1236     virtual void save_record (const char *filename)
1237       TARGET_DEFAULT_NORETURN (tcomplain ());
1238 
1239     /* Delete the recorded execution trace from the current position
1240        onwards.  */
1241     virtual bool supports_delete_record ()
1242       TARGET_DEFAULT_RETURN (false);
1243     virtual void delete_record ()
1244       TARGET_DEFAULT_NORETURN (tcomplain ());
1245 
1246     /* Query if the record target is currently replaying PTID.  */
1247     virtual bool record_is_replaying (ptid_t ptid)
1248       TARGET_DEFAULT_RETURN (false);
1249 
1250     /* Query if the record target will replay PTID if it were resumed in
1251        execution direction DIR.  */
1252     virtual bool record_will_replay (ptid_t ptid, int dir)
1253       TARGET_DEFAULT_RETURN (false);
1254 
1255     /* Stop replaying.  */
1256     virtual void record_stop_replaying ()
1257       TARGET_DEFAULT_IGNORE ();
1258 
1259     /* Go to the begin of the execution trace.  */
1260     virtual void goto_record_begin ()
1261       TARGET_DEFAULT_NORETURN (tcomplain ());
1262 
1263     /* Go to the end of the execution trace.  */
1264     virtual void goto_record_end ()
1265       TARGET_DEFAULT_NORETURN (tcomplain ());
1266 
1267     /* Go to a specific location in the recorded execution trace.  */
1268     virtual void goto_record (ULONGEST insn)
1269       TARGET_DEFAULT_NORETURN (tcomplain ());
1270 
1271     /* Disassemble SIZE instructions in the recorded execution trace from
1272        the current position.
1273        If SIZE < 0, disassemble abs (SIZE) preceding instructions; otherwise,
1274        disassemble SIZE succeeding instructions.  */
1275     virtual void insn_history (int size, gdb_disassembly_flags flags)
1276       TARGET_DEFAULT_NORETURN (tcomplain ());
1277 
1278     /* Disassemble SIZE instructions in the recorded execution trace around
1279        FROM.
1280        If SIZE < 0, disassemble abs (SIZE) instructions before FROM; otherwise,
1281        disassemble SIZE instructions after FROM.  */
1282     virtual void insn_history_from (ULONGEST from, int size,
1283                                             gdb_disassembly_flags flags)
1284       TARGET_DEFAULT_NORETURN (tcomplain ());
1285 
1286     /* Disassemble a section of the recorded execution trace from instruction
1287        BEGIN (inclusive) to instruction END (inclusive).  */
1288     virtual void insn_history_range (ULONGEST begin, ULONGEST end,
1289                                              gdb_disassembly_flags flags)
1290       TARGET_DEFAULT_NORETURN (tcomplain ());
1291 
1292     /* Print a function trace of the recorded execution trace.
1293        If SIZE < 0, print abs (SIZE) preceding functions; otherwise, print SIZE
1294        succeeding functions.  */
1295     virtual void call_history (int size, record_print_flags flags)
1296       TARGET_DEFAULT_NORETURN (tcomplain ());
1297 
1298     /* Print a function trace of the recorded execution trace starting
1299        at function FROM.
1300        If SIZE < 0, print abs (SIZE) functions before FROM; otherwise, print
1301        SIZE functions after FROM.  */
1302     virtual void call_history_from (ULONGEST begin, int size, record_print_flags flags)
1303       TARGET_DEFAULT_NORETURN (tcomplain ());
1304 
1305     /* Print a function trace of an execution trace section from function BEGIN
1306        (inclusive) to function END (inclusive).  */
1307     virtual void call_history_range (ULONGEST begin, ULONGEST end, record_print_flags flags)
1308       TARGET_DEFAULT_NORETURN (tcomplain ());
1309 
1310     /* True if TARGET_OBJECT_LIBRARIES_SVR4 may be read with a
1311        non-empty annex.  */
1312     virtual bool augmented_libraries_svr4_read ()
1313       TARGET_DEFAULT_RETURN (false);
1314 
1315     /* Those unwinders are tried before any other arch unwinders.  If
1316        SELF doesn't have unwinders, it should delegate to the
1317        "beneath" target.  */
1318     virtual const struct frame_unwind *get_unwinder ()
1319       TARGET_DEFAULT_RETURN (NULL);
1320 
1321     virtual const struct frame_unwind *get_tailcall_unwinder ()
1322       TARGET_DEFAULT_RETURN (NULL);
1323 
1324     /* Prepare to generate a core file.  */
1325     virtual void prepare_to_generate_core ()
1326       TARGET_DEFAULT_IGNORE ();
1327 
1328     /* Cleanup after generating a core file.  */
1329     virtual void done_generating_core ()
1330       TARGET_DEFAULT_IGNORE ();
1331 
1332     /* Returns true if the target supports memory tagging, false otherwise.  */
1333     virtual bool supports_memory_tagging ()
1334       TARGET_DEFAULT_RETURN (false);
1335 
1336     /* Return the allocated memory tags of type TYPE associated with
1337        [ADDRESS, ADDRESS + LEN) in TAGS.
1338 
1339        LEN is the number of bytes in the memory range.  TAGS is a vector of
1340        bytes containing the tags found in the above memory range.
1341 
1342        It is up to the architecture/target to interpret the bytes in the TAGS
1343        vector and read the tags appropriately.
1344 
1345        Returns true if fetching the tags succeeded and false otherwise.  */
1346     virtual bool fetch_memtags (CORE_ADDR address, size_t len,
1347                                         gdb::byte_vector &tags, int type)
1348       TARGET_DEFAULT_NORETURN (tcomplain ());
1349 
1350     /* Write the allocation tags of type TYPE contained in TAGS to the memory
1351        range [ADDRESS, ADDRESS + LEN).
1352 
1353        LEN is the number of bytes in the memory range.  TAGS is a vector of
1354        bytes containing the tags to be stored to the memory range.
1355 
1356        It is up to the architecture/target to interpret the bytes in the TAGS
1357        vector and store them appropriately.
1358 
1359        Returns true if storing the tags succeeded and false otherwise.  */
1360     virtual bool store_memtags (CORE_ADDR address, size_t len,
1361                                         const gdb::byte_vector &tags, int type)
1362       TARGET_DEFAULT_NORETURN (tcomplain ());
1363 
1364     /* Returns true if ADDRESS is tagged, otherwise returns false.  */
1365     virtual bool is_address_tagged (gdbarch *gdbarch, CORE_ADDR address)
1366       TARGET_DEFAULT_NORETURN (tcomplain ());
1367 
1368     /* Return the x86 XSAVE extended state area layout.  */
1369     virtual x86_xsave_layout fetch_x86_xsave_layout ()
1370       TARGET_DEFAULT_RETURN (x86_xsave_layout ());
1371   };
1372 
1373 /* Deleter for std::unique_ptr.  See comments in
1374    target_ops::~target_ops and target_ops::close about heap-allocated
1375    targets.  */
1376 struct target_ops_deleter
1377 {
operatortarget_ops_deleter1378   void operator() (target_ops *target)
1379   {
1380     target->close ();
1381   }
1382 };
1383 
1384 /* A unique pointer for target_ops.  */
1385 typedef std::unique_ptr<target_ops, target_ops_deleter> target_ops_up;
1386 
1387 /* A policy class to interface gdb::ref_ptr with target_ops.  */
1388 
1389 struct target_ops_ref_policy
1390 {
increftarget_ops_ref_policy1391   static void incref (target_ops *t)
1392   {
1393     t->incref ();
1394   }
1395 
1396   /* Decrement the reference count on T, and, if the reference count
1397      reaches zero, close the target.  */
1398   static void decref (target_ops *t);
1399 };
1400 
1401 /* A gdb::ref_ptr pointer to a target_ops.  */
1402 typedef gdb::ref_ptr<target_ops, target_ops_ref_policy> target_ops_ref;
1403 
1404 /* Native target backends call this once at initialization time to
1405    inform the core about which is the target that can respond to "run"
1406    or "attach".  Note: native targets are always singletons.  */
1407 extern void set_native_target (target_ops *target);
1408 
1409 /* Get the registered native target, if there's one.  Otherwise return
1410    NULL.  */
1411 extern target_ops *get_native_target ();
1412 
1413 /* Type that manages a target stack.  See description of target stacks
1414    and strata at the top of the file.  */
1415 
1416 class target_stack
1417 {
1418 public:
1419   target_stack () = default;
1420   DISABLE_COPY_AND_ASSIGN (target_stack);
1421 
1422   /* Push a new target into the stack of the existing target
1423      accessors, possibly superseding some existing accessor.  */
1424   void push (target_ops *t);
1425 
1426   /* Remove a target from the stack, wherever it may be.  Return true
1427      if it was removed, false otherwise.  */
1428   bool unpush (target_ops *t);
1429 
1430   /* Returns true if T is pushed on the target stack.  */
is_pushed(const target_ops * t)1431   bool is_pushed (const target_ops *t) const
1432   { return at (t->stratum ()) == t; }
1433 
1434   /* Return the target at STRATUM.  */
at(strata stratum)1435   target_ops *at (strata stratum) const { return m_stack[stratum].get (); }
1436 
1437   /* Return the target at the top of the stack.  */
top()1438   target_ops *top () const { return at (m_top); }
1439 
1440   /* Find the next target down the stack from the specified target.  */
1441   target_ops *find_beneath (const target_ops *t) const;
1442 
1443 private:
1444   /* The stratum of the top target.  */
1445   enum strata m_top {};
1446 
1447   /* The stack, represented as an array, with one slot per stratum.
1448      If no target is pushed at some stratum, the corresponding slot is
1449      null.  */
1450   std::array<target_ops_ref, (int) debug_stratum + 1> m_stack;
1451 };
1452 
1453 /* Return the dummy target.  */
1454 extern target_ops *get_dummy_target ();
1455 
1456 /* Define easy words for doing these operations on our current target.  */
1457 
1458 extern const char *target_shortname ();
1459 
1460 /* Find the correct target to use for "attach".  If a target on the
1461    current stack supports attaching, then it is returned.  Otherwise,
1462    the default run target is returned.  */
1463 
1464 extern struct target_ops *find_attach_target (void);
1465 
1466 /* Find the correct target to use for "run".  If a target on the
1467    current stack supports creating a new inferior, then it is
1468    returned.  Otherwise, the default run target is returned.  */
1469 
1470 extern struct target_ops *find_run_target (void);
1471 
1472 /* Some targets don't generate traps when attaching to the inferior,
1473    or their target_attach implementation takes care of the waiting.
1474    These targets must set to_attach_no_wait.  */
1475 
1476 extern bool target_attach_no_wait ();
1477 
1478 /* The target_attach operation places a process under debugger control,
1479    and stops the process.
1480 
1481    This operation provides a target-specific hook that allows the
1482    necessary bookkeeping to be performed after an attach completes.  */
1483 
1484 extern void target_post_attach (int pid);
1485 
1486 /* Display a message indicating we're about to attach to a given
1487    process.  */
1488 
1489 extern void target_announce_attach (int from_tty, int pid);
1490 
1491 /* Display a message indicating we're about to detach from the current
1492    inferior process.  */
1493 
1494 extern void target_announce_detach (int from_tty);
1495 
1496 /* Takes a program previously attached to and detaches it.
1497    The program may resume execution (some targets do, some don't) and will
1498    no longer stop on signals, etc.  We better not have left any breakpoints
1499    in the program or it'll die when it hits one.  FROM_TTY says whether to be
1500    verbose or not.  */
1501 
1502 extern void target_detach (inferior *inf, int from_tty);
1503 
1504 /* Disconnect from the current target without resuming it (leaving it
1505    waiting for a debugger).  */
1506 
1507 extern void target_disconnect (const char *, int);
1508 
1509 /* Resume execution (or prepare for execution) of the current thread
1510    (INFERIOR_PTID), while optionally letting other threads of the
1511    current process or all processes run free.
1512 
1513    STEP says whether to hardware single-step the current thread or to
1514    let it run free; SIGNAL is the signal to be given to the current
1515    thread, or GDB_SIGNAL_0 for no signal.  The caller may not pass
1516    GDB_SIGNAL_DEFAULT.
1517 
1518    SCOPE_PTID indicates the resumption scope.  I.e., which threads
1519    (other than the current) run free.  If resuming a single thread,
1520    SCOPE_PTID is the same thread as the current thread.  A wildcard
1521    SCOPE_PTID (all threads, or all threads of process) lets threads
1522    other than the current (for which the wildcard SCOPE_PTID matches)
1523    resume with their 'thread->suspend.stop_signal' signal (usually
1524    GDB_SIGNAL_0) if it is in "pass" state, or with no signal if in "no
1525    pass" state.  Note neither STEP nor SIGNAL apply to any thread
1526    other than the current.
1527 
1528    In order to efficiently handle batches of resumption requests,
1529    targets may implement this method such that it records the
1530    resumption request, but defers the actual resumption to the
1531    target_commit_resume method implementation.  See
1532    target_commit_resume below.  */
1533 extern void target_resume (ptid_t scope_ptid,
1534                                  int step, enum gdb_signal signal);
1535 
1536 /* Ensure that all resumed threads are committed to the target.
1537 
1538    See the description of process_stratum_target::commit_resumed_state
1539    for more details.  */
1540 extern void target_commit_resumed ();
1541 
1542 /* For target_read_memory see target/target.h.  */
1543 
1544 /* The default target_ops::to_wait implementation.  */
1545 
1546 extern ptid_t default_target_wait (struct target_ops *ops,
1547                                            ptid_t ptid,
1548                                            struct target_waitstatus *status,
1549                                            target_wait_flags options);
1550 
1551 /* Return true if the target has pending events to report to the core.
1552    See target_ops::has_pending_events().  */
1553 
1554 extern bool target_has_pending_events ();
1555 
1556 /* Fetch at least register REGNO, or all regs if regno == -1.  No result.  */
1557 
1558 extern void target_fetch_registers (struct regcache *regcache, int regno);
1559 
1560 /* Store at least register REGNO, or all regs if REGNO == -1.
1561    It can store as many registers as it wants to, so target_prepare_to_store
1562    must have been previously called.  Calls error() if there are problems.  */
1563 
1564 extern void target_store_registers (struct regcache *regcache, int regs);
1565 
1566 /* Get ready to modify the registers array.  On machines which store
1567    individual registers, this doesn't need to do anything.  On machines
1568    which store all the registers in one fell swoop, this makes sure
1569    that REGISTERS contains all the registers from the program being
1570    debugged.  */
1571 
1572 extern void target_prepare_to_store (regcache *regcache);
1573 
1574 /* Implement the "info proc" command.  This returns one if the request
1575    was handled, and zero otherwise.  It can also throw an exception if
1576    an error was encountered while attempting to handle the
1577    request.  */
1578 
1579 int target_info_proc (const char *, enum info_proc_what);
1580 
1581 /* Returns true if this target can disable address space randomization.  */
1582 
1583 int target_supports_disable_randomization (void);
1584 
1585 /* Returns true if this target can enable and disable tracepoints
1586    while a trace experiment is running.  */
1587 
1588 extern bool target_supports_enable_disable_tracepoint ();
1589 
1590 extern bool target_supports_string_tracing ();
1591 
1592 /* Returns true if this target can handle breakpoint conditions
1593    on its end.  */
1594 
1595 extern bool target_supports_evaluation_of_breakpoint_conditions ();
1596 
1597 /* Does this target support dumpcore API?  */
1598 
1599 extern bool target_supports_dumpcore ();
1600 
1601 /* Generate the core file with target API.  */
1602 
1603 extern void target_dumpcore (const char *filename);
1604 
1605 /* Returns true if this target can handle breakpoint commands
1606    on its end.  */
1607 
1608 extern bool target_can_run_breakpoint_commands ();
1609 
1610 /* For target_read_memory see target/target.h.  */
1611 
1612 extern int target_read_raw_memory (CORE_ADDR memaddr, gdb_byte *myaddr,
1613                                            ssize_t len);
1614 
1615 extern int target_read_stack (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len);
1616 
1617 extern int target_read_code (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len);
1618 
1619 /* For target_write_memory see target/target.h.  */
1620 
1621 extern int target_write_raw_memory (CORE_ADDR memaddr, const gdb_byte *myaddr,
1622                                             ssize_t len);
1623 
1624 /* Fetches the target's memory map.  If one is found it is sorted
1625    and returned, after some consistency checking.  Otherwise, NULL
1626    is returned.  */
1627 std::vector<mem_region> target_memory_map (void);
1628 
1629 /* Erases all flash memory regions on the target.  */
1630 void flash_erase_command (const char *cmd, int from_tty);
1631 
1632 /* Erase the specified flash region.  */
1633 void target_flash_erase (ULONGEST address, LONGEST length);
1634 
1635 /* Finish a sequence of flash operations.  */
1636 void target_flash_done (void);
1637 
1638 /* Describes a request for a memory write operation.  */
1639 struct memory_write_request
1640 {
1641   memory_write_request (ULONGEST begin_, ULONGEST end_,
1642                               gdb_byte *data_ = nullptr, void *baton_ = nullptr)
beginmemory_write_request1643     : begin (begin_), end (end_), data (data_), baton (baton_)
1644   {}
1645 
1646   /* Begining address that must be written.  */
1647   ULONGEST begin;
1648   /* Past-the-end address.  */
1649   ULONGEST end;
1650   /* The data to write.  */
1651   gdb_byte *data;
1652   /* A callback baton for progress reporting for this request.  */
1653   void *baton;
1654 };
1655 
1656 /* Enumeration specifying different flash preservation behaviour.  */
1657 enum flash_preserve_mode
1658   {
1659     flash_preserve,
1660     flash_discard
1661   };
1662 
1663 /* Write several memory blocks at once.  This version can be more
1664    efficient than making several calls to target_write_memory, in
1665    particular because it can optimize accesses to flash memory.
1666 
1667    Moreover, this is currently the only memory access function in gdb
1668    that supports writing to flash memory, and it should be used for
1669    all cases where access to flash memory is desirable.
1670 
1671    REQUESTS is the vector of memory_write_request.
1672    PRESERVE_FLASH_P indicates what to do with blocks which must be
1673      erased, but not completely rewritten.
1674    PROGRESS_CB is a function that will be periodically called to provide
1675      feedback to user.  It will be called with the baton corresponding
1676      to the request currently being written.  It may also be called
1677      with a NULL baton, when preserved flash sectors are being rewritten.
1678 
1679    The function returns 0 on success, and error otherwise.  */
1680 int target_write_memory_blocks
1681     (const std::vector<memory_write_request> &requests,
1682      enum flash_preserve_mode preserve_flash_p,
1683      void (*progress_cb) (ULONGEST, void *));
1684 
1685 /* Print a line about the current target.  */
1686 
1687 extern void target_files_info ();
1688 
1689 /* Insert a breakpoint at address BP_TGT->placed_address in
1690    the target machine.  Returns 0 for success, and returns non-zero or
1691    throws an error (with a detailed failure reason error code and
1692    message) otherwise.  */
1693 
1694 extern int target_insert_breakpoint (struct gdbarch *gdbarch,
1695                                              struct bp_target_info *bp_tgt);
1696 
1697 /* Remove a breakpoint at address BP_TGT->placed_address in the target
1698    machine.  Result is 0 for success, non-zero for error.  */
1699 
1700 extern int target_remove_breakpoint (struct gdbarch *gdbarch,
1701                                              struct bp_target_info *bp_tgt,
1702                                              enum remove_bp_reason reason);
1703 
1704 /* Return true if the target stack has a non-default
1705   "terminal_ours" method.  */
1706 
1707 extern bool target_supports_terminal_ours (void);
1708 
1709 /* Kill the inferior process.   Make it go away.  */
1710 
1711 extern void target_kill (void);
1712 
1713 /* Load an executable file into the target process.  This is expected
1714    to not only bring new code into the target process, but also to
1715    update GDB's symbol tables to match.
1716 
1717    ARG contains command-line arguments, to be broken down with
1718    buildargv ().  The first non-switch argument is the filename to
1719    load, FILE; the second is a number (as parsed by strtoul (..., ...,
1720    0)), which is an offset to apply to the load addresses of FILE's
1721    sections.  The target may define switches, or other non-switch
1722    arguments, as it pleases.  */
1723 
1724 extern void target_load (const char *arg, int from_tty);
1725 
1726 /* On some targets, we can catch an inferior fork or vfork event when
1727    it occurs.  These functions insert/remove an already-created
1728    catchpoint for such events.  They return  0 for success, 1 if the
1729    catchpoint type is not supported and -1 for failure.  */
1730 
1731 extern int target_insert_fork_catchpoint (int pid);
1732 
1733 extern int target_remove_fork_catchpoint (int pid);
1734 
1735 extern int target_insert_vfork_catchpoint (int pid);
1736 
1737 extern int target_remove_vfork_catchpoint (int pid);
1738 
1739 /* Call the follow_fork method on the current target stack.
1740 
1741    This function is called when the inferior forks or vforks, to perform any
1742    bookkeeping and fiddling necessary to continue debugging either the parent,
1743    the child or both.  */
1744 
1745 void target_follow_fork (inferior *inf, ptid_t child_ptid,
1746                                target_waitkind fork_kind, bool follow_child,
1747                                bool detach_fork);
1748 
1749 /* Handle the target-specific bookkeeping required when the inferior makes an
1750    exec call.
1751 
1752    The current inferior at the time of the call is the inferior that did the
1753    exec.  FOLLOW_INF is the inferior in which execution continues post-exec.
1754    If "follow-exec-mode" is "same", FOLLOW_INF is the same as the current
1755    inferior, meaning that execution continues with the same inferior.  If
1756    "follow-exec-mode" is "new", FOLLOW_INF is a different inferior, meaning
1757    that execution continues in a new inferior.
1758 
1759    On exit, the target must leave FOLLOW_INF as the current inferior.  */
1760 
1761 void target_follow_exec (inferior *follow_inf, ptid_t ptid,
1762                                const char *execd_pathname);
1763 
1764 /* On some targets, we can catch an inferior exec event when it
1765    occurs.  These functions insert/remove an already-created
1766    catchpoint for such events.  They return  0 for success, 1 if the
1767    catchpoint type is not supported and -1 for failure.  */
1768 
1769 extern int target_insert_exec_catchpoint (int pid);
1770 
1771 extern int target_remove_exec_catchpoint (int pid);
1772 
1773 /* Syscall catch.
1774 
1775    NEEDED is true if any syscall catch (of any kind) is requested.
1776    If NEEDED is false, it means the target can disable the mechanism to
1777    catch system calls because there are no more catchpoints of this type.
1778 
1779    ANY_COUNT is nonzero if a generic (filter-less) syscall catch is
1780    being requested.  In this case, SYSCALL_COUNTS should be ignored.
1781 
1782    SYSCALL_COUNTS is an array of ints, indexed by syscall number.  An
1783    element in this array is nonzero if that syscall should be caught.
1784    This argument only matters if ANY_COUNT is zero.
1785 
1786    Return 0 for success, 1 if syscall catchpoints are not supported or -1
1787    for failure.  */
1788 
1789 extern int target_set_syscall_catchpoint
1790   (int pid, bool needed, int any_count,
1791    gdb::array_view<const int> syscall_counts);
1792 
1793 /* The debugger has completed a blocking wait() call.  There is now
1794    some process event that must be processed.  This function should
1795    be defined by those targets that require the debugger to perform
1796    cleanup or internal state changes in response to the process event.  */
1797 
1798 /* For target_mourn_inferior see target/target.h.  */
1799 
1800 /* Does target have enough data to do a run or attach command?  */
1801 
1802 extern int target_can_run ();
1803 
1804 /* Set list of signals to be handled in the target.
1805 
1806    PASS_SIGNALS is an array indexed by target signal number
1807    (enum gdb_signal).  For every signal whose entry in this array is
1808    non-zero, the target is allowed -but not required- to skip reporting
1809    arrival of the signal to the GDB core by returning from target_wait,
1810    and to pass the signal directly to the inferior instead.
1811 
1812    However, if the target is hardware single-stepping a thread that is
1813    about to receive a signal, it needs to be reported in any case, even
1814    if mentioned in a previous target_pass_signals call.   */
1815 
1816 extern void target_pass_signals
1817   (gdb::array_view<const unsigned char> pass_signals);
1818 
1819 /* Set list of signals the target may pass to the inferior.  This
1820    directly maps to the "handle SIGNAL pass/nopass" setting.
1821 
1822    PROGRAM_SIGNALS is an array indexed by target signal
1823    number (enum gdb_signal).  For every signal whose entry in this
1824    array is non-zero, the target is allowed to pass the signal to the
1825    inferior.  Signals not present in the array shall be silently
1826    discarded.  This does not influence whether to pass signals to the
1827    inferior as a result of a target_resume call.  This is useful in
1828    scenarios where the target needs to decide whether to pass or not a
1829    signal to the inferior without GDB core involvement, such as for
1830    example, when detaching (as threads may have been suspended with
1831    pending signals not reported to GDB).  */
1832 
1833 extern void target_program_signals
1834   (gdb::array_view<const unsigned char> program_signals);
1835 
1836 /* Check to see if a thread is still alive.  */
1837 
1838 extern int target_thread_alive (ptid_t ptid);
1839 
1840 /* Sync the target's threads with GDB's thread list.  */
1841 
1842 extern void target_update_thread_list (void);
1843 
1844 /* Make target stop in a continuable fashion.  (For instance, under
1845    Unix, this should act like SIGSTOP).  Note that this function is
1846    asynchronous: it does not wait for the target to become stopped
1847    before returning.  If this is the behavior you want please use
1848    target_stop_and_wait.  */
1849 
1850 extern void target_stop (ptid_t ptid);
1851 
1852 /* Interrupt the target.  Unlike target_stop, this does not specify
1853    which thread/process reports the stop.  For most target this acts
1854    like raising a SIGINT, though that's not absolutely required.  This
1855    function is asynchronous.  */
1856 
1857 extern void target_interrupt ();
1858 
1859 /* Pass a ^C, as determined to have been pressed by checking the quit
1860    flag, to the target, as if the user had typed the ^C on the
1861    inferior's controlling terminal while the inferior was in the
1862    foreground.  Remote targets may take the opportunity to detect the
1863    remote side is not responding and offer to disconnect.  */
1864 
1865 extern void target_pass_ctrlc (void);
1866 
1867 /* The default target_ops::to_pass_ctrlc implementation.  Simply calls
1868    target_interrupt.  */
1869 extern void default_target_pass_ctrlc (struct target_ops *ops);
1870 
1871 /* Send the specified COMMAND to the target's monitor
1872    (shell,interpreter) for execution.  The result of the query is
1873    placed in OUTBUF.  */
1874 
1875 extern void target_rcmd (const char *command, struct ui_file *outbuf);
1876 
1877 /* Does the target include memory?  (Dummy targets don't.)  */
1878 
1879 extern int target_has_memory ();
1880 
1881 /* Does the target have a stack?  (Exec files don't, VxWorks doesn't, until
1882    we start a process.)  */
1883 
1884 extern int target_has_stack ();
1885 
1886 /* Does the target have registers?  (Exec files don't.)  */
1887 
1888 extern int target_has_registers ();
1889 
1890 /* Does the target have execution?  Can we make it jump (through
1891    hoops), or pop its stack a few times?  This means that the current
1892    target is currently executing; for some targets, that's the same as
1893    whether or not the target is capable of execution, but there are
1894    also targets which can be current while not executing.  In that
1895    case this will become true after to_create_inferior or
1896    to_attach.  INF is the inferior to use; nullptr means to use the
1897    current inferior.  */
1898 
1899 extern bool target_has_execution (inferior *inf = nullptr);
1900 
1901 /* Can the target support the debugger control of thread execution?
1902    Can it lock the thread scheduler?  */
1903 
1904 extern bool target_can_lock_scheduler ();
1905 
1906 /* Controls whether async mode is permitted.  */
1907 extern bool target_async_permitted;
1908 
1909 /* Can the target support asynchronous execution?  */
1910 extern bool target_can_async_p ();
1911 
1912 /* An overload of the above that can be called when the target is not yet
1913    pushed, this calls TARGET::can_async_p directly.  */
1914 extern bool target_can_async_p (struct target_ops *target);
1915 
1916 /* Is the target in asynchronous execution mode?  */
1917 extern bool target_is_async_p ();
1918 
1919 /* Enables/disabled async target events.  */
1920 extern void target_async (bool enable);
1921 
1922 /* Enables/disables thread create and exit events.  */
1923 extern void target_thread_events (int enable);
1924 
1925 /* Returns true if the target supports setting thread options
1926    OPTIONS.  */
1927 extern bool target_supports_set_thread_options (gdb_thread_options options);
1928 
1929 /* Whether support for controlling the target backends always in
1930    non-stop mode is enabled.  */
1931 extern enum auto_boolean target_non_stop_enabled;
1932 
1933 /* Is the target in non-stop mode?  Some targets control the inferior
1934    in non-stop mode even with "set non-stop off".  Always true if "set
1935    non-stop" is on.  */
1936 extern bool target_is_non_stop_p ();
1937 
1938 /* Return true if at least one inferior has a non-stop target.  */
1939 extern bool exists_non_stop_target ();
1940 
1941 extern exec_direction_kind target_execution_direction ();
1942 
1943 /* Converts a process id to a string.  Usually, the string just contains
1944    `process xyz', but on some systems it may contain
1945    `process xyz thread abc'.  */
1946 
1947 extern std::string target_pid_to_str (ptid_t ptid);
1948 
1949 extern std::string normal_pid_to_str (ptid_t ptid);
1950 
1951 /* Return a short string describing extra information about PID,
1952    e.g. "sleeping", "runnable", "running on LWP 3".  Null return value
1953    is okay.  */
1954 
1955 extern const char *target_extra_thread_info (thread_info *tp);
1956 
1957 /* Return the thread's name, or NULL if the target is unable to determine it.
1958    The returned value must not be freed by the caller.
1959 
1960    You likely don't want to call this function, but use the thread_name
1961    function instead, which prefers the user-given thread name, if set.  */
1962 
1963 extern const char *target_thread_name (struct thread_info *);
1964 
1965 /* Given a pointer to a thread library specific thread handle and
1966    its length, return a pointer to the corresponding thread_info struct.  */
1967 
1968 extern struct thread_info *target_thread_handle_to_thread_info
1969   (const gdb_byte *thread_handle, int handle_len, struct inferior *inf);
1970 
1971 /* Given a thread, return the thread handle, a target-specific sequence of
1972    bytes which serves as a thread identifier within the program being
1973    debugged.  */
1974 extern gdb::array_view<const gdb_byte> target_thread_info_to_thread_handle
1975   (struct thread_info *);
1976 
1977 /* Attempts to find the pathname of the executable file
1978    that was run to create a specified process.
1979 
1980    The process PID must be stopped when this operation is used.
1981 
1982    If the executable file cannot be determined, NULL is returned.
1983 
1984    Else, a pointer to a character string containing the pathname
1985    is returned.  This string should be copied into a buffer by
1986    the client if the string will not be immediately used, or if
1987    it must persist.  */
1988 
1989 extern const char *target_pid_to_exec_file (int pid);
1990 
1991 /* See the to_thread_architecture description in struct target_ops.  */
1992 
1993 extern gdbarch *target_thread_architecture (ptid_t ptid);
1994 
1995 /*
1996  * Iterator function for target memory regions.
1997  * Calls a callback function once for each memory region 'mapped'
1998  * in the child process.  Defined as a simple macro rather than
1999  * as a function macro so that it can be tested for nullity.
2000  */
2001 
2002 extern int target_find_memory_regions (find_memory_region_ftype func,
2003                                                void *data);
2004 
2005 /*
2006  * Compose corefile .note section.
2007  */
2008 
2009 extern gdb::unique_xmalloc_ptr<char> target_make_corefile_notes (bfd *bfd,
2010                                                                                  int *size_p);
2011 
2012 /* Bookmark interfaces.  */
2013 extern gdb_byte *target_get_bookmark (const char *args, int from_tty);
2014 
2015 extern void target_goto_bookmark (const gdb_byte *arg, int from_tty);
2016 
2017 /* Hardware watchpoint interfaces.  */
2018 
2019 /* GDB's current model is that there are three "kinds" of watchpoints,
2020    with respect to when they trigger and how you can move past them.
2021 
2022    Those are: continuable, steppable, and non-steppable.
2023 
2024    Continuable watchpoints are like x86's -- those trigger after the
2025    memory access's side effects are fully committed to memory.  I.e.,
2026    they trap with the PC pointing at the next instruction already.
2027    Continuing past such a watchpoint is doable by just normally
2028    continuing, hence the name.
2029 
2030    Both steppable and non-steppable watchpoints trap before the memory
2031    access.  I.e, the PC points at the instruction that is accessing
2032    the memory.  So GDB needs to single-step once past the current
2033    instruction in order to make the access effective and check whether
2034    the instruction's side effects change the watched expression.
2035 
2036    Now, in order to step past that instruction, depending on
2037    architecture and target, you can have two situations:
2038 
2039    - steppable watchpoints: you can single-step with the watchpoint
2040      still armed, and the watchpoint won't trigger again.
2041 
2042    - non-steppable watchpoints: if you try to single-step with the
2043      watchpoint still armed, you'd trap the watchpoint again and the
2044      thread wouldn't make any progress.  So GDB needs to temporarily
2045      remove the watchpoint in order to step past it.
2046 
2047    If your target/architecture does not signal that it has either
2048    steppable or non-steppable watchpoints via either
2049    target_have_steppable_watchpoint or
2050    gdbarch_have_nonsteppable_watchpoint, GDB assumes continuable
2051    watchpoints.  */
2052 
2053 /* Returns true if we were stopped by a hardware watchpoint (memory read or
2054    write).  Only the INFERIOR_PTID task is being queried.  */
2055 
2056 extern bool target_stopped_by_watchpoint ();
2057 
2058 /* Returns true if the target stopped because it executed a
2059    software breakpoint instruction.  */
2060 
2061 extern bool target_stopped_by_sw_breakpoint ();
2062 
2063 extern bool target_supports_stopped_by_sw_breakpoint ();
2064 
2065 extern bool target_stopped_by_hw_breakpoint ();
2066 
2067 extern bool target_supports_stopped_by_hw_breakpoint ();
2068 
2069 /* True if we have steppable watchpoints  */
2070 
2071 extern bool target_have_steppable_watchpoint ();
2072 
2073 /* Provide defaults for hardware watchpoint functions.  */
2074 
2075 /* If the *_hw_breakpoint functions have not been defined
2076    elsewhere use the definitions in the target vector.  */
2077 
2078 /* Returns positive if we can set a hardware watchpoint of type TYPE.
2079    Returns negative if the target doesn't have enough hardware debug
2080    registers available.  Return zero if hardware watchpoint of type
2081    TYPE isn't supported.  TYPE is one of bp_hardware_watchpoint,
2082    bp_read_watchpoint, bp_write_watchpoint, or bp_hardware_breakpoint.
2083    CNT is the number of such watchpoints used so far, including this
2084    one.  OTHERTYPE is the number of watchpoints of other types than
2085    this one used so far.  */
2086 
2087 extern int target_can_use_hardware_watchpoint (bptype type, int cnt,
2088                                                          int othertype);
2089 
2090 /* Returns the number of debug registers needed to watch the given
2091    memory region, or zero if not supported.  */
2092 
2093 extern int target_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len);
2094 
2095 extern int target_can_do_single_step ();
2096 
2097 /* Set/clear a hardware watchpoint starting at ADDR, for LEN bytes.
2098    TYPE is 0 for write, 1 for read, and 2 for read/write accesses.
2099    COND is the expression for its condition, or NULL if there's none.
2100    Returns 0 for success, 1 if the watchpoint type is not supported,
2101    -1 for failure.  */
2102 
2103 extern int target_insert_watchpoint (CORE_ADDR addr, int len,
2104                                              target_hw_bp_type type, expression *cond);
2105 
2106 extern int target_remove_watchpoint (CORE_ADDR addr, int len,
2107                                              target_hw_bp_type type, expression *cond);
2108 
2109 /* Insert a new masked watchpoint at ADDR using the mask MASK.
2110    RW may be hw_read for a read watchpoint, hw_write for a write watchpoint
2111    or hw_access for an access watchpoint.  Returns 0 for success, 1 if
2112    masked watchpoints are not supported, -1 for failure.  */
2113 
2114 extern int target_insert_mask_watchpoint (CORE_ADDR, CORE_ADDR,
2115                                                     enum target_hw_bp_type);
2116 
2117 /* Remove a masked watchpoint at ADDR with 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, non-zero
2120    for failure.  */
2121 
2122 extern int target_remove_mask_watchpoint (CORE_ADDR, CORE_ADDR,
2123                                                     enum target_hw_bp_type);
2124 
2125 /* Insert a hardware breakpoint at address BP_TGT->placed_address in
2126    the target machine.  Returns 0 for success, and returns non-zero or
2127    throws an error (with a detailed failure reason error code and
2128    message) otherwise.  */
2129 
2130 extern int target_insert_hw_breakpoint (gdbarch *gdbarch,
2131                                                   bp_target_info *bp_tgt);
2132 
2133 extern int target_remove_hw_breakpoint (gdbarch *gdbarch,
2134                                                   bp_target_info *bp_tgt);
2135 
2136 /* Return number of debug registers needed for a ranged breakpoint,
2137    or -1 if ranged breakpoints are not supported.  */
2138 
2139 extern int target_ranged_break_num_registers (void);
2140 
2141 /* Return non-zero if target knows the data address which triggered this
2142    target_stopped_by_watchpoint, in such case place it to *ADDR_P.  Only the
2143    INFERIOR_PTID task is being queried.  */
2144 #define target_stopped_data_address(target, addr_p) \
2145   (target)->stopped_data_address (addr_p)
2146 
2147 /* Return non-zero if ADDR is within the range of a watchpoint spanning
2148    LENGTH bytes beginning at START.  */
2149 #define target_watchpoint_addr_within_range(target, addr, start, length) \
2150   (target)->watchpoint_addr_within_range (addr, start, length)
2151 
2152 /* Return non-zero if the target is capable of using hardware to evaluate
2153    the condition expression.  In this case, if the condition is false when
2154    the watched memory location changes, execution may continue without the
2155    debugger being notified.
2156 
2157    Due to limitations in the hardware implementation, it may be capable of
2158    avoiding triggering the watchpoint in some cases where the condition
2159    expression is false, but may report some false positives as well.
2160    For this reason, GDB will still evaluate the condition expression when
2161    the watchpoint triggers.  */
2162 
2163 extern bool target_can_accel_watchpoint_condition (CORE_ADDR addr, int len,
2164                                                                int type, expression *cond);
2165 
2166 /* Return number of debug registers needed for a masked watchpoint,
2167    -1 if masked watchpoints are not supported or -2 if the given address
2168    and mask combination cannot be used.  */
2169 
2170 extern int target_masked_watch_num_registers (CORE_ADDR addr, CORE_ADDR mask);
2171 
2172 /* Target can execute in reverse?  */
2173 
2174 extern bool target_can_execute_reverse ();
2175 
2176 extern const struct target_desc *target_read_description (struct target_ops *);
2177 
2178 extern ptid_t target_get_ada_task_ptid (long lwp, ULONGEST tid);
2179 
2180 /* Main entry point for searching memory.  */
2181 extern int target_search_memory (CORE_ADDR start_addr,
2182                                          ULONGEST search_space_len,
2183                                          const gdb_byte *pattern,
2184                                          ULONGEST pattern_len,
2185                                          CORE_ADDR *found_addrp);
2186 
2187 /* Target file operations.  */
2188 
2189 /* Return true if the filesystem seen by the current inferior
2190    is the local filesystem, zero otherwise.  */
2191 
2192 extern bool target_filesystem_is_local ();
2193 
2194 /* Open FILENAME on the target, in the filesystem as seen by INF,
2195    using FLAGS and MODE.  If INF is NULL, use the filesystem seen by
2196    the debugger (GDB or, for remote targets, the remote stub).  Return
2197    a target file descriptor, or -1 if an error occurs (and set
2198    *TARGET_ERRNO).  If WARN_IF_SLOW is true, print a warning message
2199    if the file is being accessed over a link that may be slow.  */
2200 extern int target_fileio_open (struct inferior *inf,
2201                                      const char *filename, int flags,
2202                                      int mode, bool warn_if_slow,
2203                                      fileio_error *target_errno);
2204 
2205 /* Write up to LEN bytes from WRITE_BUF to FD on the target.
2206    Return the number of bytes written, or -1 if an error occurs
2207    (and set *TARGET_ERRNO).  */
2208 extern int target_fileio_pwrite (int fd, const gdb_byte *write_buf, int len,
2209                                          ULONGEST offset, fileio_error *target_errno);
2210 
2211 /* Read up to LEN bytes FD on the target into READ_BUF.
2212    Return the number of bytes read, or -1 if an error occurs
2213    (and set *TARGET_ERRNO).  */
2214 extern int target_fileio_pread (int fd, gdb_byte *read_buf, int len,
2215                                         ULONGEST offset, fileio_error *target_errno);
2216 
2217 /* Get information about the file opened as FD on the target
2218    and put it in SB.  Return 0 on success, or -1 if an error
2219    occurs (and set *TARGET_ERRNO).  */
2220 extern int target_fileio_fstat (int fd, struct stat *sb,
2221                                         fileio_error *target_errno);
2222 
2223 /* Close FD on the target.  Return 0, or -1 if an error occurs
2224    (and set *TARGET_ERRNO).  */
2225 extern int target_fileio_close (int fd, fileio_error *target_errno);
2226 
2227 /* Unlink FILENAME on the target, in the filesystem as seen by INF.
2228    If INF is NULL, use the filesystem seen by the debugger (GDB or,
2229    for remote targets, the remote stub).  Return 0, or -1 if an error
2230    occurs (and set *TARGET_ERRNO).  */
2231 extern int target_fileio_unlink (struct inferior *inf,
2232                                          const char *filename,
2233                                          fileio_error *target_errno);
2234 
2235 /* Read value of symbolic link FILENAME on the target, in the
2236    filesystem as seen by INF.  If INF is NULL, use the filesystem seen
2237    by the debugger (GDB or, for remote targets, the remote stub).
2238    Return a null-terminated string allocated via xmalloc, or NULL if
2239    an error occurs (and set *TARGET_ERRNO).  */
2240 extern std::optional<std::string> target_fileio_readlink
2241     (struct inferior *inf, const char *filename, fileio_error *target_errno);
2242 
2243 /* Read target file FILENAME, in the filesystem as seen by INF.  If
2244    INF is NULL, use the filesystem seen by the debugger (GDB or, for
2245    remote targets, the remote stub).  The return value will be -1 if
2246    the transfer fails or is not supported; 0 if the object is empty;
2247    or the length of the object otherwise.  If a positive value is
2248    returned, a sufficiently large buffer will be allocated using
2249    xmalloc and returned in *BUF_P containing the contents of the
2250    object.
2251 
2252    This method should be used for objects sufficiently small to store
2253    in a single xmalloc'd buffer, when no fixed bound on the object's
2254    size is known in advance.  */
2255 extern LONGEST target_fileio_read_alloc (struct inferior *inf,
2256                                                    const char *filename,
2257                                                    gdb_byte **buf_p);
2258 
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 result is NUL-terminated and
2262    returned as a string, allocated using xmalloc.  If an error occurs
2263    or the transfer is unsupported, NULL is returned.  Empty objects
2264    are returned as allocated but empty strings.  A warning is issued
2265    if the result contains any embedded NUL bytes.  */
2266 extern gdb::unique_xmalloc_ptr<char> target_fileio_read_stralloc
2267     (struct inferior *inf, const char *filename);
2268 
2269 /* Invalidate the target associated with open handles that were open
2270    on target TARG, since we're about to close (and maybe destroy) the
2271    target.  The handles remain open from the client's perspective, but
2272    trying to do anything with them other than closing them will fail
2273    with EIO.  */
2274 extern void fileio_handles_invalidate_target (target_ops *targ);
2275 
2276 /* Tracepoint-related operations.  */
2277 
2278 extern void target_trace_init ();
2279 
2280 extern void target_download_tracepoint (bp_location *location);
2281 
2282 extern bool target_can_download_tracepoint ();
2283 
2284 extern void target_download_trace_state_variable (const trace_state_variable &tsv);
2285 
2286 extern void target_enable_tracepoint (bp_location *loc);
2287 
2288 extern void target_disable_tracepoint (bp_location *loc);
2289 
2290 extern void target_trace_start ();
2291 
2292 extern void target_trace_set_readonly_regions ();
2293 
2294 extern int target_get_trace_status (trace_status *ts);
2295 
2296 extern void target_get_tracepoint_status (tracepoint *tp, uploaded_tp *utp);
2297 
2298 extern void target_trace_stop ();
2299 
2300 extern int target_trace_find (trace_find_type type, int num, CORE_ADDR addr1,
2301                                     CORE_ADDR addr2, int *tpp);
2302 
2303 extern bool target_get_trace_state_variable_value (int tsv, LONGEST *val);
2304 
2305 extern int target_save_trace_data (const char *filename);
2306 
2307 extern int target_upload_tracepoints (uploaded_tp **utpp);
2308 
2309 extern int target_upload_trace_state_variables (uploaded_tsv **utsvp);
2310 
2311 extern LONGEST target_get_raw_trace_data (gdb_byte *buf, ULONGEST offset,
2312                                                     LONGEST len);
2313 
2314 extern int target_get_min_fast_tracepoint_insn_len ();
2315 
2316 extern void target_set_disconnected_tracing (int val);
2317 
2318 extern void target_set_circular_trace_buffer (int val);
2319 
2320 extern void target_set_trace_buffer_size (LONGEST val);
2321 
2322 extern bool target_set_trace_notes (const char *user, const char *notes,
2323                                             const char *stopnotes);
2324 
2325 extern bool target_get_tib_address (ptid_t ptid, CORE_ADDR *addr);
2326 
2327 extern void target_set_permissions ();
2328 
2329 extern bool target_static_tracepoint_marker_at
2330   (CORE_ADDR addr, static_tracepoint_marker *marker);
2331 
2332 extern std::vector<static_tracepoint_marker>
2333   target_static_tracepoint_markers_by_strid (const char *marker_id);
2334 
2335 extern traceframe_info_up target_traceframe_info ();
2336 
2337 extern bool target_use_agent (bool use);
2338 
2339 extern bool target_can_use_agent ();
2340 
2341 extern bool target_augmented_libraries_svr4_read ();
2342 
2343 extern bool target_supports_memory_tagging ();
2344 
2345 extern bool target_fetch_memtags (CORE_ADDR address, size_t len,
2346                                           gdb::byte_vector &tags, int type);
2347 
2348 extern bool target_store_memtags (CORE_ADDR address, size_t len,
2349                                           const gdb::byte_vector &tags, int type);
2350 
2351 extern bool target_is_address_tagged (gdbarch *gdbarch, CORE_ADDR address);
2352 
2353 extern x86_xsave_layout target_fetch_x86_xsave_layout ();
2354 
2355 /* Command logging facility.  */
2356 
2357 extern void target_log_command (const char *p);
2358 
2359 extern int target_core_of_thread (ptid_t ptid);
2360 
2361 /* See to_get_unwinder in struct target_ops.  */
2362 extern const struct frame_unwind *target_get_unwinder (void);
2363 
2364 /* See to_get_tailcall_unwinder in struct target_ops.  */
2365 extern const struct frame_unwind *target_get_tailcall_unwinder (void);
2366 
2367 /* This implements basic memory verification, reading target memory
2368    and performing the comparison here (as opposed to accelerated
2369    verification making use of the qCRC packet, for example).  */
2370 
2371 extern int simple_verify_memory (struct target_ops* ops,
2372                                          const gdb_byte *data,
2373                                          CORE_ADDR memaddr, ULONGEST size);
2374 
2375 /* Verify that the memory in the [MEMADDR, MEMADDR+SIZE) range matches
2376    the contents of [DATA,DATA+SIZE).  Returns 1 if there's a match, 0
2377    if there's a mismatch, and -1 if an error is encountered while
2378    reading memory.  Throws an error if the functionality is found not
2379    to be supported by the current target.  */
2380 int target_verify_memory (const gdb_byte *data,
2381                                 CORE_ADDR memaddr, ULONGEST size);
2382 
2383 /* Routines for maintenance of the target structures...
2384 
2385    add_target:   Add a target to the list of all possible targets.
2386    This only makes sense for targets that should be activated using
2387    the "target TARGET_NAME ..." command.
2388 
2389    push_target:  Make this target the top of the stack of currently used
2390    targets, within its particular stratum of the stack.  Result
2391    is 0 if now atop the stack, nonzero if not on top (maybe
2392    should warn user).
2393 
2394    unpush_target: Remove this from the stack of currently used targets,
2395    no matter where it is on the list.  Returns 0 if no
2396    change, 1 if removed from stack.  */
2397 
2398 /* Type of callback called when the user activates a target with
2399    "target TARGET_NAME".  The callback routine takes the rest of the
2400    parameters from the command, and (if successful) pushes a new
2401    target onto the stack.  */
2402 typedef void target_open_ftype (const char *args, int from_tty);
2403 
2404 /* Add the target described by INFO to the list of possible targets
2405    and add a new command 'target $(INFO->shortname)'.  Set COMPLETER
2406    as the command's completer if not NULL.  */
2407 
2408 extern void add_target (const target_info &info,
2409                               target_open_ftype *func,
2410                               completer_ftype *completer = NULL);
2411 
2412 /* Adds a command ALIAS for the target described by INFO and marks it
2413    deprecated.  This is useful for maintaining backwards compatibility
2414    when renaming targets.  */
2415 
2416 extern void add_deprecated_target_alias (const target_info &info,
2417                                                    const char *alias);
2418 
2419 /* A unique_ptr helper to unpush a target.  */
2420 
2421 struct target_unpusher
2422 {
2423   void operator() (struct target_ops *ops) const;
2424 };
2425 
2426 /* A unique_ptr that unpushes a target on destruction.  */
2427 
2428 typedef std::unique_ptr<struct target_ops, target_unpusher> target_unpush_up;
2429 
2430 extern void target_pre_inferior (int);
2431 
2432 extern void target_preopen (int);
2433 
2434 extern CORE_ADDR target_translate_tls_address (struct objfile *objfile,
2435                                                          CORE_ADDR offset);
2436 
2437 /* Return the "section" containing the specified address.  */
2438 const struct target_section *target_section_by_addr (struct target_ops *target,
2439                                                                  CORE_ADDR addr);
2440 
2441 /* Return the target section table this target (or the targets
2442    beneath) currently manipulate.  */
2443 
2444 extern const std::vector<target_section> *target_get_section_table
2445   (struct target_ops *target);
2446 
2447 /* Default implementation of get_section_table for dummy_target.  */
2448 
2449 extern const std::vector<target_section> *default_get_section_table ();
2450 
2451 /* From mem-break.c */
2452 
2453 extern int memory_remove_breakpoint (struct target_ops *,
2454                                              struct gdbarch *, struct bp_target_info *,
2455                                              enum remove_bp_reason);
2456 
2457 extern int memory_insert_breakpoint (struct target_ops *,
2458                                              struct gdbarch *, struct bp_target_info *);
2459 
2460 /* Convenience template use to add memory breakpoints support to a
2461    target.  */
2462 
2463 template <typename BaseTarget>
2464 struct memory_breakpoint_target : public BaseTarget
2465 {
insert_breakpointmemory_breakpoint_target2466   int insert_breakpoint (struct gdbarch *gdbarch,
2467                                struct bp_target_info *bp_tgt) override
2468   { return memory_insert_breakpoint (this, gdbarch, bp_tgt); }
2469 
remove_breakpointmemory_breakpoint_target2470   int remove_breakpoint (struct gdbarch *gdbarch,
2471                                struct bp_target_info *bp_tgt,
2472                                enum remove_bp_reason reason) override
2473   { return memory_remove_breakpoint (this, gdbarch, bp_tgt, reason); }
2474 };
2475 
2476 /* Check whether the memory at the breakpoint's placed address still
2477    contains the expected breakpoint instruction.  */
2478 
2479 extern int memory_validate_breakpoint (struct gdbarch *gdbarch,
2480                                                struct bp_target_info *bp_tgt);
2481 
2482 extern int default_memory_remove_breakpoint (struct gdbarch *,
2483                                                        struct bp_target_info *);
2484 
2485 extern int default_memory_insert_breakpoint (struct gdbarch *,
2486                                                        struct bp_target_info *);
2487 
2488 
2489 /* From target.c */
2490 
2491 extern void initialize_targets (void);
2492 
2493 extern void noprocess (void) ATTRIBUTE_NORETURN;
2494 
2495 extern void target_require_runnable (void);
2496 
2497 /* Find the target at STRATUM.  If no target is at that stratum,
2498    return NULL.  */
2499 
2500 struct target_ops *find_target_at (enum strata stratum);
2501 
2502 /* Read OS data object of type TYPE from the target, and return it in XML
2503    format.  The return value follows the same rules as target_read_stralloc.  */
2504 
2505 extern std::optional<gdb::char_vector> target_get_osdata (const char *type);
2506 
2507 /* Stuff that should be shared among the various remote targets.  */
2508 
2509 
2510 /* Timeout limit for response from target.  */
2511 extern int remote_timeout;
2512 
2513 
2514 
2515 /* Set the show memory breakpoints mode to show, and return a
2516    scoped_restore to restore it back to the current value.  */
2517 extern scoped_restore_tmpl<int>
2518     make_scoped_restore_show_memory_breakpoints (int show);
2519 
2520 /* True if we should trust readonly sections from the
2521    executable when reading memory.  */
2522 extern bool trust_readonly;
2523 
2524 extern bool may_write_registers;
2525 extern bool may_write_memory;
2526 extern bool may_insert_breakpoints;
2527 extern bool may_insert_tracepoints;
2528 extern bool may_insert_fast_tracepoints;
2529 extern bool may_stop;
2530 
2531 extern void update_target_permissions (void);
2532 
2533 
2534 /* Imported from machine dependent code.  */
2535 
2536 /* See to_enable_btrace in struct target_ops.  */
2537 extern struct btrace_target_info *
2538   target_enable_btrace (thread_info *tp, const struct btrace_config *);
2539 
2540 /* See to_disable_btrace in struct target_ops.  */
2541 extern void target_disable_btrace (struct btrace_target_info *btinfo);
2542 
2543 /* See to_teardown_btrace in struct target_ops.  */
2544 extern void target_teardown_btrace (struct btrace_target_info *btinfo);
2545 
2546 /* See to_read_btrace in struct target_ops.  */
2547 extern enum btrace_error target_read_btrace (struct btrace_data *,
2548                                                        struct btrace_target_info *,
2549                                                        enum btrace_read_type);
2550 
2551 /* See to_btrace_conf in struct target_ops.  */
2552 extern const struct btrace_config *
2553   target_btrace_conf (const struct btrace_target_info *);
2554 
2555 /* See to_stop_recording in struct target_ops.  */
2556 extern void target_stop_recording (void);
2557 
2558 /* See to_save_record in struct target_ops.  */
2559 extern void target_save_record (const char *filename);
2560 
2561 /* Query if the target supports deleting the execution log.  */
2562 extern int target_supports_delete_record (void);
2563 
2564 /* See to_delete_record in struct target_ops.  */
2565 extern void target_delete_record (void);
2566 
2567 /* See to_record_method.  */
2568 extern enum record_method target_record_method (ptid_t ptid);
2569 
2570 /* See to_record_is_replaying in struct target_ops.  */
2571 extern int target_record_is_replaying (ptid_t ptid);
2572 
2573 /* See to_record_will_replay in struct target_ops.  */
2574 extern int target_record_will_replay (ptid_t ptid, int dir);
2575 
2576 /* See to_record_stop_replaying in struct target_ops.  */
2577 extern void target_record_stop_replaying (void);
2578 
2579 /* See to_goto_record_begin in struct target_ops.  */
2580 extern void target_goto_record_begin (void);
2581 
2582 /* See to_goto_record_end in struct target_ops.  */
2583 extern void target_goto_record_end (void);
2584 
2585 /* See to_goto_record in struct target_ops.  */
2586 extern void target_goto_record (ULONGEST insn);
2587 
2588 /* See to_insn_history.  */
2589 extern void target_insn_history (int size, gdb_disassembly_flags flags);
2590 
2591 /* See to_insn_history_from.  */
2592 extern void target_insn_history_from (ULONGEST from, int size,
2593                                               gdb_disassembly_flags flags);
2594 
2595 /* See to_insn_history_range.  */
2596 extern void target_insn_history_range (ULONGEST begin, ULONGEST end,
2597                                                gdb_disassembly_flags flags);
2598 
2599 /* See to_call_history.  */
2600 extern void target_call_history (int size, record_print_flags flags);
2601 
2602 /* See to_call_history_from.  */
2603 extern void target_call_history_from (ULONGEST begin, int size,
2604                                               record_print_flags flags);
2605 
2606 /* See to_call_history_range.  */
2607 extern void target_call_history_range (ULONGEST begin, ULONGEST end,
2608                                                record_print_flags flags);
2609 
2610 /* See to_prepare_to_generate_core.  */
2611 extern void target_prepare_to_generate_core (void);
2612 
2613 /* See to_done_generating_core.  */
2614 extern void target_done_generating_core (void);
2615 
2616 #endif /* !defined (TARGET_H) */
2617