From: Doug Evans Date: Thu, 10 Dec 2015 20:00:28 +0000 (-0800) Subject: patch ../102422525.patch X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b62f48720bc5255667cf2f5c5aca34af78fb657e;p=thirdparty%2Fbinutils-gdb.git patch ../102422525.patch --- diff --git a/README.google b/README.google index a13241190aa..0561e352912 100644 --- a/README.google +++ b/README.google @@ -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 + + 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. diff --git a/gdb/exec.c b/gdb/exec.c index 3dfc437a9b3..0ea19801edd 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -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, §ions, §ions_end)) diff --git a/gdb/google.c b/gdb/google.c index e0e87375924..9ad6ede16e5 100644 --- a/gdb/google.c +++ b/gdb/google.c @@ -20,6 +20,42 @@ #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"); + } +} + extern initialize_file_ftype _initialize_google; void diff --git a/gdb/google.h b/gdb/google.h index 76299e64026..a8871eddb34 100644 --- a/gdb/google.h +++ b/gdb/google.h @@ -20,4 +20,6 @@ #ifndef GOOGLE_H #define GOOGLE_H +extern void warn_troublesome_environment (void); + #endif /* GOOGLE_H */ diff --git a/gdb/main.c b/gdb/main.c index aecd60afe6c..68c4b85df4e 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -38,7 +38,7 @@ #include "objfiles.h" #include "auto-load.h" #include "maint.h" - +#include "google.h" #include "filenames.h" #include "filestuff.h" #include @@ -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: "); diff --git a/gdb/symfile.c b/gdb/symfile.c index 0c35ffa3f00..7cc475eafa9 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -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 (""); } diff --git a/gdb/testsuite/gdb.base/sepdebug.exp b/gdb/testsuite/gdb.base/sepdebug.exp index c363be46e55..512fb131946 100644 --- a/gdb/testsuite/gdb.base/sepdebug.exp +++ b/gdb/testsuite/gdb.base/sepdebug.exp @@ -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" } diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 381297a584a..f74d1220201 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -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"