public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] cc-with-tweaks: show dwz stderr and verify result
@ 2019-05-10 20:30 Simon Marchi
  0 siblings, 0 replies; only message in thread
From: Simon Marchi @ 2019-05-10 20:30 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a9eac7f9b45e92b83db476d167e5ff26607a8b47

commit a9eac7f9b45e92b83db476d167e5ff26607a8b47
Author: Simon Marchi <simon.marchi@efficios.com>
Date:   Fri May 10 16:29:00 2019 -0400

    cc-with-tweaks: show dwz stderr and verify result
    
    When running the gdb.base/index-cache.exp test case with the
    cc-with-dwz-m board, I noticed that the final executable didn't actually
    contain a .gnu_debugaltlink section with the name of the external dwz
    file:
    
        $ readelf --debug-dump=links testsuite/outputs/gdb.base/index-cache/index-cache
        * empty *
    
    Running dwz by hand, I realized it's because dwz complains that the
    output .debug_info section is empty and fails:
    
        $ gcc ~/src/binutils-gdb/gdb/testsuite/gdb.base/index-cache.c -g3 -O0 -o a && cp a b
        $ dwz -m foo a b
        dwz: foo: .debug_info section not present
        $ echo $?
        1
    
    This is because index-cache.c is trivial (just an empty main) and dwz
    doesn't find anything to factor out to the dwz file. [1]
    
    I think that cc-with-tweaks should fail in this scenario: if the user
    asks for an external dwz file to be generated (the -m flag), then it
    should be an error if cc-with-tweaks doesn't manage to produce an
    executable with the proper link to this external dwz file.  Otherwise,
    the test runs with a regular non-dwzified executable, which gives a
    false sense of security about whether the feature under test works with
    dwzified executables.
    
    So this patch adds checks for that after invoking dwz.  It also removes
    the 2>&1 to allow the error message to be printed like so:
    
        Running /home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.base/index-cache.exp ...
        gdb compile failed, dwz: /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.base/index-cache/index-cache.dwz: .debug_info section not present
    
    - In the -m case (multi-file compression), we check if the expected output file
      exists.
    - In the -z case (single-file compression), we check if the file
      contents has changed.  This should catch cases where dwz doesn't modify the
      file because it's not worth it.
    
    It was chosen not to check for dwz's exit code, as it is not very
    reliable up to dwz 0.12.
    
    With this patch, fewer tests will pass than before with the
    cc-with-dwz and cc-with-dwz-m boards, but those were false positives
    anyway, as the test ran with regular executables.
    
    [1] Note that dwz has been patched by Tom de Vries to work correctly in
    this case, so we can use dwz master to run the test:
    
    https://sourceware.org/git/?p=dwz.git;a=commit;h=08becc8b33453b6d013a65e7eeae57fc1881e801
    
    gdb/ChangeLog:
    
    	* contrib/cc-with-tweaks.sh: Validate dwz's work.

Diff:
---
 gdb/ChangeLog                 |  4 ++++
 gdb/contrib/cc-with-tweaks.sh | 34 ++++++++++++++++++++++++++++++++--
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index f1c39a4..4da4096 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,7 @@
+2019-05-10  Simon Marchi  <simon.marchi@efficios.com>
+
+	* contrib/cc-with-tweaks.sh: Validate dwz's work.
+
 2019-05-10  Tom Tromey  <tromey@adacore.com>
 
 	* ada-lang.c (catch_ada_completer): New function.
diff --git a/gdb/contrib/cc-with-tweaks.sh b/gdb/contrib/cc-with-tweaks.sh
index 47379cc..7df16bc 100755
--- a/gdb/contrib/cc-with-tweaks.sh
+++ b/gdb/contrib/cc-with-tweaks.sh
@@ -180,11 +180,41 @@ if [ "$want_index" = true ]; then
 fi
 
 if [ "$want_dwz" = true ]; then
-    $DWZ "$output_file" > /dev/null 2>&1
+    # Validate dwz's result by checking if the executable was modified.
+    cp "$output_file" "${output_file}.copy"
+    $DWZ "$output_file" > /dev/null
+    cmp "$output_file" "$output_file.copy" > /dev/null
+    cmp_rc=$?
+    rm -f "${output_file}.copy"
+
+    case $cmp_rc in
+    0)
+	echo "$myname: dwz did not modify ${output_file}."
+        exit 1
+	;;
+    1)
+	# File was modified, great.
+	;;
+    *)
+	# Other cmp error, it presumably has already printed something on
+	# stderr.
+	exit 1
+	;;
+    esac
 elif [ "$want_multi" = true ]; then
+    # Remove the dwz output file if it exists, so we don't mistake it for a
+    # new file in case dwz fails.
+    rm -f "${output_file}.dwz"
+
     cp $output_file ${output_file}.alt
-    $DWZ -m ${output_file}.dwz "$output_file" ${output_file}.alt > /dev/null 2>&1
+    $DWZ -m ${output_file}.dwz "$output_file" ${output_file}.alt > /dev/null
     rm -f ${output_file}.alt
+
+    # Validate dwz's work by checking if the expected output file exists.
+    if [ ! -f "${output_file}.dwz" ]; then
+	echo "$myname: dwz file ${output_file}.dwz missing."
+	exit 1
+    fi
 fi
 
 if [ "$want_dwp" = true ]; then


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-05-10 20:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-10 20:30 [binutils-gdb] cc-with-tweaks: show dwz stderr and verify result Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).