* 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.
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
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))
#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
#ifndef GOOGLE_H
#define GOOGLE_H
+extern void warn_troublesome_environment (void);
+
#endif /* GOOGLE_H */
#include "objfiles.h"
#include "auto-load.h"
#include "maint.h"
-
+#include "google.h"
#include "filenames.h"
#include "filestuff.h"
#include <signal.h>
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: ");
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.
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 ||
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 ("");
}
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"
}
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
-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"