e0ea83ebb1
Summary of changes: - libdtrace changeset: 12902:3bb859a7330c user: Bryan Cantrill <Bryan.Cantrill@Sun.COM> date: Fri Jul 23 17:34:02 2010 -0700 summary: 6679140 asymmetric alloc/dealloc activity can induce dynamic variable drops changeset: 12692:4341b447c069 user: Ali Bahrami <Ali.Bahrami@Oracle.COM> date: Thu Jun 24 18:16:42 2010 -0600 summary: 6916796 OSnet mapfiles should use version 2 link-editor syntax changeset: 12507:501806a754d2 user: Alan Maguire <Alan.Maguire@Sun.COM> date: Thu May 27 17:29:51 2010 -0400 summary: PSARC 2010/106 DTrace TCP and UDP providers changeset: 11798:1e7f1f154004 user: Roger A. Faulkner <Roger.Faulkner@Sun.COM> date: Sun Feb 28 18:42:20 2010 -0800 summary: PSARC 2009/657 delete obsolete system call traps changeset: 11466:d60272412fb0 user: Roger A. Faulkner <Roger.Faulkner@Sun.COM> date: Mon Jan 11 17:42:13 2010 -0800 summary: 6915578 MUTEX_HELD() and RW_LOCK_HELD() macros should be available to Posix threads changeset: 11237:0d23e47ed228 user: Jonathan Haslam <Jonathan.Haslam@Sun.COM> date: Thu Dec 03 13:39:19 2009 +0000 summary: 6795386 macro arguments and globbing in DTrace probe descriptions don't mix changeset: 10791:944abfb5b345 user: Jonathan Haslam <Jonathan.Haslam@Sun.COM> date: Wed Oct 14 11:25:23 2009 +0100 summary: 6886953 large symbols lead to stack exhaustion changeset: 10326:8e3fbeec2d76 user: Siddheshwar Mahesh <Siddheshwar.Mahesh@Sun.COM> date: Mon Aug 17 13:26:49 2009 -0500 summary: 6868411 NFS provider generates error on ci_remote on RDMA operations changeset: 10207:87c40ea3fc4b user: jmcp <James.McPherson@Sun.COM> date: Wed Jul 29 16:56:03 2009 -0700 summary: 6864230 hiho, hiho, it'ch chtime for CH to go changeset: 10044:2643c1cd9e2a user: Priya Krishnan <Priya.Krishnan@Sun.COM> date: Mon Jul 06 21:19:41 2009 -0400 summary: 6855027 iscsit.d breaks dtrace in osol based on snv_117 changeset: 9900:1b86d65a4f9e user: Ali Bahrami <Ali.Bahrami@Sun.COM> date: Thu Jun 18 13:16:39 2009 -0600 summary: 6851224 elf_getshnum() and elf_getshstrndx() incompatible with 2002 ELF gABI agreement changeset: 9885:a3d5e9d9e779 user: Robert Mastors <Robert.Mastors@Sun.COM> date: Tue Jun 16 15:25:25 2009 -0500 summary: 6711844 assert: vp->v_shrlocks == 0L, file: ../../common/fs/vnode.c, line: 2333 changeset: 9881:741c9e4e094c user: Charles Ting <Charles.Ting@Sun.COM> date: Tue Jun 16 14:51:40 2009 -0400 summary: 6849606 SRP DTrace Probe for xfer-done misses completion of READ transfers changeset: 9829:e8059fcaee97 user: Charles Ting <Charles.Ting@Sun.COM> date: Tue Jun 09 10:11:35 2009 -0400 summary: 6804431 Add Dtrace probes to SRPT changeset: 9812:a2990074321f user: Priya Krishnan <Priya.Krishnan@Sun.COM> date: Mon Jun 08 09:49:48 2009 -0400 summary: 6847237 The iscsit.d DTrace translator should include iscsi.d for the definition of iscsiinfo_t changeset: 9721:4f7e194c7c37 user: Priya Krishnan <Priya.Krishnan@Sun.COM> date: Tue May 26 10:40:43 2009 -0400 summary: 6809997 COMSTAR iscsi target DTrace Provider needed changeset: 9625:8aa5731291b4 user: Sam Cramer <Sam.Cramer@Sun.COM> date: Wed May 13 17:10:06 2009 -0700 summary: 6840354 "/usr/lib/dtrace/fc.d", line 59: syntax error near "fct_local_port_t" changeset: 9609:8874cc8d5e3f user: Sam Cramer <Sam.Cramer@Sun.COM> date: Mon May 11 21:02:27 2009 -0700 summary: 6809580 fct DTrace providers needed for qlt changeset: 9578:c4b38ec17f4e user: Sam Cramer <Sam.Cramer@Sun.COM> date: Fri May 08 12:12:40 2009 -0700 summary: 6809580 fct DTrace providers needed for qlt changeset: 9531:dc8924ef7839 user: Rafael Vanoni <rafael.vanoni@sun.com> date: Mon May 04 11:48:15 2009 -0700 summary: 6730130 dtrace missing printf handler for stdev changeset: 9389:750ed3471e90 user: Vamsi Nagineni <Vamsi.Krishna@Sun.COM> date: Fri Apr 17 06:26:47 2009 -0700 summary: 6812050 dtrace should translate curpsinfo->pr_contract changeset: 9085:ff7eb0bace56 user: Ali Bahrami <Ali.Bahrami@Sun.COM> date: Wed Mar 18 13:28:28 2009 -0600 summary: 6813909 generalize eh_frame support to non-amd64 platforms changeset: 8803:8c01b39012c9 user: Jonathan Haslam <Jonathan.Haslam@Sun.COM> date: Fri Feb 13 07:13:13 2009 +0000 summary: PSARC 2008/480 DTrace CPC Provider changeset: 8744:03d5725cda56 user: Ali Bahrami <Ali.Bahrami@Sun.COM> date: Tue Feb 10 09:38:02 2009 -0700 summary: 6798660 Cadmium .NOT file processing problem with CWD relative file paths changeset: 8337:079ecc003ca6 user: Jonathan Haslam <Jonathan.Haslam@Sun.COM> date: Thu Dec 11 11:26:47 2008 +0000 summary: 6750659 drti.o crashes app due to corrupt environment changeset: 7991:d3b751ef3d85 user: Jonathan Haslam <Jonathan.Haslam@Sun.COM> date: Mon Nov 03 10:26:23 2008 +0000 summary: 6738982 Representative thread after DTrace stop() action is incorrect changeset: 7208:568549b138d8 user: vv149972 date: Mon Jul 28 23:14:31 2008 -0700 summary: 6696397 NFS v3 provider reports all UDP clients as 0.0.0.0 changeset: 6878:360e73ea6b0c user: brendan date: Fri Jun 13 19:06:55 2008 -0700 summary: PSARC 2008/302 DTrace IP Provider changeset: 6554:b5817e112852 user: ahl date: Mon May 05 14:38:24 2008 -0700 summary: 6677812 race between dtrace activities in non-local zones ---- - ctf tools: changeset: 12177:800b7f847f1e user: Surya Prakki <Surya.Prakki@Sun.COM> date: Sun Apr 18 23:59:57 2010 -0700 summary: 6941452 ctfconvert fails on VLAs with code generated by SS12u1 changeset: 11432:c1c450bf62f2 user: John Levon <john.levon@sun.com> date: Tue Jan 05 06:57:53 2010 -0800 summary: 6905711 anonymous and empty SOUs crash ctfconvert changeset: 11227:cd2ac59c39f2 user: Ali Bahrami <Ali.Bahrami@Sun.COM> date: Wed Dec 02 15:37:55 2009 -0700 summary: 6900241 ld should track SHT_GROUP sections by symbol name, not section name changeset: 10380:5394a7172e1f user: Ali Bahrami <Ali.Bahrami@Sun.COM> date: Tue Aug 25 13:51:43 2009 -0600 summary: 6866605 SUNWonbld ELF analysis tools need overhaul (fix ctfmerge/libc dependency) changeset: 10207:87c40ea3fc4b user: jmcp <James.McPherson@Sun.COM> date: Wed Jul 29 16:56:03 2009 -0700 summary: 6864230 hiho, hiho, it'ch chtime for CH to go changeset: 10206:51f52702df72 user: John Levon <john.levon@sun.com> date: Wed Jul 29 14:36:30 2009 -0700 summary: 6854065 CTF tools should error out given 1024+-member structures changeset: 7230:429b4f7acf1a user: sn199410 date: Wed Jul 30 16:10:30 2008 -0700 summary: 6575435 ctf tools cannot handle C99 VLAs ("variable length arrays") changeset: 6936:72189fcd99e4 user: sommerfe date: Sun Jun 22 09:13:44 2008 -0700 summary: 6716983 left-for-dead ctfmerge worker threads awake to take out maker ---- - dtrace command utility: changeset: 12507:501806a754d2 user: Alan Maguire <Alan.Maguire@Sun.COM> date: Thu May 27 17:29:51 2010 -0400 summary: PSARC 2010/106 DTrace TCP and UDP providers changeset: 11838:32bb5d254240 user: Liane Praza <Liane.Praza@Sun.COM> date: Tue Mar 02 19:29:26 2010 -0700 summary: PSARC 2010/067 Interim modernization updates changeset: 11270:47a962fe7b45 user: Frank Van Der Linden <Frank.Vanderlinden@Sun.COM> date: Mon Dec 07 13:47:36 2009 -0800 summary: 6907170 fix for 6875656 left out updates to DTrace test suite changeset: 11237:0d23e47ed228 user: Jonathan Haslam <Jonathan.Haslam@Sun.COM> date: Thu Dec 03 13:39:19 2009 +0000 summary: 6795386 macro arguments and globbing in DTrace probe descriptions don't mix changeset: 11153:dec430d20576 user: Frank Van Der Linden <Frank.Vanderlinden@Sun.COM> date: Sun Nov 22 19:22:26 2009 -0800 summary: 6875656 xdt needs to support more XenTrace probes changeset: 11102:b91faef0c984 user: Gavin Maltby <Gavin.Maltby@Sun.COM> date: Thu Nov 19 15:28:11 2009 +1100 summary: PSARC/2009/554 door_xcreate - extended door creation interface for private doors changeset: 11066:cebb50cbe4f9 user: Rafael Vanoni <rafael.vanoni@sun.com> date: Fri Nov 13 01:32:32 2009 -0800 summary: PSARC/2009/396 Tickless Kernel Architecture / lbolt decoupling changeset: 10791:944abfb5b345 user: Jonathan Haslam <Jonathan.Haslam@Sun.COM> date: Wed Oct 14 11:25:23 2009 +0100 summary: 6886953 large symbols lead to stack exhaustion changeset: 10207:87c40ea3fc4b user: jmcp <James.McPherson@Sun.COM> date: Wed Jul 29 16:56:03 2009 -0700 summary: 6864230 hiho, hiho, it'ch chtime for CH to go changeset: 9531:dc8924ef7839 user: Rafael Vanoni <rafael.vanoni@sun.com> date: Mon May 04 11:48:15 2009 -0700 summary: 6730130 dtrace missing printf handler for stdev changeset: 9397:e667d620a75c user: Jonathan Haslam <Jonathan.Haslam@Sun.COM> date: Mon Apr 20 07:58:44 2009 +0100 summary: 6806023 cpc provider event name validation needs to be a bit tighter changeset: 8803:8c01b39012c9 user: Jonathan Haslam <Jonathan.Haslam@Sun.COM> date: Fri Feb 13 07:13:13 2009 +0000 summary: PSARC 2008/480 DTrace CPC Provider changeset: 8605:0189cb9c5358 user: Jonathan Haslam <Jonathan.Haslam@Sun.COM> date: Thu Jan 22 12:09:13 2009 +0000 summary: 6749441 intrstat(1M) shows zeroed values after suspend/resume changeset: 8337:079ecc003ca6 user: Jonathan Haslam <Jonathan.Haslam@Sun.COM> date: Thu Dec 11 11:26:47 2008 +0000 summary: 6750659 drti.o crashes app due to corrupt environment changeset: 8287:771477e4b843 user: John Sonnenschein <John.Sonnenschein@Sun.COM> date: Fri Dec 05 19:08:38 2008 -0800 summary: PSARC 2005/462 Removal of Perl 5.6.1 from Solaris 11 changeset: 7991:d3b751ef3d85 user: Jonathan Haslam <Jonathan.Haslam@Sun.COM> date: Mon Nov 03 10:26:23 2008 +0000 summary: 6738982 Representative thread after DTrace stop() action is incorrect changeset: 7502:da077e5d991e user: Aruna Ramakrishna <aruna@cs.umn.edu> date: Sat Sep 06 05:36:02 2008 -0400 summary: 6706947 tcp_trace should be replaced with dtrace probes. changeset: 7484:a48e950bad22 user: Tom Erickson <tomee@eng.sun.com> date: Wed Sep 03 15:14:25 2008 -0700 summary: 6737926 getAggregate() method fails to specify anonymous aggregation explicitly changeset: 7299:d9a056040774 user: John Beck <John.Beck@Sun.COM> date: Thu Aug 07 12:44:26 2008 -0700 summary: 6734627 protocmp complains about opt/SUNWdtrt/README after TW -> Hg switch changeset: 6998:58787ea78303 user: brendan date: Tue Jul 01 18:28:22 2008 -0700 summary: 6721426 tst.sdtargs.d passes despite dtrace "invalid address" error changeset: 6878:360e73ea6b0c user: brendan date: Fri Jun 13 19:06:55 2008 -0700 summary: PSARC 2008/302 DTrace IP Provider changeset: 6670:1961a43f2335 user: tariq date: Tue May 20 15:08:16 2008 -0700 summary: 6685348 Hypervisor event provider for DTrace changeset: 6554:b5817e112852 user: ahl date: Mon May 05 14:38:24 2008 -0700 summary: 6677812 race between dtrace activities in non-local zones changeset: 6543:465433824d87 user: rie date: Fri May 02 15:01:06 2008 -0700 summary: 6683064 check_rtime could do with some spring cleaning
758 lines
19 KiB
C
758 lines
19 KiB
C
/*
|
|
* 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
|
|
* or http://www.opensolaris.org/os/licensing.
|
|
* 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 2010 Sun Microsystems, Inc. All rights reserved.
|
|
* Use is subject to license terms.
|
|
*/
|
|
|
|
#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 {
|
|
dtrace_hdl_t *dpp_dtp;
|
|
dt_pcb_t *dpp_pcb;
|
|
dt_proc_t *dpp_dpr;
|
|
struct ps_prochandle *dpp_pr;
|
|
const char *dpp_mod;
|
|
char *dpp_func;
|
|
const char *dpp_name;
|
|
const char *dpp_obj;
|
|
uintptr_t dpp_pc;
|
|
size_t dpp_size;
|
|
Lmid_t dpp_lmid;
|
|
uint_t dpp_nmatches;
|
|
uint64_t dpp_stret[4];
|
|
GElf_Sym dpp_last;
|
|
uint_t dpp_last_taken;
|
|
} dt_pid_probe_t;
|
|
|
|
/*
|
|
* Compose the lmid and object name into the canonical representation. We
|
|
* omit the lmid for the default link map for convenience.
|
|
*/
|
|
static void
|
|
dt_pid_objname(char *buf, size_t len, Lmid_t lmid, const char *obj)
|
|
{
|
|
if (lmid == LM_ID_BASE)
|
|
(void) strncpy(buf, obj, len);
|
|
else
|
|
(void) snprintf(buf, len, "LM%lx`%s", lmid, obj);
|
|
}
|
|
|
|
static int
|
|
dt_pid_error(dtrace_hdl_t *dtp, dt_pcb_t *pcb, dt_proc_t *dpr,
|
|
fasttrap_probe_spec_t *ftp, dt_errtag_t tag, const char *fmt, ...)
|
|
{
|
|
va_list ap;
|
|
int len;
|
|
|
|
if (ftp != NULL)
|
|
dt_free(dtp, ftp);
|
|
|
|
va_start(ap, fmt);
|
|
if (pcb == NULL) {
|
|
assert(dpr != NULL);
|
|
len = vsnprintf(dpr->dpr_errmsg, sizeof (dpr->dpr_errmsg),
|
|
fmt, ap);
|
|
assert(len >= 2);
|
|
if (dpr->dpr_errmsg[len - 2] == '\n')
|
|
dpr->dpr_errmsg[len - 2] = '\0';
|
|
} else {
|
|
dt_set_errmsg(dtp, dt_errtag(tag), pcb->pcb_region,
|
|
pcb->pcb_filetag, pcb->pcb_fileptr ? yylineno : 0, fmt, ap);
|
|
}
|
|
va_end(ap);
|
|
|
|
return (1);
|
|
}
|
|
|
|
static int
|
|
dt_pid_per_sym(dt_pid_probe_t *pp, const GElf_Sym *symp, const char *func)
|
|
{
|
|
dtrace_hdl_t *dtp = pp->dpp_dtp;
|
|
dt_pcb_t *pcb = pp->dpp_pcb;
|
|
dt_proc_t *dpr = pp->dpp_dpr;
|
|
fasttrap_probe_spec_t *ftp;
|
|
uint64_t off;
|
|
char *end;
|
|
uint_t nmatches = 0;
|
|
ulong_t sz;
|
|
int glob, err;
|
|
int isdash = strcmp("-", func) == 0;
|
|
pid_t pid;
|
|
|
|
pid = Pstatus(pp->dpp_pr)->pr_pid;
|
|
|
|
dt_dprintf("creating probe pid%d:%s:%s:%s\n", (int)pid, pp->dpp_obj,
|
|
func, pp->dpp_name);
|
|
|
|
sz = sizeof (fasttrap_probe_spec_t) + (isdash ? 4 :
|
|
(symp->st_size - 1) * sizeof (ftp->ftps_offs[0]));
|
|
|
|
if ((ftp = dt_alloc(dtp, sz)) == NULL) {
|
|
dt_dprintf("proc_per_sym: dt_alloc(%lu) failed\n", sz);
|
|
return (1); /* errno is set for us */
|
|
}
|
|
|
|
ftp->ftps_pid = pid;
|
|
(void) strncpy(ftp->ftps_func, func, sizeof (ftp->ftps_func));
|
|
|
|
dt_pid_objname(ftp->ftps_mod, sizeof (ftp->ftps_mod), pp->dpp_lmid,
|
|
pp->dpp_obj);
|
|
|
|
if (!isdash && gmatch("return", pp->dpp_name)) {
|
|
if (dt_pid_create_return_probe(pp->dpp_pr, dtp, ftp, symp,
|
|
pp->dpp_stret) < 0) {
|
|
return (dt_pid_error(dtp, pcb, dpr, ftp,
|
|
D_PROC_CREATEFAIL, "failed to create return probe "
|
|
"for '%s': %s", func,
|
|
dtrace_errmsg(dtp, dtrace_errno(dtp))));
|
|
}
|
|
|
|
nmatches++;
|
|
}
|
|
|
|
if (!isdash && gmatch("entry", pp->dpp_name)) {
|
|
if (dt_pid_create_entry_probe(pp->dpp_pr, dtp, ftp, symp) < 0) {
|
|
return (dt_pid_error(dtp, pcb, dpr, ftp,
|
|
D_PROC_CREATEFAIL, "failed to create entry probe "
|
|
"for '%s': %s", func,
|
|
dtrace_errmsg(dtp, dtrace_errno(dtp))));
|
|
}
|
|
|
|
nmatches++;
|
|
}
|
|
|
|
glob = strisglob(pp->dpp_name);
|
|
if (!glob && nmatches == 0) {
|
|
off = strtoull(pp->dpp_name, &end, 16);
|
|
if (*end != '\0') {
|
|
return (dt_pid_error(dtp, pcb, dpr, ftp, D_PROC_NAME,
|
|
"'%s' is an invalid probe name", pp->dpp_name));
|
|
}
|
|
|
|
if (off >= symp->st_size) {
|
|
return (dt_pid_error(dtp, pcb, dpr, ftp, D_PROC_OFF,
|
|
"offset 0x%llx outside of function '%s'",
|
|
(u_longlong_t)off, func));
|
|
}
|
|
|
|
err = dt_pid_create_offset_probe(pp->dpp_pr, pp->dpp_dtp, ftp,
|
|
symp, off);
|
|
|
|
if (err == DT_PROC_ERR) {
|
|
return (dt_pid_error(dtp, pcb, dpr, ftp,
|
|
D_PROC_CREATEFAIL, "failed to create probe at "
|
|
"'%s+0x%llx': %s", func, (u_longlong_t)off,
|
|
dtrace_errmsg(dtp, dtrace_errno(dtp))));
|
|
}
|
|
|
|
if (err == DT_PROC_ALIGN) {
|
|
return (dt_pid_error(dtp, pcb, dpr, ftp, D_PROC_ALIGN,
|
|
"offset 0x%llx is not aligned on an instruction",
|
|
(u_longlong_t)off));
|
|
}
|
|
|
|
nmatches++;
|
|
|
|
} else if (glob && !isdash) {
|
|
if (dt_pid_create_glob_offset_probes(pp->dpp_pr,
|
|
pp->dpp_dtp, ftp, symp, pp->dpp_name) < 0) {
|
|
return (dt_pid_error(dtp, pcb, dpr, ftp,
|
|
D_PROC_CREATEFAIL,
|
|
"failed to create offset probes in '%s': %s", func,
|
|
dtrace_errmsg(dtp, dtrace_errno(dtp))));
|
|
}
|
|
|
|
nmatches++;
|
|
}
|
|
|
|
pp->dpp_nmatches += nmatches;
|
|
|
|
dt_free(dtp, ftp);
|
|
|
|
return (0);
|
|
}
|
|
|
|
static int
|
|
dt_pid_sym_filt(void *arg, const GElf_Sym *symp, const char *func)
|
|
{
|
|
dt_pid_probe_t *pp = arg;
|
|
|
|
if (symp->st_shndx == SHN_UNDEF)
|
|
return (0);
|
|
|
|
if (symp->st_size == 0) {
|
|
dt_dprintf("st_size of %s is zero\n", func);
|
|
return (0);
|
|
}
|
|
|
|
if (pp->dpp_last_taken == 0 ||
|
|
symp->st_value != pp->dpp_last.st_value ||
|
|
symp->st_size != pp->dpp_last.st_size) {
|
|
/*
|
|
* 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.
|
|
*/
|
|
if (strcmp(func, "_init") == 0 || strcmp(func, "_fini") == 0)
|
|
return (0);
|
|
|
|
if ((pp->dpp_last_taken = gmatch(func, pp->dpp_func)) != 0) {
|
|
pp->dpp_last = *symp;
|
|
return (dt_pid_per_sym(pp, symp, func));
|
|
}
|
|
}
|
|
|
|
return (0);
|
|
}
|
|
|
|
static int
|
|
dt_pid_per_mod(void *arg, const prmap_t *pmp, const char *obj)
|
|
{
|
|
dt_pid_probe_t *pp = arg;
|
|
dtrace_hdl_t *dtp = pp->dpp_dtp;
|
|
dt_pcb_t *pcb = pp->dpp_pcb;
|
|
dt_proc_t *dpr = pp->dpp_dpr;
|
|
GElf_Sym sym;
|
|
|
|
if (obj == NULL)
|
|
return (0);
|
|
|
|
(void) Plmid(pp->dpp_pr, pmp->pr_vaddr, &pp->dpp_lmid);
|
|
|
|
if ((pp->dpp_obj = strrchr(obj, '/')) == NULL)
|
|
pp->dpp_obj = obj;
|
|
else
|
|
pp->dpp_obj++;
|
|
|
|
if (Pxlookup_by_name(pp->dpp_pr, pp->dpp_lmid, obj, ".stret1", &sym,
|
|
NULL) == 0)
|
|
pp->dpp_stret[0] = sym.st_value;
|
|
else
|
|
pp->dpp_stret[0] = 0;
|
|
|
|
if (Pxlookup_by_name(pp->dpp_pr, pp->dpp_lmid, obj, ".stret2", &sym,
|
|
NULL) == 0)
|
|
pp->dpp_stret[1] = sym.st_value;
|
|
else
|
|
pp->dpp_stret[1] = 0;
|
|
|
|
if (Pxlookup_by_name(pp->dpp_pr, pp->dpp_lmid, obj, ".stret4", &sym,
|
|
NULL) == 0)
|
|
pp->dpp_stret[2] = sym.st_value;
|
|
else
|
|
pp->dpp_stret[2] = 0;
|
|
|
|
if (Pxlookup_by_name(pp->dpp_pr, pp->dpp_lmid, obj, ".stret8", &sym,
|
|
NULL) == 0)
|
|
pp->dpp_stret[3] = sym.st_value;
|
|
else
|
|
pp->dpp_stret[3] = 0;
|
|
|
|
dt_dprintf("%s stret %llx %llx %llx %llx\n", obj,
|
|
(u_longlong_t)pp->dpp_stret[0], (u_longlong_t)pp->dpp_stret[1],
|
|
(u_longlong_t)pp->dpp_stret[2], (u_longlong_t)pp->dpp_stret[3]);
|
|
|
|
/*
|
|
* 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 (!strisglob(pp->dpp_func)) {
|
|
/*
|
|
* 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.
|
|
*/
|
|
if (Pxlookup_by_name(pp->dpp_pr, pp->dpp_lmid, obj,
|
|
pp->dpp_func, &sym, NULL) != 0) {
|
|
if (strcmp("-", pp->dpp_func) == 0) {
|
|
sym.st_name = 0;
|
|
sym.st_info =
|
|
GELF_ST_INFO(STB_LOCAL, STT_FUNC);
|
|
sym.st_other = 0;
|
|
sym.st_value = 0;
|
|
sym.st_size = Pstatus(pp->dpp_pr)->pr_dmodel ==
|
|
PR_MODEL_ILP32 ? -1U : -1ULL;
|
|
|
|
} else if (!strisglob(pp->dpp_mod)) {
|
|
return (dt_pid_error(dtp, pcb, dpr, NULL,
|
|
D_PROC_FUNC,
|
|
"failed to lookup '%s' in module '%s'",
|
|
pp->dpp_func, pp->dpp_mod));
|
|
} else {
|
|
return (0);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Only match defined functions of non-zero size.
|
|
*/
|
|
if (GELF_ST_TYPE(sym.st_info) != STT_FUNC ||
|
|
sym.st_shndx == SHN_UNDEF || sym.st_size == 0)
|
|
return (0);
|
|
|
|
/*
|
|
* We don't instrument PLTs -- they're dynamically rewritten,
|
|
* and, so, inherently dicey to instrument.
|
|
*/
|
|
if (Ppltdest(pp->dpp_pr, sym.st_value) != NULL)
|
|
return (0);
|
|
|
|
(void) Plookup_by_addr(pp->dpp_pr, sym.st_value, pp->dpp_func,
|
|
DTRACE_FUNCNAMELEN, &sym);
|
|
|
|
return (dt_pid_per_sym(pp, &sym, pp->dpp_func));
|
|
} else {
|
|
uint_t nmatches = pp->dpp_nmatches;
|
|
|
|
if (Psymbol_iter_by_addr(pp->dpp_pr, obj, PR_SYMTAB,
|
|
BIND_ANY | TYPE_FUNC, dt_pid_sym_filt, pp) == 1)
|
|
return (1);
|
|
|
|
if (nmatches == pp->dpp_nmatches) {
|
|
/*
|
|
* If we didn't match anything in the PR_SYMTAB, try
|
|
* the PR_DYNSYM.
|
|
*/
|
|
if (Psymbol_iter_by_addr(pp->dpp_pr, obj, PR_DYNSYM,
|
|
BIND_ANY | TYPE_FUNC, dt_pid_sym_filt, pp) == 1)
|
|
return (1);
|
|
}
|
|
}
|
|
|
|
return (0);
|
|
}
|
|
|
|
static int
|
|
dt_pid_mod_filt(void *arg, const prmap_t *pmp, const char *obj)
|
|
{
|
|
char name[DTRACE_MODNAMELEN];
|
|
dt_pid_probe_t *pp = arg;
|
|
|
|
if ((pp->dpp_obj = strrchr(obj, '/')) == NULL)
|
|
pp->dpp_obj = obj;
|
|
else
|
|
pp->dpp_obj++;
|
|
|
|
if (gmatch(pp->dpp_obj, pp->dpp_mod))
|
|
return (dt_pid_per_mod(pp, pmp, obj));
|
|
|
|
(void) Plmid(pp->dpp_pr, pmp->pr_vaddr, &pp->dpp_lmid);
|
|
|
|
dt_pid_objname(name, sizeof (name), pp->dpp_lmid, pp->dpp_obj);
|
|
|
|
if (gmatch(name, pp->dpp_mod))
|
|
return (dt_pid_per_mod(pp, pmp, obj));
|
|
|
|
return (0);
|
|
}
|
|
|
|
static const prmap_t *
|
|
dt_pid_fix_mod(dtrace_probedesc_t *pdp, struct ps_prochandle *P)
|
|
{
|
|
char m[MAXPATHLEN];
|
|
Lmid_t lmid = PR_LMID_EVERY;
|
|
const char *obj;
|
|
const prmap_t *pmp;
|
|
|
|
/*
|
|
* Pick apart the link map from the library name.
|
|
*/
|
|
if (strchr(pdp->dtpd_mod, '`') != NULL) {
|
|
char *end;
|
|
|
|
if (strncmp(pdp->dtpd_mod, "LM", 2) != 0 ||
|
|
!isdigit(pdp->dtpd_mod[2]))
|
|
return (NULL);
|
|
|
|
lmid = strtoul(&pdp->dtpd_mod[2], &end, 16);
|
|
|
|
obj = end + 1;
|
|
|
|
if (*end != '`' || strchr(obj, '`') != NULL)
|
|
return (NULL);
|
|
|
|
} else {
|
|
obj = pdp->dtpd_mod;
|
|
}
|
|
|
|
if ((pmp = Plmid_to_map(P, lmid, obj)) == NULL)
|
|
return (NULL);
|
|
|
|
(void) Pobjname(P, pmp->pr_vaddr, m, sizeof (m));
|
|
if ((obj = strrchr(m, '/')) == NULL)
|
|
obj = &m[0];
|
|
else
|
|
obj++;
|
|
|
|
(void) Plmid(P, pmp->pr_vaddr, &lmid);
|
|
dt_pid_objname(pdp->dtpd_mod, sizeof (pdp->dtpd_mod), lmid, obj);
|
|
|
|
return (pmp);
|
|
}
|
|
|
|
|
|
static int
|
|
dt_pid_create_pid_probes(dtrace_probedesc_t *pdp, dtrace_hdl_t *dtp,
|
|
dt_pcb_t *pcb, dt_proc_t *dpr)
|
|
{
|
|
dt_pid_probe_t pp;
|
|
int ret = 0;
|
|
|
|
pp.dpp_dtp = dtp;
|
|
pp.dpp_dpr = dpr;
|
|
pp.dpp_pr = dpr->dpr_proc;
|
|
pp.dpp_pcb = pcb;
|
|
|
|
/*
|
|
* We can only trace dynamically-linked executables (since we've
|
|
* hidden some magic in ld.so.1 as well as libc.so.1).
|
|
*/
|
|
if (Pname_to_map(pp.dpp_pr, PR_OBJ_LDSO) == NULL) {
|
|
return (dt_pid_error(dtp, pcb, dpr, NULL, D_PROC_DYN,
|
|
"process %s is not a dynamically-linked executable",
|
|
&pdp->dtpd_provider[3]));
|
|
}
|
|
|
|
pp.dpp_mod = pdp->dtpd_mod[0] != '\0' ? pdp->dtpd_mod : "*";
|
|
pp.dpp_func = pdp->dtpd_func[0] != '\0' ? pdp->dtpd_func : "*";
|
|
pp.dpp_name = pdp->dtpd_name[0] != '\0' ? pdp->dtpd_name : "*";
|
|
pp.dpp_last_taken = 0;
|
|
|
|
if (strcmp(pp.dpp_func, "-") == 0) {
|
|
const prmap_t *aout, *pmp;
|
|
|
|
if (pdp->dtpd_mod[0] == '\0') {
|
|
pp.dpp_mod = pdp->dtpd_mod;
|
|
(void) strcpy(pdp->dtpd_mod, "a.out");
|
|
} else if (strisglob(pp.dpp_mod) ||
|
|
(aout = Pname_to_map(pp.dpp_pr, "a.out")) == NULL ||
|
|
(pmp = Pname_to_map(pp.dpp_pr, pp.dpp_mod)) == NULL ||
|
|
aout->pr_vaddr != pmp->pr_vaddr) {
|
|
return (dt_pid_error(dtp, pcb, dpr, NULL, D_PROC_LIB,
|
|
"only the a.out module is valid with the "
|
|
"'-' function"));
|
|
}
|
|
|
|
if (strisglob(pp.dpp_name)) {
|
|
return (dt_pid_error(dtp, pcb, dpr, NULL, D_PROC_NAME,
|
|
"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 '*'.
|
|
*/
|
|
if (strisglob(pp.dpp_mod)) {
|
|
ret = Pobject_iter(pp.dpp_pr, dt_pid_mod_filt, &pp);
|
|
} else {
|
|
const prmap_t *pmp;
|
|
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.
|
|
*/
|
|
if ((pmp = dt_pid_fix_mod(pdp, pp.dpp_pr)) != NULL) {
|
|
if ((obj = strchr(pdp->dtpd_mod, '`')) == NULL)
|
|
obj = pdp->dtpd_mod;
|
|
else
|
|
obj++;
|
|
|
|
ret = dt_pid_per_mod(&pp, pmp, obj);
|
|
}
|
|
}
|
|
|
|
return (ret);
|
|
}
|
|
|
|
static int
|
|
dt_pid_usdt_mapping(void *data, const prmap_t *pmp, const char *oname)
|
|
{
|
|
struct ps_prochandle *P = data;
|
|
GElf_Sym sym;
|
|
prsyminfo_t sip;
|
|
dof_helper_t dh;
|
|
GElf_Half e_type;
|
|
const char *mname;
|
|
const char *syms[] = { "___SUNW_dof", "__SUNW_dof" };
|
|
int i, fd = -1;
|
|
|
|
/*
|
|
* 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++) {
|
|
if (Pxlookup_by_name(P, PR_LMID_EVERY, oname, syms[i], &sym,
|
|
&sip) != 0) {
|
|
continue;
|
|
}
|
|
|
|
if ((mname = strrchr(oname, '/')) == NULL)
|
|
mname = oname;
|
|
else
|
|
mname++;
|
|
|
|
dt_dprintf("lookup of %s succeeded for %s\n", syms[i], mname);
|
|
|
|
if (Pread(P, &e_type, sizeof (e_type), pmp->pr_vaddr +
|
|
offsetof(Elf64_Ehdr, e_type)) != sizeof (e_type)) {
|
|
dt_dprintf("read of ELF header failed");
|
|
continue;
|
|
}
|
|
|
|
dh.dofhp_dof = sym.st_value;
|
|
dh.dofhp_addr = (e_type == ET_EXEC) ? 0 : pmp->pr_vaddr;
|
|
|
|
dt_pid_objname(dh.dofhp_mod, sizeof (dh.dofhp_mod),
|
|
sip.prs_lmid, mname);
|
|
|
|
if (fd == -1 &&
|
|
(fd = pr_open(P, "/dev/dtrace/helper", O_RDWR, 0)) < 0) {
|
|
dt_dprintf("pr_open of helper device failed: %s\n",
|
|
strerror(errno));
|
|
return (-1); /* errno is set for us */
|
|
}
|
|
|
|
if (pr_ioctl(P, fd, DTRACEHIOC_ADDDOF, &dh, sizeof (dh)) < 0)
|
|
dt_dprintf("DOF was rejected for %s\n", dh.dofhp_mod);
|
|
}
|
|
|
|
if (fd != -1)
|
|
(void) pr_close(P, fd);
|
|
|
|
return (0);
|
|
}
|
|
|
|
static int
|
|
dt_pid_create_usdt_probes(dtrace_probedesc_t *pdp, dtrace_hdl_t *dtp,
|
|
dt_pcb_t *pcb, dt_proc_t *dpr)
|
|
{
|
|
struct ps_prochandle *P = dpr->dpr_proc;
|
|
int ret = 0;
|
|
|
|
assert(MUTEX_HELD(&dpr->dpr_lock));
|
|
|
|
(void) Pupdate_maps(P);
|
|
if (Pobject_iter(P, dt_pid_usdt_mapping, P) != 0) {
|
|
ret = -1;
|
|
(void) dt_pid_error(dtp, pcb, dpr, NULL, D_PROC_USDT,
|
|
"failed to instantiate probes for pid %d: %s",
|
|
(int)Pstatus(P)->pr_pid, strerror(errno));
|
|
}
|
|
|
|
/*
|
|
* Put the module name in its canonical form.
|
|
*/
|
|
(void) dt_pid_fix_mod(pdp, P);
|
|
|
|
return (ret);
|
|
}
|
|
|
|
static pid_t
|
|
dt_pid_get_pid(dtrace_probedesc_t *pdp, dtrace_hdl_t *dtp, dt_pcb_t *pcb,
|
|
dt_proc_t *dpr)
|
|
{
|
|
pid_t pid;
|
|
char *c, *last = NULL, *end;
|
|
|
|
for (c = &pdp->dtpd_provider[0]; *c != '\0'; c++) {
|
|
if (!isdigit(*c))
|
|
last = c;
|
|
}
|
|
|
|
if (last == NULL || (*(++last) == '\0')) {
|
|
(void) dt_pid_error(dtp, pcb, dpr, NULL, D_PROC_BADPROV,
|
|
"'%s' is not a valid provider", pdp->dtpd_provider);
|
|
return (-1);
|
|
}
|
|
|
|
errno = 0;
|
|
pid = strtol(last, &end, 10);
|
|
|
|
if (errno != 0 || end == last || end[0] != '\0' || pid <= 0) {
|
|
(void) dt_pid_error(dtp, pcb, dpr, NULL, D_PROC_BADPID,
|
|
"'%s' does not contain a valid pid", pdp->dtpd_provider);
|
|
return (-1);
|
|
}
|
|
|
|
return (pid);
|
|
}
|
|
|
|
int
|
|
dt_pid_create_probes(dtrace_probedesc_t *pdp, dtrace_hdl_t *dtp, dt_pcb_t *pcb)
|
|
{
|
|
char provname[DTRACE_PROVNAMELEN];
|
|
struct ps_prochandle *P;
|
|
dt_proc_t *dpr;
|
|
pid_t pid;
|
|
int err = 0;
|
|
|
|
assert(pcb != NULL);
|
|
|
|
if ((pid = dt_pid_get_pid(pdp, dtp, pcb, NULL)) == -1)
|
|
return (-1);
|
|
|
|
if (dtp->dt_ftfd == -1) {
|
|
if (dtp->dt_fterr == ENOENT) {
|
|
(void) dt_pid_error(dtp, pcb, NULL, NULL, D_PROC_NODEV,
|
|
"pid provider is not installed on this system");
|
|
} else {
|
|
(void) dt_pid_error(dtp, pcb, NULL, NULL, D_PROC_NODEV,
|
|
"pid provider is not available: %s",
|
|
strerror(dtp->dt_fterr));
|
|
}
|
|
|
|
return (-1);
|
|
}
|
|
|
|
(void) snprintf(provname, sizeof (provname), "pid%d", (int)pid);
|
|
|
|
if (gmatch(provname, pdp->dtpd_provider) != 0) {
|
|
if ((P = dt_proc_grab(dtp, pid, PGRAB_RDONLY | PGRAB_FORCE,
|
|
0)) == NULL) {
|
|
(void) dt_pid_error(dtp, pcb, NULL, NULL, D_PROC_GRAB,
|
|
"failed to grab process %d", (int)pid);
|
|
return (-1);
|
|
}
|
|
|
|
dpr = dt_proc_lookup(dtp, P, 0);
|
|
assert(dpr != NULL);
|
|
(void) pthread_mutex_lock(&dpr->dpr_lock);
|
|
|
|
if ((err = dt_pid_create_pid_probes(pdp, dtp, pcb, dpr)) == 0) {
|
|
/*
|
|
* Alert other retained enablings which may match
|
|
* against the newly created probes.
|
|
*/
|
|
(void) dt_ioctl(dtp, DTRACEIOC_ENABLE, NULL);
|
|
}
|
|
|
|
(void) pthread_mutex_unlock(&dpr->dpr_lock);
|
|
dt_proc_release(dtp, P);
|
|
}
|
|
|
|
/*
|
|
* If it's not strictly a pid provider, we might match a USDT provider.
|
|
*/
|
|
if (strcmp(provname, pdp->dtpd_provider) != 0) {
|
|
if ((P = dt_proc_grab(dtp, pid, 0, 1)) == NULL) {
|
|
(void) dt_pid_error(dtp, pcb, NULL, NULL, D_PROC_GRAB,
|
|
"failed to grab process %d", (int)pid);
|
|
return (-1);
|
|
}
|
|
|
|
dpr = dt_proc_lookup(dtp, P, 0);
|
|
assert(dpr != NULL);
|
|
(void) pthread_mutex_lock(&dpr->dpr_lock);
|
|
|
|
if (!dpr->dpr_usdt) {
|
|
err = dt_pid_create_usdt_probes(pdp, dtp, pcb, dpr);
|
|
dpr->dpr_usdt = B_TRUE;
|
|
}
|
|
|
|
(void) pthread_mutex_unlock(&dpr->dpr_lock);
|
|
dt_proc_release(dtp, P);
|
|
}
|
|
|
|
return (err ? -1 : 0);
|
|
}
|
|
|
|
int
|
|
dt_pid_create_probes_module(dtrace_hdl_t *dtp, dt_proc_t *dpr)
|
|
{
|
|
dtrace_prog_t *pgp;
|
|
dt_stmt_t *stp;
|
|
dtrace_probedesc_t *pdp, pd;
|
|
pid_t pid;
|
|
int ret = 0, found = B_FALSE;
|
|
char provname[DTRACE_PROVNAMELEN];
|
|
|
|
(void) snprintf(provname, sizeof (provname), "pid%d",
|
|
(int)dpr->dpr_pid);
|
|
|
|
for (pgp = dt_list_next(&dtp->dt_programs); pgp != NULL;
|
|
pgp = dt_list_next(pgp)) {
|
|
|
|
for (stp = dt_list_next(&pgp->dp_stmts); stp != NULL;
|
|
stp = dt_list_next(stp)) {
|
|
|
|
pdp = &stp->ds_desc->dtsd_ecbdesc->dted_probe;
|
|
pid = dt_pid_get_pid(pdp, dtp, NULL, dpr);
|
|
if (pid != dpr->dpr_pid)
|
|
continue;
|
|
|
|
found = B_TRUE;
|
|
|
|
pd = *pdp;
|
|
|
|
if (gmatch(provname, pdp->dtpd_provider) != 0 &&
|
|
dt_pid_create_pid_probes(&pd, dtp, NULL, dpr) != 0)
|
|
ret = 1;
|
|
|
|
/*
|
|
* If it's not strictly a pid provider, we might match
|
|
* a USDT provider.
|
|
*/
|
|
if (strcmp(provname, pdp->dtpd_provider) != 0 &&
|
|
dt_pid_create_usdt_probes(&pd, dtp, NULL, dpr) != 0)
|
|
ret = 1;
|
|
}
|
|
}
|
|
|
|
if (found) {
|
|
/*
|
|
* Give DTrace a shot to the ribs to get it to check
|
|
* out the newly created probes.
|
|
*/
|
|
(void) dt_ioctl(dtp, DTRACEIOC_ENABLE, NULL);
|
|
}
|
|
|
|
return (ret);
|
|
}
|