xref: /titanic_51/usr/src/cmd/mdb/common/kmdb/kmdb_conf.c (revision cbdcbd056f15c9c9fd82d5543b3a502677c4d391)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #include <sys/isa_defs.h>
27 #include <sys/utsname.h>
28 #include <strings.h>
29 
30 #include <kmdb/kmdb_dpi.h>
31 #include <kmdb/kmdb_kdi.h>
32 #include <mdb/mdb_err.h>
33 #include <mdb/mdb.h>
34 
35 static const char _mdb_version[] = KMDB_VERSION;
36 
37 const char *
38 mdb_conf_version(void)
39 {
40 	return (_mdb_version);
41 }
42 
43 const char *
44 mdb_conf_isa(void)
45 {
46 #if defined(__sparc)
47 #if defined(__sparcv9)
48 	return ("sparcv9");
49 #else	/* __sparcv9 */
50 	return ("sparc");
51 #endif	/* __sparcv9 */
52 #elif defined(__amd64)
53 	return ("amd64");
54 #elif defined(__i386)
55 	return ("i386");
56 #else
57 #error	"unknown ISA"
58 #endif
59 }
60 
61 /*
62  * These functions are needed for path evaluation, and must be run prior to
63  * target initialization.  The kmdb symbol resolution machinery hasn't been
64  * initialized at this point, so we have to rely on the kernel to look up
65  * utsname and platform for us.
66  */
67 
68 void
69 mdb_conf_uname(struct utsname *utsp)
70 {
71 	bzero(utsp, sizeof (struct utsname));
72 
73 	if (kmdb_dpi_get_state(NULL) == DPI_STATE_INIT) {
74 		struct utsname *utsaddr;
75 
76 		/*
77 		 * The kernel is running during DPI initialization, so we'll ask
78 		 * it to do the lookup.  Our own symbol resolution facilities
79 		 * won't be available until after the debugger starts.
80 		 */
81 		if ((utsaddr = (struct utsname *)kmdb_kdi_lookup_by_name("unix",
82 		    "utsname")) == NULL) {
83 			warn("'utsname' symbol is missing from kernel\n");
84 			(void) strcpy(utsp->sysname, "unknown");
85 			return;
86 		}
87 
88 		bcopy(utsaddr, utsp, sizeof (struct utsname));
89 	} else
90 		(void) mdb_tgt_uname(mdb.m_target, utsp);
91 }
92 
93 const char *
94 mdb_conf_platform(void)
95 {
96 	if (kmdb_dpi_get_state(NULL) == DPI_STATE_INIT) {
97 		static char plat[SYS_NMLN];
98 		caddr_t plataddr;
99 
100 		/*
101 		 * The kernel is running during DPI initialization, so we'll ask
102 		 * it to do the lookup.  Our own symbol resolution facilities
103 		 * won't be available until after the debugger starts.
104 		 */
105 		if ((plataddr = (caddr_t)kmdb_kdi_lookup_by_name("unix",
106 		    "platform")) == NULL) {
107 			warn("conf: 'platform' symbol is missing from "
108 			    "kernel\n");
109 			return ("unknown");
110 		}
111 
112 		(void) strncpy(plat, plataddr, sizeof (plat));
113 		plat[sizeof (plat) - 1] = '\0';
114 
115 		return (plat);
116 	} else
117 		return (mdb_tgt_platform(mdb.m_target));
118 }
119