xref: /dflybsd-src/contrib/gdb-7/gdb/addrmap.h (revision de8e141f24382815c10a4012d209bbbf7abf1112)
15796c8dcSSimon Schubert /* addrmap.h --- interface to address map data structure.
25796c8dcSSimon Schubert 
3*ef5ccd6cSJohn Marino    Copyright (C) 2007-2013 Free Software Foundation, Inc.
45796c8dcSSimon Schubert 
55796c8dcSSimon Schubert    This file is part of GDB.
65796c8dcSSimon Schubert 
75796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
85796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
95796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
105796c8dcSSimon Schubert    (at your option) any later version.
115796c8dcSSimon Schubert 
125796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
135796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
145796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
155796c8dcSSimon Schubert    GNU General Public License for more details.
165796c8dcSSimon Schubert 
175796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
185796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
195796c8dcSSimon Schubert 
205796c8dcSSimon Schubert #ifndef ADDRMAP_H
215796c8dcSSimon Schubert #define ADDRMAP_H
225796c8dcSSimon Schubert 
235796c8dcSSimon Schubert /* An address map is essentially a table mapping CORE_ADDRs onto GDB
245796c8dcSSimon Schubert    data structures, like blocks, symtabs, partial symtabs, and so on.
255796c8dcSSimon Schubert    An address map uses memory proportional to the number of
265796c8dcSSimon Schubert    transitions in the map, where a CORE_ADDR N is mapped to one
275796c8dcSSimon Schubert    object, and N+1 is mapped to a different object.
285796c8dcSSimon Schubert 
295796c8dcSSimon Schubert    Address maps come in two flavors: fixed, and mutable.  Mutable
305796c8dcSSimon Schubert    address maps consume more memory, but can be changed and extended.
315796c8dcSSimon Schubert    A fixed address map, once constructed (from a mutable address map),
325796c8dcSSimon Schubert    can't be edited.  Both kinds of map are allocated in obstacks.  */
335796c8dcSSimon Schubert 
345796c8dcSSimon Schubert /* The opaque type representing address maps.  */
355796c8dcSSimon Schubert struct addrmap;
365796c8dcSSimon Schubert 
375796c8dcSSimon Schubert /* Create a mutable address map which maps every address to NULL.
385796c8dcSSimon Schubert    Allocate entries in OBSTACK.  */
395796c8dcSSimon Schubert struct addrmap *addrmap_create_mutable (struct obstack *obstack);
405796c8dcSSimon Schubert 
415796c8dcSSimon Schubert /* In the mutable address map MAP, associate the addresses from START
425796c8dcSSimon Schubert    to END_INCLUSIVE that are currently associated with NULL with OBJ
435796c8dcSSimon Schubert    instead.  Addresses mapped to an object other than NULL are left
445796c8dcSSimon Schubert    unchanged.
455796c8dcSSimon Schubert 
465796c8dcSSimon Schubert    As the name suggests, END_INCLUSIVE is also mapped to OBJ.  This
475796c8dcSSimon Schubert    convention is unusual, but it allows callers to accurately specify
485796c8dcSSimon Schubert    ranges that abut the top of the address space, and ranges that
495796c8dcSSimon Schubert    cover the entire address space.
505796c8dcSSimon Schubert 
515796c8dcSSimon Schubert    This operation seems a bit complicated for a primitive: if it's
525796c8dcSSimon Schubert    needed, why not just have a simpler primitive operation that sets a
535796c8dcSSimon Schubert    range to a value, wiping out whatever was there before, and then
545796c8dcSSimon Schubert    let the caller construct more complicated operations from that,
555796c8dcSSimon Schubert    along with some others for traversal?
565796c8dcSSimon Schubert 
575796c8dcSSimon Schubert    It turns out this is the mutation operation we want to use all the
585796c8dcSSimon Schubert    time, at least for now.  Our immediate use for address maps is to
595796c8dcSSimon Schubert    represent lexical blocks whose address ranges are not contiguous.
605796c8dcSSimon Schubert    We walk the tree of lexical blocks present in the debug info, and
615796c8dcSSimon Schubert    only create 'struct block' objects after we've traversed all a
625796c8dcSSimon Schubert    block's children.  If a lexical block declares no local variables
635796c8dcSSimon Schubert    (and isn't the lexical block for a function's body), we omit it
645796c8dcSSimon Schubert    from GDB's data structures entirely.
655796c8dcSSimon Schubert 
665796c8dcSSimon Schubert    However, this means that we don't decide to create a block (and
675796c8dcSSimon Schubert    thus record it in the address map) until after we've traversed its
685796c8dcSSimon Schubert    children.  If we do decide to create the block, we do so at a time
695796c8dcSSimon Schubert    when all its children have already been recorded in the map.  So
705796c8dcSSimon Schubert    this operation --- change only those addresses left unset --- is
715796c8dcSSimon Schubert    actually the operation we want to use every time.
725796c8dcSSimon Schubert 
735796c8dcSSimon Schubert    It seems simpler to let the code which operates on the
745796c8dcSSimon Schubert    representation directly deal with the hair of implementing these
755796c8dcSSimon Schubert    semantics than to provide an interface which allows it to be
765796c8dcSSimon Schubert    implemented efficiently, but doesn't reveal too much of the
775796c8dcSSimon Schubert    representation.  */
785796c8dcSSimon Schubert void addrmap_set_empty (struct addrmap *map,
795796c8dcSSimon Schubert                         CORE_ADDR start, CORE_ADDR end_inclusive,
805796c8dcSSimon Schubert                         void *obj);
815796c8dcSSimon Schubert 
825796c8dcSSimon Schubert /* Return the object associated with ADDR in MAP.  */
835796c8dcSSimon Schubert void *addrmap_find (struct addrmap *map, CORE_ADDR addr);
845796c8dcSSimon Schubert 
855796c8dcSSimon Schubert /* Create a fixed address map which is a copy of the mutable address
865796c8dcSSimon Schubert    map ORIGINAL.  Allocate entries in OBSTACK.  */
875796c8dcSSimon Schubert struct addrmap *addrmap_create_fixed (struct addrmap *original,
885796c8dcSSimon Schubert                                       struct obstack *obstack);
895796c8dcSSimon Schubert 
905796c8dcSSimon Schubert /* Relocate all the addresses in MAP by OFFSET.  (This can be applied
915796c8dcSSimon Schubert    to either mutable or immutable maps.)  */
925796c8dcSSimon Schubert void addrmap_relocate (struct addrmap *map, CORE_ADDR offset);
935796c8dcSSimon Schubert 
94c50c785cSJohn Marino /* The type of a function used to iterate over the map.
95c50c785cSJohn Marino    OBJ is NULL for unmapped regions.  */
96c50c785cSJohn Marino typedef int (*addrmap_foreach_fn) (void *data, CORE_ADDR start_addr,
97c50c785cSJohn Marino 				   void *obj);
98c50c785cSJohn Marino 
99c50c785cSJohn Marino /* Call FN, passing it DATA, for every address in MAP, following an
100c50c785cSJohn Marino    in-order traversal.  If FN ever returns a non-zero value, the
101c50c785cSJohn Marino    iteration ceases immediately, and the value is returned.
102c50c785cSJohn Marino    Otherwise, this function returns 0.  */
103c50c785cSJohn Marino int addrmap_foreach (struct addrmap *map, addrmap_foreach_fn fn, void *data);
104c50c785cSJohn Marino 
1055796c8dcSSimon Schubert #endif /* ADDRMAP_H */
106