beifg: Simplify the quite complicated way to divide a number by 2 in be_ifg_stat().
[libfirm] / ir / debug / debugger.c
index 1a4fa1b..aeed330 100644 (file)
@@ -1,20 +1,6 @@
 /*
 /*
- * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
- *
  * This file is part of libFirm.
  * This file is part of libFirm.
- *
- * This file may be distributed and/or modified under the terms of the
- * GNU General Public License version 2 as published by the Free Software
- * Foundation and appearing in the file LICENSE.GPL included in the
- * packaging of this file.
- *
- * Licensees holding valid libFirm Professional Edition licenses may use
- * this file in accordance with the libFirm Commercial License.
- * Agreement provided with the Software.
- *
- * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
- * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE.
+ * Copyright (C) 2012 University of Karlsruhe.
  */
 
 /**
  */
 
 /**
@@ -22,7 +8,6 @@
  * @brief     Helper function for integrated debug support
  * @author    Michael Beck
  * @date      2005
  * @brief     Helper function for integrated debug support
  * @author    Michael Beck
  * @date      2005
- * @version   $Id$
  */
 #include "config.h"
 
  */
 #include "config.h"
 
 #include <stdio.h>
 #include <signal.h>
 #include <string.h>
 #include <stdio.h>
 #include <signal.h>
 #include <string.h>
-
-#ifdef HAVE_STRINGS_H
 #include <strings.h>
 #include <strings.h>
-#endif
+#include <time.h>
 
 #include <ctype.h>
 
 
 #include <ctype.h>
 
@@ -56,6 +39,7 @@
 #include "iredges_t.h"
 #include "debug.h"
 #include "error.h"
 #include "iredges_t.h"
 #include "debug.h"
 #include "error.h"
+#include "util.h"
 
 #ifdef _WIN32
 /* Break into the debugger. The Win32 way. */
 
 #ifdef _WIN32
 /* Break into the debugger. The Win32 way. */
@@ -86,23 +70,22 @@ typedef enum {
 /**
  * Reasons for node number breakpoints.
  */
 /**
  * Reasons for node number breakpoints.
  */
-typedef enum _bp_reasons_t {
-       BP_ON_NEW_NODE,    /**< break if node with number is created */
+typedef enum bp_reasons_t {
+       BP_ON_NEW_THING,   /**< break if node, entity or type with number is created */
        BP_ON_REPLACE,     /**< break if node with number is replaced */
        BP_ON_LOWER,       /**< break if node with number is lowered */
        BP_ON_REMIRG,      /**< break if an IRG is removed */
        BP_ON_NEW_ENT,     /**< break if a new entity is created */
        BP_ON_REPLACE,     /**< break if node with number is replaced */
        BP_ON_LOWER,       /**< break if node with number is lowered */
        BP_ON_REMIRG,      /**< break if an IRG is removed */
        BP_ON_NEW_ENT,     /**< break if a new entity is created */
-       BP_ON_NEW_TYPE,    /**< break if a new type is created */
        BP_MAX_REASON
 } bp_reasons_t;
 
 /** A breakpoint. */
        BP_MAX_REASON
 } bp_reasons_t;
 
 /** A breakpoint. */
-typedef struct _breakpoint {
+typedef struct breakpoint {
        bp_kind      kind;        /**< the kind of this break point */
        unsigned     bpnr;        /**< break point number */
        int          active;      /**< non-zero, if this break point is active */
        bp_reasons_t reason;      /**< reason for the breakpoint */
        bp_kind      kind;        /**< the kind of this break point */
        unsigned     bpnr;        /**< break point number */
        int          active;      /**< non-zero, if this break point is active */
        bp_reasons_t reason;      /**< reason for the breakpoint */
-       struct _breakpoint *next; /**< link to the next one */
+       struct breakpoint *next; /**< link to the next one */
 } breakpoint;
 
 /** A number breakpoint. */
 } breakpoint;
 
 /** A number breakpoint. */
@@ -121,7 +104,7 @@ typedef struct {
 } bp_ident_t;
 
 /** Calculate the hash value for an ident breakpoint. */
 } bp_ident_t;
 
 /** Calculate the hash value for an ident breakpoint. */
-#define HASH_IDENT_BP(key) (HASH_PTR((key).id) ^ (key).bp.reason)
+#define HASH_IDENT_BP(key) (hash_ptr((key).id) ^ (key).bp.reason)
 
 /** The set containing the breakpoints on node numbers. */
 static set *bp_numbers;
 
 /** The set containing the breakpoints on node numbers. */
 static set *bp_numbers;
