Back to index

glibc  2.9
dl-debug.c
Go to the documentation of this file.
00001 /* Communicate dynamic linker state to the debugger at runtime.
00002    Copyright (C) 1996, 1998,2000,2002,2004,2005,2006
00003        Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <ldsodefs.h>
00022 
00023 
00024 /* These are the members in the public `struct link_map' type.
00025    Sanity check that the internal type and the public type match.  */
00026 #define VERIFY_MEMBER(name) \
00027   (offsetof (struct link_map_public, name) == offsetof (struct link_map, name))
00028 extern const int verify_link_map_members[(VERIFY_MEMBER (l_addr)
00029                                      && VERIFY_MEMBER (l_name)
00030                                      && VERIFY_MEMBER (l_ld)
00031                                      && VERIFY_MEMBER (l_next)
00032                                      && VERIFY_MEMBER (l_prev))
00033                                     ? 1 : -1];
00034 
00035 /* This structure communicates dl state to the debugger.  The debugger
00036    normally finds it via the DT_DEBUG entry in the dynamic section, but in
00037    a statically-linked program there is no dynamic section for the debugger
00038    to examine and it looks for this particular symbol name.  */
00039 struct r_debug _r_debug;
00040 
00041 
00042 /* Initialize _r_debug if it has not already been done.  The argument is
00043    the run-time load address of the dynamic linker, to be put in
00044    _r_debug.r_ldbase.  Returns the address of _r_debug.  */
00045 
00046 struct r_debug *
00047 internal_function
00048 _dl_debug_initialize (ElfW(Addr) ldbase, Lmid_t ns)
00049 {
00050   struct r_debug *r;
00051 
00052   if (ns == LM_ID_BASE)
00053     r = &_r_debug;
00054   else
00055     r = &GL(dl_ns)[ns]._ns_debug;
00056 
00057   if (r->r_map == NULL || ldbase != 0)
00058     {
00059       /* Tell the debugger where to find the map of loaded objects.  */
00060       r->r_version = 1      /* R_DEBUG_VERSION XXX */;
00061       r->r_ldbase = ldbase ?: _r_debug.r_ldbase;
00062       r->r_map = (void *) GL(dl_ns)[ns]._ns_loaded;
00063       r->r_brk = (ElfW(Addr)) &_dl_debug_state;
00064     }
00065 
00066   return r;
00067 }
00068 
00069 
00070 /* This function exists solely to have a breakpoint set on it by the
00071    debugger.  The debugger is supposed to find this function's address by
00072    examining the r_brk member of struct r_debug, but GDB 4.15 in fact looks
00073    for this particular symbol name in the PT_INTERP file.  */
00074 void
00075 _dl_debug_state (void)
00076 {
00077 }
00078 rtld_hidden_def (_dl_debug_state)