View | Details | Return to bug 19165
Collapse All | Expand All

(-)gcc/diagnostic.def (-10 / +10 lines)
Lines 28-45 DEFINE_DIAGNOSTIC_KIND (DK_UNSPECIFIED, Link Here
28
   This is used by the diagnostic machinery when it wants to disable a
28
   This is used by the diagnostic machinery when it wants to disable a
29
   diagnostic without disabling the option which causes it.  */
29
   diagnostic without disabling the option which causes it.  */
30
DEFINE_DIAGNOSTIC_KIND (DK_IGNORED, "")
30
DEFINE_DIAGNOSTIC_KIND (DK_IGNORED, "")
31
31
32
/* The remainder are real diagnostic types.  */
32
/* The remainder are real diagnostic types.  */
33
DEFINE_DIAGNOSTIC_KIND (DK_FATAL, "fatal error: ")
33
DEFINE_DIAGNOSTIC_KIND (DK_FATAL, "fatal error")
34
DEFINE_DIAGNOSTIC_KIND (DK_ICE, "internal compiler error: ")
34
DEFINE_DIAGNOSTIC_KIND (DK_ICE, "internal compiler error")
35
DEFINE_DIAGNOSTIC_KIND (DK_ERROR, "error: ")
35
DEFINE_DIAGNOSTIC_KIND (DK_ERROR, "error")
36
DEFINE_DIAGNOSTIC_KIND (DK_SORRY, "sorry, unimplemented: ")
36
DEFINE_DIAGNOSTIC_KIND (DK_SORRY, "sorry, unimplemented")
37
DEFINE_DIAGNOSTIC_KIND (DK_WARNING, "warning: ")
37
DEFINE_DIAGNOSTIC_KIND (DK_WARNING, "warning")
38
DEFINE_DIAGNOSTIC_KIND (DK_ANACHRONISM, "anachronism: ")
38
DEFINE_DIAGNOSTIC_KIND (DK_ANACHRONISM, "anachronism")
39
DEFINE_DIAGNOSTIC_KIND (DK_NOTE, "note: ")
39
DEFINE_DIAGNOSTIC_KIND (DK_NOTE, "note")
40
DEFINE_DIAGNOSTIC_KIND (DK_DEBUG, "debug: ")
40
DEFINE_DIAGNOSTIC_KIND (DK_DEBUG, "debug")
41
/* These two would be re-classified as DK_WARNING or DK_ERROR, so the
41
/* These two would be re-classified as DK_WARNING or DK_ERROR, so the
42
prefix does not matter.  */
42
prefix does not matter.  */
43
DEFINE_DIAGNOSTIC_KIND (DK_PEDWARN, "pedwarn: ")
43
DEFINE_DIAGNOSTIC_KIND (DK_PEDWARN, "")
44
DEFINE_DIAGNOSTIC_KIND (DK_PERMERROR, "permerror: ")
44
DEFINE_DIAGNOSTIC_KIND (DK_PERMERROR, "")
45
45
(-)gcc/diagnostic-xml.c (+164 lines)
Line 0 Link Here
1
/* Language-independent diagnostic subroutines for the GNU Compiler Collection
2
   Copyright (C) 2009 Free Software Foundation, Inc.
3
   Contributed by Manuel Lopez-Ibanez <manu@gcc.gnu.org>
4
5
This file is part of GCC.
6
7
GCC is free software; you can redistribute it and/or modify it under
8
the terms of the GNU General Public License as published by the Free
9
Software Foundation; either version 3, or (at your option) any later
10
version.
11
12
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13
WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15
for more details.
16
17
You should have received a copy of the GNU General Public License
18
along with GCC; see the file COPYING3.  If not see
19
<http://www.gnu.org/licenses/>.  */
20
21
#include "config.h"
22
#undef FLOAT /* This is for hpux. They should change hpux.  */
23
#undef FFS  /* Some systems define this in param.h.  */
24
#include "system.h"
25
#include "coretypes.h"
26
#include "tm.h"
27
#include "tree.h"
28
#include "version.h"
29
#include "tm_p.h"
30
#include "flags.h"
31
#include "input.h"
32
#include "toplev.h"
33
#include "intl.h"
34
#include "diagnostic-xml.h"
35
#include "langhooks.h"
36
#include "langhooks-def.h"
37
#include "opts.h"
38
#include "plugin.h"
39
40
41
static void xml_diagnostic_starter (diagnostic_context *,
42
				    diagnostic_info *);
43
static void xml_diagnostic_finalizer (diagnostic_context *,
44
				      diagnostic_info *);
45
46
static char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1;
47
48
/* Return a malloc'd string containing MSG formatted a la printf.  The
49
   caller is responsible for freeing the memory.  */
50
static char *
51
build_message_string (const char *msg, ...)
52
{
53
  char *str;
54
  va_list ap;
55
56
  va_start (ap, msg);
57
  vasprintf (&str, msg, ap);
58
  va_end (ap);
59
60
  return str;
61
}
62
63
/* Return a malloc'd string describing a location.  The caller is
64
   responsible for freeing the memory.  */
65
static char *
66
xml_diagnostic_build_prefix (diagnostic_info *diagnostic)
67
{
68
  static const char *const diagnostic_kind_text[] = {
69
#define DEFINE_DIAGNOSTIC_KIND(K, T) (T),
70
#include "diagnostic.def"
71
#undef DEFINE_DIAGNOSTIC_KIND
72
    "must-not-happen"
73
  };
74
  const char *class_text = diagnostic_kind_text[diagnostic->kind];
75
  expanded_location s = expand_location (diagnostic->location);
76
  if (diagnostic->override_column)
77
    s.column = diagnostic->override_column;
78
  gcc_assert (diagnostic->kind < DK_LAST_DIAGNOSTIC_KIND);
79
80
  return
81
    (s.file == NULL
82
     ? build_message_string ("<diagnostic class=\"%s\" location=\"%s\">\n",
83
			     class_text, progname)
84
     : flag_show_column
85
     ? build_message_string ("<diagnostic class=\"%s\" location=\"%s:%d:%d\">\n", 
86
			     class_text, s.file, s.line, s.column)
87
     : build_message_string ("<diagnostic class=\"%s\" location=\"%s:%d\">\n",
88
			     class_text, s.file, s.line));
89
}
90
91
static void
92
xml_diagnostic_report_current_module (diagnostic_context *context)
93
{
94
  const struct line_map *map;
95
96
  if (pp_needs_newline (context->printer))
97
    {
98
      pp_newline (context->printer);
99
      pp_needs_newline (context->printer) = false;
100
    }
101
102
  if (input_location <= BUILTINS_LOCATION)
103
    return;
104
105
  map = linemap_lookup (line_table, input_location);
106
  if (map && diagnostic_last_module_changed (context, map))
107
    {
108
      diagnostic_set_last_module (context, map);
109
      if (! MAIN_FILE_P (map))
110
	{
111
	  map = INCLUDED_FROM (line_table, map);
112
	  if (flag_show_column)
113
	    pp_verbatim (context->printer,
114
			 "Included from %s:%d:%d",
115
			 map->to_file,
116
			 LAST_SOURCE_LINE (map), LAST_SOURCE_COLUMN (map));
117
	  else
118
	    pp_verbatim (context->printer,
119
			 "In file included from %s:%d",
120
			 map->to_file, LAST_SOURCE_LINE (map));
121
	  while (! MAIN_FILE_P (map))
122
	    {
123
	      map = INCLUDED_FROM (line_table, map);
124
	      pp_verbatim (context->printer,
125
			   ",\n                 from %s:%d",
126
			   map->to_file, LAST_SOURCE_LINE (map));
127
	    }
128
	  pp_verbatim (context->printer, ":");
129
	  pp_newline (context->printer);
130
	}
131
    }
132
}
133
134
static void
135
xml_diagnostic_starter (diagnostic_context *context,
136
			diagnostic_info *diagnostic)
137
{
138
  context->printer->wrapping.rule = DIAGNOSTICS_SHOW_PREFIX_ONCE;
139
  xml_diagnostic_report_current_module (context);
140
  lang_hooks.print_error_function (context, input_filename, diagnostic);
141
  pp_set_prefix (context->printer, xml_diagnostic_build_prefix (diagnostic));
142
}
143
144
/* Initialize the diagnostic message outputting machinery.  */
145
void
146
xml_diagnostic_initialize (diagnostic_context *context)
147
{
148
  /* Default diagnostic_initialize should have been run again.  */
149
  gcc_assert (context);
150
  /* Override with xml variants.  */
151
  diagnostic_starter (context) = xml_diagnostic_starter;
152
  diagnostic_finalizer (context) = xml_diagnostic_finalizer;
153
}
154
155
156
static void
157
xml_diagnostic_finalizer (diagnostic_context *context,
158
				  diagnostic_info *diagnostic ATTRIBUTE_UNUSED)
159
{
160
  pp_newline (context->printer);
161
  pp_verbatim (context->printer, "</diagnostic>");
162
  pp_newline (context->printer);
163
  pp_destroy_prefix (context->printer);
164
}
(-)gcc/diagnostic.c (-15 / +6 lines)
Lines 151-172 diagnostic_build_prefix (diagnostic_info Link Here
151
#define DEFINE_DIAGNOSTIC_KIND(K, T) (T),
151
#define DEFINE_DIAGNOSTIC_KIND(K, T) (T),
152
#include "diagnostic.def"
152
#include "diagnostic.def"
153
#undef DEFINE_DIAGNOSTIC_KIND
153
#undef DEFINE_DIAGNOSTIC_KIND
154
    "must-not-happen"
154
    "must-not-happen"
155
  };
155
  };
