changeset 5041:8bd749a329c9

6599699 libproc sometimes fails to determine a processes brand 6602294 ps_pbrandname breaks apps linked directly against librtld_db
author edp
date Thu, 13 Sep 2007 11:38:19 -0700
parents ff6ebd8761a6
children 105442d80fa2
files usr/src/cmd/sgs/librtld_db/common/mapfile-vers usr/src/cmd/sgs/librtld_db/common/rd_elf.c usr/src/lib/libproc/common/Pbrand.c
diffstat 3 files changed, 17 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/sgs/librtld_db/common/mapfile-vers	Thu Sep 13 10:10:42 2007 -0700
+++ b/usr/src/cmd/sgs/librtld_db/common/mapfile-vers	Thu Sep 13 11:38:19 2007 -0700
@@ -1,5 +1,5 @@
 #
-# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
 # CDDL HEADER START
@@ -54,5 +54,4 @@
 	ps_plog = PARENT;
 	ps_pread = PARENT;
 	ps_pwrite = PARENT;
-	ps_pbrandname = PARENT;
 };
--- a/usr/src/cmd/sgs/librtld_db/common/rd_elf.c	Thu Sep 13 10:10:42 2007 -0700
+++ b/usr/src/cmd/sgs/librtld_db/common/rd_elf.c	Thu Sep 13 11:38:19 2007 -0700
@@ -19,7 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -64,6 +64,15 @@
 #define	TListnode		Listnode
 #endif	/* _LP64 */
 
+/*
+ * BrandZ added ps_pbrandname().  Many debuggers that link directly
+ * against librtld_db.so may not implement this interface.  Hence
+ * we won't call the function directly, instead we'll try to look it
+ * up using the linker first and only invoke it if we find it.
+ */
+typedef ps_err_e (*ps_pbrandname_fp_t)(struct ps_prochandle *,
+    char *, size_t);
+
 static rd_err_e
 validate_rdebug(struct rd_agent *rap)
 {
@@ -177,6 +186,7 @@
 	rd_err_e		rc = RD_OK;
 	char			brandname[MAXPATHLEN];
 	char			brandlib[MAXPATHLEN];
+	ps_pbrandname_fp_t	ps_pbrandname;
 
 	/*
 	 * librtld_db attempts three different methods to find
@@ -281,7 +291,9 @@
 	 * If we are debugging a branded executable, load the appropriate helper
 	 * library, and call its initialization routine.
 	 */
-	if (ps_pbrandname(php, brandname, MAXPATHLEN) == PS_OK) {
+	ps_pbrandname = (ps_pbrandname_fp_t)dlsym(RTLD_PROBE, "ps_pbrandname");
+	if ((ps_pbrandname != NULL) &&
+	    (ps_pbrandname(php, brandname, MAXPATHLEN) == PS_OK)) {
 		const char *isa = "";
 
 #ifdef __amd64
--- a/usr/src/lib/libproc/common/Pbrand.c	Thu Sep 13 10:10:42 2007 -0700
+++ b/usr/src/lib/libproc/common/Pbrand.c	Thu Sep 13 11:38:19 2007 -0700
@@ -19,7 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -35,7 +35,7 @@
 	if ((addr = Pgetauxval(P, AT_SUN_BRANDNAME)) == -1)
 		return (NULL);
 
-	if (ps_pread(P, addr, buf, buflen) != PS_OK)
+	if (Pread_string(P, buf, buflen, addr) == -1)
 		return (NULL);
 
 	return (buf);