diff options
author | Tom Tromey <tromey@redhat.com> | 2011-10-17 09:59:40 +0000 |
---|---|---|
committer | Dodji Seketeli <dodji@gcc.gnu.org> | 2011-10-17 11:59:40 +0200 |
commit | 847e697a240e6d30335335c62084743978fa2084 (patch) | |
tree | 1df29dda9c3f6fb6e559fa82140695ea5b6130d1 /libcpp | |
parent | 07a0b324eb7e353146340f00db380c6d92851fc9 (diff) | |
download | gcc-847e697a240e6d30335335c62084743978fa2084.zip gcc-847e697a240e6d30335335c62084743978fa2084.tar.gz gcc-847e697a240e6d30335335c62084743978fa2084.tar.bz2 |
Support -fdebug-cpp option
This patch adds -fdebug-cpp option. When used with -E this dumps the
relevant macro map before every single token. This clutters the output
a lot but has proved to be invaluable in tracking some bugs during the
development of the virtual location support.
Co-Authored-By: Dodji Seketeli <dodji@redhat.com>
From-SVN: r180084
Diffstat (limited to 'libcpp')
-rw-r--r-- | libcpp/ChangeLog | 7 | ||||
-rw-r--r-- | libcpp/include/cpplib.h | 4 | ||||
-rw-r--r-- | libcpp/include/line-map.h | 4 | ||||
-rw-r--r-- | libcpp/line-map.c | 38 |
4 files changed, 53 insertions, 0 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 5eab7b0..bd86466 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,6 +1,13 @@ 2011-10-15 Tom Tromey <tromey@redhat.com> Dodji Seketeli <dodji@redhat.com> + * include/cpplib.h (struct cpp_options)<debug>: New struct member. + * include/line-map.h (linemap_dump_location): Declare ... + * line-map.c (linemap_dump_location): ... new function. + +2011-10-15 Tom Tromey <tromey@redhat.com> + Dodji Seketeli <dodji@redhat.com> + * include/cpplib.h (struct cpp_options)<track_macro_expansion>: New option. * internal.h (struct macro_context): New struct. diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 3e01c11..825bf2f 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -392,6 +392,10 @@ struct cpp_options /* Nonzero means we're looking at already preprocessed code, so don't bother trying to do macro expansion and whatnot. */ unsigned char preprocessed; + + /* Nonzero means we are going to emit debugging logs during + preprocessing. */ + unsigned char debug; /* Nonzero means we are tracking locations of tokens involved in macro expansion. 1 Means we track the location in degraded mode diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h index 724f3f0..04a523c 100644 --- a/libcpp/include/line-map.h +++ b/libcpp/include/line-map.h @@ -675,4 +675,8 @@ expanded_location linemap_expand_location_full (struct line_maps *, source_location loc, enum location_resolution_kind lrk); +/* Dump debugging information about source location LOC into the file + stream STREAM. SET is the line map set LOC comes from. */ +void linemap_dump_location (struct line_maps *, source_location, FILE *); + #endif /* !LIBCPP_LINE_MAP_H */ diff --git a/libcpp/line-map.c b/libcpp/line-map.c index fe07c16..3dbaeab 100644 --- a/libcpp/line-map.c +++ b/libcpp/line-map.c @@ -1105,3 +1105,41 @@ linemap_expand_location_full (struct line_maps *set, xloc = linemap_expand_location (map, loc); return xloc; } + +/* Dump debugging information about source location LOC into the file + stream STREAM. SET is the line map set LOC comes from. */ + +void +linemap_dump_location (struct line_maps *set, + source_location loc, + FILE *stream) +{ + const struct line_map *map; + source_location location; + const char *path, *from; + int l,c,s,e; + + if (loc == 0) + return; + + location = + linemap_resolve_location (set, loc, LRK_MACRO_DEFINITION_LOCATION, &map); + path = LINEMAP_FILE (map); + + l = SOURCE_LINE (map, location); + c = SOURCE_COLUMN (map, location); + s = LINEMAP_SYSP (map) != 0; + e = location != loc; + + if (e) + from = "N/A"; + else + from = (INCLUDED_FROM (set, map)) + ? LINEMAP_FILE (INCLUDED_FROM (set, map)) + : "<NULL>"; + + /* P: path, L: line, C: column, S: in-system-header, M: map address, + E: macro expansion?. */ + fprintf (stream, "{P:%s;F:%s;L:%d;C:%d;S:%d;M:%p;E:%d,LOC:%d}", + path, from, l, c, s, (void*)map, e, loc); +} |