warning fix
[libfirm] / ir / be / bestabs.c
1 /**
2  * Stabs support.
3  *
4  * @author Michael Beck
5  * @date   11.9.2006
6  * @cvsid  $Id$
7  */
8
9 #ifdef HAVE_CONFIG_H
10 # include "config.h"
11 #endif
12
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <assert.h>
16
17 #include "irprog.h"
18 #include "entity.h"
19 #include "irgraph.h"
20 #include "typewalk.h"
21 #include "tv.h"
22 #include "xmalloc.h"
23 #include "pmap.h"
24 #include "pdeq.h"
25 #include "irtools.h"
26 #include "obst.h"
27 #include "array.h"
28 #include "be_dbgout.h"
29 #include "beabi.h"
30
31 /* Non-Stab Symbol and Stab Symbol Types */
32 enum stabs_types {
33         N_UNDF    = 0x00,    /**< 0: Undefined symbol */
34         N_ABS     = 0x02,    /**< 2: File scope absolute symbol */
35         N_TEXT    = 0x04,    /**< 4: File scope text symbol */
36         N_DATA    = 0x06,    /**< 6: File scope data symbol */
37         N_BSS     = 0x08,    /**< 8: File scope BSS symbol */
38         N_INDR    = 0x0A,    /**< 10: Symbol is indirected to another symbol */
39         N_FN_SEQ  = 0x0C,    /**< 12: Same as N_FN, for Sequent compilers */
40         N_COMM    = 0x12,    /**< 18: Common--visible after shared library dynamic link */
41         N_SETA    = 0x14,    /**< 20: Absolute set element */
42         N_SETT    = 0x17,    /**< 23: Text segment set element */
43         N_SETD    = 0x18,    /**< 24: Data segment set element */
44         N_SETB    = 0x1A,    /**< 26: BSS segment set element */
45         N_SETV    = 0x1C,    /**< 28: Pointer to set vector */
46         N_WARNING = 0x1E,    /**< 30: Print a warning message during linking */
47         N_FN      = 0x1F,    /**< 31: File name of a `.o' file */
48         N_GSYM    = 0x20,    /**< 32: Global symbol */
49         N_FNAME   = 0x22,    /**< 34: Function name (for BSD Fortran) */
50         N_FUN     = 0x24,    /**< 36: Function name */
51         N_STSYM   = 0x26,    /**< 38: Data segment file-scope variable */
52         N_LCSYM   = 0x28,    /**< 40: BSS segment file-scope variable */
53         N_MAIN    = 0x2A,    /**< 42: Name of main routine */
54         N_ROSYM   = 0x2C,    /**< 44: Variable in .rodata section */
55         N_PC      = 0x30,    /**< 48: Global symbol (for Pascal) */
56         N_NSYMS   = 0x32,    /**< 50: Number of symbols (according to Ultrix V4.0) */
57         N_NOMAP   = 0x34,    /**< 52: No DST map */
58         N_OBJ     = 0x38,    /**< 56: Object file (Solaris2) */
59         N_OPT     = 0x3C,    /**< 60: Debugger options (Solaris2) */
60         N_RSYM    = 0x40,    /**< 64: Register variable */
61         N_M2C     = 0x42,    /**< 66: Modula-2 compilation unit */
62         N_SLINE   = 0x44,    /**< 68: Line number in text segment */
63         N_DSLINE  = 0x46,    /**< 70: Line number in data segment */
64         N_BSLINE  = 0x48,    /**< 72: Line number in bss segment */
65         N_BROWS   = 0x48,    /**< 72: Sun source code browser, path to `.cb' file */
66         N_DEFD    = 0x4A,    /**< 74: GNU Modula2 definition module dependency */
67         N_FLINE   = 0x4C,    /**< 76: Function start/body/end line numbers (Solaris2) */
68         N_EHDECL  = 0x50,    /**< 80: GNU C++ exception variable */
69         N_MOD2    = 0x50,    /**< 80: Modula2 info "for imc" (according to Ultrix V4.0) */
70         N_CATCH   = 0x54,    /**< 84: GNU C++ catch clause */
71         N_SSYM    = 0x60,    /**< 96: Structure of union element */
72         N_ENDM    = 0x62,    /**< 98: Last stab for module (Solaris2) */
73         N_SO      = 0x64,    /**< 100: Path and name of source file */
74         N_LSYM    = 0x80,    /**< 128: Stack variable */
75         N_BINCL   = 0x82,    /**< 130: Beginning of an include file (Sun only) */
76         N_SOL     = 0x84,    /**< 132: Name of include file */
77         N_PSYM    = 0xA0,    /**< 160: Parameter variable */
78         N_EINCL   = 0xA2,    /**< 162: End of an include file */
79         N_ENTRY   = 0xA4,    /**< 164: Alternate entry point */
80         N_LBRAC   = 0xC0,    /**< 192: Beginning of a lexical block */
81         N_EXCL    = 0xC2,    /**< 194: Place holder for a deleted include file */
82         N_SCOPE   = 0xC4,    /**< 196: Modula2 scope information (Sun linker) */
83         N_RBRAC   = 0xE0,    /**< 224: End of a lexical block */
84         N_BCOMM   = 0xE2,    /**< 226: Begin named common block */
85         N_ECOMM   = 0xE4,    /**< 228: End named common block */
86         N_ECOML   = 0xE8,    /**< 232: Member of a common block */
87         N_WITH    = 0xEA,    /**< 234: Pascal with statement: type,,0,0,offset (Solaris2) */
88         N_NBTEXT  = 0xF0,    /**< 240: Gould non-base registers */
89         N_NBDATA  = 0xF2,    /**< 242: Gould non-base registers */
90         N_NBBSS   = 0xF4,    /**< 244: Gould non-base registers */
91         N_NBSTS   = 0xF6,    /**< 246: Gould non-base registers */
92         N_NBLCS   = 0xF8,    /**< 248: Gould non-base registers */
93 };
94
95 /**
96  * The stabs handle.
97  */
98 typedef struct stabs_handle {
99         dbg_handle base;         /**< the base class */
100         FILE       *f;           /**< the file write to */
101         entity     *cur_ent;     /**< current method entity */
102         unsigned   next_type_nr; /**< next type number */
103         pmap       *type_map;    /**< a map from type to type number */
104 } stabs_handle;
105
106 /**
107  * Returns the stabs type number of a Firm type.
108  */
109 static unsigned get_type_number(stabs_handle *h, ir_type *tp) {
110         pmap_entry *entry;
111
112         if (tp == NULL) {
113                 /* map to the void type */
114                 return 0;
115         }
116         entry = pmap_find(h->type_map, tp);
117         return entry ? PTR_TO_INT(entry->value) : 0;
118 }  /* get_type_number */
119
120 /**
121  * Assign a stabs type number to a Firm type.
122  */
123 static unsigned assign_type_number(stabs_handle *h, ir_type *tp) {
124         unsigned num;
125         if (tp == NULL) {
126                 /* map to the void type */
127                 return 0;
128         }
129         num = h->next_type_nr++;
130         pmap_insert(h->type_map, tp, INT_TO_PTR(num));
131         return num;
132 }  /* assign_type_number */
133
134 /**
135  * generate the void type.
136  */
137 static void gen_void_type(stabs_handle *h) {
138         fprintf(h->f, "\t.stabs \"void:t%u=%u\",%d,0,0,0\n", 0, 0, N_LSYM);
139 }  /* gen_void_type */
140
141 typedef struct walker_env {
142         stabs_handle *h;
143         waitq        *wq;
144 } wenv_t;
145
146 /* a type is not ready: put it on the wait queue */
147 #define SET_TYPE_NOT_READY(wq, tp) \
148   do { \
149     set_type_link(tp, (void *)1);  \
150     waitq_put(wq, tp);              \
151   } while(0)
152
153 /* a the is ready */
154 #define SET_TYPE_READY(tp)     set_type_link(tp, NULL)
155
156 /* check whether a type is ready */
157 #define IS_TYPE_READY(tp)      (get_type_link(tp) == NULL)
158
159 #ifdef EXPLICITE_PTR_TYPES
160 #define SKIP_PTR(tp)  tp
161 #else
162 #define SKIP_PTR(tp)   (is_Pointer_type(tp) ? get_pointer_points_to_type(tp) : tp)
163 #endif
164
165 /**
166  * Generates a primitive type.
167  *
168  * @param h    the stabs handle
169  * @param tp   the type
170  */
171 static void gen_primitive_type(stabs_handle *h, ir_type *tp)
172 {
173         ir_mode *mode = get_type_mode(tp);
174         unsigned type_num;
175
176         if (mode == mode_T) {
177     /* jack and FirmJC compiler use mode_T for the void type.
178                 Ignore it here as it's name is remapped to "void". */
179                 return;
180         }  /* if */
181
182         if (0 && get_mode_size_bits(mode) & 7) {
183                 /* this is a bitfield type, ignore it */
184                 return;
185         }  /* if */
186
187         type_num = assign_type_number(h, tp);
188
189         if (mode_is_int(mode)) {
190                 char buf[64];
191                 fprintf(h->f, "\t.stabs \"%s:t%u=r%u;", get_type_name(tp), type_num, type_num);
192                 tarval_snprintf(buf, sizeof(buf), get_mode_min(mode));
193                 fprintf(h->f, "%s;", buf);
194                 tarval_snprintf(buf, sizeof(buf), get_mode_max(mode));
195                 fprintf(h->f, "%s;\",%d,0,0,0\n", buf, N_LSYM);
196         } else if (mode_is_float(mode)) {
197                 int size = get_type_size_bytes(tp);
198                 fprintf(h->f, "\t.stabs \"%s:t%u=r1;%d;0;\",%d,0,0,0\n", get_type_name(tp), type_num, size, N_LSYM);
199         }
200 }  /* gen_primitive_type */
201
202 /**
203  * Generates an enum type
204  *
205  * @param h    the stabs handle
206  * @param tp   the type
207  */
208 static void gen_enum_type(stabs_handle *h, ir_type *tp) {
209         unsigned type_num = assign_type_number(h, tp);
210         int i, n;
211
212         fprintf(h->f, "\t.stabs \"%s:T%u=e", get_type_name(tp), type_num);
213         for (i = 0, n = get_enumeration_n_enums(tp); i < n; ++i) {
214                 ir_enum_const *ec = get_enumeration_const(tp, i);
215                 char buf[64];
216
217                 tarval_snprintf(buf, sizeof(buf), get_enumeration_value(ec));
218                 fprintf(h->f, "%s:%s,", get_enumeration_name(ec), buf);
219         }
220         fprintf(h->f, ";\",%d,0,0,0\n", N_LSYM);
221 }  /* gen_enum_type */
222
223 /**
224  * Generates a pointer type
225  *
226  * @param h    the stabs handle
227  * @param tp   the type
228  */
229 static void gen_pointer_type(stabs_handle *h, ir_type *tp) {
230         unsigned type_num = assign_type_number(h, tp);
231         unsigned el_num   = get_type_number(h, get_pointer_points_to_type(tp));
232
233         fprintf(h->f, "\t.stabs \"%s:t%u=*%u\",%d,0,0,0\n",
234                 get_type_name(tp), type_num, el_num, N_LSYM);
235 }  /* gen_pointer_type */
236
237 /**
238  * Generates a struct/union type
239  *
240  * @param h    the stabs handle
241  * @param tp   the type
242  */
243 static void gen_struct_union_type(stabs_handle *h, ir_type *tp) {
244         unsigned type_num = assign_type_number(h, tp);
245         int i, n;
246         char desc;
247
248         if (is_Struct_type(tp)) {
249                 desc = 's';
250                 if (get_type_mode(tp) != NULL) {
251                         /* this is a bitfield type, ignore it safely */
252                         return;
253                 }
254         }
255         else
256                 desc = 'u';
257
258         fprintf(h->f, "\t.stabs \"%s:T%u=%c%d",
259                 get_type_name(tp), type_num, desc, get_type_size_bytes(tp));
260
261         for (i = 0, n = get_compound_n_members(tp); i < n; ++i) {
262                 entity  *ent = get_compound_member(tp, i);
263                 ir_type *mtp = get_entity_type(ent);
264                 int ofs, size;
265
266                 ofs  = get_entity_offset_bits(ent);
267                 if (is_Struct_type(mtp) && get_type_mode(mtp) != NULL) {
268                         /* this structure is a bitfield, skip */
269                         int i, n;
270
271                         for (i = 0, n = get_struct_n_members(mtp); i < n; ++i) {
272                                 entity *ent = get_struct_member(mtp, i);
273                                 ir_type *tp = get_entity_type(ent);
274                                 int bofs;
275
276                                 type_num = get_type_number(h, tp);
277                                 size = get_type_size_bits(tp);
278                                 bofs = ofs + get_entity_offset_bits(ent);
279
280                                 /* name:type, bit offset from the start of the struct', number of bits in the element. */
281                                 fprintf(h->f, "%s:%u,%d,%d;", get_entity_name(ent), type_num, bofs, size);
282                         }
283                 } else {
284                         /* no bitfield */
285                         type_num = get_type_number(h, mtp);
286                         size = get_type_size_bits(mtp);
287
288                         /* name:type, bit offset from the start of the struct', number of bits in the element. */
289                         fprintf(h->f, "%s:%u,%d,%d;", get_entity_name(ent), type_num, ofs, size);
290                 }
291         }
292         fprintf(h->f, ";\",%d,0,0,0\n", N_LSYM);
293 }  /* gen_struct_type */
294
295 /**
296  * Generates an array type
297  *
298  * @param h    the stabs handle
299  * @param tp   the type
300  */
301 static void gen_array_type(stabs_handle *h, ir_type *tp) {
302         unsigned type_num = assign_type_number(h, tp);
303         int i, n = get_array_n_dimensions(tp);
304         int *perm;
305         ir_type *etp;
306
307         NEW_ARR_A(int, perm, n);
308         for (i = 0; i < n; ++i) {
309                 perm[i] = get_array_order(tp, i);
310         }
311         fprintf(h->f, "\t.stabs \"%s:t%u=a", get_type_name(tp), type_num);
312
313         for (i = 0; i < n; ++i) {
314                 int dim = perm[i];
315                 long min = get_array_lower_bound_int(tp, dim);
316                 long max = get_array_upper_bound_int(tp, dim);
317
318                 /* FIXME r1 must be integer type, but seems to work for now */
319                 fprintf(h->f, "r1;%ld;%ld;", min, max-1);
320         }
321
322         etp = get_array_element_type(tp);
323         type_num = get_type_number(h, etp);
324         fprintf(h->f, "%d\",%d,0,0,0\n", type_num, N_LSYM);
325 }  /* gen_array_type */
326
327 /**
328  * Generates a method type
329  *
330  * @param h    the stabs handle
331  * @param tp   the type
332  */
333 static void gen_method_type(stabs_handle *h, ir_type *tp) {
334         unsigned type_num = assign_type_number(h, tp);
335         ir_type *rtp = NULL;
336         unsigned res_type_num;
337
338         if (get_method_n_ress(tp) > 0)
339                 rtp = get_method_res_type(tp, 0);
340         res_type_num = get_type_number(h, rtp);
341
342         fprintf(h->f, "\t.stabs \"%s:t%u=f%u\",%d,0,0,0\n",
343                 get_type_name(tp), type_num, res_type_num, N_LSYM);
344 }  /* gen_method_type */
345
346 /**
347  * type-walker: generate declaration for simple types,
348  * put all other types on a wait queue
349  */
350 static void walk_type(type_or_ent *tore, void *ctx)
351 {
352         wenv_t *env = ctx;
353         ir_type  *tp;
354
355         if (get_kind(tore) == k_type) {
356                 tp = (ir_type *)tore;
357
358                 /* ignore the unknown type */
359                 if (tp == firm_unknown_type)
360                         return;
361         } else {
362                 return;
363         }  /* if */
364
365         switch (get_type_tpop_code(tp)) {
366         case tpo_class:
367                 if (tp == get_glob_type()) {
368                         SET_TYPE_READY(tp);
369                         break;
370                 }
371                 /* fall through */
372         case tpo_struct:
373         case tpo_union:
374                 SET_TYPE_NOT_READY(env->wq, tp);
375                 break;
376
377         case tpo_enumeration:
378                 gen_enum_type(env->h, tp);
379                 SET_TYPE_READY(tp);
380                 break;
381
382         case tpo_primitive:
383                 gen_primitive_type(env->h, tp);
384                 SET_TYPE_READY(tp);
385                 break;
386
387         case tpo_method:
388         case tpo_array:
389                 SET_TYPE_NOT_READY(env->wq, tp);
390                 break;
391
392         case tpo_pointer:
393                 /* must construct the pointer type */
394                 SET_TYPE_NOT_READY(env->wq, tp);
395                 break;
396
397         case tpo_unknown:
398                 /* the unknown type: ignore */
399                 break;
400         default:
401                 assert(! "Unknown tpop code");
402         }  /* switch */
403 }  /* walk_type */
404
405 /**
406  * check, if a method type can be generated
407  */
408 static int is_method_type_ready(ir_type *tp)
409 {
410   int i;
411   ir_type *etp;
412
413   for (i = get_method_n_ress(tp) - 1; i >= 0; --i) {
414     etp = SKIP_PTR(get_method_res_type(tp, i));
415
416     if (! IS_TYPE_READY(etp) && (! is_compound_type(etp) || is_Array_type(etp)))
417       return 0;
418   }  /* for */
419
420   for (i = get_method_n_params(tp) - 1; i >= 0; --i) {
421     etp = SKIP_PTR(get_method_param_type(tp, i));
422
423     if (! IS_TYPE_READY(etp) && (! is_compound_type(etp) || is_Array_type(etp)))
424       return 0;
425   }  /* for */
426   return 1;
427 }  /* is_method_type_ready */
428
429 /**
430  * check, whether a compound type can be generated
431  */
432 static int is_compound_type_ready(ir_type *tp)
433 {
434   int i;
435   ir_type *etp;
436
437   for (i = get_compound_n_members(tp) - 1; i >= 0; --i) {
438     etp = SKIP_PTR(get_entity_type(get_compound_member(tp, i)));
439
440     if (! IS_TYPE_READY(etp) && (! is_compound_type(etp) || is_Array_type(etp)))
441       return 0;
442   }  /* for */
443   return 1;
444 }  /* is_compound_type_ready */
445
446 /**
447  * generate declaration for all types
448  */
449 static void finish_types(stabs_handle *h, waitq *wq)
450 {
451   ir_type *tp;
452
453   while (! waitq_empty(wq)) {
454     tp = waitq_get(wq);
455
456     switch (get_type_tpop_code(tp)) {
457     case tpo_method:
458       if (is_method_type_ready(tp)) {
459         if (get_method_n_ress(tp) <= 1)
460           gen_method_type(h, tp);
461         else {
462           fprintf(stderr, "Warning: Cannot create stabs debug info for type %s\n", get_type_name(tp));
463         }  /* if */
464         SET_TYPE_READY(tp);
465         continue;
466       }  /* if */
467       break;
468     case tpo_class:
469     case tpo_union:
470     case tpo_struct:
471       if (is_compound_type_ready(tp)) {
472         gen_struct_union_type(h, tp);
473         SET_TYPE_READY(tp);
474         continue;
475       }  /* if */
476       break;
477     case tpo_array:
478       if (IS_TYPE_READY(get_array_element_type(tp))) {
479         gen_array_type(h, tp);
480         SET_TYPE_READY(tp);
481         continue;
482       }  /* if */
483       break;
484     case tpo_pointer:
485       if (IS_TYPE_READY(get_pointer_points_to_type(tp))) {
486         gen_pointer_type(h, tp);
487         SET_TYPE_READY(tp);
488         continue;
489       }  /* if */
490       break;
491     default:
492       assert(! "Unknown tpop code");
493     }  /* switch */
494
495     /* still not ready, defer type output */
496     pdeq_putr(wq, tp);
497   }  /* while */
498 }  /* finish_types */
499
500 /**
501  * generate all types.
502  */
503 static void gen_types(stabs_handle *h) {
504         wenv_t env;
505
506         env.h  = h;
507         env.wq = new_waitq();
508         type_walk(NULL, walk_type, &env);
509         finish_types(h, env.wq);
510         del_waitq(env.wq);
511 }  /* gen_types */
512
513
514 /* -------------------------- I/F ----------------------------- */
515
516 /**
517  * start a new source object (compilation unit)
518  */
519 static void stabs_so(dbg_handle *handle, const char *filename) {
520         stabs_handle *h = (stabs_handle *)handle;
521         fprintf(h->f, "\t.stabs \"%s\",%d,0,0,.Ltext0\n", filename, N_SO);
522 }  /* stabs_so */
523
524 /**
525  * Main Program
526  */
527 static void stabs_main_program(dbg_handle *handle) {
528         stabs_handle *h = (stabs_handle *)handle;
529         ir_graph *irg = get_irp_main_irg();
530         if (irg) {
531                 fprintf(h->f, "\t.stabs \"%s\",%d,0,0,0\n", get_entity_name(get_irg_entity(irg)), N_MAIN);
532         }
533 }  /* stabs_main_program */
534
535 /**
536  * prints a line number
537  */
538 static void stabs_line(dbg_handle *handle, unsigned lineno, const char *address) {
539         stabs_handle *h = (stabs_handle *)handle;
540         fprintf(h->f, ".stabn %d, 0, %u, %s-%s\n", N_SLINE, lineno, address, get_entity_ld_name(h->cur_ent));
541 }  /* stabs_line */
542
543 /**
544  * dump the stabs for a function
545  */
546 static void stabs_method(dbg_handle *handle, entity *ent, const be_stack_layout_t *layout) {
547         stabs_handle *h = (stabs_handle *)handle;
548         ir_type *mtp, *rtp;
549         unsigned type_num;
550         int i, n, between_size;
551
552         h->cur_ent = ent;
553
554         mtp = get_entity_type(ent);
555         if (is_lowered_type(mtp))
556                 mtp = get_associated_type(mtp);
557         if (get_method_n_ress(mtp) > 0)
558                 rtp = get_method_res_type(mtp, 0);
559         else
560                 rtp = NULL;
561         type_num = get_type_number(h, rtp);
562         fprintf(h->f, "\t.stabs \"%s:%c%u\",%u,0,0,%s\n",
563                 get_entity_name(ent),
564                 get_entity_visibility(ent) == visibility_external_visible ? 'F' : 'f',
565                 type_num,
566                 N_FUN,
567                 get_entity_ld_name(ent));
568
569         between_size = get_type_size_bytes(layout->between_type);
570         for (i = 0, n = get_method_n_params(mtp); i < n; ++i) {
571                 ir_type *ptp      = get_method_param_type(mtp, i);
572         const char *name  = get_method_param_name(mtp, i);
573                 unsigned type_num = get_type_number(h, ptp);
574         char buf[16];
575         int ofs = 0;
576                 entity *stack_ent;
577
578         if (! name) {
579           snprintf(buf, sizeof(buf), "arg%d", i);
580           name = buf;
581         }
582                 /* check if this parameter has a stack entity. If it has, it
583                    it transmitted on the stack, else in a register */
584                 stack_ent = layout->param_map[i];
585                 if (stack_ent) {
586                         ofs = get_entity_offset_bytes(stack_ent) + between_size;
587                 }
588                 fprintf(h->f, "\t.stabs \"%s:p%u\",%d,0,0,%d\n", name, type_num, N_PSYM, ofs);
589         }
590 }  /* stabs_method */
591
592 /**
593  * dump types
594  */
595 static void stabs_types(dbg_handle *handle) {
596         stabs_handle *h = (stabs_handle *)handle;
597
598         /* allocate the zero for the void type */
599         h->next_type_nr++;
600         gen_void_type(h);
601         gen_types(h);
602 }  /* stabs_types */
603
604 /**
605  * dump a global
606  */
607 static void stabs_global(dbg_handle *handle, struct obstack *obst, entity *ent) {
608         stabs_handle *h = (stabs_handle *)handle;
609         unsigned tp_num = get_type_number(h, get_entity_type(ent));
610
611         if (obst) {
612                 obstack_printf(obst, "\t.stabs \"%s:G%u\",%d,0,0,0\n",
613                         get_entity_name(ent), tp_num, N_GSYM);
614         } else {
615                 fprintf(h->f, "\t.stabs \"%s:G%u\",%d,0,0,0\n",
616                         get_entity_name(ent), tp_num, N_GSYM);
617         }
618 }  /* stabs_global */
619
620 /**
621  * Close the stabs handler.
622  */
623 static void stabs_close(dbg_handle *handle) {
624         stabs_handle *h = (stabs_handle *)handle;
625         pmap_destroy(h->type_map);
626         free(h);
627 }  /* stabs_close */
628
629 /** The stabs operations. */
630 static const debug_ops stabs_ops = {
631         stabs_close,
632         stabs_so,
633         stabs_main_program,
634         stabs_method,
635         stabs_line,
636         stabs_types,
637         stabs_global
638 };
639
640 /* Opens a stabs handler */
641 dbg_handle *be_stabs_open(FILE *out) {
642         stabs_handle *h = xmalloc(sizeof(*h));
643
644         h->base.ops     = &stabs_ops;
645         h->f            = out;
646         h->cur_ent      = NULL;
647         h->next_type_nr = 0;
648         h->type_map     = pmap_create_ex(64);
649         return &h->base;
650 }  /* stabs_open */
651
652 /** close a debug handler. */
653 void be_dbg_close(dbg_handle *h) {
654         if (h->ops->close)
655                 h->ops->close(h);
656 }  /* be_dbg_close */
657
658 /**
659  * start a new source object (compilation unit)
660  */
661 void be_dbg_so(dbg_handle *h, const char *filename) {
662         if (h->ops->so)
663                 h->ops->so(h, filename);
664 }  /* be_dbg_begin */
665
666 /**
667  * Main program
668  */
669 void be_dbg_main_program(dbg_handle *h) {
670         if (h->ops->main_program)
671                 h->ops->main_program(h);
672 }  /* be_dbg_main_program */
673
674 /** debug for a function */
675 void be_dbg_method(dbg_handle *h, entity *ent, const be_stack_layout_t *layout) {
676         if (h->ops->method)
677                 h->ops->method(h, ent, layout);
678 }  /* be_dbg_method */
679
680 /** debug for line number */
681 void be_dbg_line(dbg_handle *h, unsigned lineno, const char *address) {
682         if (h->ops->line)
683                 h->ops->line(h, lineno, address);
684 }  /* be_dbg_line */
685
686 /** dump types */
687 void be_dbg_types(dbg_handle *h) {
688         if (h->ops->types)
689                 h->ops->types(h);
690 }  /* be_dbg_types */
691
692 /** dump a global */
693 void be_dbg_global(dbg_handle *h, struct obstack *obst, entity *ent) {
694         if (h->ops->global)
695                 h->ops->global(h, obst, ent);
696 }  /* be_dbg_global */