addrmap.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* addrmap.h --- interface to address map data structure.
  2. Copyright (C) 2007-2022 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. #include "gdbsupport/function-view.h"
  17. /* An address map is essentially a table mapping CORE_ADDRs onto GDB
  18. data structures, like blocks, symtabs, partial symtabs, and so on.
  19. An address map uses memory proportional to the number of
  20. transitions in the map, where a CORE_ADDR N is mapped to one
  21. object, and N+1 is mapped to a different object.
  22. Address maps come in two flavors: fixed, and mutable. Mutable
  23. address maps consume more memory, but can be changed and extended.
  24. A fixed address map, once constructed (from a mutable address map),
  25. can't be edited. Both kinds of map are allocated in obstacks. */
  26. /* The opaque type representing address maps. */
  27. struct addrmap;
  28. /* Create a mutable address map which maps every address to NULL.
  29. Allocate entries in OBSTACK. */
  30. struct addrmap *addrmap_create_mutable (struct obstack *obstack);
  31. /* In the mutable address map MAP, associate the addresses from START
  32. to END_INCLUSIVE that are currently associated with NULL with OBJ
  33. instead. Addresses mapped to an object other than NULL are left
  34. unchanged.
  35. As the name suggests, END_INCLUSIVE is also mapped to OBJ. This
  36. convention is unusual, but it allows callers to accurately specify
  37. ranges that abut the top of the address space, and ranges that
  38. cover the entire address space.
  39. This operation seems a bit complicated for a primitive: if it's
  40. needed, why not just have a simpler primitive operation that sets a
  41. range to a value, wiping out whatever was there before, and then
  42. let the caller construct more complicated operations from that,
  43. along with some others for traversal?
  44. It turns out this is the mutation operation we want to use all the
  45. time, at least for now. Our immediate use for address maps is to
  46. represent lexical blocks whose address ranges are not contiguous.
  47. We walk the tree of lexical blocks present in the debug info, and
  48. only create 'struct block' objects after we've traversed all a
  49. block's children. If a lexical block declares no local variables
  50. (and isn't the lexical block for a function's body), we omit it
  51. from GDB's data structures entirely.
  52. However, this means that we don't decide to create a block (and
  53. thus record it in the address map) until after we've traversed its
  54. children. If we do decide to create the block, we do so at a time
  55. when all its children have already been recorded in the map. So
  56. this operation --- change only those addresses left unset --- is
  57. actually the operation we want to use every time.
  58. It seems simpler to let the code which operates on the
  59. representation directly deal with the hair of implementing these
  60. semantics than to provide an interface which allows it to be
  61. implemented efficiently, but doesn't reveal too much of the
  62. representation. */
  63. void addrmap_set_empty (struct addrmap *map,
  64. CORE_ADDR start, CORE_ADDR end_inclusive,
  65. void *obj);
  66. /* Return the object associated with ADDR in MAP. */
  67. void *addrmap_find (struct addrmap *map, CORE_ADDR addr);
  68. /* Create a fixed address map which is a copy of the mutable address
  69. map ORIGINAL. Allocate entries in OBSTACK. */
  70. struct addrmap *addrmap_create_fixed (struct addrmap *original,
  71. struct obstack *obstack);
  72. /* Relocate all the addresses in MAP by OFFSET. (This can be applied
  73. to either mutable or immutable maps.) */
  74. void addrmap_relocate (struct addrmap *map, CORE_ADDR offset);
  75. /* The type of a function used to iterate over the map.
  76. OBJ is NULL for unmapped regions. */
  77. typedef gdb::function_view<int (CORE_ADDR start_addr, void *obj)>
  78. addrmap_foreach_fn;
  79. /* Call FN for every address in MAP, following an in-order traversal.
  80. If FN ever returns a non-zero value, the iteration ceases
  81. immediately, and the value is returned. Otherwise, this function
  82. returns 0. */
  83. int addrmap_foreach (struct addrmap *map, addrmap_foreach_fn fn);
  84. /* Dump the addrmap to OUTFILE. If PAYLOAD is non-NULL, only dump any
  85. components that map to PAYLOAD. (If PAYLOAD is NULL, the entire
  86. map is dumped.) */
  87. void addrmap_dump (struct addrmap *map, struct ui_file *outfile,
  88. void *payload);
  89. #endif /* ADDRMAP_H */