]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
patch ../102422525.patch
authorDoug Evans <dje@google.com>
Thu, 10 Dec 2015 20:00:28 +0000 (12:00 -0800)
committerDoug Evans <dje@google.com>
Thu, 10 Dec 2015 20:00:28 +0000 (12:00 -0800)
README.google
gdb/exec.c
gdb/google.c
gdb/google.h
gdb/main.c
gdb/symfile.c
gdb/testsuite/gdb.base/sepdebug.exp
gdb/testsuite/lib/gdb.exp

index a13241190aa4de0fd22bd57e03b61d63e2290241..0561e3529120fdb12964863c454d4e3a219f2a56 100644 (file)
@@ -14,3 +14,23 @@ they are an ongoing maintenance burden.
        * Makefile.in: Add google.c.
        * google.c: New file.
        * google.h: New file.
+
+2015-09-05  Doug Evans  <dje@google.com>
+
+       Implement 1155829.
+       * exec.c (elf_64_p): New function.
+       (exec_file_attach): If the file format is not recognized, check if
+       it's 64-bit elf and if so recommend using 64-bit gdb. Improve error
+       message if binary is accidently a core file.
+       * main.c (captured_main): Call warn_troublesome_environment if !quiet.
+       * google.c (warn_troublesome_environment): New function.
+       * symfile.c (print_no_debugging_symbols_found): New function.
+       (symbol_file_add_with_addrs_or_offsets): Call it if no debugging
+       symbols found.
+       (reread_symbols): Ditto.
+       * testsuite/lib/gdb.exp (gdb_file_cmd): Update to match
+       output of print_no_debugging_symbols_found.
+       Properly update gdb_file_cmd_debug_info for nodebug when
+       loading new symbol table.
+       * testsuite/gdb.base/sepdebug.exp: Update expected output to match
+       "no debugging symbols found" warning change for 1155829.
index 3dfc437a9b313d29bf7c41ec883343db9f8830ff..0ea19801eddb51c76a1a8de8531ea2f4639dc0d8 100644 (file)
@@ -135,6 +135,23 @@ exec_file_clear (int from_tty)
     printf_unfiltered (_("No executable file now.\n"));
 }
 
+/* Bug 1155829.
+   Subroutine of exec_file_attach to simplify it.
+   Return non-zero if HEADER is a 64-bit ELF file.  */
+
+#include "elf/external.h"
+#include "elf/common.h"
+
+static int
+elf_64_p (Elf64_External_Ehdr *header)
+{
+  return (header->e_ident[EI_MAG0] == ELFMAG0
+          && header->e_ident[EI_MAG1] == ELFMAG1
+          && header->e_ident[EI_MAG2] == ELFMAG2
+          && header->e_ident[EI_MAG3] == ELFMAG3
+          && header->e_ident[EI_CLASS] == ELFCLASS64);
+}
+
 /* See gdbcore.h.  */
 
 void
@@ -297,12 +314,54 @@ exec_file_attach (const char *filename, int from_tty)
 
       if (!bfd_check_format_matches (exec_bfd, bfd_object, &matching))
        {
+         /* Bug 1155829.  If we're trying to debug a 64 bit binary with
+            32-bit gdb print a more useful error message.  */
+         bfd_error_type error_kind = bfd_get_error ();
+         struct gdbarch *cur_arch = target_gdbarch ();
+         const struct bfd_arch_info *arch = gdbarch_bfd_arch_info (cur_arch);
+         int is_core = 0, is_elf_64_on_32 = 0;
+
+         if (error_kind == bfd_error_file_not_recognized
+             && arch->arch == bfd_arch_i386)
+           {
+             Elf64_External_Ehdr header;
+
+             /* A common user error is "gdb core".  */
+             if (bfd_check_format_matches (current_program_space->ebfd, bfd_core, NULL))
+               is_core = 1;
+             else if (bfd_seek (exec_bfd, 0, SEEK_SET) == 0
+                      && bfd_bread (&header, sizeof (header), exec_bfd) == sizeof (header)
+                      && elf_64_p (&header))
+               is_elf_64_on_32 = 1;
+           }
+
          /* Make sure to close exec_bfd, or else "run" might try to use
             it.  */
          exec_close ();
-         error (_("\"%s\": not in executable format: %s"),
-                scratch_pathname,
-                gdb_bfd_errmsg (bfd_get_error (), matching));
+
+         if (is_core)
+           {
+             error (_("\n"
+                      "\"%s\": Is a core file.\n"
+                      "Do \"gdb binary core\" instead.\n"),
+                    scratch_pathname);
+           }
+         if (is_elf_64_on_32)
+           {
+             /* We enhance the text of the argument to error() instead of
+                printing the enhanced text here, we don't want to assume what
+                error() will do with the text.  */
+             error (_("\n"
+                      "\"%s\": Unable to debug 64-bit ELF file.\n"
+                      "To debug 64-bit binaries you need to use 64-bit gdb.\n"),
+                    scratch_pathname);
+           }
+         else
+           {
+             error (_("\"%s\": not in executable format: %s"),
+                    scratch_pathname,
+                gdb_bfd_errmsg (error_kind, matching));
+           }
        }
 
       if (build_section_table (exec_bfd, &sections, &sections_end))
