stab.c 5.7 KB

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