8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / mdb / common / modules / libsysevent / libsysevent.c
blob73e8bcbec88aa497e76ecbe5a6824c5fa7357914
1 /*
2 * CDDL HEADER START
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
7 * with the License.
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]
20 * CDDL HEADER END
23 * Copyright 2002-2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <sys/sysevent.h>
30 #include <sys/sysevent_impl.h>
31 #include <libsysevent.h>
32 #include <libsysevent_impl.h>
33 #include "../genunix/sysevent.h"
35 int
36 sysevent(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
38 if ((flags & DCMD_ADDRSPEC) == 0)
39 return (DCMD_USAGE);
41 if ((flags & DCMD_LOOP) == 0) {
42 if (mdb_pwalk_dcmd("sysevent", "sysevent", argc, argv,
43 addr) == -1) {
44 mdb_warn("can't walk sysevent queue");
45 return (DCMD_ERR);
47 return (DCMD_OK);
50 return (sysevent_buf(addr, flags, 0));
53 /*ARGSUSED*/
54 int
55 sysevent_handle(uintptr_t addr, uint_t flags, int argc,
56 const mdb_arg_t *argv)
58 ssize_t channel_name_sz;
59 char channel_name[CLASS_LIST_FIELD_MAX];
60 subscriber_priv_t sub;
61 sysevent_impl_hdl_t sysevent_hdl;
63 if ((flags & DCMD_ADDRSPEC) == 0)
64 return (DCMD_USAGE);
67 if (argc != 0)
68 return (DCMD_USAGE);
71 if (mdb_vread(&sysevent_hdl, sizeof (sysevent_hdl),
72 (uintptr_t)addr) == -1) {
73 mdb_warn("failed to read sysevent handle at %p", addr);
74 return (DCMD_ERR);
76 if ((channel_name_sz = mdb_readstr(channel_name, CLASS_LIST_FIELD_MAX,
77 (uintptr_t)sysevent_hdl.sh_channel_name)) == -1) {
78 mdb_warn("failed to read channel name at %p",
79 sysevent_hdl.sh_channel_name);
80 return (DCMD_ERR);
82 if (channel_name_sz >= CLASS_LIST_FIELD_MAX - 1)
83 (void) strcpy(&channel_name[CLASS_LIST_FIELD_MAX - 4], "...");
85 if (sysevent_hdl.sh_type == SUBSCRIBER) {
86 if (mdb_vread(&sub, sizeof (sub),
87 (uintptr_t)sysevent_hdl.sh_priv_data) == -1) {
88 mdb_warn("failed to read sysevent handle at %p", addr);
89 return (DCMD_ERR);
92 if (DCMD_HDRSPEC(flags))
93 mdb_printf("%<u>%-?s %-24s %-13s %-5s %-?s"
94 "%</u>\n", "ADDR", "NAME", "TYPE", "ID",
95 "EVENT QUEUE ADDR");
97 mdb_printf("%-?p %-24s %-13s %-5lu %-?p\n",
98 addr, channel_name, "SUBSCRIBER", sysevent_hdl.sh_id,
99 (uintptr_t)sub.sp_evq_head);
101 } else {
102 if (DCMD_HDRSPEC(flags))
103 mdb_printf("%<u>%-?s %-24s %-13s %-5s %-?s"
104 "%</u>\n", "ADDR", "NAME",
105 "TYPE", "ID", "CLASS LIST ADDR");
107 mdb_printf("%-?p %-24s %-13s %-5lu %-?p\n",
108 addr, channel_name, "PUBLISHER", sysevent_hdl.sh_id,
109 (uintptr_t)sysevent_hdl.sh_priv_data +
110 offsetof(publisher_priv_t, pp_class_hash));
113 return (DCMD_OK);
116 static const mdb_dcmd_t dcmds[] = {
117 { "sysevent", "?[-v]", "print the contents of a sysevent queue",
118 sysevent},
119 { "sysevent_handle", ":", "print sysevent subscriber/publisher handle",
120 sysevent_handle},
121 { "sysevent_class_list", ":", "print sysevent class list",
122 sysevent_class_list },
123 { "sysevent_subclass_list", ":", "print sysevent subclass list",
124 sysevent_subclass_list },
125 { NULL }
129 sysevent_walk_init(mdb_walk_state_t *wsp)
131 if (wsp->walk_addr == NULL) {
132 mdb_warn("sysevent does not support global walks");
133 return (WALK_ERR);
136 return (WALK_NEXT);
140 sysevent_walk_step(mdb_walk_state_t *wsp)
142 int status;
143 sysevent_queue_t se_q;
145 if (wsp->walk_addr == NULL)
146 return (WALK_DONE);
148 if (mdb_vread(&se_q, sizeof (se_q), wsp->walk_addr) == -1) {
149 mdb_warn("failed to read sysevent queue at %p", wsp->walk_addr);
150 return (WALK_ERR);
153 status = wsp->walk_callback((uintptr_t)se_q.sq_ev, NULL,
154 wsp->walk_cbdata);
156 wsp->walk_addr = (uintptr_t)se_q.sq_next;
158 return (status);
161 static const mdb_walker_t walkers[] = {
162 { "sysevent", "walk sysevent buffer queue",
163 sysevent_walk_init, sysevent_walk_step,
164 NULL },
165 { "sysevent_class_list", "walk sysevent subsccription class list",
166 sysevent_class_list_walk_init, sysevent_class_list_walk_step,
167 sysevent_class_list_walk_fini },
168 { "sysevent_subclass_list", "walk sysevent subsccription subclass list",
169 sysevent_subclass_list_walk_init,
170 sysevent_subclass_list_walk_step, NULL },
171 { NULL }
174 static const mdb_modinfo_t modinfo = {
175 MDB_API_VERSION, dcmds, walkers
178 const mdb_modinfo_t *
179 _mdb_init(void)
181 return (&modinfo);