156
  const char *text = _(diagnostic_kind_text[diagnostic->kind]);
156
  const char *kind_text = _(diagnostic_kind_text[diagnostic->kind]);
157
  expanded_location s = expand_location (diagnostic->location);
157
  expanded_location s = expand_location (diagnostic->location);
158
  if (diagnostic->override_column)
158
  if (diagnostic->override_column)
159
    s.column = diagnostic->override_column;
159
    s.column = diagnostic->override_column;
160
  gcc_assert (diagnostic->kind < DK_LAST_DIAGNOSTIC_KIND);
160
  gcc_assert (diagnostic->kind < DK_LAST_DIAGNOSTIC_KIND);
161
161
162
  return
162
  return
163
    (s.file == NULL
163
    (s.file == NULL
164
     ? build_message_string ("%s: %s", progname, text)
164
     ? build_message_string ("%s: %s: ", progname, kind_text)
165
     : flag_show_column
165
     : flag_show_column
166
     ? build_message_string ("%s:%d:%d: %s", s.file, s.line, s.column, text)
166
     ? build_message_string ("%s:%d:%d: %s: ", s.file, s.line, s.column, kind_text)
167
     : build_message_string ("%s:%d: %s", s.file, s.line, text));
167
     : build_message_string ("%s:%d: %s: ", s.file, s.line, kind_text));
