aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2016-08-19 00:18:18 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2016-08-19 00:18:18 +0000
commit82f72146967e71693f2d4f6646f35c3c00780602 (patch)
tree5faef7399b046f2419d8c84d6f16545f6f1e97cc /gcc
parentf4e46e34a2c517e1c6c3d0802aba82a9637d677d (diff)
downloadgcc-82f72146967e71693f2d4f6646f35c3c00780602.zip
gcc-82f72146967e71693f2d4f6646f35c3c00780602.tar.gz
gcc-82f72146967e71693f2d4f6646f35c3c00780602.tar.bz2
Add source information to -fverbose-asm
gcc/ChangeLog: * doc/invoke.texi (fverbose-asm): Note that source code lines are emitted, and provide an example. * final.c (asm_show_source): New function. (final_scan_insn): Call asm_show_source. From-SVN: r239604
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/doc/invoke.texi83
-rw-r--r--gcc/final.c28
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/verbose-asm-2.c15
5 files changed, 135 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c268e00..65efe1e 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,12 @@
2016-08-18 David Malcolm <dmalcolm@redhat.com>
+ * doc/invoke.texi (fverbose-asm): Note that source code lines
+ are emitted, and provide an example.
+ * final.c (asm_show_source): New function.
+ (final_scan_insn): Call asm_show_source.
+
+2016-08-18 David Malcolm <dmalcolm@redhat.com>
+
* diagnostic-show-locus.c (colorizer::colorizer): Replace diagnostic
param with diagnostic_kind.
(class colorizer): Similarly replace field m_diagnostic with
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index d04be6f..1f04501 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -11426,6 +11426,89 @@ debugging the compiler itself).
extra information to be omitted and is useful when comparing two assembler
files.
+The added comments include:
+
+@itemize @bullet
+
+@item
+information on the compiler version and command-line options,
+
+@item
+the source code lines associated with the assembly instructions,
+in the form FILENAME:LINENUMBER:CONTENT OF LINE,
+
+@item
+hints on which high-level expressions correspond to
+the various assembly instruction operands.
+
+@end itemize
+
+For example, given this C source file:
+
+@smallexample
+int test (int n)
+@{
+ int i;
+ int total = 0;
+
+ for (i = 0; i < n; i++)
+ total += i * i;
+
+ return total;
+@}
+@end smallexample
+
+compiling to (x86_64) assembly via @option{-S} and emitting the result
+direct to stdout via @option{-o} @option{-}
+
+@smallexample
+gcc -S test.c -fverbose-asm -Os -o -
+@end smallexample
+
+gives output similar to this:
+
+@smallexample
+ .file "test.c"
+# GNU C11 (GCC) version 7.0.0 20160809 (experimental) (x86_64-pc-linux-gnu)
+ [...snip...]
+# options passed:
+ [...snip...]
+
+ .text
+ .globl test
+ .type test, @@function
+test:
+.LFB0:
+ .cfi_startproc
+# test.c:4: int total = 0;
+ xorl %eax, %eax # <retval>
+# test.c:6: for (i = 0; i < n; i++)
+ xorl %edx, %edx # i
+.L2:
+# test.c:6: for (i = 0; i < n; i++)
+ cmpl %edi, %edx # n, i
+ jge .L5 #,
+# test.c:7: total += i * i;
+ movl %edx, %ecx # i, tmp92
+ imull %edx, %ecx # i, tmp92
+# test.c:6: for (i = 0; i < n; i++)
+ incl %edx # i
+# test.c:7: total += i * i;
+ addl %ecx, %eax # tmp92, <retval>
+ jmp .L2 #
+.L5:
+# test.c:10: @}
+ ret
+ .cfi_endproc
+.LFE0:
+ .size test, .-test
+ .ident "GCC: (GNU) 7.0.0 20160809 (experimental)"
+ .section .note.GNU-stack,"",@@progbits
+@end smallexample
+
+The comments are intended for humans rather than machines and hence the
+precise format of the comments is subject to change.
+
@item -frecord-gcc-switches
@opindex frecord-gcc-switches
This switch causes the command line used to invoke the
diff --git a/gcc/final.c b/gcc/final.c
index 5b04311..eccc3d8 100644
--- a/gcc/final.c
+++ b/gcc/final.c
@@ -2140,6 +2140,26 @@ call_from_call_insn (rtx_call_insn *insn)
return x;
}
+/* Print a comment into the asm showing FILENAME, LINENUM, and the
+ corresponding source line, if available. */
+
+static void
+asm_show_source (const char *filename, int linenum)
+{
+ if (!filename)
+ return;
+
+ int line_size;
+ const char *line = location_get_source_line (filename, linenum, &line_size);
+ if (!line)
+ return;
+
+ fprintf (asm_out_file, "%s %s:%i: ", ASM_COMMENT_START, filename, linenum);
+ /* "line" is not 0-terminated, so we must use line_size. */
+ fwrite (line, 1, line_size, asm_out_file);
+ fputc ('\n', asm_out_file);
+}
+
/* The final scan for one insn, INSN.
Args are same as in `final', except that INSN
is the insn being scanned.
@@ -2563,8 +2583,12 @@ final_scan_insn (rtx_insn *insn, FILE *file, int optimize_p ATTRIBUTE_UNUSED,
note in a row. */
if (!DECL_IGNORED_P (current_function_decl)
&& notice_source_line (insn, &is_stmt))
- (*debug_hooks->source_line) (last_linenum, last_filename,
- last_discriminator, is_stmt);
+ {
+ if (flag_verbose_asm)
+ asm_show_source (last_filename, last_linenum);
+ (*debug_hooks->source_line) (last_linenum, last_filename,
+ last_discriminator, is_stmt);
+ }
if (GET_CODE (body) == PARALLEL
&& GET_CODE (XVECEXP (body, 0, 0)) == ASM_INPUT)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 7da5595..dd893ca 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,9 @@
2016-08-18 David Malcolm <dmalcolm@redhat.com>
+ * gcc.dg/verbose-asm-2.c: New test case.
+
+2016-08-18 David Malcolm <dmalcolm@redhat.com>
+
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
(custom_diagnostic_finalizer): Update for change to
diagnostic_show_locus.
diff --git a/gcc/testsuite/gcc.dg/verbose-asm-2.c b/gcc/testsuite/gcc.dg/verbose-asm-2.c
new file mode 100644
index 0000000..747bff1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/verbose-asm-2.c
@@ -0,0 +1,15 @@
+/* Ensure that the -fverbose-asm leads to source code information in the generated asm. */
+/* { dg-options "-fverbose-asm" } */
+
+int test (int n)
+{
+ int i;
+ int total = 0;
+
+ for (i = 0; i < n; i++)
+ total += i * i;
+
+ return total;
+}
+
+/* { dg-final { scan-assembler "total = 0" } } */