Add a runtime flag Wprint-abs-path 34/161434/3
authorOleg Ogurtsov <o.ogurtsov@samsung.com>
Thu, 23 Nov 2017 09:30:36 +0000 (12:30 +0300)
committerOleg Ogurtsov <o.ogurtsov@samsung.com>
Tue, 5 Dec 2017 12:08:07 +0000 (15:08 +0300)
A runtime flag for printing a real path to the source file on warning.

gcc/
* Makefile.in: added dependencies of linking.
* common.opt: added a flag description.
* diagnostic.c: added the dependence of the runtime flag and
implementation.

Change-Id: I3eb9178892f3c230845dc8e5c9ab4e1b1613f6f0

gcc/Makefile.in
gcc/common.opt
gcc/diagnostic.c

index 46aaac4..72afff1 100644 (file)
@@ -1553,6 +1553,10 @@ OBJS-libcommon-target = $(common_out_object_file) prefix.o params.o \
        opts.o opts-common.o options.o vec.o hooks.o common/common-targhooks.o \
        hash-table.o file-find.o
 
+OBJS-diagnostics-common = \
+       $(common_out_object_file) prefix.o params.o \
+       opts.o opts-common.o options.o hooks.o common/common-targhooks.o
+
 # This lists all host objects for the front ends.
 ALL_HOST_FRONTEND_OBJS = $(foreach v,$(CONFIG_LANGUAGES),$($(v)_OBJS))
 
@@ -1993,7 +1997,7 @@ COLLECT2_LIBS = @COLLECT2_LIBS@
 collect2$(exeext): $(COLLECT2_OBJS) $(LIBDEPS)
 # Don't try modifying collect2 (aka ld) in place--it might be linking this.
        +$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o T$@ \
-               $(COLLECT2_OBJS) $(LIBS) $(COLLECT2_LIBS)
+               $(COLLECT2_OBJS) $(LIBS) $(COLLECT2_LIBS) $(OBJS-diagnostics-common)
        mv -f T$@ $@
 
 CFLAGS-collect2.o += -DTARGET_MACHINE=\"$(target_noncanonical)\" \
@@ -2731,12 +2735,13 @@ s-iov: build/gcov-iov$(build_exeext) $(BASEVER) $(DEVPHASE)
 GCOV_OBJS = gcov.o
 gcov$(exeext): $(GCOV_OBJS) $(LIBDEPS)
        +$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) $(GCOV_OBJS) \
-               hash-table.o ggc-none.o $(LIBS) -o $@
+               hash-table.o ggc-none.o $(LIBS) \
+               $(OBJS-diagnostics-common) -o $@
 GCOV_DUMP_OBJS = gcov-dump.o
 gcov-dump$(exeext): $(GCOV_DUMP_OBJS) $(LIBDEPS)
        +$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) $(GCOV_DUMP_OBJS) \
                hash-table.o ggc-none.o\
-               $(LIBS) -o $@
+               $(LIBS) $(OBJS-diagnostics-common) -o $@
 
 GCOV_TOOL_DEP_FILES = $(srcdir)/../libgcc/libgcov-util.c gcov-io.c $(GCOV_IO_H) \
   $(srcdir)/../libgcc/libgcov-driver.c $(srcdir)/../libgcc/libgcov-driver-system.c \
@@ -2752,7 +2757,8 @@ libgcov-merge-tool.o: $(srcdir)/../libgcc/libgcov-merge.c $(GCOV_TOOL_DEP_FILES)
          -DIN_GCOV_TOOL=1 -o $@ $<
 GCOV_TOOL_OBJS = gcov-tool.o libgcov-util.o libgcov-driver-tool.o libgcov-merge-tool.o
 gcov-tool$(exeext): $(GCOV_TOOL_OBJS) $(LIBDEPS)
-       +$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) $(GCOV_TOOL_OBJS) $(LIBS) -o $@
+       +$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) $(GCOV_TOOL_OBJS) $(LIBS) \
+               $(OBJS-diagnostics-common) -o $@
 #\f
 # Build the include directories.  The stamp files are stmp-* rather than
 # s-* so that mostlyclean does not force the include directory to
index 67048db..1dc66d5 100644 (file)
@@ -655,6 +655,10 @@ Wpedantic
 Common Var(pedantic) Init(0) Warning
 Issue warnings needed for strict compliance to the standard.
 
+Wprint-abs-path
+Common Var(flag_source_abs_path) Init(0)
+Print a absolute path to the source file.
+
 Wreturn-local-addr
 Common Var(warn_return_local_addr) Init(1) Warning
 Warn about returning a pointer/reference to a local or temporary variable.
index 8106172..745b8ae 100644 (file)
@@ -27,6 +27,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "coretypes.h"
 #include "version.h"
 #include "demangle.h"
+#include "options.h"
 #include "intl.h"
 #include "backtrace.h"
 #include "diagnostic.h"
@@ -290,12 +291,21 @@ diagnostic_get_location_text (diagnostic_context *context,
   if (!strcmp (s.file, N_("<built-in>")))
     return build_message_string ("%s%s:%s", locus_cs, s.file, locus_ce);
 
+  char *resolved_path = NULL;
+  if (flag_source_abs_path != 0)
+    resolved_path = realpath (s.file, NULL);
+
+  char *ret;
   if (context->show_column)
-    return build_message_string ("%s%s:%d:%d:%s", locus_cs, s.file, s.line,
-                                s.column, locus_ce);
+    ret = build_message_string ("%s%s:%d:%d:%s", locus_cs,
+                                (!resolved_path ? s.file : resolved_path),
+                                s.line, s.column, locus_ce);
   else
-    return build_message_string ("%s%s:%d:%s", locus_cs, s.file, s.line,
-                                locus_ce);
+    ret = build_message_string ("%s%s:%d:%s", locus_cs,
+                                (!resolved_path ? s.file : resolved_path),
+                                s.line, locus_ce);
+  free(resolved_path);
+  return ret;
 }
 
 /* Return a malloc'd string describing a location and the severity of the