4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 #include <stdio_ext.h>
34 #include <proc_service.h>
36 static int show_map(void *, const prmap_t
*, const char *);
41 main(int argc
, char **argv
)
48 core_content_t content
= CC_CONTENT_DATA
| CC_CONTENT_ANON
;
51 if ((command
= strrchr(argv
[0], '/')) != NULL
)
57 while ((opt
= getopt(argc
, argv
, "Fl")) != EOF
) {
59 case 'F': /* force grabbing (no O_EXCL) */
62 case 'l': /* show unresolved link map names */
74 if (errflg
|| argc
<= 0) {
75 (void) fprintf(stderr
,
76 "usage:\t%s [-Fl] { pid | core } ...\n", command
);
77 (void) fprintf(stderr
,
78 " (report process dynamic libraries)\n");
79 (void) fprintf(stderr
,
80 " -F: force grabbing of the target process\n"
81 " -l: show unresolved dynamic linker map names\n");
86 * Make sure we'll have enough file descriptors to handle a target
87 * that has many many mappings.
89 if (getrlimit(RLIMIT_NOFILE
, &rlim
) == 0) {
90 rlim
.rlim_cur
= rlim
.rlim_max
;
91 (void) setrlimit(RLIMIT_NOFILE
, &rlim
);
92 (void) enable_extended_FILE_stdio(-1, -1);
95 (void) proc_initstdio();
101 struct ps_prochandle
*Pr
;
103 (void) proc_flushstdio();
105 if ((Pr
= proc_arg_grab(arg
= *argv
++, PR_ARG_ANY
,
106 PGRAB_RETAIN
| Fflag
, &gcode
)) == NULL
) {
108 (void) fprintf(stderr
, "%s: cannot examine %s: %s\n",
109 command
, arg
, Pgrab_error(gcode
));
114 (void) memcpy(&psinfo
, Ppsinfo(Pr
), sizeof (psinfo_t
));
115 proc_unctrl_psinfo(&psinfo
);
117 if (Pstate(Pr
) == PS_DEAD
) {
118 if ((Pcontent(Pr
) & content
) != content
) {
119 (void) fprintf(stderr
, "%s: core '%s' has "
120 "insufficient content\n", command
, arg
);
124 (void) printf("core '%s' of %d:\t%.70s\n",
125 arg
, (int)psinfo
.pr_pid
, psinfo
.pr_psargs
);
127 (void) printf("%d:\t%.70s\n",
128 (int)psinfo
.pr_pid
, psinfo
.pr_psargs
);
131 if (Pgetauxval(Pr
, AT_BASE
) != -1L && Prd_agent(Pr
) == NULL
) {
132 (void) fprintf(stderr
, "%s: warning: librtld_db failed "
133 "to initialize; shared library information will "
134 "not be available\n", command
);
138 rc
+= Pobject_iter(Pr
, show_map
, Pr
);
140 rc
+= Pobject_iter_resolved(Pr
, show_map
, Pr
);
143 (void) proc_finistdio();
149 show_map(void *cd
, const prmap_t
*pmap
, const char *object_name
)
151 char pathname
[PATH_MAX
];
152 struct ps_prochandle
*Pr
= cd
;
156 /* omit the executable file */
157 if (strcmp(pmap
->pr_mapname
, "a.out") == 0)
160 /* also omit the dynamic linker */
161 if (ps_pauxv(Pr
, &auxv
) == PS_OK
) {
162 while (auxv
->a_type
!= AT_NULL
) {
163 if (auxv
->a_type
== AT_BASE
) {
164 if (pmap
->pr_vaddr
== auxv
->a_un
.a_val
)
172 /* freedom from symlinks; canonical form */
173 if ((len
= resolvepath(object_name
, pathname
, sizeof (pathname
))) > 0)
174 pathname
[len
] = '\0';
176 (void) strncpy(pathname
, object_name
, sizeof (pathname
));
178 (void) printf("%s\n", pathname
);