scripts: Add more information to dump_syms failures

dump_syms will sometimes abort unexpectedly when trying to generate
symbols using the elf + debug files. There are useful debugging
messages in the output (particularly, the abort message), but we're
throwing the information away.

We really want dump_syms to work in elf+debug case; the elf-only
fallback is not useful in many cases. In particular, we need it to work
more consistently for generating chrome symbols including the debug file.

Dump more info if dump_syms fails. Example output (for a .ko file, which
we don't expect to work -- this is just to show what the output looks
like):

14:49:55.677: WARNING: dump_syms ['/build/eve/lib/modules/5.4.209-19290-g970e38523367/kernel/sound/usb/snd-usb-audio.ko', '/build/eve/usr/lib/debug/lib/modules/5.4.209-19290-g970e38523367/kernel/sound/usb/snd-usb-audio.ko.debug'] crashed with SIGIOT|SIGABRT; retrying w/out CFI
14:49:55.678: WARNING: output:
/build/eve/lib/modules/5.4.209-19290-g970e38523367/kernel/sound/usb/snd-usb-audio.ko: file contains no debugging information (no ".stab" or ".debug_info" sections)
Found debugging info in /build/eve/usr/lib/debug/lib/modules/5.4.209-19290-g970e38523367/kernel/sound/usb/snd-usb-audio.ko.debug
Section .symtab has already been loaded.
libc++abi: terminating with uncaught exception of type std::out_of_range: vector

14:49:55.694: WARNING: dump_syms ['/build/eve/lib/modules/5.4.209-19290-g970e38523367/kernel/sound/usb/snd-usb-audio.ko', '/build/eve/usr/lib/debug/lib/modules/5.4.209-19290-g970e38523367/kernel/sound/usb/snd-usb-audio.ko.debug'] crashed with SIGIOT|SIGABRT; retrying w/out debug
14:49:55.694: WARNING: output:
/build/eve/lib/modules/5.4.209-19290-g970e38523367/kernel/sound/usb/snd-usb-audio.ko: file contains no debugging information (no ".stab" or ".debug_info" sections)
Found debugging info in /build/eve/usr/lib/debug/lib/modules/5.4.209-19290-g970e38523367/kernel/sound/usb/snd-usb-audio.ko.debug
Section .symtab has already been loaded.
libc++abi: terminating with uncaught exception of type std::out_of_range: vector

BUG=b:241470012
TEST=Ran `cros_generate_breakpad_symbols  --board=eve`

Change-Id: I5c3d0a803200a910dd36143882500147c722eab7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/3828521
Commit-Queue: Ian Barkley-Yeung <iby@chromium.org>
Tested-by: Ian Barkley-Yeung <iby@chromium.org>
Reviewed-by: Tim Bain <tbain@google.com>
diff --git a/scripts/cros_generate_breakpad_symbols.py b/scripts/cros_generate_breakpad_symbols.py
index 89b6ae1..f9654ed 100644
--- a/scripts/cros_generate_breakpad_symbols.py
+++ b/scripts/cros_generate_breakpad_symbols.py
@@ -103,11 +103,17 @@
         cmd_base + cmd_args, stderr=True, stdout=temp.name,
         check=False, debug_level=logging.DEBUG)
 
-  def _CrashCheck(ret, msg):
-    if ret < 0:
+  def _CrashCheck(result, file_or_files, msg):
+    if result.returncode:
       cbuildbot_alerts.PrintBuildbotStepWarnings()
-      logging.warning('dump_syms crashed with %s; %s',
-                      signals.StrSignal(-ret), msg)
+      if result.returncode < 0:
+        logging.warning('dump_syms %s crashed with %s; %s',
+                        file_or_files, signals.StrSignal(-result.returncode),
+                        msg)
+      else:
+        logging.warning('dump_syms %s returned %d; %s',
+                        file_or_files, result.returncode, msg)
+      logging.warning('output:\n%s', result.stderr.decode('utf-8'))
 
   osutils.SafeMakedirs(breakpad_dir)
   with cros_build_lib.UnbufferedNamedTemporaryFile(
@@ -116,8 +122,10 @@
       # Try to dump the symbols using the debug file like normal.
       if debug_file_only:
         cmd_args = [debug_file]
+        file_or_files = debug_file
       else:
         cmd_args = [elf_file, os.path.dirname(debug_file)]
+        file_or_files = [elf_file, debug_file]
 
       result = _DumpIt(cmd_args)
 
@@ -125,10 +133,10 @@
         # Sometimes dump_syms can crash because there's too much info.
         # Try dumping and stripping the extended stuff out.  At least
         # this way we'll get the extended symbols.  https://crbug.com/266064
-        _CrashCheck(result.returncode, 'retrying w/out CFI')
+        _CrashCheck(result, file_or_files, 'retrying w/out CFI')
         cmd_args = ['-c', '-r'] + cmd_args
         result = _DumpIt(cmd_args)
-        _CrashCheck(result.returncode, 'retrying w/out debug')
+        _CrashCheck(result, file_or_files, 'retrying w/out debug')
 
       basic_dump = result.returncode
     else:
@@ -142,13 +150,12 @@
         # A lot of files (like kernel files) contain no debug information,
         # do not consider such occurrences as errors.
         cbuildbot_alerts.PrintBuildbotStepWarnings()
-        _CrashCheck(result.returncode, 'giving up entirely')
         if b'file contains no debugging information' in result.stderr:
-          logging.warning('no symbols found for %s', elf_file)
+          logging.warning('dump_syms failed; giving up entirely.')
+          logging.warning('No symbols found for %s', elf_file)
         else:
           num_errors.value += 1
-          logging.error('dumping symbols for %s failed:\n%s', elf_file,
-                        result.stderr.decode('utf-8'))
+          _CrashCheck(result, elf_file, 'giving up entirely')
         os.unlink(temp.name)
         return num_errors.value