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 /gcc/c-family/c-ppoutput.c | |
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 'gcc/c-family/c-ppoutput.c')
-rw-r--r-- | gcc/c-family/c-ppoutput.c | 57 |
1 files changed, 46 insertions, 11 deletions
diff --git a/gcc/c-family/c-ppoutput.c b/gcc/c-family/c-ppoutput.c index 892f1ea..df46ce4 100644 --- a/gcc/c-family/c-ppoutput.c +++ b/gcc/c-family/c-ppoutput.c @@ -59,7 +59,9 @@ static void account_for_newlines (const unsigned char *, size_t); static int dump_macro (cpp_reader *, cpp_hashnode *, void *); static void dump_queued_macros (cpp_reader *); +static void print_line_1 (source_location, const char*, FILE *); static void print_line (source_location, const char *); +static void maybe_print_line_1 (source_location, FILE *); static void maybe_print_line (source_location); static void do_line_change (cpp_reader *, const cpp_token *, source_location, int); @@ -243,7 +245,12 @@ scan_translation_unit (cpp_reader *pfile) in_pragma = false; } else - cpp_output_token (token, print.outf); + { + if (cpp_get_options (parse_in)->debug) + linemap_dump_location (line_table, token->src_loc, + print.outf); + cpp_output_token (token, print.outf); + } if (token->type == CPP_COMMENT) account_for_newlines (token->val.str.text, token->val.str.len); @@ -297,8 +304,9 @@ scan_translation_unit_trad (cpp_reader *pfile) /* If the token read on logical line LINE needs to be output on a different line to the current one, output the required newlines or a line marker, and return 1. Otherwise return 0. */ + static void -maybe_print_line (source_location src_loc) +maybe_print_line_1 (source_location src_loc, FILE *stream) { int src_line = LOCATION_LINE (src_loc); const char *src_file = LOCATION_FILE (src_loc); @@ -306,7 +314,7 @@ maybe_print_line (source_location src_loc) /* End the previous line of text. */ if (print.printed) { - putc ('\n', print.outf); + putc ('\n', stream); print.src_line++; print.printed = 0; } @@ -318,22 +326,37 @@ maybe_print_line (source_location src_loc) { while (src_line > print.src_line) { - putc ('\n', print.outf); + putc ('\n', stream); print.src_line++; } } else - print_line (src_loc, ""); + print_line_1 (src_loc, "", stream); + +} + +/* If the token read on logical line LINE needs to be output on a + different line to the current one, output the required newlines or + a line marker, and return 1. Otherwise return 0. */ + +static void +maybe_print_line (source_location src_loc) +{ + if (cpp_get_options (parse_in)->debug) + linemap_dump_location (line_table, src_loc, + print.outf); + maybe_print_line_1 (src_loc, print.outf); } /* Output a line marker for logical line LINE. Special flags are "1" or "2" indicating entering or leaving a file. */ + static void -print_line (source_location src_loc, const char *special_flags) +print_line_1 (source_location src_loc, const char *special_flags, FILE *stream) { /* End any previous line of text. */ if (print.printed) - putc ('\n', print.outf); + putc ('\n', stream); print.printed = 0; if (!flag_no_line_commands) @@ -354,20 +377,32 @@ print_line (source_location src_loc, const char *special_flags) (const unsigned char *) file_path, to_file_len); *p = '\0'; - fprintf (print.outf, "# %u \"%s\"%s", + fprintf (stream, "# %u \"%s\"%s", print.src_line == 0 ? 1 : print.src_line, to_file_quoted, special_flags); sysp = in_system_header_at (src_loc); if (sysp == 2) - fputs (" 3 4", print.outf); + fputs (" 3 4", stream); else if (sysp == 1) - fputs (" 3", print.outf); + fputs (" 3", stream); - putc ('\n', print.outf); + putc ('\n', stream); } } +/* Output a line marker for logical line LINE. Special flags are "1" + or "2" indicating entering or leaving a file. */ + +static void +print_line (source_location src_loc, const char *special_flags) +{ + if (cpp_get_options (parse_in)->debug) + linemap_dump_location (line_table, src_loc, + print.outf); + print_line_1 (src_loc, special_flags, print.outf); +} + /* Helper function for cb_line_change and scan_translation_unit. */ static void do_line_change (cpp_reader *pfile, const cpp_token *token, |