On 05/01/2015 06:56 PM, David Malcolm wrote:
As a relative newcomer to GCC, one of the issues I had was
becoming comfortable with the linemap API and its internal
representation.

To familiarize myself with it, I wrote a dumping routine
to try to visualize how the source_location space is carved
up between line maps, and what each number can mean.

It struck me that this would benefit others, so this patch
adds this visualization, via an undocumented option
-fdump-locations, and adds a text file to libcpp's sources
documenting a simple example of compiling a small C file,
with a header and macro expansions (built using the
-fdump-locations option and a little hand-editing).

gcc/ChangeLog:
        * common.opt (fdump-locations): New option.
        * input.c: Include diagnostic-core.h.
        (get_end_location): New function.
        (write_digit): New function.
        (write_digit_row): New function.
        (dump_location_range): New function.
        (dump_labelled_location_range): New function.
        (dump_location_info): New function.
        * input.h (dump_location_info): New prototype.
        * toplev.c (compile_file): Handle flag_dump_locations.

libcpp/ChangeLog:
        * include/line-map.h (source_location): Add a reference to
        location-example.txt to the descriptive comment.
        * location-example.txt: New file.
Maybe "dump-internal-locations"? Not sure I want to bikeshed on the name any more than that. If you feel strongly about the option name, then I won't stress about it.



+void
+dump_location_info (FILE *stream)
+{
+  if (0)
+    line_table_dump (stream,
+                    line_table,
+                    LINEMAPS_ORDINARY_USED (line_table),
+                    LINEMAPS_MACRO_USED (line_table));
Should the if (0) code go away?

+
+  /* A brute-force visualization: emit a warning at every location.  */
+  if (0)
+    for (source_location loc = 0; loc < line_table->highest_location; loc++)
+      warning_at (loc, 0, "this is location %i", loc);
+      /* Alternatively, we could use inform (), though this
+        also shows lots of locations in stdc-predef.h */
And again.


So I think with removing the if (0) code and the possible option name change this is good to go.

Jeff

Reply via email to