GDBserver
/home/stan/gdb/src/gdb/gdbserver/target.h
Go to the documentation of this file.
00001 /* Target operations for the remote server for GDB.
00002    Copyright (C) 2002-2013 Free Software Foundation, Inc.
00003 
00004    Contributed by MontaVista Software.
00005 
00006    This file is part of GDB.
00007 
00008    This program is free software; you can redistribute it and/or modify
00009    it under the terms of the GNU General Public License as published by
00010    the Free Software Foundation; either version 3 of the License, or
00011    (at your option) any later version.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00020 
00021 #ifndef TARGET_H
00022 #define TARGET_H
00023 
00024 #include "target/resume.h"
00025 #include "target/wait.h"
00026 #include "target/waitstatus.h"
00027 
00028 struct emit_ops;
00029 struct btrace_target_info;
00030 struct buffer;
00031 struct process_info;
00032 
00033 /* This structure describes how to resume a particular thread (or all
00034    threads) based on the client's request.  If thread is -1, then this
00035    entry applies to all threads.  These are passed around as an
00036    array.  */
00037 
00038 struct thread_resume
00039 {
00040   ptid_t thread;
00041 
00042   /* How to "resume".  */
00043   enum resume_kind kind;
00044 
00045   /* If non-zero, send this signal when we resume, or to stop the
00046      thread.  If stopping a thread, and this is 0, the target should
00047      stop the thread however it best decides to (e.g., SIGSTOP on
00048      linux; SuspendThread on win32).  This is a host signal value (not
00049      enum gdb_signal).  */
00050   int sig;
00051 
00052   /* Range to single step within.  Valid only iff KIND is resume_step.
00053 
00054      Single-step once, and then continuing stepping as long as the
00055      thread stops in this range.  (If the range is empty
00056      [STEP_RANGE_START == STEP_RANGE_END], then this is a single-step
00057      request.)  */
00058   CORE_ADDR step_range_start;   /* Inclusive */
00059   CORE_ADDR step_range_end;     /* Exclusive */
00060 };
00061 
00062 struct target_ops
00063 {
00064   /* Start a new process.
00065 
00066      PROGRAM is a path to the program to execute.
00067      ARGS is a standard NULL-terminated array of arguments,
00068      to be passed to the inferior as ``argv''.
00069 
00070      Returns the new PID on success, -1 on failure.  Registers the new
00071      process with the process list.  */
00072 
00073   int (*create_inferior) (char *program, char **args);
00074 
00075   /* Attach to a running process.
00076 
00077      PID is the process ID to attach to, specified by the user
00078      or a higher layer.
00079 
00080      Returns -1 if attaching is unsupported, 0 on success, and calls
00081      error() otherwise.  */
00082 
00083   int (*attach) (unsigned long pid);
00084 
00085   /* Kill inferior PID.  Return -1 on failure, and 0 on success.  */
00086 
00087   int (*kill) (int pid);
00088 
00089   /* Detach from inferior PID. Return -1 on failure, and 0 on
00090      success.  */
00091 
00092   int (*detach) (int pid);
00093 
00094   /* The inferior process has died.  Do what is right.  */
00095 
00096   void (*mourn) (struct process_info *proc);
00097 
00098   /* Wait for inferior PID to exit.  */
00099   void (*join) (int pid);
00100 
00101   /* Return 1 iff the thread with process ID PID is alive.  */
00102 
00103   int (*thread_alive) (ptid_t pid);
00104 
00105   /* Resume the inferior process.  */
00106 
00107   void (*resume) (struct thread_resume *resume_info, size_t n);
00108 
00109   /* Wait for the inferior process or thread to change state.  Store
00110      status through argument pointer STATUS.
00111 
00112      PTID = -1 to wait for any pid to do something, PTID(pid,0,0) to
00113      wait for any thread of process pid to do something.  Return ptid
00114      of child, or -1 in case of error; store status through argument
00115      pointer STATUS.  OPTIONS is a bit set of options defined as
00116      TARGET_W* above.  If options contains TARGET_WNOHANG and there's
00117      no child stop to report, return is
00118      null_ptid/TARGET_WAITKIND_IGNORE.  */
00119 
00120   ptid_t (*wait) (ptid_t ptid, struct target_waitstatus *status, int options);
00121 
00122   /* Fetch registers from the inferior process.
00123 
00124      If REGNO is -1, fetch all registers; otherwise, fetch at least REGNO.  */
00125 
00126   void (*fetch_registers) (struct regcache *regcache, int regno);
00127 
00128   /* Store registers to the inferior process.
00129 
00130      If REGNO is -1, store all registers; otherwise, store at least REGNO.  */
00131 
00132   void (*store_registers) (struct regcache *regcache, int regno);
00133 
00134   /* Prepare to read or write memory from the inferior process.
00135      Targets use this to do what is necessary to get the state of the
00136      inferior such that it is possible to access memory.
00137 
00138      This should generally only be called from client facing routines,
00139      such as gdb_read_memory/gdb_write_memory, or the insert_point
00140      callbacks.
00141 
00142      Like `read_memory' and `write_memory' below, returns 0 on success
00143      and errno on failure.  */
00144 
00145   int (*prepare_to_access_memory) (void);
00146 
00147   /* Undo the effects of prepare_to_access_memory.  */
00148 
00149   void (*done_accessing_memory) (void);
00150 
00151   /* Read memory from the inferior process.  This should generally be
00152      called through read_inferior_memory, which handles breakpoint shadowing.
00153 
00154      Read LEN bytes at MEMADDR into a buffer at MYADDR.
00155   
00156      Returns 0 on success and errno on failure.  */
00157 
00158   int (*read_memory) (CORE_ADDR memaddr, unsigned char *myaddr, int len);
00159 
00160   /* Write memory to the inferior process.  This should generally be
00161      called through write_inferior_memory, which handles breakpoint shadowing.
00162 
00163      Write LEN bytes from the buffer at MYADDR to MEMADDR.
00164 
00165      Returns 0 on success and errno on failure.  */
00166 
00167   int (*write_memory) (CORE_ADDR memaddr, const unsigned char *myaddr,
00168                        int len);
00169 
00170   /* Query GDB for the values of any symbols we're interested in.
00171      This function is called whenever we receive a "qSymbols::"
00172      query, which corresponds to every time more symbols (might)
00173      become available.  NULL if we aren't interested in any
00174      symbols.  */
00175 
00176   void (*look_up_symbols) (void);
00177 
00178   /* Send an interrupt request to the inferior process,
00179      however is appropriate.  */
00180 
00181   void (*request_interrupt) (void);
00182 
00183   /* Read auxiliary vector data from the inferior process.
00184 
00185      Read LEN bytes at OFFSET into a buffer at MYADDR.  */
00186 
00187   int (*read_auxv) (CORE_ADDR offset, unsigned char *myaddr,
00188                     unsigned int len);
00189 
00190   /* Insert and remove a break or watchpoint.
00191      Returns 0 on success, -1 on failure and 1 on unsupported.
00192      The type is coded as follows:
00193        '0' - software-breakpoint
00194        '1' - hardware-breakpoint
00195        '2' - write watchpoint
00196        '3' - read watchpoint
00197        '4' - access watchpoint  */
00198 
00199   int (*insert_point) (char type, CORE_ADDR addr, int len);
00200   int (*remove_point) (char type, CORE_ADDR addr, int len);
00201 
00202   /* Returns 1 if target was stopped due to a watchpoint hit, 0 otherwise.  */
00203 
00204   int (*stopped_by_watchpoint) (void);
00205 
00206   /* Returns the address associated with the watchpoint that hit, if any;
00207      returns 0 otherwise.  */
00208 
00209   CORE_ADDR (*stopped_data_address) (void);
00210 
00211   /* Reports the text, data offsets of the executable.  This is
00212      needed for uclinux where the executable is relocated during load
00213      time.  */
00214 
00215   int (*read_offsets) (CORE_ADDR *text, CORE_ADDR *data);
00216 
00217   /* Fetch the address associated with a specific thread local storage
00218      area, determined by the specified THREAD, OFFSET, and LOAD_MODULE.
00219      Stores it in *ADDRESS and returns zero on success; otherwise returns
00220      an error code.  A return value of -1 means this system does not
00221      support the operation.  */
00222 
00223   int (*get_tls_address) (struct thread_info *thread, CORE_ADDR offset,
00224                           CORE_ADDR load_module, CORE_ADDR *address);
00225 
00226    /* Read/Write from/to spufs using qXfer packets.  */
00227   int (*qxfer_spu) (const char *annex, unsigned char *readbuf,
00228                     unsigned const char *writebuf, CORE_ADDR offset, int len);
00229 
00230   /* Fill BUF with an hostio error packet representing the last hostio
00231      error.  */
00232   void (*hostio_last_error) (char *buf);
00233 
00234   /* Read/Write OS data using qXfer packets.  */
00235   int (*qxfer_osdata) (const char *annex, unsigned char *readbuf,
00236                        unsigned const char *writebuf, CORE_ADDR offset,
00237                        int len);
00238 
00239   /* Read/Write extra signal info.  */
00240   int (*qxfer_siginfo) (const char *annex, unsigned char *readbuf,
00241                         unsigned const char *writebuf,
00242                         CORE_ADDR offset, int len);
00243 
00244   int (*supports_non_stop) (void);
00245 
00246   /* Enables async target events.  Returns the previous enable
00247      state.  */
00248   int (*async) (int enable);
00249 
00250   /* Switch to non-stop (1) or all-stop (0) mode.  Return 0 on
00251      success, -1 otherwise.  */
00252   int (*start_non_stop) (int);
00253 
00254   /* Returns true if the target supports multi-process debugging.  */
00255   int (*supports_multi_process) (void);
00256 
00257   /* If not NULL, target-specific routine to process monitor command.
00258      Returns 1 if handled, or 0 to perform default processing.  */
00259   int (*handle_monitor_command) (char *);
00260 
00261   /* Returns the core given a thread, or -1 if not known.  */
00262   int (*core_of_thread) (ptid_t);
00263 
00264   /* Read loadmaps.  Read LEN bytes at OFFSET into a buffer at MYADDR.  */
00265   int (*read_loadmap) (const char *annex, CORE_ADDR offset,
00266                        unsigned char *myaddr, unsigned int len);
00267 
00268   /* Target specific qSupported support.  */
00269   void (*process_qsupported) (const char *);
00270 
00271   /* Return 1 if the target supports tracepoints, 0 (or leave the
00272      callback NULL) otherwise.  */
00273   int (*supports_tracepoints) (void);
00274 
00275   /* Read PC from REGCACHE.  */
00276   CORE_ADDR (*read_pc) (struct regcache *regcache);
00277 
00278   /* Write PC to REGCACHE.  */
00279   void (*write_pc) (struct regcache *regcache, CORE_ADDR pc);
00280 
00281   /* Return true if THREAD is known to be stopped now.  */
00282   int (*thread_stopped) (struct thread_info *thread);
00283 
00284   /* Read Thread Information Block address.  */
00285   int (*get_tib_address) (ptid_t ptid, CORE_ADDR *address);
00286 
00287   /* Pause all threads.  If FREEZE, arrange for any resume attempt to
00288      be ignored until an unpause_all call unfreezes threads again.
00289      There can be nested calls to pause_all, so a freeze counter
00290      should be maintained.  */
00291   void (*pause_all) (int freeze);
00292 
00293   /* Unpause all threads.  Threads that hadn't been resumed by the
00294      client should be left stopped.  Basically a pause/unpause call
00295      pair should not end up resuming threads that were stopped before
00296      the pause call.  */
00297   void (*unpause_all) (int unfreeze);
00298 
00299   /* Cancel all pending breakpoints hits in all threads.  */
00300   void (*cancel_breakpoints) (void);
00301 
00302   /* Stabilize all threads.  That is, force them out of jump pads.  */
00303   void (*stabilize_threads) (void);
00304 
00305   /* Install a fast tracepoint jump pad.  TPOINT is the address of the
00306      tracepoint internal object as used by the IPA agent.  TPADDR is
00307      the address of tracepoint.  COLLECTOR is address of the function
00308      the jump pad redirects to.  LOCKADDR is the address of the jump
00309      pad lock object.  ORIG_SIZE is the size in bytes of the
00310      instruction at TPADDR.  JUMP_ENTRY points to the address of the
00311      jump pad entry, and on return holds the address past the end of
00312      the created jump pad.  If a trampoline is created by the function,
00313      then TRAMPOLINE and TRAMPOLINE_SIZE return the address and size of
00314      the trampoline, else they remain unchanged.  JJUMP_PAD_INSN is a
00315      buffer containing a copy of the instruction at TPADDR.
00316      ADJUST_INSN_ADDR and ADJUST_INSN_ADDR_END are output parameters that
00317      return the address range where the instruction at TPADDR was relocated
00318      to.  If an error occurs, the ERR may be used to pass on an error
00319      message.  */
00320   int (*install_fast_tracepoint_jump_pad) (CORE_ADDR tpoint, CORE_ADDR tpaddr,
00321                                            CORE_ADDR collector,
00322                                            CORE_ADDR lockaddr,
00323                                            ULONGEST orig_size,
00324                                            CORE_ADDR *jump_entry,
00325                                            CORE_ADDR *trampoline,
00326                                            ULONGEST *trampoline_size,
00327                                            unsigned char *jjump_pad_insn,
00328                                            ULONGEST *jjump_pad_insn_size,
00329                                            CORE_ADDR *adjusted_insn_addr,
00330                                            CORE_ADDR *adjusted_insn_addr_end,
00331                                            char *err);
00332 
00333   /* Return the bytecode operations vector for the current inferior.
00334      Returns NULL if bytecode compilation is not supported.  */
00335   struct emit_ops *(*emit_ops) (void);
00336 
00337   /* Returns true if the target supports disabling randomization.  */
00338   int (*supports_disable_randomization) (void);
00339 
00340   /* Return the minimum length of an instruction that can be safely overwritten
00341      for use as a fast tracepoint.  */
00342   int (*get_min_fast_tracepoint_insn_len) (void);
00343 
00344   /* Read solib info on SVR4 platforms.  */
00345   int (*qxfer_libraries_svr4) (const char *annex, unsigned char *readbuf,
00346                                unsigned const char *writebuf,
00347                                CORE_ADDR offset, int len);
00348 
00349   /* Return true if target supports debugging agent.  */
00350   int (*supports_agent) (void);
00351 
00352   /* Check whether the target supports branch tracing.  */
00353   int (*supports_btrace) (void);
00354 
00355   /* Enable branch tracing for @ptid and allocate a branch trace target
00356      information struct for reading and for disabling branch trace.  */
00357   struct btrace_target_info *(*enable_btrace) (ptid_t ptid);
00358 
00359   /* Disable branch tracing.  */
00360   int (*disable_btrace) (struct btrace_target_info *tinfo);
00361 
00362   /* Read branch trace data into buffer.  We use an int to specify the type
00363      to break a cyclic dependency.  */
00364   void (*read_btrace) (struct btrace_target_info *, struct buffer *, int type);
00365 
00366   /* Return true if target supports range stepping.  */
00367   int (*supports_range_stepping) (void);
00368 };
00369 
00370 extern struct target_ops *the_target;
00371 
00372 void set_target_ops (struct target_ops *);
00373 
00374 #define create_inferior(program, args) \
00375   (*the_target->create_inferior) (program, args)
00376 
00377 #define myattach(pid) \
00378   (*the_target->attach) (pid)
00379 
00380 int kill_inferior (int);
00381 
00382 #define detach_inferior(pid) \
00383   (*the_target->detach) (pid)
00384 
00385 #define mourn_inferior(PROC) \
00386   (*the_target->mourn) (PROC)
00387 
00388 #define mythread_alive(pid) \
00389   (*the_target->thread_alive) (pid)
00390 
00391 #define fetch_inferior_registers(regcache, regno)       \
00392   (*the_target->fetch_registers) (regcache, regno)
00393 
00394 #define store_inferior_registers(regcache, regno) \
00395   (*the_target->store_registers) (regcache, regno)
00396 
00397 #define join_inferior(pid) \
00398   (*the_target->join) (pid)
00399 
00400 #define target_supports_non_stop() \
00401   (the_target->supports_non_stop ? (*the_target->supports_non_stop ) () : 0)
00402 
00403 #define target_async(enable) \
00404   (the_target->async ? (*the_target->async) (enable) : 0)
00405 
00406 #define target_supports_multi_process() \
00407   (the_target->supports_multi_process ? \
00408    (*the_target->supports_multi_process) () : 0)
00409 
00410 #define target_process_qsupported(query)                \
00411   do                                                    \
00412     {                                                   \
00413       if (the_target->process_qsupported)               \
00414         the_target->process_qsupported (query);         \
00415     } while (0)
00416 
00417 #define target_supports_tracepoints()                   \
00418   (the_target->supports_tracepoints                     \
00419    ? (*the_target->supports_tracepoints) () : 0)
00420 
00421 #define target_supports_fast_tracepoints()              \
00422   (the_target->install_fast_tracepoint_jump_pad != NULL)
00423 
00424 #define target_get_min_fast_tracepoint_insn_len()       \
00425   (the_target->get_min_fast_tracepoint_insn_len         \
00426    ? (*the_target->get_min_fast_tracepoint_insn_len) () : 0)
00427 
00428 #define thread_stopped(thread) \
00429   (*the_target->thread_stopped) (thread)
00430 
00431 #define pause_all(freeze)                       \
00432   do                                            \
00433     {                                           \
00434       if (the_target->pause_all)                \
00435         (*the_target->pause_all) (freeze);      \
00436     } while (0)
00437 
00438 #define unpause_all(unfreeze)                   \
00439   do                                            \
00440     {                                           \
00441       if (the_target->unpause_all)              \
00442         (*the_target->unpause_all) (unfreeze);  \
00443     } while (0)
00444 
00445 #define cancel_breakpoints()                    \
00446   do                                            \
00447     {                                           \
00448       if (the_target->cancel_breakpoints)       \
00449         (*the_target->cancel_breakpoints) ();   \
00450     } while (0)
00451 
00452 #define stabilize_threads()                     \
00453   do                                            \
00454     {                                           \
00455       if (the_target->stabilize_threads)        \
00456         (*the_target->stabilize_threads) ();    \
00457     } while (0)
00458 
00459 #define install_fast_tracepoint_jump_pad(tpoint, tpaddr,                \
00460                                          collector, lockaddr,           \
00461                                          orig_size,                     \
00462                                          jump_entry,                    \
00463                                          trampoline, trampoline_size,   \
00464                                          jjump_pad_insn,                \
00465                                          jjump_pad_insn_size,           \
00466                                          adjusted_insn_addr,            \
00467                                          adjusted_insn_addr_end,        \
00468                                          err)                           \
00469   (*the_target->install_fast_tracepoint_jump_pad) (tpoint, tpaddr,      \
00470                                                    collector,lockaddr,  \
00471                                                    orig_size, jump_entry, \
00472                                                    trampoline,          \
00473                                                    trampoline_size,     \
00474                                                    jjump_pad_insn,      \
00475                                                    jjump_pad_insn_size, \
00476                                                    adjusted_insn_addr,  \
00477                                                    adjusted_insn_addr_end, \
00478                                                    err)
00479 
00480 #define target_emit_ops() \
00481   (the_target->emit_ops ? (*the_target->emit_ops) () : NULL)
00482 
00483 #define target_supports_disable_randomization() \
00484   (the_target->supports_disable_randomization ? \
00485    (*the_target->supports_disable_randomization) () : 0)
00486 
00487 #define target_supports_agent() \
00488   (the_target->supports_agent ? \
00489    (*the_target->supports_agent) () : 0)
00490 
00491 #define target_supports_btrace() \
00492   (the_target->supports_btrace ? (*the_target->supports_btrace) () : 0)
00493 
00494 #define target_enable_btrace(ptid) \
00495   (*the_target->enable_btrace) (ptid)
00496 
00497 #define target_disable_btrace(tinfo) \
00498   (*the_target->disable_btrace) (tinfo)
00499 
00500 #define target_read_btrace(tinfo, buffer, type) \
00501   (*the_target->read_btrace) (tinfo, buffer, type)
00502 
00503 #define target_supports_range_stepping() \
00504   (the_target->supports_range_stepping ? \
00505    (*the_target->supports_range_stepping) () : 0)
00506 
00507 /* Start non-stop mode, returns 0 on success, -1 on failure.   */
00508 
00509 int start_non_stop (int nonstop);
00510 
00511 ptid_t mywait (ptid_t ptid, struct target_waitstatus *ourstatus, int options,
00512                int connected_wait);
00513 
00514 #define prepare_to_access_memory()              \
00515   (the_target->prepare_to_access_memory         \
00516    ? (*the_target->prepare_to_access_memory) () \
00517    : 0)
00518 
00519 #define done_accessing_memory()                         \
00520   do                                                    \
00521     {                                                   \
00522       if (the_target->done_accessing_memory)            \
00523         (*the_target->done_accessing_memory) ();        \
00524     } while (0)
00525 
00526 #define target_core_of_thread(ptid)             \
00527   (the_target->core_of_thread ? (*the_target->core_of_thread) (ptid) \
00528    : -1)
00529 
00530 int read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len);
00531 
00532 int write_inferior_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
00533                            int len);
00534 
00535 void set_desired_inferior (int id);
00536 
00537 const char *target_pid_to_str (ptid_t);
00538 
00539 #endif /* TARGET_H */
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines