2001-03-10 06:17:24 +00:00
|
|
|
/* Provide legacy r_debug and link_map support for SVR4-like native targets.
|
2006-02-02 22:15:01 +00:00
|
|
|
|
|
|
|
Copyright (C) 2000, 2001, 2006
|
2001-03-10 06:17:24 +00:00
|
|
|
Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2005-12-17 22:34:03 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA. */
|
2001-03-10 06:17:24 +00:00
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
#include "gdbcore.h"
|
|
|
|
#include "solib-svr4.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_LINK_H
|
2001-03-20 02:57:42 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_NLIST_H
|
|
|
|
/* nlist.h needs to be included before link.h on some older *BSD systems. */
|
|
|
|
#include <nlist.h>
|
|
|
|
#endif
|
|
|
|
|
2001-03-10 06:17:24 +00:00
|
|
|
#include <link.h>
|
|
|
|
|
|
|
|
/* Fetch (and possibly build) an appropriate link_map_offsets structure
|
|
|
|
for native targets using struct definitions from link.h. */
|
|
|
|
|
|
|
|
static struct link_map_offsets *
|
|
|
|
legacy_svr4_fetch_link_map_offsets (void)
|
|
|
|
{
|
|
|
|
static struct link_map_offsets lmo;
|
|
|
|
static struct link_map_offsets *lmp = 0;
|
|
|
|
#if defined (HAVE_STRUCT_LINK_MAP32)
|
|
|
|
static struct link_map_offsets lmo32;
|
|
|
|
static struct link_map_offsets *lmp32 = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef offsetof
|
|
|
|
#define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
|
|
|
|
#endif
|
|
|
|
#define fieldsize(TYPE, MEMBER) (sizeof (((TYPE *)0)->MEMBER))
|
|
|
|
|
|
|
|
if (lmp == 0)
|
|
|
|
{
|
|
|
|
lmp = &lmo;
|
|
|
|
|
2001-03-19 05:46:27 +00:00
|
|
|
#ifdef HAVE_STRUCT_LINK_MAP_WITH_L_MEMBERS
|
2006-02-02 22:15:01 +00:00
|
|
|
lmo.r_version_offset = offsetof (struct r_debug, r_version);
|
|
|
|
lmo.r_version_size = fieldsize (struct r_debug, r_version);
|
2001-03-10 06:17:24 +00:00
|
|
|
lmo.r_map_offset = offsetof (struct r_debug, r_map);
|
2006-02-02 22:15:01 +00:00
|
|
|
lmo.r_ldsomap_offset = -1;
|
2001-03-10 06:17:24 +00:00
|
|
|
|
|
|
|
lmo.link_map_size = sizeof (struct link_map);
|
|
|
|
|
|
|
|
lmo.l_addr_offset = offsetof (struct link_map, l_addr);
|
|
|
|
lmo.l_addr_size = fieldsize (struct link_map, l_addr);
|
|
|
|
|
|
|
|
lmo.l_next_offset = offsetof (struct link_map, l_next);
|
|
|
|
lmo.l_next_size = fieldsize (struct link_map, l_next);
|
|
|
|
|
|
|
|
lmo.l_prev_offset = offsetof (struct link_map, l_prev);
|
|
|
|
lmo.l_prev_size = fieldsize (struct link_map, l_prev);
|
|
|
|
|
|
|
|
lmo.l_name_offset = offsetof (struct link_map, l_name);
|
|
|
|
lmo.l_name_size = fieldsize (struct link_map, l_name);
|
2001-03-19 05:46:27 +00:00
|
|
|
#else /* !defined(HAVE_STRUCT_LINK_MAP_WITH_L_MEMBERS) */
|
|
|
|
#ifdef HAVE_STRUCT_LINK_MAP_WITH_LM_MEMBERS
|
2001-03-10 06:17:24 +00:00
|
|
|
lmo.link_map_size = sizeof (struct link_map);
|
|
|
|
|
|
|
|
lmo.l_addr_offset = offsetof (struct link_map, lm_addr);
|
|
|
|
lmo.l_addr_size = fieldsize (struct link_map, lm_addr);
|
|
|
|
|
|
|
|
lmo.l_next_offset = offsetof (struct link_map, lm_next);
|
|
|
|
lmo.l_next_size = fieldsize (struct link_map, lm_next);
|
|
|
|
|
|
|
|
lmo.l_name_offset = offsetof (struct link_map, lm_name);
|
|
|
|
lmo.l_name_size = fieldsize (struct link_map, lm_name);
|
2001-03-19 05:46:27 +00:00
|
|
|
#else /* !defined(HAVE_STRUCT_LINK_MAP_WITH_LM_MEMBERS) */
|
|
|
|
#if HAVE_STRUCT_SO_MAP_WITH_SOM_MEMBERS
|
|
|
|
lmo.link_map_size = sizeof (struct so_map);
|
|
|
|
|
|
|
|
lmo.l_addr_offset = offsetof (struct so_map, som_addr);
|
|
|
|
lmo.l_addr_size = fieldsize (struct so_map, som_addr);
|
|
|
|
|
|
|
|
lmo.l_next_offset = offsetof (struct so_map, som_next);
|
|
|
|
lmo.l_next_size = fieldsize (struct so_map, som_next);
|
|
|
|
|
|
|
|
lmo.l_name_offset = offsetof (struct so_map, som_path);
|
|
|
|
lmo.l_name_size = fieldsize (struct so_map, som_path);
|
|
|
|
#endif /* HAVE_STRUCT_SO_MAP_WITH_SOM_MEMBERS */
|
|
|
|
#endif /* HAVE_STRUCT_LINK_MAP_WITH_LM_MEMBERS */
|
|
|
|
#endif /* HAVE_STRUCT_LINK_MAP_WITH_L_MEMBERS */
|
2001-03-10 06:17:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined (HAVE_STRUCT_LINK_MAP32)
|
|
|
|
if (lmp32 == 0)
|
|
|
|
{
|
|
|
|
lmp32 = &lmo32;
|
|
|
|
|
2006-02-02 22:15:01 +00:00
|
|
|
lmo32.r_version_offset = offsetof (struct r_debug32, r_version);
|
|
|
|
lmo32.r_version_size = fieldsize (struct r_debug32, r_version);
|
2001-03-10 06:17:24 +00:00
|
|
|
lmo32.r_map_offset = offsetof (struct r_debug32, r_map);
|
2006-02-02 22:15:01 +00:00
|
|
|
lmo32.r_ldsomap_offset = -1;
|
2001-03-10 06:17:24 +00:00
|
|
|
|
|
|
|
lmo32.link_map_size = sizeof (struct link_map32);
|
|
|
|
|
|
|
|
lmo32.l_addr_offset = offsetof (struct link_map32, l_addr);
|
|
|
|
lmo32.l_addr_size = fieldsize (struct link_map32, l_addr);
|
|
|
|
|
|
|
|
lmo32.l_next_offset = offsetof (struct link_map32, l_next);
|
|
|
|
lmo32.l_next_size = fieldsize (struct link_map32, l_next);
|
|
|
|
|
|
|
|
lmo32.l_prev_offset = offsetof (struct link_map32, l_prev);
|
|
|
|
lmo32.l_prev_size = fieldsize (struct link_map32, l_prev);
|
|
|
|
|
|
|
|
lmo32.l_name_offset = offsetof (struct link_map32, l_name);
|
|
|
|
lmo32.l_name_size = fieldsize (struct link_map32, l_name);
|
|
|
|
}
|
|
|
|
#endif /* defined (HAVE_STRUCT_LINK_MAP32) */
|
|
|
|
|
|
|
|
#if defined (HAVE_STRUCT_LINK_MAP32)
|
2002-01-07 19:45:14 +00:00
|
|
|
if (exec_bfd != NULL)
|
|
|
|
{
|
|
|
|
if (bfd_get_arch_size (exec_bfd) == 32)
|
|
|
|
return lmp32;
|
|
|
|
}
|
2002-02-07 23:08:55 +00:00
|
|
|
if (TARGET_PTR_BIT == 32)
|
2001-03-10 06:17:24 +00:00
|
|
|
return lmp32;
|
|
|
|
#endif
|
2002-02-07 23:08:55 +00:00
|
|
|
return lmp;
|
2001-03-10 06:17:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_LINK_H */
|
|
|
|
|
2003-06-11 13:16:30 +00:00
|
|
|
extern initialize_file_ftype _initialize_svr4_lm; /* -Wmissing-prototypes */
|
|
|
|
|
2001-03-10 06:17:24 +00:00
|
|
|
void
|
|
|
|
_initialize_svr4_lm (void)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_LINK_H
|
|
|
|
legacy_svr4_fetch_link_map_offsets_hook = legacy_svr4_fetch_link_map_offsets;
|
|
|
|
#endif /* HAVE_LINK_H */
|
|
|
|
}
|