stab.c 6.0 KB

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