@@ -193,7 +176,7 @@ static const char __attribute__((used)) firm_debug_info_string[] =
 int firm_debug_active(void)
 {
        return is_active;
 int firm_debug_active(void)
 {
        return is_active;
-}  /* firm_debug_active */
+}
 
 /**
  * Reset the debug text buffer.
 
 /**
  * Reset the debug text buffer.
@@ -201,42 +184,34 @@ int firm_debug_active(void)
 static void reset_dbg_buf(void)
 {
        firm_dbg_msg_buf[0] = '\0';
 static void reset_dbg_buf(void)
 {
        firm_dbg_msg_buf[0] = '\0';
-}  /* reset_dbg_buf */
-
-static void add_to_dbg_buf(const char *buf)
-{
-       strncat(firm_dbg_msg_buf, buf, sizeof(firm_dbg_msg_buf));
-}  /* add_to_dbg_buf */
+}
 
 const char *firm_debug_text(void)
 {
        firm_dbg_msg_buf[sizeof(firm_dbg_msg_buf) - 1] = '\0';
        return firm_dbg_msg_buf;
 
 const char *firm_debug_text(void)
 {
        firm_dbg_msg_buf[sizeof(firm_dbg_msg_buf) - 1] = '\0';
        return firm_dbg_msg_buf;
-}  /* firm_debug_text */
+}
 
 /**
  * debug output
  */
 static void dbg_printf(const char *fmt, ...)
 {
 
 /**
  * debug output
  */
 static void dbg_printf(const char *fmt, ...)
 {
-       char buf[1024];
-
-       va_list args;
-       va_start(args, fmt);
-
        if (fmt[0] != '+')
                reset_dbg_buf();
        else
                ++fmt;
 
        if (fmt[0] != '+')
                reset_dbg_buf();
        else
                ++fmt;
 
-       ir_vsnprintf(buf, sizeof(buf), fmt, args);
+       va_list args;
+       va_start(args, fmt);
+       if (redir_output) {
+               size_t const cur = strlen(firm_dbg_msg_buf);
+               ir_vsnprintf(firm_dbg_msg_buf + cur, sizeof(firm_dbg_msg_buf) - cur, fmt, args);
+       } else {
+               ir_vprintf(fmt, args);
+       }
        va_end(args);
        va_end(args);
-
-       if (redir_output)
-               add_to_dbg_buf(buf);
-       else
-               puts(buf);
-}  /* dbg_printf */
+}
 
 /**
  * A new node is created.
 
 /**
  * A new node is created.
@@ -252,14 +227,14 @@ static void dbg_new_node(void *ctx, ir_graph *irg, ir_node *node)
        (void) irg;
 
        key.nr        = get_irn_node_nr(node);
        (void) irg;
 
        key.nr        = get_irn_node_nr(node);
-       key.bp.reason = BP_ON_NEW_NODE;
+       key.bp.reason = BP_ON_NEW_THING;
 
 
-       elem = set_find(bp_numbers, &key, sizeof(key), HASH_NR_BP(key));
+       elem = set_find(bp_nr_t, bp_numbers, &key, sizeof(key), HASH_NR_BP(key));
        if (elem && elem->bp.active) {
                dbg_printf("Firm BP %u reached, %+F created\n", elem->bp.bpnr, node);
                firm_debug_break();
        }
        if (elem && elem->bp.active) {
                dbg_printf("Firm BP %u reached, %+F created\n", elem->bp.bpnr, node);
                firm_debug_break();
        }
-}  /* dbg_new_node */
+}
 
 /**
  * A node is replaced.
 
 /**
  * A node is replaced.
@@ -276,12 +251,12 @@ static void dbg_replace(void *ctx, ir_node *old, ir_node *nw)
        key.nr        = get_irn_node_nr(old);
        key.bp.reason = BP_ON_REPLACE;
 
        key.nr        = get_irn_node_nr(old);
        key.bp.reason = BP_ON_REPLACE;
 
-       elem = set_find(bp_numbers, &key, sizeof(key), HASH_NR_BP(key));
+       elem = set_find(bp_nr_t, bp_numbers, &key, sizeof(key), HASH_NR_BP(key));
        if (elem && elem->bp.active) {
                dbg_printf("Firm BP %u reached, %+F will be replaced by %+F\n", elem->bp.bpnr, old, nw);
                firm_debug_break();
        }
        if (elem && elem->bp.active) {
                dbg_printf("Firm BP %u reached, %+F will be replaced by %+F\n", elem->bp.bpnr, old, nw);
                firm_debug_break();
        }
-}  /* dbg_replace */
+}
 
 /**
  * A new node is lowered.
 
 /**
  * A new node is lowered.
@@ -297,12 +272,12 @@ static void dbg_lower(void *ctx, ir_node *node)
        key.nr        = get_irn_node_nr(node);
        key.bp.reason = BP_ON_LOWER;
 
        key.nr        = get_irn_node_nr(node);
        key.bp.reason = BP_ON_LOWER;
 
-       elem = set_find(bp_numbers, &key, sizeof(key), HASH_NR_BP(key));
+       elem = set_find(bp_nr_t, bp_numbers, &key, sizeof(key), HASH_NR_BP(key));
        if (elem && elem->bp.active) {
                dbg_printf("Firm BP %u reached, %+F will be lowered\n", elem->bp.bpnr, node);
                firm_debug_break();
        }
        if (elem && elem->bp.active) {
                dbg_printf("Firm BP %u reached, %+F will be lowered\n", elem->bp.bpnr, node);
                firm_debug_break();
        }
-}  /* dbg_lower */
+}
 
 /**
  * A graph will be deleted.
 
 /**
  * A graph will be deleted.
@@ -318,7 +293,7 @@ static void dbg_free_graph(void *ctx, ir_graph *irg)
                key.nr        = get_irg_graph_nr(irg);
                key.bp.reason = BP_ON_REMIRG;
 
                key.nr        = get_irg_graph_nr(irg);
                key.bp.reason = BP_ON_REMIRG;
 
-               elem = set_find(bp_numbers, &key, sizeof(key), HASH_NR_BP(key));
+               elem = set_find(bp_nr_t, bp_numbers, &key, sizeof(key), HASH_NR_BP(key));
                if (elem && elem->bp.active) {
                        ir_printf("Firm BP %u reached, %+F will be deleted\n", elem->bp.bpnr, irg);
                        firm_debug_break();
                if (elem && elem->bp.active) {
                        ir_printf("Firm BP %u reached, %+F will be deleted\n", elem->bp.bpnr, irg);
                        firm_debug_break();
@@ -334,13 +309,13 @@ static void dbg_free_graph(void *ctx, ir_graph *irg)
                key.id        = get_entity_ident(ent);
                key.bp.reason = BP_ON_REMIRG;
 
                key.id        = get_entity_ident(ent);
                key.bp.reason = BP_ON_REMIRG;
 
-               elem = set_find(bp_idents, &key, sizeof(key), HASH_IDENT_BP(key));
+               elem = set_find(bp_ident_t, bp_idents, &key, sizeof(key), HASH_IDENT_BP(key));
                if (elem && elem->bp.active) {
                        dbg_printf("Firm BP %u reached, %+F will be deleted\n", elem->bp.bpnr, ent);
                        firm_debug_break();
                }
        }
                if (elem && elem->bp.active) {
                        dbg_printf("Firm BP %u reached, %+F will be deleted\n", elem->bp.bpnr, ent);
                        firm_debug_break();
                }
        }
-}  /* dbg_free_graph */
+}
 
 /**
  * An entity was created.
 
 /**
  * An entity was created.
@@ -357,7 +332,7 @@ static void dbg_new_entity(void *ctx, ir_entity *ent)
                key.id        = get_entity_ident(ent);
                key.bp.reason = BP_ON_NEW_ENT;
 
                key.id        = get_entity_ident(ent);
                key.bp.reason = BP_ON_NEW_ENT;
 
-               elem = set_find(bp_idents, &key, sizeof(key), HASH_IDENT_BP(key));
+               elem = set_find(bp_ident_t, bp_idents, &key, sizeof(key), HASH_IDENT_BP(key));
                if (elem && elem->bp.active) {
                        ir_printf("Firm BP %u reached, %+F was created\n", elem->bp.bpnr, ent);
                        firm_debug_break();
                if (elem && elem->bp.active) {
                        ir_printf("Firm BP %u reached, %+F was created\n", elem->bp.bpnr, ent);
                        firm_debug_break();
@@ -367,15 +342,15 @@ static void dbg_new_entity(void *ctx, ir_entity *ent)
                bp_nr_t key, *elem;
 
                key.nr        = get_entity_nr(ent);
                bp_nr_t key, *elem;
 
                key.nr        = get_entity_nr(ent);
-               key.bp.reason = BP_ON_NEW_ENT;
+               key.bp.reason = BP_ON_NEW_THING;
 
 
-               elem = set_find(bp_numbers, &key, sizeof(key), HASH_NR_BP(key));
+               elem = set_find(bp_nr_t, bp_numbers, &key, sizeof(key), HASH_NR_BP(key));
                if (elem && elem->bp.active) {
                        dbg_printf("Firm BP %u reached, %+F was created\n", elem->bp.bpnr, ent);
                        firm_debug_break();
                }
        }
                if (elem && elem->bp.active) {
                        dbg_printf("Firm BP %u reached, %+F was created\n", elem->bp.bpnr, ent);
                        firm_debug_break();
                }
        }
-}  /* dbg_new_entity */
+}
 
 /**
  * A type was created.
 
 /**
  * A type was created.
@@ -390,15 +365,15 @@ static void dbg_new_type(void *ctx, ir_type *tp)
                bp_nr_t key, *elem;
 
                key.nr        = get_type_nr(tp);
                bp_nr_t key, *elem;
 
                key.nr        = get_type_nr(tp);
-               key.bp.reason = BP_ON_NEW_TYPE;
+               key.bp.reason = BP_ON_NEW_THING;
 
 
-               elem = set_find(bp_numbers, &key, sizeof(key), HASH_NR_BP(key));
+               elem = set_find(bp_nr_t, bp_numbers, &key, sizeof(key), HASH_NR_BP(key));
                if (elem && elem->bp.active) {
                        ir_printf("Firm BP %u reached, %+F was created\n", elem->bp.bpnr, tp);
                        firm_debug_break();
                }
        }
                if (elem && elem->bp.active) {
                        ir_printf("Firm BP %u reached, %+F was created\n", elem->bp.bpnr, tp);
                        firm_debug_break();
                }
        }
-}  /* dbg_new_type */
+}
 
 /**
  * Return the reason string.
 
 /**
  * Return the reason string.
@@ -406,48 +381,47 @@ static void dbg_new_type(void *ctx, ir_type *tp)
 static const char *reason_str(bp_reasons_t reason)
 {
        switch (reason) {
 static const char *reason_str(bp_reasons_t reason)
 {
        switch (reason) {
-       case BP_ON_NEW_NODE: return "node creation";
-       case BP_ON_REPLACE:  return "node replace";
-       case BP_ON_LOWER:    return "node lowering";
-       case BP_ON_REMIRG:   return "removing IRG";
-       case BP_ON_NEW_ENT:  return "entity creation";
-       case BP_ON_NEW_TYPE: return "type creation";
-       case BP_MAX_REASON:  break;
+       case BP_ON_NEW_THING: return "node, entity or type creation";
+       case BP_ON_REPLACE:   return "node replace";
+       case BP_ON_LOWER:     return "node lowering";
+       case BP_ON_REMIRG:    return "removing IRG";
+       case BP_ON_NEW_ENT:   return "entity creation";
+       case BP_MAX_REASON:   break;
        }
        panic("unsupported reason");
        }
        panic("unsupported reason");
-}  /* reason_str */
+}
 
 /**
  * Compare two number breakpoints.
  */
 static int cmp_nr_bp(const void *elt, const void *key, size_t size)
 {
 
 /**
  * Compare two number breakpoints.
  */
 static int cmp_nr_bp(const void *elt, const void *key, size_t size)
 {
-       const bp_nr_t *e1 = elt;
-       const bp_nr_t *e2 = key;
+       const bp_nr_t *e1 = (const bp_nr_t*)elt;
+       const bp_nr_t *e2 = (const bp_nr_t*)key;
        (void) size;
 
        return (e1->nr - e2->nr) | (e1->bp.reason - e2->bp.reason);
        (void) size;
 
        return (e1->nr - e2->nr) | (e1->bp.reason - e2->bp.reason);
-}  /* cmp_nr_bp */
+}
 
 /**
  * Compare two ident breakpoints.
  */
 static int cmp_ident_bp(const void *elt, const void *key, size_t size)
 {
 
 /**
  * Compare two ident breakpoints.
  */
 static int cmp_ident_bp(const void *elt, const void *key, size_t size)
 {
-       const bp_ident_t *e1 = elt;
-       const bp_ident_t *e2 = key;
+       const bp_ident_t *e1 = (const bp_ident_t*)elt;
+       const bp_ident_t *e2 = (const bp_ident_t*)key;
        (void) size;
 
        return (e1->id != e2->id) | (e1->bp.reason - e2->bp.reason);
        (void) size;
 
        return (e1->id != e2->id) | (e1->bp.reason - e2->bp.reason);
-}  /* cmp_ident_bp */
+}
 
 /**
  * Update the hooks.
  */
 static void update_hooks(breakpoint *bp)
 {
 
 /**
  * Update the hooks.
  */
 static void update_hooks(breakpoint *bp)
 {
-#define CASE_ON(a, b)  case a: if (! IS_HOOKED(hook_##b)) HOOK(hook_##b, dbg_##b); break
-#define CASE_OFF(a, b) case a: if (IS_HOOKED(hook_##b)) UNHOOK(hook_##b); break
+#define CASE_ON(a, hook, handler)  case a: if (! IS_HOOKED(hook)) HOOK(hook, handler); break
+#define CASE_OFF(a, hook) case a: if (IS_HOOKED(hook)) UNHOOK(hook); break
 
        if (bp->active)
                ++num_active_bp[bp->reason];
 
        if (bp->active)
                ++num_active_bp[bp->reason];
@@ -457,12 +431,18 @@ static void update_hooks(breakpoint *bp)
        if (num_active_bp[bp->reason] > 0) {
                /* register the hooks on demand */
                switch (bp->reason) {
        if (num_active_bp[bp->reason] > 0) {
                /* register the hooks on demand */
                switch (bp->reason) {
-               CASE_ON(BP_ON_NEW_NODE, new_node);
-               CASE_ON(BP_ON_REPLACE, replace);
-               CASE_ON(BP_ON_LOWER, lower);
-               CASE_ON(BP_ON_REMIRG, free_graph);
-               CASE_ON(BP_ON_NEW_ENT, new_entity);
-               CASE_ON(BP_ON_NEW_TYPE, new_type);
+               CASE_ON(BP_ON_REPLACE, hook_replace,    dbg_replace);
+               CASE_ON(BP_ON_LOWER,   hook_lower,      dbg_lower);
+               CASE_ON(BP_ON_REMIRG,  hook_free_graph, dbg_free_graph);
+               CASE_ON(BP_ON_NEW_ENT, hook_new_entity, dbg_new_entity);
+               case BP_ON_NEW_THING:
+                       if (!IS_HOOKED(hook_new_node))
+                               HOOK(hook_new_node, dbg_new_node);
+                       if (!IS_HOOKED(hook_new_type))
+                               HOOK(hook_new_type, dbg_new_type);
+                       if (!IS_HOOKED(hook_new_entity))
+                               HOOK(hook_new_entity, dbg_new_entity);
+                       break;
                default:
                        break;
                }
                default:
                        break;
                }
@@ -470,19 +450,25 @@ static void update_hooks(breakpoint *bp)
        else {
                /* unregister the hook on demand */
                switch (bp->reason) {
        else {
                /* unregister the hook on demand */
                switch (bp->reason) {
-               CASE_OFF(BP_ON_NEW_NODE, new_node);
-               CASE_OFF(BP_ON_REPLACE, replace);
-               CASE_OFF(BP_ON_LOWER, lower);
-               CASE_OFF(BP_ON_REMIRG, free_graph);
-               CASE_OFF(BP_ON_NEW_ENT, new_entity);
-               CASE_OFF(BP_ON_NEW_TYPE, new_type);
+               CASE_OFF(BP_ON_REPLACE,  hook_replace);
+               CASE_OFF(BP_ON_LOWER,    hook_lower);
+               CASE_OFF(BP_ON_REMIRG,   hook_free_graph);
+               CASE_OFF(BP_ON_NEW_ENT,  hook_new_entity);
+               case BP_ON_NEW_THING:
+                       if (IS_HOOKED(hook_new_node))
+                               UNHOOK(hook_new_node);
+                       if (IS_HOOKED(hook_new_type))
+                               UNHOOK(hook_new_type);
+                       if (IS_HOOKED(hook_new_entity))
+                               UNHOOK(hook_new_entity);
+                       break;
                default:
                        break;
                }
        }
 #undef CASE_ON
 #undef CASE_OFF
                default:
                        break;
                }
        }
 #undef CASE_ON
 #undef CASE_OFF
-}  /* update_hooks */
+}
 
 /**
  * Break if nr is reached.
 
 /**
  * Break if nr is reached.
@@ -497,7 +483,7 @@ static void break_on_nr(long nr, bp_reasons_t reason)
        key.bp.reason = reason;
        key.nr        = nr;
 
        key.bp.reason = reason;
        key.nr        = nr;
 
-       elem = set_insert(bp_numbers, &key, sizeof(key), HASH_NR_BP(key));
+       elem = set_insert(bp_nr_t, bp_numbers, &key, sizeof(key), HASH_NR_BP(key));
 
        if (elem->bp.bpnr == 0) {
                /* new break point */
 
        if (elem->bp.bpnr == 0) {
                /* new break point */
@@ -509,7 +495,7 @@ static void break_on_nr(long nr, bp_reasons_t reason)
 
                update_hooks(&elem->bp);
        }
 
                update_hooks(&elem->bp);
        }
-}  /* break_on_nr */
+}
 
 /**
  * Break if ident name is reached.
 
 /**
  * Break if ident name is reached.
@@ -524,7 +510,7 @@ static void break_on_ident(const char *name, bp_reasons_t reason)
        key.bp.reason = reason;
        key.id        = new_id_from_str(name);
 
        key.bp.reason = reason;
        key.id        = new_id_from_str(name);
 
-       elem = set_insert(bp_idents, &key, sizeof(key), HASH_IDENT_BP(key));
+       elem = set_insert(bp_ident_t, bp_idents, &key, sizeof(key), HASH_IDENT_BP(key));
 
        if (elem->bp.bpnr == 0) {
                /* new break point */
 
        if (elem->bp.bpnr == 0) {
                /* new break point */
@@ -536,7 +522,7 @@ static void break_on_ident(const char *name, bp_reasons_t reason)
 
                update_hooks(&elem->bp);
        }
 
                update_hooks(&elem->bp);
        }
