4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2001-2002 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
31 #include <ipp/ipp_impl.h>
32 #include <mdb/mdb_modapi.h>
34 static uintptr_t ipp_mod_byid
;
35 static uintptr_t ipp_action_byid
;
37 static int byid_walk_init(mdb_walk_state_t
*);
38 static int byid_walk_step(mdb_walk_state_t
*);
39 static void byid_walk_fini(mdb_walk_state_t
*);
41 static int action(uintptr_t, uint_t
, int, const mdb_arg_t
*);
42 static int action_format(uintptr_t, const void *, void *);
43 static int action_dump(uintptr_t, ipp_action_t
*, boolean_t
);
44 static int action_summary(uintptr_t, ipp_action_t
*, boolean_t
);
46 static int cfglock(uintptr_t, uint_t
, int, const mdb_arg_t
*);
48 static int mod(uintptr_t, uint_t
, int, const mdb_arg_t
*);
49 static int mod_format(uintptr_t, const void *, void *);
50 static int mod_dump(uintptr_t, ipp_mod_t
*, boolean_t
);
51 static int mod_summary(uintptr_t, ipp_mod_t
*, boolean_t
);
52 static int cfglock(uintptr_t, uint_t
, int, const mdb_arg_t
*);
54 static int ippops(uintptr_t, uint_t
, int, const mdb_arg_t
*);
56 static int packet(uintptr_t, uint_t
, int, const mdb_arg_t
*);
57 static void dump_classes(uintptr_t, uint_t
);
58 static void dump_log(uintptr_t, uint_t
);
59 static void aid2aname(ipp_action_id_t
, char *);
61 static int ref_walk_init(mdb_walk_state_t
*);
62 static int ref_walk_step(mdb_walk_state_t
*);
63 static void ref_walk_fini(mdb_walk_state_t
*);
65 typedef struct afdata
{
72 typedef struct mfdata
{
80 * walker. Skips entries that are NULL.
85 mdb_walk_state_t
*wsp
)
89 if (mdb_vread(&start
, sizeof (uintptr_t), wsp
->walk_addr
) == -1) {
90 mdb_warn("failed to read from address %p", wsp
->walk_addr
);
94 wsp
->walk_addr
= start
;
101 mdb_walk_state_t
*wsp
)
106 if (mdb_vread(&ptr
, sizeof (void *), wsp
->walk_addr
) == -1) {
107 mdb_warn("failed to read from address %p", wsp
->walk_addr
);
111 if (ptr
== (void *)-1) {
113 } else if (ptr
== NULL
) {
116 status
= wsp
->walk_callback((uintptr_t)ptr
, NULL
,
120 wsp
->walk_addr
+= sizeof (void *);
128 mdb_walk_state_t
*wsp
)
139 const mdb_arg_t
*argv
)
145 afp
= mdb_zalloc(sizeof (afdata_t
), UM_SLEEP
);
147 if (mdb_getopts(argc
, argv
,
148 'v', MDB_OPT_SETBITS
, AF_VERBOSE
, &afp
->af_flags
,
152 if ((flags
& DCMD_LOOPFIRST
) || !(flags
& DCMD_LOOP
))
153 afp
->af_banner
= B_TRUE
;
155 if (flags
& DCMD_ADDRSPEC
) {
156 status
= action_format(addr
, NULL
, afp
);
157 rc
= (status
== WALK_NEXT
) ? DCMD_OK
: DCMD_ERR
;
161 if (mdb_pwalk("ipp_byid", action_format
, afp
,
162 ipp_action_byid
) == -1) {
163 mdb_warn("failed to execute ipp_byid walk");
168 mdb_free(afp
, sizeof (afdata_t
));
180 afdata_t
*afp
= (afdata_t
*)arg
;
184 ap
= mdb_alloc(sizeof (ipp_action_t
), UM_SLEEP
);
185 if (mdb_vread(ap
, sizeof (ipp_action_t
), addr
) == -1) {
186 mdb_warn("failed to read ipp_action_t at %p", addr
);
191 if (afp
->af_flags
& AF_VERBOSE
)
192 rc
= action_dump(addr
, ap
, afp
->af_banner
);
194 rc
= action_summary(addr
, ap
, afp
->af_banner
);
196 afp
->af_banner
= B_FALSE
;
198 mdb_free(ap
, sizeof (ipp_action_t
));
209 mdb_printf("%?p: %20s = %d\n", addr
, "id", ap
->ippa_id
);
210 if (!ap
->ippa_nameless
) {
211 mdb_printf("%?s %20s = %s\n", "", "name", ap
->ippa_name
);
213 mdb_printf("%?s %20s = 0x%p\n", "", "mod", ap
->ippa_mod
);
214 mdb_printf("%?s %20s = 0x%p\n", "", "ref", ap
->ippa_ref
);
215 mdb_printf("%?s %20s = 0x%p\n", "", "refby", ap
->ippa_refby
);
216 mdb_printf("%?s %20s = 0x%p\n", "", "ptr", ap
->ippa_ptr
);
218 mdb_printf("%?s %20s = ", "", "state");
219 switch (ap
->ippa_state
) {
220 case IPP_ASTATE_PROTO
:
221 mdb_printf("%s\n", "PROTO");
223 case IPP_ASTATE_CONFIG_PENDING
:
224 mdb_printf("%s\n", "CONFIG_PENDING");
226 case IPP_ASTATE_AVAILABLE
:
227 mdb_printf("%s\n", "AVAILABLE");
230 mdb_printf("%s\n", "<unknown>");
234 mdb_printf("%?s %20s = %d\n", "", "packets", ap
->ippa_packets
);
235 mdb_printf("%?s %20s = %d\n", "", "hold_count", ap
->ippa_hold_count
);
236 mdb_printf("%?s %20s = %s\n", "", "destruct_pending",
237 (ap
->ippa_destruct_pending
) ? "TRUE" : "FALSE");
238 mdb_printf("%?s %20s = 0x%p\n", "", "lock",
239 addr
+ ((uintptr_t)ap
->ippa_lock
- (uintptr_t)ap
));
240 mdb_printf("%?s %20s = 0x%p\n", "", "config_lock",
241 addr
+ ((uintptr_t)ap
->ippa_config_lock
- (uintptr_t)ap
));
257 mdb_printf("%?s %<u>%20s %5s %20s%</u>\n",
258 "", "NAME", "ID", "MODNAME");
260 imp
= mdb_alloc(sizeof (ipp_mod_t
), UM_SLEEP
);
261 ptr
= (uintptr_t)ap
->ippa_mod
;
262 if (mdb_vread(imp
, sizeof (ipp_mod_t
), ptr
) == -1) {
263 mdb_warn("failed to read ipp_mod_t at %p", ptr
);
264 mdb_free(imp
, sizeof (ipp_mod_t
));
268 mdb_printf("%?p:%20s %5d %20s\n", addr
, ap
->ippa_name
, ap
->ippa_id
,
271 mdb_free(imp
, sizeof (ipp_mod_t
));
281 const mdb_arg_t
*argv
)
285 if ((flags
& DCMD_ADDRSPEC
) == 0)
288 clp
= mdb_alloc(sizeof (cfglock_t
), UM_SLEEP
);
289 if (mdb_vread(clp
, sizeof (cfglock_t
), addr
) == -1) {
290 mdb_warn("failed to read cfglock_t at %p", addr
);
291 mdb_free(clp
, sizeof (cfglock_t
));
295 mdb_printf("%?p: %20s = %p\n", addr
, "owner", clp
->cl_owner
);
296 mdb_printf("%?s %20s = %s\n", "", "reader",
297 clp
->cl_reader
? "TRUE" : "FALSE");
298 mdb_printf("%?s %20s = %d\n", "", "writers", clp
->cl_writers
);
299 mdb_printf("%?s %20s = 0x%p\n", "", "mutex",
300 addr
+ ((uintptr_t)clp
->cl_mutex
- (uintptr_t)clp
));
301 mdb_printf("%?s %20s = 0x%p\n", "", "cv",
302 addr
+ ((uintptr_t)clp
->cl_cv
- (uintptr_t)clp
));
305 mdb_free(clp
, sizeof (cfglock_t
));
316 const mdb_arg_t
*argv
)
322 mfp
= mdb_zalloc(sizeof (mfdata_t
), UM_SLEEP
);
324 if (mdb_getopts(argc
, argv
,
325 'v', MDB_OPT_SETBITS
, MF_VERBOSE
, &mfp
->mf_flags
,
329 if ((flags
& DCMD_LOOPFIRST
) || !(flags
& DCMD_LOOP
))
330 mfp
->mf_banner
= B_TRUE
;
332 if (flags
& DCMD_ADDRSPEC
) {
333 status
= mod_format(addr
, NULL
, mfp
);
334 rc
= (status
== WALK_NEXT
) ? DCMD_OK
: DCMD_ERR
;
338 if (mdb_pwalk("ipp_byid", mod_format
, mfp
,
339 ipp_mod_byid
) == -1) {
340 mdb_warn("failed to execute ipp_byid walk");
345 mdb_free(mfp
, sizeof (mfdata_t
));
357 mfdata_t
*mfp
= (mfdata_t
*)arg
;
361 imp
= mdb_alloc(sizeof (ipp_mod_t
), UM_SLEEP
);
362 if (mdb_vread(imp
, sizeof (ipp_mod_t
), addr
) == -1) {
363 mdb_warn("failed to read ipp_mod_t at %p", addr
);
368 if (mfp
->mf_flags
& MF_VERBOSE
)
369 rc
= mod_dump(addr
, imp
, mfp
->mf_banner
);
371 rc
= mod_summary(addr
, imp
, mfp
->mf_banner
);
373 mfp
->mf_banner
= B_FALSE
;
375 mdb_free(imp
, sizeof (ipp_mod_t
));
386 mdb_printf("%?p: %20s = %d\n", addr
, "id", imp
->ippm_id
);
387 mdb_printf("%?s %20s = %s\n", "", "name", imp
->ippm_name
);
388 mdb_printf("%?s %20s = 0x%p\n", "", "ops", imp
->ippm_ops
);
389 mdb_printf("%?s %20s = 0x%p\n", "", "action", imp
->ippm_action
);
391 mdb_printf("%?s %20s = ", "", "state");
392 switch (imp
->ippm_state
) {
393 case IPP_MODSTATE_PROTO
:
394 mdb_printf("%s\n", "PROTO");
396 case IPP_MODSTATE_AVAILABLE
:
397 mdb_printf("%s\n", "AVAILABLE");
400 mdb_printf("%s\n", "<unknown>");
404 mdb_printf("%?s %20s = %d\n", "", "hold_count", imp
->ippm_hold_count
);
405 mdb_printf("%?s %20s = %s\n", "", "destruct_pending",
406 (imp
->ippm_destruct_pending
) ? "TRUE" : "FALSE");
407 mdb_printf("%?s %20s = 0x%p\n", "", "lock",
408 addr
+ ((uintptr_t)imp
->ippm_lock
- (uintptr_t)imp
));
421 mdb_printf("%?s %<u>%20s %5s%</u>\n",
424 mdb_printf("%?p:%20s %5d\n", addr
, imp
->ippm_name
, imp
->ippm_id
);
435 const mdb_arg_t
*argv
)
439 char buf
[MDB_SYM_NAMLEN
];
441 if ((flags
& DCMD_ADDRSPEC
) == 0)
444 ippo
= mdb_alloc(sizeof (ipp_ops_t
), UM_SLEEP
);
445 if (mdb_vread(ippo
, sizeof (ipp_ops_t
), addr
) == -1) {
446 mdb_warn("failed to read ipp_ops_t at %p", addr
);
447 mdb_free(ippo
, sizeof (ipp_ops_t
));
451 mdb_printf("%?p: %20s = %d\n", addr
, "rev", ippo
->ippo_rev
);
453 if (mdb_lookup_by_addr((uintptr_t)ippo
->ippo_action_create
,
454 MDB_SYM_EXACT
, buf
, MDB_SYM_NAMLEN
, &sym
) == 0)
455 mdb_printf("%?s %20s = %s\n", "", "action_create", buf
);
457 mdb_printf("%?s %20s = 0x%p\n", "", "action_create",
458 ippo
->ippo_action_create
);
460 if (mdb_lookup_by_addr((uintptr_t)ippo
->ippo_action_modify
,
461 MDB_SYM_EXACT
, buf
, MDB_SYM_NAMLEN
, &sym
) == 0)
462 mdb_printf("%?s %20s = %s\n", "", "action_modify", buf
);
464 mdb_printf("%?s %20s = 0x%p\n", "", "action_modify",
465 ippo
->ippo_action_modify
);
467 if (mdb_lookup_by_addr((uintptr_t)ippo
->ippo_action_destroy
,
468 MDB_SYM_EXACT
, buf
, MDB_SYM_NAMLEN
, &sym
) == 0)
469 mdb_printf("%?s %20s = %s\n", "", "action_destroy", buf
);
471 mdb_printf("%?s %20s = 0x%p\n", "", "action_destroy",
472 ippo
->ippo_action_destroy
);
474 if (mdb_lookup_by_addr((uintptr_t)ippo
->ippo_action_info
,
475 MDB_SYM_EXACT
, buf
, MDB_SYM_NAMLEN
, &sym
) == 0)
476 mdb_printf("%?s %20s = %s\n", "", "action_info", buf
);
478 mdb_printf("%?s %20s = 0x%p\n", "", "action_info",
479 ippo
->ippo_action_info
);
481 if (mdb_lookup_by_addr((uintptr_t)ippo
->ippo_action_invoke
,
482 MDB_SYM_EXACT
, buf
, MDB_SYM_NAMLEN
, &sym
) == 0)
483 mdb_printf("%?s %20s = %s\n", "", "action_invoke", buf
);
485 mdb_printf("%?s %20s = 0x%p\n", "", "action_invoke",
486 ippo
->ippo_action_invoke
);
490 mdb_free(ippo
, sizeof (ipp_ops_t
));
496 mdb_walk_state_t
*wsp
)
498 if (wsp
->walk_addr
== NULL
)
506 mdb_walk_state_t
*wsp
)
511 if (wsp
->walk_addr
== NULL
)
514 rp
= mdb_alloc(sizeof (ipp_ref_t
), UM_SLEEP
);
516 if (mdb_vread(rp
, sizeof (ipp_ref_t
), wsp
->walk_addr
) == -1) {
517 mdb_warn("failed to read ipp_ref_t at %p", wsp
->walk_addr
);
518 mdb_free(rp
, sizeof (ipp_ref_t
));
522 status
= wsp
->walk_callback((uintptr_t)rp
->ippr_ptr
, NULL
,
525 wsp
->walk_addr
= (uintptr_t)(rp
->ippr_nextp
);
527 mdb_free(rp
, sizeof (ipp_ref_t
));
534 mdb_walk_state_t
*wsp
)
544 const mdb_arg_t
*argv
)
548 if ((flags
& DCMD_ADDRSPEC
) == 0)
551 pp
= mdb_alloc(sizeof (ipp_packet_t
), UM_SLEEP
);
552 if (mdb_vread(pp
, sizeof (ipp_packet_t
), addr
) == -1) {
553 mdb_warn("failed to read ipp_packet_t at %p", addr
);
554 mdb_free(pp
, sizeof (ipp_packet_t
));
558 mdb_printf("%?p: %20s = 0x%p\n", addr
, "data", pp
->ippp_data
);
559 mdb_printf("%?s %20s = 0x%p\n", "", "private", pp
->ippp_private
);
560 dump_classes((uintptr_t)pp
->ippp_class_array
, pp
->ippp_class_windex
);
561 dump_log((uintptr_t)pp
->ippp_log
, pp
->ippp_log_windex
);
563 mdb_free(pp
, sizeof (ipp_packet_t
));
575 boolean_t first_time
= B_TRUE
;
576 char buf
[MAXNAMELEN
];
578 array
= mdb_alloc(sizeof (ipp_class_t
) * nelt
, UM_SLEEP
);
579 if (mdb_vread(array
, sizeof (ipp_class_t
) * nelt
, ptr
) == -1) {
580 mdb_warn("failed to read ipp_class_t array at %p", ptr
);
584 for (i
= 0; i
< nelt
; i
++) {
586 mdb_printf("%20s %?s %<u>%15s %15s%</u>\n", "",
587 "classes", "NAME", "ACTION");
588 first_time
= B_FALSE
;
592 aid2aname(cp
->ippc_aid
, buf
);
593 mdb_printf("%20s %?p: %15s %15s%\n", "",
594 ptr
+ (i
* sizeof (ipp_class_t
)), cp
->ippc_name
, buf
);
597 mdb_free(cp
, sizeof (ipp_class_t
) * nelt
);
608 boolean_t first_time
= B_TRUE
;
609 char buf
[MAXNAMELEN
];
611 array
= mdb_alloc(sizeof (ipp_log_t
) * nelt
, UM_SLEEP
);
612 if (mdb_vread(array
, sizeof (ipp_log_t
) * nelt
, ptr
) == -1) {
613 mdb_warn("failed to read ipp_log_t array at %p", ptr
);
617 for (i
= 0; i
< nelt
; i
++) {
619 mdb_printf("%20s %?s %<u>%15s %15s%</u>\n", "",
620 "log", "CLASS NAME", "ACTION");
621 first_time
= B_FALSE
;
625 aid2aname(lp
->ippl_aid
, buf
);
626 mdb_printf("%20s %?p: %15s %15s\n", "",
627 ptr
+ (i
* sizeof (ipp_class_t
)), lp
->ippl_name
, buf
);
630 mdb_free(lp
, sizeof (ipp_log_t
) * nelt
);
643 case IPP_ACTION_INVAL
:
644 strcpy(buf
, "invalid");
646 case IPP_ACTION_CONT
:
647 strcpy(buf
, "continue");
649 case IPP_ACTION_DEFER
:
650 strcpy(buf
, "defer");
652 case IPP_ACTION_DROP
:
656 if (mdb_vread(&addr
, sizeof (uintptr_t),
657 ipp_action_byid
) == -1) {
658 mdb_warn("failed to read from address %p",
664 addr
+= ((int32_t)aid
* sizeof (void *));
665 if (mdb_vread(&ptr
, sizeof (uintptr_t), addr
) == -1) {
666 mdb_warn("failed to read from address %p", addr
);
671 ap
= mdb_alloc(sizeof (ipp_action_t
), UM_SLEEP
);
672 if (mdb_vread(ap
, sizeof (ipp_action_t
), ptr
) == -1) {
673 mdb_warn("failed to read ipp_action_t at %p", ptr
);
674 mdb_free(ap
, sizeof (ipp_action_t
));
679 if (ap
->ippa_id
!= aid
) {
680 mdb_warn("corrupt action at %p", ptr
);
681 mdb_free(ap
, sizeof (ipp_action_t
));
686 strcpy(buf
, ap
->ippa_name
);
690 static const mdb_dcmd_t dcmds
[] = {
691 { "ipp_action", "?[-v]",
692 "display ipp_action structure", action
},
693 { "ipp_mod", "?[-v]",
694 "display ipp_mod structure", mod
},
696 "display cfglock structure", cfglock
},
698 "display ipp_ops structure", ippops
},
700 "display ipp_packet structure", packet
},
704 static const mdb_walker_t walkers
[] = {
705 { "ipp_byid", "walk byid array", byid_walk_init
, byid_walk_step
,
707 { "ipp_ref", "walk reference list", ref_walk_init
, ref_walk_step
,
712 static const mdb_modinfo_t ipp_modinfo
= { MDB_API_VERSION
, dcmds
, walkers
};
714 const mdb_modinfo_t
*
719 if (mdb_lookup_by_name("ipp_action_byid", &sym
) == -1) {
720 mdb_warn("failed to lookup 'ipp_action_byid'");
724 ipp_action_byid
= (uintptr_t)sym
.st_value
;
726 if (mdb_lookup_by_name("ipp_mod_byid", &sym
) == -1) {
727 mdb_warn("failed to lookup 'ipp_mod_byid'");
731 ipp_mod_byid
= (uintptr_t)sym
.st_value
;
733 return (&ipp_modinfo
);