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.
29 #include <ipp/ipp_impl.h>
30 #include <mdb/mdb_modapi.h>
32 static uintptr_t ipp_mod_byid
;
33 static uintptr_t ipp_action_byid
;
35 static int byid_walk_init(mdb_walk_state_t
*);
36 static int byid_walk_step(mdb_walk_state_t
*);
37 static void byid_walk_fini(mdb_walk_state_t
*);
39 static int action(uintptr_t, uint_t
, int, const mdb_arg_t
*);
40 static int action_format(uintptr_t, const void *, void *);
41 static int action_dump(uintptr_t, ipp_action_t
*, boolean_t
);
42 static int action_summary(uintptr_t, ipp_action_t
*, boolean_t
);
44 static int cfglock(uintptr_t, uint_t
, int, const mdb_arg_t
*);
46 static int mod(uintptr_t, uint_t
, int, const mdb_arg_t
*);
47 static int mod_format(uintptr_t, const void *, void *);
48 static int mod_dump(uintptr_t, ipp_mod_t
*, boolean_t
);
49 static int mod_summary(uintptr_t, ipp_mod_t
*, boolean_t
);
50 static int cfglock(uintptr_t, uint_t
, int, const mdb_arg_t
*);
52 static int ippops(uintptr_t, uint_t
, int, const mdb_arg_t
*);
54 static int packet(uintptr_t, uint_t
, int, const mdb_arg_t
*);
55 static void dump_classes(uintptr_t, uint_t
);
56 static void dump_log(uintptr_t, uint_t
);
57 static void aid2aname(ipp_action_id_t
, char *);
59 static int ref_walk_init(mdb_walk_state_t
*);
60 static int ref_walk_step(mdb_walk_state_t
*);
61 static void ref_walk_fini(mdb_walk_state_t
*);
63 typedef struct afdata
{
70 typedef struct mfdata
{
78 * walker. Skips entries that are NULL.
83 mdb_walk_state_t
*wsp
)
87 if (mdb_vread(&start
, sizeof (uintptr_t), wsp
->walk_addr
) == -1) {
88 mdb_warn("failed to read from address %p", wsp
->walk_addr
);
92 wsp
->walk_addr
= start
;
99 mdb_walk_state_t
*wsp
)
104 if (mdb_vread(&ptr
, sizeof (void *), wsp
->walk_addr
) == -1) {
105 mdb_warn("failed to read from address %p", wsp
->walk_addr
);
109 if (ptr
== (void *)-1) {
111 } else if (ptr
== NULL
) {
114 status
= wsp
->walk_callback((uintptr_t)ptr
, NULL
,
118 wsp
->walk_addr
+= sizeof (void *);
126 mdb_walk_state_t
*wsp
)
137 const mdb_arg_t
*argv
)
143 afp
= mdb_zalloc(sizeof (afdata_t
), UM_SLEEP
);
145 if (mdb_getopts(argc
, argv
,
146 'v', MDB_OPT_SETBITS
, AF_VERBOSE
, &afp
->af_flags
,
150 if ((flags
& DCMD_LOOPFIRST
) || !(flags
& DCMD_LOOP
))
151 afp
->af_banner
= B_TRUE
;
153 if (flags
& DCMD_ADDRSPEC
) {
154 status
= action_format(addr
, NULL
, afp
);
155 rc
= (status
== WALK_NEXT
) ? DCMD_OK
: DCMD_ERR
;
159 if (mdb_pwalk("ipp_byid", action_format
, afp
,
160 ipp_action_byid
) == -1) {
161 mdb_warn("failed to execute ipp_byid walk");
166 mdb_free(afp
, sizeof (afdata_t
));
178 afdata_t
*afp
= (afdata_t
*)arg
;
182 ap
= mdb_alloc(sizeof (ipp_action_t
), UM_SLEEP
);
183 if (mdb_vread(ap
, sizeof (ipp_action_t
), addr
) == -1) {
184 mdb_warn("failed to read ipp_action_t at %p", addr
);
189 if (afp
->af_flags
& AF_VERBOSE
)
190 rc
= action_dump(addr
, ap
, afp
->af_banner
);
192 rc
= action_summary(addr
, ap
, afp
->af_banner
);
194 afp
->af_banner
= B_FALSE
;
196 mdb_free(ap
, sizeof (ipp_action_t
));
207 mdb_printf("%?p: %20s = %d\n", addr
, "id", ap
->ippa_id
);
208 if (!ap
->ippa_nameless
) {
209 mdb_printf("%?s %20s = %s\n", "", "name", ap
->ippa_name
);
211 mdb_printf("%?s %20s = 0x%p\n", "", "mod", ap
->ippa_mod
);
212 mdb_printf("%?s %20s = 0x%p\n", "", "ref", ap
->ippa_ref
);
213 mdb_printf("%?s %20s = 0x%p\n", "", "refby", ap
->ippa_refby
);
214 mdb_printf("%?s %20s = 0x%p\n", "", "ptr", ap
->ippa_ptr
);
216 mdb_printf("%?s %20s = ", "", "state");
217 switch (ap
->ippa_state
) {
218 case IPP_ASTATE_PROTO
:
219 mdb_printf("%s\n", "PROTO");
221 case IPP_ASTATE_CONFIG_PENDING
:
222 mdb_printf("%s\n", "CONFIG_PENDING");
224 case IPP_ASTATE_AVAILABLE
:
225 mdb_printf("%s\n", "AVAILABLE");
228 mdb_printf("%s\n", "<unknown>");
232 mdb_printf("%?s %20s = %d\n", "", "packets", ap
->ippa_packets
);
233 mdb_printf("%?s %20s = %d\n", "", "hold_count", ap
->ippa_hold_count
);
234 mdb_printf("%?s %20s = %s\n", "", "destruct_pending",
235 (ap
->ippa_destruct_pending
) ? "TRUE" : "FALSE");
236 mdb_printf("%?s %20s = 0x%p\n", "", "lock",
237 addr
+ ((uintptr_t)ap
->ippa_lock
- (uintptr_t)ap
));
238 mdb_printf("%?s %20s = 0x%p\n", "", "config_lock",
239 addr
+ ((uintptr_t)ap
->ippa_config_lock
- (uintptr_t)ap
));
255 mdb_printf("%?s %<u>%20s %5s %20s%</u>\n",
256 "", "NAME", "ID", "MODNAME");
258 imp
= mdb_alloc(sizeof (ipp_mod_t
), UM_SLEEP
);
259 ptr
= (uintptr_t)ap
->ippa_mod
;
260 if (mdb_vread(imp
, sizeof (ipp_mod_t
), ptr
) == -1) {
261 mdb_warn("failed to read ipp_mod_t at %p", ptr
);
262 mdb_free(imp
, sizeof (ipp_mod_t
));
266 mdb_printf("%?p:%20s %5d %20s\n", addr
, ap
->ippa_name
, ap
->ippa_id
,
269 mdb_free(imp
, sizeof (ipp_mod_t
));
279 const mdb_arg_t
*argv
)
283 if ((flags
& DCMD_ADDRSPEC
) == 0)
286 clp
= mdb_alloc(sizeof (cfglock_t
), UM_SLEEP
);
287 if (mdb_vread(clp
, sizeof (cfglock_t
), addr
) == -1) {
288 mdb_warn("failed to read cfglock_t at %p", addr
);
289 mdb_free(clp
, sizeof (cfglock_t
));
293 mdb_printf("%?p: %20s = %p\n", addr
, "owner", clp
->cl_owner
);
294 mdb_printf("%?s %20s = %s\n", "", "reader",
295 clp
->cl_reader
? "TRUE" : "FALSE");
296 mdb_printf("%?s %20s = %d\n", "", "writers", clp
->cl_writers
);
297 mdb_printf("%?s %20s = 0x%p\n", "", "mutex",
298 addr
+ ((uintptr_t)clp
->cl_mutex
- (uintptr_t)clp
));
299 mdb_printf("%?s %20s = 0x%p\n", "", "cv",
300 addr
+ ((uintptr_t)clp
->cl_cv
- (uintptr_t)clp
));
303 mdb_free(clp
, sizeof (cfglock_t
));
314 const mdb_arg_t
*argv
)
320 mfp
= mdb_zalloc(sizeof (mfdata_t
), UM_SLEEP
);
322 if (mdb_getopts(argc
, argv
,
323 'v', MDB_OPT_SETBITS
, MF_VERBOSE
, &mfp
->mf_flags
,
327 if ((flags
& DCMD_LOOPFIRST
) || !(flags
& DCMD_LOOP
))
328 mfp
->mf_banner
= B_TRUE
;
330 if (flags
& DCMD_ADDRSPEC
) {
331 status
= mod_format(addr
, NULL
, mfp
);
332 rc
= (status
== WALK_NEXT
) ? DCMD_OK
: DCMD_ERR
;
336 if (mdb_pwalk("ipp_byid", mod_format
, mfp
,
337 ipp_mod_byid
) == -1) {
338 mdb_warn("failed to execute ipp_byid walk");
343 mdb_free(mfp
, sizeof (mfdata_t
));
355 mfdata_t
*mfp
= (mfdata_t
*)arg
;
359 imp
= mdb_alloc(sizeof (ipp_mod_t
), UM_SLEEP
);
360 if (mdb_vread(imp
, sizeof (ipp_mod_t
), addr
) == -1) {
361 mdb_warn("failed to read ipp_mod_t at %p", addr
);
366 if (mfp
->mf_flags
& MF_VERBOSE
)
367 rc
= mod_dump(addr
, imp
, mfp
->mf_banner
);
369 rc
= mod_summary(addr
, imp
, mfp
->mf_banner
);
371 mfp
->mf_banner
= B_FALSE
;
373 mdb_free(imp
, sizeof (ipp_mod_t
));
384 mdb_printf("%?p: %20s = %d\n", addr
, "id", imp
->ippm_id
);
385 mdb_printf("%?s %20s = %s\n", "", "name", imp
->ippm_name
);
386 mdb_printf("%?s %20s = 0x%p\n", "", "ops", imp
->ippm_ops
);
387 mdb_printf("%?s %20s = 0x%p\n", "", "action", imp
->ippm_action
);
389 mdb_printf("%?s %20s = ", "", "state");
390 switch (imp
->ippm_state
) {
391 case IPP_MODSTATE_PROTO
:
392 mdb_printf("%s\n", "PROTO");
394 case IPP_MODSTATE_AVAILABLE
:
395 mdb_printf("%s\n", "AVAILABLE");
398 mdb_printf("%s\n", "<unknown>");
402 mdb_printf("%?s %20s = %d\n", "", "hold_count", imp
->ippm_hold_count
);
403 mdb_printf("%?s %20s = %s\n", "", "destruct_pending",
404 (imp
->ippm_destruct_pending
) ? "TRUE" : "FALSE");
405 mdb_printf("%?s %20s = 0x%p\n", "", "lock",
406 addr
+ ((uintptr_t)imp
->ippm_lock
- (uintptr_t)imp
));
419 mdb_printf("%?s %<u>%20s %5s%</u>\n",
422 mdb_printf("%?p:%20s %5d\n", addr
, imp
->ippm_name
, imp
->ippm_id
);
433 const mdb_arg_t
*argv
)
437 char buf
[MDB_SYM_NAMLEN
];
439 if ((flags
& DCMD_ADDRSPEC
) == 0)
442 ippo
= mdb_alloc(sizeof (ipp_ops_t
), UM_SLEEP
);
443 if (mdb_vread(ippo
, sizeof (ipp_ops_t
), addr
) == -1) {
444 mdb_warn("failed to read ipp_ops_t at %p", addr
);
445 mdb_free(ippo
, sizeof (ipp_ops_t
));
449 mdb_printf("%?p: %20s = %d\n", addr
, "rev", ippo
->ippo_rev
);
451 if (mdb_lookup_by_addr((uintptr_t)ippo
->ippo_action_create
,
452 MDB_SYM_EXACT
, buf
, MDB_SYM_NAMLEN
, &sym
) == 0)
453 mdb_printf("%?s %20s = %s\n", "", "action_create", buf
);
455 mdb_printf("%?s %20s = 0x%p\n", "", "action_create",
456 ippo
->ippo_action_create
);
458 if (mdb_lookup_by_addr((uintptr_t)ippo
->ippo_action_modify
,
459 MDB_SYM_EXACT
, buf
, MDB_SYM_NAMLEN
, &sym
) == 0)
460 mdb_printf("%?s %20s = %s\n", "", "action_modify", buf
);
462 mdb_printf("%?s %20s = 0x%p\n", "", "action_modify",
463 ippo
->ippo_action_modify
);
465 if (mdb_lookup_by_addr((uintptr_t)ippo
->ippo_action_destroy
,
466 MDB_SYM_EXACT
, buf
, MDB_SYM_NAMLEN
, &sym
) == 0)
467 mdb_printf("%?s %20s = %s\n", "", "action_destroy", buf
);
469 mdb_printf("%?s %20s = 0x%p\n", "", "action_destroy",
470 ippo
->ippo_action_destroy
);
472 if (mdb_lookup_by_addr((uintptr_t)ippo
->ippo_action_info
,
473 MDB_SYM_EXACT
, buf
, MDB_SYM_NAMLEN
, &sym
) == 0)
474 mdb_printf("%?s %20s = %s\n", "", "action_info", buf
);
476 mdb_printf("%?s %20s = 0x%p\n", "", "action_info",
477 ippo
->ippo_action_info
);
479 if (mdb_lookup_by_addr((uintptr_t)ippo
->ippo_action_invoke
,
480 MDB_SYM_EXACT
, buf
, MDB_SYM_NAMLEN
, &sym
) == 0)
481 mdb_printf("%?s %20s = %s\n", "", "action_invoke", buf
);
483 mdb_printf("%?s %20s = 0x%p\n", "", "action_invoke",
484 ippo
->ippo_action_invoke
);
488 mdb_free(ippo
, sizeof (ipp_ops_t
));
494 mdb_walk_state_t
*wsp
)
496 if (wsp
->walk_addr
== (uintptr_t)NULL
)
504 mdb_walk_state_t
*wsp
)
509 if (wsp
->walk_addr
== (uintptr_t)NULL
)
512 rp
= mdb_alloc(sizeof (ipp_ref_t
), UM_SLEEP
);
514 if (mdb_vread(rp
, sizeof (ipp_ref_t
), wsp
->walk_addr
) == -1) {
515 mdb_warn("failed to read ipp_ref_t at %p", wsp
->walk_addr
);
516 mdb_free(rp
, sizeof (ipp_ref_t
));
520 status
= wsp
->walk_callback((uintptr_t)rp
->ippr_ptr
, NULL
,
523 wsp
->walk_addr
= (uintptr_t)(rp
->ippr_nextp
);
525 mdb_free(rp
, sizeof (ipp_ref_t
));
532 mdb_walk_state_t
*wsp
)
542 const mdb_arg_t
*argv
)
546 if ((flags
& DCMD_ADDRSPEC
) == 0)
549 pp
= mdb_alloc(sizeof (ipp_packet_t
), UM_SLEEP
);
550 if (mdb_vread(pp
, sizeof (ipp_packet_t
), addr
) == -1) {
551 mdb_warn("failed to read ipp_packet_t at %p", addr
);
552 mdb_free(pp
, sizeof (ipp_packet_t
));
556 mdb_printf("%?p: %20s = 0x%p\n", addr
, "data", pp
->ippp_data
);
557 mdb_printf("%?s %20s = 0x%p\n", "", "private", pp
->ippp_private
);
558 dump_classes((uintptr_t)pp
->ippp_class_array
, pp
->ippp_class_windex
);
559 dump_log((uintptr_t)pp
->ippp_log
, pp
->ippp_log_windex
);
561 mdb_free(pp
, sizeof (ipp_packet_t
));
573 boolean_t first_time
= B_TRUE
;
574 char buf
[MAXNAMELEN
];
576 array
= mdb_alloc(sizeof (ipp_class_t
) * nelt
, UM_SLEEP
);
577 if (mdb_vread(array
, sizeof (ipp_class_t
) * nelt
, ptr
) == -1) {
578 mdb_warn("failed to read ipp_class_t array at %p", ptr
);
582 for (i
= 0; i
< nelt
; i
++) {
584 mdb_printf("%20s %?s %<u>%15s %15s%</u>\n", "",
585 "classes", "NAME", "ACTION");
586 first_time
= B_FALSE
;
590 aid2aname(cp
->ippc_aid
, buf
);
591 mdb_printf("%20s %?p: %15s %15s%\n", "",
592 ptr
+ (i
* sizeof (ipp_class_t
)), cp
->ippc_name
, buf
);
595 mdb_free(cp
, sizeof (ipp_class_t
) * nelt
);
606 boolean_t first_time
= B_TRUE
;
607 char buf
[MAXNAMELEN
];
609 array
= mdb_alloc(sizeof (ipp_log_t
) * nelt
, UM_SLEEP
);
610 if (mdb_vread(array
, sizeof (ipp_log_t
) * nelt
, ptr
) == -1) {
611 mdb_warn("failed to read ipp_log_t array at %p", ptr
);
615 for (i
= 0; i
< nelt
; i
++) {
617 mdb_printf("%20s %?s %<u>%15s %15s%</u>\n", "",
618 "log", "CLASS NAME", "ACTION");
619 first_time
= B_FALSE
;
623 aid2aname(lp
->ippl_aid
, buf
);
624 mdb_printf("%20s %?p: %15s %15s\n", "",
625 ptr
+ (i
* sizeof (ipp_class_t
)), lp
->ippl_name
, buf
);
628 mdb_free(lp
, sizeof (ipp_log_t
) * nelt
);
641 case IPP_ACTION_INVAL
:
642 strcpy(buf
, "invalid");
644 case IPP_ACTION_CONT
:
645 strcpy(buf
, "continue");
647 case IPP_ACTION_DEFER
:
648 strcpy(buf
, "defer");
650 case IPP_ACTION_DROP
:
654 if (mdb_vread(&addr
, sizeof (uintptr_t),
655 ipp_action_byid
) == -1) {
656 mdb_warn("failed to read from address %p",
662 addr
+= ((int32_t)aid
* sizeof (void *));
663 if (mdb_vread(&ptr
, sizeof (uintptr_t), addr
) == -1) {
664 mdb_warn("failed to read from address %p", addr
);
669 ap
= mdb_alloc(sizeof (ipp_action_t
), UM_SLEEP
);
670 if (mdb_vread(ap
, sizeof (ipp_action_t
), ptr
) == -1) {
671 mdb_warn("failed to read ipp_action_t at %p", ptr
);
672 mdb_free(ap
, sizeof (ipp_action_t
));
677 if (ap
->ippa_id
!= aid
) {
678 mdb_warn("corrupt action at %p", ptr
);
679 mdb_free(ap
, sizeof (ipp_action_t
));
684 strcpy(buf
, ap
->ippa_name
);
688 static const mdb_dcmd_t dcmds
[] = {
689 { "ipp_action", "?[-v]",
690 "display ipp_action structure", action
},
691 { "ipp_mod", "?[-v]",
692 "display ipp_mod structure", mod
},
694 "display cfglock structure", cfglock
},
696 "display ipp_ops structure", ippops
},
698 "display ipp_packet structure", packet
},
702 static const mdb_walker_t walkers
[] = {
703 { "ipp_byid", "walk byid array", byid_walk_init
, byid_walk_step
,
705 { "ipp_ref", "walk reference list", ref_walk_init
, ref_walk_step
,
710 static const mdb_modinfo_t ipp_modinfo
= { MDB_API_VERSION
, dcmds
, walkers
};
712 const mdb_modinfo_t
*
717 if (mdb_lookup_by_name("ipp_action_byid", &sym
) == -1) {
718 mdb_warn("failed to lookup 'ipp_action_byid'");
722 ipp_action_byid
= (uintptr_t)sym
.st_value
;
724 if (mdb_lookup_by_name("ipp_mod_byid", &sym
) == -1) {
725 mdb_warn("failed to lookup 'ipp_mod_byid'");
729 ipp_mod_byid
= (uintptr_t)sym
.st_value
;
731 return (&ipp_modinfo
);