stab.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*
  2. * (c) copyright 1990 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. *
  5. * Author: Ceriel J.H. Jacobs
  6. */
  7. /* D E B U G G E R S Y M B O L T A B L E */
  8. /* $Id$ */
  9. #include "dbsymtab.h"
  10. #ifdef DBSYMTAB
  11. #include <alloc.h>
  12. #include <em_arith.h>
  13. #include <em_label.h>
  14. #include <em_code.h>
  15. #include <flt_arith.h>
  16. #include <stb.h>
  17. #include "LLlex.h"
  18. #include "stack.h"
  19. #include "def.h"
  20. #include "type.h"
  21. #include "struct.h"
  22. #include "field.h"
  23. #include "idf.h"
  24. #include "Lpars.h"
  25. #include "level.h"
  26. extern long full_mask[];
  27. extern char *sprint();
  28. #define INCR_SIZE 64
  29. static struct db_str {
  30. unsigned sz;
  31. char *base;
  32. char *currpos;
  33. } db_str;
  34. static void create_db_str()
  35. {
  36. if (! db_str.base) {
  37. db_str.base = Malloc(INCR_SIZE);
  38. db_str.sz = INCR_SIZE;
  39. }
  40. db_str.currpos = db_str.base;
  41. }
  42. static void addc_db_str(int c)
  43. {
  44. int df = db_str.currpos - db_str.base;
  45. if (df >= db_str.sz-1) {
  46. db_str.sz += INCR_SIZE;
  47. db_str.base = Realloc(db_str.base, db_str.sz);
  48. db_str.currpos = db_str.base + df;
  49. }
  50. *db_str.currpos++ = c;
  51. *db_str.currpos = '\0';
  52. }
  53. static void adds_db_str(char *s)
  54. {
  55. while (*s) addc_db_str(*s++);
  56. }
  57. static void stb_type(struct type *tp)
  58. {
  59. char buf[128];
  60. static int stb_count;
  61. long l;
  62. if (tp->tp_dbindex > 0) {
  63. adds_db_str(sprint(buf, "%d", tp->tp_dbindex));
  64. return;
  65. }
  66. if (tp->tp_dbindex < 0 && tp->tp_size < 0) {
  67. adds_db_str(sprint(buf, "%d", -tp->tp_dbindex));
  68. return;
  69. }
  70. if (tp->tp_dbindex <= 0) {
  71. tp->tp_dbindex = ++stb_count;
  72. }
  73. adds_db_str(sprint(buf, "%d=", tp->tp_dbindex));
  74. switch(tp->tp_fund) {
  75. /* simple types ... */
  76. case VOID:
  77. adds_db_str(sprint(buf, "%d", void_type->tp_dbindex));
  78. break;
  79. case INT:
  80. case LONG:
  81. case CHAR:
  82. case SHORT:
  83. l = full_mask[(int)tp->tp_size];
  84. if (tp->tp_unsigned) {
  85. adds_db_str(sprint(buf,
  86. "r%d;0;%ld",
  87. tp->tp_dbindex,
  88. l));
  89. }
  90. else {
  91. l &= ~ (1L << ((int)tp->tp_size * 8 - 1));
  92. adds_db_str(sprint(buf,
  93. "r%d;%ld;%ld",
  94. tp->tp_dbindex,
  95. -l-1,
  96. l));
  97. }
  98. break;
  99. case FLOAT:
  100. case DOUBLE:
  101. case LNGDBL:
  102. adds_db_str(sprint(buf,
  103. "r%d;%ld;0",
  104. tp->tp_dbindex,
  105. (long)tp->tp_size));
  106. break;
  107. /* constructed types ... */
  108. case POINTER:
  109. addc_db_str('*');
  110. stb_type(tp->tp_up);
  111. break;
  112. case ARRAY:
  113. if (tp->tp_size > 0) {
  114. adds_db_str("ar");
  115. stb_type(int_type);
  116. adds_db_str(sprint(buf, ";0;%ld;", tp->tp_size / tp->tp_up->tp_size - 1));
  117. stb_type(tp->tp_up);
  118. }
  119. break;
  120. case ENUM:
  121. if (tp->tp_size < 0) {
  122. adds_db_str(sprint(buf,
  123. "xe%s:",
  124. tp->tp_idf->id_text));
  125. tp->tp_dbindex = -tp->tp_dbindex;
  126. break;
  127. }
  128. addc_db_str('e');
  129. {
  130. struct stack_entry *se = local_level->sl_entry;
  131. while (se) {
  132. struct def *edef = se->se_idf->id_def;
  133. while (edef) {
  134. if (edef->df_type == tp &&
  135. edef->df_sc == ENUM) {
  136. adds_db_str(sprint(buf,
  137. "%s:%ld,",
  138. se->se_idf->id_text,
  139. edef->df_address));
  140. }
  141. edef = edef->next;
  142. }
  143. se = se->next;
  144. }
  145. }
  146. addc_db_str(';');
  147. break;
  148. case STRUCT:
  149. case UNION:
  150. if (tp->tp_size < 0) {
  151. adds_db_str(sprint(buf,
  152. "x%c%s:",
  153. tp->tp_fund == STRUCT ? 's' : 'u',
  154. tp->tp_idf->id_text));
  155. tp->tp_dbindex = -tp->tp_dbindex;
  156. break;
  157. }
  158. adds_db_str(sprint(buf,
  159. "%c%ld",
  160. tp->tp_fund == STRUCT ? 's' : 'u',
  161. tp->tp_size));
  162. {
  163. struct sdef *sdef = tp->tp_sdef;
  164. while (sdef) {
  165. adds_db_str(sdef->sd_idf->id_text);
  166. addc_db_str(':');
  167. if (sdef->sd_type->tp_fund == FIELD) {
  168. stb_type(sdef->sd_type->tp_up);
  169. adds_db_str(sprint(buf,
  170. ",%ld,%ld;",
  171. sdef->sd_offset*8+sdef->sd_type->tp_field->fd_shift,
  172. sdef->sd_type->tp_field->fd_width));
  173. }
  174. else {
  175. stb_type(sdef->sd_type);
  176. adds_db_str(sprint(buf,
  177. ",%ld,%ld;",
  178. sdef->sd_offset*8,
  179. sdef->sd_type->tp_size*8));
  180. }
  181. sdef = sdef->sd_sdef;
  182. }
  183. }
  184. addc_db_str(';');
  185. break;
  186. case FUNCTION:
  187. addc_db_str('f');
  188. stb_type(tp->tp_up);
  189. }
  190. }
  191. void stb_tag(struct tag *tg, char *str)
  192. {
  193. create_db_str();
  194. adds_db_str(str);
  195. adds_db_str(":T");
  196. stb_type(tg->tg_type);
  197. addc_db_str(';');
  198. C_ms_stb_cst(db_str.base,
  199. N_LSYM,
  200. tg->tg_type == void_type || tg->tg_type->tp_size >= 32767
  201. ? 0
  202. : (int)tg->tg_type->tp_size,
  203. (arith) 0);
  204. }
  205. void stb_typedef(struct type *tp, char *str)
  206. {
  207. create_db_str();
  208. adds_db_str(str);
  209. adds_db_str(":t");
  210. stb_type(tp);
  211. addc_db_str(';');
  212. C_ms_stb_cst(db_str.base,
  213. N_LSYM,
  214. tp == void_type || tp->tp_size >= 32767
  215. ? 0
  216. : (int)tp->tp_size,
  217. (arith) 0);
  218. }
  219. void stb_string(struct def *df, int kind, char *str)
  220. {
  221. struct type *tp = df->df_type;
  222. create_db_str();
  223. adds_db_str(str);
  224. addc_db_str(':');
  225. switch(kind) {
  226. case FUNCTION:
  227. addc_db_str(df->df_sc == STATIC ? 'f' : 'F');
  228. stb_type(tp->tp_up);
  229. addc_db_str(';');
  230. C_ms_stb_pnam(db_str.base, N_FUN, 1 /* proclevel */, str);
  231. break;
  232. default:
  233. if (df->df_sc == FORMAL ||
  234. (df->df_sc == REGISTER && df->df_address >= 0)) {
  235. /* value parameter */
  236. addc_db_str('p');
  237. stb_type(tp);
  238. addc_db_str(';');
  239. C_ms_stb_cst(db_str.base, N_PSYM, 0, df->df_address);
  240. }
  241. else if (df->df_sc != AUTO && df->df_sc != REGISTER) {
  242. /* global */
  243. int stabtp = df->df_initialized ? N_STSYM : N_LCSYM;
  244. if (df->df_sc == STATIC) {
  245. if (df->df_level >= L_LOCAL) {
  246. addc_db_str('V');
  247. }
  248. else {
  249. addc_db_str('S');
  250. }
  251. }
  252. else {
  253. addc_db_str('G');
  254. }
  255. stb_type(tp);
  256. addc_db_str(';');
  257. if (df->df_sc == STATIC && df->df_level >= L_LOCAL) {
  258. C_ms_stb_dlb(db_str.base, stabtp, 0, (label) df->df_address, (arith) 0);
  259. }
  260. else {
  261. C_ms_stb_dnam(db_str.base, stabtp, 0, str, (arith) 0);
  262. }
  263. }
  264. else { /* local variable */
  265. stb_type(tp); /* assign type num to avoid
  266. difficult to parse string */
  267. addc_db_str(';');
  268. C_ms_stb_cst(db_str.base, N_LSYM, 0, df->df_address);
  269. }
  270. break;
  271. }
  272. }
  273. #endif /* DBSYMTAB */