-}  /* break_on_ident */
+}
 
 /**
  * Sets/resets the active flag of breakpoint bp.
 
 /**
  * Sets/resets the active flag of breakpoint bp.
@@ -557,7 +543,7 @@ static void bp_activate(unsigned bp, int active)
                }
        }
        dbg_printf("Error: Firm BP %u not exists.\n", bp);
                }
        }
        dbg_printf("Error: Firm BP %u not exists.\n", bp);
-}  /* bp_activate */
+}
 
 
 /**
 
 
 /**
@@ -565,7 +551,7 @@ static void bp_activate(unsigned bp, int active)
  */
 static void show_commands(void)
 {
  */
 static void show_commands(void)
 {
-       dbg_printf("Internal Firm debugger extension $Revision$ commands:\n"
+       dbg_printf("Internal Firm debugger extension commands:\n"
                "init                  break after initialization\n"
                "create nr             break if node nr was created\n"
                "replace nr            break if node nr is replaced by another node\n"
                "init                  break after initialization\n"
                "create nr             break if node nr was created\n"
                "replace nr            break if node nr is replaced by another node\n"
@@ -583,9 +569,10 @@ static void show_commands(void)
                "setoutfile name file  redirects debug output of module name to file\n"
                "irgname name          prints address and graph number of a method given by its name\n"
                "irgldname ldname      prints address and graph number of a method given by its ldname\n"
                "setoutfile name file  redirects debug output of module name to file\n"
                "irgname name          prints address and graph number of a method given by its name\n"
                "irgldname ldname      prints address and graph number of a method given by its ldname\n"
+               "initialnodenr n|rand  set initial node number to n or random number\n"
                "help                  list all commands\n"
                );
                "help                  list all commands\n"
                );
-}  /* show_commands */
+}
 
 /**
  * Shows all Firm breakpoints.
 
 /**
  * Shows all Firm breakpoints.
@@ -617,7 +604,7 @@ static void show_bp(void)
                dbg_printf(p->active ? "+enabled" : "+disabled");
        }
        dbg_printf(have_one ? "+\n" : "+ NONE\n");
                dbg_printf(p->active ? "+enabled" : "+disabled");
        }
        dbg_printf(have_one ? "+\n" : "+ NONE\n");
-}  /* show_bp */
+}
 
 /**
  * firm_dbg_register() expects that the name is stored persistent.
 
 /**
  * firm_dbg_register() expects that the name is stored persistent.
@@ -628,7 +615,7 @@ static firm_dbg_module_t *dbg_register(const char *name)
        ident *id = new_id_from_str(name);
 
        return firm_dbg_register(get_id_str(id));
        ident *id = new_id_from_str(name);
 
        return firm_dbg_register(get_id_str(id));
-}  /* dbg_register */
+}
 
 /**
  * Sets the debug mask of module name to lvl
 
 /**
  * Sets the debug mask of module name to lvl
@@ -642,7 +629,7 @@ static void set_dbg_level(const char *name, unsigned lvl)
 
                dbg_printf("Setting debug mask of module %s to %u\n", name, lvl);
        }
 
                dbg_printf("Setting debug mask of module %s to %u\n", name, lvl);
        }
-}  /* set_dbg_level */
+}
 
 /**
  * Redirects the debug output of module name to fname
 
 /**
  * Redirects the debug output of module name to fname
@@ -659,7 +646,7 @@ static void set_dbg_outfile(const char *name, const char *fname)
 
        firm_dbg_set_file(module, f);
        dbg_printf("Redirecting debug output of module %s to file %s\n", name, fname);
 
        firm_dbg_set_file(module, f);
        dbg_printf("Redirecting debug output of module %s to file %s\n", name, fname);
-}  /* set_dbg_outfile */
+}
 
 /**
  * Show info about a firm thing.
 
 /**
  * Show info about a firm thing.
@@ -677,10 +664,10 @@ static void show_firm_object(void *firm_thing)
                fprintf(f, "BAD: (%p)\n", firm_thing);
                break;
        case k_entity:
                fprintf(f, "BAD: (%p)\n", firm_thing);
                break;
        case k_entity:
-               dump_entity_to_file(f, firm_thing);
+               dump_entity_to_file(f, (ir_entity*)firm_thing);
                break;
        case k_type:
                break;
        case k_type:
-               dump_type_to_file(f, firm_thing);
+               dump_type_to_file(f, (ir_type*)firm_thing);
                break;
        case k_ir_graph:
        case k_ir_node:
                break;
        case k_ir_graph:
        case k_ir_node:
@@ -688,15 +675,13 @@ static void show_firm_object(void *firm_thing)
        case k_ir_op:
        case k_tarval:
        case k_ir_loop:
        case k_ir_op:
        case k_tarval:
        case k_ir_loop:
-       case k_ir_compound_graph_path:
-       case k_ir_extblk:
        case k_ir_prog:
                fprintf(f, "NIY\n");
                break;
        default:
                fprintf(f, "Cannot identify thing at (%p).\n", firm_thing);
        }
        case k_ir_prog:
                fprintf(f, "NIY\n");
                break;
        default:
                fprintf(f, "Cannot identify thing at (%p).\n", firm_thing);
        }
-}  /* show_firm_object */
+}
 
 /**
  * Find a firm type by its number.
 
 /**
  * Find a firm type by its number.
@@ -715,7 +700,7 @@ static ir_type *find_type_nr(long nr)
        if (get_type_nr(tp) == nr)
                return tp;
        return NULL;
        if (get_type_nr(tp) == nr)
                return tp;
        return NULL;
-}  /* find_type_nr */
+}
 
 /**
  * Find a firm type by its name.
 
 /**
  * Find a firm type by its name.
@@ -737,7 +722,7 @@ static ir_type *find_type_name(const char *name)
        if (strcmp(get_compound_name(tp), name) == 0)
                return tp;
        return NULL;
        if (strcmp(get_compound_name(tp), name) == 0)
                return tp;
        return NULL;
-}  /* find_type_name */
+}
 
 /** The environment for the entity search functions. */
 typedef struct find_env {
 
 /** The environment for the entity search functions. */
 typedef struct find_env {
@@ -753,27 +738,27 @@ typedef struct find_env {
  */
 static void check_ent_nr(type_or_ent tore, void *ctx)
 {
  */
 static void check_ent_nr(type_or_ent tore, void *ctx)
 {
-       find_env_t *env = ctx;
+       find_env_t *env = (find_env_t*)ctx;
 
        if (is_entity(tore.ent)) {
                if (get_entity_nr(tore.ent) == env->u.nr) {
                        env->res = tore.ent;
                }
        }
 
        if (is_entity(tore.ent)) {
                if (get_entity_nr(tore.ent) == env->u.nr) {
                        env->res = tore.ent;
                }
        }
-}  /* check_ent_nr */
+}
 
 /**
  * Type-walker: Find an entity with given name.
  */
 static void check_ent_name(type_or_ent tore, void *ctx)
 {
 
 /**
  * Type-walker: Find an entity with given name.
  */
 static void check_ent_name(type_or_ent tore, void *ctx)
 {
-       find_env_t *env = ctx;
+       find_env_t *env = (find_env_t*)ctx;
 
        if (is_entity(tore.ent))
                if (strcmp(get_entity_name(tore.ent), env->u.name) == 0) {
                        env->res = tore.ent;
                }
 
        if (is_entity(tore.ent))
                if (strcmp(get_entity_name(tore.ent), env->u.name) == 0) {
                        env->res = tore.ent;
                }
-}  /* check_ent_name */
+}
 
 /**
  * Find a firm entity by its number.
 
 /**
  * Find a firm entity by its number.
@@ -786,7 +771,7 @@ static ir_entity *find_entity_nr(long nr)
        env.res  = NULL;
        type_walk(check_ent_nr, NULL, &env);
        return env.res;
        env.res  = NULL;
        type_walk(check_ent_nr, NULL, &env);
        return env.res;
-}  /* find_entity_nr */
+}
 
 /**
  * Find a firm entity by its name.
 
 /**
  * Find a firm entity by its name.
@@ -799,7 +784,7 @@ static ir_entity *find_entity_name(const char *name)
        env.res    = NULL;
        type_walk(check_ent_name, NULL, &env);
        return env.res;
        env.res    = NULL;
        type_walk(check_ent_name, NULL, &env);
        return env.res;
-}  /* find_entity_name */
+}
 
 /**
  * Search methods for a name.
 
 /**
  * Search methods for a name.
@@ -828,7 +813,7 @@ static void show_by_name(type_or_ent tore, void *env)
                        }
                }
        }
                        }
                }
        }
-}  /* show_by_name */
+}
 
 /**
  * Search methods for a ldname.
 
 /**
  * Search methods for a ldname.
@@ -857,7 +842,7 @@ static void show_by_ldname(type_or_ent tore, void *env)
                        }
                }
        }
                        }
                }
        }
-}  /* show_by_ldname */
+}
 
 /**
  * prints the address and graph number of all irgs with given name
 
 /**
  * prints the address and graph number of all irgs with given name
@@ -867,7 +852,7 @@ static void irg_name(const char *name)
        ident *id = new_id_from_str(name);
 
        type_walk(show_by_name, NULL, (void *)id);
        ident *id = new_id_from_str(name);
 
        type_walk(show_by_name, NULL, (void *)id);
-}  /* irg_name */
+}
 
 /**
  * prints the address and graph number of all irgs with given ld_name
 
 /**
  * prints the address and graph number of all irgs with given ld_name
@@ -877,27 +862,29 @@ static void irg_ld_name(const char *name)
        ident *id = new_id_from_str(name);
 
        type_walk(show_by_ldname, NULL, (void *)id);
        ident *id = new_id_from_str(name);
 
        type_walk(show_by_ldname, NULL, (void *)id);
-}  /* irg_ld_name */
+}
 
 enum tokens {
 
 enum tokens {
-       tok_create = 256,
-       tok_replace,
+       first_token = 256,
+       tok_bp = first_token,
+       tok_create,
+       tok_disable,
+       tok_dumpfilter,
+       tok_enable,
+       tok_help,
+       tok_init,
+       tok_irgldname,
+       tok_irgname,
        tok_lower,
        tok_lower,
-       tok_remirg,
        tok_newent,
        tok_newent,
-       tok_newtype,
-       tok_showtype,
-       tok_showent,
-       tok_init,
-       tok_bp,
-       tok_enable,
-       tok_disable,
-       tok_setmask,
+       tok_remirg,
+       tok_replace,
        tok_setlvl,
        tok_setlvl,
+       tok_setmask,
        tok_setoutfile,
        tok_setoutfile,
-       tok_irgname,
-       tok_irgldname,
-       tok_help,
+       tok_showent,
+       tok_showtype,
+       tok_initialnodenr,
        tok_identifier,
        tok_number,
        tok_eof,
        tok_identifier,
        tok_number,
        tok_eof,
@@ -905,24 +892,25 @@ enum tokens {
 };
 
 static const char *reserved[] = {
 };
 
 static const char *reserved[] = {
+       "bp",
        "create",
        "create",
-       "replace",
+       "disable",
+       "dumpfilter",
+       "enable",
+       "help",
+       "init",
+       "irgldname",
+       "irgname",
        "lower",
        "lower",
-       "remirg",
        "newent",
        "newent",
-       "newtype",
-       "showtype",
-       "showent",
-       "init",
-       "bp",
-       "enable",
-       "disable",
-       "setmask",
+       "remirg",
+       "replace",
        "setlvl",
        "setlvl",
+       "setmask",
        "setoutfile",
        "setoutfile",
-       "irgname",
-       "irgldname",
-       "help"
+       "showent",
+       "showtype",
+       "initialnodenr",
 };
 
 /**
 };
 
 /**
@@ -933,7 +921,7 @@ static struct lexer {
        unsigned cur_token;   /**< current token. */
        unsigned number;      /**< current token attribute. */
        const char *s;        /**< current token attribute. */
        unsigned cur_token;   /**< current token. */
        unsigned number;      /**< current token attribute. */
        const char *s;        /**< current token attribute. */
-       unsigned len;         /**< current token attribute. */
+       size_t len;           /**< current token attribute. */
 
        const char *curr_pos;
        const char *end_pos;
 
        const char *curr_pos;
        const char *end_pos;
@@ -948,7 +936,7 @@ static void init_lexer(const char *input)
        lexer.has_token = 0;
        lexer.curr_pos  = input;
        lexer.end_pos   = input + strlen(input);
        lexer.has_token = 0;
        lexer.curr_pos  = input;
        lexer.end_pos   = input + strlen(input);
-}  /* init_lexer */
+}
 
 
 /**
 
 
 /**
@@ -959,9 +947,9 @@ static char next_char(void)
        if (lexer.curr_pos >= lexer.end_pos)
                return '\0';
        return *lexer.curr_pos++;
        if (lexer.curr_pos >= lexer.end_pos)
                return '\0';
        return *lexer.curr_pos++;
-}  /* next_char */
+}
 
 
-#define unput()                if (lexer.curr_pos < lexer.end_pos) --lexer.curr_pos
+#define unput()    if (lexer.curr_pos < lexer.end_pos) --lexer.curr_pos
 
 #undef MIN
 #define MIN(a, b) (a) < (b) ? (a) : (b)
 
 #undef MIN
 #define MIN(a, b) (a) < (b) ? (a) : (b)
