On Jul 6, 2003, Neil Booth <[EMAIL PROTECTED]> wrote:
> Alexandre Oliva wrote:-
>> #pragma GCC debugdir "/path/name"
> This looks good at first glance. I image we'd only accept it if
> -fpreprocessed?
Cool, here's the patch I came up with. I'm still bootstrapping it.
Ok if it passes?
BTW, I may have found out why the differences in macro line numbers
were gone: distcc assumes -Mpwd requires local execution, so it never
ran separate preprocessing and remote compilation. Oops. Maybe the
problem isn't gone, after all. We'll see...
Index: gcc/ChangeLog
from Alexandre Oliva <[EMAIL PROTECTED]>
* c.opt: Introduce -Mpwd.
* gcc.c (cpp_unique_options): Pass it.
* c-opts.c (c_common_handle_options): Set...
* cpplib.h (struct cpp_options): ... current_directory option.
(struct cpp_callbacks): Add dir_change.
* cpplib.c (do_pragma_debugdir): New.
(_cpp_init_internal_pragmas): Register it.
* cppinit.c (read_original_filename): Call...
(read_original_directory): New. Look for #pragma GCC debugdir
and process it.
(cpp_read_main_file): Call dir_change callback if current_directory
option is set.
* toplev.c (src_pwd): New static variable.
(set_src_pwd, get_src_pwd): New functions.
* toplev.h (get_src_pwd, set_src_pwd): Declare.
* dbxout.c (dbxout_init): Call get_src_pwd() instead of getpwd().
* dwarf2out.c (gen_compile_unit_die): Likewise.
* dwarfout.c (output_compile_unit_die, dwarfout_init): Likewise.
* c-lex.c (cb_dir_change): New.
(init_c_lex): Set dir_change callback.
* c-ppoutput.c (cb_dir_change): New.
(init_pp_output): Set dir_change callback.
* doc/cpp.texi: Add #pragma GCC debugdir and -Mpwd.
* doc/invoke.texi: Add -Mpwd.
* doc/cppopts.texi: Document it.
Index: gcc/c-lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-lex.c,v
retrieving revision 1.207
diff -u -p -r1.207 c-lex.c
--- gcc/c-lex.c 5 Jul 2003 00:23:47 -0000 1.207
+++ gcc/c-lex.c 6 Jul 2003 19:11:53 -0000
@@ -72,6 +72,7 @@ static tree lex_charconst (const cpp_tok
static void update_header_times (const char *);
static int dump_one_header (splay_tree_node, void *);
static void cb_line_change (cpp_reader *, const cpp_token *, int);
+static bool cb_dir_change (cpp_reader *, const char *);
static void cb_ident (cpp_reader *, unsigned int, const cpp_string *);
static void cb_def_pragma (cpp_reader *, unsigned int);
static void cb_define (cpp_reader *, unsigned int, cpp_hashnode *);
@@ -98,6 +99,7 @@ init_c_lex (void)
cb = cpp_get_callbacks (parse_in);
cb->line_change = cb_line_change;
+ cb->dir_change = cb_dir_change;
cb->ident = cb_ident;
cb->def_pragma = cb_def_pragma;
cb->valid_pch = c_common_valid_pch;
@@ -200,6 +202,12 @@ cb_line_change (cpp_reader *pfile ATTRIB
src_lineno = SOURCE_LINE (map, token->line);
}
+static bool
+cb_dir_change (cpp_reader *pfile ATTRIBUTE_UNUSED, const char *dir)
+{
+ return set_src_pwd (dir);
+}
+
void
fe_file_change (const struct line_map *new_map)
{
Index: gcc/c-opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-opts.c,v
retrieving revision 1.69
diff -u -p -r1.69 c-opts.c
--- gcc/c-opts.c 5 Jul 2003 07:20:32 -0000 1.69
+++ gcc/c-opts.c 6 Jul 2003 19:11:54 -0000
@@ -356,6 +356,10 @@ c_common_handle_option (size_t scode, co
cpp_opts->deps.phony_targets = true;
break;
+ case OPT_Mpwd:
+ cpp_opts->current_directory = true;
+ break;
+
case OPT_MQ:
case OPT_MT:
deps_seen = true;
Index: gcc/c-ppoutput.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-ppoutput.c,v
retrieving revision 1.6
diff -u -p -r1.6 c-ppoutput.c
--- gcc/c-ppoutput.c 22 Jun 2003 13:41:24 -0000 1.6
+++ gcc/c-ppoutput.c 6 Jul 2003 19:11:54 -0000
@@ -52,6 +52,7 @@ static void maybe_print_line (const stru
/* Callback routines for the parser. Most of these are active only
in specific modes. */
static void cb_line_change (cpp_reader *, const cpp_token *, int);
+static bool cb_dir_change (cpp_reader *, const char *);
static void cb_define (cpp_reader *, unsigned int, cpp_hashnode *);
static void cb_undef (cpp_reader *, unsigned int, cpp_hashnode *);
static void cb_include (cpp_reader *, unsigned int, const unsigned char *,
@@ -99,6 +100,7 @@ init_pp_output (FILE *out_stream)
assembly language; the assembler may choke on them. */
if (cpp_get_options (parse_in)->lang != CLK_ASM)
{
+ cb->dir_change = cb_dir_change;
cb->ident = cb_ident;
cb->def_pragma = cb_def_pragma;
}
@@ -377,6 +379,25 @@ cb_def_pragma (cpp_reader *pfile, unsign
fputs ("#pragma ", print.outf);
cpp_output_line (pfile, print.outf);
print.line++;
+}
+
+/* Output a GCC debugdir pragma. */
+static bool
+cb_dir_change (cpp_reader *pfile ATTRIBUTE_UNUSED, const char *dir)
+{
+ size_t dir_len = strlen (dir);
+ unsigned char *dir_quoted = alloca (dir_len * 4 + 1);
+ unsigned char *p;
+
+ /* cpp_quote_string does not nul-terminate, so we have to do it
+ ourselves. */
+ p = cpp_quote_string (dir_quoted,
+ (unsigned char *)dir, dir_len);
+ *p = '\0';
+
+ fprintf (print.outf, "#pragma GCC debugdir \"%s\"\n", dir_quoted);
+ print.line++;
+ return true;
}
/* Dump out the hash table. */
Index: gcc/c.opt
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c.opt,v
retrieving revision 1.6
diff -u -p -r1.6 c.opt
--- gcc/c.opt 5 Jul 2003 00:23:47 -0000 1.6
+++ gcc/c.opt 6 Jul 2003 19:11:54 -0000
@@ -107,6 +107,9 @@ C ObjC C++ ObjC++ Separate
MP
C ObjC C++ ObjC++
+Mpwd
+C ObjC C++ ObjC++
+
MQ
C ObjC C++ ObjC++ Joined Separate
Index: gcc/cppinit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppinit.c,v
retrieving revision 1.285
diff -u -p -r1.285 cppinit.c
--- gcc/cppinit.c 5 Jul 2003 00:23:48 -0000 1.285
+++ gcc/cppinit.c 6 Jul 2003 19:11:55 -0000
@@ -30,6 +30,7 @@ Foundation, 59 Temple Place - Suite 330,
static void init_library (void);
static void mark_named_operators (cpp_reader *);
static void read_original_filename (cpp_reader *);
+static void read_original_directory (cpp_reader *);
static void post_options (cpp_reader *);
/* If we have designated initializers (GCC >2.7) these tables can be
@@ -466,6 +467,10 @@ cpp_read_main_file (cpp_reader *pfile, c
if (CPP_OPTION (pfile, preprocessed))
read_original_filename (pfile);
+ if (CPP_OPTION (pfile, current_directory)
+ && pfile->cb.dir_change)
+ pfile->cb.dir_change (pfile, getpwd ());
+
return pfile->map->to_file;
}
@@ -490,12 +495,68 @@ read_original_filename (cpp_reader *pfil
if (token1->type == CPP_NUMBER)
{
_cpp_handle_directive (pfile, token->flags & PREV_WHITE);
+ read_original_directory (pfile);
return;
}
}
/* Backup as if nothing happened. */
_cpp_backup_tokens (pfile, 1);
+}
+
+/* For preprocessed files, if the tokens following the first filename
+ line is of the form # pragma GCC debugdir "/path/name", handle the
+ directive so we know the original current directory. */
+static void
+read_original_directory (cpp_reader *pfile)
+{
+ const cpp_token *hash, *token;
+
+ /* Lex ahead; if the first tokens are of the form # NUM, then
+ process the directive, otherwise back up. */
+ hash = _cpp_lex_direct (pfile);
+ if (hash->type != CPP_HASH)
+ {
+ _cpp_backup_tokens (pfile, 1);
+ return;
+ }
+
+ token = _cpp_lex_direct (pfile);
+
+ if (! (token->type == CPP_NAME
+ && token->val.node->is_directive
+ && token->val.node->ident.len == 6
+ && strncmp ((const char *) token->val.node->ident.str,
+ "pragma", 6) == 0))
+ {
+ _cpp_backup_tokens (pfile, 2);
+ return;
+ }
+
+ token = _cpp_lex_direct (pfile);
+
+ if (! (token->type == CPP_NAME
+ && token->val.node->ident.len == 3
+ && strncmp ((const char *) token->val.node->ident.str,
+ "GCC", 3) == 0))
+ {
+ _cpp_backup_tokens (pfile, 3);
+ return;
+ }
+
+ token = _cpp_lex_direct (pfile);
+
+ if (! (token->type == CPP_NAME
+ && token->val.node->ident.len == 8
+ && strncmp ((const char *) token->val.node->ident.str,
+ "debugdir", 8) == 0))
+ {
+ _cpp_backup_tokens (pfile, 4);
+ return;
+ }
+
+ _cpp_backup_tokens (pfile, 3);
+ _cpp_handle_directive (pfile, hash->flags & PREV_WHITE);
}
/* This is called at the end of preprocessing. It pops the last
Index: gcc/cpplib.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.c,v
retrieving revision 1.341
diff -u -p -r1.341 cpplib.c
--- gcc/cpplib.c 5 Jul 2003 00:23:52 -0000 1.341
+++ gcc/cpplib.c 6 Jul 2003 19:11:56 -0000
@@ -124,6 +124,7 @@ static void do_pragma_once (cpp_reader *
static void do_pragma_poison (cpp_reader *);
static void do_pragma_system_header (cpp_reader *);
static void do_pragma_dependency (cpp_reader *);
+static void do_pragma_debugdir (cpp_reader *);
static void do_linemarker (cpp_reader *);
static const cpp_token *get_token_no_padding (cpp_reader *);
static const cpp_token *get__Pragma_string (cpp_reader *);
@@ -1023,6 +1024,7 @@ _cpp_init_internal_pragmas (cpp_reader *
cpp_register_pragma (pfile, "GCC", "poison", do_pragma_poison);
cpp_register_pragma (pfile, "GCC", "system_header", do_pragma_system_header);
cpp_register_pragma (pfile, "GCC", "dependency", do_pragma_dependency);
+ cpp_register_pragma (pfile, "GCC", "debugdir", do_pragma_debugdir);
}
/* Return the number of registered pragmas in PE. */
@@ -1241,6 +1243,42 @@ do_pragma_dependency (cpp_reader *pfile)
}
free ((void *) fname);
+}
+
+/* Set the current directory (for debugging info) to the given string. */
+static void
+do_pragma_debugdir (cpp_reader *pfile)
+{
+ const cpp_token *tok;
+
+ tok = _cpp_lex_token (pfile);
+ if (tok->type != CPP_STRING)
+ {
+ _cpp_backup_tokens (pfile, 1);
+ skip_rest_of_line (pfile);
+ cpp_error (pfile, DL_ERROR, "invalid #pragma GCC debugdir directive");
+ return;
+ }
+
+ if (! CPP_OPTION (pfile, preprocessed))
+ cpp_error (pfile, DL_ERROR,
+ "only preprocessed sources can contain #pragma GCC debugdir");
+
+ if (pfile->cb.dir_change)
+ {
+ char *debugdir = alloca (tok->val.str.len - 1);
+ memcpy (debugdir, (const char *) tok->val.str.text + 1,
+ tok->val.str.len - 2);
+ debugdir[tok->val.str.len - 2] = '\0';
+ if (! pfile->cb.dir_change (pfile, debugdir))
+ cpp_error (pfile, DL_ERROR,
+ "too late for #pragma GCC debugdir");
+ }
+
+ CPP_OPTION (pfile, current_directory) = 0;
+
+ check_eol (pfile);
+ skip_rest_of_line (pfile);
}
/* Get a token but skip padding. */
Index: gcc/cpplib.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.h,v
retrieving revision 1.259
diff -u -p -r1.259 cpplib.h
--- gcc/cpplib.h 5 Jul 2003 00:23:52 -0000 1.259
+++ gcc/cpplib.h 6 Jul 2003 19:11:57 -0000
@@ -378,6 +378,11 @@ struct cpp_options
/* Nonzero means __STDC__ should have the value 0 in system headers. */
unsigned char stdc_0_in_system_headers;
+
+ /* Nonzero means output a <directory> line marker directive right
+ after the initial file name line marker, and before a duplicate
+ initial line marker. */
+ unsigned char current_directory;
};
/* Call backs to cpplib client. */
@@ -386,6 +391,7 @@ struct cpp_callbacks
/* Called when a new line of preprocessed output is started. */
void (*line_change) (cpp_reader *, const cpp_token *, int);
void (*file_change) (cpp_reader *, const struct line_map *);
+ bool (*dir_change) (cpp_reader *, const char *);
void (*include) (cpp_reader *, unsigned int, const unsigned char *,
const char *, int);
void (*define) (cpp_reader *, unsigned int, cpp_hashnode *);
Index: gcc/dbxout.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/dbxout.c,v
retrieving revision 1.152
diff -u -p -r1.152 dbxout.c
--- gcc/dbxout.c 3 Jul 2003 10:18:17 -0000 1.152
+++ gcc/dbxout.c 6 Jul 2003 19:11:59 -0000
@@ -469,7 +469,8 @@ dbxout_init (const char *input_file_name
/* Put the current working directory in an N_SO symbol. */
if (use_gnu_debug_info_extensions)
{
- if (!cwd && (cwd = getpwd ()) && (!*cwd || cwd[strlen (cwd) - 1] != '/'))
+ if (!cwd && (cwd = get_src_pwd ())
+ && (!*cwd || cwd[strlen (cwd) - 1] != '/'))
cwd = concat (cwd, FILE_NAME_JOINER, NULL);
if (cwd)
{
Index: gcc/dwarf2out.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/dwarf2out.c,v
retrieving revision 1.440
diff -u -p -r1.440 dwarf2out.c
--- gcc/dwarf2out.c 1 Jul 2003 12:17:52 -0000 1.440
+++ gcc/dwarf2out.c 6 Jul 2003 19:12:06 -0000
@@ -9475,7 +9475,7 @@ add_name_attribute (dw_die_ref die, cons
static void
add_comp_dir_attribute (dw_die_ref die)
{
- const char *wd = getpwd ();
+ const char *wd = get_src_pwd ();
if (wd != NULL)
add_AT_string (die, DW_AT_comp_dir, wd);
}
Index: gcc/dwarfout.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/dwarfout.c,v
retrieving revision 1.129
diff -u -p -r1.129 dwarfout.c
--- gcc/dwarfout.c 5 Jul 2003 15:17:26 -0000 1.129
+++ gcc/dwarfout.c 6 Jul 2003 19:12:10 -0000
@@ -4043,7 +4043,7 @@ output_compile_unit_die (void *arg)
stmt_list_attribute (LINE_BEGIN_LABEL);
{
- const char *wd = getpwd ();
+ const char *wd = get_src_pwd ();
if (wd)
comp_dir_attribute (wd);
}
@@ -6119,7 +6119,7 @@ dwarfout_init (const char *main_input_fi
ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SFNAMES_SECTION);
ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
{
- const char *pwd = getpwd ();
+ const char *pwd = get_src_pwd ();
char *dirname;
if (!pwd)
Index: gcc/gcc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcc.c,v
retrieving revision 1.385
diff -u -p -r1.385 gcc.c
--- gcc/gcc.c 6 Jul 2003 06:15:35 -0000 1.385
+++ gcc/gcc.c 6 Jul 2003 19:12:16 -0000
@@ -743,7 +743,7 @@ static const char *cpp_unique_options =
%{!Q:-quiet} %{nostdinc*} %{C} %{CC} %{v} %{I*} %{P} %I\
%{MD:-MD %{!o:%b.d}%{o*:%.d%*}}\
%{MMD:-MMD %{!o:%b.d}%{o*:%.d%*}}\
- %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*}\
+ %{M} %{MM} %{MF*} %{MG} %{MP} %{Mpwd} %{MQ*} %{MT*}\
%{!E:%{!M:%{!MM:%{MD|MMD:%{o*:-MQ %*}}}}}\
%{trigraphs} %{remap} %{g3:-dD} %{H} %C %{D*&U*&A*} %{i*} %Z %i\
%{E|M|MM:%W{o*}}";
Index: gcc/toplev.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.c,v
retrieving revision 1.797
diff -u -p -r1.797 toplev.c
--- gcc/toplev.c 5 Jul 2003 16:11:52 -0000 1.797
+++ gcc/toplev.c 6 Jul 2003 19:12:19 -0000
@@ -1560,6 +1560,41 @@ FILE *asm_out_file;
FILE *aux_info_file;
FILE *rtl_dump_file = NULL;
+/* The current working directory of a translation. It's generally the
+ directory from which compilation was initiated, but a preprocessed
+ file may specify the original directory in which it was
+ created. */
+
+static const char *src_pwd;
+
+/* Initialize src_pwd with the given string, and return true. If it
+ was already initialized, return false. As a special case, it may
+ be called with a NULL argument to test whether src_pwd has NOT been
+ initialized yet. */
+
+bool
+set_src_pwd (const char *pwd)
+{
+ if (src_pwd)
+ return false;
+
+ src_pwd = xstrdup (pwd);
+ return true;
+}
+
+/* Return the directory from which the translation unit was initiated,
+ in case set_src_pwd() was not called before to assign it a
+ different value. */
+
+const char *
+get_src_pwd (void)
+{
+ if (! src_pwd)
+ src_pwd = getpwd ();
+
+ return src_pwd;
+}
+
/* Decode the string P as an integral parameter.
If the string is indeed an integer return its numeric value else
issue an Invalid Option error for the option PNAME and return DEFVAL.
Index: gcc/toplev.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.h,v
retrieving revision 1.105
diff -u -p -r1.105 toplev.h
--- gcc/toplev.h 5 Jul 2003 16:11:52 -0000 1.105
+++ gcc/toplev.h 6 Jul 2003 19:12:19 -0000
@@ -167,4 +167,10 @@ extern bool fast_math_flags_set_p (void)
extern int exact_log2_wide (unsigned HOST_WIDE_INT);
extern int floor_log2_wide (unsigned HOST_WIDE_INT);
+/* Functions used to get and set GCC's notion of in what directory
+ compilation was started. */
+
+extern const char *get_src_pwd (void);
+extern bool set_src_pwd (const char *);
+
#endif /* ! GCC_TOPLEV_H */
Index: gcc/doc/cpp.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/cpp.texi,v
retrieving revision 1.61
diff -u -p -r1.61 cpp.texi
--- gcc/doc/cpp.texi 5 Jul 2003 00:23:53 -0000 1.61
+++ gcc/doc/cpp.texi 6 Jul 2003 19:12:22 -0000
@@ -3291,6 +3291,12 @@ preprocessor itself. Other pragmas are
compilers. They are documented in the GCC manual.
@ftable @code
[EMAIL PROTECTED] #pragma GCC debugdir
[EMAIL PROTECTED] GCC debugdir} is an internal note emitted by the
+preprocessor when given the @option{-Mpwd} flag. This pragma must not
+be present in source files. In preprocessed files, it must appear
+right after the initial file name.
+
@item #pragma GCC dependency
@code{#pragma GCC dependency} allows you to check the relative dates of
the current file and another file. If the other file is more recent than
@@ -4133,7 +4139,8 @@ without notice.
cpp [EMAIL PROTECTED]@[EMAIL PROTECTED]@dots{}] [EMAIL PROTECTED]@var{macro}]
[EMAIL PROTECTED]@[EMAIL PROTECTED] [EMAIL PROTECTED]@[EMAIL PROTECTED]
[EMAIL PROTECTED]|@option{-MM}] [EMAIL PROTECTED] [EMAIL PROTECTED] @var{filename}]
- [EMAIL PROTECTED] [EMAIL PROTECTED] @[EMAIL PROTECTED] [EMAIL PROTECTED] @[EMAIL PROTECTED]
+ [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] @[EMAIL PROTECTED]
+ [EMAIL PROTECTED] @[EMAIL PROTECTED]
[EMAIL PROTECTED] @var{language}] [EMAIL PROTECTED]@var{standard}]
@var{infile} @var{outfile}
Index: gcc/doc/cppopts.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/cppopts.texi,v
retrieving revision 1.25
diff -u -p -r1.25 cppopts.texi
--- gcc/doc/cppopts.texi 5 Jul 2003 00:23:53 -0000 1.25
+++ gcc/doc/cppopts.texi 6 Jul 2003 19:12:23 -0000
@@ -1,4 +1,4 @@
[EMAIL PROTECTED] Copyright (c) 1999, 2000, 2001, 2002
[EMAIL PROTECTED] Copyright (c) 1999, 2000, 2001, 2002, 2003
@c Free Software Foundation, Inc.
@c This is part of the CPP and GCC manuals.
@c For copying conditions, see the file gcc.texi.
@@ -260,6 +260,13 @@ test.o: test.c test.h
test.h:
@end example
+
[EMAIL PROTECTED] -Mpwd
[EMAIL PROTECTED] Mpwd
+This option instructs CPP to output, right after the initial line
+marker, a @code{#pragma} that tells GCC the current working directory.
+GCC will use this directory, when it's present, as the current working
+directory emitted in some debugging information formats.
@item -MT @var{target}
@opindex MT
Index: gcc/doc/invoke.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/invoke.texi,v
retrieving revision 1.308
diff -u -p -r1.308 invoke.texi
--- gcc/doc/invoke.texi 5 Jul 2003 00:19:47 -0000 1.308
+++ gcc/doc/invoke.texi 6 Jul 2003 19:12:32 -0000
@@ -300,7 +300,7 @@ in the following sections.
-include @var{file} -imacros @var{file} @gol
-iprefix @var{file} -iwithprefix @var{dir} @gol
-iwithprefixbefore @var{dir} -isystem @var{dir} @gol
--M -MM -MF -MG -MP -MQ -MT -nostdinc -P -remap @gol
+-M -MM -MF -MG -MP -Mpwd -MQ -MT -nostdinc -P -remap @gol
-trigraphs -undef [EMAIL PROTECTED] -Wp,@var{option} @gol
-Xpreprocessor @var{option}}
--
Alexandre Oliva Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer [EMAIL PROTECTED], gcc.gnu.org}
CS PhD student at IC-Unicamp [EMAIL PROTECTED], gnu.org}
Free Software Evangelist Professional serial bug killer
__
distcc mailing list http://distcc.samba.org/
To unsubscribe or change options:
http://lists.samba.org/cgi-bin/mailman/listinfo/distcc