home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / gdb-4.9 / gdb / target.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-12  |  15.0 KB  |  425 lines

  1. /* Interface between GDB and target environments, including files and processes
  2.    Copyright 1990, 1991, 1992 Free Software Foundation, Inc.
  3.    Contributed by Cygnus Support.  Written by John Gilmore.
  4.  
  5. This file is part of GDB.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #if !defined (TARGET_H)
  22. #define TARGET_H
  23.  
  24. /* This include file defines the interface between the main part
  25.    of the debugger, and the part which is target-specific, or
  26.    specific to the communications interface between us and the
  27.    target.
  28.  
  29.    A TARGET is an interface between the debugger and a particular 
  30.    kind of file or process.  Targets can be STACKED in STRATA, 
  31.    so that more than one target can potentially respond to a request.
  32.    In particular, memory accesses will walk down the stack of targets
  33.    until they find a target that is interested in handling that particular
  34.    address.  STRATA are artificial boundaries on the stack, within
  35.    which particular kinds of targets live.  Strata exist so that
  36.    people don't get confused by pushing e.g. a process target and then
  37.    a file target, and wondering why they can't see the current values
  38.    of variables any more (the file target is handling them and they
  39.    never get to the process target).  So when you push a file target,
  40.    it goes into the file stratum, which is always below the process
  41.    stratum.  */
  42.  
  43. #include "bfd.h"
  44.  
  45. enum strata {
  46.     dummy_stratum,        /* The lowest of the low */
  47.     file_stratum,        /* Executable files, etc */
  48.     core_stratum,        /* Core dump files */
  49.     process_stratum        /* Executing processes */
  50. };
  51.  
  52. struct target_ops
  53. {
  54.   char           *to_shortname;    /* Name this target type */
  55.   char           *to_longname;    /* Name for printing */
  56.   char            *to_doc;            /* Documentation.  Does not include trailing
  57.                    newline, and starts with a one-line descrip-
  58.                    tion (probably similar to to_longname). */
  59.   void           (*to_open) PARAMS ((char *, int));
  60.   void           (*to_close) PARAMS ((int));
  61.   void           (*to_attach) PARAMS ((char *, int));
  62.   void           (*to_detach) PARAMS ((char *, int));
  63.   void           (*to_resume) PARAMS ((int, int));
  64.   int            (*to_wait) PARAMS ((int *));
  65.   void           (*to_fetch_registers) PARAMS ((int));
  66.   void           (*to_store_registers) PARAMS ((int));
  67.   void           (*to_prepare_to_store) PARAMS ((void));
  68.   int            (*to_xfer_memory) PARAMS ((CORE_ADDR, char *, int, int,
  69.                      struct target_ops *));
  70.   void           (*to_files_info) PARAMS ((struct target_ops *));
  71.   int            (*to_insert_breakpoint) PARAMS ((CORE_ADDR, char *));
  72.   int           (*to_remove_breakpoint) PARAMS ((CORE_ADDR, char *));
  73.   void           (*to_terminal_init) PARAMS ((void));
  74.   void           (*to_terminal_inferior) PARAMS ((void));
  75.   void           (*to_terminal_ours_for_output) PARAMS ((void));
  76.   void           (*to_terminal_ours) PARAMS ((void));
  77.   void           (*to_terminal_info) PARAMS ((char *, int));
  78.   void           (*to_kill) PARAMS ((void));
  79.   void           (*to_load) PARAMS ((char *, int));
  80.   int           (*to_lookup_symbol) PARAMS ((char *, CORE_ADDR *));
  81.   void           (*to_create_inferior) PARAMS ((char *, char *, char **));
  82.   void           (*to_mourn_inferior) PARAMS ((void));
  83.   int          (*to_can_run) PARAMS ((void));
  84.   void          (*to_notice_signals) PARAMS ((void));
  85.   enum strata   to_stratum;
  86.   struct target_ops
  87.                *to_next;
  88.   int        to_has_all_memory;
  89.   int        to_has_memory;
  90.   int        to_has_stack;
  91.   int        to_has_registers;
  92.   int        to_has_execution;
  93.   struct section_table
  94.                *to_sections;
  95.   struct section_table
  96.            *to_sections_end;
  97.   int        to_magic;
  98.   /* Need sub-structure for target machine related rather than comm related? */
  99. };
  100.  
  101. /* Magic number for checking ops size.  If a struct doesn't end with this
  102.    number, somebody changed the declaration but didn't change all the
  103.    places that initialize one.  */
  104.  
  105. #define    OPS_MAGIC    3840
  106.  
  107. /* The ops structure for our "current" target process.  */
  108.  
  109. extern struct target_ops    *current_target;
  110.  
  111. /* Define easy words for doing these operations on our current target.  */
  112.  
  113. #define    target_shortname    (current_target->to_shortname)
  114. #define    target_longname        (current_target->to_longname)
  115.  
  116. /* The open routine takes the rest of the parameters from the command,
  117.    and (if successful) pushes a new target onto the stack.
  118.    Targets should supply this routine, if only to provide an error message.  */
  119. #define    target_open(name, from_tty)    \
  120.     (*current_target->to_open) (name, from_tty)
  121.  
  122. /* Does whatever cleanup is required for a target that we are no longer
  123.    going to be calling.  Argument says whether we are quitting gdb and
  124.    should not get hung in case of errors, or whether we want a clean
  125.    termination even if it takes a while.  This routine is automatically
  126.    always called just before a routine is popped off the target stack.
  127.    Closing file descriptors and freeing memory are typical things it should
  128.    do.  */
  129.  
  130. #define    target_close(quitting)    \
  131.     (*current_target->to_close) (quitting)
  132.  
  133. /* Attaches to a process on the target side.  Arguments are as passed
  134.    to the `attach' command by the user.  This routine can be called
  135.    when the target is not on the target-stack, if the target_can_run
  136.    routine returns 1; in that case, it must push itself onto the stack.  
  137.    Upon exit, the target should be ready for normal operations, and
  138.    should be ready to deliver the status of the process immediately 
  139.    (without waiting) to an upcoming target_wait call.  */
  140.  
  141. #define    target_attach(args, from_tty)    \
  142.     (*current_target->to_attach) (args, from_tty)
  143.  
  144. /* Takes a program previously attached to and detaches it.
  145.    The program may resume execution (some targets do, some don't) and will
  146.    no longer stop on signals, etc.  We better not have left any breakpoints
  147.    in the program or it'll die when it hits one.  ARGS is arguments
  148.    typed by the user (e.g. a signal to send the process).  FROM_TTY
  149.    says whether to be verbose or not.  */
  150.  
  151. #define    target_detach(args, from_tty)        \
  152.     (*current_target->to_detach) (args, from_tty)
  153.  
  154. /* Resume execution of the target process.  STEP says whether to single-step
  155.    or to run free; SIGGNAL is the signal value (e.g. SIGINT) to be given
  156.    to the target, or zero for no signal.  */
  157.  
  158. #define    target_resume(step, siggnal)    \
  159.     (*current_target->to_resume) (step, siggnal)
  160.  
  161. /* Wait for inferior process to do something.  Return pid of child,
  162.    or -1 in case of error; store status through argument pointer STATUS.  */
  163.  
  164. #define    target_wait(status)        \
  165.     (*current_target->to_wait) (status)
  166.  
  167. /* Fetch register REGNO, or all regs if regno == -1.  No result.  */
  168.  
  169. #define    target_fetch_registers(regno)    \
  170.     (*current_target->to_fetch_registers) (regno)
  171.  
  172. /* Store at least register REGNO, or all regs if REGNO == -1.
  173.    It can store as many registers as it wants to, so the entire registers
  174.    array must be valid.  Result is 0 for success, -1 for problems.  */
  175.  
  176. #define    target_store_registers(regs)    \
  177.     (*current_target->to_store_registers) (regs)
  178.  
  179. /* Get ready to modify the registers array.  On machines which store
  180.    individual registers, this doesn't need to do anything.  On machines
  181.    which store all the registers in one fell swoop, this makes sure
  182.    that REGISTERS contains all the registers from the program being
  183.    debugged.  */
  184.  
  185. #define    target_prepare_to_store()    \
  186.     (*current_target->to_prepare_to_store) ()
  187.  
  188. /* Reading and writing memory actually happens through a glue
  189.    function which iterates across the various targets.  Result is
  190.    0 for success, or an errno value.  */
  191.  
  192. extern int
  193. target_read_string PARAMS ((CORE_ADDR, char *, int));
  194.  
  195. extern int
  196. target_read_memory PARAMS ((CORE_ADDR, char *, int));
  197.  
  198. extern int
  199. target_write_memory PARAMS ((CORE_ADDR, char *, int));
  200.  
  201. extern int
  202. xfer_memory PARAMS ((CORE_ADDR, char *, int, int, struct target_ops *));
  203.  
  204. extern int
  205. child_xfer_memory PARAMS ((CORE_ADDR, char *, int, int, struct target_ops *));
  206.  
  207. extern int
  208. target_xfer_memory PARAMS ((CORE_ADDR, char *, int, int));
  209.  
  210. /* From exec.c */
  211.  
  212. extern void
  213. print_section_info PARAMS ((struct target_ops *, bfd *));
  214.  
  215. /* Print a line about the current target.  */
  216.  
  217. #define    target_files_info()    \
  218.     (*current_target->to_files_info) (current_target)
  219.  
  220. /* Insert a breakpoint at address ADDR in the target machine.
  221.    SAVE is a pointer to memory allocated for saving the
  222.    target contents.  It is guaranteed by the caller to be long enough
  223.    to save "sizeof BREAKPOINT" bytes.  Result is 0 for success, or
  224.    an errno value.  */
  225.  
  226. #define    target_insert_breakpoint(addr, save)    \
  227.     (*current_target->to_insert_breakpoint) (addr, save)
  228.  
  229. /* Remove a breakpoint at address ADDR in the target machine.
  230.    SAVE is a pointer to the same save area 
  231.    that was previously passed to target_insert_breakpoint.  
  232.    Result is 0 for success, or an errno value.  */
  233.  
  234. #define    target_remove_breakpoint(addr, save)    \
  235.     (*current_target->to_remove_breakpoint) (addr, save)
  236.  
  237. /* Initialize the terminal settings we record for the inferior,
  238.    before we actually run the inferior.  */
  239.  
  240. #define target_terminal_init() \
  241.     (*current_target->to_terminal_init) ()
  242.     
  243. /* Put the inferior's terminal settings into effect.
  244.    This is preparation for starting or resuming the inferior.  */
  245.  
  246. #define target_terminal_inferior() \
  247.     (*current_target->to_terminal_inferior) ()
  248.  
  249. /* Put some of our terminal settings into effect,
  250.    enough to get proper results from our output,
  251.    but do not change into or out of RAW mode
  252.    so that no input is discarded.
  253.  
  254.    After doing this, either terminal_ours or terminal_inferior
  255.    should be called to get back to a normal state of affairs.  */
  256.  
  257. #define target_terminal_ours_for_output() \
  258.     (*current_target->to_terminal_ours_for_output) ()
  259.  
  260. /* Put our terminal settings into effect.
  261.    First record the inferior's terminal settings
  262.    so they can be restored properly later.  */
  263.  
  264. #define target_terminal_ours() \
  265.     (*current_target->to_terminal_ours) ()
  266.  
  267. /* Print useful information about our terminal status, if such a thing
  268.    exists.  */
  269.  
  270. #define target_terminal_info(arg, from_tty) \
  271.     (*current_target->to_terminal_info) (arg, from_tty)
  272.  
  273. /* Kill the inferior process.   Make it go away.  */
  274.  
  275. #define target_kill() \
  276.     (*current_target->to_kill) ()
  277.  
  278. /* Load an executable file into the target process.  This is expected to
  279.    not only bring new code into the target process, but also to update
  280.    GDB's symbol tables to match.  */
  281.  
  282. #define target_load(arg, from_tty) \
  283.     (*current_target->to_load) (arg, from_tty)
  284.  
  285. /* Look up a symbol in the target's symbol table.  NAME is the symbol
  286.    name.  ADDRP is a CORE_ADDR * pointing to where the value of the symbol
  287.    should be returned.  The result is 0 if successful, nonzero if the
  288.    symbol does not exist in the target environment.  This function should
  289.    not call error() if communication with the target is interrupted, since
  290.    it is called from symbol reading, but should return nonzero, possibly
  291.    doing a complain().  */
  292.  
  293. #define target_lookup_symbol(name, addrp)     \
  294.   (*current_target->to_lookup_symbol) (name, addrp)
  295.  
  296. /* Start an inferior process and set inferior_pid to its pid.
  297.    EXEC_FILE is the file to run.
  298.    ALLARGS is a string containing the arguments to the program.
  299.    ENV is the environment vector to pass.  Errors reported with error().
  300.    On VxWorks and various standalone systems, we ignore exec_file.  */
  301.  
  302. #define    target_create_inferior(exec_file, args, env)    \
  303.     (*current_target->to_create_inferior) (exec_file, args, env)
  304.  
  305. /* The inferior process has died.  Do what is right.  */
  306.  
  307. #define    target_mourn_inferior()    \
  308.     (*current_target->to_mourn_inferior) ()
  309.  
  310. /* Does target have enough data to do a run or attach command? */
  311.  
  312. #define target_can_run(t) \
  313.       ((t)->to_can_run) ()
  314.  
  315. /* post process changes to signal handling in the inferior.  */
  316.  
  317. #define target_notice_signals() \
  318.       (*current_target->to_notice_signals) ()
  319.  
  320. /* Pointer to next target in the chain, e.g. a core file and an exec file.  */
  321.  
  322. #define    target_next \
  323.     (current_target->to_next)
  324.  
  325. /* Does the target include all of memory, or only part of it?  This
  326.    determines whether we look up the target chain for other parts of
  327.    memory if this target can't satisfy a request.  */
  328.  
  329. #define    target_has_all_memory    \
  330.     (current_target->to_has_all_memory)
  331.  
  332. /* Does the target include memory?  (Dummy targets don't.)  */
  333.  
  334. #define    target_has_memory    \
  335.     (current_target->to_has_memory)
  336.  
  337. /* Does the target have a stack?  (Exec files don't, VxWorks doesn't, until
  338.    we start a process.)  */
  339.    
  340. #define    target_has_stack    \
  341.     (current_target->to_has_stack)
  342.  
  343. /* Does the target have registers?  (Exec files don't.)  */
  344.  
  345. #define    target_has_registers    \
  346.     (current_target->to_has_registers)
  347.  
  348. /* Does the target have execution?  Can we make it jump (through hoops),
  349.    or pop its stack a few times?  */
  350.  
  351. #define    target_has_execution    \
  352.     (current_target->to_has_execution)
  353.  
  354. /* Routines for maintenance of the target structures...
  355.  
  356.    add_target:   Add a target to the list of all possible targets.
  357.  
  358.    push_target:  Make this target the top of the stack of currently used
  359.          targets, within its particular stratum of the stack.  Result
  360.          is 0 if now atop the stack, nonzero if not on top (maybe
  361.          should warn user).
  362.  
  363.    unpush_target: Remove this from the stack of currently used targets,
  364.          no matter where it is on the list.  Returns 0 if no
  365.          change, 1 if removed from stack.
  366.  
  367.    pop_target:     Remove the top thing on the stack of current targets.  */
  368.  
  369. extern void
  370. add_target PARAMS ((struct target_ops *));
  371.  
  372. extern int
  373. push_target PARAMS ((struct target_ops *));
  374.  
  375. extern int
  376. unpush_target PARAMS ((struct target_ops *));
  377.  
  378. extern void
  379. target_preopen PARAMS ((int));
  380.  
  381. extern void
  382. pop_target PARAMS ((void));
  383.  
  384. /* Struct section_table maps address ranges to file sections.  It is
  385.    mostly used with BFD files, but can be used without (e.g. for handling
  386.    raw disks, or files not in formats handled by BFD).  */
  387.  
  388. struct section_table {
  389.   CORE_ADDR addr;        /* Lowest address in section */
  390.   CORE_ADDR endaddr;        /* 1+highest address in section */
  391.   sec_ptr   sec_ptr;        /* BFD section pointer */
  392.   bfd       *bfd;        /* BFD file pointer */
  393. };
  394.  
  395. /* Builds a section table, given args BFD, SECTABLE_PTR, SECEND_PTR.
  396.    Returns 0 if OK, 1 on error.  */
  397.  
  398. extern int
  399. build_section_table PARAMS ((bfd *, struct section_table **,
  400.                  struct section_table **));
  401.  
  402. /* From mem-break.c */
  403.  
  404. extern int
  405. memory_remove_breakpoint PARAMS ((CORE_ADDR, char *));
  406.  
  407. extern int
  408. memory_insert_breakpoint PARAMS ((CORE_ADDR, char *));
  409.  
  410. /* From target.c */
  411.  
  412. void
  413. noprocess PARAMS ((void));
  414.  
  415. void
  416. find_default_attach PARAMS ((char *, int));
  417.  
  418. void
  419. find_default_create_inferior PARAMS ((char *, char *, char **));
  420.  
  421. struct target_ops *
  422. find_core_target PARAMS ((void));
  423.  
  424. #endif    /* !defined (TARGET_H) */
  425.