@@ -972,15 +960,15 @@ static char next_char(void)
 static unsigned get_token(void)
 {
        char c;
 static unsigned get_token(void)
 {
        char c;
-       int i;
+       size_t i;
 
        /* skip white space */
        do {
                c = next_char();
 
        /* skip white space */
        do {
                c = next_char();
-       } while (c != '\0' && isspace(c));
+       } while (c != '\0' && isspace((unsigned char)c));
 
        lexer.tok_start = lexer.curr_pos - 1;
 
        lexer.tok_start = lexer.curr_pos - 1;
-       if (c == '.' || isalpha(c)) {
+       if (c == '.' || isalpha((unsigned char)c)) {
                /* command begins here */
                int         len = 0;
                const char* tok_start;
                /* command begins here */
                int         len = 0;
                const char* tok_start;
@@ -988,7 +976,7 @@ static unsigned get_token(void)
                do {
                        c = next_char();
                        ++len;
                do {
                        c = next_char();
                        ++len;
-               } while (isgraph(c));
+               } while (isgraph((unsigned char)c));
                unput();
 
                tok_start = lexer.tok_start;
                unput();
 
                tok_start = lexer.tok_start;
@@ -996,16 +984,16 @@ static unsigned get_token(void)
                        ++tok_start;
                        --len;
                }
                        ++tok_start;
                        --len;
                }
-               for (i = sizeof(reserved)/sizeof(reserved[0]) - 1; i >= 0; --i) {
+               for (i = ARRAY_SIZE(reserved); i-- != 0;) {
                        if (strncasecmp(tok_start, reserved[i], len) == 0 && reserved[i][len] == '\0')
                        if (strncasecmp(tok_start, reserved[i], len) == 0 && reserved[i][len] == '\0')
-                               return 256 + i;
+                               return first_token + i;
                }
 
                /* identifier */
                lexer.s   = lexer.tok_start;
                lexer.len = lexer.curr_pos - lexer.s;
                return tok_identifier;
                }
 
                /* identifier */
                lexer.s   = lexer.tok_start;
                lexer.len = lexer.curr_pos - lexer.s;
                return tok_identifier;
-       } else if (isdigit(c) || c == '-') {
+       } else if (isdigit((unsigned char)c) || c == '-') {
                unsigned number = 0;
                unsigned sign   = 0;
 
                unsigned number = 0;
                unsigned sign   = 0;
 
@@ -1022,12 +1010,12 @@ static unsigned get_token(void)
                                for (;;) {
                                        c = next_char();
 
                                for (;;) {
                                        c = next_char();
 
-                                       if (! isxdigit(c))
+                                       if (! isxdigit((unsigned char)c))
                                                break;
                                                break;
-                                       if (isdigit(c))
+                                       if (isdigit((unsigned char)c))
                                                number = (number << 4) | (c - '0');
                                        else
                                                number = (number << 4) | (c - '0');
                                        else
-                                               number = (number << 4) | (toupper(c) - 'A' + 10);
+                                               number = (number << 4) | (toupper((unsigned char)c) - 'A' + 10);
                                }
                                unput();
                                lexer.number = number;
                                }
                                unput();
                                lexer.number = number;
@@ -1035,7 +1023,7 @@ static unsigned get_token(void)
                        }
                }
                for (;;) {
                        }
                }
                for (;;) {
-                       if (! isdigit(c))
+                       if (! isdigit((unsigned char)c))
                                break;
                        number = number * 10 + (c - '0');
                        c = next_char();
                                break;
                        number = number * 10 + (c - '0');
                        c = next_char();
@@ -1047,12 +1035,12 @@ static unsigned get_token(void)
        else if (c == '\0')
                return tok_eof;
        return c;
        else if (c == '\0')
                return tok_eof;
        return c;
-}  /* get_token */
+}
 
 void firm_debug(const char *cmd)
 {
        char name[1024], fname[1024];
 
 void firm_debug(const char *cmd)
 {
        char name[1024], fname[1024];
-       int len;
+       size_t len;
 
        init_lexer(cmd);
 
 
        init_lexer(cmd);
 
@@ -1069,7 +1057,7 @@ void firm_debug(const char *cmd)
                        token = get_token();
                        if (token != tok_number)
                                goto error;
                        token = get_token();
                        if (token != tok_number)
                                goto error;
-                       break_on_nr(lexer.number, BP_ON_NEW_NODE);
+                       break_on_nr(lexer.number, BP_ON_NEW_THING);
                        break;
 
                case tok_replace:
                        break;
 
                case tok_replace:
@@ -1104,7 +1092,7 @@ void firm_debug(const char *cmd)
                        token = get_token();
 
                        if (token == tok_number)
                        token = get_token();
 
                        if (token == tok_number)
-                               break_on_nr(lexer.number, BP_ON_NEW_ENT);
+                               break_on_nr(lexer.number, BP_ON_NEW_THING);
                        else if (token == tok_identifier) {
                                len = MIN(lexer.len, 1023);
                                strncpy(name, lexer.s, len);
                        else if (token == tok_identifier) {
                                len = MIN(lexer.len, 1023);
                                strncpy(name, lexer.s, len);
@@ -1114,20 +1102,6 @@ void firm_debug(const char *cmd)
                                goto error;
                        break;
 
                                goto error;
                        break;
 
-               case tok_newtype:
-                       token = get_token();
-
-                       if (token == tok_number)
-                               break_on_nr(lexer.number, BP_ON_NEW_TYPE);
-                       else if (token == tok_identifier) {
-                               len = MIN(lexer.len, 1023);
-                               strncpy(name, lexer.s, len);
-                               name[len] = '\0';
-                               break_on_ident(name, BP_ON_NEW_TYPE);
-                       } else
-                               goto error;
-                       break;
-
                case tok_showtype:
                        token = get_token();
 
                case tok_showtype:
                        token = get_token();
 
@@ -1221,6 +1195,7 @@ void firm_debug(const char *cmd)
                        strncpy(fname, lexer.s, len);
                        fname[len] = '\0';
                        set_dbg_outfile(name, fname);
                        strncpy(fname, lexer.s, len);
                        fname[len] = '\0';
                        set_dbg_outfile(name, fname);
+                       break;
 
                case tok_irgname:
                        token = get_token();
 
                case tok_irgname:
                        token = get_token();
@@ -1230,6 +1205,20 @@ void firm_debug(const char *cmd)
                        strncpy(name, lexer.s, len);
                        name[len] = '\0';
                        irg_name(name);
                        strncpy(name, lexer.s, len);
                        name[len] = '\0';
                        irg_name(name);
+                       break;
+
+               case tok_initialnodenr:
+                       token = get_token();
+                       if (token == tok_number) {
+                               dbg_printf("Setting initial node number to %u\n", lexer.number);
+                               irp->max_node_nr = lexer.number;
+                       } else if (token == tok_identifier && !strcmp(lexer.s, "rand")) {
+                               dbg_printf("Randomizing initial node number\n");
+                               srand(time(0));
+                               irp->max_node_nr += rand() % 6666;
+                       } else
+                               goto error;
+                       break;
 
                case tok_irgldname:
                        token = get_token();
 
                case tok_irgldname:
                        token = get_token();
@@ -1241,6 +1230,16 @@ void firm_debug(const char *cmd)
                        irg_ld_name(name);
                        break;
 
                        irg_ld_name(name);
                        break;
 
+               case tok_dumpfilter:
+                       token = get_token();
+                       if (token != tok_identifier)
+                               goto error;
+                       len = MIN(lexer.len, 1023);
+                       strncpy(name, lexer.s, len);
+                       name[len] = '\0';
+                       ir_set_dump_filter(name);
+                       break;
+
                case tok_help:
                        show_commands();
                        break;
                case tok_help:
                        show_commands();
                        break;
@@ -1261,7 +1260,7 @@ error:
        }
 leave:
        ;
        }
 leave:
        ;
-}  /* firm_debug */
+}
 
 void firm_init_debugger(void)
 {
 
 void firm_init_debugger(void)
 {
@@ -1279,7 +1278,13 @@ void firm_init_debugger(void)
 
        if (break_on_init)
                firm_debug_break();
 
        if (break_on_init)
                firm_debug_break();
-}  /* firm_init_debugger */
+}
+
+void firm_finish_debugger(void)
+{
+       del_set(bp_numbers);
+       del_set(bp_idents);
+}
 
 /**
  * A gdb helper function to print firm objects.
 
 /**
  * A gdb helper function to print firm objects.
@@ -1304,7 +1309,6 @@ const char *gdb_out_edge_helper(const ir_node *node)
        char *b = buf;
        size_t l;
        size_t len = sizeof(buf);
        char *b = buf;
        size_t l;
        size_t len = sizeof(buf);
-       const ir_edge_t *edge;
        foreach_out_edge(node, edge) {
                ir_node *n = get_edge_src_irn(edge);
 
        foreach_out_edge(node, edge) {
                ir_node *n = get_edge_src_irn(edge);