7081442 Xorg mdb modules can't load
authorAlan Coopersmith <Alan.Coopersmith@Oracle.COM>
Sun, 21 Aug 2011 23:17:36 -0700
changeset 1192 60e4ec16e28d
parent 1191 6ab513e20948
child 1193 81e7bcbed056
7081442 Xorg mdb modules can't load
open-src/xserver/xorg/Makefile
open-src/xserver/xorg/sun-src/os/solaris/mdb/README
open-src/xserver/xorg/sun-src/os/solaris/mdb/modules/Makefile
open-src/xserver/xorg/sun-src/os/solaris/mdb/modules/Xserver_clients.c
open-src/xserver/xorg/sun-src/os/solaris/mdb/modules/Xserver_device_grabs.c
open-src/xserver/xorg/sun-src/os/solaris/mdb/modules/Xserver_mdb.h
open-src/xserver/xorg/sun-src/os/solaris/mdb/modules/mapfile
--- a/open-src/xserver/xorg/Makefile	Mon Aug 15 15:09:02 2011 -0700
+++ b/open-src/xserver/xorg/Makefile	Sun Aug 21 23:17:36 2011 -0700
@@ -309,6 +309,7 @@
 # Since configure options aren't used to build the mdb modules, pass
 # those variables at build time
 MDB_BUILD_ENV=$(CONFIG_ENV) $(BUILD_ENV)
+MDB_BUILD_ENV += CFLAGS="$(LIB_CFLAGS)" LDFLAGS="$(LIB_LDFLAGS)"
 
 build_mdb: $(BUILT_MDB_MODULE)
 
--- a/open-src/xserver/xorg/sun-src/os/solaris/mdb/README	Mon Aug 15 15:09:02 2011 -0700
+++ b/open-src/xserver/xorg/sun-src/os/solaris/mdb/README	Sun Aug 21 23:17:36 2011 -0700
@@ -182,13 +182,14 @@
 front, it will automatically call the associated walker to list the
 information for all the entries in the list.
 
-For more information about using mdb, see the Modular Debugger Guide manual
-on http://docs.sun.com/ and the mdb OpenSolaris Community website at
+For more information about using mdb, see the Solaris Modular Debugger Guide
+on http://www.oracle.com/technetwork/indexes/documentation/index.html and 
+the mdb OpenSolaris Community website at
 http://hub.opensolaris.org/bin/view/Community+Group+mdb/
 
 =============================================================================
 
-Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
 
 Permission is hereby granted, free of charge, to any person obtaining a
 copy of this software and associated documentation files (the "Software"),
--- a/open-src/xserver/xorg/sun-src/os/solaris/mdb/modules/Makefile	Mon Aug 15 15:09:02 2011 -0700
+++ b/open-src/xserver/xorg/sun-src/os/solaris/mdb/modules/Makefile	Sun Aug 21 23:17:36 2011 -0700
@@ -1,4 +1,5 @@
-# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+#
+# Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
 #
 # Permission is hereby granted, free of charge, to any person obtaining a
 # copy of this software and associated documentation files (the "Software"),
@@ -25,7 +26,7 @@
 
 CFLAGS += -K pic -g
 CPPFLAGS += -I ../../../../include -I ../../../.. -I ../../../../Xext
-LDFLAGS += -Wl,-z,text
+LDFLAGS += -Wl,-z,text -M mapfile
 
 HEADERS = Xserver_mdb.h
 SOURCES = Xserver_clients.c Xserver_device_grabs.c mdb_module.c
--- a/open-src/xserver/xorg/sun-src/os/solaris/mdb/modules/Xserver_clients.c	Mon Aug 15 15:09:02 2011 -0700
+++ b/open-src/xserver/xorg/sun-src/os/solaris/mdb/modules/Xserver_clients.c	Sun Aug 21 23:17:36 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -23,13 +23,13 @@
 
 
 #include <sys/mdb_modapi.h>
+#include "Xserver_mdb.h"
 
 #include "xorg-server.h"
 #include "dixstruct.h"
 #include "misc.h"
 #include "os/osdep.h"
 #include "IA/interactive_srv.h"
-#include "Xserver_mdb.h"
 
 struct client_walk_data {
     uintptr_t client_next;
@@ -37,11 +37,15 @@
     ClientRec client_data;
 };
 
