we can do without the odd align.h
[libfirm] / ir / debug / debugger.c
index 4bb9d89..5969687 100644 (file)
@@ -33,6 +33,8 @@
 #include <windows.h>
 #endif
 
+#include "debugger.h"
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <signal.h>
 
 #ifdef _WIN32
 /* Break into the debugger. The Win32 way. */
-void firm_debug_break(void) {
+void firm_debug_break(void)
+{
        DebugBreak();
 }
 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64))
 /* Break into the debugger. The ia32/x86_64 way under GCC. */
-void firm_debug_break(void) {
+void firm_debug_break(void)
+{
        __asm__ __volatile__("int3");
 }
 #else
 /* Break into the debugger. Poor Unix way. */
-void firm_debug_break(void) {
+void firm_debug_break(void)
+{
        raise(SIGINT);
 }
 #endif /* _WIN32 */
@@ -160,14 +165,14 @@ static int is_active = 0;
 do {                                      \
        debugger_hooks[h].hook._##h = fkt;    \
        register_hook(h, &debugger_hooks[h]); \
-} while(0)
+} while (0)
 
 /** unhook the hook h */
 #define UNHOOK(h) \
 do {                                        \
        unregister_hook(h, &debugger_hooks[h]); \
        debugger_hooks[h].hook._##h = NULL;     \
-} while(0)
+} while (0)
 
 /** returns non-zero if a entry hook h is used */
 #define IS_HOOKED(h) (debugger_hooks[h].hook._##h != NULL)
