xref: /titanic_50/usr/src/cmd/mdb/common/kmdb/kmdb_conf.c (revision 8b464eb836173b92f2b7a65623cd06c8c3c59289)
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 <sys/isa_defs.h>
30 #include <sys/utsname.h>
31 #include <strings.h>
32 
33 #include <kmdb/kmdb_dpi.h>
34 #include <kmdb/kmdb_kdi.h>
35 #include <mdb/mdb_err.h>
36 #include <mdb/mdb.h>
37 
38 static const char _mdb_version[] = KMDB_VERSION;
39 
40 const char *
41 mdb_conf_version(void)
42 {
43 	return (_mdb_version);
44 }
45 
46 const char *
47 mdb_conf_isa(void)
48 {
49 #if defined(__sparc)
50 #if defined(__sparcv9)
51 	return ("sparcv9");
52 #else	/* __sparcv9 */
53 	return ("sparc");
54 #endif	/* __sparcv9 */
55 #elif defined(__amd64)
56 	return ("amd64");
57 #elif defined(__i386)
58 	return ("i386");
59 #else
60 #error	"unknown ISA"
61 #endif
62 }
63 
64 /*
65  * These functions are needed for path evaluation, and must be run prior to
66  * target initialization.  The kmdb symbol resolution machinery hasn't been
67  * initialized at this point, so we have to rely on the kernel to look up
68  * utsname and platform for us.
69  */
70 
71 void
72 mdb_conf_uname(struct utsname *utsp)
73 {
74 	bzero(utsp, sizeof (struct utsname));
75 
76 	if (kmdb_dpi_get_state(NULL) == DPI_STATE_INIT) {
77 		struct utsname *utsaddr;
78 
79 		/*
80 		 * The kernel is running during DPI initialization, so we'll ask
81 		 * it to do the lookup.  Our own symbol resolution facilities
82 		 * won't be available until after the debugger starts.
83 		 */
84 		if ((utsaddr = (struct utsname *)kmdb_kdi_lookup_by_name("unix",
85 		    "utsname")) == NULL) {
86 			warn("'utsname' symbol is missing from kernel\n");
87 			strcpy(utsp->sysname, "unknown");
88 			return;
89 		}
90 
91 		bcopy(utsaddr, utsp, sizeof (struct utsname));
92 	} else
93 		(void) mdb_tgt_uname(mdb.m_target, utsp);
94 }
95 
96 const char *
97 mdb_conf_platform(void)
98 {
99 	if (kmdb_dpi_get_state(NULL) == DPI_STATE_INIT) {
100 		static char plat[SYS_NMLN];
101 		caddr_t plataddr;
102 
103 		/*
104 		 * The kernel is running during DPI initialization, so we'll ask
105 		 * it to do the lookup.  Our own symbol resolution facilities
106 		 * won't be available until after the debugger starts.
107 		 */
108 		if ((plataddr = (caddr_t)kmdb_kdi_lookup_by_name("unix",
109 		    "platform")) == NULL) {
110 			warn("conf: 'platform' symbol is missing from "
111 			    "kernel\n");
112 			return ("unknown");
113 		}
114 
115 		strncpy(plat, plataddr, sizeof (plat));
116 		plat[sizeof (plat) - 1] = '\0';
117 
118 		return (plat);
119 	} else
120 		return (mdb_tgt_platform(mdb.m_target));
121 }
122