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