speedup for cycle
[libfirm] / ir / debug / debugger.c
index d0009b6..c9ea709 100644 (file)
@@ -13,7 +13,7 @@
 #include "config.h"
 #endif
 
-#ifndef NDEBUG
+#ifdef DEBUG_libfirm
 
 #ifdef _WIN32
 #define WIN32_LEAN_AND_MEAN
@@ -312,7 +312,7 @@ static void dbg_free_graph(void *ctx, ir_graph *irg)
   }
   {
     bp_ident_t key, *elem;
-    entity *ent = get_irg_entity(irg);
+    ir_entity *ent = get_irg_entity(irg);
 
     if (! ent)
       return;
@@ -334,7 +334,7 @@ static void dbg_free_graph(void *ctx, ir_graph *irg)
  * @param ctx   the hook context
  * @param ent   the newly created entity
  */
-static void dbg_new_entity(void *ctx, entity *ent)
+static void dbg_new_entity(void *ctx, ir_entity *ent)
 {
   {
     bp_ident_t key, *elem;
@@ -573,6 +573,8 @@ static void show_commands(void) {
     ".setmask name msk      sets the debug module name to mask msk\n"
     ".setlvl  name lvl      sets the debug module name to level lvl\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"
     ".help                  list all commands\n"
   );
 }  /* show_commands */
@@ -727,14 +729,14 @@ typedef struct find_env {
     long        nr;   /**< the number that is searched for */
     const char *name; /**< the name that is searched for */
   } u;
-  entity *res;        /**< the result */
+  ir_entity *res;     /**< the result */
 } find_env_t;
 
 /**
  * Type-walker: Find an entity with given number.
  */
 static void check_ent_nr(type_or_ent *tore, void *ctx) {
-  entity *ent = (entity *)tore;
+  ir_entity *ent = (ir_entity *)tore;
   find_env_t *env = ctx;
 
   if (is_entity(ent))
@@ -747,7 +749,7 @@ static void check_ent_nr(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) {
-  entity *ent = (entity *)tore;
+  ir_entity *ent = (ir_entity *)tore;
   find_env_t *env = ctx;
 
   if (is_entity(ent))
@@ -759,7 +761,7 @@ static void check_ent_name(type_or_ent *tore, void *ctx) {
 /**
  * Find a firm entity by its number.
  */
-static entity *find_entity_nr(long nr) {
+static ir_entity *find_entity_nr(long nr) {
   find_env_t env;
 
   env.u.nr = nr;
@@ -771,7 +773,7 @@ static entity *find_entity_nr(long nr) {
 /**
  * Find a firm entity by its name.
  */
-static entity *find_entity_name(const char *name) {
+static ir_entity *find_entity_name(const char *name) {
   find_env_t env;
 
   env.u.name = name;
@@ -780,6 +782,80 @@ static entity *find_entity_name(const char *name) {
   return env.res;
 }  /* find_entity_name */
 
+/**
+ * Search methods for a name.
+ */
+static void show_by_name(type_or_ent *tore, void *env) {
+  ident *id = (ident *)env;
+
+  if (is_entity(tore)) {
+    ir_entity *ent = (ir_entity *)tore;
+
+    if (is_method_entity(ent)) {
+      if (get_entity_ident(ent) == id) {
+        ir_type *owner = get_entity_owner(ent);
+        ir_graph *irg = get_entity_irg(ent);
+
+        if (owner != get_glob_type()) {
+          printf("%s::%s", get_type_name(owner), get_id_str(id));
+        } else {
+          printf("%s", get_id_str(id));
+        }
+        if (irg)
+          printf("[%ld] (%p)\n", get_irg_graph_nr(irg), irg);
+        else
+          printf(" NULL\n");
+      }
+    }
+  }
+}  /* show_by_name */
+
+/**
+ * Search methods for a ldname.
+ */
+static void show_by_ldname(type_or_ent *tore, void *env) {
+  ident *id = (ident *)env;
+
+  if (is_entity(tore)) {
+    ir_entity *ent = (ir_entity *)tore;
+
+    if (is_method_entity(ent)) {
+      if (get_entity_ld_ident(ent) == id) {
+        ir_type *owner = get_entity_owner(ent);
+        ir_graph *irg = get_entity_irg(ent);
+
+        if (owner != get_glob_type()) {
+          printf("%s::%s", get_type_name(owner), get_id_str(id));
+        } else {
+          printf("%s", get_id_str(id));
+        }
+        if (irg)
+          printf("[%ld] (%p)\n", get_irg_graph_nr(irg), irg);
+        else
+          printf(" NULL\n");
+      }
+    }
+  }
+}  /* show_by_ldname */
+
+/**
+ * prints the address and graph number of all irgs with given name
+ */
+static void irg_name(const char *name) {
+  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
+ */
+static void irg_ld_name(const char *name) {
+  ident *id = new_id_from_str(name);
+
+  type_walk(show_by_ldname, NULL, (void *)id);
+}  /* irg_ld_name */
+
 /**
  * High level function to use from debugger interface
  *
@@ -848,6 +924,10 @@ void firm_debug(const char *cmd) {
     set_dbg_level(name, (1 << lvl) - 1);
   else if (sscanf(cmd, ".setoutfile %s %s\n", name, fname) == 2)
     set_dbg_outfile(name, fname);
+  else if (sscanf(cmd, ".irgname %s\n", name) == 1)
+    irg_name(name);
+  else if (sscanf(cmd, ".irgldname %s\n", name) == 1)
+    irg_ld_name(name);
   else {
     show_commands();
   }
@@ -975,6 +1055,14 @@ static int _firm_only_that_you_can_compile_with_NDEBUG_defined;
  *
  * Redirects debug output of module name to file.
  *
+ * @b .irgname name
+ *
+ * Prints address and graph number of a method given by its name.
+ *
+ * @b .irgldname name
+ *
+ * Prints address and graph number of a method given by its linker name.
+ *
  * @b .help
  *
  * List all commands.