Add the column to the debug information.
authorChristoph Mallon <christoph.mallon@gmx.de>
Tue, 24 Apr 2012 18:42:40 +0000 (20:42 +0200)
committerChristoph Mallon <christoph.mallon@gmx.de>
Tue, 24 Apr 2012 18:51:56 +0000 (20:51 +0200)
include/libfirm/dbginfo.h
ir/be/bedwarf.c
ir/be/beemitter.c
ir/be/bestabs.c
ir/debug/dbginfo.c

index 785fb6e..dee59b4 100644 (file)
@@ -144,13 +144,20 @@ typedef void merge_sets_func(ir_node **new_node_array, int new_num_entries, ir_n
 FIRM_API void dbg_init(merge_pair_func *dbg_info_merge_pair,
                        merge_sets_func *dbg_info_merge_sets);
 
+typedef struct src_loc_t {
+       char const *file;
+       unsigned    line;
+       unsigned    column;
+} src_loc_t;
+
 /**
  * The type of the debug info retriever function.
- *  When given a dbg_info returns the name (usually the filename) of the
- *  compilation unit defining it. @p line is set to the line number of the
- *  definition.
+ *  When given a dbg_info returns the name (usually the filename), line number
+ *  and column number of the definition.
+ *  Any part of the returned information may be NULL/0, which means it is not
+ *  available.
  */
-typedef const char *(*retrieve_dbg_func)(const dbg_info *dbg, unsigned *line);
+typedef src_loc_t (*retrieve_dbg_func)(dbg_info const *dbg);
 
 /**
  * Sets a debug info retriever.
@@ -175,7 +182,7 @@ FIRM_API void ir_set_type_debug_retrieve(retrieve_type_dbg_func func);
 /**
  * Retrieve the debug info.
  */
-FIRM_API const char *ir_retrieve_dbg_info(const dbg_info *dbg, unsigned *line);
+FIRM_API src_loc_t ir_retrieve_dbg_info(dbg_info const *dbg);
 
 /**
  * Retrieve type debug info
index 62d7cfc..5c7fa64 100644 (file)
@@ -637,21 +637,15 @@ static void emit_pubnames(dwarf_t *env)
 
 static void dwarf_set_dbg_info(dbg_handle *h, dbg_info *dbgi)
 {
-       dwarf_t *env = (dwarf_t*) h;
-       const char *filename;
-       unsigned    lineno;
-       unsigned    column = 0;
-       unsigned    filenum;
+       dwarf_t  *const env = (dwarf_t*)h;
+       src_loc_t const loc = ir_retrieve_dbg_info(dbgi);
+       unsigned        filenum;
 
-       if (dbgi == NULL)
+       if (!loc.file)
                return;
 
-       filename = ir_retrieve_dbg_info(dbgi, &lineno);
-       if (filename == NULL)
-               return;
-       filenum = insert_file(env, filename);
-
-       be_emit_irprintf("\t.loc %u %u %u\n", filenum, lineno, column);
+       filenum = insert_file(env, loc.file);
+       be_emit_irprintf("\t.loc %u %u %u\n", filenum, loc.line, loc.column);
        be_emit_write_line();
 }
 
@@ -674,25 +668,10 @@ static void emit_entity_label(const ir_entity *entity)
  */
 static void emit_dbginfo(dwarf_t *env, const dbg_info *dbgi)
 {
-       const char *filename;
-       unsigned line;
-       unsigned file;
-
-       if (dbgi == NULL) {
-               emit_uleb128(0);
-               emit_uleb128(0);
-               return;
-       }
-       filename = ir_retrieve_dbg_info(dbgi, &line);
-       if (filename == NULL) {
-               emit_uleb128(0);
-               emit_uleb128(0);
-               return;
-       }
-
-       file = insert_file(env, filename);
+       src_loc_t const loc  = ir_retrieve_dbg_info(dbgi);
+       unsigned  const file = loc.file ? insert_file(env, loc.file) : 0;
        emit_uleb128(file);
-       emit_uleb128(line);
+       emit_uleb128(loc.line);
 }
 
 static void emit_subprogram_abbrev(void)
index 9b2d6a0..ae35cfb 100644 (file)
@@ -100,8 +100,7 @@ void be_emit_pad_comment(void)
 void be_emit_finish_line_gas(const ir_node *node)
 {
        dbg_info   *dbg;
-       const char *sourcefile;
-       unsigned    lineno;
+       src_loc_t   loc;
 
        if (node == NULL) {
                be_emit_char('\n');
@@ -113,11 +112,16 @@ void be_emit_finish_line_gas(const ir_node *node)
        be_emit_cstring("/* ");
        be_emit_irprintf("%+F ", node);
 
-       dbg        = get_irn_dbg_info(node);
-       sourcefile = ir_retrieve_dbg_info(dbg, &lineno);
-       if (sourcefile != NULL) {
-               be_emit_string(sourcefile);
-               be_emit_irprintf(":%u", lineno);
+       dbg = get_irn_dbg_info(node);
+       loc = ir_retrieve_dbg_info(dbg);
+       if (loc.file) {
+               be_emit_string(loc.file);
+               if (loc.line != 0) {
+                       be_emit_irprintf(":%u", loc.line);
+                       if (loc.column != 0) {
+                               be_emit_irprintf(":%u", loc.column);
+                       }
+               }
        }
        be_emit_cstring(" */\n");
        be_emit_write_line();
index a385da5..ca8d7ad 100644 (file)
@@ -661,28 +661,26 @@ static void stabs_unit_end(dbg_handle *handle)
 
 static void stabs_set_dbg_info(dbg_handle *h, dbg_info *dbgi)
 {
-       stabs_handle *handle = (stabs_handle*) h;
-       unsigned      lineno;
-       const char   *fname  = ir_retrieve_dbg_info(dbgi, &lineno);
+       stabs_handle *const handle = (stabs_handle*) h;
+       src_loc_t     const loc    = ir_retrieve_dbg_info(dbgi);
 
-       if (fname == NULL)
+       if (!loc.file)
                return;
 
-       if (handle->curr_file != fname) {
-               if (fname != handle->main_file) {
-                       be_emit_irprintf("\t.stabs\t\"%s\",%d,0,0,0\n", fname, N_SOL);
+       if (handle->curr_file != loc.file) {
+               if (handle->main_file != loc.file) {
+                       be_emit_irprintf("\t.stabs\t\"%s\",%d,0,0,0\n", loc.file, N_SOL);
                        be_emit_write_line();
                }
-               handle->curr_file = fname;
+               handle->curr_file = loc.file;
        }
-       if (handle->last_line != lineno) {
+       if (handle->last_line != loc.line) {
                char label[64];
 
                snprintf(label, sizeof(label), ".LM%u", ++handle->label_num);
-               handle->last_line = lineno;
+               handle->last_line = loc.line;
 
-               be_emit_irprintf("\t.stabn\t%d, 0, %u, %s-%s\n", N_SLINE, lineno,
-                                label, get_entity_ld_name(handle->cur_ent));
+               be_emit_irprintf("\t.stabn\t%d, 0, %u, %s-%s\n", N_SLINE, loc.line, label, get_entity_ld_name(handle->cur_ent));
                be_emit_write_line();
 
                be_emit_string(label);
index 139391f..a9b000f 100644 (file)
@@ -100,22 +100,25 @@ void default_dbg_info_merge_sets(ir_node **new_nodes, int n_new_nodes,
        }
 }
 
+static src_loc_t default_retrieve_dbg(dbg_info const *const dbg)
+{
+       (void)dbg;
+       src_loc_t const loc = { NULL, 0, 0 };
+       return loc;
+}
+
 /** The debug info retriever function. */
-static retrieve_dbg_func      retrieve_dbg      = NULL;
+static retrieve_dbg_func      retrieve_dbg      = default_retrieve_dbg;
 static retrieve_type_dbg_func retrieve_type_dbg = NULL;
 
 void ir_set_debug_retrieve(retrieve_dbg_func func)
 {
-       retrieve_dbg = func;
+       retrieve_dbg = func ? func : default_retrieve_dbg;
 }
 
-const char *ir_retrieve_dbg_info(const dbg_info *dbg, unsigned *line)
+src_loc_t ir_retrieve_dbg_info(dbg_info const *const dbg)
 {
-       if (retrieve_dbg)
-               return retrieve_dbg(dbg, line);
-
-       *line = 0;
-       return NULL;
+       return retrieve_dbg(dbg);
 }
 
 void ir_set_type_debug_retrieve(retrieve_type_dbg_func func)
@@ -135,13 +138,16 @@ void ir_retrieve_type_dbg_info(char *buffer, size_t buffer_size,
 
 void ir_dbg_info_snprint(char *buf, size_t bufsize, const dbg_info *dbg)
 {
-       unsigned    line;
-       const char *source = ir_retrieve_dbg_info(dbg, &line);
+       src_loc_t const loc = ir_retrieve_dbg_info(dbg);
 
-       if (source == NULL) {
+       if (!loc.file) {
                assert(bufsize > 0);
                buf[0] = 0;
                return;
        }
-       snprintf(buf, bufsize, "%s:%u", source, line);
+       if (loc.column == 0) {
+               snprintf(buf, bufsize, "%s:%u", loc.file, loc.line);
+       } else {
+               snprintf(buf, bufsize, "%s:%u:%u", loc.file, loc.line, loc.column);
+       }
 }