Introduce class target_stack
[external/binutils.git] / gdb / target.h
1 /* Interface between GDB and target environments, including files and processes
2
3    Copyright (C) 1990-2018 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 #if !defined (TARGET_H)
23 #define TARGET_H
24
25 struct objfile;
26 struct ui_file;
27 struct mem_attrib;
28 struct target_ops;
29 struct bp_location;
30 struct bp_target_info;
31 struct regcache;
32 struct target_section_table;
33 struct trace_state_variable;
34 struct trace_status;
35 struct uploaded_tsv;
36 struct uploaded_tp;
37 struct static_tracepoint_marker;
38 struct traceframe_info;
39 struct expression;
40 struct dcache_struct;
41 struct inferior;
42
43 #include "infrun.h" /* For enum exec_direction_kind.  */
44 #include "breakpoint.h" /* For enum bptype.  */
45 #include "common/scoped_restore.h"
46
47 /* This include file defines the interface between the main part
48    of the debugger, and the part which is target-specific, or
49    specific to the communications interface between us and the
50    target.
51
52    A TARGET is an interface between the debugger and a particular
53    kind of file or process.  Targets can be STACKED in STRATA,
54    so that more than one target can potentially respond to a request.
55    In particular, memory accesses will walk down the stack of targets
56    until they find a target that is interested in handling that particular
57    address.  STRATA are artificial boundaries on the stack, within
58    which particular kinds of targets live.  Strata exist so that
59    people don't get confused by pushing e.g. a process target and then
60    a file target, and wondering why they can't see the current values
61    of variables any more (the file target is handling them and they
62    never get to the process target).  So when you push a file target,
63    it goes into the file stratum, which is always below the process
64    stratum.
65
66    Note that rather than allow an empty stack, we always have the
67    dummy target at the bottom stratum, so we can call the target
68    methods without checking them.  */
69
70 #include "target/target.h"
71 #include "target/resume.h"
72 #include "target/wait.h"
73 #include "target/waitstatus.h"
74 #include "bfd.h"
75 #include "symtab.h"
76 #include "memattr.h"
77 #include "vec.h"
78 #include "gdb_signals.h"
79 #include "btrace.h"
80 #include "record.h"
81 #include "command.h"
82 #include "disasm.h"
83 #include "tracepoint.h"
84
85 #include "break-common.h" /* For enum target_hw_bp_type.  */
86
87 enum strata
88   {
89     dummy_stratum,              /* The lowest of the low */
90     file_stratum,               /* Executable files, etc */
91     process_stratum,            /* Executing processes or core dump files */
92     thread_stratum,             /* Executing threads */
93     record_stratum,             /* Support record debugging */
94     arch_stratum,               /* Architecture overrides */
95     debug_stratum               /* Target debug.  Must be last.  */
96   };
97
98 enum thread_control_capabilities
99   {
100     tc_none = 0,                /* Default: can't control thread execution.  */
101     tc_schedlock = 1,           /* Can lock the thread scheduler.  */
102   };
103
104 /* The structure below stores information about a system call.
105    It is basically used in the "catch syscall" command, and in
106    every function that gives information about a system call.
107    
108    It's also good to mention that its fields represent everything
109    that we currently know about a syscall in GDB.  */
110 struct syscall
111   {
112     /* The syscall number.  */
113     int number;
114
115     /* The syscall name.  */
116     const char *name;
117   };
118
119 /* Return a pretty printed form of TARGET_OPTIONS.
120    Space for the result is malloc'd, caller must free.  */
121 extern char *target_options_to_string (int target_options);
122
123 /* Possible types of events that the inferior handler will have to
124    deal with.  */
125 enum inferior_event_type
126   {
127     /* Process a normal inferior event which will result in target_wait
128        being called.  */
129     INF_REG_EVENT,
130     /* We are called to do stuff after the inferior stops.  */
131     INF_EXEC_COMPLETE,
132   };
133 \f
134 /* Target objects which can be transfered using target_read,
135    target_write, et cetera.  */
136
137 enum target_object
138 {
139   /* AVR target specific transfer.  See "avr-tdep.c" and "remote.c".  */
140   TARGET_OBJECT_AVR,
141   /* SPU target specific transfer.  See "spu-tdep.c".  */
142   TARGET_OBJECT_SPU,
143   /* Transfer up-to LEN bytes of memory starting at OFFSET.  */
144   TARGET_OBJECT_MEMORY,
145   /* Memory, avoiding GDB's data cache and trusting the executable.
146      Target implementations of to_xfer_partial never need to handle
147      this object, and most callers should not use it.  */
148   TARGET_OBJECT_RAW_MEMORY,
149   /* Memory known to be part of the target's stack.  This is cached even
150      if it is not in a region marked as such, since it is known to be
151      "normal" RAM.  */
152   TARGET_OBJECT_STACK_MEMORY,
153   /* Memory known to be part of the target code.   This is cached even
154      if it is not in a region marked as such.  */
155   TARGET_OBJECT_CODE_MEMORY,
156   /* Kernel Unwind Table.  See "ia64-tdep.c".  */
157   TARGET_OBJECT_UNWIND_TABLE,
158   /* Transfer auxilliary vector.  */
159   TARGET_OBJECT_AUXV,
160   /* StackGhost cookie.  See "sparc-tdep.c".  */
161   TARGET_OBJECT_WCOOKIE,
162   /* Target memory map in XML format.  */
163   TARGET_OBJECT_MEMORY_MAP,
164   /* Flash memory.  This object can be used to write contents to
165      a previously erased flash memory.  Using it without erasing
166      flash can have unexpected results.  Addresses are physical
167      address on target, and not relative to flash start.  */
168   TARGET_OBJECT_FLASH,
169   /* Available target-specific features, e.g. registers and coprocessors.
170      See "target-descriptions.c".  ANNEX should never be empty.  */
171   TARGET_OBJECT_AVAILABLE_FEATURES,
172   /* Currently loaded libraries, in XML format.  */
173   TARGET_OBJECT_LIBRARIES,
174   /* Currently loaded libraries specific for SVR4 systems, in XML format.  */
175   TARGET_OBJECT_LIBRARIES_SVR4,
176   /* Currently loaded libraries specific to AIX systems, in XML format.  */
177   TARGET_OBJECT_LIBRARIES_AIX,
178   /* Get OS specific data.  The ANNEX specifies the type (running
179      processes, etc.).  The data being transfered is expected to follow
180      the DTD specified in features/osdata.dtd.  */
181   TARGET_OBJECT_OSDATA,
182   /* Extra signal info.  Usually the contents of `siginfo_t' on unix
183      platforms.  */
184   TARGET_OBJECT_SIGNAL_INFO,
185   /* The list of threads that are being debugged.  */
186   TARGET_OBJECT_THREADS,
187   /* Collected static trace data.  */
188   TARGET_OBJECT_STATIC_TRACE_DATA,
189   /* Traceframe info, in XML format.  */
190   TARGET_OBJECT_TRACEFRAME_INFO,
191   /* Load maps for FDPIC systems.  */
192   TARGET_OBJECT_FDPIC,
193   /* Darwin dynamic linker info data.  */
194   TARGET_OBJECT_DARWIN_DYLD_INFO,
195   /* OpenVMS Unwind Information Block.  */
196   TARGET_OBJECT_OPENVMS_UIB,
197   /* Branch trace data, in XML format.  */
198   TARGET_OBJECT_BTRACE,
199   /* Branch trace configuration, in XML format.  */
200   TARGET_OBJECT_BTRACE_CONF,
201   /* The pathname of the executable file that was run to create
202      a specified process.  ANNEX should be a string representation
203      of the process ID of the process in question, in hexadecimal
204      format.  */
205   TARGET_OBJECT_EXEC_FILE,
206   /* Possible future objects: TARGET_OBJECT_FILE, ...  */
207 };
208
209 /* Possible values returned by target_xfer_partial, etc.  */
210
211 enum target_xfer_status
212 {
213   /* Some bytes are transferred.  */
214   TARGET_XFER_OK = 1,
215
216   /* No further transfer is possible.  */
217   TARGET_XFER_EOF = 0,
218
219   /* The piece of the object requested is unavailable.  */
220   TARGET_XFER_UNAVAILABLE = 2,
221
222   /* Generic I/O error.  Note that it's important that this is '-1',
223      as we still have target_xfer-related code returning hardcoded
224      '-1' on error.  */
225   TARGET_XFER_E_IO = -1,
226
227   /* Keep list in sync with target_xfer_status_to_string.  */
228 };
229
230 /* Return the string form of STATUS.  */
231
232 extern const char *
233   target_xfer_status_to_string (enum target_xfer_status status);
234
235 typedef enum target_xfer_status
236   target_xfer_partial_ftype (struct target_ops *ops,
237                              enum target_object object,
238                              const char *annex,
239                              gdb_byte *readbuf,
240                              const gdb_byte *writebuf,
241                              ULONGEST offset,
242                              ULONGEST len,
243                              ULONGEST *xfered_len);
244
245 enum target_xfer_status
246   raw_memory_xfer_partial (struct target_ops *ops, gdb_byte *readbuf,
247                            const gdb_byte *writebuf, ULONGEST memaddr,
248                            LONGEST len, ULONGEST *xfered_len);
249
250 /* Request that OPS transfer up to LEN addressable units of the target's
251    OBJECT.  When reading from a memory object, the size of an addressable unit
252    is architecture dependent and can be found using
253    gdbarch_addressable_memory_unit_size.  Otherwise, an addressable unit is 1
254    byte long.  BUF should point to a buffer large enough to hold the read data,
255    taking into account the addressable unit size.  The OFFSET, for a seekable
256    object, specifies the starting point.  The ANNEX can be used to provide
257    additional data-specific information to the target.
258
259    Return the number of addressable units actually transferred, or a negative
260    error code (an 'enum target_xfer_error' value) if the transfer is not
261    supported or otherwise fails.  Return of a positive value less than
262    LEN indicates that no further transfer is possible.  Unlike the raw
263    to_xfer_partial interface, callers of these functions do not need
264    to retry partial transfers.  */
265
266 extern LONGEST target_read (struct target_ops *ops,
267                             enum target_object object,
268                             const char *annex, gdb_byte *buf,
269                             ULONGEST offset, LONGEST len);
270
271 struct memory_read_result
272 {
273   memory_read_result (ULONGEST begin_, ULONGEST end_,
274                       gdb::unique_xmalloc_ptr<gdb_byte> &&data_)
275     : begin (begin_),
276       end (end_),
277       data (std::move (data_))
278   {
279   }
280
281   ~memory_read_result () = default;
282
283   memory_read_result (memory_read_result &&other) = default;
284
285   DISABLE_COPY_AND_ASSIGN (memory_read_result);
286
287   /* First address that was read.  */
288   ULONGEST begin;
289   /* Past-the-end address.  */
290   ULONGEST end;
291   /* The data.  */
292   gdb::unique_xmalloc_ptr<gdb_byte> data;
293 };
294
295 extern std::vector<memory_read_result> read_memory_robust
296     (struct target_ops *ops, const ULONGEST offset, const LONGEST len);
297
298 /* Request that OPS transfer up to LEN addressable units from BUF to the
299    target's OBJECT.  When writing to a memory object, the addressable unit
300    size is architecture dependent and can be found using
301    gdbarch_addressable_memory_unit_size.  Otherwise, an addressable unit is 1
302    byte long.  The OFFSET, for a seekable object, specifies the starting point.
303    The ANNEX can be used to provide additional data-specific information to
304    the target.
305
306    Return the number of addressable units actually transferred, or a negative
307    error code (an 'enum target_xfer_status' value) if the transfer is not
308    supported or otherwise fails.  Return of a positive value less than
309    LEN indicates that no further transfer is possible.  Unlike the raw
310    to_xfer_partial interface, callers of these functions do not need to
311    retry partial transfers.  */
312
313 extern LONGEST target_write (struct target_ops *ops,
314                              enum target_object object,
315                              const char *annex, const gdb_byte *buf,
316                              ULONGEST offset, LONGEST len);
317
318 /* Similar to target_write, except that it also calls PROGRESS with
319    the number of bytes written and the opaque BATON after every
320    successful partial write (and before the first write).  This is
321    useful for progress reporting and user interaction while writing
322    data.  To abort the transfer, the progress callback can throw an
323    exception.  */
324
325 LONGEST target_write_with_progress (struct target_ops *ops,
326                                     enum target_object object,
327                                     const char *annex, const gdb_byte *buf,
328                                     ULONGEST offset, LONGEST len,
329                                     void (*progress) (ULONGEST, void *),
330                                     void *baton);
331
332 /* Wrapper to perform a full read of unknown size.  OBJECT/ANNEX will be read
333    using OPS.  The return value will be uninstantiated if the transfer fails or
334    is not supported.
335
336    This method should be used for objects sufficiently small to store
337    in a single xmalloc'd buffer, when no fixed bound on the object's
338    size is known in advance.  Don't try to read TARGET_OBJECT_MEMORY
339    through this function.  */
340
341 extern gdb::optional<gdb::byte_vector> target_read_alloc
342     (struct target_ops *ops, enum target_object object, const char *annex);
343
344 /* Read OBJECT/ANNEX using OPS.  The result is a NUL-terminated character vector
345    (therefore usable as a NUL-terminated string).  If an error occurs or the
346    transfer is unsupported, the return value will be uninstantiated.  Empty
347    objects are returned as allocated but empty strings.  Therefore, on success,
348    the returned vector is guaranteed to have at least one element.  A warning is
349    issued if the result contains any embedded NUL bytes.  */
350
351 extern gdb::optional<gdb::char_vector> target_read_stralloc
352     (struct target_ops *ops, enum target_object object, const char *annex);
353
354 /* See target_ops->to_xfer_partial.  */
355 extern target_xfer_partial_ftype target_xfer_partial;
356
357 /* Wrappers to target read/write that perform memory transfers.  They
358    throw an error if the memory transfer fails.
359
360    NOTE: cagney/2003-10-23: The naming schema is lifted from
361    "frame.h".  The parameter order is lifted from get_frame_memory,
362    which in turn lifted it from read_memory.  */
363
364 extern void get_target_memory (struct target_ops *ops, CORE_ADDR addr,
365                                gdb_byte *buf, LONGEST len);
366 extern ULONGEST get_target_memory_unsigned (struct target_ops *ops,
367                                             CORE_ADDR addr, int len,
368                                             enum bfd_endian byte_order);
369 \f
370 struct thread_info;             /* fwd decl for parameter list below: */
371
372 /* The type of the callback to the to_async method.  */
373
374 typedef void async_callback_ftype (enum inferior_event_type event_type,
375                                    void *context);
376
377 /* Normally target debug printing is purely type-based.  However,
378    sometimes it is necessary to override the debug printing on a
379    per-argument basis.  This macro can be used, attribute-style, to
380    name the target debug printing function for a particular method
381    argument.  FUNC is the name of the function.  The macro's
382    definition is empty because it is only used by the
383    make-target-delegates script.  */
384
385 #define TARGET_DEBUG_PRINTER(FUNC)
386
387 /* These defines are used to mark target_ops methods.  The script
388    make-target-delegates scans these and auto-generates the base
389    method implementations.  There are four macros that can be used:
390    
391    1. TARGET_DEFAULT_IGNORE.  There is no argument.  The base method
392    does nothing.  This is only valid if the method return type is
393    'void'.
394    
395    2. TARGET_DEFAULT_NORETURN.  The argument is a function call, like
396    'tcomplain ()'.  The base method simply makes this call, which is
397    assumed not to return.
398    
399    3. TARGET_DEFAULT_RETURN.  The argument is a C expression.  The
400    base method returns this expression's value.
401    
402    4. TARGET_DEFAULT_FUNC.  The argument is the name of a function.
403    make-target-delegates does not generate a base method in this case,
404    but instead uses the argument function as the base method.  */
405
406 #define TARGET_DEFAULT_IGNORE()
407 #define TARGET_DEFAULT_NORETURN(ARG)
408 #define TARGET_DEFAULT_RETURN(ARG)
409 #define TARGET_DEFAULT_FUNC(ARG)
410
411 /* Each target that can be activated with "target TARGET_NAME" passes
412    the address of one of these objects to add_target, which uses the
413    object's address as unique identifier, and registers the "target
414    TARGET_NAME" command using SHORTNAME as target name.  */
415
416 struct target_info
417 {
418   /* Name of this target.  */
419   const char *shortname;
420
421   /* Name for printing.  */
422   const char *longname;
423
424   /* Documentation.  Does not include trailing newline, and starts
425      with a one-line description (probably similar to longname).  */
426   const char *doc;
427 };
428
429 struct target_ops
430   {
431     /* To the target under this one.  */
432     target_ops *beneath () const;
433
434     /* Free resources associated with the target.  Note that singleton
435        targets, like e.g., native targets, are global objects, not
436        heap allocated, and are thus only deleted on GDB exit.  The
437        main teardown entry point is the "close" method, below.  */
438     virtual ~target_ops () {}
439
440     /* Return a reference to this target's unique target_info
441        object.  */
442     virtual const target_info &info () const = 0;
443
444     /* Name this target type.  */
445     const char *shortname ()
446     { return info ().shortname; }
447
448     const char *longname ()
449     { return info ().longname; }
450
451     /* Close the target.  This is where the target can handle
452        teardown.  Heap-allocated targets should delete themselves
453        before returning.  */
454     virtual void close ();
455
456     /* Attaches to a process on the target side.  Arguments are as
457        passed to the `attach' command by the user.  This routine can
458        be called when the target is not on the target-stack, if the
459        target_ops::can_run method returns 1; in that case, it must push
460        itself onto the stack.  Upon exit, the target should be ready
461        for normal operations, and should be ready to deliver the
462        status of the process immediately (without waiting) to an
463        upcoming target_wait call.  */
464     virtual bool can_attach ();
465     virtual void attach (const char *, int);
466     virtual void post_attach (int)
467       TARGET_DEFAULT_IGNORE ();
468     virtual void detach (inferior *, int)
469       TARGET_DEFAULT_IGNORE ();
470     virtual void disconnect (const char *, int)
471       TARGET_DEFAULT_NORETURN (tcomplain ());
472     virtual void resume (ptid_t,
473                          int TARGET_DEBUG_PRINTER (target_debug_print_step),
474                          enum gdb_signal)
475       TARGET_DEFAULT_NORETURN (noprocess ());
476     virtual void commit_resume ()
477       TARGET_DEFAULT_IGNORE ();
478     virtual ptid_t wait (ptid_t, struct target_waitstatus *,
479                          int TARGET_DEBUG_PRINTER (target_debug_print_options))
480       TARGET_DEFAULT_FUNC (default_target_wait);
481     virtual void fetch_registers (struct regcache *, int)
482       TARGET_DEFAULT_IGNORE ();
483     virtual void store_registers (struct regcache *, int)
484       TARGET_DEFAULT_NORETURN (noprocess ());
485     virtual void prepare_to_store (struct regcache *)
486       TARGET_DEFAULT_NORETURN (noprocess ());
487
488     virtual void files_info ()
489       TARGET_DEFAULT_IGNORE ();
490     virtual int insert_breakpoint (struct gdbarch *,
491                                  struct bp_target_info *)
492       TARGET_DEFAULT_NORETURN (noprocess ());
493     virtual int remove_breakpoint (struct gdbarch *,
494                                  struct bp_target_info *,
495                                  enum remove_bp_reason)
496       TARGET_DEFAULT_NORETURN (noprocess ());
497
498     /* Returns true if the target stopped because it executed a
499        software breakpoint.  This is necessary for correct background
500        execution / non-stop mode operation, and for correct PC
501        adjustment on targets where the PC needs to be adjusted when a
502        software breakpoint triggers.  In these modes, by the time GDB
503        processes a breakpoint event, the breakpoint may already be
504        done from the target, so GDB needs to be able to tell whether
505        it should ignore the event and whether it should adjust the PC.
506        See adjust_pc_after_break.  */
507     virtual bool stopped_by_sw_breakpoint ()
508       TARGET_DEFAULT_RETURN (false);
509     /* Returns true if the above method is supported.  */
510     virtual bool supports_stopped_by_sw_breakpoint ()
511       TARGET_DEFAULT_RETURN (false);
512
513     /* Returns true if the target stopped for a hardware breakpoint.
514        Likewise, if the target supports hardware breakpoints, this
515        method is necessary for correct background execution / non-stop
516        mode operation.  Even though hardware breakpoints do not
517        require PC adjustment, GDB needs to be able to tell whether the
518        hardware breakpoint event is a delayed event for a breakpoint
519        that is already gone and should thus be ignored.  */
520     virtual bool stopped_by_hw_breakpoint ()
521       TARGET_DEFAULT_RETURN (false);
522     /* Returns true if the above method is supported.  */
523     virtual bool supports_stopped_by_hw_breakpoint ()
524       TARGET_DEFAULT_RETURN (false);
525
526     virtual int can_use_hw_breakpoint (enum bptype, int, int)
527       TARGET_DEFAULT_RETURN (0);
528     virtual int ranged_break_num_registers ()
529       TARGET_DEFAULT_RETURN (-1);
530     virtual int insert_hw_breakpoint (struct gdbarch *,
531                                       struct bp_target_info *)
532       TARGET_DEFAULT_RETURN (-1);
533     virtual int remove_hw_breakpoint (struct gdbarch *,
534                                       struct bp_target_info *)
535       TARGET_DEFAULT_RETURN (-1);
536
537     /* Documentation of what the two routines below are expected to do is
538        provided with the corresponding target_* macros.  */
539     virtual int remove_watchpoint (CORE_ADDR, int,
540                                  enum target_hw_bp_type, struct expression *)
541       TARGET_DEFAULT_RETURN (-1);
542     virtual int insert_watchpoint (CORE_ADDR, int,
543                                  enum target_hw_bp_type, struct expression *)
544       TARGET_DEFAULT_RETURN (-1);
545
546     virtual int insert_mask_watchpoint (CORE_ADDR, CORE_ADDR,
547                                         enum target_hw_bp_type)
548       TARGET_DEFAULT_RETURN (1);
549     virtual int remove_mask_watchpoint (CORE_ADDR, CORE_ADDR,
550                                         enum target_hw_bp_type)
551       TARGET_DEFAULT_RETURN (1);
552     virtual bool stopped_by_watchpoint ()
553       TARGET_DEFAULT_RETURN (false);
554     virtual int have_steppable_watchpoint ()
555       TARGET_DEFAULT_RETURN (false);
556     virtual bool have_continuable_watchpoint ()
557       TARGET_DEFAULT_RETURN (false);
558     virtual bool stopped_data_address (CORE_ADDR *)
559       TARGET_DEFAULT_RETURN (false);
560     virtual bool watchpoint_addr_within_range (CORE_ADDR, CORE_ADDR, int)
561       TARGET_DEFAULT_FUNC (default_watchpoint_addr_within_range);
562
563     /* Documentation of this routine is provided with the corresponding
564        target_* macro.  */
565     virtual int region_ok_for_hw_watchpoint (CORE_ADDR, int)
566       TARGET_DEFAULT_FUNC (default_region_ok_for_hw_watchpoint);
567
568     virtual bool can_accel_watchpoint_condition (CORE_ADDR, int, int,
569                                                  struct expression *)
570       TARGET_DEFAULT_RETURN (false);
571     virtual int masked_watch_num_registers (CORE_ADDR, CORE_ADDR)
572       TARGET_DEFAULT_RETURN (-1);
573
574     /* Return 1 for sure target can do single step.  Return -1 for
575        unknown.  Return 0 for target can't do.  */
576     virtual int can_do_single_step ()
577       TARGET_DEFAULT_RETURN (-1);
578
579     virtual bool supports_terminal_ours ()
580       TARGET_DEFAULT_RETURN (false);
581     virtual void terminal_init ()
582       TARGET_DEFAULT_IGNORE ();
583     virtual void terminal_inferior ()
584       TARGET_DEFAULT_IGNORE ();
585     virtual void terminal_save_inferior ()
586       TARGET_DEFAULT_IGNORE ();
587     virtual void terminal_ours_for_output ()
588       TARGET_DEFAULT_IGNORE ();
589     virtual void terminal_ours ()
590       TARGET_DEFAULT_IGNORE ();
591     virtual void terminal_info (const char *, int)
592       TARGET_DEFAULT_FUNC (default_terminal_info);
593     virtual void kill ()
594       TARGET_DEFAULT_NORETURN (noprocess ());
595     virtual void load (const char *, int)
596       TARGET_DEFAULT_NORETURN (tcomplain ());
597     /* Start an inferior process and set inferior_ptid to its pid.
598        EXEC_FILE is the file to run.
599        ALLARGS is a string containing the arguments to the program.
600        ENV is the environment vector to pass.  Errors reported with error().
601        On VxWorks and various standalone systems, we ignore exec_file.  */
602     virtual bool can_create_inferior ();
603     virtual void create_inferior (const char *, const std::string &,
604                                   char **, int);
605     virtual void post_startup_inferior (ptid_t)
606       TARGET_DEFAULT_IGNORE ();
607     virtual int insert_fork_catchpoint (int)
608       TARGET_DEFAULT_RETURN (1);
609     virtual int remove_fork_catchpoint (int)
610       TARGET_DEFAULT_RETURN (1);
611     virtual int insert_vfork_catchpoint (int)
612       TARGET_DEFAULT_RETURN (1);
613     virtual int remove_vfork_catchpoint (int)
614       TARGET_DEFAULT_RETURN (1);
615     virtual int follow_fork (int, int)
616       TARGET_DEFAULT_FUNC (default_follow_fork);
617     virtual int insert_exec_catchpoint (int)
618       TARGET_DEFAULT_RETURN (1);
619     virtual int remove_exec_catchpoint (int)
620       TARGET_DEFAULT_RETURN (1);
621     virtual void follow_exec (struct inferior *, char *)
622       TARGET_DEFAULT_IGNORE ();
623     virtual int set_syscall_catchpoint (int, bool, int,
624                                         gdb::array_view<const int>)
625       TARGET_DEFAULT_RETURN (1);
626     virtual void mourn_inferior ()
627       TARGET_DEFAULT_FUNC (default_mourn_inferior);
628
629     /* Note that can_run is special and can be invoked on an unpushed
630        target.  Targets defining this method must also define
631        to_can_async_p and to_supports_non_stop.  */
632     virtual bool can_run ();
633
634     /* Documentation of this routine is provided with the corresponding
635        target_* macro.  */
636     virtual void pass_signals (int,
637                                unsigned char * TARGET_DEBUG_PRINTER (target_debug_print_signals))
638       TARGET_DEFAULT_IGNORE ();
639
640     /* Documentation of this routine is provided with the
641        corresponding target_* function.  */
642     virtual void program_signals (int,
643                                   unsigned char * TARGET_DEBUG_PRINTER (target_debug_print_signals))
644       TARGET_DEFAULT_IGNORE ();
645
646     virtual bool thread_alive (ptid_t ptid)
647       TARGET_DEFAULT_RETURN (false);
648     virtual void update_thread_list ()
649       TARGET_DEFAULT_IGNORE ();
650     virtual const char *pid_to_str (ptid_t)
651       TARGET_DEFAULT_FUNC (default_pid_to_str);
652     virtual const char *extra_thread_info (thread_info *)
653       TARGET_DEFAULT_RETURN (NULL);
654     virtual const char *thread_name (thread_info *)
655       TARGET_DEFAULT_RETURN (NULL);
656     virtual thread_info *thread_handle_to_thread_info (const gdb_byte *,
657                                                        int,
658                                                        inferior *inf)
659       TARGET_DEFAULT_RETURN (NULL);
660     virtual void stop (ptid_t)
661       TARGET_DEFAULT_IGNORE ();
662     virtual void interrupt ()
663       TARGET_DEFAULT_IGNORE ();
664     virtual void pass_ctrlc ()
665       TARGET_DEFAULT_FUNC (default_target_pass_ctrlc);
666     virtual void rcmd (const char *command, struct ui_file *output)
667       TARGET_DEFAULT_FUNC (default_rcmd);
668     virtual char *pid_to_exec_file (int pid)
669       TARGET_DEFAULT_RETURN (NULL);
670     virtual void log_command (const char *)
671       TARGET_DEFAULT_IGNORE ();
672     virtual struct target_section_table *get_section_table ()
673       TARGET_DEFAULT_RETURN (NULL);
674     enum strata to_stratum;
675
676     /* Provide default values for all "must have" methods.  */
677     virtual bool has_all_memory () { return false; }
678     virtual bool has_memory () { return false; }
679     virtual bool has_stack () { return false; }
680     virtual bool has_registers () { return false; }
681     virtual bool has_execution (ptid_t) { return false; }
682
683     /* Control thread execution.  */
684     virtual thread_control_capabilities get_thread_control_capabilities ()
685       TARGET_DEFAULT_RETURN (tc_none);
686     virtual bool attach_no_wait ()
687       TARGET_DEFAULT_RETURN (0);
688     /* This method must be implemented in some situations.  See the
689        comment on 'can_run'.  */
690     virtual bool can_async_p ()
691       TARGET_DEFAULT_RETURN (false);
692     virtual bool is_async_p ()
693       TARGET_DEFAULT_RETURN (false);
694     virtual void async (int)
695       TARGET_DEFAULT_NORETURN (tcomplain ());
696     virtual void thread_events (int)
697       TARGET_DEFAULT_IGNORE ();
698     /* This method must be implemented in some situations.  See the
699        comment on 'can_run'.  */
700     virtual bool supports_non_stop ()
701       TARGET_DEFAULT_RETURN (false);
702     /* Return true if the target operates in non-stop mode even with
703        "set non-stop off".  */
704     virtual bool always_non_stop_p ()
705       TARGET_DEFAULT_RETURN (false);
706     /* find_memory_regions support method for gcore */
707     virtual int find_memory_regions (find_memory_region_ftype func, void *data)
708       TARGET_DEFAULT_FUNC (dummy_find_memory_regions);
709     /* make_corefile_notes support method for gcore */
710     virtual char *make_corefile_notes (bfd *, int *)
711       TARGET_DEFAULT_FUNC (dummy_make_corefile_notes);
712     /* get_bookmark support method for bookmarks */
713     virtual gdb_byte *get_bookmark (const char *, int)
714       TARGET_DEFAULT_NORETURN (tcomplain ());
715     /* goto_bookmark support method for bookmarks */
716     virtual void goto_bookmark (const gdb_byte *, int)
717       TARGET_DEFAULT_NORETURN (tcomplain ());
718     /* Return the thread-local address at OFFSET in the
719        thread-local storage for the thread PTID and the shared library
720        or executable file given by OBJFILE.  If that block of
721        thread-local storage hasn't been allocated yet, this function
722        may return an error.  LOAD_MODULE_ADDR may be zero for statically
723        linked multithreaded inferiors.  */
724     virtual CORE_ADDR get_thread_local_address (ptid_t ptid,
725                                                 CORE_ADDR load_module_addr,
726                                                 CORE_ADDR offset)
727       TARGET_DEFAULT_NORETURN (generic_tls_error ());
728
729     /* Request that OPS transfer up to LEN addressable units of the target's
730        OBJECT.  When reading from a memory object, the size of an addressable
731        unit is architecture dependent and can be found using
732        gdbarch_addressable_memory_unit_size.  Otherwise, an addressable unit is
733        1 byte long.  The OFFSET, for a seekable object, specifies the
734        starting point.  The ANNEX can be used to provide additional
735        data-specific information to the target.
736
737        Return the transferred status, error or OK (an
738        'enum target_xfer_status' value).  Save the number of addressable units
739        actually transferred in *XFERED_LEN if transfer is successful
740        (TARGET_XFER_OK) or the number unavailable units if the requested
741        data is unavailable (TARGET_XFER_UNAVAILABLE).  *XFERED_LEN
742        smaller than LEN does not indicate the end of the object, only
743        the end of the transfer; higher level code should continue
744        transferring if desired.  This is handled in target.c.
745
746        The interface does not support a "retry" mechanism.  Instead it
747        assumes that at least one addressable unit will be transfered on each
748        successful call.
749
750        NOTE: cagney/2003-10-17: The current interface can lead to
751        fragmented transfers.  Lower target levels should not implement
752        hacks, such as enlarging the transfer, in an attempt to
753        compensate for this.  Instead, the target stack should be
754        extended so that it implements supply/collect methods and a
755        look-aside object cache.  With that available, the lowest
756        target can safely and freely "push" data up the stack.
757
758        See target_read and target_write for more information.  One,
759        and only one, of readbuf or writebuf must be non-NULL.  */
760
761     virtual enum target_xfer_status xfer_partial (enum target_object object,
762                                                   const char *annex,
763                                                   gdb_byte *readbuf,
764                                                   const gdb_byte *writebuf,
765                                                   ULONGEST offset, ULONGEST len,
766                                                   ULONGEST *xfered_len)
767       TARGET_DEFAULT_RETURN (TARGET_XFER_E_IO);
768
769     /* Return the limit on the size of any single memory transfer
770        for the target.  */
771
772     virtual ULONGEST get_memory_xfer_limit ()
773       TARGET_DEFAULT_RETURN (ULONGEST_MAX);
774
775     /* Returns the memory map for the target.  A return value of NULL
776        means that no memory map is available.  If a memory address
777        does not fall within any returned regions, it's assumed to be
778        RAM.  The returned memory regions should not overlap.
779
780        The order of regions does not matter; target_memory_map will
781        sort regions by starting address.  For that reason, this
782        function should not be called directly except via
783        target_memory_map.
784
785        This method should not cache data; if the memory map could
786        change unexpectedly, it should be invalidated, and higher
787        layers will re-fetch it.  */
788     virtual std::vector<mem_region> memory_map ()
789       TARGET_DEFAULT_RETURN (std::vector<mem_region> ());
790
791     /* Erases the region of flash memory starting at ADDRESS, of
792        length LENGTH.
793
794        Precondition: both ADDRESS and ADDRESS+LENGTH should be aligned
795        on flash block boundaries, as reported by 'to_memory_map'.  */
796     virtual void flash_erase (ULONGEST address, LONGEST length)
797       TARGET_DEFAULT_NORETURN (tcomplain ());
798
799     /* Finishes a flash memory write sequence.  After this operation
800        all flash memory should be available for writing and the result
801        of reading from areas written by 'to_flash_write' should be
802        equal to what was written.  */
803     virtual void flash_done ()
804       TARGET_DEFAULT_NORETURN (tcomplain ());
805
806     /* Describe the architecture-specific features of this target.  If
807        OPS doesn't have a description, this should delegate to the
808        "beneath" target.  Returns the description found, or NULL if no
809        description was available.  */
810     virtual const struct target_desc *read_description ()
811          TARGET_DEFAULT_RETURN (NULL);
812
813     /* Build the PTID of the thread on which a given task is running,
814        based on LWP and THREAD.  These values are extracted from the
815        task Private_Data section of the Ada Task Control Block, and
816        their interpretation depends on the target.  */
817     virtual ptid_t get_ada_task_ptid (long lwp, long thread)
818       TARGET_DEFAULT_FUNC (default_get_ada_task_ptid);
819
820     /* Read one auxv entry from *READPTR, not reading locations >= ENDPTR.
821        Return 0 if *READPTR is already at the end of the buffer.
822        Return -1 if there is insufficient buffer for a whole entry.
823        Return 1 if an entry was read into *TYPEP and *VALP.  */
824     virtual int auxv_parse (gdb_byte **readptr,
825                             gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
826       TARGET_DEFAULT_FUNC (default_auxv_parse);
827
828     /* Search SEARCH_SPACE_LEN bytes beginning at START_ADDR for the
829        sequence of bytes in PATTERN with length PATTERN_LEN.
830
831        The result is 1 if found, 0 if not found, and -1 if there was an error
832        requiring halting of the search (e.g. memory read error).
833        If the pattern is found the address is recorded in FOUND_ADDRP.  */
834     virtual int search_memory (CORE_ADDR start_addr, ULONGEST search_space_len,
835                                const gdb_byte *pattern, ULONGEST pattern_len,
836                                CORE_ADDR *found_addrp)
837       TARGET_DEFAULT_FUNC (default_search_memory);
838
839     /* Can target execute in reverse?  */
840     virtual bool can_execute_reverse ()
841       TARGET_DEFAULT_RETURN (false);
842
843     /* The direction the target is currently executing.  Must be
844        implemented on targets that support reverse execution and async
845        mode.  The default simply returns forward execution.  */
846     virtual enum exec_direction_kind execution_direction ()
847       TARGET_DEFAULT_FUNC (default_execution_direction);
848
849     /* Does this target support debugging multiple processes
850        simultaneously?  */
851     virtual bool supports_multi_process ()
852       TARGET_DEFAULT_RETURN (false);
853
854     /* Does this target support enabling and disabling tracepoints while a trace
855        experiment is running?  */
856     virtual bool supports_enable_disable_tracepoint ()
857       TARGET_DEFAULT_RETURN (false);
858
859     /* Does this target support disabling address space randomization?  */
860     virtual bool supports_disable_randomization ()
861       TARGET_DEFAULT_FUNC (find_default_supports_disable_randomization);
862
863     /* Does this target support the tracenz bytecode for string collection?  */
864     virtual bool supports_string_tracing ()
865       TARGET_DEFAULT_RETURN (false);
866
867     /* Does this target support evaluation of breakpoint conditions on its
868        end?  */
869     virtual bool supports_evaluation_of_breakpoint_conditions ()
870       TARGET_DEFAULT_RETURN (false);
871
872     /* Does this target support evaluation of breakpoint commands on its
873        end?  */
874     virtual bool can_run_breakpoint_commands ()
875       TARGET_DEFAULT_RETURN (false);
876
877     /* Determine current architecture of thread PTID.
878
879        The target is supposed to determine the architecture of the code where
880        the target is currently stopped at (on Cell, if a target is in spu_run,
881        to_thread_architecture would return SPU, otherwise PPC32 or PPC64).
882        This is architecture used to perform decr_pc_after_break adjustment,
883        and also determines the frame architecture of the innermost frame.
884        ptrace operations need to operate according to target_gdbarch ().
885
886        The default implementation always returns target_gdbarch ().  */
887     virtual struct gdbarch *thread_architecture (ptid_t)
888       TARGET_DEFAULT_FUNC (default_thread_architecture);
889
890     /* Determine current address space of thread PTID.
891
892        The default implementation always returns the inferior's
893        address space.  */
894     virtual struct address_space *thread_address_space (ptid_t)
895       TARGET_DEFAULT_FUNC (default_thread_address_space);
896
897     /* Target file operations.  */
898
899     /* Return nonzero if the filesystem seen by the current inferior
900        is the local filesystem, zero otherwise.  */
901     virtual bool filesystem_is_local ()
902       TARGET_DEFAULT_RETURN (true);
903
904     /* Open FILENAME on the target, in the filesystem as seen by INF,
905        using FLAGS and MODE.  If INF is NULL, use the filesystem seen
906        by the debugger (GDB or, for remote targets, the remote stub).
907        If WARN_IF_SLOW is nonzero, print a warning message if the file
908        is being accessed over a link that may be slow.  Return a
909        target file descriptor, or -1 if an error occurs (and set
910        *TARGET_ERRNO).  */
911     virtual int fileio_open (struct inferior *inf, const char *filename,
912                              int flags, int mode, int warn_if_slow,
913                              int *target_errno);
914
915     /* Write up to LEN bytes from WRITE_BUF to FD on the target.
916        Return the number of bytes written, or -1 if an error occurs
917        (and set *TARGET_ERRNO).  */
918     virtual int fileio_pwrite (int fd, const gdb_byte *write_buf, int len,
919                                ULONGEST offset, int *target_errno);
920
921     /* Read up to LEN bytes FD on the target into READ_BUF.
922        Return the number of bytes read, or -1 if an error occurs
923        (and set *TARGET_ERRNO).  */
924     virtual int fileio_pread (int fd, gdb_byte *read_buf, int len,
925                               ULONGEST offset, int *target_errno);
926
927     /* Get information about the file opened as FD and put it in
928        SB.  Return 0 on success, or -1 if an error occurs (and set
929        *TARGET_ERRNO).  */
930     virtual int fileio_fstat (int fd, struct stat *sb, int *target_errno);
931
932     /* Close FD on the target.  Return 0, or -1 if an error occurs
933        (and set *TARGET_ERRNO).  */
934     virtual int fileio_close (int fd, int *target_errno);
935
936     /* Unlink FILENAME on the target, in the filesystem as seen by
937        INF.  If INF is NULL, use the filesystem seen by the debugger
938        (GDB or, for remote targets, the remote stub).  Return 0, or
939        -1 if an error occurs (and set *TARGET_ERRNO).  */
940     virtual int fileio_unlink (struct inferior *inf,
941                                const char *filename,
942                                int *target_errno);
943
944     /* Read value of symbolic link FILENAME on the target, in the
945        filesystem as seen by INF.  If INF is NULL, use the filesystem
946        seen by the debugger (GDB or, for remote targets, the remote
947        stub).  Return a string, or an empty optional if an error
948        occurs (and set *TARGET_ERRNO).  */
949     virtual gdb::optional<std::string> fileio_readlink (struct inferior *inf,
950                                                         const char *filename,
951                                                         int *target_errno);
952
953     /* Implement the "info proc" command.  Returns true if the target
954        actually implemented the command, false otherwise.  */
955     virtual bool info_proc (const char *, enum info_proc_what);
956
957     /* Tracepoint-related operations.  */
958
959     /* Prepare the target for a tracing run.  */
960     virtual void trace_init ()
961       TARGET_DEFAULT_NORETURN (tcomplain ());
962
963     /* Send full details of a tracepoint location to the target.  */
964     virtual void download_tracepoint (struct bp_location *location)
965       TARGET_DEFAULT_NORETURN (tcomplain ());
966
967     /* Is the target able to download tracepoint locations in current
968        state?  */
969     virtual bool can_download_tracepoint ()
970       TARGET_DEFAULT_RETURN (false);
971
972     /* Send full details of a trace state variable to the target.  */
973     virtual void download_trace_state_variable (const trace_state_variable &tsv)
974       TARGET_DEFAULT_NORETURN (tcomplain ());
975
976     /* Enable a tracepoint on the target.  */
977     virtual void enable_tracepoint (struct bp_location *location)
978       TARGET_DEFAULT_NORETURN (tcomplain ());
979
980     /* Disable a tracepoint on the target.  */
981     virtual void disable_tracepoint (struct bp_location *location)
982       TARGET_DEFAULT_NORETURN (tcomplain ());
983
984     /* Inform the target info of memory regions that are readonly
985        (such as text sections), and so it should return data from
986        those rather than look in the trace buffer.  */
987     virtual void trace_set_readonly_regions ()
988       TARGET_DEFAULT_NORETURN (tcomplain ());
989
990     /* Start a trace run.  */
991     virtual void trace_start ()
992       TARGET_DEFAULT_NORETURN (tcomplain ());
993
994     /* Get the current status of a tracing run.  */
995     virtual int get_trace_status (struct trace_status *ts)
996       TARGET_DEFAULT_RETURN (-1);
997
998     virtual void get_tracepoint_status (struct breakpoint *tp,
999                                         struct uploaded_tp *utp)
1000       TARGET_DEFAULT_NORETURN (tcomplain ());
1001
1002     /* Stop a trace run.  */
1003     virtual void trace_stop ()
1004       TARGET_DEFAULT_NORETURN (tcomplain ());
1005
1006    /* Ask the target to find a trace frame of the given type TYPE,
1007       using NUM, ADDR1, and ADDR2 as search parameters.  Returns the
1008       number of the trace frame, and also the tracepoint number at
1009       TPP.  If no trace frame matches, return -1.  May throw if the
1010       operation fails.  */
1011     virtual int trace_find (enum trace_find_type type, int num,
1012                             CORE_ADDR addr1, CORE_ADDR addr2, int *tpp)
1013       TARGET_DEFAULT_RETURN (-1);
1014
1015     /* Get the value of the trace state variable number TSV, returning
1016        1 if the value is known and writing the value itself into the
1017        location pointed to by VAL, else returning 0.  */
1018     virtual bool get_trace_state_variable_value (int tsv, LONGEST *val)
1019       TARGET_DEFAULT_RETURN (false);
1020
1021     virtual int save_trace_data (const char *filename)
1022       TARGET_DEFAULT_NORETURN (tcomplain ());
1023
1024     virtual int upload_tracepoints (struct uploaded_tp **utpp)
1025       TARGET_DEFAULT_RETURN (0);
1026
1027     virtual int upload_trace_state_variables (struct uploaded_tsv **utsvp)
1028       TARGET_DEFAULT_RETURN (0);
1029
1030     virtual LONGEST get_raw_trace_data (gdb_byte *buf,
1031                                         ULONGEST offset, LONGEST len)
1032       TARGET_DEFAULT_NORETURN (tcomplain ());
1033
1034     /* Get the minimum length of instruction on which a fast tracepoint
1035        may be set on the target.  If this operation is unsupported,
1036        return -1.  If for some reason the minimum length cannot be
1037        determined, return 0.  */
1038     virtual int get_min_fast_tracepoint_insn_len ()
1039       TARGET_DEFAULT_RETURN (-1);
1040
1041     /* Set the target's tracing behavior in response to unexpected
1042        disconnection - set VAL to 1 to keep tracing, 0 to stop.  */
1043     virtual void set_disconnected_tracing (int val)
1044       TARGET_DEFAULT_IGNORE ();
1045     virtual void set_circular_trace_buffer (int val)
1046       TARGET_DEFAULT_IGNORE ();
1047     /* Set the size of trace buffer in the target.  */
1048     virtual void set_trace_buffer_size (LONGEST val)
1049       TARGET_DEFAULT_IGNORE ();
1050
1051     /* Add/change textual notes about the trace run, returning 1 if
1052        successful, 0 otherwise.  */
1053     virtual bool set_trace_notes (const char *user, const char *notes,
1054                                   const char *stopnotes)
1055       TARGET_DEFAULT_RETURN (false);
1056
1057     /* Return the processor core that thread PTID was last seen on.
1058        This information is updated only when:
1059        - update_thread_list is called
1060        - thread stops
1061        If the core cannot be determined -- either for the specified
1062        thread, or right now, or in this debug session, or for this
1063        target -- return -1.  */
1064     virtual int core_of_thread (ptid_t ptid)
1065       TARGET_DEFAULT_RETURN (-1);
1066
1067     /* Verify that the memory in the [MEMADDR, MEMADDR+SIZE) range
1068        matches the contents of [DATA,DATA+SIZE).  Returns 1 if there's
1069        a match, 0 if there's a mismatch, and -1 if an error is
1070        encountered while reading memory.  */
1071     virtual int verify_memory (const gdb_byte *data,
1072                                CORE_ADDR memaddr, ULONGEST size)
1073       TARGET_DEFAULT_FUNC (default_verify_memory);
1074
1075     /* Return the address of the start of the Thread Information Block
1076        a Windows OS specific feature.  */
1077     virtual bool get_tib_address (ptid_t ptid, CORE_ADDR *addr)
1078       TARGET_DEFAULT_NORETURN (tcomplain ());
1079
1080     /* Send the new settings of write permission variables.  */
1081     virtual void set_permissions ()
1082       TARGET_DEFAULT_IGNORE ();
1083
1084     /* Look for a static tracepoint marker at ADDR, and fill in MARKER
1085        with its details.  Return true on success, false on failure.  */
1086     virtual bool static_tracepoint_marker_at (CORE_ADDR,
1087                                               static_tracepoint_marker *marker)
1088       TARGET_DEFAULT_RETURN (false);
1089
1090     /* Return a vector of all tracepoints markers string id ID, or all
1091        markers if ID is NULL.  */
1092     virtual std::vector<static_tracepoint_marker>
1093       static_tracepoint_markers_by_strid (const char *id)
1094       TARGET_DEFAULT_NORETURN (tcomplain ());
1095
1096     /* Return a traceframe info object describing the current
1097        traceframe's contents.  This method should not cache data;
1098        higher layers take care of caching, invalidating, and
1099        re-fetching when necessary.  */
1100     virtual traceframe_info_up traceframe_info ()
1101       TARGET_DEFAULT_NORETURN (tcomplain ());
1102
1103     /* Ask the target to use or not to use agent according to USE.
1104        Return true if successful, false otherwise.  */
1105     virtual bool use_agent (bool use)
1106       TARGET_DEFAULT_NORETURN (tcomplain ());
1107
1108     /* Is the target able to use agent in current state?  */
1109     virtual bool can_use_agent ()
1110       TARGET_DEFAULT_RETURN (false);
1111
1112     /* Enable branch tracing for PTID using CONF configuration.
1113        Return a branch trace target information struct for reading and for
1114        disabling branch trace.  */
1115     virtual struct btrace_target_info *enable_btrace (ptid_t ptid,
1116                                                       const struct btrace_config *conf)
1117       TARGET_DEFAULT_NORETURN (tcomplain ());
1118
1119     /* Disable branch tracing and deallocate TINFO.  */
1120     virtual void disable_btrace (struct btrace_target_info *tinfo)
1121       TARGET_DEFAULT_NORETURN (tcomplain ());
1122
1123     /* Disable branch tracing and deallocate TINFO.  This function is similar
1124        to to_disable_btrace, except that it is called during teardown and is
1125        only allowed to perform actions that are safe.  A counter-example would
1126        be attempting to talk to a remote target.  */
1127     virtual void teardown_btrace (struct btrace_target_info *tinfo)
1128       TARGET_DEFAULT_NORETURN (tcomplain ());
1129
1130     /* Read branch trace data for the thread indicated by BTINFO into DATA.
1131        DATA is cleared before new trace is added.  */
1132     virtual enum btrace_error read_btrace (struct btrace_data *data,
1133                                            struct btrace_target_info *btinfo,
1134                                            enum btrace_read_type type)
1135       TARGET_DEFAULT_NORETURN (tcomplain ());
1136
1137     /* Get the branch trace configuration.  */
1138     virtual const struct btrace_config *btrace_conf (const struct btrace_target_info *)
1139       TARGET_DEFAULT_RETURN (NULL);
1140
1141     /* Current recording method.  */
1142     virtual enum record_method record_method (ptid_t ptid)
1143       TARGET_DEFAULT_RETURN (RECORD_METHOD_NONE);
1144
1145     /* Stop trace recording.  */
1146     virtual void stop_recording ()
1147       TARGET_DEFAULT_IGNORE ();
1148
1149     /* Print information about the recording.  */
1150     virtual void info_record ()
1151       TARGET_DEFAULT_IGNORE ();
1152
1153     /* Save the recorded execution trace into a file.  */
1154     virtual void save_record (const char *filename)
1155       TARGET_DEFAULT_NORETURN (tcomplain ());
1156
1157     /* Delete the recorded execution trace from the current position
1158        onwards.  */
1159     virtual bool supports_delete_record ()
1160       TARGET_DEFAULT_RETURN (false);
1161     virtual void delete_record ()
1162       TARGET_DEFAULT_NORETURN (tcomplain ());
1163
1164     /* Query if the record target is currently replaying PTID.  */
1165     virtual bool record_is_replaying (ptid_t ptid)
1166       TARGET_DEFAULT_RETURN (false);
1167
1168     /* Query if the record target will replay PTID if it were resumed in
1169        execution direction DIR.  */
1170     virtual bool record_will_replay (ptid_t ptid, int dir)
1171       TARGET_DEFAULT_RETURN (false);
1172
1173     /* Stop replaying.  */
1174     virtual void record_stop_replaying ()
1175       TARGET_DEFAULT_IGNORE ();
1176
1177     /* Go to the begin of the execution trace.  */
1178     virtual void goto_record_begin ()
1179       TARGET_DEFAULT_NORETURN (tcomplain ());
1180
1181     /* Go to the end of the execution trace.  */
1182     virtual void goto_record_end ()
1183       TARGET_DEFAULT_NORETURN (tcomplain ());
1184
1185     /* Go to a specific location in the recorded execution trace.  */
1186     virtual void goto_record (ULONGEST insn)
1187       TARGET_DEFAULT_NORETURN (tcomplain ());
1188
1189     /* Disassemble SIZE instructions in the recorded execution trace from
1190        the current position.
1191        If SIZE < 0, disassemble abs (SIZE) preceding instructions; otherwise,
1192        disassemble SIZE succeeding instructions.  */
1193     virtual void insn_history (int size, gdb_disassembly_flags flags)
1194       TARGET_DEFAULT_NORETURN (tcomplain ());
1195
1196     /* Disassemble SIZE instructions in the recorded execution trace around
1197        FROM.
1198        If SIZE < 0, disassemble abs (SIZE) instructions before FROM; otherwise,
1199        disassemble SIZE instructions after FROM.  */
1200     virtual void insn_history_from (ULONGEST from, int size,
1201                                     gdb_disassembly_flags flags)
1202       TARGET_DEFAULT_NORETURN (tcomplain ());
1203
1204     /* Disassemble a section of the recorded execution trace from instruction
1205        BEGIN (inclusive) to instruction END (inclusive).  */
1206     virtual void insn_history_range (ULONGEST begin, ULONGEST end,
1207                                      gdb_disassembly_flags flags)
1208       TARGET_DEFAULT_NORETURN (tcomplain ());
1209
1210     /* Print a function trace of the recorded execution trace.
1211        If SIZE < 0, print abs (SIZE) preceding functions; otherwise, print SIZE
1212        succeeding functions.  */
1213     virtual void call_history (int size, record_print_flags flags)
1214       TARGET_DEFAULT_NORETURN (tcomplain ());
1215
1216     /* Print a function trace of the recorded execution trace starting
1217        at function FROM.
1218        If SIZE < 0, print abs (SIZE) functions before FROM; otherwise, print
1219        SIZE functions after FROM.  */
1220     virtual void call_history_from (ULONGEST begin, int size, record_print_flags flags)
1221       TARGET_DEFAULT_NORETURN (tcomplain ());
1222
1223     /* Print a function trace of an execution trace section from function BEGIN
1224        (inclusive) to function END (inclusive).  */
1225     virtual void call_history_range (ULONGEST begin, ULONGEST end, record_print_flags flags)
1226       TARGET_DEFAULT_NORETURN (tcomplain ());
1227
1228     /* True if TARGET_OBJECT_LIBRARIES_SVR4 may be read with a
1229        non-empty annex.  */
1230     virtual bool augmented_libraries_svr4_read ()
1231       TARGET_DEFAULT_RETURN (false);
1232
1233     /* Those unwinders are tried before any other arch unwinders.  If
1234        SELF doesn't have unwinders, it should delegate to the
1235        "beneath" target.  */
1236     virtual const struct frame_unwind *get_unwinder ()
1237       TARGET_DEFAULT_RETURN (NULL);
1238
1239     virtual const struct frame_unwind *get_tailcall_unwinder ()
1240       TARGET_DEFAULT_RETURN (NULL);
1241
1242     /* Prepare to generate a core file.  */
1243     virtual void prepare_to_generate_core ()
1244       TARGET_DEFAULT_IGNORE ();
1245
1246     /* Cleanup after generating a core file.  */
1247     virtual void done_generating_core ()
1248       TARGET_DEFAULT_IGNORE ();
1249   };
1250
1251 /* Deleter for std::unique_ptr.  See comments in
1252    target_ops::~target_ops and target_ops::close about heap-allocated
1253    targets.  */
1254 struct target_ops_deleter
1255 {
1256   void operator() (target_ops *target)
1257   {
1258     target->close ();
1259   }
1260 };
1261
1262 /* A unique pointer for target_ops.  */
1263 typedef std::unique_ptr<target_ops, target_ops_deleter> target_ops_up;
1264
1265 /* Native target backends call this once at initialization time to
1266    inform the core about which is the target that can respond to "run"
1267    or "attach".  Note: native targets are always singletons.  */
1268 extern void set_native_target (target_ops *target);
1269
1270 /* Get the registered native target, if there's one.  Otherwise return
1271    NULL.  */
1272 extern target_ops *get_native_target ();
1273
1274 /* Type that manages a target stack.  See description of target stacks
1275    and strata at the top of the file.  */
1276
1277 class target_stack
1278 {
1279 public:
1280   target_stack () = default;
1281   DISABLE_COPY_AND_ASSIGN (target_stack);
1282
1283   /* Push a new target into the stack of the existing target
1284      accessors, possibly superseding some existing accessor.  */
1285   void push (target_ops *t);
1286
1287   /* Remove a target from the stack, wherever it may be.  Return true
1288      if it was removed, false otherwise.  */
1289   bool unpush (target_ops *t);
1290
1291   /* Returns true if T is pushed on the target stack.  */
1292   bool is_pushed (target_ops *t) const
1293   { return at (t->to_stratum) == t; }
1294
1295   /* Return the target at STRATUM.  */
1296   target_ops *at (strata stratum) const { return m_stack[stratum]; }
1297
1298   /* Return the target at the top of the stack.  */
1299   target_ops *top () const { return at (m_top); }
1300
1301   /* Find the next target down the stack from the specified target.  */
1302   target_ops *find_beneath (const target_ops *t) const;
1303
1304 private:
1305   /* The stratum of the top target.  */
1306   enum strata m_top {};
1307
1308   /* The stack, represented as an array, with one slot per stratum.
1309      If no target is pushed at some stratum, the corresponding slot is
1310      null.  */
1311   target_ops *m_stack[(int) debug_stratum + 1] {};
1312 };
1313
1314 /* The ops structure for our "current" target process.  This should
1315    never be NULL.  If there is no target, it points to the dummy_target.  */
1316
1317 extern target_ops *current_top_target ();
1318
1319 /* Define easy words for doing these operations on our current target.  */
1320
1321 #define target_shortname        (current_top_target ()->shortname ())
1322 #define target_longname         (current_top_target ()->longname ())
1323
1324 /* Does whatever cleanup is required for a target that we are no
1325    longer going to be calling.  This routine is automatically always
1326    called after popping the target off the target stack - the target's
1327    own methods are no longer available through the target vector.
1328    Closing file descriptors and freeing all memory allocated memory are
1329    typical things it should do.  */
1330
1331 void target_close (struct target_ops *targ);
1332
1333 /* Find the correct target to use for "attach".  If a target on the
1334    current stack supports attaching, then it is returned.  Otherwise,
1335    the default run target is returned.  */
1336
1337 extern struct target_ops *find_attach_target (void);
1338
1339 /* Find the correct target to use for "run".  If a target on the
1340    current stack supports creating a new inferior, then it is
1341    returned.  Otherwise, the default run target is returned.  */
1342
1343 extern struct target_ops *find_run_target (void);
1344
1345 /* Some targets don't generate traps when attaching to the inferior,
1346    or their target_attach implementation takes care of the waiting.
1347    These targets must set to_attach_no_wait.  */
1348
1349 #define target_attach_no_wait() \
1350   (current_top_target ()->attach_no_wait ())
1351
1352 /* The target_attach operation places a process under debugger control,
1353    and stops the process.
1354
1355    This operation provides a target-specific hook that allows the
1356    necessary bookkeeping to be performed after an attach completes.  */
1357 #define target_post_attach(pid) \
1358      (current_top_target ()->post_attach) (pid)
1359
1360 /* Display a message indicating we're about to detach from the current
1361    inferior process.  */
1362
1363 extern void target_announce_detach (int from_tty);
1364
1365 /* Takes a program previously attached to and detaches it.
1366    The program may resume execution (some targets do, some don't) and will
1367    no longer stop on signals, etc.  We better not have left any breakpoints
1368    in the program or it'll die when it hits one.  FROM_TTY says whether to be
1369    verbose or not.  */
1370
1371 extern void target_detach (inferior *inf, int from_tty);
1372
1373 /* Disconnect from the current target without resuming it (leaving it
1374    waiting for a debugger).  */
1375
1376 extern void target_disconnect (const char *, int);
1377
1378 /* Resume execution (or prepare for execution) of a target thread,
1379    process or all processes.  STEP says whether to hardware
1380    single-step or to run free; SIGGNAL is the signal to be given to
1381    the target, or GDB_SIGNAL_0 for no signal.  The caller may not pass
1382    GDB_SIGNAL_DEFAULT.  A specific PTID means `step/resume only this
1383    process id'.  A wildcard PTID (all threads, or all threads of
1384    process) means `step/resume INFERIOR_PTID, and let other threads
1385    (for which the wildcard PTID matches) resume with their
1386    'thread->suspend.stop_signal' signal (usually GDB_SIGNAL_0) if it
1387    is in "pass" state, or with no signal if in "no pass" state.
1388
1389    In order to efficiently handle batches of resumption requests,
1390    targets may implement this method such that it records the
1391    resumption request, but defers the actual resumption to the
1392    target_commit_resume method implementation.  See
1393    target_commit_resume below.  */
1394 extern void target_resume (ptid_t ptid, int step, enum gdb_signal signal);
1395
1396 /* Commit a series of resumption requests previously prepared with
1397    target_resume calls.
1398
1399    GDB always calls target_commit_resume after calling target_resume
1400    one or more times.  A target may thus use this method in
1401    coordination with the target_resume method to batch target-side
1402    resumption requests.  In that case, the target doesn't actually
1403    resume in its target_resume implementation.  Instead, it prepares
1404    the resumption in target_resume, and defers the actual resumption
1405    to target_commit_resume.  E.g., the remote target uses this to
1406    coalesce multiple resumption requests in a single vCont packet.  */
1407 extern void target_commit_resume ();
1408
1409 /* Setup to defer target_commit_resume calls, and reactivate
1410    target_commit_resume on destruction, if it was previously
1411    active.  */
1412 extern scoped_restore_tmpl<int> make_scoped_defer_target_commit_resume ();
1413
1414 /* For target_read_memory see target/target.h.  */
1415
1416 /* The default target_ops::to_wait implementation.  */
1417
1418 extern ptid_t default_target_wait (struct target_ops *ops,
1419                                    ptid_t ptid,
1420                                    struct target_waitstatus *status,
1421                                    int options);
1422
1423 /* Fetch at least register REGNO, or all regs if regno == -1.  No result.  */
1424
1425 extern void target_fetch_registers (struct regcache *regcache, int regno);
1426
1427 /* Store at least register REGNO, or all regs if REGNO == -1.
1428    It can store as many registers as it wants to, so target_prepare_to_store
1429    must have been previously called.  Calls error() if there are problems.  */
1430
1431 extern void target_store_registers (struct regcache *regcache, int regs);
1432
1433 /* Get ready to modify the registers array.  On machines which store
1434    individual registers, this doesn't need to do anything.  On machines
1435    which store all the registers in one fell swoop, this makes sure
1436    that REGISTERS contains all the registers from the program being
1437    debugged.  */
1438
1439 #define target_prepare_to_store(regcache)       \
1440      (current_top_target ()->prepare_to_store) (regcache)
1441
1442 /* Determine current address space of thread PTID.  */
1443
1444 struct address_space *target_thread_address_space (ptid_t);
1445
1446 /* Implement the "info proc" command.  This returns one if the request
1447    was handled, and zero otherwise.  It can also throw an exception if
1448    an error was encountered while attempting to handle the
1449    request.  */
1450
1451 int target_info_proc (const char *, enum info_proc_what);
1452
1453 /* Returns true if this target can disable address space randomization.  */
1454
1455 int target_supports_disable_randomization (void);
1456
1457 /* Returns true if this target can enable and disable tracepoints
1458    while a trace experiment is running.  */
1459
1460 #define target_supports_enable_disable_tracepoint() \
1461   (current_top_target ()->supports_enable_disable_tracepoint) ()
1462
1463 #define target_supports_string_tracing() \
1464   (current_top_target ()->supports_string_tracing) ()
1465
1466 /* Returns true if this target can handle breakpoint conditions
1467    on its end.  */
1468
1469 #define target_supports_evaluation_of_breakpoint_conditions() \
1470   (current_top_target ()->supports_evaluation_of_breakpoint_conditions) ()
1471
1472 /* Returns true if this target can handle breakpoint commands
1473    on its end.  */
1474
1475 #define target_can_run_breakpoint_commands() \
1476   (current_top_target ()->can_run_breakpoint_commands) ()
1477
1478 extern int target_read_string (CORE_ADDR, gdb::unique_xmalloc_ptr<char> *,
1479                                int, int *);
1480
1481 /* For target_read_memory see target/target.h.  */
1482
1483 extern int target_read_raw_memory (CORE_ADDR memaddr, gdb_byte *myaddr,
1484                                    ssize_t len);
1485
1486 extern int target_read_stack (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len);
1487
1488 extern int target_read_code (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len);
1489
1490 /* For target_write_memory see target/target.h.  */
1491
1492 extern int target_write_raw_memory (CORE_ADDR memaddr, const gdb_byte *myaddr,
1493                                     ssize_t len);
1494
1495 /* Fetches the target's memory map.  If one is found it is sorted
1496    and returned, after some consistency checking.  Otherwise, NULL
1497    is returned.  */
1498 std::vector<mem_region> target_memory_map (void);
1499
1500 /* Erases all flash memory regions on the target.  */
1501 void flash_erase_command (const char *cmd, int from_tty);
1502
1503 /* Erase the specified flash region.  */
1504 void target_flash_erase (ULONGEST address, LONGEST length);
1505
1506 /* Finish a sequence of flash operations.  */
1507 void target_flash_done (void);
1508
1509 /* Describes a request for a memory write operation.  */
1510 struct memory_write_request
1511 {
1512   memory_write_request (ULONGEST begin_, ULONGEST end_,
1513                         gdb_byte *data_ = nullptr, void *baton_ = nullptr)
1514     : begin (begin_), end (end_), data (data_), baton (baton_)
1515   {}
1516
1517   /* Begining address that must be written.  */
1518   ULONGEST begin;
1519   /* Past-the-end address.  */
1520   ULONGEST end;
1521   /* The data to write.  */
1522   gdb_byte *data;
1523   /* A callback baton for progress reporting for this request.  */
1524   void *baton;
1525 };
1526
1527 /* Enumeration specifying different flash preservation behaviour.  */
1528 enum flash_preserve_mode
1529   {
1530     flash_preserve,
1531     flash_discard
1532   };
1533
1534 /* Write several memory blocks at once.  This version can be more
1535    efficient than making several calls to target_write_memory, in
1536    particular because it can optimize accesses to flash memory.
1537
1538    Moreover, this is currently the only memory access function in gdb
1539    that supports writing to flash memory, and it should be used for
1540    all cases where access to flash memory is desirable.
1541
1542    REQUESTS is the vector (see vec.h) of memory_write_request.
1543    PRESERVE_FLASH_P indicates what to do with blocks which must be
1544      erased, but not completely rewritten.
1545    PROGRESS_CB is a function that will be periodically called to provide
1546      feedback to user.  It will be called with the baton corresponding
1547      to the request currently being written.  It may also be called
1548      with a NULL baton, when preserved flash sectors are being rewritten.
1549
1550    The function returns 0 on success, and error otherwise.  */
1551 int target_write_memory_blocks
1552     (const std::vector<memory_write_request> &requests,
1553      enum flash_preserve_mode preserve_flash_p,
1554      void (*progress_cb) (ULONGEST, void *));
1555
1556 /* Print a line about the current target.  */
1557
1558 #define target_files_info()     \
1559      (current_top_target ()->files_info) ()
1560
1561 /* Insert a breakpoint at address BP_TGT->placed_address in
1562    the target machine.  Returns 0 for success, and returns non-zero or
1563    throws an error (with a detailed failure reason error code and
1564    message) otherwise.  */
1565
1566 extern int target_insert_breakpoint (struct gdbarch *gdbarch,
1567                                      struct bp_target_info *bp_tgt);
1568
1569 /* Remove a breakpoint at address BP_TGT->placed_address in the target
1570    machine.  Result is 0 for success, non-zero for error.  */
1571
1572 extern int target_remove_breakpoint (struct gdbarch *gdbarch,
1573                                      struct bp_target_info *bp_tgt,
1574                                      enum remove_bp_reason reason);
1575
1576 /* Return true if the target stack has a non-default
1577   "terminal_ours" method.  */
1578
1579 extern int target_supports_terminal_ours (void);
1580
1581 /* Kill the inferior process.   Make it go away.  */
1582
1583 extern void target_kill (void);
1584
1585 /* Load an executable file into the target process.  This is expected
1586    to not only bring new code into the target process, but also to
1587    update GDB's symbol tables to match.
1588
1589    ARG contains command-line arguments, to be broken down with
1590    buildargv ().  The first non-switch argument is the filename to
1591    load, FILE; the second is a number (as parsed by strtoul (..., ...,
1592    0)), which is an offset to apply to the load addresses of FILE's
1593    sections.  The target may define switches, or other non-switch
1594    arguments, as it pleases.  */
1595
1596 extern void target_load (const char *arg, int from_tty);
1597
1598 /* Some targets (such as ttrace-based HPUX) don't allow us to request
1599    notification of inferior events such as fork and vork immediately
1600    after the inferior is created.  (This because of how gdb gets an
1601    inferior created via invoking a shell to do it.  In such a scenario,
1602    if the shell init file has commands in it, the shell will fork and
1603    exec for each of those commands, and we will see each such fork
1604    event.  Very bad.)
1605
1606    Such targets will supply an appropriate definition for this function.  */
1607
1608 #define target_post_startup_inferior(ptid) \
1609      (current_top_target ()->post_startup_inferior) (ptid)
1610
1611 /* On some targets, we can catch an inferior fork or vfork event when
1612    it occurs.  These functions insert/remove an already-created
1613    catchpoint for such events.  They return  0 for success, 1 if the
1614    catchpoint type is not supported and -1 for failure.  */
1615
1616 #define target_insert_fork_catchpoint(pid) \
1617      (current_top_target ()->insert_fork_catchpoint) (pid)
1618
1619 #define target_remove_fork_catchpoint(pid) \
1620      (current_top_target ()->remove_fork_catchpoint) (pid)
1621
1622 #define target_insert_vfork_catchpoint(pid) \
1623      (current_top_target ()->insert_vfork_catchpoint) (pid)
1624
1625 #define target_remove_vfork_catchpoint(pid) \
1626      (current_top_target ()->remove_vfork_catchpoint) (pid)
1627
1628 /* If the inferior forks or vforks, this function will be called at
1629    the next resume in order to perform any bookkeeping and fiddling
1630    necessary to continue debugging either the parent or child, as
1631    requested, and releasing the other.  Information about the fork
1632    or vfork event is available via get_last_target_status ().
1633    This function returns 1 if the inferior should not be resumed
1634    (i.e. there is another event pending).  */
1635
1636 int target_follow_fork (int follow_child, int detach_fork);
1637
1638 /* Handle the target-specific bookkeeping required when the inferior
1639    makes an exec call.  INF is the exec'd inferior.  */
1640
1641 void target_follow_exec (struct inferior *inf, char *execd_pathname);
1642
1643 /* On some targets, we can catch an inferior exec event when it
1644    occurs.  These functions insert/remove an already-created
1645    catchpoint for such events.  They return  0 for success, 1 if the
1646    catchpoint type is not supported and -1 for failure.  */
1647
1648 #define target_insert_exec_catchpoint(pid) \
1649      (current_top_target ()->insert_exec_catchpoint) (pid)
1650
1651 #define target_remove_exec_catchpoint(pid) \
1652      (current_top_target ()->remove_exec_catchpoint) (pid)
1653
1654 /* Syscall catch.
1655
1656    NEEDED is true if any syscall catch (of any kind) is requested.
1657    If NEEDED is false, it means the target can disable the mechanism to
1658    catch system calls because there are no more catchpoints of this type.
1659
1660    ANY_COUNT is nonzero if a generic (filter-less) syscall catch is
1661    being requested.  In this case, SYSCALL_COUNTS should be ignored.
1662
1663    SYSCALL_COUNTS is an array of ints, indexed by syscall number.  An
1664    element in this array is nonzero if that syscall should be caught.
1665    This argument only matters if ANY_COUNT is zero.
1666
1667    Return 0 for success, 1 if syscall catchpoints are not supported or -1
1668    for failure.  */
1669
1670 #define target_set_syscall_catchpoint(pid, needed, any_count, syscall_counts) \
1671      (current_top_target ()->set_syscall_catchpoint) (pid, needed, any_count, \
1672                                              syscall_counts)
1673
1674 /* The debugger has completed a blocking wait() call.  There is now
1675    some process event that must be processed.  This function should
1676    be defined by those targets that require the debugger to perform
1677    cleanup or internal state changes in response to the process event.  */
1678
1679 /* For target_mourn_inferior see target/target.h.  */
1680
1681 /* Does target have enough data to do a run or attach command?  */
1682
1683 extern int target_can_run ();
1684
1685 /* Set list of signals to be handled in the target.
1686
1687    PASS_SIGNALS is an array of size NSIG, indexed by target signal number
1688    (enum gdb_signal).  For every signal whose entry in this array is
1689    non-zero, the target is allowed -but not required- to skip reporting
1690    arrival of the signal to the GDB core by returning from target_wait,
1691    and to pass the signal directly to the inferior instead.
1692
1693    However, if the target is hardware single-stepping a thread that is
1694    about to receive a signal, it needs to be reported in any case, even
1695    if mentioned in a previous target_pass_signals call.   */
1696
1697 extern void target_pass_signals (int nsig, unsigned char *pass_signals);
1698
1699 /* Set list of signals the target may pass to the inferior.  This
1700    directly maps to the "handle SIGNAL pass/nopass" setting.
1701
1702    PROGRAM_SIGNALS is an array of size NSIG, indexed by target signal
1703    number (enum gdb_signal).  For every signal whose entry in this
1704    array is non-zero, the target is allowed to pass the signal to the
1705    inferior.  Signals not present in the array shall be silently
1706    discarded.  This does not influence whether to pass signals to the
1707    inferior as a result of a target_resume call.  This is useful in
1708    scenarios where the target needs to decide whether to pass or not a
1709    signal to the inferior without GDB core involvement, such as for
1710    example, when detaching (as threads may have been suspended with
1711    pending signals not reported to GDB).  */
1712
1713 extern void target_program_signals (int nsig, unsigned char *program_signals);
1714
1715 /* Check to see if a thread is still alive.  */
1716
1717 extern int target_thread_alive (ptid_t ptid);
1718
1719 /* Sync the target's threads with GDB's thread list.  */
1720
1721 extern void target_update_thread_list (void);
1722
1723 /* Make target stop in a continuable fashion.  (For instance, under
1724    Unix, this should act like SIGSTOP).  Note that this function is
1725    asynchronous: it does not wait for the target to become stopped
1726    before returning.  If this is the behavior you want please use
1727    target_stop_and_wait.  */
1728
1729 extern void target_stop (ptid_t ptid);
1730
1731 /* Interrupt the target.  Unlike target_stop, this does not specify
1732    which thread/process reports the stop.  For most target this acts
1733    like raising a SIGINT, though that's not absolutely required.  This
1734    function is asynchronous.  */
1735
1736 extern void target_interrupt ();
1737
1738 /* Pass a ^C, as determined to have been pressed by checking the quit
1739    flag, to the target, as if the user had typed the ^C on the
1740    inferior's controlling terminal while the inferior was in the
1741    foreground.  Remote targets may take the opportunity to detect the
1742    remote side is not responding and offer to disconnect.  */
1743
1744 extern void target_pass_ctrlc (void);
1745
1746 /* The default target_ops::to_pass_ctrlc implementation.  Simply calls
1747    target_interrupt.  */
1748 extern void default_target_pass_ctrlc (struct target_ops *ops);
1749
1750 /* Send the specified COMMAND to the target's monitor
1751    (shell,interpreter) for execution.  The result of the query is
1752    placed in OUTBUF.  */
1753
1754 #define target_rcmd(command, outbuf) \
1755      (current_top_target ()->rcmd) (command, outbuf)
1756
1757
1758 /* Does the target include all of memory, or only part of it?  This
1759    determines whether we look up the target chain for other parts of
1760    memory if this target can't satisfy a request.  */
1761
1762 extern int target_has_all_memory_1 (void);
1763 #define target_has_all_memory target_has_all_memory_1 ()
1764
1765 /* Does the target include memory?  (Dummy targets don't.)  */
1766
1767 extern int target_has_memory_1 (void);
1768 #define target_has_memory target_has_memory_1 ()
1769
1770 /* Does the target have a stack?  (Exec files don't, VxWorks doesn't, until
1771    we start a process.)  */
1772
1773 extern int target_has_stack_1 (void);
1774 #define target_has_stack target_has_stack_1 ()
1775
1776 /* Does the target have registers?  (Exec files don't.)  */
1777
1778 extern int target_has_registers_1 (void);
1779 #define target_has_registers target_has_registers_1 ()
1780
1781 /* Does the target have execution?  Can we make it jump (through
1782    hoops), or pop its stack a few times?  This means that the current
1783    target is currently executing; for some targets, that's the same as
1784    whether or not the target is capable of execution, but there are
1785    also targets which can be current while not executing.  In that
1786    case this will become true after to_create_inferior or
1787    to_attach.  */
1788
1789 extern int target_has_execution_1 (ptid_t);
1790
1791 /* Like target_has_execution_1, but always passes inferior_ptid.  */
1792
1793 extern int target_has_execution_current (void);
1794
1795 #define target_has_execution target_has_execution_current ()
1796
1797 /* Default implementations for process_stratum targets.  Return true
1798    if there's a selected inferior, false otherwise.  */
1799
1800 extern int default_child_has_all_memory ();
1801 extern int default_child_has_memory ();
1802 extern int default_child_has_stack ();
1803 extern int default_child_has_registers ();
1804 extern int default_child_has_execution (ptid_t the_ptid);
1805
1806 /* Can the target support the debugger control of thread execution?
1807    Can it lock the thread scheduler?  */
1808
1809 #define target_can_lock_scheduler \
1810   (current_top_target ()->get_thread_control_capabilities () & tc_schedlock)
1811
1812 /* Controls whether async mode is permitted.  */
1813 extern int target_async_permitted;
1814
1815 /* Can the target support asynchronous execution?  */
1816 #define target_can_async_p() (current_top_target ()->can_async_p ())
1817
1818 /* Is the target in asynchronous execution mode?  */
1819 #define target_is_async_p() (current_top_target ()->is_async_p ())
1820
1821 /* Enables/disabled async target events.  */
1822 extern void target_async (int enable);
1823
1824 /* Enables/disables thread create and exit events.  */
1825 extern void target_thread_events (int enable);
1826
1827 /* Whether support for controlling the target backends always in
1828    non-stop mode is enabled.  */
1829 extern enum auto_boolean target_non_stop_enabled;
1830
1831 /* Is the target in non-stop mode?  Some targets control the inferior
1832    in non-stop mode even with "set non-stop off".  Always true if "set
1833    non-stop" is on.  */
1834 extern int target_is_non_stop_p (void);
1835
1836 #define target_execution_direction() \
1837   (current_top_target ()->execution_direction ())
1838
1839 /* Converts a process id to a string.  Usually, the string just contains
1840    `process xyz', but on some systems it may contain
1841    `process xyz thread abc'.  */
1842
1843 extern const char *target_pid_to_str (ptid_t ptid);
1844
1845 extern const char *normal_pid_to_str (ptid_t ptid);
1846
1847 /* Return a short string describing extra information about PID,
1848    e.g. "sleeping", "runnable", "running on LWP 3".  Null return value
1849    is okay.  */
1850
1851 #define target_extra_thread_info(TP) \
1852      (current_top_target ()->extra_thread_info (TP))
1853
1854 /* Return the thread's name, or NULL if the target is unable to determine it.
1855    The returned value must not be freed by the caller.  */
1856
1857 extern const char *target_thread_name (struct thread_info *);
1858
1859 /* Given a pointer to a thread library specific thread handle and
1860    its length, return a pointer to the corresponding thread_info struct.  */
1861
1862 extern struct thread_info *target_thread_handle_to_thread_info
1863   (const gdb_byte *thread_handle, int handle_len, struct inferior *inf);
1864
1865 /* Attempts to find the pathname of the executable file
1866    that was run to create a specified process.
1867
1868    The process PID must be stopped when this operation is used.
1869
1870    If the executable file cannot be determined, NULL is returned.
1871
1872    Else, a pointer to a character string containing the pathname
1873    is returned.  This string should be copied into a buffer by
1874    the client if the string will not be immediately used, or if
1875    it must persist.  */
1876
1877 #define target_pid_to_exec_file(pid) \
1878      (current_top_target ()->pid_to_exec_file) (pid)
1879
1880 /* See the to_thread_architecture description in struct target_ops.  */
1881
1882 #define target_thread_architecture(ptid) \
1883      (current_top_target ()->thread_architecture (ptid))
1884
1885 /*
1886  * Iterator function for target memory regions.
1887  * Calls a callback function once for each memory region 'mapped'
1888  * in the child process.  Defined as a simple macro rather than
1889  * as a function macro so that it can be tested for nullity.
1890  */
1891
1892 #define target_find_memory_regions(FUNC, DATA) \
1893      (current_top_target ()->find_memory_regions) (FUNC, DATA)
1894
1895 /*
1896  * Compose corefile .note section.
1897  */
1898
1899 #define target_make_corefile_notes(BFD, SIZE_P) \
1900      (current_top_target ()->make_corefile_notes) (BFD, SIZE_P)
1901
1902 /* Bookmark interfaces.  */
1903 #define target_get_bookmark(ARGS, FROM_TTY) \
1904      (current_top_target ()->get_bookmark) (ARGS, FROM_TTY)
1905
1906 #define target_goto_bookmark(ARG, FROM_TTY) \
1907      (current_top_target ()->goto_bookmark) (ARG, FROM_TTY)
1908
1909 /* Hardware watchpoint interfaces.  */
1910
1911 /* Returns non-zero if we were stopped by a hardware watchpoint (memory read or
1912    write).  Only the INFERIOR_PTID task is being queried.  */
1913
1914 #define target_stopped_by_watchpoint()          \
1915   ((current_top_target ()->stopped_by_watchpoint) ())
1916
1917 /* Returns non-zero if the target stopped because it executed a
1918    software breakpoint instruction.  */
1919
1920 #define target_stopped_by_sw_breakpoint()               \
1921   ((current_top_target ()->stopped_by_sw_breakpoint) ())
1922
1923 #define target_supports_stopped_by_sw_breakpoint() \
1924   ((current_top_target ()->supports_stopped_by_sw_breakpoint) ())
1925
1926 #define target_stopped_by_hw_breakpoint()                               \
1927   ((current_top_target ()->stopped_by_hw_breakpoint) ())
1928
1929 #define target_supports_stopped_by_hw_breakpoint() \
1930   ((current_top_target ()->supports_stopped_by_hw_breakpoint) ())
1931
1932 /* Non-zero if we have steppable watchpoints  */
1933
1934 #define target_have_steppable_watchpoint \
1935   (current_top_target ()->have_steppable_watchpoint ())
1936
1937 /* Non-zero if we have continuable watchpoints  */
1938
1939 #define target_have_continuable_watchpoint \
1940   (current_top_target ()->have_continuable_watchpoint ())
1941
1942 /* Provide defaults for hardware watchpoint functions.  */
1943
1944 /* If the *_hw_beakpoint functions have not been defined
1945    elsewhere use the definitions in the target vector.  */
1946
1947 /* Returns positive if we can set a hardware watchpoint of type TYPE.
1948    Returns negative if the target doesn't have enough hardware debug
1949    registers available.  Return zero if hardware watchpoint of type
1950    TYPE isn't supported.  TYPE is one of bp_hardware_watchpoint,
1951    bp_read_watchpoint, bp_write_watchpoint, or bp_hardware_breakpoint.
1952    CNT is the number of such watchpoints used so far, including this
1953    one.  OTHERTYPE is the number of watchpoints of other types than
1954    this one used so far.  */
1955
1956 #define target_can_use_hardware_watchpoint(TYPE,CNT,OTHERTYPE) \
1957  (current_top_target ()->can_use_hw_breakpoint) ( \
1958                                              TYPE, CNT, OTHERTYPE)
1959
1960 /* Returns the number of debug registers needed to watch the given
1961    memory region, or zero if not supported.  */
1962
1963 #define target_region_ok_for_hw_watchpoint(addr, len) \
1964     (current_top_target ()->region_ok_for_hw_watchpoint) (addr, len)
1965
1966
1967 #define target_can_do_single_step() \
1968   (current_top_target ()->can_do_single_step) ()
1969
1970 /* Set/clear a hardware watchpoint starting at ADDR, for LEN bytes.
1971    TYPE is 0 for write, 1 for read, and 2 for read/write accesses.
1972    COND is the expression for its condition, or NULL if there's none.
1973    Returns 0 for success, 1 if the watchpoint type is not supported,
1974    -1 for failure.  */
1975
1976 #define target_insert_watchpoint(addr, len, type, cond) \
1977      (current_top_target ()->insert_watchpoint) (addr, len, type, cond)
1978
1979 #define target_remove_watchpoint(addr, len, type, cond) \
1980      (current_top_target ()->remove_watchpoint) (addr, len, type, cond)
1981
1982 /* Insert a new masked watchpoint at ADDR using the mask MASK.
1983    RW may be hw_read for a read watchpoint, hw_write for a write watchpoint
1984    or hw_access for an access watchpoint.  Returns 0 for success, 1 if
1985    masked watchpoints are not supported, -1 for failure.  */
1986
1987 extern int target_insert_mask_watchpoint (CORE_ADDR, CORE_ADDR,
1988                                           enum target_hw_bp_type);
1989
1990 /* Remove a masked watchpoint at ADDR with the mask MASK.
1991    RW may be hw_read for a read watchpoint, hw_write for a write watchpoint
1992    or hw_access for an access watchpoint.  Returns 0 for success, non-zero
1993    for failure.  */
1994
1995 extern int target_remove_mask_watchpoint (CORE_ADDR, CORE_ADDR,
1996                                           enum target_hw_bp_type);
1997
1998 /* Insert a hardware breakpoint at address BP_TGT->placed_address in
1999    the target machine.  Returns 0 for success, and returns non-zero or
2000    throws an error (with a detailed failure reason error code and
2001    message) otherwise.  */
2002
2003 #define target_insert_hw_breakpoint(gdbarch, bp_tgt) \
2004      (current_top_target ()->insert_hw_breakpoint) (gdbarch, bp_tgt)
2005
2006 #define target_remove_hw_breakpoint(gdbarch, bp_tgt) \
2007      (current_top_target ()->remove_hw_breakpoint) (gdbarch, bp_tgt)
2008
2009 /* Return number of debug registers needed for a ranged breakpoint,
2010    or -1 if ranged breakpoints are not supported.  */
2011
2012 extern int target_ranged_break_num_registers (void);
2013
2014 /* Return non-zero if target knows the data address which triggered this
2015    target_stopped_by_watchpoint, in such case place it to *ADDR_P.  Only the
2016    INFERIOR_PTID task is being queried.  */
2017 #define target_stopped_data_address(target, addr_p) \
2018   (target)->stopped_data_address (addr_p)
2019
2020 /* Return non-zero if ADDR is within the range of a watchpoint spanning
2021    LENGTH bytes beginning at START.  */
2022 #define target_watchpoint_addr_within_range(target, addr, start, length) \
2023   (target)->watchpoint_addr_within_range (addr, start, length)
2024
2025 /* Return non-zero if the target is capable of using hardware to evaluate
2026    the condition expression.  In this case, if the condition is false when
2027    the watched memory location changes, execution may continue without the
2028    debugger being notified.
2029
2030    Due to limitations in the hardware implementation, it may be capable of
2031    avoiding triggering the watchpoint in some cases where the condition
2032    expression is false, but may report some false positives as well.
2033    For this reason, GDB will still evaluate the condition expression when
2034    the watchpoint triggers.  */
2035 #define target_can_accel_watchpoint_condition(addr, len, type, cond) \
2036   (current_top_target ()->can_accel_watchpoint_condition) (addr, len, type, cond)
2037
2038 /* Return number of debug registers needed for a masked watchpoint,
2039    -1 if masked watchpoints are not supported or -2 if the given address
2040    and mask combination cannot be used.  */
2041
2042 extern int target_masked_watch_num_registers (CORE_ADDR addr, CORE_ADDR mask);
2043
2044 /* Target can execute in reverse?  */
2045 #define target_can_execute_reverse \
2046       current_top_target ()->can_execute_reverse ()
2047
2048 extern const struct target_desc *target_read_description (struct target_ops *);
2049
2050 #define target_get_ada_task_ptid(lwp, tid) \
2051      (current_top_target ()->get_ada_task_ptid) (lwp,tid)
2052
2053 /* Utility implementation of searching memory.  */
2054 extern int simple_search_memory (struct target_ops* ops,
2055                                  CORE_ADDR start_addr,
2056                                  ULONGEST search_space_len,
2057                                  const gdb_byte *pattern,
2058                                  ULONGEST pattern_len,
2059                                  CORE_ADDR *found_addrp);
2060
2061 /* Main entry point for searching memory.  */
2062 extern int target_search_memory (CORE_ADDR start_addr,
2063                                  ULONGEST search_space_len,
2064                                  const gdb_byte *pattern,
2065                                  ULONGEST pattern_len,
2066                                  CORE_ADDR *found_addrp);
2067
2068 /* Target file operations.  */
2069
2070 /* Return nonzero if the filesystem seen by the current inferior
2071    is the local filesystem, zero otherwise.  */
2072 #define target_filesystem_is_local() \
2073   current_top_target ()->filesystem_is_local ()
2074
2075 /* Open FILENAME on the target, in the filesystem as seen by INF,
2076    using FLAGS and MODE.  If INF is NULL, use the filesystem seen
2077    by the debugger (GDB or, for remote targets, the remote stub).
2078    Return a target file descriptor, or -1 if an error occurs (and
2079    set *TARGET_ERRNO).  */
2080 extern int target_fileio_open (struct inferior *inf,
2081                                const char *filename, int flags,
2082                                int mode, int *target_errno);
2083
2084 /* Like target_fileio_open, but print a warning message if the
2085    file is being accessed over a link that may be slow.  */
2086 extern int target_fileio_open_warn_if_slow (struct inferior *inf,
2087                                             const char *filename,
2088                                             int flags,
2089                                             int mode,
2090                                             int *target_errno);
2091
2092 /* Write up to LEN bytes from WRITE_BUF to FD on the target.
2093    Return the number of bytes written, or -1 if an error occurs
2094    (and set *TARGET_ERRNO).  */
2095 extern int target_fileio_pwrite (int fd, const gdb_byte *write_buf, int len,
2096                                  ULONGEST offset, int *target_errno);
2097
2098 /* Read up to LEN bytes FD on the target into READ_BUF.
2099    Return the number of bytes read, or -1 if an error occurs
2100    (and set *TARGET_ERRNO).  */
2101 extern int target_fileio_pread (int fd, gdb_byte *read_buf, int len,
2102                                 ULONGEST offset, int *target_errno);
2103
2104 /* Get information about the file opened as FD on the target
2105    and put it in SB.  Return 0 on success, or -1 if an error
2106    occurs (and set *TARGET_ERRNO).  */
2107 extern int target_fileio_fstat (int fd, struct stat *sb,
2108                                 int *target_errno);
2109
2110 /* Close FD on the target.  Return 0, or -1 if an error occurs
2111    (and set *TARGET_ERRNO).  */
2112 extern int target_fileio_close (int fd, int *target_errno);
2113
2114 /* Unlink FILENAME on the target, in the filesystem as seen by INF.
2115    If INF is NULL, use the filesystem seen by the debugger (GDB or,
2116    for remote targets, the remote stub).  Return 0, or -1 if an error
2117    occurs (and set *TARGET_ERRNO).  */
2118 extern int target_fileio_unlink (struct inferior *inf,
2119                                  const char *filename,
2120                                  int *target_errno);
2121
2122 /* Read value of symbolic link FILENAME on the target, in the
2123    filesystem as seen by INF.  If INF is NULL, use the filesystem seen
2124    by the debugger (GDB or, for remote targets, the remote stub).
2125    Return a null-terminated string allocated via xmalloc, or NULL if
2126    an error occurs (and set *TARGET_ERRNO).  */
2127 extern gdb::optional<std::string> target_fileio_readlink
2128     (struct inferior *inf, const char *filename, int *target_errno);
2129
2130 /* Read target file FILENAME, in the filesystem as seen by INF.  If
2131    INF is NULL, use the filesystem seen by the debugger (GDB or, for
2132    remote targets, the remote stub).  The return value will be -1 if
2133    the transfer fails or is not supported; 0 if the object is empty;
2134    or the length of the object otherwise.  If a positive value is
2135    returned, a sufficiently large buffer will be allocated using
2136    xmalloc and returned in *BUF_P containing the contents of the
2137    object.
2138
2139    This method should be used for objects sufficiently small to store
2140    in a single xmalloc'd buffer, when no fixed bound on the object's
2141    size is known in advance.  */
2142 extern LONGEST target_fileio_read_alloc (struct inferior *inf,
2143                                          const char *filename,
2144                                          gdb_byte **buf_p);
2145
2146 /* Read target file FILENAME, in the filesystem as seen by INF.  If
2147    INF is NULL, use the filesystem seen by the debugger (GDB or, for
2148    remote targets, the remote stub).  The result is NUL-terminated and
2149    returned as a string, allocated using xmalloc.  If an error occurs
2150    or the transfer is unsupported, NULL is returned.  Empty objects
2151    are returned as allocated but empty strings.  A warning is issued
2152    if the result contains any embedded NUL bytes.  */
2153 extern gdb::unique_xmalloc_ptr<char> target_fileio_read_stralloc
2154     (struct inferior *inf, const char *filename);
2155
2156
2157 /* Tracepoint-related operations.  */
2158
2159 #define target_trace_init() \
2160   (current_top_target ()->trace_init) ()
2161
2162 #define target_download_tracepoint(t) \
2163   (current_top_target ()->download_tracepoint) (t)
2164
2165 #define target_can_download_tracepoint() \
2166   (current_top_target ()->can_download_tracepoint) ()
2167
2168 #define target_download_trace_state_variable(tsv) \
2169   (current_top_target ()->download_trace_state_variable) (tsv)
2170
2171 #define target_enable_tracepoint(loc) \
2172   (current_top_target ()->enable_tracepoint) (loc)
2173
2174 #define target_disable_tracepoint(loc) \
2175   (current_top_target ()->disable_tracepoint) (loc)
2176
2177 #define target_trace_start() \
2178   (current_top_target ()->trace_start) ()
2179
2180 #define target_trace_set_readonly_regions() \
2181   (current_top_target ()->trace_set_readonly_regions) ()
2182
2183 #define target_get_trace_status(ts) \
2184   (current_top_target ()->get_trace_status) (ts)
2185
2186 #define target_get_tracepoint_status(tp,utp)            \
2187   (current_top_target ()->get_tracepoint_status) (tp, utp)
2188
2189 #define target_trace_stop() \
2190   (current_top_target ()->trace_stop) ()
2191
2192 #define target_trace_find(type,num,addr1,addr2,tpp) \
2193   (current_top_target ()->trace_find) (\
2194                                    (type), (num), (addr1), (addr2), (tpp))
2195
2196 #define target_get_trace_state_variable_value(tsv,val) \
2197   (current_top_target ()->get_trace_state_variable_value) ((tsv), (val))
2198
2199 #define target_save_trace_data(filename) \
2200   (current_top_target ()->save_trace_data) (filename)
2201
2202 #define target_upload_tracepoints(utpp) \
2203   (current_top_target ()->upload_tracepoints) (utpp)
2204
2205 #define target_upload_trace_state_variables(utsvp) \
2206   (current_top_target ()->upload_trace_state_variables) (utsvp)
2207
2208 #define target_get_raw_trace_data(buf,offset,len) \
2209   (current_top_target ()->get_raw_trace_data) ((buf), (offset), (len))
2210
2211 #define target_get_min_fast_tracepoint_insn_len() \
2212   (current_top_target ()->get_min_fast_tracepoint_insn_len) ()
2213
2214 #define target_set_disconnected_tracing(val) \
2215   (current_top_target ()->set_disconnected_tracing) (val)
2216
2217 #define target_set_circular_trace_buffer(val)   \
2218   (current_top_target ()->set_circular_trace_buffer) (val)
2219
2220 #define target_set_trace_buffer_size(val)       \
2221   (current_top_target ()->set_trace_buffer_size) (val)
2222
2223 #define target_set_trace_notes(user,notes,stopnotes)            \
2224   (current_top_target ()->set_trace_notes) ((user), (notes), (stopnotes))
2225
2226 #define target_get_tib_address(ptid, addr) \
2227   (current_top_target ()->get_tib_address) ((ptid), (addr))
2228
2229 #define target_set_permissions() \
2230   (current_top_target ()->set_permissions) ()
2231
2232 #define target_static_tracepoint_marker_at(addr, marker) \
2233   (current_top_target ()->static_tracepoint_marker_at) (addr, marker)
2234
2235 #define target_static_tracepoint_markers_by_strid(marker_id) \
2236   (current_top_target ()->static_tracepoint_markers_by_strid) (marker_id)
2237
2238 #define target_traceframe_info() \
2239   (current_top_target ()->traceframe_info) ()
2240
2241 #define target_use_agent(use) \
2242   (current_top_target ()->use_agent) (use)
2243
2244 #define target_can_use_agent() \
2245   (current_top_target ()->can_use_agent) ()
2246
2247 #define target_augmented_libraries_svr4_read() \
2248   (current_top_target ()->augmented_libraries_svr4_read) ()
2249
2250 /* Command logging facility.  */
2251
2252 #define target_log_command(p)                                   \
2253   (current_top_target ()->log_command) (p)
2254
2255
2256 extern int target_core_of_thread (ptid_t ptid);
2257
2258 /* See to_get_unwinder in struct target_ops.  */
2259 extern const struct frame_unwind *target_get_unwinder (void);
2260
2261 /* See to_get_tailcall_unwinder in struct target_ops.  */
2262 extern const struct frame_unwind *target_get_tailcall_unwinder (void);
2263
2264 /* This implements basic memory verification, reading target memory
2265    and performing the comparison here (as opposed to accelerated
2266    verification making use of the qCRC packet, for example).  */
2267
2268 extern int simple_verify_memory (struct target_ops* ops,
2269                                  const gdb_byte *data,
2270                                  CORE_ADDR memaddr, ULONGEST size);
2271
2272 /* Verify that the memory in the [MEMADDR, MEMADDR+SIZE) range matches
2273    the contents of [DATA,DATA+SIZE).  Returns 1 if there's a match, 0
2274    if there's a mismatch, and -1 if an error is encountered while
2275    reading memory.  Throws an error if the functionality is found not
2276    to be supported by the current target.  */
2277 int target_verify_memory (const gdb_byte *data,
2278                           CORE_ADDR memaddr, ULONGEST size);
2279
2280 /* Routines for maintenance of the target structures...
2281
2282    add_target:   Add a target to the list of all possible targets.
2283    This only makes sense for targets that should be activated using
2284    the "target TARGET_NAME ..." command.
2285
2286    push_target:  Make this target the top of the stack of currently used
2287    targets, within its particular stratum of the stack.  Result
2288    is 0 if now atop the stack, nonzero if not on top (maybe
2289    should warn user).
2290
2291    unpush_target: Remove this from the stack of currently used targets,
2292    no matter where it is on the list.  Returns 0 if no
2293    change, 1 if removed from stack.  */
2294
2295 /* Type of callback called when the user activates a target with
2296    "target TARGET_NAME".  The callback routine takes the rest of the
2297    parameters from the command, and (if successful) pushes a new
2298    target onto the stack.  */
2299 typedef void target_open_ftype (const char *args, int from_tty);
2300
2301 /* Add the target described by INFO to the list of possible targets
2302    and add a new command 'target $(INFO->shortname)'.  Set COMPLETER
2303    as the command's completer if not NULL.  */
2304
2305 extern void add_target (const target_info &info,
2306                         target_open_ftype *func,
2307                         completer_ftype *completer = NULL);
2308
2309 /* Adds a command ALIAS for the target described by INFO and marks it
2310    deprecated.  This is useful for maintaining backwards compatibility
2311    when renaming targets.  */
2312
2313 extern void add_deprecated_target_alias (const target_info &info,
2314                                          const char *alias);
2315
2316 extern void push_target (struct target_ops *);
2317
2318 extern int unpush_target (struct target_ops *);
2319
2320 extern void target_pre_inferior (int);
2321
2322 extern void target_preopen (int);
2323
2324 /* Does whatever cleanup is required to get rid of all pushed targets.  */
2325 extern void pop_all_targets (void);
2326
2327 /* Like pop_all_targets, but pops only targets whose stratum is at or
2328    above STRATUM.  */
2329 extern void pop_all_targets_at_and_above (enum strata stratum);
2330
2331 /* Like pop_all_targets, but pops only targets whose stratum is
2332    strictly above ABOVE_STRATUM.  */
2333 extern void pop_all_targets_above (enum strata above_stratum);
2334
2335 extern int target_is_pushed (struct target_ops *t);
2336
2337 extern CORE_ADDR target_translate_tls_address (struct objfile *objfile,
2338                                                CORE_ADDR offset);
2339
2340 /* Struct target_section maps address ranges to file sections.  It is
2341    mostly used with BFD files, but can be used without (e.g. for handling
2342    raw disks, or files not in formats handled by BFD).  */
2343
2344 struct target_section
2345   {
2346     CORE_ADDR addr;             /* Lowest address in section */
2347     CORE_ADDR endaddr;          /* 1+highest address in section */
2348
2349     struct bfd_section *the_bfd_section;
2350
2351     /* The "owner" of the section.
2352        It can be any unique value.  It is set by add_target_sections
2353        and used by remove_target_sections.
2354        For example, for executables it is a pointer to exec_bfd and
2355        for shlibs it is the so_list pointer.  */
2356     void *owner;
2357   };
2358
2359 /* Holds an array of target sections.  Defined by [SECTIONS..SECTIONS_END[.  */
2360
2361 struct target_section_table
2362 {
2363   struct target_section *sections;
2364   struct target_section *sections_end;
2365 };
2366
2367 /* Return the "section" containing the specified address.  */
2368 struct target_section *target_section_by_addr (struct target_ops *target,
2369                                                CORE_ADDR addr);
2370
2371 /* Return the target section table this target (or the targets
2372    beneath) currently manipulate.  */
2373
2374 extern struct target_section_table *target_get_section_table
2375   (struct target_ops *target);
2376
2377 /* From mem-break.c */
2378
2379 extern int memory_remove_breakpoint (struct target_ops *,
2380                                      struct gdbarch *, struct bp_target_info *,
2381                                      enum remove_bp_reason);
2382
2383 extern int memory_insert_breakpoint (struct target_ops *,
2384                                      struct gdbarch *, struct bp_target_info *);
2385
2386 /* Convenience template use to add memory breakpoints support to a
2387    target.  */
2388
2389 template <typename BaseTarget>
2390 struct memory_breakpoint_target : public BaseTarget
2391 {
2392   int insert_breakpoint (struct gdbarch *gdbarch,
2393                          struct bp_target_info *bp_tgt) override
2394   { return memory_insert_breakpoint (this, gdbarch, bp_tgt); }
2395
2396   int remove_breakpoint (struct gdbarch *gdbarch,
2397                          struct bp_target_info *bp_tgt,
2398                          enum remove_bp_reason reason) override
2399   { return memory_remove_breakpoint (this, gdbarch, bp_tgt, reason); }
2400 };
2401
2402 /* Check whether the memory at the breakpoint's placed address still
2403    contains the expected breakpoint instruction.  */
2404
2405 extern int memory_validate_breakpoint (struct gdbarch *gdbarch,
2406                                        struct bp_target_info *bp_tgt);
2407
2408 extern int default_memory_remove_breakpoint (struct gdbarch *,
2409                                              struct bp_target_info *);
2410
2411 extern int default_memory_insert_breakpoint (struct gdbarch *,
2412                                              struct bp_target_info *);
2413
2414
2415 /* From target.c */
2416
2417 extern void initialize_targets (void);
2418
2419 extern void noprocess (void) ATTRIBUTE_NORETURN;
2420
2421 extern void target_require_runnable (void);
2422
2423 /* Find the target at STRATUM.  If no target is at that stratum,
2424    return NULL.  */
2425
2426 struct target_ops *find_target_at (enum strata stratum);
2427
2428 /* Read OS data object of type TYPE from the target, and return it in XML
2429    format.  The return value follows the same rules as target_read_stralloc.  */
2430
2431 extern gdb::optional<gdb::char_vector> target_get_osdata (const char *type);
2432
2433 /* Stuff that should be shared among the various remote targets.  */
2434
2435 /* Debugging level.  0 is off, and non-zero values mean to print some debug
2436    information (higher values, more information).  */
2437 extern int remote_debug;
2438
2439 /* Speed in bits per second, or -1 which means don't mess with the speed.  */
2440 extern int baud_rate;
2441
2442 /* Parity for serial port  */
2443 extern int serial_parity;
2444
2445 /* Timeout limit for response from target.  */
2446 extern int remote_timeout;
2447
2448 \f
2449
2450 /* Set the show memory breakpoints mode to show, and return a
2451    scoped_restore to restore it back to the current value.  */
2452 extern scoped_restore_tmpl<int>
2453     make_scoped_restore_show_memory_breakpoints (int show);
2454
2455 extern int may_write_registers;
2456 extern int may_write_memory;
2457 extern int may_insert_breakpoints;
2458 extern int may_insert_tracepoints;
2459 extern int may_insert_fast_tracepoints;
2460 extern int may_stop;
2461
2462 extern void update_target_permissions (void);
2463
2464 \f
2465 /* Imported from machine dependent code.  */
2466
2467 /* See to_enable_btrace in struct target_ops.  */
2468 extern struct btrace_target_info *
2469   target_enable_btrace (ptid_t ptid, const struct btrace_config *);
2470
2471 /* See to_disable_btrace in struct target_ops.  */
2472 extern void target_disable_btrace (struct btrace_target_info *btinfo);
2473
2474 /* See to_teardown_btrace in struct target_ops.  */
2475 extern void target_teardown_btrace (struct btrace_target_info *btinfo);
2476
2477 /* See to_read_btrace in struct target_ops.  */
2478 extern enum btrace_error target_read_btrace (struct btrace_data *,
2479                                              struct btrace_target_info *,
2480                                              enum btrace_read_type);
2481
2482 /* See to_btrace_conf in struct target_ops.  */
2483 extern const struct btrace_config *
2484   target_btrace_conf (const struct btrace_target_info *);
2485
2486 /* See to_stop_recording in struct target_ops.  */
2487 extern void target_stop_recording (void);
2488
2489 /* See to_save_record in struct target_ops.  */
2490 extern void target_save_record (const char *filename);
2491
2492 /* Query if the target supports deleting the execution log.  */
2493 extern int target_supports_delete_record (void);
2494
2495 /* See to_delete_record in struct target_ops.  */
2496 extern void target_delete_record (void);
2497
2498 /* See to_record_method.  */
2499 extern enum record_method target_record_method (ptid_t ptid);
2500
2501 /* See to_record_is_replaying in struct target_ops.  */
2502 extern int target_record_is_replaying (ptid_t ptid);
2503
2504 /* See to_record_will_replay in struct target_ops.  */
2505 extern int target_record_will_replay (ptid_t ptid, int dir);
2506
2507 /* See to_record_stop_replaying in struct target_ops.  */
2508 extern void target_record_stop_replaying (void);
2509
2510 /* See to_goto_record_begin in struct target_ops.  */
2511 extern void target_goto_record_begin (void);
2512
2513 /* See to_goto_record_end in struct target_ops.  */
2514 extern void target_goto_record_end (void);
2515
2516 /* See to_goto_record in struct target_ops.  */
2517 extern void target_goto_record (ULONGEST insn);
2518
2519 /* See to_insn_history.  */
2520 extern void target_insn_history (int size, gdb_disassembly_flags flags);
2521
2522 /* See to_insn_history_from.  */
2523 extern void target_insn_history_from (ULONGEST from, int size,
2524                                       gdb_disassembly_flags flags);
2525
2526 /* See to_insn_history_range.  */
2527 extern void target_insn_history_range (ULONGEST begin, ULONGEST end,
2528                                        gdb_disassembly_flags flags);
2529
2530 /* See to_call_history.  */
2531 extern void target_call_history (int size, record_print_flags flags);
2532
2533 /* See to_call_history_from.  */
2534 extern void target_call_history_from (ULONGEST begin, int size,
2535                                       record_print_flags flags);
2536
2537 /* See to_call_history_range.  */
2538 extern void target_call_history_range (ULONGEST begin, ULONGEST end,
2539                                        record_print_flags flags);
2540
2541 /* See to_prepare_to_generate_core.  */
2542 extern void target_prepare_to_generate_core (void);
2543
2544 /* See to_done_generating_core.  */
2545 extern void target_done_generating_core (void);
2546
2547 #if GDB_SELF_TEST
2548 namespace selftests {
2549
2550 /* A mock process_stratum target_ops that doesn't read/write registers
2551    anywhere.  */
2552
2553 class test_target_ops : public target_ops
2554 {
2555 public:
2556   test_target_ops ()
2557     : target_ops {}
2558   {
2559     to_stratum = process_stratum;
2560   }
2561
2562   const target_info &info () const override;
2563
2564   bool has_registers () override
2565   {
2566     return true;
2567   }
2568
2569   bool has_stack () override
2570   {
2571     return true;
2572   }
2573
2574   bool has_memory () override
2575   {
2576     return true;
2577   }
2578
2579   void prepare_to_store (regcache *regs) override
2580   {
2581   }
2582
2583   void store_registers (regcache *regs, int regno) override
2584   {
2585   }
2586 };
2587
2588
2589 } // namespace selftests
2590 #endif /* GDB_SELF_TEST */
2591
2592 #endif /* !defined (TARGET_H) */