gdb/gdbserver/target.h - gdb

Data types defined

Macros defined

Source code

  1. /* Target operations for the remote server for GDB.
  2.    Copyright (C) 2002-2015 Free Software Foundation, Inc.

  3.    Contributed by MontaVista Software.

  4.    This file is part of GDB.

  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 3 of the License, or
  8.    (at your option) any later version.

  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.

  13.    You should have received a copy of the GNU General Public License
  14.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  15. #ifndef TARGET_H
  16. #define TARGET_H

  17. #include "target/target.h"
  18. #include "target/resume.h"
  19. #include "target/wait.h"
  20. #include "target/waitstatus.h"
  21. #include "mem-break.h"

  22. struct emit_ops;
  23. struct btrace_target_info;
  24. struct buffer;
  25. struct process_info;

  26. /* This structure describes how to resume a particular thread (or all
  27.    threads) based on the client's request.  If thread is -1, then this
  28.    entry applies to all threads.  These are passed around as an
  29.    array.  */

  30. struct thread_resume
  31. {
  32.   ptid_t thread;

  33.   /* How to "resume".  */
  34.   enum resume_kind kind;

  35.   /* If non-zero, send this signal when we resume, or to stop the
  36.      thread.  If stopping a thread, and this is 0, the target should
  37.      stop the thread however it best decides to (e.g., SIGSTOP on
  38.      linux; SuspendThread on win32).  This is a host signal value (not
  39.      enum gdb_signal).  */
  40.   int sig;

  41.   /* Range to single step within.  Valid only iff KIND is resume_step.

  42.      Single-step once, and then continuing stepping as long as the
  43.      thread stops in this range.  (If the range is empty
  44.      [STEP_RANGE_START == STEP_RANGE_END], then this is a single-step
  45.      request.)  */
  46.   CORE_ADDR step_range_start;        /* Inclusive */
  47.   CORE_ADDR step_range_end;        /* Exclusive */
  48. };

  49. struct target_ops
  50. {
  51.   /* Start a new process.

  52.      PROGRAM is a path to the program to execute.
  53.      ARGS is a standard NULL-terminated array of arguments,
  54.      to be passed to the inferior as ``argv''.

  55.      Returns the new PID on success, -1 on failure.  Registers the new
  56.      process with the process list.  */

  57.   int (*create_inferior) (char *program, char **args);

  58.   /* Attach to a running process.

  59.      PID is the process ID to attach to, specified by the user
  60.      or a higher layer.

  61.      Returns -1 if attaching is unsupported, 0 on success, and calls
  62.      error() otherwise.  */

  63.   int (*attach) (unsigned long pid);

  64.   /* Kill inferior PID.  Return -1 on failure, and 0 on success.  */

  65.   int (*kill) (int pid);

  66.   /* Detach from inferior PID. Return -1 on failure, and 0 on
  67.      success.  */

  68.   int (*detach) (int pid);

  69.   /* The inferior process has died.  Do what is right.  */

  70.   void (*mourn) (struct process_info *proc);

  71.   /* Wait for inferior PID to exit.  */
  72.   void (*join) (int pid);

  73.   /* Return 1 iff the thread with process ID PID is alive.  */

  74.   int (*thread_alive) (ptid_t pid);

  75.   /* Resume the inferior process.  */

  76.   void (*resume) (struct thread_resume *resume_info, size_t n);

  77.   /* Wait for the inferior process or thread to change state.  Store
  78.      status through argument pointer STATUS.

  79.      PTID = -1 to wait for any pid to do something, PTID(pid,0,0) to
  80.      wait for any thread of process pid to do something.  Return ptid
  81.      of child, or -1 in case of error; store status through argument
  82.      pointer STATUS.  OPTIONS is a bit set of options defined as
  83.      TARGET_W* above.  If options contains TARGET_WNOHANG and there's
  84.      no child stop to report, return is
  85.      null_ptid/TARGET_WAITKIND_IGNORE.  */

  86.   ptid_t (*wait) (ptid_t ptid, struct target_waitstatus *status, int options);

  87.   /* Fetch registers from the inferior process.

  88.      If REGNO is -1, fetch all registers; otherwise, fetch at least REGNO.  */

  89.   void (*fetch_registers) (struct regcache *regcache, int regno);

  90.   /* Store registers to the inferior process.

  91.      If REGNO is -1, store all registers; otherwise, store at least REGNO.  */

  92.   void (*store_registers) (struct regcache *regcache, int regno);

  93.   /* Prepare to read or write memory from the inferior process.
  94.      Targets use this to do what is necessary to get the state of the
  95.      inferior such that it is possible to access memory.

  96.      This should generally only be called from client facing routines,
  97.      such as gdb_read_memory/gdb_write_memory, or the GDB breakpoint
  98.      insertion routine.

  99.      Like `read_memory' and `write_memory' below, returns 0 on success
  100.      and errno on failure.  */

  101.   int (*prepare_to_access_memory) (void);

  102.   /* Undo the effects of prepare_to_access_memory.  */

  103.   void (*done_accessing_memory) (void);

  104.   /* Read memory from the inferior process.  This should generally be
  105.      called through read_inferior_memory, which handles breakpoint shadowing.

  106.      Read LEN bytes at MEMADDR into a buffer at MYADDR.

  107.      Returns 0 on success and errno on failure.  */

  108.   int (*read_memory) (CORE_ADDR memaddr, unsigned char *myaddr, int len);

  109.   /* Write memory to the inferior process.  This should generally be
  110.      called through write_inferior_memory, which handles breakpoint shadowing.

  111.      Write LEN bytes from the buffer at MYADDR to MEMADDR.

  112.      Returns 0 on success and errno on failure.  */

  113.   int (*write_memory) (CORE_ADDR memaddr, const unsigned char *myaddr,
  114.                        int len);

  115.   /* Query GDB for the values of any symbols we're interested in.
  116.      This function is called whenever we receive a "qSymbols::"
  117.      query, which corresponds to every time more symbols (might)
  118.      become available.  NULL if we aren't interested in any
  119.      symbols.  */

  120.   void (*look_up_symbols) (void);

  121.   /* Send an interrupt request to the inferior process,
  122.      however is appropriate.  */

  123.   void (*request_interrupt) (void);

  124.   /* Read auxiliary vector data from the inferior process.

  125.      Read LEN bytes at OFFSET into a buffer at MYADDR.  */

  126.   int (*read_auxv) (CORE_ADDR offset, unsigned char *myaddr,
  127.                     unsigned int len);

  128.   /* Returns true if GDB Z breakpoint type TYPE is supported, false
  129.      otherwise.  The type is coded as follows:
  130.        '0' - software-breakpoint
  131.        '1' - hardware-breakpoint
  132.        '2' - write watchpoint
  133.        '3' - read watchpoint
  134.        '4' - access watchpoint
  135.   */
  136.   int (*supports_z_point_type) (char z_type);

  137.   /* Insert and remove a break or watchpoint.
  138.      Returns 0 on success, -1 on failure and 1 on unsupported.  */

  139.   int (*insert_point) (enum raw_bkpt_type type, CORE_ADDR addr,
  140.                        int size, struct raw_breakpoint *bp);
  141.   int (*remove_point) (enum raw_bkpt_type type, CORE_ADDR addr,
  142.                        int size, struct raw_breakpoint *bp);

  143.   /* Returns 1 if target was stopped due to a watchpoint hit, 0 otherwise.  */

  144.   int (*stopped_by_watchpoint) (void);

  145.   /* Returns the address associated with the watchpoint that hit, if any;
  146.      returns 0 otherwise.  */

  147.   CORE_ADDR (*stopped_data_address) (void);

  148.   /* Reports the text, data offsets of the executable.  This is
  149.      needed for uclinux where the executable is relocated during load
  150.      time.  */

  151.   int (*read_offsets) (CORE_ADDR *text, CORE_ADDR *data);

  152.   /* Fetch the address associated with a specific thread local storage
  153.      area, determined by the specified THREAD, OFFSET, and LOAD_MODULE.
  154.      Stores it in *ADDRESS and returns zero on success; otherwise returns
  155.      an error codeA return value of -1 means this system does not
  156.      support the operation.  */

  157.   int (*get_tls_address) (struct thread_info *thread, CORE_ADDR offset,
  158.                           CORE_ADDR load_module, CORE_ADDR *address);

  159.    /* Read/Write from/to spufs using qXfer packets.  */
  160.   int (*qxfer_spu) (const char *annex, unsigned char *readbuf,
  161.                     unsigned const char *writebuf, CORE_ADDR offset, int len);

  162.   /* Fill BUF with an hostio error packet representing the last hostio
  163.      error.  */
  164.   void (*hostio_last_error) (char *buf);

  165.   /* Read/Write OS data using qXfer packets.  */
  166.   int (*qxfer_osdata) (const char *annex, unsigned char *readbuf,
  167.                        unsigned const char *writebuf, CORE_ADDR offset,
  168.                        int len);

  169.   /* Read/Write extra signal info.  */
  170.   int (*qxfer_siginfo) (const char *annex, unsigned char *readbuf,
  171.                         unsigned const char *writebuf,
  172.                         CORE_ADDR offset, int len);

  173.   int (*supports_non_stop) (void);

  174.   /* Enables async target events.  Returns the previous enable
  175.      state.  */
  176.   int (*async) (int enable);

  177.   /* Switch to non-stop (1) or all-stop (0) mode.  Return 0 on
  178.      success, -1 otherwise.  */
  179.   int (*start_non_stop) (int);

  180.   /* Returns true if the target supports multi-process debugging.  */
  181.   int (*supports_multi_process) (void);

  182.   /* If not NULL, target-specific routine to process monitor command.
  183.      Returns 1 if handled, or 0 to perform default processing.  */
  184.   int (*handle_monitor_command) (char *);

  185.   /* Returns the core given a thread, or -1 if not known.  */
  186.   int (*core_of_thread) (ptid_t);

  187.   /* Read loadmaps.  Read LEN bytes at OFFSET into a buffer at MYADDR.  */
  188.   int (*read_loadmap) (const char *annex, CORE_ADDR offset,
  189.                        unsigned char *myaddr, unsigned int len);

  190.   /* Target specific qSupported support.  */
  191.   void (*process_qsupported) (const char *);

  192.   /* Return 1 if the target supports tracepoints, 0 (or leave the
  193.      callback NULL) otherwise.  */
  194.   int (*supports_tracepoints) (void);

  195.   /* Read PC from REGCACHE.  */
  196.   CORE_ADDR (*read_pc) (struct regcache *regcache);

  197.   /* Write PC to REGCACHE.  */
  198.   void (*write_pc) (struct regcache *regcache, CORE_ADDR pc);

  199.   /* Return true if THREAD is known to be stopped now.  */
  200.   int (*thread_stopped) (struct thread_info *thread);

  201.   /* Read Thread Information Block address.  */
  202.   int (*get_tib_address) (ptid_t ptid, CORE_ADDR *address);

  203.   /* Pause all threads.  If FREEZE, arrange for any resume attempt to
  204.      be ignored until an unpause_all call unfreezes threads again.
  205.      There can be nested calls to pause_all, so a freeze counter
  206.      should be maintained.  */
  207.   void (*pause_all) (int freeze);

  208.   /* Unpause all threads.  Threads that hadn't been resumed by the
  209.      client should be left stopped.  Basically a pause/unpause call
  210.      pair should not end up resuming threads that were stopped before
  211.      the pause call.  */
  212.   void (*unpause_all) (int unfreeze);

  213.   /* Stabilize all threads.  That is, force them out of jump pads.  */
  214.   void (*stabilize_threads) (void);

  215.   /* Install a fast tracepoint jump pad.  TPOINT is the address of the
  216.      tracepoint internal object as used by the IPA agent.  TPADDR is
  217.      the address of tracepoint.  COLLECTOR is address of the function
  218.      the jump pad redirects to.  LOCKADDR is the address of the jump
  219.      pad lock object.  ORIG_SIZE is the size in bytes of the
  220.      instruction at TPADDR.  JUMP_ENTRY points to the address of the
  221.      jump pad entry, and on return holds the address past the end of
  222.      the created jump pad.  If a trampoline is created by the function,
  223.      then TRAMPOLINE and TRAMPOLINE_SIZE return the address and size of
  224.      the trampoline, else they remain unchanged.  JJUMP_PAD_INSN is a
  225.      buffer containing a copy of the instruction at TPADDR.
  226.      ADJUST_INSN_ADDR and ADJUST_INSN_ADDR_END are output parameters that
  227.      return the address range where the instruction at TPADDR was relocated
  228.      to.  If an error occurs, the ERR may be used to pass on an error
  229.      message.  */
  230.   int (*install_fast_tracepoint_jump_pad) (CORE_ADDR tpoint, CORE_ADDR tpaddr,
  231.                                            CORE_ADDR collector,
  232.                                            CORE_ADDR lockaddr,
  233.                                            ULONGEST orig_size,
  234.                                            CORE_ADDR *jump_entry,
  235.                                            CORE_ADDR *trampoline,
  236.                                            ULONGEST *trampoline_size,
  237.                                            unsigned char *jjump_pad_insn,
  238.                                            ULONGEST *jjump_pad_insn_size,
  239.                                            CORE_ADDR *adjusted_insn_addr,
  240.                                            CORE_ADDR *adjusted_insn_addr_end,
  241.                                            char *err);

  242.   /* Return the bytecode operations vector for the current inferior.
  243.      Returns NULL if bytecode compilation is not supported.  */
  244.   struct emit_ops *(*emit_ops) (void);

  245.   /* Returns true if the target supports disabling randomization.  */
  246.   int (*supports_disable_randomization) (void);

  247.   /* Return the minimum length of an instruction that can be safely overwritten
  248.      for use as a fast tracepoint.  */
  249.   int (*get_min_fast_tracepoint_insn_len) (void);

  250.   /* Read solib info on SVR4 platforms.  */
  251.   int (*qxfer_libraries_svr4) (const char *annex, unsigned char *readbuf,
  252.                                unsigned const char *writebuf,
  253.                                CORE_ADDR offset, int len);

  254.   /* Return true if target supports debugging agent.  */
  255.   int (*supports_agent) (void);

  256.   /* Check whether the target supports branch tracing.  */
  257.   int (*supports_btrace) (struct target_ops *);

  258.   /* Enable branch tracing for @ptid and allocate a branch trace target
  259.      information struct for reading and for disabling branch trace.  */
  260.   struct btrace_target_info *(*enable_btrace) (ptid_t ptid);

  261.   /* Disable branch tracing.
  262.      Returns zero on success, non-zero otherwise.  */
  263.   int (*disable_btrace) (struct btrace_target_info *tinfo);

  264.   /* Read branch trace data into buffer.  We use an int to specify the type
  265.      to break a cyclic dependency.
  266.      Return 0 on success; print an error message into BUFFER and return -1,
  267.      otherwise.  */
  268.   int (*read_btrace) (struct btrace_target_info *, struct buffer *, int type);

  269.   /* Return true if target supports range stepping.  */
  270.   int (*supports_range_stepping) (void);
  271. };

  272. extern struct target_ops *the_target;

  273. void set_target_ops (struct target_ops *);

  274. #define create_inferior(program, args) \
  275.   (*the_target->create_inferior) (program, args)

  276. #define myattach(pid) \
  277.   (*the_target->attach) (pid)

  278. int kill_inferior (int);

  279. #define detach_inferior(pid) \
  280.   (*the_target->detach) (pid)

  281. #define mourn_inferior(PROC) \
  282.   (*the_target->mourn) (PROC)

  283. #define mythread_alive(pid) \
  284.   (*the_target->thread_alive) (pid)

  285. #define fetch_inferior_registers(regcache, regno)        \
  286.   (*the_target->fetch_registers) (regcache, regno)

  287. #define store_inferior_registers(regcache, regno) \
  288.   (*the_target->store_registers) (regcache, regno)

  289. #define join_inferior(pid) \
  290.   (*the_target->join) (pid)

  291. #define target_supports_non_stop() \
  292.   (the_target->supports_non_stop ? (*the_target->supports_non_stop ) () : 0)

  293. #define target_async(enable) \
  294.   (the_target->async ? (*the_target->async) (enable) : 0)

  295. #define target_supports_multi_process() \
  296.   (the_target->supports_multi_process ? \
  297.    (*the_target->supports_multi_process) () : 0)

  298. #define target_process_qsupported(query)                \
  299.   do                                                        \
  300.     {                                                        \
  301.       if (the_target->process_qsupported)                \
  302.         the_target->process_qsupported (query);                \
  303.     } while (0)

  304. #define target_supports_tracepoints()                        \
  305.   (the_target->supports_tracepoints                        \
  306.    ? (*the_target->supports_tracepoints) () : 0)

  307. #define target_supports_fast_tracepoints()                \
  308.   (the_target->install_fast_tracepoint_jump_pad != NULL)

  309. #define target_get_min_fast_tracepoint_insn_len()        \
  310.   (the_target->get_min_fast_tracepoint_insn_len                \
  311.    ? (*the_target->get_min_fast_tracepoint_insn_len) () : 0)

  312. #define thread_stopped(thread) \
  313.   (*the_target->thread_stopped) (thread)

  314. #define pause_all(freeze)                        \
  315.   do                                                \
  316.     {                                                \
  317.       if (the_target->pause_all)                \
  318.         (*the_target->pause_all) (freeze);        \
  319.     } while (0)

  320. #define unpause_all(unfreeze)                        \
  321.   do                                                \
  322.     {                                                \
  323.       if (the_target->unpause_all)                \
  324.         (*the_target->unpause_all) (unfreeze);        \
  325.     } while (0)

  326. #define stabilize_threads()                        \
  327.   do                                                \
  328.     {                                                \
  329.       if (the_target->stabilize_threads)             \
  330.         (*the_target->stabilize_threads) ();          \
  331.     } while (0)

  332. #define install_fast_tracepoint_jump_pad(tpoint, tpaddr,                \
  333.                                          collector, lockaddr,                \
  334.                                          orig_size,                        \
  335.                                          jump_entry,                        \
  336.                                          trampoline, trampoline_size,        \
  337.                                          jjump_pad_insn,                \
  338.                                          jjump_pad_insn_size,                \
  339.                                          adjusted_insn_addr,                \
  340.                                          adjusted_insn_addr_end,        \
  341.                                          err)                                \
  342.   (*the_target->install_fast_tracepoint_jump_pad) (tpoint, tpaddr,        \
  343.                                                    collector,lockaddr,        \
  344.                                                    orig_size, jump_entry, \
  345.                                                    trampoline,                \
  346.                                                    trampoline_size,        \
  347.                                                    jjump_pad_insn,        \
  348.                                                    jjump_pad_insn_size, \
  349.                                                    adjusted_insn_addr,        \
  350.                                                    adjusted_insn_addr_end, \
  351.                                                    err)

  352. #define target_emit_ops() \
  353.   (the_target->emit_ops ? (*the_target->emit_ops) () : NULL)

  354. #define target_supports_disable_randomization() \
  355.   (the_target->supports_disable_randomization ? \
  356.    (*the_target->supports_disable_randomization) () : 0)

  357. #define target_supports_agent() \
  358.   (the_target->supports_agent ? \
  359.    (*the_target->supports_agent) () : 0)

  360. #define target_supports_btrace()                        \
  361.   (the_target->supports_btrace                                \
  362.    ? (*the_target->supports_btrace) (the_target) : 0)

  363. #define target_enable_btrace(ptid) \
  364.   (*the_target->enable_btrace) (ptid)

  365. #define target_disable_btrace(tinfo) \
  366.   (*the_target->disable_btrace) (tinfo)

  367. #define target_read_btrace(tinfo, buffer, type)        \
  368.   (*the_target->read_btrace) (tinfo, buffer, type)

  369. #define target_supports_range_stepping() \
  370.   (the_target->supports_range_stepping ? \
  371.    (*the_target->supports_range_stepping) () : 0)

  372. /* Start non-stop mode, returns 0 on success, -1 on failure.   */

  373. int start_non_stop (int nonstop);

  374. ptid_t mywait (ptid_t ptid, struct target_waitstatus *ourstatus, int options,
  375.                int connected_wait);

  376. #define prepare_to_access_memory()                \
  377.   (the_target->prepare_to_access_memory                \
  378.    ? (*the_target->prepare_to_access_memory) () \
  379.    : 0)

  380. #define done_accessing_memory()                                \
  381.   do                                                        \
  382.     {                                                        \
  383.       if (the_target->done_accessing_memory)             \
  384.         (*the_target->done_accessing_memory) ();          \
  385.     } while (0)

  386. #define target_core_of_thread(ptid)                \
  387.   (the_target->core_of_thread ? (*the_target->core_of_thread) (ptid) \
  388.    : -1)

  389. int read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len);

  390. int write_inferior_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
  391.                            int len);

  392. void set_desired_thread (int id);

  393. const char *target_pid_to_str (ptid_t);

  394. #endif /* TARGET_H */