buildsym-legacy.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /* Legacy support routines for building symbol tables in GDB's internal format.
  2. Copyright (C) 1986-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. #include "defs.h"
  15. #include "buildsym-legacy.h"
  16. #include "symtab.h"
  17. /* The work-in-progress of the compunit we are building.
  18. This is created first, before any subfiles by start_compunit_symtab. */
  19. static struct buildsym_compunit *buildsym_compunit;
  20. void
  21. record_debugformat (const char *format)
  22. {
  23. buildsym_compunit->record_debugformat (format);
  24. }
  25. void
  26. record_producer (const char *producer)
  27. {
  28. buildsym_compunit->record_producer (producer);
  29. }
  30. /* See buildsym.h. */
  31. void
  32. set_last_source_file (const char *name)
  33. {
  34. gdb_assert (buildsym_compunit != nullptr || name == nullptr);
  35. if (buildsym_compunit != nullptr)
  36. buildsym_compunit->set_last_source_file (name);
  37. }
  38. /* See buildsym.h. */
  39. const char *
  40. get_last_source_file ()
  41. {
  42. if (buildsym_compunit == nullptr)
  43. return nullptr;
  44. return buildsym_compunit->get_last_source_file ();
  45. }
  46. /* See buildsym.h. */
  47. void
  48. set_last_source_start_addr (CORE_ADDR addr)
  49. {
  50. gdb_assert (buildsym_compunit != nullptr);
  51. buildsym_compunit->set_last_source_start_addr (addr);
  52. }
  53. /* See buildsym.h. */
  54. CORE_ADDR
  55. get_last_source_start_addr ()
  56. {
  57. gdb_assert (buildsym_compunit != nullptr);
  58. return buildsym_compunit->get_last_source_start_addr ();
  59. }
  60. /* See buildsym.h. */
  61. bool
  62. outermost_context_p ()
  63. {
  64. gdb_assert (buildsym_compunit != nullptr);
  65. return buildsym_compunit->outermost_context_p ();
  66. }
  67. /* See buildsym.h. */
  68. int
  69. get_context_stack_depth ()
  70. {
  71. gdb_assert (buildsym_compunit != nullptr);
  72. return buildsym_compunit->get_context_stack_depth ();
  73. }
  74. /* See buildsym.h. */
  75. struct subfile *
  76. get_current_subfile ()
  77. {
  78. gdb_assert (buildsym_compunit != nullptr);
  79. return buildsym_compunit->get_current_subfile ();
  80. }
  81. /* See buildsym.h. */
  82. struct pending **
  83. get_local_symbols ()
  84. {
  85. gdb_assert (buildsym_compunit != nullptr);
  86. return buildsym_compunit->get_local_symbols ();
  87. }
  88. /* See buildsym.h. */
  89. struct pending **
  90. get_file_symbols ()
  91. {
  92. gdb_assert (buildsym_compunit != nullptr);
  93. return buildsym_compunit->get_file_symbols ();
  94. }
  95. /* See buildsym.h. */
  96. struct pending **
  97. get_global_symbols ()
  98. {
  99. gdb_assert (buildsym_compunit != nullptr);
  100. return buildsym_compunit->get_global_symbols ();
  101. }
  102. void
  103. start_subfile (const char *name)
  104. {
  105. gdb_assert (buildsym_compunit != nullptr);
  106. buildsym_compunit->start_subfile (name);
  107. }
  108. void
  109. patch_subfile_names (struct subfile *subfile, const char *name)
  110. {
  111. gdb_assert (buildsym_compunit != nullptr);
  112. buildsym_compunit->patch_subfile_names (subfile, name);
  113. }
  114. void
  115. push_subfile ()
  116. {
  117. gdb_assert (buildsym_compunit != nullptr);
  118. buildsym_compunit->push_subfile ();
  119. }
  120. const char *
  121. pop_subfile ()
  122. {
  123. gdb_assert (buildsym_compunit != nullptr);
  124. return buildsym_compunit->pop_subfile ();
  125. }
  126. /* Delete the buildsym compunit. */
  127. static void
  128. free_buildsym_compunit (void)
  129. {
  130. if (buildsym_compunit == NULL)
  131. return;
  132. delete buildsym_compunit;
  133. buildsym_compunit = NULL;
  134. }
  135. struct compunit_symtab *
  136. end_compunit_symtab (CORE_ADDR end_addr, int section)
  137. {
  138. gdb_assert (buildsym_compunit != nullptr);
  139. struct compunit_symtab *result
  140. = buildsym_compunit->end_compunit_symtab (end_addr, section);
  141. free_buildsym_compunit ();
  142. return result;
  143. }
  144. struct context_stack *
  145. push_context (int desc, CORE_ADDR valu)
  146. {
  147. gdb_assert (buildsym_compunit != nullptr);
  148. return buildsym_compunit->push_context (desc, valu);
  149. }
  150. struct context_stack
  151. pop_context ()
  152. {
  153. gdb_assert (buildsym_compunit != nullptr);
  154. return buildsym_compunit->pop_context ();
  155. }
  156. struct block *
  157. finish_block (struct symbol *symbol, struct pending_block *old_blocks,
  158. const struct dynamic_prop *static_link,
  159. CORE_ADDR start, CORE_ADDR end)
  160. {
  161. gdb_assert (buildsym_compunit != nullptr);
  162. return buildsym_compunit->finish_block (symbol, old_blocks, static_link,
  163. start, end);
  164. }
  165. void
  166. record_line (struct subfile *subfile, int line, CORE_ADDR pc)
  167. {
  168. gdb_assert (buildsym_compunit != nullptr);
  169. /* Assume every line entry is a statement start, that is a good place to
  170. put a breakpoint for that line number. */
  171. buildsym_compunit->record_line (subfile, line, pc, LEF_IS_STMT);
  172. }
  173. /* Start a new compunit_symtab for a new source file in OBJFILE. Called, for
  174. example, when a stabs symbol of type N_SO is seen, or when a DWARF
  175. DW_TAG_compile_unit DIE is seen. It indicates the start of data for one
  176. original source file.
  177. NAME is the name of the file (cannot be NULL). COMP_DIR is the
  178. directory in which the file was compiled (or NULL if not known).
  179. START_ADDR is the lowest address of objects in the file (or 0 if
  180. not known). LANGUAGE is the language of the source file, or
  181. language_unknown if not known, in which case it'll be deduced from
  182. the filename. */
  183. struct compunit_symtab *
  184. start_compunit_symtab (struct objfile *objfile, const char *name,
  185. const char *comp_dir, CORE_ADDR start_addr,
  186. enum language language)
  187. {
  188. /* These should have been reset either by successful completion of building
  189. a symtab, or by the scoped_free_pendings destructor. */
  190. gdb_assert (buildsym_compunit == nullptr);
  191. buildsym_compunit = new struct buildsym_compunit (objfile, name, comp_dir,
  192. language, start_addr);
  193. return buildsym_compunit->get_compunit_symtab ();
  194. }
  195. /* At end of reading syms, or in case of quit, ensure everything
  196. associated with building symtabs is freed.
  197. N.B. This is *not* intended to be used when building psymtabs. Some debug
  198. info readers call this anyway, which is harmless if confusing. */
  199. scoped_free_pendings::~scoped_free_pendings ()
  200. {
  201. free_buildsym_compunit ();
  202. }
  203. /* See buildsym-legacy.h. */
  204. struct buildsym_compunit *
  205. get_buildsym_compunit ()
  206. {
  207. gdb_assert (buildsym_compunit != nullptr);
  208. return buildsym_compunit;
  209. }