@@ -182,36 +187,29 @@ do {                                        \
 #define FIRM_DBG_MINOR  0
 
 /** for automatic detection of the debug extension */
-static const char firm_debug_info_string[] =
+static const char __attribute__((used)) firm_debug_info_string[] =
        API_VERSION(FIRM_DBG_MAJOR, FIRM_DBG_MINOR);
 
-/**
- * Returns non-zero, if the debug extension is active
- */
-int firm_debug_active(void) {
+int firm_debug_active(void)
+{
        return is_active;
 }  /* firm_debug_active */
 
 /**
  * Reset the debug text buffer.
  */
-static void reset_dbg_buf(void) {
+static void reset_dbg_buf(void)
+{
        firm_dbg_msg_buf[0] = '\0';
 }  /* reset_dbg_buf */
 
-/**
- * Add text to the debug text buffer.
- */
-static void add_to_dbg_buf(const char *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 */
 
-/**
- * Return the content of the debug text buffer.
- *
- * To be called from the debugger.
- */
-const char *firm_debug_text(void) {
+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 */
@@ -466,7 +464,7 @@ static void update_hooks(breakpoint *bp)
                CASE_ON(BP_ON_NEW_ENT, new_entity);
                CASE_ON(BP_ON_NEW_TYPE, new_type);
                default:
-                       ;
+                       break;
                }
        }
        else {
@@ -479,7 +477,7 @@ static void update_hooks(breakpoint *bp)
                CASE_OFF(BP_ON_NEW_ENT, new_entity);
                CASE_OFF(BP_ON_NEW_TYPE, new_type);
                default:
-                       ;
+                       break;
                }
        }
 #undef CASE_ON
@@ -516,7 +514,8 @@ static void break_on_nr(long nr, bp_reasons_t reason)
 /**
  * Break if ident name is reached.
  */
-static void break_on_ident(const char *name, bp_reasons_t reason) {
+static void break_on_ident(const char *name, bp_reasons_t reason)
+{
        bp_ident_t key, *elem;
 
        key.bp.kind   = BP_IDENT;
@@ -564,7 +563,8 @@ static void bp_activate(unsigned bp, int active)
 /**
  * Show a list of supported commands
  */
-static void show_commands(void) {
+static void show_commands(void)
+{
        dbg_printf("Internal Firm debugger extension $Revision$ commands:\n"
                "init                  break after initialization\n"
                "create nr             break if node nr was created\n"
@@ -590,7 +590,8 @@ static void show_commands(void) {
 /**
  * Shows all Firm breakpoints.
  */
-static void show_bp(void) {
+static void show_bp(void)
+{
        breakpoint *p;
        bp_nr_t  *node_p;
        bp_ident_t *ident_p;
@@ -622,7 +623,8 @@ static void show_bp(void) {
  * firm_dbg_register() expects that the name is stored persistent.
  * So we need this little helper function
  */
-static firm_dbg_module_t *dbg_register(const char *name) {
+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));
@@ -662,7 +664,8 @@ static void set_dbg_outfile(const char *name, const char *fname)
 /**
  * Show info about a firm thing.
  */
-static void show_firm_object(void *firm_thing) {
+static void show_firm_object(void *firm_thing)
+{
        FILE *f = stdout;
 
        if (firm_thing == NULL) {
@@ -698,7 +701,8 @@ static void show_firm_object(void *firm_thing) {
 /**
  * Find a firm type by its number.
  */
-static ir_type *find_type_nr(long nr) {
+static ir_type *find_type_nr(long nr)
+{
        int i, n = get_irp_n_types();
        ir_type *tp;
 
@@ -716,7 +720,8 @@ static ir_type *find_type_nr(long nr) {
 /**
  * Find a firm type by its name.
  */
-static ir_type *find_type_name(const char *name) {
+static ir_type *find_type_name(const char *name)
+{
        int i, n = get_irp_n_types();
        ir_type *tp;
 
@@ -746,7 +751,8 @@ typedef struct find_env {
 /**
  * Type-walker: Find an entity with given number.
  */
-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;
 
        if (is_entity(tore.ent)) {
@@ -759,7 +765,8 @@ 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) {
+static void check_ent_name(type_or_ent tore, void *ctx)
+{
        find_env_t *env = ctx;
 
        if (is_entity(tore.ent))
@@ -771,7 +778,8 @@ static void check_ent_name(type_or_ent tore, void *ctx) {
 /**
  * Find a firm entity by its number.
  */
-static ir_entity *find_entity_nr(long nr) {
+static ir_entity *find_entity_nr(long nr)
+{
        find_env_t env;
 
        env.u.nr = nr;
@@ -783,7 +791,8 @@ static ir_entity *find_entity_nr(long nr) {
 /**
  * Find a firm entity by its name.
  */
-static ir_entity *find_entity_name(const char *name) {
+static ir_entity *find_entity_name(const char *name)
+{
        find_env_t env;
 
        env.u.name = name;
@@ -795,7 +804,8 @@ static ir_entity *find_entity_name(const char *name) {
 /**
  * Search methods for a name.
  */
-static void show_by_name(type_or_ent tore, void *env) {
+static void show_by_name(type_or_ent tore, void *env)
+{
        ident *id = (ident *)env;
 
        if (is_entity(tore.ent)) {
@@ -823,7 +833,8 @@ static void show_by_name(type_or_ent tore, void *env) {
 /**
  * Search methods for a ldname.
  */
-static void show_by_ldname(type_or_ent tore, void *env) {
+static void show_by_ldname(type_or_ent tore, void *env)
+{
        ident *id = (ident *)env;
 
        if (is_entity(tore.ent)) {
@@ -851,7 +862,8 @@ static void show_by_ldname(type_or_ent tore, void *env) {
 /**
  * prints the address and graph number of all irgs with given name
  */
-static void irg_name(const char *name) {
+static void irg_name(const char *name)
+{
        ident *id = new_id_from_str(name);
 
        type_walk(show_by_name, NULL, (void *)id);
@@ -860,7 +872,8 @@ static void irg_name(const char *name) {
 /**
  * prints the address and graph number of all irgs with given ld_name
  */
-static void irg_ld_name(const char *name) {
+static void irg_ld_name(const char *name)
+{
        ident *id = new_id_from_str(name);
 
        type_walk(show_by_ldname, NULL, (void *)id);
@@ -930,7 +943,8 @@ static struct lexer {
 /**
  * Initialize the lexer.
  */
-static void init_lexer(const char *input) {
+static void init_lexer(const char *input)
+{
        lexer.has_token = 0;
        lexer.curr_pos  = input;
        lexer.end_pos   = input + strlen(input);
@@ -940,7 +954,8 @@ static void init_lexer(const char *input) {
 /**
  * Get the next char from the input.
  */
-static char next_char(void) {
+static char next_char(void)
+{
        if (lexer.curr_pos >= lexer.end_pos)
                return '\0';
        return *lexer.curr_pos++;
@@ -954,7 +969,8 @@ static char next_char(void) {
 /**
  * The lexer.
  */
-static unsigned get_token(void) {
+static unsigned get_token(void)
+{
        char c;
        int i;
 
@@ -1033,12 +1049,8 @@ static unsigned get_token(void) {
        return c;
 }  /* get_token */
 
-/**
- * High level function to use from debugger interface
- *
- * See show_commands() for supported commands.
- */
-void firm_debug(const char *cmd) {
+void firm_debug(const char *cmd)
+{
        char name[1024], fname[1024];
        int len;
 
@@ -1251,7 +1263,6 @@ leave:
        ;
 }  /* firm_debug */
 
-/* creates the debugger tables */
 void firm_init_debugger(void)
 {
        char *env;
@@ -1273,22 +1284,22 @@ void firm_init_debugger(void)
 /**
  * A gdb helper function to print firm objects.
  */
-const char *gdb_node_helper(void *firm_object) {
+const char *gdb_node_helper(void *firm_object)
+{
        static char buf[1024];
        ir_snprintf(buf, sizeof(buf), "%+F", firm_object);
        return buf;
 }
 
-/**
- * A gdb helper function to print tarvals.
- */
-const char *gdb_tarval_helper(void *tv_object) {
+const char *gdb_tarval_helper(void *tv_object)
+{
        static char buf[1024];
        ir_snprintf(buf, sizeof(buf), "%+T", tv_object);
        return buf;
 }
 
-const char *gdb_out_edge_helper(const ir_node *node) {
+const char *gdb_out_edge_helper(const ir_node *node)
+{
        static char buf[4*1024];
        char *b = buf;
        size_t l;