GDB (API)
|
00001 /* Program and address space management, for GDB, the GNU debugger. 00002 00003 Copyright (C) 2009-2013 Free Software Foundation, Inc. 00004 00005 This file is part of GDB. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00019 00020 00021 #ifndef PROGSPACE_H 00022 #define PROGSPACE_H 00023 00024 #include "target.h" 00025 #include "vec.h" 00026 #include "gdb_vecs.h" 00027 #include "registry.h" 00028 00029 struct target_ops; 00030 struct bfd; 00031 struct objfile; 00032 struct inferior; 00033 struct exec; 00034 struct address_space; 00035 struct program_space_data; 00036 00037 typedef struct so_list *so_list_ptr; 00038 DEF_VEC_P (so_list_ptr); 00039 00040 /* A program space represents a symbolic view of an address space. 00041 Roughly speaking, it holds all the data associated with a 00042 non-running-yet program (main executable, main symbols), and when 00043 an inferior is running and is bound to it, includes the list of its 00044 mapped in shared libraries. 00045 00046 In the traditional debugging scenario, there's a 1-1 correspondence 00047 among program spaces, inferiors and address spaces, like so: 00048 00049 pspace1 (prog1) <--> inf1(pid1) <--> aspace1 00050 00051 In the case of debugging more than one traditional unix process or 00052 program, we still have: 00053 00054 |-----------------+------------+---------| 00055 | pspace1 (prog1) | inf1(pid1) | aspace1 | 00056 |----------------------------------------| 00057 | pspace2 (prog1) | no inf yet | aspace2 | 00058 |-----------------+------------+---------| 00059 | pspace3 (prog2) | inf2(pid2) | aspace3 | 00060 |-----------------+------------+---------| 00061 00062 In the former example, if inf1 forks (and GDB stays attached to 00063 both processes), the new child will have its own program and 00064 address spaces. Like so: 00065 00066 |-----------------+------------+---------| 00067 | pspace1 (prog1) | inf1(pid1) | aspace1 | 00068 |-----------------+------------+---------| 00069 | pspace2 (prog1) | inf2(pid2) | aspace2 | 00070 |-----------------+------------+---------| 00071 00072 However, had inf1 from the latter case vforked instead, it would 00073 share the program and address spaces with its parent, until it 00074 execs or exits, like so: 00075 00076 |-----------------+------------+---------| 00077 | pspace1 (prog1) | inf1(pid1) | aspace1 | 00078 | | inf2(pid2) | | 00079 |-----------------+------------+---------| 00080 00081 When the vfork child execs, it is finally given new program and 00082 address spaces. 00083 00084 |-----------------+------------+---------| 00085 | pspace1 (prog1) | inf1(pid1) | aspace1 | 00086 |-----------------+------------+---------| 00087 | pspace2 (prog1) | inf2(pid2) | aspace2 | 00088 |-----------------+------------+---------| 00089 00090 There are targets where the OS (if any) doesn't provide memory 00091 management or VM protection, where all inferiors share the same 00092 address space --- e.g. uClinux. GDB models this by having all 00093 inferiors share the same address space, but, giving each its own 00094 program space, like so: 00095 00096 |-----------------+------------+---------| 00097 | pspace1 (prog1) | inf1(pid1) | | 00098 |-----------------+------------+ | 00099 | pspace2 (prog1) | inf2(pid2) | aspace1 | 00100 |-----------------+------------+ | 00101 | pspace3 (prog2) | inf3(pid3) | | 00102 |-----------------+------------+---------| 00103 00104 The address space sharing matters for run control and breakpoints 00105 management. E.g., did we just hit a known breakpoint that we need 00106 to step over? Is this breakpoint a duplicate of this other one, or 00107 do I need to insert a trap? 00108 00109 Then, there are targets where all symbols look the same for all 00110 inferiors, although each has its own address space, as e.g., 00111 Ericsson DICOS. In such case, the model is: 00112 00113 |---------+------------+---------| 00114 | | inf1(pid1) | aspace1 | 00115 | +------------+---------| 00116 | pspace | inf2(pid2) | aspace2 | 00117 | +------------+---------| 00118 | | inf3(pid3) | aspace3 | 00119 |---------+------------+---------| 00120 00121 Note however, that the DICOS debug API takes care of making GDB 00122 believe that breakpoints are "global". That is, although each 00123 process does have its own private copy of data symbols (just like a 00124 bunch of forks), to the breakpoints module, all processes share a 00125 single address space, so all breakpoints set at the same address 00126 are duplicates of each other, even breakpoints set in the data 00127 space (e.g., call dummy breakpoints placed on stack). This allows 00128 a simplification in the spaces implementation: we avoid caring for 00129 a many-many links between address and program spaces. Either 00130 there's a single address space bound to the program space 00131 (traditional unix/uClinux), or, in the DICOS case, the address 00132 space bound to the program space is mostly ignored. */ 00133 00134 /* The program space structure. */ 00135 00136 struct program_space 00137 { 00138 /* Pointer to next in linked list. */ 00139 struct program_space *next; 00140 00141 /* Unique ID number. */ 00142 int num; 00143 00144 /* The main executable loaded into this program space. This is 00145 managed by the exec target. */ 00146 00147 /* The BFD handle for the main executable. */ 00148 bfd *ebfd; 00149 /* The last-modified time, from when the exec was brought in. */ 00150 long ebfd_mtime; 00151 /* Similar to bfd_get_filename (exec_bfd) but in original form given 00152 by user, without symbolic links and pathname resolved. 00153 It needs to be freed by xfree. It is not NULL iff EBFD is not NULL. */ 00154 char *pspace_exec_filename; 00155 00156 /* The address space attached to this program space. More than one 00157 program space may be bound to the same address space. In the 00158 traditional unix-like debugging scenario, this will usually 00159 match the address space bound to the inferior, and is mostly 00160 used by the breakpoints module for address matches. If the 00161 target shares a program space for all inferiors and breakpoints 00162 are global, then this field is ignored (we don't currently 00163 support inferiors sharing a program space if the target doesn't 00164 make breakpoints global). */ 00165 struct address_space *aspace; 00166 00167 /* True if this program space's section offsets don't yet represent 00168 the final offsets of the "live" address space (that is, the 00169 section addresses still require the relocation offsets to be 00170 applied, and hence we can't trust the section addresses for 00171 anything that pokes at live memory). E.g., for qOffsets 00172 targets, or for PIE executables, until we connect and ask the 00173 target for the final relocation offsets, the symbols we've used 00174 to set breakpoints point at the wrong addresses. */ 00175 int executing_startup; 00176 00177 /* True if no breakpoints should be inserted in this program 00178 space. */ 00179 int breakpoints_not_allowed; 00180 00181 /* The object file that the main symbol table was loaded from 00182 (e.g. the argument to the "symbol-file" or "file" command). */ 00183 struct objfile *symfile_object_file; 00184 00185 /* All known objfiles are kept in a linked list. This points to 00186 the head of this list. */ 00187 struct objfile *objfiles; 00188 00189 /* The set of target sections matching the sections mapped into 00190 this program space. Managed by both exec_ops and solib.c. */ 00191 struct target_section_table target_sections; 00192 00193 /* List of shared objects mapped into this space. Managed by 00194 solib.c. */ 00195 struct so_list *so_list; 00196 00197 /* Number of calls to solib_add. */ 00198 unsigned solib_add_generation; 00199 00200 /* When an solib is added, it is also added to this vector. This 00201 is so we can properly report solib changes to the user. */ 00202 VEC (so_list_ptr) *added_solibs; 00203 00204 /* When an solib is removed, its name is added to this vector. 00205 This is so we can properly report solib changes to the user. */ 00206 VEC (char_ptr) *deleted_solibs; 00207 00208 /* Per pspace data-pointers required by other GDB modules. */ 00209 REGISTRY_FIELDS; 00210 }; 00211 00212 /* The object file that the main symbol table was loaded from (e.g. the 00213 argument to the "symbol-file" or "file" command). */ 00214 00215 #define symfile_objfile current_program_space->symfile_object_file 00216 00217 /* All known objfiles are kept in a linked list. This points to the 00218 root of this list. */ 00219 #define object_files current_program_space->objfiles 00220 00221 /* The set of target sections matching the sections mapped into the 00222 current program space. */ 00223 #define current_target_sections (¤t_program_space->target_sections) 00224 00225 /* The list of all program spaces. There's always at least one. */ 00226 extern struct program_space *program_spaces; 00227 00228 /* The current program space. This is always non-null. */ 00229 extern struct program_space *current_program_space; 00230 00231 #define ALL_PSPACES(pspace) \ 00232 for ((pspace) = program_spaces; (pspace) != NULL; (pspace) = (pspace)->next) 00233 00234 /* Add a new empty program space, and assign ASPACE to it. Returns the 00235 pointer to the new object. */ 00236 extern struct program_space *add_program_space (struct address_space *aspace); 00237 00238 /* Release PSPACE and removes it from the pspace list. */ 00239 extern void remove_program_space (struct program_space *pspace); 00240 00241 /* Returns the number of program spaces listed. */ 00242 extern int number_of_program_spaces (void); 00243 00244 /* Copies program space SRC to DEST. Copies the main executable file, 00245 and the main symbol file. Returns DEST. */ 00246 extern struct program_space *clone_program_space (struct program_space *dest, 00247 struct program_space *src); 00248 00249 /* Save the current program space so that it may be restored by a later 00250 call to do_cleanups. Returns the struct cleanup pointer needed for 00251 later doing the cleanup. */ 00252 extern struct cleanup *save_current_program_space (void); 00253 00254 /* Sets PSPACE as the current program space. This is usually used 00255 instead of set_current_space_and_thread when the current 00256 thread/inferior is not important for the operations that follow. 00257 E.g., when accessing the raw symbol tables. If memory access is 00258 required, then you should use switch_to_program_space_and_thread. 00259 Otherwise, it is the caller's responsibility to make sure that the 00260 currently selected inferior/thread matches the selected program 00261 space. */ 00262 extern void set_current_program_space (struct program_space *pspace); 00263 00264 /* Saves the current thread (may be null), frame and program space in 00265 the current cleanup chain. */ 00266 extern struct cleanup *save_current_space_and_thread (void); 00267 00268 /* Switches full context to program space PSPACE. Switches to the 00269 first thread found bound to PSPACE. */ 00270 extern void switch_to_program_space_and_thread (struct program_space *pspace); 00271 00272 /* Create a new address space object, and add it to the list. */ 00273 extern struct address_space *new_address_space (void); 00274 00275 /* Maybe create a new address space object, and add it to the list, or 00276 return a pointer to an existing address space, in case inferiors 00277 share an address space. */ 00278 extern struct address_space *maybe_new_address_space (void); 00279 00280 /* Returns the integer address space id of ASPACE. */ 00281 extern int address_space_num (struct address_space *aspace); 00282 00283 /* Update all program spaces matching to address spaces. The user may 00284 have created several program spaces, and loaded executables into 00285 them before connecting to the target interface that will create the 00286 inferiors. All that happens before GDB has a chance to know if the 00287 inferiors will share an address space or not. Call this after 00288 having connected to the target interface and having fetched the 00289 target description, to fixup the program/address spaces 00290 mappings. */ 00291 extern void update_address_spaces (void); 00292 00293 /* Prune away automatically added program spaces that aren't required 00294 anymore. */ 00295 extern void prune_program_spaces (void); 00296 00297 /* Reset saved solib data at the start of an solib event. This lets 00298 us properly collect the data when calling solib_add, so it can then 00299 later be printed. */ 00300 extern void clear_program_space_solib_cache (struct program_space *); 00301 00302 /* Keep a registry of per-pspace data-pointers required by other GDB 00303 modules. */ 00304 00305 DECLARE_REGISTRY (program_space); 00306 00307 #endif