aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2015-05-13 13:58:18 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2015-05-13 13:58:18 +0000
commitba4ad400f1e4f726adb431aedea3c0ddf1e3315a (patch)
tree263b351fcddaa726d296fc21e6f1f001c2221d5e /libcpp
parent49d50b6b8f727b681410a1865aadd915a14df2a5 (diff)
downloadgcc-ba4ad400f1e4f726adb431aedea3c0ddf1e3315a.zip
gcc-ba4ad400f1e4f726adb431aedea3c0ddf1e3315a.tar.gz
gcc-ba4ad400f1e4f726adb431aedea3c0ddf1e3315a.tar.bz2
libcpp/input.c: Add a way to visualize the linemaps (-fdump-internal-locations)
gcc/ChangeLog: * common.opt (fdump-internal-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. From-SVN: r223163
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog6
-rw-r--r--libcpp/include/line-map.h4
-rw-r--r--libcpp/location-example.txt216
3 files changed, 225 insertions, 1 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index 229ffd3..32582dd 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,5 +1,11 @@
2015-05-13 David Malcolm <dmalcolm@redhat.com>
+ * include/line-map.h (source_location): Add a reference to
+ location-example.txt to the descriptive comment.
+ * location-example.txt: New file.
+
+2015-05-13 David Malcolm <dmalcolm@redhat.com>
+
* include/line-map.h (MAX_SOURCE_LOCATION): Convert from a macro
to a const source_location.
(RESERVED_LOCATION_COUNT): Likewise.
diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index 86a33f1..27aa094 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -113,7 +113,9 @@ typedef unsigned int linenum_type;
... | |
0xffffffff | UINT_MAX |
-----------+-------------------------------+-------------------------------
- . */
+
+ To see how this works in practice, see the worked example in
+ libcpp/location-example.txt. */
typedef unsigned int source_location;
/* Memory allocation function typedef. Works like xrealloc. */
diff --git a/libcpp/location-example.txt b/libcpp/location-example.txt
new file mode 100644
index 0000000..a5f95b2
--- /dev/null
+++ b/libcpp/location-example.txt
@@ -0,0 +1,216 @@
+Consider compiling test.c, with this content:
+VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
+#include "test.h"
+
+int
+main (int argc, char **argv)
+{
+ int a = PLUS (1,2);
+ int b = PLUS (3,4);
+ return 0;
+}
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+...where test.h has this content:
+VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
+extern int foo ();
+
+#define PLUS(A, B) A + B
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+
+The undocumented -fdump-internal-locations option outputs this information
+to stderr, showing what each source_location value means. Source code
+lines are quoted, showing both per-line source_location values and
+per-line&column source_location values (written vertically under the
+corresponding character of source code).
+
+VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
+RESERVED LOCATIONS
+ source_location interval: 0 <= loc < 2
+
+ORDINARY MAP: 0
+ source_location interval: 2 <= loc < 3
+ file: test.c
+ starting at line: 1
+ column bits: 7
+test.c: 1|loc: 2|#include "test.h"
+ |00000001111111111
+ |34567890123456789
+
+ORDINARY MAP: 1
+ source_location interval: 3 <= loc < 4
+ file: <built-in>
+ starting at line: 0
+ column bits: 0
+
+ORDINARY MAP: 2
+ source_location interval: 4 <= loc < 5
+ file: <command-line>
+ starting at line: 0
+ column bits: 0
+
+ORDINARY MAP: 3
+ source_location interval: 5 <= loc < 5005
+ file: /usr/include/stdc-predef.h
+ starting at line: 1
+ column bits: 7
+(contents of /usr/include/stdc-predef.h snipped for brevity)
+
+ORDINARY MAP: 4
+ source_location interval: 5005 <= loc < 5006
+ file: <command-line>
+ starting at line: 1
+ column bits: 7
+
+ORDINARY MAP: 5
+ source_location interval: 5006 <= loc < 5134
+ file: test.c
+ starting at line: 1
+ column bits: 7
+test.c: 1|loc: 5006|#include "test.h"
+ |55555555555555555
+ |00000000000000000
+ |00011111111112222
+ |78901234567890123
+
+ORDINARY MAP: 6
+ source_location interval: 5134 <= loc < 5416
+ file: test.h
+ starting at line: 1
+ column bits: 7
+test.h: 1|loc: 5134|extern int foo ();
+ |555555555555555555
+ |111111111111111111
+ |333334444444444555
+ |567890123456789012
+test.h: 2|loc: 5262|
+ |
+ |
+ |
+ |
+test.h: 3|loc: 5390|#define PLUS(A, B) A + B
+ |555555555555555555555555
+ |333333333444444444444444
+ |999999999000000000011111
+ |123456789012345678901234
+
+ORDINARY MAP: 7
+ source_location interval: 5416 <= loc < 6314
+ file: test.c
+ starting at line: 2
+ column bits: 7
+test.c: 2|loc: 5416|
+ |
+ |
+ |
+ |
+test.c: 3|loc: 5544|int
+ |555
+ |555
+ |444
+ |567
+test.c: 4|loc: 5672|main (int argc, char **argv)
+ |5555555555555555555555555555
+ |6666666666666666666666666667
+ |7777777888888888899999999990
+ |3456789012345678901234567890
+test.c: 5|loc: 5800|{
+ |5
+ |8
+ |0
+ |1
+test.c: 6|loc: 5928| int a = PLUS (1,2);
+ |555555555555555555555
+ |999999999999999999999
+ |233333333334444444444
+ |901234567890123456789
+test.c: 7|loc: 6056| int b = PLUS (3,4);
+ |666666666666666666666
+ |000000000000000000000
+ |555666666666677777777
+ |789012345678901234567
+test.c: 8|loc: 6184| return 0;
+ |66666666666
+ |11111111111
+ |88888999999
+ |56789012345
+test.c: 9|loc: 6312|}
+ |6
+ |3
+ |1
+ |3
+
+UNALLOCATED LOCATIONS
+ source_location interval: 6314 <= loc < 2147483633
+
+MACRO 1: PLUS (7 tokens)
+ source_location interval: 2147483633 <= loc < 2147483640
+test.c:7:11: note: expansion point is location 6067
+ int b = PLUS (3,4);
+ ^
+ map->start_location: 2147483633
+ macro_locations:
+ 0: 6073, 5410
+test.c:7:17: note: token 0 has x-location == 6073
+ int b = PLUS (3,4);
+ ^
+test.c:7:17: note: token 0 has y-location == 5410
+ 1: 5412, 5412
+In file included from test.c:1:0:
+test.h:3:22: note: token 1 has x-location == y-location == 5412
+ #define PLUS(A, B) A + B
+ ^
+ 2: 6075, 5414
+test.c:7:19: note: token 2 has x-location == 6075
+ int b = PLUS (3,4);
+ ^
+test.c:7:19: note: token 2 has y-location == 5414
+ 3: 0, 2947526575
+cc1: note: token 3 has x-location == 0
+cc1: note: token 3 has y-location == 2947526575
+ 4: 2947526575, 2947526575
+x-location == y-location == 2947526575 encodes token # 800042942
+ 5: 2947526575, 2947526575
+x-location == y-location == 2947526575 encodes token # 800042942
+ 6: 2947526575, 2947526575
+x-location == y-location == 2947526575 encodes token # 800042942
+
+MACRO 0: PLUS (7 tokens)
+ source_location interval: 2147483640 <= loc < 2147483647
+test.c:6:11: note: expansion point is location 5939
+ int a = PLUS (1,2);
+ ^
+ map->start_location: 2147483640
+ macro_locations:
+ 0: 5945, 5410
+test.c:6:17: note: token 0 has x-location == 5945
+ int a = PLUS (1,2);
+ ^
+test.c:6:17: note: token 0 has y-location == 5410
+ 1: 5412, 5412
+In file included from test.c:1:0:
+test.h:3:22: note: token 1 has x-location == y-location == 5412
+ #define PLUS(A, B) A + B
+ ^
+ 2: 5947, 5414
+test.c:6:19: note: token 2 has x-location == 5947
+ int a = PLUS (1,2);
+ ^
+test.c:6:19: note: token 2 has y-location == 5414
+ 3: 0, 2947526575
+cc1: note: token 3 has x-location == 0
+cc1: note: token 3 has y-location == 2947526575
+ 4: 2947526575, 2947526575
+x-location == y-location == 2947526575 encodes token # 800042935
+ 5: 2947526575, 2947526575
+x-location == y-location == 2947526575 encodes token # 800042935
+ 6: 2947526575, 2947526575
+x-location == y-location == 2947526575 encodes token # 800042935
+
+MAX_SOURCE_LOCATION
+ source_location interval: 2147483647 <= loc < 2147483648
+
+AD-HOC LOCATIONS
+ source_location interval: 2147483648 <= loc < 4294967295
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^