gdb/glibc-tdep.c - gdb

Functions defined

Source code

  1. /* Target-dependent code for the GNU C Library (glibc).

  2.    Copyright (C) 2002-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "defs.h"
  15. #include "frame.h"
  16. #include "symtab.h"
  17. #include "symfile.h"
  18. #include "objfiles.h"

  19. #include "glibc-tdep.h"

  20. /* Calling functions in shared libraries.  */

  21. /* See the comments for SKIP_SOLIB_RESOLVER at the top of infrun.c.
  22.    This function:
  23.    1) decides whether a PLT has sent us into the linker to resolve
  24.       a function reference, and
  25.    2) if so, tells us where to set a temporary breakpoint that will
  26.       trigger when the dynamic linker is done.  */

  27. CORE_ADDR
  28. glibc_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
  29. {
  30.   /* The GNU dynamic linker is part of the GNU C library, and is used
  31.      by all GNU systems (GNU/Hurd, GNU/Linux).  An unresolved PLT
  32.      entry points to "_dl_runtime_resolve", which calls "fixup" to
  33.      patch the PLT, and then passes control to the function.

  34.      We look for the symbol `_dl_runtime_resolve', and find `fixup' in
  35.      the same objfile.  If we are at the entry point of `fixup', then
  36.      we set a breakpoint at the return address (at the top of the
  37.      stack), and continue.

  38.      It's kind of gross to do all these checks every time we're
  39.      called, since they don't change once the executable has gotten
  40.      started.  But this is only a temporary hack --- upcoming versions
  41.      of GNU/Linux will provide a portable, efficient interface for
  42.      debugging programs that use shared libraries.  */

  43.   struct bound_minimal_symbol resolver
  44.     = lookup_minimal_symbol_and_objfile ("_dl_runtime_resolve");

  45.   if (resolver.minsym)
  46.     {
  47.       /* The dynamic linker began using this name in early 2005.  */
  48.       struct bound_minimal_symbol fixup
  49.         = lookup_minimal_symbol ("_dl_fixup", NULL, resolver.objfile);

  50.       /* This is the name used in older versions.  */
  51.       if (! fixup.minsym)
  52.         fixup = lookup_minimal_symbol ("fixup", NULL, resolver.objfile);

  53.       if (fixup.minsym && BMSYMBOL_VALUE_ADDRESS (fixup) == pc)
  54.         return frame_unwind_caller_pc (get_current_frame ());
  55.     }

  56.   return 0;
  57. }