index e0e87375924f0928f1ad09949406cea76c7e7954..9ad6ede16e5b019354cecfd18e7b48ad66518636 100644 (file)
 #include "defs.h"
 #include "google.h"
 
+/* Bug 1155829.
+   Warn about troublesome environment variables.
+   While it might be nice to move this to python/lib/google/google3/__init__.py
+   we'd have to export the quiet flag, which could be useful in general, but
+   later.  */
+
+void
+warn_troublesome_environment (void)
+{
+  const char *ld_library_path;
+
+  if (getenv ("LD_ASSUME_KERNEL") != NULL)
+    {
+      printf_filtered ("\n");
+      printf_filtered (_("WARNING: GDB has detected that you have set the\n"
+                         "LD_ASSUME_KERNEL environment variable.\n"));
+      printf_filtered (_("You may have intended to do this, but you should know\n"
+                         "that this can often cause problems while debugging.\n"));
+      printf_filtered (_("For more information see http://wiki/Main/GdbFaq#LD_ASSUME_KERNEL_usage_warning\n"));
+      printf_filtered ("\n");
+    }
+
+  ld_library_path = getenv ("LD_LIBRARY_PATH");
+  if (ld_library_path != NULL
+      && strstr (ld_library_path, "/usr/lib/debug") != NULL)
+    {
+      printf_filtered ("\n");
+      printf_filtered (_("WARNING: GDB has detected that your LD_LIBRARY_PATH environment variable\n"
+                         "includes /usr/lib/debug. You may have intended this, but if your program\n"
+                         "is using a different libc than /usr/lib/libc.so, it is the wrong thing to do.\n"
+                         "For example Crosstool V11 and higher use the libc from GRTE.\n"));
+      printf_filtered (_("For more information see http://wiki/Main/GdbFaq#LD_LIBRARY_PATH_usage_warning\n"));
+      printf_filtered ("\n");
+    }
+}
+\f
 extern initialize_file_ftype _initialize_google;
 
 void
index 76299e64026539d88ccef7e59deece7a1fd6a861..a8871eddb3410262d0b2fdbfd9d9c77def3db240 100644 (file)
@@ -20,4 +20,6 @@
 #ifndef GOOGLE_H
 #define GOOGLE_H
 
+extern void warn_troublesome_environment (void);
+
 #endif /* GOOGLE_H */
index aecd60afe6ca56b3f8ed3681eaf1ea06a464855a..68c4b85df4edd80fee9f13d6e984cede52ba8f9d 100644 (file)
@@ -38,7 +38,7 @@
 #include "objfiles.h"
 #include "auto-load.h"
 #include "maint.h"
-
+#include "google.h"
 #include "filenames.h"
 #include "filestuff.h"
 #include <signal.h>
@@ -992,6 +992,11 @@ captured_main (void *data)
                                   operations.  */
     }
 
+  /* GOOGLE LOCAL ref# 1155829.
+     Warn about troublesome environment variables.  */
+  if (!quiet)
+    warn_troublesome_environment ();
+
   /* Set off error and warning messages with a blank line.  */
   xfree (warning_pre_print);
   warning_pre_print = _("\nwarning: ");
index 0c35ffa3f0013065fdfd14852c3c5e20e0b4774f..7cc475eafa984c4b1a7f82db75248fa95c4417ac 100644 (file)
@@ -1121,6 +1121,29 @@ finish_new_objfile (struct objfile *objfile, int add_flags)
   clear_complaints (&symfile_complaints, 0, add_flags & SYMFILE_VERBOSE);
 }
 
