gdb/addrmap.h - gdb

Data types defined

Macros defined

Source code

  1. /* addrmap.h --- interface to address map data structure.

  2.    Copyright (C) 2007-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 ADDRMAP_H
  15. #define ADDRMAP_H

  16. /* An address map is essentially a table mapping CORE_ADDRs onto GDB
  17.    data structures, like blocks, symtabs, partial symtabs, and so on.
  18.    An address map uses memory proportional to the number of
  19.    transitions in the map, where a CORE_ADDR N is mapped to one
  20.    object, and N+1 is mapped to a different object.

  21.    Address maps come in two flavors: fixed, and mutable.  Mutable
  22.    address maps consume more memory, but can be changed and extended.
  23.    A fixed address map, once constructed (from a mutable address map),
  24.    can't be edited.  Both kinds of map are allocated in obstacks.  */

  25. /* The opaque type representing address maps.  */
  26. struct addrmap;

  27. /* Create a mutable address map which maps every address to NULL.
  28.    Allocate entries in OBSTACK.  */
  29. struct addrmap *addrmap_create_mutable (struct obstack *obstack);

  30. /* In the mutable address map MAP, associate the addresses from START
  31.    to END_INCLUSIVE that are currently associated with NULL with OBJ
  32.    instead.  Addresses mapped to an object other than NULL are left
  33.    unchanged.

  34.    As the name suggests, END_INCLUSIVE is also mapped to OBJ.  This
  35.    convention is unusual, but it allows callers to accurately specify
  36.    ranges that abut the top of the address space, and ranges that
  37.    cover the entire address space.

  38.    This operation seems a bit complicated for a primitive: if it's
  39.    needed, why not just have a simpler primitive operation that sets a
  40.    range to a value, wiping out whatever was there before, and then
  41.    let the caller construct more complicated operations from that,
  42.    along with some others for traversal?

  43.    It turns out this is the mutation operation we want to use all the
  44.    time, at least for now.  Our immediate use for address maps is to
  45.    represent lexical blocks whose address ranges are not contiguous.
  46.    We walk the tree of lexical blocks present in the debug info, and
  47.    only create 'struct block' objects after we've traversed all a
  48.    block's children.  If a lexical block declares no local variables
  49.    (and isn't the lexical block for a function's body), we omit it
  50.    from GDB's data structures entirely.

  51.    However, this means that we don't decide to create a block (and
  52.    thus record it in the address map) until after we've traversed its
  53.    children.  If we do decide to create the block, we do so at a time
  54.    when all its children have already been recorded in the map.  So
  55.    this operation --- change only those addresses left unset --- is
  56.    actually the operation we want to use every time.

  57.    It seems simpler to let the code which operates on the
  58.    representation directly deal with the hair of implementing these
  59.    semantics than to provide an interface which allows it to be
  60.    implemented efficiently, but doesn't reveal too much of the
  61.    representation.  */
  62. void addrmap_set_empty (struct addrmap *map,
  63.                         CORE_ADDR start, CORE_ADDR end_inclusive,
  64.                         void *obj);

  65. /* Return the object associated with ADDR in MAP.  */
  66. void *addrmap_find (struct addrmap *map, CORE_ADDR addr);

  67. /* Create a fixed address map which is a copy of the mutable address
  68.    map ORIGINAL.  Allocate entries in OBSTACK.  */
  69. struct addrmap *addrmap_create_fixed (struct addrmap *original,
  70.                                       struct obstack *obstack);

  71. /* Relocate all the addresses in MAP by OFFSET.  (This can be applied
  72.    to either mutable or immutable maps.)  */
  73. void addrmap_relocate (struct addrmap *map, CORE_ADDR offset);

  74. /* The type of a function used to iterate over the map.
  75.    OBJ is NULL for unmapped regions.  */
  76. typedef int (*addrmap_foreach_fn) (void *data, CORE_ADDR start_addr,
  77.                                    void *obj);

  78. /* Call FN, passing it DATA, for every address in MAP, following an
  79.    in-order traversal.  If FN ever returns a non-zero value, the
  80.    iteration ceases immediately, and the value is returned.
  81.    Otherwise, this function returns 0.  */
  82. int addrmap_foreach (struct addrmap *map, addrmap_foreach_fn fn, void *data);

  83. #endif /* ADDRMAP_H */