dt_pid.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <assert.h>
#include <strings.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <alloca.h>
#include <libgen.h>
#include <stddef.h>
#include <dt_impl.h>
#include <dt_pid.h>
#include <dt_string.h>
typedef struct dt_pid_probe {
struct ps_prochandle *dpp_pr;
const char *dpp_mod;
char *dpp_func;
const char *dpp_name;
const char *dpp_obj;
static void
{
char *end;
if (sz < 4000) {
sz = 0;
return;
}
} else {
}
goto create_err;
nmatches++;
}
goto create_err;
nmatches++;
}
if (*end != '\0') {
if (sz != 0)
}
char buf[DTRACE_FUNCNAMELEN];
/*
* We need to copy the function name to the stack
* because 'func' may be freed by virtue of calling
* dt_proc_release() on the libproc handle.
*/
if (sz != 0)
}
if (err == DT_PROC_ERR)
goto create_err;
if (err == DT_PROC_ALIGN) {
if (sz != 0)
}
nmatches++;
goto create_err;
nmatches++;
}
if (sz != 0)
return;
if (sz != 0)
}
static int
{
return (0);
return (0);
}
/*
* Due to 4524008, _init and _fini may have a bloated st_size.
* While this bug has been fixed for a while, old binaries
* may exist that still exhibit this problem. As a result, we
* don't match _init and _fini though we allow users to
* specify them explicitly.
*/
return (0);
}
}
return (0);
}
static void
{
return;
else
NULL) == 0)
else
NULL) == 0)
else
NULL) == 0)
else
NULL) == 0)
else
/*
* If pp->dpp_func contains any globbing meta-characters, we need
* to iterate over the symbol table and compare each function name
* against the pattern.
*/
/*
* If we fail to lookup the symbol, try interpreting the
* function as the special "-" function that indicates that the
* probe name should be interpreted as a absolute virtual
* address. If that fails and we were matching a specific
* function in a specific module, report the error, otherwise
* just fail silently in the hopes that some other object will
* contain the desired symbol.
*/
} else {
return;
}
}
/*
* Only match defined functions of non-zero size.
*/
return;
/*
* We don't instrument PLTs -- they're dynamically rewritten,
* and, so, inherently dicey to instrument.
*/
return;
} else {
/*
* If we didn't match anything in the PR_SYMTAB, try
* the PR_DYNSYM.
*/
}
}
}
static int
{
} else {
char name[DTRACE_MODNAMELEN];
else
}
return (0);
}
static const prmap_t *
{
char m[MAXPATHLEN];
const char *obj;
/*
* Pick apart the link map from the library name.
*/
char *end;
return (NULL);
return (NULL);
} else {
}
return (NULL);
obj = &m[0];
else
obj++;
if (lmid == LM_ID_BASE)
else
return (pmp);
}
static void
{
/*
* We can only trace dynamically-linked executables (since we've
*/
}
"with the '-' function\n");
}
"be specified with the '-' function\n");
}
}
/*
* If pp.dpp_mod contains any globbing meta-characters, we need
* to iterate over each module and compare its name against the
* pattern. An empty module name is treated as '*'.
*/
} else {
char *obj;
/*
* If can't find a matching module, don't sweat it -- either
* we'll fail the enabling because the probes don't exist or
* we'll wait for that module to come along.
*/
else
obj++;
}
}
}
static int
{
struct ps_prochandle *P = data;
int fd;
const char *mname;
int i;
/*
* The symbol ___SUNW_dof is for lazy-loaded DOF sections, and
* __SUNW_dof is for actively-loaded DOF sections. We try to force
* in both types of DOF section since the process may not yet have
* run the code to instantiate these providers.
*/
for (i = 0; i < 2; i++) {
&sip) != 0) {
continue;
}
else
mname++;
dt_dprintf("read of ELF header failed");
continue;
}
"%s", mname);
} else {
}
dt_dprintf("pr_open of helper device failed: %s\n",
return (errno);
}
return (errno);
}
return (0);
}
static int
{
int err;
(void) Pupdate_maps(P);
/*
* Put the module name in its canonical form.
*/
(void) dt_pid_fix_mod(pdp, P);
return (err);
}
static pid_t
{
if (!isdigit(*c))
last = c;
}
*errp = D_PROC_BADPROV;
return (-1);
}
pdp->dtpd_provider);
}
errno = 0;
*errp = D_PROC_BADPID;
return (-1);
}
pdp->dtpd_provider);
}
*errp = 0;
return (pid);
}
void
{
char provname[DTRACE_PROVNAMELEN];
struct ps_prochandle *P;
int err = 0;
"installed on this system\n");
} else {
}
}
} else {
}
dt_proc_release(dtp, P);
if (err != 0)
}
}
void
{
char provname[DTRACE_PROVNAMELEN];
int err;
continue;
(int)pid);
else
}
}
if (found) {
/*
* Give DTrace a shot to the ribs to get it to check
* out the newly created probes.
*/
}
}