convenience function to see if mux gets optimized away
[libfirm] / ir / be / bestabs.c
index 9a0a6eb..55a5ef8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
+ * Copyright (C) 1995-2011 University of Karlsruhe.  All right reserved.
  *
  * This file is part of libFirm.
  *
@@ -24,9 +24,7 @@
  * @date    11.9.2006
  * @version $Id$
  */
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include "config.h"
 
 #include <stdio.h>
 #include <stdlib.h>
 #include "pdeq.h"
 #include "irtools.h"
 #include "obst.h"
-#include "array.h"
+#include "array_t.h"
 #include "be_dbgout_t.h"
 #include "beabi.h"
 #include "bemodule.h"
 #include "beemitter.h"
 #include "dbginfo.h"
+#include "begnuas.h"
 
 /* Non-Stab Symbol and Stab Symbol Types */
 enum stabs_types {
@@ -117,7 +116,7 @@ enum stabs_types {
  */
 typedef struct stabs_handle {
        dbg_handle              base;         /**< the base class */
-       ir_entity               *cur_ent;     /**< current method entity */
+       const ir_entity               *cur_ent;     /**< current method entity */
        const be_stack_layout_t *layout;      /**< current stack layout */
        unsigned                next_type_nr; /**< next type number */
        pmap                    *type_map;    /**< a map from type to type number */
@@ -130,7 +129,8 @@ typedef struct stabs_handle {
 /**
  * Returns the stabs type number of a Firm type.
  */
-static unsigned get_type_number(stabs_handle *h, ir_type *tp) {
+static unsigned get_type_number(stabs_handle *h, ir_type *tp)
+{
        pmap_entry *entry;
        unsigned num;
 
@@ -143,7 +143,7 @@ static unsigned get_type_number(stabs_handle *h, ir_type *tp) {
                num = h->next_type_nr++;
                pmap_insert(h->type_map, tp, INT_TO_PTR(num));
        } else {
-               num = PTR_TO_INT(entry->value);
+               num = (unsigned)PTR_TO_INT(entry->value);
        }
        return num;
 }  /* get_type_number */
@@ -151,14 +151,16 @@ static unsigned get_type_number(stabs_handle *h, ir_type *tp) {
 /**
  * Map a given Type to void by assigned the type number 0.
  */
-static void map_to_void(stabs_handle *h, ir_type *tp) {
+static void map_to_void(stabs_handle *h, ir_type *tp)
+{
        pmap_insert(h->type_map, tp, INT_TO_PTR(0));
 }
 
 /**
  * generate the void type.
  */
-static void gen_void_type(stabs_handle *h) {
+static void gen_void_type(stabs_handle *h)
+{
        (void) h;
        be_emit_irprintf("\t.stabs\t\"void:t%u=%u\",%d,0,0,0\n", 0, 0, N_LSYM);
        be_emit_write_line();
@@ -171,10 +173,10 @@ typedef struct walker_env {
 
 /* a type is not ready: put it on the wait queue */
 #define SET_TYPE_NOT_READY(wq, tp) \
-  do { \
-    set_type_link(tp, (void *)1);  \
-    waitq_put(wq, tp);             \
-  } while(0)
+       do { \
+               set_type_link(tp, (void *)1);  \
+               waitq_put(wq, tp);             \
+       } while (0)
 
 /* a the is ready */
 #define SET_TYPE_READY(tp)     set_type_link(tp, NULL)
@@ -200,7 +202,8 @@ static const tarval_mode_info dec_output = {
 /**
  * emit a tarval as decimal
  */
-static void be_emit_tv_as_decimal(tarval *tv) {
+static void be_emit_tv_as_decimal(ir_tarval *tv)
+{
        ir_mode *mode = get_tarval_mode(tv);
        const tarval_mode_info *old = get_tarval_mode_output_option(mode);
 
@@ -209,13 +212,27 @@ static void be_emit_tv_as_decimal(tarval *tv) {
        set_tarval_mode_output_option(mode, old);
 }
 
+static void emit_type_name(const ir_type *type)
+{
+       char *c;
+       char buf[256];
+       ir_print_type(buf, sizeof(buf), type);
+       /* replace special chars to be on the safe side */
+       for (c = buf; *c != '\0'; ++c) {
+               if (*c == '\n' || *c == '"' || *c == '\\')
+                       *c = '?';
+       }
+       be_emit_string(buf);
+}
+
 /**
  * Generates a primitive type.
  *
  * @param h    the stabs handle
  * @param tp   the type
  */
-static void gen_primitive_type(stabs_handle *h, ir_type *tp) {
+static void gen_primitive_type(stabs_handle *h, ir_type *tp)
+{
        ir_mode *mode = get_type_mode(tp);
        unsigned type_num;
 
@@ -227,15 +244,19 @@ static void gen_primitive_type(stabs_handle *h, ir_type *tp) {
                return;
        }  /* if */
 
-       if (0 && get_mode_size_bits(mode) & 7) {
+#if 0
+       if (get_mode_size_bits(mode) & 7) {
                /* this is a bitfield type, ignore it */
                return;
        }  /* if */
+#endif
 
        type_num = get_type_number(h, tp);
 
        if (mode_is_int(mode)) {
-               be_emit_irprintf("\t.stabs\t\"%s:t%u=r%u;", get_type_name(tp), type_num, type_num);
+               be_emit_cstring("\t.stabs\t\"");
+               emit_type_name(tp);
+               be_emit_irprintf(":t%u=r%u;", type_num, type_num);
                be_emit_tv_as_decimal(get_mode_min(mode));
                be_emit_char(';');
                be_emit_tv_as_decimal(get_mode_max(mode));
@@ -243,7 +264,9 @@ static void gen_primitive_type(stabs_handle *h, ir_type *tp) {
                be_emit_write_line();
        } else if (mode_is_float(mode)) {
                int size = get_type_size_bytes(tp);
-               be_emit_irprintf("\t.stabs\t\"%s:t%u=r1;%d;0;\",%d,0,0,0\n", get_type_name(tp), type_num, size, N_LSYM);
+               be_emit_cstring("\t.stabs\t\"");
+               emit_type_name(tp);
+               be_emit_irprintf(":t%u=r1;%d;0;\",%d,0,0,0\n", type_num, size, N_LSYM);
                be_emit_write_line();
        }
 }  /* gen_primitive_type */
@@ -254,18 +277,21 @@ static void gen_primitive_type(stabs_handle *h, ir_type *tp) {
  * @param h    the stabs handle
  * @param tp   the type
  */
-static void gen_enum_type(stabs_handle *h, ir_type *tp) {
+static void gen_enum_type(stabs_handle *h, ir_type *tp)
+{
        unsigned type_num = get_type_number(h, tp);
        int i, n;
 
        SET_TYPE_READY(tp);
-       be_emit_irprintf("\t.stabs\t\"%s:T%u=e", get_type_name(tp), type_num);
+       be_emit_cstring("\t.stabs\t\"");
+       emit_type_name(tp);
+       be_emit_irprintf(":T%u=e", type_num);
        for (i = 0, n = get_enumeration_n_enums(tp); i < n; ++i) {
                ir_enum_const *ec = get_enumeration_const(tp, i);
                char buf[64];
 
                tarval_snprintf(buf, sizeof(buf), get_enumeration_value(ec));
-               be_emit_irprintf("%s:%s,", get_enumeration_name(ec), buf);
+               be_emit_irprintf("%s:%s,", get_enumeration_const_name(ec), buf);
        }
        be_emit_irprintf(";\",%d,0,0,0\n", N_LSYM);
        be_emit_write_line();
@@ -274,7 +300,8 @@ static void gen_enum_type(stabs_handle *h, ir_type *tp) {
 /**
  * print a pointer type
  */
-void print_pointer_type(stabs_handle *h, ir_type *tp, int local) {
+static void print_pointer_type(stabs_handle *h, ir_type *tp, int local)
+{
        unsigned     type_num = local ? h->next_type_nr++ : get_type_number(h, tp);
        ir_type      *el_tp   = get_pointer_points_to_type(tp);
        unsigned     el_num   = get_type_number(h, el_tp);
@@ -288,7 +315,8 @@ void print_pointer_type(stabs_handle *h, ir_type *tp, int local) {
  * @param env  the walker environment
  * @param tp   the type
  */
-static void gen_pointer_type(wenv_t *env, ir_type *tp) {
+static void gen_pointer_type(wenv_t *env, ir_type *tp)
+{
        stabs_handle *h       = env->h;
        ir_type      *el_tp   = get_pointer_points_to_type(tp);
 
@@ -296,7 +324,9 @@ static void gen_pointer_type(wenv_t *env, ir_type *tp) {
        if (! IS_TYPE_READY(el_tp))
                waitq_put(env->wq, el_tp);
 
-       be_emit_irprintf("\t.stabs\t\"%s:t", get_type_name(tp));
+       be_emit_cstring("\t.stabs\t\"");
+       emit_type_name(tp);
+       be_emit_cstring(":t");
        print_pointer_type(h, tp, 0);
        be_emit_irprintf("\",%d,0,0,0\n", N_LSYM);
        be_emit_write_line();
@@ -305,20 +335,21 @@ static void gen_pointer_type(wenv_t *env, ir_type *tp) {
 /**
  * print an array type
  */
-static void print_array_type(stabs_handle *h, ir_type *tp, int local) {
+static void print_array_type(stabs_handle *h, ir_type *tp, int local)
+{
        ir_type      *etp     = get_array_element_type(tp);
-       int          i, n     = get_array_n_dimensions(tp);
+       size_t       i, n     = get_array_n_dimensions(tp);
        unsigned     type_num = local ? h->next_type_nr++ : get_type_number(h, tp);
-       int          *perm;
+       size_t       *perm;
 
        be_emit_irprintf("%u=a", type_num);
-       NEW_ARR_A(int, perm, n);
+       perm = ALLOCAN(size_t, n);
        for (i = 0; i < n; ++i) {
                perm[i] = get_array_order(tp, i);
        }
 
        for (i = 0; i < n; ++i) {
-               int dim = perm[i];
+               size_t dim = perm[i];
 
                if (is_Const(get_array_lower_bound(tp, dim)) && is_Const(get_array_upper_bound(tp, dim))) {
                        long min = get_array_lower_bound_int(tp, dim);
@@ -339,7 +370,8 @@ static void print_array_type(stabs_handle *h, ir_type *tp, int local) {
  * @param env  the walker environment
  * @param tp   the type
  */
-static void gen_array_type(wenv_t *env, ir_type *tp) {
+static void gen_array_type(wenv_t *env, ir_type *tp)
+{
        stabs_handle *h   = env->h;
        ir_type      *etp = get_array_element_type(tp);
 
@@ -347,7 +379,9 @@ static void gen_array_type(wenv_t *env, ir_type *tp) {
        if (! IS_TYPE_READY(etp))
                waitq_put(env->wq, etp);
 
-       be_emit_irprintf("\t.stabs\t\"%s:t", get_type_name(tp));
+       be_emit_cstring("\t.stabs\t\"");
+       emit_type_name(tp);
+       be_emit_cstring(":t");
 
        print_array_type(h, tp, 0);
 
@@ -361,7 +395,8 @@ static void gen_array_type(wenv_t *env, ir_type *tp) {
  * @param env  the walker environment
  * @param tp   the type
  */
-static void gen_struct_union_type(wenv_t *env, ir_type *tp) {
+static void gen_struct_union_type(wenv_t *env, ir_type *tp)
+{
        stabs_handle *h       = env->h;
        unsigned     type_num = get_type_number(h, tp);
        int          i, n;
@@ -378,8 +413,9 @@ static void gen_struct_union_type(wenv_t *env, ir_type *tp) {
        else if (is_Union_type(tp))
                desc = 'u';
 
-       be_emit_irprintf("\t.stabs\t\"%s:Tt%u=%c%d",
-               get_type_name(tp), type_num, desc, get_type_size_bytes(tp));
+       be_emit_cstring("\t.stabs\t\"");
+       emit_type_name(tp);
+       be_emit_irprintf(":Tt%u=%c%d", type_num, desc, get_type_size_bytes(tp));
 
        for (i = 0, n = get_compound_n_members(tp); i < n; ++i) {
                ir_entity *ent = get_compound_member(tp, i);
@@ -392,19 +428,20 @@ static void gen_struct_union_type(wenv_t *env, ir_type *tp) {
                ofs  = get_entity_offset(ent);
                if (is_Struct_type(mtp) && get_type_mode(mtp) != NULL) {
                        /* this structure is a bitfield, skip */
-                       int i, n;
+                       int m;
+                       int n_members = get_struct_n_members(mtp);
 
-                       for (i = 0, n = get_struct_n_members(mtp); i < n; ++i) {
-                               ir_entity *ent = get_struct_member(mtp, i);
-                               ir_type *tp = get_entity_type(ent);
+                       for (m = 0; m < n_members; ++m) {
+                               ir_entity *member    = get_struct_member(mtp, m);
+                               ir_type   *member_tp = get_entity_type(member);
                                int bofs;
 
-                               type_num = get_type_number(h, tp);
-                               size = get_type_size_bytes(tp) * 8;
-                               bofs = (ofs + get_entity_offset(ent)) * 8 + get_entity_offset_bits_remainder(ent);
+                               type_num = get_type_number(h, member_tp);
+                               size = get_type_size_bytes(member_tp) * 8;
+                               bofs = (ofs + get_entity_offset(member)) * 8 + get_entity_offset_bits_remainder(member);
 
                                /* name:type, bit offset from the start of the struct', number of bits in the element. */
-                               be_emit_irprintf("%s:%u,%d,%u;", get_entity_name(ent), type_num, bofs, size);
+                               be_emit_irprintf("%s:%u,%d,%u;", get_entity_name(member), type_num, bofs, size);
                        }
                } else {
                        /* no bitfield */
@@ -436,7 +473,8 @@ static void gen_struct_union_type(wenv_t *env, ir_type *tp) {
  * @param env  the walker environment
  * @param tp   the type
  */
-static void gen_method_type(wenv_t *env, ir_type *tp) {
+static void gen_method_type(wenv_t *env, ir_type *tp)
+{
        stabs_handle *h       = env->h;
        unsigned     type_num = get_type_number(h, tp);
        ir_type *rtp = NULL;
@@ -451,7 +489,9 @@ static void gen_method_type(wenv_t *env, ir_type *tp) {
        }
        res_type_num = get_type_number(h, rtp);
 
-       be_emit_irprintf("\t.stabs\t\"%s:t%u=f%u", get_type_name(tp), type_num, res_type_num);
+       be_emit_cstring("\t.stabs\t\"");
+       emit_type_name(tp);
+       be_emit_irprintf(":t%u=f%u", type_num, res_type_num);
 
        /* handle more than one return type */
        for (i = 1; i < n; ++i) {
@@ -471,7 +511,7 @@ static void gen_method_type(wenv_t *env, ir_type *tp) {
  */
 static void walk_type(type_or_ent tore, void *ctx)
 {
-       wenv_t *env = ctx;
+       wenv_t *env = (wenv_t*)ctx;
        ir_type  *tp;
 
        if (is_type(tore.typ)) {
@@ -531,10 +571,9 @@ static void walk_type(type_or_ent tore, void *ctx)
 static void finish_types(wenv_t *env)
 {
        waitq *wq = env->wq;
-       ir_type *tp;
 
        while (! waitq_empty(wq)) {
-               tp = waitq_get(wq);
+               ir_type *tp = (ir_type*)waitq_get(wq);
                if (IS_TYPE_READY(tp))
                        continue;
 
@@ -572,14 +611,20 @@ static void finish_types(wenv_t *env)
 /**
  * generate all types.
  */
-static void gen_types(stabs_handle *h) {
+static void gen_types(stabs_handle *h)
+{
        wenv_t env;
 
        env.h  = h;
        env.wq = new_waitq();
+
+       irp_reserve_resources(irp, IRP_RESOURCE_TYPE_LINK);
        type_walk(NULL, walk_type, &env);
+       irp_free_resources(irp, IRP_RESOURCE_TYPE_LINK);
+
        finish_types(&env);
        del_waitq(env.wq);
+
 }  /* gen_types */
 
 
@@ -588,25 +633,30 @@ static void gen_types(stabs_handle *h) {
 /**
  * start a new source object (compilation unit)
  */
-static void stabs_so(dbg_handle *handle, const char *filename) {
+static void stabs_unit_begin(dbg_handle *handle, const char *filename)
+{
        stabs_handle *h = (stabs_handle *)handle;
+
+       /* needed for the debug support */
+       be_gas_emit_switch_section(GAS_SECTION_TEXT);
+       be_emit_irprintf("%stext0:\n", be_gas_get_private_prefix());
+       be_emit_write_line();
+
        h->main_file = h->curr_file = filename;
-       be_emit_irprintf("\t.stabs\t\"%s\",%d,0,0,.Ltext0\n", filename, N_SO);
+       be_emit_irprintf("\t.stabs\t\"%s\",%d,0,0,%stext0\n", filename, N_SO, be_gas_get_private_prefix());
        be_emit_write_line();
-}  /* stabs_so */
+}
 
-/**
- * Main Program
- */
-static void stabs_main_program(dbg_handle *handle) {
+static void stabs_unit_end(dbg_handle *handle)
+{
        ir_graph *irg = get_irp_main_irg();
-
        (void) handle;
        if (irg) {
-               be_emit_irprintf("\t.stabs\t\"%s\",%d,0,0,0\n", get_entity_name(get_irg_entity(irg)), N_MAIN);
-               be_emit_write_line();
+               ir_entity *entity = get_irg_entity(irg);
+               be_emit_irprintf("\t.stabs\t\"%s\",%d,0,0,0\n",
+                                get_entity_ld_name(entity), N_MAIN);
        }
-}  /* stabs_main_program */
+}
 
 static void stabs_set_dbg_info(dbg_handle *h, dbg_info *dbgi)
 {
@@ -643,19 +693,22 @@ static void stabs_set_dbg_info(dbg_handle *h, dbg_info *dbgi)
 /**
  * dump the stabs for a method begin
  */
-static void stabs_method_begin(dbg_handle *handle, ir_entity *ent, const be_stack_layout_t *layout) {
+static void stabs_method_begin(dbg_handle *handle, const ir_entity *ent)
+{
        stabs_handle *h = (stabs_handle *)handle;
+       ir_graph     *irg = get_entity_irg(ent);
        ir_type      *mtp, *rtp;
        unsigned     type_num;
        int          i, n, between_size;
+       be_stack_layout_t *layout = be_get_irg_stack_layout(irg);
 
        h->cur_ent = ent;
        h->layout  = layout;
 
        /* create the method entry */
        mtp = get_entity_type(ent);
-       if (is_lowered_type(mtp))
-               mtp = get_associated_type(mtp);
+       while (is_lowered_type(mtp))
+               mtp = get_higher_type(mtp);
        if (get_method_n_ress(mtp) > 0)
                rtp = get_method_res_type(mtp, 0);
        else
@@ -663,7 +716,7 @@ static void stabs_method_begin(dbg_handle *handle, ir_entity *ent, const be_stac
        type_num = get_type_number(h, rtp);
        be_emit_irprintf("\t.stabs\t\"%s:%c%u\",%u,0,0,%s\n",
                get_entity_name(ent),
-               get_entity_visibility(ent) == visibility_external_visible ? 'F' : 'f',
+               get_entity_visibility(ent) == ir_visibility_local ? 'f' : 'F',
                type_num,
                N_FUN,
                get_entity_ld_name(ent));
@@ -672,19 +725,18 @@ static void stabs_method_begin(dbg_handle *handle, ir_entity *ent, const be_stac
        /* create parameter entries */
        between_size = get_type_size_bytes(layout->between_type);
        for (i = 0, n = get_method_n_params(mtp); i < n; ++i) {
-               ir_type *ptp      = get_method_param_type(mtp, i);
-        const char *name  = get_method_param_name(mtp, i);
-               unsigned type_num = get_type_number(h, ptp);
-        char buf[16];
-        int ofs = 0;
-               ir_entity *stack_ent;
-
-        if (! name) {
-          snprintf(buf, sizeof(buf), "arg%d", i);
-          name = buf;
-        }
+               ir_type    *ptp  = get_method_param_type(mtp, i);
+               const char *name = NULL;
+               char        buf[16];
+               int         ofs  = 0;
+               ir_entity  *stack_ent;
+
+               if (! name) {
+                       snprintf(buf, sizeof(buf), "arg%d", i);
+                       name = buf;
+               }
                /* check if this parameter has a stack entity. If it has, it
-                  it transmitted on the stack, else in a register */
+                * it transmitted on the stack, else in a register */
                stack_ent = layout->param_map[i];
                if (stack_ent) {
                        ofs = get_entity_offset(stack_ent) + between_size;
@@ -711,9 +763,10 @@ static void stabs_method_begin(dbg_handle *handle, ir_entity *ent, const be_stac
 /**
  * dump the stabs for a method end
  */
-static void stabs_method_end(dbg_handle *handle) {
+static void stabs_method_end(dbg_handle *handle)
+{
        stabs_handle            *h = (stabs_handle *)handle;
-       ir_entity               *ent = h->cur_ent;
+       const ir_entity         *ent = h->cur_ent;
        const be_stack_layout_t *layout = h->layout;
        const char              *ld_name = get_entity_ld_name(ent);
        int                     i, n, frame_size;
@@ -722,24 +775,24 @@ static void stabs_method_end(dbg_handle *handle) {
        /* create entries for automatic variables on the stack */
        frame_size = get_type_size_bytes(layout->frame_type);
        for (i = 0, n = get_compound_n_members(layout->frame_type); i < n; ++i) {
-               ir_entity *ent = get_compound_member(layout->frame_type, i);
+               ir_entity *member = get_compound_member(layout->frame_type, i);
                ir_type *tp;
                int ofs;
                unsigned type_num;
 
                /* ignore spill slots and other helper objects */
-               if (is_entity_compiler_generated(ent))
+               if (is_entity_compiler_generated(member))
                        continue;
 
-               tp = get_entity_type(ent);
+               tp = get_entity_type(member);
                /* should not happen in backend but ... */
                if (is_Method_type(tp))
                        continue;
                type_num = get_type_number(h, tp);
-               ofs      = -frame_size + get_entity_offset(ent);
+               ofs      = -frame_size + get_entity_offset(member);
 
                be_emit_irprintf("\t.stabs\t\"%s:%u\",%d,0,0,%d\n",
-                       get_entity_name(ent), type_num, N_LSYM, ofs);
+                                get_entity_name(member), type_num, N_LSYM, ofs);
                be_emit_write_line();
        }
        /* we need a lexical block here */
@@ -758,7 +811,8 @@ static void stabs_method_end(dbg_handle *handle) {
 /**
  * dump types
  */
-static void stabs_types(dbg_handle *handle) {
+static void stabs_types(dbg_handle *handle)
+{
        stabs_handle *h = (stabs_handle *)handle;
 
        /* allocate the zero for the void type */
@@ -770,25 +824,25 @@ static void stabs_types(dbg_handle *handle) {
 /**
  * dump a variable in the global type
  */
-static void stabs_variable(dbg_handle *handle, ir_entity *ent) {
+static void stabs_variable(dbg_handle *handle, const ir_entity *ent)
+{
        stabs_handle *h = (stabs_handle *)handle;
        unsigned tp_num = get_type_number(h, get_entity_type(ent));
        char buf[1024];
 
-       if (get_entity_visibility(ent) == visibility_external_visible) {
-               /* a global variable */
-               snprintf(buf, sizeof(buf), "\t.stabs\t\"%s:G%u\",%d,0,0,0\n",
-                       get_entity_name(ent), tp_num, N_GSYM);
-       } else { /* some kind of local */
-               ir_variability variability = get_entity_variability(ent);
+       if (get_entity_visibility(ent) == ir_visibility_local) {
+               /* some kind of local */
+               ir_linkage linkage = get_entity_linkage(ent);
                int kind = N_STSYM;
 
-               if (variability == variability_uninitialized)
-                       kind = N_LCSYM;
-               else if (variability == variability_constant)
+               if (linkage & IR_LINKAGE_CONSTANT)
                        kind = N_ROSYM;
                snprintf(buf, sizeof(buf), "\t.stabs\t\"%s:S%u\",%d,0,0,%s\n",
-                       get_entity_name(ent), tp_num, kind, get_entity_ld_name(ent));
+                        get_entity_name(ent), tp_num, kind, get_entity_ld_name(ent));
+       } else {
+               /* a global variable */
+               snprintf(buf, sizeof(buf), "\t.stabs\t\"%s:G%u\",%d,0,0,0\n",
+                        get_entity_name(ent), tp_num, (int)N_GSYM);
        }
        buf[sizeof(buf) - 1] = '\0';
 
@@ -798,7 +852,8 @@ static void stabs_variable(dbg_handle *handle, ir_entity *ent) {
 /**
  * Close the stabs handler.
  */
-static void stabs_close(dbg_handle *handle) {
+static void stabs_close(dbg_handle *handle)
+{
        stabs_handle *h = (stabs_handle *)handle;
        pmap_destroy(h->type_map);
        free(h);
@@ -807,8 +862,8 @@ static void stabs_close(dbg_handle *handle) {
 /** The stabs operations. */
 static const debug_ops stabs_ops = {
        stabs_close,
-       stabs_so,
-       stabs_main_program,
+       stabs_unit_begin,
+       stabs_unit_end,
        stabs_method_begin,
        stabs_method_end,
        stabs_types,
@@ -817,23 +872,18 @@ static const debug_ops stabs_ops = {
 };
 
 /* Opens a stabs handler */
-dbg_handle *be_stabs_open(void) {
-       stabs_handle *h = xmalloc(sizeof(*h));
+static dbg_handle *be_stabs_open(void)
+{
+       stabs_handle *h = XMALLOCZ(stabs_handle);
 
        h->base.ops     = &stabs_ops;
-       h->cur_ent      = NULL;
-       h->layout       = NULL;
-       h->next_type_nr = 0;
        h->type_map     = pmap_create_ex(64);
-       h->main_file    = NULL;
-       h->curr_file    = NULL;
 
        return &h->base;
 }
 
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_stabs)
 void be_init_stabs(void)
 {
        be_register_dbgout_module("stabs", be_stabs_open);
 }
-
-BE_REGISTER_MODULE_CONSTRUCTOR(be_init_stabs);