gdb/progspace.h - gdb

Global variables defined

Data types defined

Macros defined

Source code

  1. /* Program and address space management, for GDB, the GNU debugger.

  2.    Copyright (C) 2009-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

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

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

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


  14. #ifndef PROGSPACE_H
  15. #define PROGSPACE_H

  16. #include "target.h"
  17. #include "vec.h"
  18. #include "gdb_vecs.h"
  19. #include "registry.h"

  20. struct target_ops;
  21. struct bfd;
  22. struct objfile;
  23. struct inferior;
  24. struct exec;
  25. struct address_space;
  26. struct program_space_data;
  27. struct address_space_data;

  28. typedef struct so_list *so_list_ptr;
  29. DEF_VEC_P (so_list_ptr);

  30. /* A program space represents a symbolic view of an address space.
  31.    Roughly speaking, it holds all the data associated with a
  32.    non-running-yet program (main executable, main symbols), and when
  33.    an inferior is running and is bound to it, includes the list of its
  34.    mapped in shared libraries.

  35.    In the traditional debugging scenario, there's a 1-1 correspondence
  36.    among program spaces, inferiors and address spaces, like so:

  37.      pspace1 (prog1) <--> inf1(pid1) <--> aspace1

  38.    In the case of debugging more than one traditional unix process or
  39.    program, we still have:

  40.      |-----------------+------------+---------|
  41.      | pspace1 (prog1) | inf1(pid1) | aspace1 |
  42.      |----------------------------------------|
  43.      | pspace2 (prog1) | no inf yet | aspace2 |
  44.      |-----------------+------------+---------|
  45.      | pspace3 (prog2) | inf2(pid2) | aspace3 |
  46.      |-----------------+------------+---------|

  47.    In the former example, if inf1 forks (and GDB stays attached to
  48.    both processes), the new child will have its own program and
  49.    address spaces.  Like so:

  50.      |-----------------+------------+---------|
  51.      | pspace1 (prog1) | inf1(pid1) | aspace1 |
  52.      |-----------------+------------+---------|
  53.      | pspace2 (prog1) | inf2(pid2) | aspace2 |
  54.      |-----------------+------------+---------|

  55.    However, had inf1 from the latter case vforked instead, it would
  56.    share the program and address spaces with its parent, until it
  57.    execs or exits, like so:

  58.      |-----------------+------------+---------|
  59.      | pspace1 (prog1) | inf1(pid1) | aspace1 |
  60.      |                 | inf2(pid2) |         |
  61.      |-----------------+------------+---------|

  62.    When the vfork child execs, it is finally given new program and
  63.    address spaces.

  64.      |-----------------+------------+---------|
  65.      | pspace1 (prog1) | inf1(pid1) | aspace1 |
  66.      |-----------------+------------+---------|
  67.      | pspace2 (prog1) | inf2(pid2) | aspace2 |
  68.      |-----------------+------------+---------|

  69.    There are targets where the OS (if any) doesn't provide memory
  70.    management or VM protection, where all inferiors share the same
  71.    address space --- e.g. uClinux.  GDB models this by having all
  72.    inferiors share the same address space, but, giving each its own
  73.    program space, like so:

  74.      |-----------------+------------+---------|
  75.      | pspace1 (prog1) | inf1(pid1) |         |
  76.      |-----------------+------------+         |
  77.      | pspace2 (prog1) | inf2(pid2) | aspace1 |
  78.      |-----------------+------------+         |
  79.      | pspace3 (prog2) | inf3(pid3) |         |
  80.      |-----------------+------------+---------|

  81.    The address space sharing matters for run control and breakpoints
  82.    management.  E.g., did we just hit a known breakpoint that we need
  83.    to step over?  Is this breakpoint a duplicate of this other one, or
  84.    do I need to insert a trap?

  85.    Then, there are targets where all symbols look the same for all
  86.    inferiors, although each has its own address space, as e.g.,
  87.    Ericsson DICOS.  In such case, the model is:

  88.      |---------+------------+---------|
  89.      |         | inf1(pid1) | aspace1 |
  90.      |         +------------+---------|
  91.      | pspace  | inf2(pid2) | aspace2 |
  92.      |         +------------+---------|
  93.      |         | inf3(pid3) | aspace3 |
  94.      |---------+------------+---------|

  95.    Note however, that the DICOS debug API takes care of making GDB
  96.    believe that breakpoints are "global".  That is, although each
  97.    process does have its own private copy of data symbols (just like a
  98.    bunch of forks), to the breakpoints module, all processes share a
  99.    single address space, so all breakpoints set at the same address
  100.    are duplicates of each other, even breakpoints set in the data
  101.    space (e.g., call dummy breakpoints placed on stack).  This allows
  102.    a simplification in the spaces implementation: we avoid caring for
  103.    a many-many links between address and program spaces.  Either
  104.    there's a single address space bound to the program space
  105.    (traditional unix/uClinux), or, in the DICOS case, the address
  106.    space bound to the program space is mostly ignored.  */

  107. /* The program space structure.  */

  108. struct program_space
  109.   {
  110.     /* Pointer to next in linked list.  */
  111.     struct program_space *next;

  112.     /* Unique ID number.  */
  113.     int num;

  114.     /* The main executable loaded into this program space.  This is
  115.        managed by the exec target.  */

  116.     /* The BFD handle for the main executable.  */
  117.     bfd *ebfd;
  118.     /* The last-modified time, from when the exec was brought in.  */
  119.     long ebfd_mtime;
  120.     /* Similar to bfd_get_filename (exec_bfd) but in original form given
  121.        by user, without symbolic links and pathname resolved.
  122.        It needs to be freed by xfree.  It is not NULL iff EBFD is not NULL.  */
  123.     char *pspace_exec_filename;

  124.     /* The address space attached to this program space.  More than one
  125.        program space may be bound to the same address space.  In the
  126.        traditional unix-like debugging scenario, this will usually
  127.        match the address space bound to the inferior, and is mostly
  128.        used by the breakpoints module for address matches.  If the
  129.        target shares a program space for all inferiors and breakpoints
  130.        are global, then this field is ignored (we don't currently
  131.        support inferiors sharing a program space if the target doesn't
  132.        make breakpoints global).  */
  133.     struct address_space *aspace;

  134.     /* True if this program space's section offsets don't yet represent
  135.        the final offsets of the "live" address space (that is, the
  136.        section addresses still require the relocation offsets to be
  137.        applied, and hence we can't trust the section addresses for
  138.        anything that pokes at live memory).  E.g., for qOffsets
  139.        targets, or for PIE executables, until we connect and ask the
  140.        target for the final relocation offsets, the symbols we've used
  141.        to set breakpoints point at the wrong addresses.  */
  142.     int executing_startup;

  143.     /* True if no breakpoints should be inserted in this program
  144.        space.  */
  145.     int breakpoints_not_allowed;

  146.     /* The object file that the main symbol table was loaded from
  147.        (e.g. the argument to the "symbol-file" or "file" command).  */
  148.     struct objfile *symfile_object_file;

  149.     /* All known objfiles are kept in a linked list.  This points to
  150.        the head of this list.  */
  151.     struct objfile *objfiles;

  152.     /* The set of target sections matching the sections mapped into
  153.        this program space.  Managed by both exec_ops and solib.c.  */
  154.     struct target_section_table target_sections;

  155.     /* List of shared objects mapped into this space.  Managed by
  156.        solib.c.  */
  157.     struct so_list *so_list;

  158.     /* Number of calls to solib_add.  */
  159.     unsigned solib_add_generation;

  160.     /* When an solib is added, it is also added to this vector.  This
  161.        is so we can properly report solib changes to the user.  */
  162.     VEC (so_list_ptr) *added_solibs;

  163.     /* When an solib is removed, its name is added to this vector.
  164.        This is so we can properly report solib changes to the user.  */
  165.     VEC (char_ptr) *deleted_solibs;

  166.     /* Per pspace data-pointers required by other GDB modules.  */
  167.     REGISTRY_FIELDS;
  168.   };

  169. /* The object file that the main symbol table was loaded from (e.g. the
  170.    argument to the "symbol-file" or "file" command).  */

  171. #define symfile_objfile current_program_space->symfile_object_file

  172. /* All known objfiles are kept in a linked list.  This points to the
  173.    root of this list.  */
  174. #define object_files current_program_space->objfiles

  175. /* The set of target sections matching the sections mapped into the
  176.    current program space.  */
  177. #define current_target_sections (&current_program_space->target_sections)

  178. /* The list of all program spaces.  There's always at least one.  */
  179. extern struct program_space *program_spaces;

  180. /* The current program space.  This is always non-null.  */
  181. extern struct program_space *current_program_space;

  182. #define ALL_PSPACES(pspace) \
  183.   for ((pspace) = program_spaces; (pspace) != NULL; (pspace) = (pspace)->next)

  184. /* Add a new empty program space, and assign ASPACE to it.  Returns the
  185.    pointer to the new object.  */
  186. extern struct program_space *add_program_space (struct address_space *aspace);

  187. /* Returns the number of program spaces listed.  */
  188. extern int number_of_program_spaces (void);

  189. /* Copies program space SRC to DEST.  Copies the main executable file,
  190.    and the main symbol file.  Returns DEST.  */
  191. extern struct program_space *clone_program_space (struct program_space *dest,
  192.                                                 struct program_space *src);

  193. /* Save the current program space so that it may be restored by a later
  194.    call to do_cleanups.  Returns the struct cleanup pointer needed for
  195.    later doing the cleanup.  */
  196. extern struct cleanup *save_current_program_space (void);

  197. /* Sets PSPACE as the current program space.  This is usually used
  198.    instead of set_current_space_and_thread when the current
  199.    thread/inferior is not important for the operations that follow.
  200.    E.g., when accessing the raw symbol tables.  If memory access is
  201.    required, then you should use switch_to_program_space_and_thread.
  202.    Otherwise, it is the caller's responsibility to make sure that the
  203.    currently selected inferior/thread matches the selected program
  204.    space.  */
  205. extern void set_current_program_space (struct program_space *pspace);

  206. /* Saves the current thread (may be null), frame and program space in
  207.    the current cleanup chain.  */
  208. extern struct cleanup *save_current_space_and_thread (void);

  209. /* Switches full context to program space PSPACE.  Switches to the
  210.    first thread found bound to PSPACE, giving preference to the
  211.    current thread, if there's one and it isn't executing.  */
  212. extern void switch_to_program_space_and_thread (struct program_space *pspace);

  213. /* Create a new address space object, and add it to the list.  */
  214. extern struct address_space *new_address_space (void);

  215. /* Maybe create a new address space object, and add it to the list, or
  216.    return a pointer to an existing address space, in case inferiors
  217.    share an address space.  */
  218. extern struct address_space *maybe_new_address_space (void);

  219. /* Returns the integer address space id of ASPACE.  */
  220. extern int address_space_num (struct address_space *aspace);

  221. /* Update all program spaces matching to address spaces.  The user may
  222.    have created several program spaces, and loaded executables into
  223.    them before connecting to the target interface that will create the
  224.    inferiors.  All that happens before GDB has a chance to know if the
  225.    inferiors will share an address space or not.  Call this after
  226.    having connected to the target interface and having fetched the
  227.    target description, to fixup the program/address spaces
  228.    mappings.  */
  229. extern void update_address_spaces (void);

  230. /* Prune away automatically added program spaces that aren't required
  231.    anymore.  */
  232. extern void prune_program_spaces (void);

  233. /* Reset saved solib data at the start of an solib event.  This lets
  234.    us properly collect the data when calling solib_add, so it can then
  235.    later be printed.  */
  236. extern void clear_program_space_solib_cache (struct program_space *);

  237. /* Keep a registry of per-pspace data-pointers required by other GDB
  238.    modules.  */

  239. DECLARE_REGISTRY (program_space);

  240. /* Keep a registry of per-aspace data-pointers required by other GDB
  241.    modules.  */

  242. DECLARE_REGISTRY (address_space);

  243. #endif