/*
* 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
*/
/*
*/
#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_program.h>
#include <dt_pid.h>
#include <dt_string.h>
typedef struct dt_pid_probe {
const char *dpp_mod;
char *dpp_func;
const char *dpp_name;
const char *dpp_obj;
/*
* Compose the lmid and object name into the canonical representation. We
* omit the lmid for the default link map for convenience.
*/
static void
{
if (lmid == LM_ID_BASE)
else
}
static int
{
int len;
} else {
}
return (1);
}
static int
{
char *end;
return (1); /* errno is set for us */
}
D_PROC_CREATEFAIL, "failed to create return probe "
"for '%s': %s", func,
}
nmatches++;
}
D_PROC_CREATEFAIL, "failed to create entry probe "
"for '%s': %s", func,
}
nmatches++;
}
if (*end != '\0') {
}
"offset 0x%llx outside of function '%s'",
}
if (err == DT_PROC_ERR) {
D_PROC_CREATEFAIL, "failed to create probe at "
}
if (err == DT_PROC_ALIGN) {
"offset 0x%llx is not aligned on an instruction",
(u_longlong_t)off));
}
nmatches++;
"failed to create offset probes in '%s': %s", func,
}
nmatches++;
}
return (0);
}
static int
{
return (0);
return (0);
}
if (pp->dpp_last_taken == 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 int
{
return (0);
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.
*/
"failed to lookup '%s' in module '%s'",
} else {
return (0);
}
}
/*
* Only match defined functions of non-zero size.
*/
return (0);
/*
* We don't instrument PLTs -- they're dynamically rewritten,
* and, so, inherently dicey to instrument.
*/
return (0);
} else {
return (1);
/*
* If we didn't match anything in the PR_SYMTAB, try
* the PR_DYNSYM.
*/
return (1);
}
}
return (0);
}
static int
{
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++;
return (pmp);
}
static int
{
int ret = 0;
/*
* We can only trace dynamically-linked executables (since we've
*/
"process %s is not a dynamically-linked executable",
}
pp.dpp_last_taken = 0;
"only the a.out module is valid with the "
"'-' function"));
}
"only individual addresses may be specified "
"with the '-' function"));
}
}
/*
* 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 we 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++;
}
}
return (ret);
}
static int
{
struct ps_prochandle *P = data;
const char *mname;
/*
* 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;
}
if (fd == -1 &&
dt_dprintf("pr_open of helper device failed: %s\n",
return (-1); /* errno is set for us */
}
}
if (fd != -1)
return (0);
}
static int
{
int ret = 0;
(void) Pupdate_maps(P);
if (Pobject_iter(P, dt_pid_usdt_mapping, P) != 0) {
ret = -1;
"failed to instantiate probes for pid %d: %s",
}
/*
* Put the module name in its canonical form.
*/
(void) dt_pid_fix_mod(pdp, P);
return (ret);
}
static pid_t
{
if (!isdigit(*c))
last = c;
}
return (-1);
}
errno = 0;
return (-1);
}
return (pid);
}
int
{
struct ps_prochandle *P;
int err = 0;
return (-1);
"pid provider is not installed on this system");
} else {
"pid provider is not available: %s",
}
return (-1);
}
0)) == NULL) {
"failed to grab process %d", (int)pid);
return (-1);
}
/*
* Alert other retained enablings which may match
* against the newly created probes.
*/
}
dt_proc_release(dtp, P);
}
/*
* If it's not strictly a pid provider, we might match a USDT provider.
*/
"failed to grab process %d", (int)pid);
return (-1);
}
}
dt_proc_release(dtp, P);
}
return (err ? -1 : 0);
}
int
{
continue;
ret = 1;
/*
* If it's not strictly a pid provider, we might match
* a USDT provider.
*/
ret = 1;
}
}
if (found) {
/*
* Give DTrace a shot to the ribs to get it to check
* out the newly created probes.
*/
}
return (ret);
}