168
}
168
}
169
169
170
/* Take any action which is expected to happen after the diagnostic
170
/* Take any action which is expected to happen after the diagnostic
171
   is written out.  This function does not always return.  */
171
   is written out.  This function does not always return.  */
172
static void
172
static void
Lines 211-230 diagnostic_action_after_output (diagnost Link Here
211
    default:
211
    default:
212
      gcc_unreachable ();
212
      gcc_unreachable ();
213
    }
213
    }
214
}
214
}
215
215
216
/* Prints out, if necessary, the name of the current function
217
   that caused an error.  Called from all error and warning functions.  */
218
void
219
diagnostic_report_current_function (diagnostic_context *context,
220
				    diagnostic_info *diagnostic)
221
{
222
  diagnostic_report_current_module (context);
223
  lang_hooks.print_error_function (context, input_filename, diagnostic);
224
}
225
226
void
216
void
227
diagnostic_report_current_module (diagnostic_context *context)
217
diagnostic_report_current_module (diagnostic_context *context)
228
{
218
{
229
  const struct line_map *map;
219
  const struct line_map *map;
230
220
Lines 268-278 diagnostic_report_current_module (diagno Link Here
268
258
269
static void
259
static void
270
default_diagnostic_starter (diagnostic_context *context,
260
default_diagnostic_starter (diagnostic_context *context,
271
			    diagnostic_info *diagnostic)
261
			    diagnostic_info *diagnostic)
272
{
262
{
273
  diagnostic_report_current_function (context, diagnostic);
263
  diagnostic_report_current_module (context);
264
  lang_hooks.print_error_function (context, input_filename, diagnostic);
274
  pp_set_prefix (context->printer, diagnostic_build_prefix (diagnostic));
265
  pp_set_prefix (context->printer, diagnostic_build_prefix (diagnostic));
275
}
266
}
276
267
277
static void
268
static void
278
default_diagnostic_finalizer (diagnostic_context *context,
269
default_diagnostic_finalizer (diagnostic_context *context,
(-)gcc/diagnostic-xml.h (+29 lines)
Line 0 Link Here
1
/* Language-independent diagnostic subroutines for the GNU Compiler Collection
2
   Copyright (C) 2009 Free Software Foundation, Inc.
3
   Contributed by Manuel Lopez-Ibanez <manu@gcc.gnu.org>
4
5
This file is part of GCC.
6
7
GCC is free software; you can redistribute it and/or modify it under
8
the terms of the GNU General Public License as published by the Free
9
Software Foundation; either version 3, or (at your option) any later
10
version.
11
12
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13
WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15
for more details.
16
17
You should have received a copy of the GNU General Public License
18
along with GCC; see the file COPYING3.  If not see
19
<http://www.gnu.org/licenses/>.  */
20
21
#ifndef GCC_DIAGNOSTIC_XML_H
22
#define GCC_DIAGNOSTIC_XML_H
23
24
#include "diagnostic.h"
25
26
void
27
xml_diagnostic_initialize (diagnostic_context *context);
28
29
#endif /* ! GCC_DIAGNOSTIC_XML_H */
(-)gcc/diagnostic.h (-2 lines)
Lines 191-202 extern diagnostic_context *global_dc; Link Here
191
#define diagnostic_override_column(DI, COL) (DI)->override_column = (COL)
191
#define diagnostic_override_column(DI, COL) (DI)->override_column = (COL)
192
192
193
/* Diagnostic related functions.  */
193
/* Diagnostic related functions.  */
194
extern void diagnostic_initialize (diagnostic_context *);
194
extern void diagnostic_initialize (diagnostic_context *);
195
extern void diagnostic_report_current_module (diagnostic_context *);
195
extern void diagnostic_report_current_module (diagnostic_context *);
196
extern void diagnostic_report_current_function (diagnostic_context *,
197
						diagnostic_info *);
198
196
199
/* Force diagnostics controlled by OPTIDX to be kind KIND.  */
197
/* Force diagnostics controlled by OPTIDX to be kind KIND.  */
200
extern diagnostic_t diagnostic_classify_diagnostic (diagnostic_context *,
198
extern diagnostic_t diagnostic_classify_diagnostic (diagnostic_context *,
201
						    int /* optidx */,
199
						    int /* optidx */,
202
						    diagnostic_t /* kind */);
200
						    diagnostic_t /* kind */);
(-)gcc/opts.c (+6 lines)
Lines 34-43 along with GCC; see the file COPYING3. Link Here
34
#include "options.h"
34
#include "options.h"
35
#include "flags.h"
35
#include "flags.h"
36
#include "toplev.h"
36
#include "toplev.h"
37
#include "params.h"
37
#include "params.h"
38
#include "diagnostic.h"
38
#include "diagnostic.h"
39
#include "diagnostic-xml.h"
39
#include "tm_p.h"		/* For OPTIMIZATION_OPTIONS.  */
40
#include "tm_p.h"		/* For OPTIMIZATION_OPTIONS.  */
40
#include "insn-attr.h"		/* For INSN_SCHEDULING.  */
41
#include "insn-attr.h"		/* For INSN_SCHEDULING.  */
41
#include "target.h"
42
#include "target.h"
42
#include "tree-pass.h"
43
#include "tree-pass.h"
43
#include "dbgcnt.h"
44
#include "dbgcnt.h"
Lines 1712-1721 common_handle_option (size_t scode, cons Link Here
1712
1713
1713
    case OPT_fdiagnostics_show_option:
1714
    case OPT_fdiagnostics_show_option:
1714
      global_dc->show_option_requested = true;
1715
      global_dc->show_option_requested = true;
1715
      break;
1716
      break;
1716
1717
1718
    case OPT_fdiagnostics_mode_:
1719
      if (!strcmp (arg, "xml"))
1720
	xml_diagnostic_initialize (global_dc);
1721
      break;
1722
1717
    case OPT_fdump_:
1723
    case OPT_fdump_:
1718
      if (!dump_switch_p (arg))
1724
      if (!dump_switch_p (arg))
1719
	return 0;
1725
	return 0;
1720
      break;
1726
      break;
1721
1727
(-)gcc/common.opt (+4 lines)
Lines 452-461 Common Joined RejectNegative Link Here
452
452
453
fdiagnostics-show-option
453
fdiagnostics-show-option
454
Common
454
Common
455
Amend appropriate diagnostic messages with the command line option that controls them
455
Amend appropriate diagnostic messages with the command line option that controls them
456
456
457
fdiagnostics-mode=
458
Common Joined RejectNegative
459
Specify the output type for diagnostics, either 'xml' or 'default'
460
457
fdump-
461
fdump-
458
Common Joined RejectNegative
462
Common Joined RejectNegative
459
-fdump-<type>	Dump various compiler internals to a file
463
-fdump-<type>	Dump various compiler internals to a file
460
464
461
fdump-final-insns=
465
fdump-final-insns=
(-)gcc/Makefile.in (+6 lines)
Lines 904-913 TREE_FLOW_H = tree-flow.h tree-flow-inli Link Here
904
		tree-ssa-alias.h
904
		tree-ssa-alias.h
905
TREE_SSA_LIVE_H = tree-ssa-live.h $(PARTITION_H) vecprim.h
905
TREE_SSA_LIVE_H = tree-ssa-live.h $(PARTITION_H) vecprim.h
906
SSAEXPAND_H = ssaexpand.h $(TREE_SSA_LIVE_H)
906
SSAEXPAND_H = ssaexpand.h $(TREE_SSA_LIVE_H)
907
PRETTY_PRINT_H = pretty-print.h $(INPUT_H) $(OBSTACK_H)
907
PRETTY_PRINT_H = pretty-print.h $(INPUT_H) $(OBSTACK_H)
908
DIAGNOSTIC_H = diagnostic.h diagnostic.def $(PRETTY_PRINT_H) options.h
908
DIAGNOSTIC_H = diagnostic.h diagnostic.def $(PRETTY_PRINT_H) options.h
909
DIAGNOSTIC_XML_H = diagnostic.h diagnostic.def $(PRETTY_PRINT_H) options.h
909
C_PRETTY_PRINT_H = c-pretty-print.h $(PRETTY_PRINT_H) $(C_COMMON_H) $(TREE_H)
910
C_PRETTY_PRINT_H = c-pretty-print.h $(PRETTY_PRINT_H) $(C_COMMON_H) $(TREE_H)
910
SCEV_H = tree-scalar-evolution.h $(GGC_H) tree-chrec.h $(PARAMS_H)
911
SCEV_H = tree-scalar-evolution.h $(GGC_H) tree-chrec.h $(PARAMS_H)
911
LAMBDA_H = lambda.h $(TREE_H) vec.h $(GGC_H)
912
LAMBDA_H = lambda.h $(TREE_H) vec.h $(GGC_H)
912
TREE_DATA_REF_H = tree-data-ref.h $(LAMBDA_H) omega.h graphds.h $(SCEV_H)
913
TREE_DATA_REF_H = tree-data-ref.h $(LAMBDA_H) omega.h graphds.h $(SCEV_H)
913
VARRAY_H = varray.h $(MACHMODE_H) $(SYSTEM_H) coretypes.h $(TM_H)
914
VARRAY_H = varray.h $(MACHMODE_H) $(SYSTEM_H) coretypes.h $(TM_H)
Lines 1146-1155 OBJS-common = \ Link Here
1146
	df-core.o \
1147
	df-core.o \
1147
	df-problems.o \
1148
	df-problems.o \
1148
	df-scan.o \
1149
	df-scan.o \
1149
	dfp.o \
1150
	dfp.o \
1150
	diagnostic.o \
1151
	diagnostic.o \
1152
	diagnostic-xml.o \
1151
	dojump.o \
1153
	dojump.o \
1152
	dominance.o \
1154
	dominance.o \
1153
	domwalk.o \
1155
	domwalk.o \
1154
	double-int.o \
1156
	double-int.o \
1155
	dse.o \
1157
	dse.o \
Lines 2589-2598 fold-const.o : fold-const.c $(CONFIG_H) Link Here
2589
   $(GIMPLE_H)
2591
   $(GIMPLE_H)
2590
diagnostic.o : diagnostic.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
2592
diagnostic.o : diagnostic.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
2591
   $(TREE_H) version.h $(TM_P_H) $(FLAGS_H) $(INPUT_H) $(TOPLEV_H) intl.h \
2593
   $(TREE_H) version.h $(TM_P_H) $(FLAGS_H) $(INPUT_H) $(TOPLEV_H) intl.h \
2592
   $(DIAGNOSTIC_H) langhooks.h $(LANGHOOKS_DEF_H) diagnostic.def opts.h \
2594
   $(DIAGNOSTIC_H) langhooks.h $(LANGHOOKS_DEF_H) diagnostic.def opts.h \
2593
   $(PLUGIN_H)
2595
   $(PLUGIN_H)
2596
diagnostic-xml.o : diagnostic-xml.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
2597
   $(TREE_H) version.h $(TM_P_H) $(FLAGS_H) $(INPUT_H) $(TOPLEV_H) intl.h \
2598
   $(DIAGNOSTIC_XML_H) $(DIAGNOSTIC_H) langhooks.h $(LANGHOOKS_DEF_H) diagnostic.def opts.h \
2599
   $(PLUGIN_H)
2594
opts.o : opts.c opts.h options.h $(TOPLEV_H) $(CONFIG_H) $(SYSTEM_H) \
2600
opts.o : opts.c opts.h options.h $(TOPLEV_H) $(CONFIG_H) $(SYSTEM_H) \
2595
   coretypes.h $(TREE_H) $(TM_H) langhooks.h $(GGC_H) $(EXPR_H) $(RTL_H) \
2601
   coretypes.h $(TREE_H) $(TM_H) langhooks.h $(GGC_H) $(EXPR_H) $(RTL_H) \
2596
   output.h $(DIAGNOSTIC_H) $(TM_P_H) $(INSN_ATTR_H) intl.h $(TARGET_H) \
2602
   output.h $(DIAGNOSTIC_H) $(TM_P_H) $(INSN_ATTR_H) intl.h $(TARGET_H) \
2597
   $(FLAGS_H) $(PARAMS_H) $(TREE_PASS_H) $(DBGCNT_H) debug.h varray.h \
2603
   $(FLAGS_H) $(PARAMS_H) $(TREE_PASS_H) $(DBGCNT_H) debug.h varray.h \
2598
   $(PLUGIN_H)
2604
   $(PLUGIN_H)

Return to bug 19165