xref: /dflybsd-src/contrib/gdb-7/gdb/progspace.h (revision de8e141f24382815c10a4012d209bbbf7abf1112)
1cf7f2e2dSJohn Marino /* Program and address space management, for GDB, the GNU debugger.
2cf7f2e2dSJohn Marino 
3*ef5ccd6cSJohn Marino    Copyright (C) 2009-2013 Free Software Foundation, Inc.
4cf7f2e2dSJohn Marino 
5cf7f2e2dSJohn Marino    This file is part of GDB.
6cf7f2e2dSJohn Marino 
7cf7f2e2dSJohn Marino    This program is free software; you can redistribute it and/or modify
8cf7f2e2dSJohn Marino    it under the terms of the GNU General Public License as published by
9cf7f2e2dSJohn Marino    the Free Software Foundation; either version 3 of the License, or
10cf7f2e2dSJohn Marino    (at your option) any later version.
11cf7f2e2dSJohn Marino 
12cf7f2e2dSJohn Marino    This program is distributed in the hope that it will be useful,
13cf7f2e2dSJohn Marino    but WITHOUT ANY WARRANTY; without even the implied warranty of
14cf7f2e2dSJohn Marino    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15cf7f2e2dSJohn Marino    GNU General Public License for more details.
16cf7f2e2dSJohn Marino 
17cf7f2e2dSJohn Marino    You should have received a copy of the GNU General Public License
18cf7f2e2dSJohn Marino    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19cf7f2e2dSJohn Marino 
20cf7f2e2dSJohn Marino 
21cf7f2e2dSJohn Marino #ifndef PROGSPACE_H
22cf7f2e2dSJohn Marino #define PROGSPACE_H
23cf7f2e2dSJohn Marino 
24cf7f2e2dSJohn Marino #include "target.h"
25cf7f2e2dSJohn Marino #include "vec.h"
26*ef5ccd6cSJohn Marino #include "gdb_vecs.h"
27*ef5ccd6cSJohn Marino #include "registry.h"
28cf7f2e2dSJohn Marino 
29cf7f2e2dSJohn Marino struct target_ops;
30cf7f2e2dSJohn Marino struct bfd;
31cf7f2e2dSJohn Marino struct objfile;
32cf7f2e2dSJohn Marino struct inferior;
33cf7f2e2dSJohn Marino struct exec;
34cf7f2e2dSJohn Marino struct address_space;
35cf7f2e2dSJohn Marino struct program_space_data;
36cf7f2e2dSJohn Marino 
37*ef5ccd6cSJohn Marino typedef struct so_list *so_list_ptr;
38*ef5ccd6cSJohn Marino DEF_VEC_P (so_list_ptr);
39*ef5ccd6cSJohn Marino 
40cf7f2e2dSJohn Marino /* A program space represents a symbolic view of an address space.
41cf7f2e2dSJohn Marino    Roughly speaking, it holds all the data associated with a
42cf7f2e2dSJohn Marino    non-running-yet program (main executable, main symbols), and when
43cf7f2e2dSJohn Marino    an inferior is running and is bound to it, includes the list of its
44cf7f2e2dSJohn Marino    mapped in shared libraries.
45cf7f2e2dSJohn Marino 
46cf7f2e2dSJohn Marino    In the traditional debugging scenario, there's a 1-1 correspondence
47cf7f2e2dSJohn Marino    among program spaces, inferiors and address spaces, like so:
48cf7f2e2dSJohn Marino 
49cf7f2e2dSJohn Marino      pspace1 (prog1) <--> inf1(pid1) <--> aspace1
50cf7f2e2dSJohn Marino 
51cf7f2e2dSJohn Marino    In the case of debugging more than one traditional unix process or
52cf7f2e2dSJohn Marino    program, we still have:
53cf7f2e2dSJohn Marino 
54cf7f2e2dSJohn Marino      |-----------------+------------+---------|
55cf7f2e2dSJohn Marino      | pspace1 (prog1) | inf1(pid1) | aspace1 |
56cf7f2e2dSJohn Marino      |----------------------------------------|
57cf7f2e2dSJohn Marino      | pspace2 (prog1) | no inf yet | aspace2 |
58cf7f2e2dSJohn Marino      |-----------------+------------+---------|
59cf7f2e2dSJohn Marino      | pspace3 (prog2) | inf2(pid2) | aspace3 |
60cf7f2e2dSJohn Marino      |-----------------+------------+---------|
61cf7f2e2dSJohn Marino 
62cf7f2e2dSJohn Marino    In the former example, if inf1 forks (and GDB stays attached to
63cf7f2e2dSJohn Marino    both processes), the new child will have its own program and
64cf7f2e2dSJohn Marino    address spaces.  Like so:
65cf7f2e2dSJohn Marino 
66cf7f2e2dSJohn Marino      |-----------------+------------+---------|
67cf7f2e2dSJohn Marino      | pspace1 (prog1) | inf1(pid1) | aspace1 |
68cf7f2e2dSJohn Marino      |-----------------+------------+---------|
69cf7f2e2dSJohn Marino      | pspace2 (prog1) | inf2(pid2) | aspace2 |
70cf7f2e2dSJohn Marino      |-----------------+------------+---------|
71cf7f2e2dSJohn Marino 
72cf7f2e2dSJohn Marino    However, had inf1 from the latter case vforked instead, it would
73cf7f2e2dSJohn Marino    share the program and address spaces with its parent, until it
74cf7f2e2dSJohn Marino    execs or exits, like so:
75cf7f2e2dSJohn Marino 
76cf7f2e2dSJohn Marino      |-----------------+------------+---------|
77cf7f2e2dSJohn Marino      | pspace1 (prog1) | inf1(pid1) | aspace1 |
78cf7f2e2dSJohn Marino      |                 | inf2(pid2) |         |
79cf7f2e2dSJohn Marino      |-----------------+------------+---------|
80cf7f2e2dSJohn Marino 
81cf7f2e2dSJohn Marino    When the vfork child execs, it is finally given new program and
82cf7f2e2dSJohn Marino    address spaces.
83cf7f2e2dSJohn Marino 
84cf7f2e2dSJohn Marino      |-----------------+------------+---------|
85cf7f2e2dSJohn Marino      | pspace1 (prog1) | inf1(pid1) | aspace1 |
86cf7f2e2dSJohn Marino      |-----------------+------------+---------|
87cf7f2e2dSJohn Marino      | pspace2 (prog1) | inf2(pid2) | aspace2 |
88cf7f2e2dSJohn Marino      |-----------------+------------+---------|
89cf7f2e2dSJohn Marino 
90cf7f2e2dSJohn Marino    There are targets where the OS (if any) doesn't provide memory
91cf7f2e2dSJohn Marino    management or VM protection, where all inferiors share the same
92cf7f2e2dSJohn Marino    address space --- e.g. uClinux.  GDB models this by having all
93cf7f2e2dSJohn Marino    inferiors share the same address space, but, giving each its own
94cf7f2e2dSJohn Marino    program space, like so:
95cf7f2e2dSJohn Marino 
96cf7f2e2dSJohn Marino      |-----------------+------------+---------|
97cf7f2e2dSJohn Marino      | pspace1 (prog1) | inf1(pid1) |         |
98cf7f2e2dSJohn Marino      |-----------------+------------+         |
99cf7f2e2dSJohn Marino      | pspace2 (prog1) | inf2(pid2) | aspace1 |
100cf7f2e2dSJohn Marino      |-----------------+------------+         |
101cf7f2e2dSJohn Marino      | pspace3 (prog2) | inf3(pid3) |         |
102cf7f2e2dSJohn Marino      |-----------------+------------+---------|
103cf7f2e2dSJohn Marino 
104cf7f2e2dSJohn Marino    The address space sharing matters for run control and breakpoints
105cf7f2e2dSJohn Marino    management.  E.g., did we just hit a known breakpoint that we need
106cf7f2e2dSJohn Marino    to step over?  Is this breakpoint a duplicate of this other one, or
107cf7f2e2dSJohn Marino    do I need to insert a trap?
108cf7f2e2dSJohn Marino 
109cf7f2e2dSJohn Marino    Then, there are targets where all symbols look the same for all
110cf7f2e2dSJohn Marino    inferiors, although each has its own address space, as e.g.,
111cf7f2e2dSJohn Marino    Ericsson DICOS.  In such case, the model is:
112cf7f2e2dSJohn Marino 
113cf7f2e2dSJohn Marino      |---------+------------+---------|
114cf7f2e2dSJohn Marino      |         | inf1(pid1) | aspace1 |
115cf7f2e2dSJohn Marino      |         +------------+---------|
116cf7f2e2dSJohn Marino      | pspace  | inf2(pid2) | aspace2 |
117cf7f2e2dSJohn Marino      |         +------------+---------|
118cf7f2e2dSJohn Marino      |         | inf3(pid3) | aspace3 |
119cf7f2e2dSJohn Marino      |---------+------------+---------|
120cf7f2e2dSJohn Marino 
121cf7f2e2dSJohn Marino    Note however, that the DICOS debug API takes care of making GDB
122cf7f2e2dSJohn Marino    believe that breakpoints are "global".  That is, although each
123cf7f2e2dSJohn Marino    process does have its own private copy of data symbols (just like a
124cf7f2e2dSJohn Marino    bunch of forks), to the breakpoints module, all processes share a
125cf7f2e2dSJohn Marino    single address space, so all breakpoints set at the same address
126cf7f2e2dSJohn Marino    are duplicates of each other, even breakpoints set in the data
127cf7f2e2dSJohn Marino    space (e.g., call dummy breakpoints placed on stack).  This allows
128cf7f2e2dSJohn Marino    a simplification in the spaces implementation: we avoid caring for
129cf7f2e2dSJohn Marino    a many-many links between address and program spaces.  Either
130cf7f2e2dSJohn Marino    there's a single address space bound to the program space
131cf7f2e2dSJohn Marino    (traditional unix/uClinux), or, in the DICOS case, the address
132cf7f2e2dSJohn Marino    space bound to the program space is mostly ignored.  */
133cf7f2e2dSJohn Marino 
134cf7f2e2dSJohn Marino /* The program space structure.  */
135cf7f2e2dSJohn Marino 
136cf7f2e2dSJohn Marino struct program_space
137cf7f2e2dSJohn Marino   {
138cf7f2e2dSJohn Marino     /* Pointer to next in linked list.  */
139cf7f2e2dSJohn Marino     struct program_space *next;
140cf7f2e2dSJohn Marino 
141cf7f2e2dSJohn Marino     /* Unique ID number.  */
142cf7f2e2dSJohn Marino     int num;
143cf7f2e2dSJohn Marino 
144cf7f2e2dSJohn Marino     /* The main executable loaded into this program space.  This is
145cf7f2e2dSJohn Marino        managed by the exec target.  */
146cf7f2e2dSJohn Marino 
147cf7f2e2dSJohn Marino     /* The BFD handle for the main executable.  */
148cf7f2e2dSJohn Marino     bfd *ebfd;
149cf7f2e2dSJohn Marino     /* The last-modified time, from when the exec was brought in.  */
150cf7f2e2dSJohn Marino     long ebfd_mtime;
151*ef5ccd6cSJohn Marino     /* Similar to bfd_get_filename (exec_bfd) but in original form given
152*ef5ccd6cSJohn Marino        by user, without symbolic links and pathname resolved.
153*ef5ccd6cSJohn Marino        It needs to be freed by xfree.  It is not NULL iff EBFD is not NULL.  */
154*ef5ccd6cSJohn Marino     char *pspace_exec_filename;
155cf7f2e2dSJohn Marino 
156cf7f2e2dSJohn Marino     /* The address space attached to this program space.  More than one
157cf7f2e2dSJohn Marino        program space may be bound to the same address space.  In the
158cf7f2e2dSJohn Marino        traditional unix-like debugging scenario, this will usually
159cf7f2e2dSJohn Marino        match the address space bound to the inferior, and is mostly
160cf7f2e2dSJohn Marino        used by the breakpoints module for address matches.  If the
161cf7f2e2dSJohn Marino        target shares a program space for all inferiors and breakpoints
162cf7f2e2dSJohn Marino        are global, then this field is ignored (we don't currently
163cf7f2e2dSJohn Marino        support inferiors sharing a program space if the target doesn't
164cf7f2e2dSJohn Marino        make breakpoints global).  */
165cf7f2e2dSJohn Marino     struct address_space *aspace;
166cf7f2e2dSJohn Marino 
167cf7f2e2dSJohn Marino     /* True if this program space's section offsets don't yet represent
168cf7f2e2dSJohn Marino        the final offsets of the "live" address space (that is, the
169cf7f2e2dSJohn Marino        section addresses still require the relocation offsets to be
170cf7f2e2dSJohn Marino        applied, and hence we can't trust the section addresses for
171cf7f2e2dSJohn Marino        anything that pokes at live memory).  E.g., for qOffsets
172cf7f2e2dSJohn Marino        targets, or for PIE executables, until we connect and ask the
173cf7f2e2dSJohn Marino        target for the final relocation offsets, the symbols we've used
174cf7f2e2dSJohn Marino        to set breakpoints point at the wrong addresses.  */
175cf7f2e2dSJohn Marino     int executing_startup;
176cf7f2e2dSJohn Marino 
177cf7f2e2dSJohn Marino     /* True if no breakpoints should be inserted in this program
178cf7f2e2dSJohn Marino        space.  */
179cf7f2e2dSJohn Marino     int breakpoints_not_allowed;
180cf7f2e2dSJohn Marino 
181cf7f2e2dSJohn Marino     /* The object file that the main symbol table was loaded from
182cf7f2e2dSJohn Marino        (e.g. the argument to the "symbol-file" or "file" command).  */
183cf7f2e2dSJohn Marino     struct objfile *symfile_object_file;
184cf7f2e2dSJohn Marino 
185cf7f2e2dSJohn Marino     /* All known objfiles are kept in a linked list.  This points to
186cf7f2e2dSJohn Marino        the head of this list.  */
187cf7f2e2dSJohn Marino     struct objfile *objfiles;
188cf7f2e2dSJohn Marino 
189cf7f2e2dSJohn Marino     /* The set of target sections matching the sections mapped into
190cf7f2e2dSJohn Marino        this program space.  Managed by both exec_ops and solib.c.  */
191cf7f2e2dSJohn Marino     struct target_section_table target_sections;
192cf7f2e2dSJohn Marino 
193cf7f2e2dSJohn Marino     /* List of shared objects mapped into this space.  Managed by
194cf7f2e2dSJohn Marino        solib.c.  */
195cf7f2e2dSJohn Marino     struct so_list *so_list;
196cf7f2e2dSJohn Marino 
197a45ae5f8SJohn Marino     /* Number of calls to solib_add.  */
198a45ae5f8SJohn Marino     unsigned solib_add_generation;
199a45ae5f8SJohn Marino 
200*ef5ccd6cSJohn Marino     /* When an solib is added, it is also added to this vector.  This
201*ef5ccd6cSJohn Marino        is so we can properly report solib changes to the user.  */
202*ef5ccd6cSJohn Marino     VEC (so_list_ptr) *added_solibs;
203*ef5ccd6cSJohn Marino 
204*ef5ccd6cSJohn Marino     /* When an solib is removed, its name is added to this vector.
205*ef5ccd6cSJohn Marino        This is so we can properly report solib changes to the user.  */
206*ef5ccd6cSJohn Marino     VEC (char_ptr) *deleted_solibs;
207*ef5ccd6cSJohn Marino 
208cf7f2e2dSJohn Marino     /* Per pspace data-pointers required by other GDB modules.  */
209*ef5ccd6cSJohn Marino     REGISTRY_FIELDS;
210cf7f2e2dSJohn Marino   };
211cf7f2e2dSJohn Marino 
212cf7f2e2dSJohn Marino /* The object file that the main symbol table was loaded from (e.g. the
213cf7f2e2dSJohn Marino    argument to the "symbol-file" or "file" command).  */
214cf7f2e2dSJohn Marino 
215cf7f2e2dSJohn Marino #define symfile_objfile current_program_space->symfile_object_file
216cf7f2e2dSJohn Marino 
217cf7f2e2dSJohn Marino /* All known objfiles are kept in a linked list.  This points to the
218cf7f2e2dSJohn Marino    root of this list.  */
219cf7f2e2dSJohn Marino #define object_files current_program_space->objfiles
220cf7f2e2dSJohn Marino 
221cf7f2e2dSJohn Marino /* The set of target sections matching the sections mapped into the
222cf7f2e2dSJohn Marino    current program space.  */
223cf7f2e2dSJohn Marino #define current_target_sections (&current_program_space->target_sections)
224cf7f2e2dSJohn Marino 
225cf7f2e2dSJohn Marino /* The list of all program spaces.  There's always at least one.  */
226cf7f2e2dSJohn Marino extern struct program_space *program_spaces;
227cf7f2e2dSJohn Marino 
228cf7f2e2dSJohn Marino /* The current program space.  This is always non-null.  */
229cf7f2e2dSJohn Marino extern struct program_space *current_program_space;
230cf7f2e2dSJohn Marino 
231cf7f2e2dSJohn Marino #define ALL_PSPACES(pspace) \
232cf7f2e2dSJohn Marino   for ((pspace) = program_spaces; (pspace) != NULL; (pspace) = (pspace)->next)
233cf7f2e2dSJohn Marino 
234cf7f2e2dSJohn Marino /* Add a new empty program space, and assign ASPACE to it.  Returns the
235cf7f2e2dSJohn Marino    pointer to the new object.  */
236cf7f2e2dSJohn Marino extern struct program_space *add_program_space (struct address_space *aspace);
237cf7f2e2dSJohn Marino 
238cf7f2e2dSJohn Marino /* Release PSPACE and removes it from the pspace list.  */
239cf7f2e2dSJohn Marino extern void remove_program_space (struct program_space *pspace);
240cf7f2e2dSJohn Marino 
241cf7f2e2dSJohn Marino /* Returns the number of program spaces listed.  */
242cf7f2e2dSJohn Marino extern int number_of_program_spaces (void);
243cf7f2e2dSJohn Marino 
244cf7f2e2dSJohn Marino /* Copies program space SRC to DEST.  Copies the main executable file,
245cf7f2e2dSJohn Marino    and the main symbol file.  Returns DEST.  */
246cf7f2e2dSJohn Marino extern struct program_space *clone_program_space (struct program_space *dest,
247cf7f2e2dSJohn Marino 						struct program_space *src);
248cf7f2e2dSJohn Marino 
249cf7f2e2dSJohn Marino /* Save the current program space so that it may be restored by a later
250cf7f2e2dSJohn Marino    call to do_cleanups.  Returns the struct cleanup pointer needed for
251cf7f2e2dSJohn Marino    later doing the cleanup.  */
252cf7f2e2dSJohn Marino extern struct cleanup *save_current_program_space (void);
253cf7f2e2dSJohn Marino 
254cf7f2e2dSJohn Marino /* Sets PSPACE as the current program space.  This is usually used
255cf7f2e2dSJohn Marino    instead of set_current_space_and_thread when the current
256cf7f2e2dSJohn Marino    thread/inferior is not important for the operations that follow.
257cf7f2e2dSJohn Marino    E.g., when accessing the raw symbol tables.  If memory access is
258cf7f2e2dSJohn Marino    required, then you should use switch_to_program_space_and_thread.
259cf7f2e2dSJohn Marino    Otherwise, it is the caller's responsibility to make sure that the
260cf7f2e2dSJohn Marino    currently selected inferior/thread matches the selected program
261cf7f2e2dSJohn Marino    space.  */
262cf7f2e2dSJohn Marino extern void set_current_program_space (struct program_space *pspace);
263cf7f2e2dSJohn Marino 
264cf7f2e2dSJohn Marino /* Saves the current thread (may be null), frame and program space in
265cf7f2e2dSJohn Marino    the current cleanup chain.  */
266cf7f2e2dSJohn Marino extern struct cleanup *save_current_space_and_thread (void);
267cf7f2e2dSJohn Marino 
268cf7f2e2dSJohn Marino /* Switches full context to program space PSPACE.  Switches to the
269cf7f2e2dSJohn Marino    first thread found bound to PSPACE.  */
270cf7f2e2dSJohn Marino extern void switch_to_program_space_and_thread (struct program_space *pspace);
271cf7f2e2dSJohn Marino 
272cf7f2e2dSJohn Marino /* Create a new address space object, and add it to the list.  */
273cf7f2e2dSJohn Marino extern struct address_space *new_address_space (void);
274cf7f2e2dSJohn Marino 
275cf7f2e2dSJohn Marino /* Maybe create a new address space object, and add it to the list, or
276cf7f2e2dSJohn Marino    return a pointer to an existing address space, in case inferiors
277cf7f2e2dSJohn Marino    share an address space.  */
278cf7f2e2dSJohn Marino extern struct address_space *maybe_new_address_space (void);
279cf7f2e2dSJohn Marino 
280cf7f2e2dSJohn Marino /* Returns the integer address space id of ASPACE.  */
281cf7f2e2dSJohn Marino extern int address_space_num (struct address_space *aspace);
282cf7f2e2dSJohn Marino 
283cf7f2e2dSJohn Marino /* Update all program spaces matching to address spaces.  The user may
284cf7f2e2dSJohn Marino    have created several program spaces, and loaded executables into
285cf7f2e2dSJohn Marino    them before connecting to the target interface that will create the
286cf7f2e2dSJohn Marino    inferiors.  All that happens before GDB has a chance to know if the
287cf7f2e2dSJohn Marino    inferiors will share an address space or not.  Call this after
288cf7f2e2dSJohn Marino    having connected to the target interface and having fetched the
289cf7f2e2dSJohn Marino    target description, to fixup the program/address spaces
290cf7f2e2dSJohn Marino    mappings.  */
291cf7f2e2dSJohn Marino extern void update_address_spaces (void);
292cf7f2e2dSJohn Marino 
293cf7f2e2dSJohn Marino /* Prune away automatically added program spaces that aren't required
294cf7f2e2dSJohn Marino    anymore.  */
295cf7f2e2dSJohn Marino extern void prune_program_spaces (void);
296cf7f2e2dSJohn Marino 
297*ef5ccd6cSJohn Marino /* Reset saved solib data at the start of an solib event.  This lets
298*ef5ccd6cSJohn Marino    us properly collect the data when calling solib_add, so it can then
299*ef5ccd6cSJohn Marino    later be printed.  */
300*ef5ccd6cSJohn Marino extern void clear_program_space_solib_cache (struct program_space *);
301*ef5ccd6cSJohn Marino 
302cf7f2e2dSJohn Marino /* Keep a registry of per-pspace data-pointers required by other GDB
303cf7f2e2dSJohn Marino    modules.  */
304cf7f2e2dSJohn Marino 
305*ef5ccd6cSJohn Marino DECLARE_REGISTRY (program_space);
306cf7f2e2dSJohn Marino 
307cf7f2e2dSJohn Marino #endif
308