Mercurial > illumos > onarm
annotate usr/src/cmd/mdb/common/modules/genunix/contract.c @ 4:1a15d5aaf794
synchronized with onnv_86 (6202) in onnv-gate
author | Koji Uno <koji.uno@sun.com> |
---|---|
date | Mon, 31 Aug 2009 14:38:03 +0900 |
parents | c9caec207d52 |
children |
rev | line source |
---|---|
0 | 1 /* |
2 * CDDL HEADER START | |
3 * | |
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. | |
8 * | |
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. | |
13 * | |
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] | |
19 * | |
20 * CDDL HEADER END | |
21 */ | |
22 /* | |
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. | |
24 * Use is subject to license terms. | |
25 */ | |
26 | |
4
1a15d5aaf794
synchronized with onnv_86 (6202) in onnv-gate
Koji Uno <koji.uno@sun.com>
parents:
0
diff
changeset
|
27 #pragma ident "%Z%%M% %I% %E% SMI" |
0 | 28 |
29 #include <mdb/mdb_modapi.h> | |
30 #include <sys/types.h> | |
31 #include <sys/contract_impl.h> | |
32 | |
33 int | |
34 ct_walk_init(mdb_walk_state_t *wsp) | |
35 { | |
36 if (wsp->walk_addr != NULL) { | |
37 wsp->walk_addr = wsp->walk_addr + | |
38 OFFSETOF(ct_type_t, ct_type_avl); | |
39 } else { | |
40 GElf_Sym sym; | |
41 if (mdb_lookup_by_name("contract_avl", &sym)) { | |
42 mdb_warn("failed to read contract_avl"); | |
43 return (WALK_ERR); | |
44 } | |
45 wsp->walk_addr = sym.st_value; | |
46 } | |
47 | |
48 if (mdb_layered_walk("avl", wsp) == -1) | |
49 return (WALK_ERR); | |
50 | |
51 return (WALK_NEXT); | |
52 } | |
53 | |
54 int | |
55 ct_event_walk_init(mdb_walk_state_t *wsp) | |
56 { | |
57 if (wsp->walk_addr == NULL) { | |
58 mdb_warn("ct_event walker requires ct_equeue address\n"); | |
59 return (WALK_ERR); | |
60 } | |
61 | |
62 wsp->walk_addr = wsp->walk_addr + | |
63 OFFSETOF(ct_equeue_t, ctq_events); | |
64 | |
65 if (mdb_layered_walk("list", wsp) == -1) | |
66 return (WALK_ERR); | |
67 | |
68 return (WALK_NEXT); | |
69 } | |
70 | |
71 int | |
72 ct_listener_walk_init(mdb_walk_state_t *wsp) | |
73 { | |
74 if (wsp->walk_addr == NULL) { | |
75 mdb_warn("ct_listener walker requires ct_equeue address\n"); | |
76 return (WALK_ERR); | |
77 } | |
78 | |
79 wsp->walk_addr = wsp->walk_addr + | |
80 OFFSETOF(ct_equeue_t, ctq_listeners); | |
81 | |
82 if (mdb_layered_walk("list", wsp) == -1) | |
83 return (WALK_ERR); | |
84 | |
85 return (WALK_NEXT); | |
86 } | |
87 | |
88 | |
89 /* ARGSUSED */ | |
90 int | |
91 cmd_contract(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) | |
92 { | |
93 contract_t ct; | |
94 ct_type_t ctt; | |
95 char str[32]; | |
96 | |
97 if (!(flags & DCMD_ADDRSPEC)) { | |
98 if (mdb_walk_dcmd("contract", "contract", argc, argv) == -1) { | |
99 mdb_warn("can't walk 'contract'"); | |
100 return (DCMD_ERR); | |
101 } | |
102 return (DCMD_OK); | |
103 } | |
104 | |
105 if (DCMD_HDRSPEC(flags)) | |
106 mdb_printf("%<u>%?s %8s %8s %8s %?s %?s%</u>\n", | |
107 "ADDR", "ID", "TYPE", "STATE", "OWNER", "REGENT"); | |
108 | |
109 if (mdb_vread(&ct, sizeof (ct), addr) != sizeof (ct)) { | |
110 mdb_warn("error reading contract_t at %p", addr); | |
111 return (DCMD_ERR); | |
112 } | |
113 if (mdb_vread(&ctt, sizeof (ctt), (uintptr_t)ct.ct_type) != | |
114 sizeof (ctt)) { | |
115 mdb_warn("error reading ct_type_t at %p", ct.ct_type); | |
116 return (DCMD_ERR); | |
117 } | |
118 if (mdb_readstr(str, sizeof (str), (uintptr_t)ctt.ct_type_name) == -1) { | |
119 mdb_warn("error reading contract type name at %p", | |
120 ctt.ct_type_name); | |
121 return (DCMD_ERR); | |
122 } | |
123 | |
124 mdb_printf("%0?p %8d %8s %8s %?p %?p\n", addr, ct.ct_id, str, | |
125 (ct.ct_state == CTS_OWNED) ? "owned" : | |
126 (ct.ct_state == CTS_INHERITED) ? "inherit" : | |
127 (ct.ct_state == CTS_ORPHAN) ? "orphan" : "dead", | |
128 ct.ct_owner, ct.ct_regent); | |
129 | |
130 return (DCMD_OK); | |
131 } | |
132 | |
133 const mdb_bitmask_t ct_event_flags[] = { | |
134 { "ACK", CTE_ACK, CTE_ACK }, | |
135 { "INFO", CTE_INFO, CTE_INFO }, | |
136 { "NEG", CTE_NEG, CTE_NEG }, | |
137 { NULL } | |
138 }; | |
139 | |
140 | |
141 /* ARGSUSED */ | |
142 int | |
143 cmd_ctevent(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) | |
144 { | |
145 ct_kevent_t cte; | |
146 | |
147 if (!(flags & DCMD_ADDRSPEC)) | |
148 return (DCMD_USAGE); | |
149 | |
150 if (DCMD_HDRSPEC(flags)) | |
151 mdb_printf("%<u>%12s %8s %12s %6s %12s %12s %s%</u>\n", | |
152 "ADDR", "ID", "CONTRACT", "TYPE", "DATA", "GDATA", "FLAGS"); | |
153 | |
154 if (mdb_vread(&cte, sizeof (cte), addr) != sizeof (cte)) { | |
155 mdb_warn("error reading ct_kevent_t at %p", addr); | |
156 return (DCMD_ERR); | |
157 } | |
158 | |
159 mdb_printf("%12p %8llu %12p %6d %12p %12p %b\n", addr, cte.cte_id, | |
160 cte.cte_contract, cte.cte_type, cte.cte_data, cte.cte_gdata, | |
161 cte.cte_flags, ct_event_flags); | |
162 | |
163 return (DCMD_OK); | |
164 } | |
165 | |
166 typedef struct findct_data { | |
167 uintptr_t fc_ctid; | |
168 uintptr_t fc_addr; | |
169 boolean_t fc_found; | |
170 } findct_data_t; | |
171 | |
172 static int | |
173 findct(uintptr_t addr, contract_t *ct, findct_data_t *arg) | |
174 { | |
175 if (ct->ct_id == arg->fc_ctid) { | |
176 arg->fc_found = B_TRUE; | |
177 arg->fc_addr = addr; | |
178 return (WALK_DONE); | |
179 } | |
180 | |
181 return (WALK_NEXT); | |
182 } | |
183 | |
184 /* ARGSUSED */ | |
185 int | |
186 cmd_ctid(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) | |
187 { | |
188 findct_data_t fcdata; | |
189 | |
190 if (!(flags & DCMD_ADDRSPEC)) | |
191 return (DCMD_USAGE); | |
192 | |
193 fcdata.fc_ctid = addr; | |
194 fcdata.fc_found = B_FALSE; | |
195 if (mdb_walk("contract", (mdb_walk_cb_t)findct, &fcdata) == -1 || | |
196 !fcdata.fc_found) | |
197 return (DCMD_ERR); | |
198 | |
199 mdb_printf("%lr", fcdata.fc_addr); | |
200 | |
201 return (DCMD_OK); | |
202 } |