stab.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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
  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)
  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 && tp->tp_size < 0) {
  74. adds_db_str(sprint(buf, "%d", -tp->tp_dbindex));
  75. return;
  76. }
  77. if (tp->tp_dbindex <= 0) {
  78. tp->tp_dbindex = ++stb_count;
  79. }
  80. adds_db_str(sprint(buf, "%d=", tp->tp_dbindex));
  81. switch(tp->tp_fund) {
  82. /* simple types ... */
  83. case VOID:
  84. adds_db_str(sprint(buf, "%d", void_type->tp_dbindex));
  85. break;
  86. case INT:
  87. case LONG:
  88. case CHAR:
  89. case SHORT:
  90. l = full_mask[(int)tp->tp_size];
  91. if (tp->tp_unsigned) {
  92. adds_db_str(sprint(buf,
  93. "r%d;0;%ld",
  94. tp->tp_dbindex,
  95. l));
  96. }
  97. else {
  98. l &= ~ (1L << ((int)tp->tp_size * 8 - 1));
  99. adds_db_str(sprint(buf,
  100. "r%d;%ld;%ld",
  101. tp->tp_dbindex,
  102. -l-1,
  103. l));
  104. }
  105. break;
  106. case FLOAT:
  107. case DOUBLE:
  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);
  117. break;
  118. case ARRAY:
  119. if (tp->tp_size > 0) {
  120. adds_db_str("ar");
  121. stb_type(int_type);
  122. adds_db_str(sprint(buf, ";0;%ld;", tp->tp_size / tp->tp_up->tp_size - 1));
  123. stb_type(tp->tp_up);
  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. tp->tp_dbindex = -tp->tp_dbindex;
  132. break;
  133. }
  134. addc_db_str('e');
  135. {
  136. register struct stack_entry *se = local_level->sl_entry;
  137. while (se) {
  138. register struct def *edef = se->se_idf->id_def;
  139. while (edef) {
  140. if (edef->df_type == tp &&
  141. edef->df_sc == ENUM) {
  142. adds_db_str(sprint(buf,
  143. "%s:%ld,",
  144. se->se_idf->id_text,
  145. edef->df_address));
  146. }
  147. edef = edef->next;
  148. }
  149. se = se->next;
  150. }
  151. }
  152. addc_db_str(';');
  153. break;
  154. case STRUCT:
  155. case UNION:
  156. if (tp->tp_size < 0) {
  157. adds_db_str(sprint(buf,
  158. "x%c%s:",
  159. tp->tp_fund == STRUCT ? 's' : 'u',
  160. tp->tp_idf->id_text));
  161. tp->tp_dbindex = -tp->tp_dbindex;
  162. break;
  163. }
  164. adds_db_str(sprint(buf,
  165. "%c%ld",
  166. tp->tp_fund == STRUCT ? 's' : 'u',
  167. tp->tp_size));
  168. {
  169. register struct sdef *sdef = tp->tp_sdef;
  170. while (sdef) {
  171. adds_db_str(sdef->sd_idf->id_text);
  172. addc_db_str(':');
  173. if (sdef->sd_type->tp_fund == FIELD) {
  174. stb_type(sdef->sd_type->tp_up);
  175. adds_db_str(sprint(buf,
  176. ",%ld,%ld;",
  177. sdef->sd_offset*8+sdef->sd_type->tp_field->fd_shift,
  178. sdef->sd_type->tp_field->fd_width));
  179. }
  180. else {
  181. stb_type(sdef->sd_type);
  182. adds_db_str(sprint(buf,
  183. ",%ld,%ld;",
  184. sdef->sd_offset*8,
  185. sdef->sd_type->tp_size*8));
  186. }
  187. sdef = sdef->sd_sdef;
  188. }
  189. }
  190. addc_db_str(';');
  191. break;
  192. case FUNCTION:
  193. addc_db_str('f');
  194. stb_type(tp->tp_up);
  195. }
  196. }
  197. stb_tag(tg, str)
  198. register struct tag *tg;
  199. char *str;
  200. {
  201. create_db_str();
  202. adds_db_str(str);
  203. adds_db_str(":T");
  204. stb_type(tg->tg_type);
  205. addc_db_str(';');
  206. C_ms_stb_cst(db_str.base,
  207. N_LSYM,
  208. tg->tg_type == void_type || tg->tg_type->tp_size >= 32767
  209. ? 0
  210. : (int)tg->tg_type->tp_size,
  211. (arith) 0);
  212. }
  213. stb_typedef(tp, str)
  214. register struct type *tp;
  215. char *str;
  216. {
  217. create_db_str();
  218. adds_db_str(str);
  219. adds_db_str(":t");
  220. stb_type(tp);
  221. addc_db_str(';');
  222. C_ms_stb_cst(db_str.base,
  223. N_LSYM,
  224. tp == void_type || tp->tp_size >= 32767
  225. ? 0
  226. : (int)tp->tp_size,
  227. (arith) 0);
  228. }
  229. stb_string(df, kind, str)
  230. register struct def *df;
  231. char *str;
  232. {
  233. register struct type *tp = df->df_type;
  234. create_db_str();
  235. adds_db_str(str);
  236. addc_db_str(':');
  237. switch(kind) {
  238. case FUNCTION:
  239. addc_db_str(df->df_sc == STATIC ? 'f' : 'F');
  240. stb_type(tp->tp_up);
  241. addc_db_str(';');
  242. C_ms_stb_pnam(db_str.base, N_FUN, 1 /* proclevel */, str);
  243. break;
  244. default:
  245. if (df->df_sc == FORMAL ||
  246. (df->df_sc == REGISTER && df->df_address >= 0)) {
  247. /* value parameter */
  248. addc_db_str('p');
  249. stb_type(tp);
  250. addc_db_str(';');
  251. C_ms_stb_cst(db_str.base, N_PSYM, 0, df->df_address);
  252. }
  253. else if (df->df_sc != AUTO && df->df_sc != REGISTER) {
  254. /* global */
  255. int stabtp = df->df_initialized ? N_STSYM : N_LCSYM;
  256. if (df->df_sc == STATIC) {
  257. if (df->df_level >= L_LOCAL) {
  258. addc_db_str('V');
  259. }
  260. else {
  261. addc_db_str('S');
  262. }
  263. }
  264. else {
  265. addc_db_str('G');
  266. }
  267. stb_type(tp);
  268. addc_db_str(';');
  269. if (df->df_sc == STATIC && df->df_level >= L_LOCAL) {
  270. C_ms_stb_dlb(db_str.base, stabtp, 0, (label) df->df_address, (arith) 0);
  271. }
  272. else {
  273. C_ms_stb_dnam(db_str.base, stabtp, 0, str, (arith) 0);
  274. }
  275. }
  276. else { /* local variable */
  277. stb_type(tp); /* assign type num to avoid
  278. difficult to parse string */
  279. addc_db_str(';');
  280. C_ms_stb_cst(db_str.base, N_LSYM, 0, df->df_address);
  281. }
  282. break;
  283. }
  284. }
  285. #endif /* DBSYMTAB */