xref: /titanic_50/usr/src/cmd/mdb/common/modules/genunix/log.c (revision 726fad2a65f16c200a03969c29cb5c86c2d427db)
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 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <mdb/mdb_modapi.h>
30 #include <sys/types.h>
31 #include <sys/stream.h>
32 #include <sys/strlog.h>
33 
34 int
35 msgbuf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
36 {
37 	queue_t q;
38 	uintptr_t qp;
39 	mblk_t next;
40 	mblk_t cont;
41 	log_ctl_t lctl;
42 	char line[1024];
43 	uint_t verbose = FALSE;
44 
45 	if (!(flags & DCMD_ADDRSPEC)) {
46 		if (mdb_readsym(&qp, sizeof (qp), "log_recentq") == -1) {
47 			mdb_warn("failed to read log_recent");
48 			return (DCMD_ERR);
49 		}
50 
51 		if (mdb_vread(&q, sizeof (q), qp) == -1) {
52 			mdb_warn("failed to read queue_t at %p", qp);
53 			return (DCMD_ERR);
54 		}
55 
56 		if (mdb_pwalk_dcmd("b_next", "msgbuf", argc, argv,
57 		    (uintptr_t)q.q_first) == -1) {
58 			mdb_warn("can't walk 'b_next'");
59 			return (DCMD_ERR);
60 		}
61 		return (DCMD_OK);
62 	}
63 
64 	if (mdb_getopts(argc, argv,
65 	    'v', MDB_OPT_SETBITS, TRUE, &verbose, NULL) != argc)
66 		return (DCMD_USAGE);
67 
68 	if (DCMD_HDRSPEC(flags)) {
69 		if (verbose)
70 			mdb_printf("%<u>%20s %?s %-40s%</u>\n",
71 			    "TIMESTAMP", "LOGCTL", "MESSAGE");
72 		else
73 			mdb_printf("%<u>%-70s%</u>\n", "MESSAGE");
74 	}
75 
76 	if (mdb_vread(&next, sizeof (next), addr) == -1) {
77 		mdb_warn("failed to read msgb structure at %p", addr);
78 		return (DCMD_ERR);
79 	}
80 
81 	if (mdb_vread(&lctl, sizeof (lctl), (uintptr_t)next.b_rptr) == -1) {
82 		mdb_warn("failed to read log_ctl_t at %p", next.b_rptr);
83 		return (DCMD_ERR);
84 	}
85 
86 	if (mdb_vread(&cont, sizeof (cont), (uintptr_t)next.b_cont) == -1) {
87 		mdb_warn("failed to read msgb structure at %p", next.b_cont);
88 		return (DCMD_ERR);
89 	}
90 
91 	if (mdb_readstr(line, sizeof (line), (uintptr_t)cont.b_rptr) == -1) {
92 		mdb_warn("failed to read string at %p", cont.b_rptr);
93 		return (DCMD_ERR);
94 	}
95 
96 	if (verbose)
97 		mdb_printf("%Y %?p ", lctl.ttime,  next.b_rptr);
98 
99 	/* skip leading CR to avoid extra lines */
100 	if (line[0] == 0x0d)
101 		mdb_printf("%s", &line[1]);
102 	else
103 		mdb_printf("%s", &line[0]);
104 
105 	return (DCMD_OK);
106 }
107