17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate #include <mdb/mdb_modapi.h>
287c478bd9Sstevel@tonic-gate #include <sys/types.h>
297c478bd9Sstevel@tonic-gate #include <sys/contract_impl.h>
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate int
ct_walk_init(mdb_walk_state_t * wsp)327c478bd9Sstevel@tonic-gate ct_walk_init(mdb_walk_state_t *wsp)
337c478bd9Sstevel@tonic-gate {
34*892ad162SToomas Soome if (wsp->walk_addr != 0) {
357c478bd9Sstevel@tonic-gate wsp->walk_addr = wsp->walk_addr +
367c478bd9Sstevel@tonic-gate OFFSETOF(ct_type_t, ct_type_avl);
377c478bd9Sstevel@tonic-gate } else {
387c478bd9Sstevel@tonic-gate GElf_Sym sym;
397c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("contract_avl", &sym)) {
407c478bd9Sstevel@tonic-gate mdb_warn("failed to read contract_avl");
417c478bd9Sstevel@tonic-gate return (WALK_ERR);
427c478bd9Sstevel@tonic-gate }
437c478bd9Sstevel@tonic-gate wsp->walk_addr = sym.st_value;
447c478bd9Sstevel@tonic-gate }
457c478bd9Sstevel@tonic-gate
467c478bd9Sstevel@tonic-gate if (mdb_layered_walk("avl", wsp) == -1)
477c478bd9Sstevel@tonic-gate return (WALK_ERR);
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate return (WALK_NEXT);
507c478bd9Sstevel@tonic-gate }
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate int
ct_event_walk_init(mdb_walk_state_t * wsp)537c478bd9Sstevel@tonic-gate ct_event_walk_init(mdb_walk_state_t *wsp)
547c478bd9Sstevel@tonic-gate {
55*892ad162SToomas Soome if (wsp->walk_addr == 0) {
567c478bd9Sstevel@tonic-gate mdb_warn("ct_event walker requires ct_equeue address\n");
577c478bd9Sstevel@tonic-gate return (WALK_ERR);
587c478bd9Sstevel@tonic-gate }
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate wsp->walk_addr = wsp->walk_addr +
617c478bd9Sstevel@tonic-gate OFFSETOF(ct_equeue_t, ctq_events);
627c478bd9Sstevel@tonic-gate
637c478bd9Sstevel@tonic-gate if (mdb_layered_walk("list", wsp) == -1)
647c478bd9Sstevel@tonic-gate return (WALK_ERR);
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gate return (WALK_NEXT);
677c478bd9Sstevel@tonic-gate }
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate int
ct_listener_walk_init(mdb_walk_state_t * wsp)707c478bd9Sstevel@tonic-gate ct_listener_walk_init(mdb_walk_state_t *wsp)
717c478bd9Sstevel@tonic-gate {
72*892ad162SToomas Soome if (wsp->walk_addr == 0) {
737c478bd9Sstevel@tonic-gate mdb_warn("ct_listener walker requires ct_equeue address\n");
747c478bd9Sstevel@tonic-gate return (WALK_ERR);
757c478bd9Sstevel@tonic-gate }
767c478bd9Sstevel@tonic-gate
777c478bd9Sstevel@tonic-gate wsp->walk_addr = wsp->walk_addr +
787c478bd9Sstevel@tonic-gate OFFSETOF(ct_equeue_t, ctq_listeners);
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate if (mdb_layered_walk("list", wsp) == -1)
817c478bd9Sstevel@tonic-gate return (WALK_ERR);
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gate return (WALK_NEXT);
847c478bd9Sstevel@tonic-gate }
857c478bd9Sstevel@tonic-gate
867c478bd9Sstevel@tonic-gate
877c478bd9Sstevel@tonic-gate /* ARGSUSED */
887c478bd9Sstevel@tonic-gate int
cmd_contract(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)897c478bd9Sstevel@tonic-gate cmd_contract(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
907c478bd9Sstevel@tonic-gate {
917c478bd9Sstevel@tonic-gate contract_t ct;
927c478bd9Sstevel@tonic-gate ct_type_t ctt;
937c478bd9Sstevel@tonic-gate char str[32];
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) {
967c478bd9Sstevel@tonic-gate if (mdb_walk_dcmd("contract", "contract", argc, argv) == -1) {
977c478bd9Sstevel@tonic-gate mdb_warn("can't walk 'contract'");
987c478bd9Sstevel@tonic-gate return (DCMD_ERR);
997c478bd9Sstevel@tonic-gate }
1007c478bd9Sstevel@tonic-gate return (DCMD_OK);
1017c478bd9Sstevel@tonic-gate }
1027c478bd9Sstevel@tonic-gate
1037c478bd9Sstevel@tonic-gate if (DCMD_HDRSPEC(flags))
1047c478bd9Sstevel@tonic-gate mdb_printf("%<u>%?s %8s %8s %8s %?s %?s%</u>\n",
1057c478bd9Sstevel@tonic-gate "ADDR", "ID", "TYPE", "STATE", "OWNER", "REGENT");
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate if (mdb_vread(&ct, sizeof (ct), addr) != sizeof (ct)) {
1087c478bd9Sstevel@tonic-gate mdb_warn("error reading contract_t at %p", addr);
1097c478bd9Sstevel@tonic-gate return (DCMD_ERR);
1107c478bd9Sstevel@tonic-gate }
1117c478bd9Sstevel@tonic-gate if (mdb_vread(&ctt, sizeof (ctt), (uintptr_t)ct.ct_type) !=
1127c478bd9Sstevel@tonic-gate sizeof (ctt)) {
1137c478bd9Sstevel@tonic-gate mdb_warn("error reading ct_type_t at %p", ct.ct_type);
1147c478bd9Sstevel@tonic-gate return (DCMD_ERR);
1157c478bd9Sstevel@tonic-gate }
1167c478bd9Sstevel@tonic-gate if (mdb_readstr(str, sizeof (str), (uintptr_t)ctt.ct_type_name) == -1) {
1177c478bd9Sstevel@tonic-gate mdb_warn("error reading contract type name at %p",
1187c478bd9Sstevel@tonic-gate ctt.ct_type_name);
1197c478bd9Sstevel@tonic-gate return (DCMD_ERR);
1207c478bd9Sstevel@tonic-gate }
1217c478bd9Sstevel@tonic-gate
1227c478bd9Sstevel@tonic-gate mdb_printf("%0?p %8d %8s %8s %?p %?p\n", addr, ct.ct_id, str,
1237c478bd9Sstevel@tonic-gate (ct.ct_state == CTS_OWNED) ? "owned" :
1247c478bd9Sstevel@tonic-gate (ct.ct_state == CTS_INHERITED) ? "inherit" :
1257c478bd9Sstevel@tonic-gate (ct.ct_state == CTS_ORPHAN) ? "orphan" : "dead",
1267c478bd9Sstevel@tonic-gate ct.ct_owner, ct.ct_regent);
1277c478bd9Sstevel@tonic-gate
1287c478bd9Sstevel@tonic-gate return (DCMD_OK);
1297c478bd9Sstevel@tonic-gate }
1307c478bd9Sstevel@tonic-gate
1317c478bd9Sstevel@tonic-gate const mdb_bitmask_t ct_event_flags[] = {
1327c478bd9Sstevel@tonic-gate { "ACK", CTE_ACK, CTE_ACK },
1337c478bd9Sstevel@tonic-gate { "INFO", CTE_INFO, CTE_INFO },
1347c478bd9Sstevel@tonic-gate { "NEG", CTE_NEG, CTE_NEG },
1357c478bd9Sstevel@tonic-gate { NULL }
1367c478bd9Sstevel@tonic-gate };
1377c478bd9Sstevel@tonic-gate
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate /* ARGSUSED */
1407c478bd9Sstevel@tonic-gate int
cmd_ctevent(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)1417c478bd9Sstevel@tonic-gate cmd_ctevent(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1427c478bd9Sstevel@tonic-gate {
1437c478bd9Sstevel@tonic-gate ct_kevent_t cte;
1447c478bd9Sstevel@tonic-gate
1457c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC))
1467c478bd9Sstevel@tonic-gate return (DCMD_USAGE);
1477c478bd9Sstevel@tonic-gate
1487c478bd9Sstevel@tonic-gate if (DCMD_HDRSPEC(flags))
1497c478bd9Sstevel@tonic-gate mdb_printf("%<u>%12s %8s %12s %6s %12s %12s %s%</u>\n",
1507c478bd9Sstevel@tonic-gate "ADDR", "ID", "CONTRACT", "TYPE", "DATA", "GDATA", "FLAGS");
1517c478bd9Sstevel@tonic-gate
1527c478bd9Sstevel@tonic-gate if (mdb_vread(&cte, sizeof (cte), addr) != sizeof (cte)) {
1537c478bd9Sstevel@tonic-gate mdb_warn("error reading ct_kevent_t at %p", addr);
1547c478bd9Sstevel@tonic-gate return (DCMD_ERR);
1557c478bd9Sstevel@tonic-gate }
1567c478bd9Sstevel@tonic-gate
1577c478bd9Sstevel@tonic-gate mdb_printf("%12p %8llu %12p %6d %12p %12p %b\n", addr, cte.cte_id,
1587c478bd9Sstevel@tonic-gate cte.cte_contract, cte.cte_type, cte.cte_data, cte.cte_gdata,
1597c478bd9Sstevel@tonic-gate cte.cte_flags, ct_event_flags);
1607c478bd9Sstevel@tonic-gate
1617c478bd9Sstevel@tonic-gate return (DCMD_OK);
1627c478bd9Sstevel@tonic-gate }
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gate typedef struct findct_data {
1657c478bd9Sstevel@tonic-gate uintptr_t fc_ctid;
1667c478bd9Sstevel@tonic-gate uintptr_t fc_addr;
1677c478bd9Sstevel@tonic-gate boolean_t fc_found;
1687c478bd9Sstevel@tonic-gate } findct_data_t;
1697c478bd9Sstevel@tonic-gate
1707c478bd9Sstevel@tonic-gate static int
findct(uintptr_t addr,contract_t * ct,findct_data_t * arg)1717c478bd9Sstevel@tonic-gate findct(uintptr_t addr, contract_t *ct, findct_data_t *arg)
1727c478bd9Sstevel@tonic-gate {
1737c478bd9Sstevel@tonic-gate if (ct->ct_id == arg->fc_ctid) {
1747c478bd9Sstevel@tonic-gate arg->fc_found = B_TRUE;
1757c478bd9Sstevel@tonic-gate arg->fc_addr = addr;
1767c478bd9Sstevel@tonic-gate return (WALK_DONE);
1777c478bd9Sstevel@tonic-gate }
1787c478bd9Sstevel@tonic-gate
1797c478bd9Sstevel@tonic-gate return (WALK_NEXT);
1807c478bd9Sstevel@tonic-gate }
1817c478bd9Sstevel@tonic-gate
1827c478bd9Sstevel@tonic-gate /* ARGSUSED */
1837c478bd9Sstevel@tonic-gate int
cmd_ctid(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)1847c478bd9Sstevel@tonic-gate cmd_ctid(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1857c478bd9Sstevel@tonic-gate {
1867c478bd9Sstevel@tonic-gate findct_data_t fcdata;
1877c478bd9Sstevel@tonic-gate
1887c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC))
1897c478bd9Sstevel@tonic-gate return (DCMD_USAGE);
1907c478bd9Sstevel@tonic-gate
1917c478bd9Sstevel@tonic-gate fcdata.fc_ctid = addr;
1927c478bd9Sstevel@tonic-gate fcdata.fc_found = B_FALSE;
1937c478bd9Sstevel@tonic-gate if (mdb_walk("contract", (mdb_walk_cb_t)findct, &fcdata) == -1 ||
1947c478bd9Sstevel@tonic-gate !fcdata.fc_found)
1957c478bd9Sstevel@tonic-gate return (DCMD_ERR);
1967c478bd9Sstevel@tonic-gate
1977c478bd9Sstevel@tonic-gate mdb_printf("%lr", fcdata.fc_addr);
1987c478bd9Sstevel@tonic-gate
1997c478bd9Sstevel@tonic-gate return (DCMD_OK);
2007c478bd9Sstevel@tonic-gate }
201