GDB (API)
/home/stan/gdb/src/gdb/glibc-tdep.c
Go to the documentation of this file.
00001 /* Target-dependent code for the GNU C Library (glibc).
00002 
00003    Copyright (C) 2002-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 #include "defs.h"
00021 #include "frame.h"
00022 #include "symtab.h"
00023 #include "symfile.h"
00024 #include "objfiles.h"
00025 
00026 #include "glibc-tdep.h"
00027 
00028 /* Calling functions in shared libraries.  */
00029 
00030 /* See the comments for SKIP_SOLIB_RESOLVER at the top of infrun.c.
00031    This function:
00032    1) decides whether a PLT has sent us into the linker to resolve
00033       a function reference, and 
00034    2) if so, tells us where to set a temporary breakpoint that will
00035       trigger when the dynamic linker is done.  */
00036 
00037 CORE_ADDR
00038 glibc_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
00039 {
00040   /* The GNU dynamic linker is part of the GNU C library, and is used
00041      by all GNU systems (GNU/Hurd, GNU/Linux).  An unresolved PLT
00042      entry points to "_dl_runtime_resolve", which calls "fixup" to
00043      patch the PLT, and then passes control to the function.
00044 
00045      We look for the symbol `_dl_runtime_resolve', and find `fixup' in
00046      the same objfile.  If we are at the entry point of `fixup', then
00047      we set a breakpoint at the return address (at the top of the
00048      stack), and continue.
00049   
00050      It's kind of gross to do all these checks every time we're
00051      called, since they don't change once the executable has gotten
00052      started.  But this is only a temporary hack --- upcoming versions
00053      of GNU/Linux will provide a portable, efficient interface for
00054      debugging programs that use shared libraries.  */
00055 
00056   struct bound_minimal_symbol resolver 
00057     = lookup_minimal_symbol_and_objfile ("_dl_runtime_resolve");
00058 
00059   if (resolver.minsym)
00060     {
00061       /* The dynamic linker began using this name in early 2005.  */
00062       struct minimal_symbol *fixup
00063         = lookup_minimal_symbol ("_dl_fixup", NULL, resolver.objfile);
00064       
00065       /* This is the name used in older versions.  */
00066       if (! fixup)
00067         fixup = lookup_minimal_symbol ("fixup", NULL, resolver.objfile);
00068 
00069       if (fixup && SYMBOL_VALUE_ADDRESS (fixup) == pc)
00070         return frame_unwind_caller_pc (get_current_frame ());
00071     }
00072 
00073   return 0;
00074 }      
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines