rd_elf.c revision 5eae5a6fd1b363c5b19d1e669b43b5c4277f4eb1
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdlib.h>
#include <stdio.h>
#include <proc_service.h>
#include <link.h>
#include <rtld_db.h>
#include <rtld.h>
#include <_rtld_db.h>
#include <msg.h>
#include <limits.h>
#include <string.h>
/*
* 64-bit builds are going to compile this module twice, the
* second time with _ELF64 defined. These defines should make
* all the necessary adjustments to the code.
*/
#ifdef _LP64
#ifdef _ELF64
#define _rd_reset32 _rd_reset64
#define _rd_event_enable32 _rd_event_enable64
#define _rd_event_getmsg32 _rd_event_getmsg64
#define _rd_loadobj_iter32 _rd_loadobj_iter64
#define find_dynamic_ent32 find_dynamic_ent64
#else /* ELF32 */
#define Rtld_db_priv Rtld_db_priv32
#define TListnode Listnode32
#endif /* _ELF64 */
#else /* _LP64 */
#endif /* _LP64 */
/*
* BrandZ added ps_pbrandname(). Many debuggers that link directly
* against librtld_db.so may not implement this interface. Hence
* we won't call the function directly, instead we'll try to look it
* up using the linker first and only invoke it if we find it.
*/
char *, size_t);
static rd_err_e
{
return (RD_ERR);
/*
* The rtld_db_priv structure contains both the traditional (exposed)
* r_debug structure as well as private data only available to
* this library.
*/
/*
* Verify that librtld_db & rtld are at the proper revision
* levels.
*/
sizeof (Rtld_db_priv)) != PS_OK) {
return (RD_DBERR);
}
return (RD_NOCAPAB);
}
/*
* Is the image being examined from a core file or not.
* If it is a core file then the following write will fail.
*/
sizeof (Rtld_db_priv)) != PS_OK)
/*
* If this *is not* a core file then rtld_db & ld.so.1 are
* considered tightly coupled. If the versions of our private
* data structures don't match - fail!
*/
return (RD_NOCAPAB);
}
return (RD_OK);
}
{
Dyn d;
do {
PS_OK) {
return (RD_DBERR);
}
dynaddr += sizeof (d);
break;
*dyn = d;
return (RD_OK);
}
return (RD_DBERR);
}
extern char rtld_db_helper_path[MAXPATHLEN];
#ifndef _ELF64
void
{
}
#endif
{
char brandname[MAXPATHLEN];
char brandlib[MAXPATHLEN];
/*
* librtld_db attempts three different methods to find
* the r_debug structure which is required to
* initialize itself. The methods are:
* method1:
* entirely independent of any text segment
* and relies on the AT_SUN_LDDATA auxvector
* to find the ld.so.1::rdebug structure.
* method2:
* lookup symbols in ld.so.1's symbol table
* to find the r_debug symbol.
* method3:
* (old dbx method) dependent upon the
* executable and not ld.so.1. We lookup the
* _DYNAMIC symbol in the executable and look for
* the DT_DEBUG entry in the .dynamic table. This
* points to rdebug.
*
* If none of that works - we fail.
*/
/*
* Method1
*
* Scan the aux vector looking for AT_BASE & AT_SUN_LDDATA
*/
}
/* LINTED */
break;
}
auxvp++;
}
}
/*
* method2 - look for r_rdebug symbol in ld.so.1
*/
/*
* If the AT_SUN_LDDATA auxv vector is not present
* fall back on doing a symlookup of
* the r_debug symbol. This is for backward
* compatiblity with older OS's
*/
} else {
}
}
/*
* method3 - find DT_DEBUG in the executables .dynamic section.
*/
return (rc);
}
return (rc);
}
return (rc);
}
}
/*
* If we are debugging a branded executable, load the appropriate helper
* library, and call its initialization routine.
*/
if ((ps_pbrandname != NULL) &&
const char *isa = "";
#ifdef __amd64
#endif /* __amd64 */
if (rtld_db_helper_path[0] != '\0')
else
brandlib));
return (RD_ERR);
}
brandlib));
return (RD_ERR);
}
} else
}
return (RD_DBERR);
}
return (RD_DBERR);
}
return (RD_DBERR);
}
rap->rd_tbinder = 0;
}
return (RD_OK);
}
{
/*
* Tell the debugged process that debugging is occuring
* This will enable the storing of event messages so that
* the can be gathered by the debugger.
*/
sizeof (Rtld_db_priv)) != PS_OK) {
return (RD_DBERR);
}
if (onoff)
else
sizeof (Rtld_db_priv)) != PS_OK) {
return (RD_DBERR);
}
return (RD_OK);
}
{
sizeof (Rtld_db_priv)) != PS_OK) {
return (RD_DBERR);
}
case RT_CONSISTENT:
break;
case RT_ADD:
break;
case RT_DELETE:
break;
}
} else
return (RD_OK);
}
{
sizeof (Rtld_db_priv)) != PS_OK) {
return (RD_DBERR);
}
/*LINTED*/
#else
#endif
sizeof (Rtld_db_priv)) != PS_OK) {
return (RD_DBERR);
}
return (RD_OK);
}
static rd_err_e
{
while (lmaddr) {
int i;
return (RD_DBERR);
}
/*
* As of 'VERSION5' we only report objects
* which have been fully relocated. While the maps
* might be in a consistent state - if a object hasn't
* been relocated - it's not really ready for the debuggers
* to examine. This is mostly due to the fact that we
* might still be mucking with the text-segment, if
* we are - we could conflict with any break-points
* the debuggers might have set.
*/
continue;
}
}
else
lobj.rl_lmident = ident;
/*
* refnameaddr is only valid from a core file
* which is VERSION3 or greater.
*/
lobj.rl_padstart = 0;
} else {
}
if (rtld_db_version >= RD_VERSION2)
if (rtld_db_version >= RD_VERSION2) {
}
if (rtld_db_version >= RD_VERSION4)
/*
* Look for beginning of data segment.
*
* NOTE: the data segment can only be found for full
* processes and not from core images.
*/
lobj.rl_data_base = 0;
lobj.rl_data_base = 0;
else {
return (RD_DBERR);
}
MSG_DB_LKMAPFAIL)));
return (RD_DBERR);
}
lobj.rl_data_base +=
break;
}
}
}
/*
* When we transfer control to the client we free the
* lock and re-atain it after we've returned from the
* client. This is to avoid any deadlock situations.
*/
*abort_iter = 1;
break;
}
}
return (RD_OK);
}
{
unsigned long ident;
uint_t abort_iter = 0;
client_data));
sizeof (Rtld_db_priv)) != PS_OK) {
return (RD_DBERR);
}
if (db_priv.rtd_dynlmlst == 0) {
return (RD_NOMAPS);
}
return (RD_DBERR);
}
return (RD_NOMAPS);
}
if (cb == 0) {
return (RD_ERR);
}
/*
* Iterate through the List of Lm_list's.
*/
return (RD_DBERR);
}
return (RD_DBERR);
}
/*
* Determine IDENT of current LM_LIST
*/
ident = LM_ID_BASE;
ident = LM_ID_LDSO;
else
return (rc);
}
if (abort_iter)
break;
}
return (rc);
return (RD_OK);
}