Print this page
OS-3477 lx brand: mdb(1) doesn't find branded symbols
OS-3426 lx brand: dtrace(1M) doesn't find branded symbols

@@ -21,10 +21,14 @@
 /*
  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
+/*
+ * Copyright (c) 2014 Joyent, Inc.  All rights reserved.
+ */
+
 #include        <stdlib.h>
 #include        <stdio.h>
 #include        <proc_service.h>
 #include        <link.h>
 #include        <rtld_db.h>

@@ -36,10 +40,18 @@
 #include        <limits.h>
 #include        <string.h>
 #include        <sys/param.h>
 
 /*
+ * We want to include zone.h to pull in the prototype for zone_get_nroot(),
+ * but we need to avoid pulling in <sys/stream.h>, which has a definition
+ * of M_DATA that conflicts with the ELF-related definition in machdep_*.h.
+ */
+#define         _SYS_STREAM_H
+#include        <zone.h>
+
+/*
  * 64-bit builds are going to compile this module twice, the
  * second time with _ELF64 defined.  These defines should make
  * all the necessary adjustments to the code.
  */
 #ifdef _LP64

@@ -281,11 +293,13 @@
 
         /*
          * If we are debugging a branded executable, load the appropriate
          * helper library, and call its initialization routine.  Being unable
          * to load the helper library is not a critical error.  (Hopefully
-         * we'll still be able to access some objects in the target.)
+         * we'll still be able to access some objects in the target.)  Note
+         * that we pull in the native root here to allow for helper libraries
+         * to be properly found from within the branded zone.
          */
         ps_pbrandname = (ps_pbrandname_fp_t)dlsym(RTLD_PROBE, "ps_pbrandname");
         while ((ps_pbrandname != NULL) &&
             (ps_pbrandname(php, brandname, MAXPATHLEN) == PS_OK)) {
                 const char *isa = "";

@@ -292,21 +306,27 @@
 
 #ifdef _LP64
                 isa = MSG_ORIG(MSG_DB_64BIT_PREFIX);
 #endif /* _LP64 */
 
-                if (rtld_db_helper_path[0] != '\0')
+                if (rtld_db_helper_path[0] != '\0') {
                         (void) snprintf(brandlib, MAXPATHLEN,
                             MSG_ORIG(MSG_DB_BRAND_HELPERPATH_PREFIX),
                             rtld_db_helper_path,
                             MSG_ORIG(MSG_DB_HELPER_PREFIX), brandname, isa,
                             brandname);
-                else
+                } else {
+                        const char *nroot = zone_get_nroot();
+
+                        if (nroot == NULL)
+                                nroot = "";
+
                         (void) snprintf(brandlib, MAXPATHLEN,
-                            MSG_ORIG(MSG_DB_BRAND_HELPERPATH),
+                            MSG_ORIG(MSG_DB_BRAND_HELPERPATH), nroot,
                             MSG_ORIG(MSG_DB_HELPER_PREFIX), brandname, isa,
                             brandname);
+                }
 
                 rap->rd_helper.rh_dlhandle = dlopen(brandlib,
                     RTLD_LAZY | RTLD_LOCAL);
                 if (rap->rd_helper.rh_dlhandle == NULL) {
                         LOG(ps_plog(MSG_ORIG(MSG_DB_HELPERLOADFAILED),