gdb-symbols.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* gdb_symbols.c - Deal with symbols for GDB format
  2. Copyright (C) 1987 Free Software Foundation, Inc.
  3. This file is part of GAS, the GNU Assembler.
  4. GAS 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 1, or (at your option)
  7. any later version.
  8. GAS 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 GAS; see the file COPYING. If not, write to
  14. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  15. /*
  16. * During assembly, note requests to place symbol values in the GDB
  17. * symbol file. When symbol values are known and the symbol file is
  18. * in memory, place the symbol values in the memory image of the file.
  19. *
  20. * This has static data: it is not data_sharable.
  21. *
  22. * gdb_symbols_begin ()
  23. * Call once before using this package.
  24. *
  25. * gdb_symbols_fixup (symbolP, offset_in_file)
  26. * Remember to put the value of a symbol into the GDB file.
  27. *
  28. * gdb_symbols_emit ()
  29. * Perform all the symbol fixups.
  30. *
  31. * uses:
  32. * xmalloc()
  33. * gdb_alter()
  34. */
  35. #include "as.h"
  36. #include "struc-symbol.h"
  37. #define SYM_GROUP (100) /* We allocate storage in lumps this big. */
  38. struct gdb_symbol /* 1 fixup request. */
  39. {
  40. symbolS * gs_symbol;
  41. long int gs_offset; /* Where in GDB symbol file. */
  42. };
  43. typedef struct gdb_symbol gdb_symbolS;
  44. struct symbol_fixup_group
  45. {
  46. struct symbol_fixup_group * sfg_next;
  47. gdb_symbolS sfg_item [SYM_GROUP];
  48. };
  49. typedef struct symbol_fixup_group symbol_fixup_groupS;
  50. static symbol_fixup_groupS * root;
  51. static short int used; /* # of last slot used. */
  52. /* Counts down from SYM_GROUP. */
  53. static symbol_fixup_groupS * /* Make storage for some more reminders. */
  54. new_sfg ()
  55. {
  56. symbol_fixup_groupS * newP;
  57. char * xmalloc();
  58. newP = (symbol_fixup_groupS *) xmalloc ((long)sizeof(symbol_fixup_groupS));
  59. newP -> sfg_next = root;
  60. used = SYM_GROUP;
  61. root = newP;
  62. return (newP);
  63. }
  64. void
  65. gdb_symbols_begin ()
  66. {
  67. root = 0;
  68. (void)new_sfg ();
  69. }
  70. void /* Build a reminder to put a symbol value */
  71. gdb_symbols_fixup (sy, offset) /* into the GDB symbol file. */
  72. symbolS * sy; /* Which symbol. */
  73. long int offset; /* Where in GDB symbol file. */
  74. {
  75. register symbol_fixup_groupS * p;
  76. register gdb_symbolS * q;
  77. p = root;
  78. know( used >= 0 );
  79. if ( used == 0)
  80. {
  81. p = new_sfg ();
  82. }
  83. q = p -> sfg_item + -- used;
  84. q -> gs_symbol = sy;
  85. q -> gs_offset = offset;
  86. }
  87. void
  88. gdb_symbols_emit () /* Append GDB symbols to object file. */
  89. {
  90. symbol_fixup_groupS * sfgP;
  91. void gdb_alter();
  92. for (sfgP = root; sfgP; sfgP = sfgP -> sfg_next)
  93. {
  94. register gdb_symbolS * gsP;
  95. register gdb_symbolS * limit;
  96. limit = sfgP -> sfg_item +
  97. (sfgP -> sfg_next ? 0 : used);
  98. for (gsP = sfgP -> sfg_item + SYM_GROUP - 1;
  99. gsP >= limit;
  100. gsP --)
  101. {
  102. gdb_alter (gsP -> gs_offset,
  103. (long int) gsP -> gs_symbol -> sy_value);
  104. }
  105. }
  106. }
  107. /* end: gdb_symbols.c */