-/* Copied from dix/privates.c in Xorg 1.6 */
-struct _Private {
-    int state;
-    pointer value;
-};
+/* Just here to satisfy linkage from inlines in privates.h
+   Should never ever be called from the module. */
+_X_HIDDEN DevPrivateKey
+_dixGetScreenPrivateKey(const DevScreenPrivateKey key, ScreenPtr pScreen)
+{
+    abort();
+    return NULL; /* compiler whines about not returning a value after abort() */
+}
+
 
 /*
  * Initialize the client walker by either using the given starting address,
@@ -145,112 +149,124 @@
     uintptr_t clientP;
     ClientRec client_data;
 
-	if (argc != 0)
-		return (DCMD_USAGE);
+    if (argc != 0)
+	return (DCMD_USAGE);
 
-	/*
-	 * If no client address was specified on the command line, we can
-	 * print out all clients by invoking the walker, using this
-	 * dcmd itself as the callback.
-	 */
-	if (!(flags & DCMD_ADDRSPEC)) {
-		if (mdb_walk_dcmd("client_walk", "client_pids",
-		    argc, argv) == -1) {
-			mdb_warn("failed to walk 'client_walk'");
-			return (DCMD_ERR);
-		}
-		return (DCMD_OK);
+    /*
+     * If no client address was specified on the command line, we can
+     * print out all clients by invoking the walker, using this
+     * dcmd itself as the callback.
+     */
+    if (!(flags & DCMD_ADDRSPEC)) {
+	if (mdb_walk_dcmd("client_walk", "client_pids",
+			  argc, argv) == -1) {
+	    mdb_warn("failed to walk 'client_walk'");
+	    return (DCMD_ERR);
 	}
+	return (DCMD_OK);
+    }
 
-	/*
-	 * If this is the first invocation of the command, print a nice
-	 * header line for the output that will follow.
-	 */
-	if (DCMD_HDRSPEC(flags))
-		mdb_printf("CLIENT SEQUENCE #  FD  PIDS\n");
+    /*
+     * If this is the first invocation of the command, print a nice
+     * header line for the output that will follow.
+     */
+    if (DCMD_HDRSPEC(flags))
+	mdb_printf("CLIENT SEQUENCE #  FD  PIDS\n");
 
 
-	if (mdb_vread(&clientP, sizeof (clientP), addr) == sizeof (clientP)) {
+    if (mdb_vread(&clientP, sizeof (clientP), addr) != sizeof (clientP)) {
+	mdb_warn("failed to read ClientPtr at %p", addr);
+    } else {
+	if (mdb_vread(&client_data, sizeof (client_data), clientP)
+	    != sizeof (client_data)) {
+	    mdb_warn("failed to read ClientRec at %p", clientP);
+	} else {
+	    mdb_printf("%5d  %10d", client_data.index, client_data.sequence);
 
-	    if (mdb_vread(&client_data, sizeof (client_data), clientP) == sizeof (client_data)) {
-		mdb_printf("%5d  %10d", client_data.index, client_data.sequence);
+	    if (client_data.osPrivate == NULL) {
+		mdb_printf(" ??? - NULL ClientPtr->osPrivate\n");
+	    } else {
+		OsCommRec oscomm;
 
-		if (client_data.osPrivate != NULL) {
-		    OsCommRec oscomm;
+		if (mdb_vread(&oscomm, sizeof (oscomm),
+			      (uintptr_t)client_data.osPrivate)
+		    != sizeof (oscomm)) {
+		    mdb_warn("failed to read struct OsCommRec at %p",
+			     client_data.osPrivate);
+		} else {
+		    ClientProcessPtr cpp = NULL;
 
-		    if (mdb_vread(&oscomm, sizeof (oscomm),
-		      (uintptr_t)client_data.osPrivate) == sizeof (oscomm)) {
-			ClientProcessPtr cpp = NULL;
+		    /* Xorg 1.9 or later */
+		    DevPrivateKeyRec IAPrivKeyRec;
+		    GElf_Sym privkey_sym;
 
-			mdb_printf("%4d ", oscomm.fd);
+		    mdb_printf("%4d ", oscomm.fd);
 
-			/* Xorg 1.6 or later */
-			{
-			    int IAPrivKeyIndex;
-			    GElf_Sym privkey_sym;
-			    if (mdb_lookup_by_obj("libia.so", "IAPrivKeyIndex",
-						   &privkey_sym) == -1) {
-				mdb_warn("failed to lookup 'libia.so`IAPrivKeyIndex'");
-			    } else {
-				if (mdb_vread(&IAPrivKeyIndex, sizeof(int),
-					      privkey_sym.st_value) != sizeof(int)) {
-				    mdb_warn("failed to read 'IAPrivKeyIndex'");
+		    if (mdb_lookup_by_obj("libia.so", "IAPrivKeyRec",
+					  &privkey_sym) == -1) {
+			mdb_warn("failed to lookup 'libia.so`IAPrivKeyRec'");
+		    } else {
+			if (mdb_vread(&IAPrivKeyRec, sizeof(DevPrivateKeyRec),
+				      privkey_sym.st_value)
+			    != sizeof(DevPrivateKeyRec)) {
+			    mdb_warn("failed to read 'IAPrivKeyRec'");
+			} else if (!IAPrivKeyRec.initialized) {
+			    mdb_warn("IAPrivKeyRec is uninitialized");
+			} else {
+			    uintptr_t dpaddr
+				= ((uintptr_t)client_data.devPrivates)
+				+ IAPrivKeyRec.offset;
+			    uintptr_t cppaddr = (uintptr_t) NULL;
+
+			    /*
+			     * ClientProcessPtr is the first entry in the
+			     * IAClientPrivatePtr that devPrivates points to
+			     */
+			    if (mdb_vread(&cppaddr, sizeof (cppaddr), dpaddr)
+				!= sizeof (cppaddr)) {
+				mdb_warn("failed to read "
+					 " client_data.devPrivates+offset");
+			    } else if (cppaddr == NULL) {
+				mdb_warn("no ClientProcessPtr found");
+			    } else if (mdb_vread(&cpp, sizeof (cpp), cppaddr)
+				       != sizeof (cpp)) {
+				cpp = NULL;
+				mdb_warn("failed to read IAClientPrivatePtr");
+			    }
+			}
+		    }
+
+		    if (cpp == NULL) {
+			mdb_printf(" ??? - NULL ClientProcessPtr\n");
+		    } else {
+			ClientProcessRec cpr;
+			ConnectionPidRec pid;
+
+			if (mdb_vread(&cpr, sizeof (cpr), (uintptr_t)cpp)
+			    != sizeof (cpr)) {
+			    mdb_warn("failed to read struct ClientProcessRec"
+				     " at %p", client_data.osPrivate);
+			} else {
+			    int i;
+			    uintptr_t pidP = (uintptr_t) cpr.pids;
+
+			    for (i = 0; i < cpr.count;
+				 i++, pidP += sizeof(pid)) {
+				if (mdb_vread(&pid, sizeof (pid), pidP)
+				    == sizeof (pid)) {
+				    mdb_printf("%d ", pid);
 				} else {
-				    void *dpaddr = &(client_data.devPrivates[IAPrivKeyIndex]);
-				    struct _Private devPriv;
-
-				    if (mdb_vread(&devPriv, sizeof (devPriv),
-						  (uintptr_t) dpaddr) != sizeof (devPriv)) {
-					mdb_warn("failed to read client_data.devPrivates[IAPrivKeyIndex]");
-				    } else {
-
-					void *cppaddr = devPriv.value;
-
-					if (mdb_vread(&cpp, sizeof (cpp), (uintptr_t) cppaddr) != sizeof (cpp)) {
-					    cpp = NULL;
-					    mdb_warn("failed to read client_data.devPrivates[IAPrivKeyIndex].value");
-					}
-				    }
+				    mdb_warn("failed to read pid #%d from %p",
+					     i, pidP);
 				}
 			    }
+			    mdb_printf("\n");
 			}
-
-			if (cpp != NULL) {
-			    ClientProcessRec cpr;
-			    ConnectionPidRec pid;
-
-			    if (mdb_vread(&cpr, sizeof (cpr),
-					  (uintptr_t)cpp) == sizeof (cpr)) {
-				int i;
-				uintptr_t pidP = (uintptr_t) cpr.pids;
-
-				for (i = 0; i < cpr.count; i++, pidP += sizeof(pid)) {
-				    if (mdb_vread(&pid, sizeof (pid), pidP) == sizeof (pid)) {
-					mdb_printf("%d ", pid);
-				    } else {
-					mdb_warn("failed to read pid #%d from %p", i, pidP);
-				    }
-				}
-				mdb_printf("\n");
+		    }
+		}
+	    }
+	}
+    }
 
-			    } else {
-				mdb_warn("failed to read struct ClientProcessRec at %p", client_data.osPrivate);
-			    }
-			} else {
-			    mdb_printf(" ??? - NULL ClientProcessPtr\n");
-			}
-		    } else {
-			mdb_warn("failed to read struct OsCommRec at %p", client_data.osPrivate);
-		    }
-		} else {
-		    mdb_printf(" ??? - NULL ClientPtr->osPrivate\n");
-		}
-	    } else {
-		mdb_warn("failed to read ClientRec at %p", clientP);
-	    }
-	} else {
-	    mdb_warn("failed to read ClientPtr at %p", addr);
-	}
-
-	return (DCMD_OK);
+    return (DCMD_OK);
 }
--- a/open-src/xserver/xorg/sun-src/os/solaris/mdb/modules/Xserver_device_grabs.c	Mon Aug 15 15:09:02 2011 -0700
+++ b/open-src/xserver/xorg/sun-src/os/solaris/mdb/modules/Xserver_device_grabs.c	Sun Aug 21 23:17:36 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -23,9 +23,11 @@
 
 
 #include <sys/mdb_modapi.h>
+
+#include "Xserver_mdb.h"
 #include "xorg-server.h"
 #include "inputstr.h"
-#include "Xserver_mdb.h"
+
 
 struct inputdev_walk_data {
     InputInfo 		inputInfo;
@@ -35,7 +37,7 @@
 /*
  * Initialize the inputdev walker by either using the given starting address,
  * or reading the value of the server's "inputInfo" pointer.  We also allocate
- * a for storage, and save this using the walk_data pointer.
+ * a struct for storage, and save this using the walk_data pointer.
  */
 _X_HIDDEN int
 inputdev_walk_init(mdb_walk_state_t *wsp)
--- a/open-src/xserver/xorg/sun-src/os/solaris/mdb/modules/Xserver_mdb.h	Mon Aug 15 15:09:02 2011 -0700
+++ b/open-src/xserver/xorg/sun-src/os/solaris/mdb/modules/Xserver_mdb.h	Sun Aug 21 23:17:36 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -27,6 +27,18 @@
 #include <sys/mdb_modapi.h>
 #include <X11/Xfuncproto.h>
 
+/*
+ * Avoid dragging in all the inline functions that cause invalid references
+ * to Xserver & libpixman symbols to appear in the mdb module, but provide
+ * stub typedefs needed by other headers from the excluded files.
+ */
+/* include/regionstr.h */
+#define REGIONSTRUCT_H
+typedef struct pixman_region16 RegionRec, *RegionPtr;
+/* include/callback.h */
+#define CALLBACK_H
+typedef void (*CallbackProcPtr) (void *, void *, void *);
+
 /* Xserver_client.c */
 _X_HIDDEN int	client_walk_init(mdb_walk_state_t *wsp);
 _X_HIDDEN int	client_walk_step(mdb_walk_state_t *wsp);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/xserver/xorg/sun-src/os/solaris/mdb/modules/mapfile	Sun Aug 21 23:17:36 2011 -0700
@@ -0,0 +1,53 @@
+#
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+# DEALINGS IN THE SOFTWARE.
+#
+
+$mapfile_version 2
+
+#
+# mapfile for Xserver mdb modules
+#
+
+SYMBOL_SCOPE {
+	global:
+
+# mdb modules reference symbols exported by mdb - this list should only
+# contain entries found in the ON gate's master copy of the mdb mapfile
+# in usr/src/cmd/mdb/common/modules/conf/mapfile-extern
+		mdb_alloc			{ FLAGS = EXTERN };
+		mdb_free			{ FLAGS = EXTERN };
+		mdb_lookup_by_name		{ FLAGS = EXTERN };
+		mdb_lookup_by_obj		{ FLAGS = EXTERN };
+		mdb_printf			{ FLAGS = EXTERN };
+		mdb_readstr			{ FLAGS = EXTERN };
+		mdb_readsym			{ FLAGS = EXTERN };
+		mdb_readvar			{ FLAGS = EXTERN };
+		mdb_vread			{ FLAGS = EXTERN };
+		mdb_warn			{ FLAGS = EXTERN };
+		mdb_walk_dcmd			{ FLAGS = EXTERN };
+
+# mdb modules aren't allowed to export any symbols except for _mdb_init
+		_mdb_init;
+
+	local:
+		*;
+};