+/* Bug 1155829.  Print "no debugging symbols found" in a more
+   noticeable fashion.
+   If VERBOSE is non-zero print a more verbose version of the warning.  */
+
+static void
+print_no_debugging_symbols_found (int verbose, const char* file_name)
+{
+  if (verbose)
+    printf_filtered ("\n");
+
+  printf_filtered (_("WARNING: no debugging symbols found in %s.\n"),
+                  file_name);
+
+  if (verbose)
+    {
+      printf_filtered (_("Either the binary was compiled without debugging information\n"
+                        "or the debugging information was removed (e.g., with strip or strip -g).\n"
+                        "Debugger capabilities will be very limited.\n"));
+      printf_filtered (_("For further information: http://wiki/Main/GdbFaq#No_debugging_symbols_found\n"));
+      printf_filtered ("\n");
+    }
+}
+
 /* Process a symbol file, as either the main file or as a dynamically
    loaded file.
 
@@ -1208,19 +1231,20 @@ symbol_file_add_with_addrs (bfd *abfd, const char *name, int add_flags,
        objfile->sf->qf->expand_all_symtabs (objfile);
     }
 
-  if (should_print && !objfile_has_symbols (objfile))
-    {
-      wrap_here ("");
-      printf_unfiltered (_("(no debugging symbols found)..."));
-      wrap_here ("");
-    }
-
   if (should_print)
     {
       if (deprecated_post_add_symbol_hook)
        deprecated_post_add_symbol_hook ();
       else
-       printf_unfiltered (_("done.\n"));
+       {
+         printf_unfiltered (_("done.\n"));
+
+         /* GOOGLE LOCAL: Printing of "no debugging symbols found" warning
+            has been moved to after "done." because the multi-line warning
+            looks better there.  */
+         if (!objfile_has_symbols (objfile))
+           print_no_debugging_symbols_found (mainline, name);
+       }
     }
 
   /* We print some messages regardless of whether 'from_tty ||
@@ -2669,7 +2693,8 @@ reread_symbols (void)
          if (!objfile_has_symbols (objfile))
            {
              wrap_here ("");
-             printf_unfiltered (_("(no debugging symbols found)\n"));
+             print_no_debugging_symbols_found (objfile == symfile_objfile,
+                                               objfile_name (objfile));
              wrap_here ("");
            }
 
index c363be46e55ca6a00d50bf3171103cbd5529af4f..512fb131946a52cc727a624a10a5765708343db1 100644 (file)
@@ -737,7 +737,7 @@ if {[build_executable sepdebug.exp sepdebug2 sepdebug2.c debug] != -1
 
     set escapedobjdirsubdir [string_to_regexp [standard_output_file {}]]
 
-    gdb_test "file [standard_output_file sepdebug2]" "warning: the debug information found in \"${escapedobjdirsubdir}/sepdebug2\\.debug\" does not match \"${escapedobjdirsubdir}/sepdebug2\" \\(CRC mismatch\\)\\..*\\(no debugging symbols found\\).*" "CRC mismatch is reported"
+    gdb_test "file [standard_output_file sepdebug2]" "warning: the debug information found in \"${escapedobjdirsubdir}/sepdebug2\\.debug\" does not match \"${escapedobjdirsubdir}/sepdebug2\" \\(CRC mismatch\\)\\..*no debugging symbols found.*" "CRC mismatch is reported"
 }
 
 
index 381297a584aba940ff96663d452f16d0c1f2a897..f74d1220201a6f9670456fd4795eeb1108072a37 100644 (file)
@@ -1397,7 +1397,7 @@ proc gdb_file_cmd { arg } {
            set gdb_file_cmd_debug_info "lzma"
            return 0
        }
-       -re "Reading symbols from.*no debugging symbols found.*done.*$gdb_prompt $" {
+       -re "Reading symbols from.*no debugging symbols found.*$gdb_prompt $" {
            verbose "\t\tLoaded $arg into $GDB with no debugging symbols"
            set gdb_file_cmd_debug_info "nodebug"
            return 0
@@ -1410,6 +1410,11 @@ proc gdb_file_cmd { arg } {
         -re "Load new symbol table from \".*\".*y or n. $" {
             send_gdb "y\n"
             gdb_expect 120 {
+               -re "Reading symbols from.*no debugging symbols found.*$gdb_prompt $" {
+                   verbose "\t\tLoaded $arg into the $GDB with no debugging symbols"
+                   set gdb_file_cmd_debug_info "nodebug"
+                   return 0
+               }
                 -re "Reading symbols from.*done.*$gdb_prompt $" {
                     verbose "\t\tLoaded $arg with new symbol table into $GDB"
                    set gdb_file_cmd_debug_info "debug"