changeset 13947:4ae108c6a5d7

3535 mdb ::print should pretty-print ipaddr_t and friends Reviewed by: Adam Leventhal <ahl@delphix.com> Reviewed by: Matthew Ahrens <mahrens@delphix.com> Reviewed by: Robert Mustacchi <rm@joyent.com> Reviewed by: Marcel Telka <marcel@telka.sk> Reviewed by: Dan McDonald <danmcd@nexenta.com> Approved by: Gordon Ross <gwr@nexenta.com>
author Sebastien Roy <seb@delphix.com>
date Thu, 07 Feb 2013 14:42:52 -0800
parents 41660db11225
children 0a75a6efa936
files usr/src/cmd/mdb/common/mdb/mdb_print.c
diffstat 1 files changed, 69 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/mdb/common/mdb/mdb_print.c	Tue Oct 30 23:03:27 2012 -0400
+++ b/usr/src/cmd/mdb/common/mdb/mdb_print.c	Thu Feb 07 14:42:52 2013 -0800
@@ -72,6 +72,7 @@
 	int pa_nest;			/* array nesting depth */
 	int pa_tab;			/* tabstop width */
 	uint_t pa_maxdepth;		/* Limit max depth */
+	uint_t pa_nooutdepth;		/* don't print output past this depth */
 } printarg_t;
 
 #define	PA_SHOWTYPE	0x001		/* print type name */
@@ -941,6 +942,7 @@
 		uint16_t i2;
 		uint8_t i1;
 		time_t t;
+		ipaddr_t I;
 	} u;
 
 	if (!(pap->pa_flags & PA_SHOWVAL))
@@ -975,12 +977,20 @@
 	}
 
 	/*
-	 * We pretty-print time_t values as a calendar date and time.
+	 * We pretty-print some integer based types.  time_t values are
+	 * printed as a calendar date and time, and IPv4 addresses as human
+	 * readable dotted quads.
 	 */
-	if (!(pap->pa_flags & (PA_INTHEX | PA_INTDEC)) &&
-	    strcmp(type, "time_t") == 0 && u.t != 0) {
-		mdb_printf("%Y", u.t);
-		return (0);
+	if (!(pap->pa_flags & (PA_INTHEX | PA_INTDEC))) {
+		if (strcmp(type, "time_t") == 0 && u.t != 0) {
+			mdb_printf("%Y", u.t);
+			return (0);
+		}
+		if (strcmp(type, "ipaddr_t") == 0 ||
+		    strcmp(type, "in_addr_t") == 0) {
+			mdb_printf("%I", u.I);
+			return (0);
+		}
 	}
 
 	/*
@@ -1280,6 +1290,46 @@
 print_sou(const char *type, const char *name, mdb_ctf_id_t id,
     mdb_ctf_id_t base, ulong_t off, printarg_t *pap)
 {
+	mdb_tgt_addr_t addr = pap->pa_addr + off / NBBY;
+
+	/*
+	 * We have pretty-printing for some structures where displaying
+	 * structure contents has no value.
+	 */
+	if (pap->pa_flags & PA_SHOWVAL) {
+		if (strcmp(type, "in6_addr_t") == 0 ||
+		    strcmp(type, "struct in6_addr") == 0) {
+			in6_addr_t in6addr;
+
+			if (mdb_tgt_aread(pap->pa_tgt, pap->pa_as, &in6addr,
+			    sizeof (in6addr), addr) != sizeof (in6addr)) {
+				mdb_warn("failed to read %s pointer at %llx",
+				    name, addr);
+				return (1);
+			}
+			mdb_printf("%N", &in6addr);
+			/*
+			 * Don't print anything further down in the
+			 * structure.
+			 */
+			pap->pa_nooutdepth = pap->pa_depth;
+			return (0);
+		}
+		if (strcmp(type, "struct in_addr") == 0) {
+			in_addr_t inaddr;
+
+			if (mdb_tgt_aread(pap->pa_tgt, pap->pa_as, &inaddr,
+			    sizeof (inaddr), addr) != sizeof (inaddr)) {
+				mdb_warn("failed to read %s pointer at %llx",
+				    name, addr);
+				return (1);
+			}
+			mdb_printf("%I", inaddr);
+			pap->pa_nooutdepth = pap->pa_depth;
+			return (0);
+		}
+	}
+
 	if (pap->pa_depth == pap->pa_maxdepth)
 		mdb_printf("{ ... }");
 	else
@@ -1484,10 +1534,19 @@
 	int kind, rc, d;
 	printarg_t *pap = data;
 
-	for (d = pap->pa_depth - 1; d >= depth; d--)
-		print_close_sou(pap, d);
-
-	if (depth > pap->pa_maxdepth)
+	for (d = pap->pa_depth - 1; d >= depth; d--) {
+		if (d < pap->pa_nooutdepth)
+			print_close_sou(pap, d);
+	}
+
+	/*
+	 * Reset pa_nooutdepth if we've come back out of the structure we
+	 * didn't want to print.
+	 */
+	if (depth <= pap->pa_nooutdepth)
+		pap->pa_nooutdepth = (uint_t)-1;
+
+	if (depth > pap->pa_maxdepth || depth > pap->pa_nooutdepth)
 		return (0);
 
 	if (!mdb_ctf_type_valid(base) ||
@@ -2273,6 +2332,7 @@
 	pa.pa_nholes = 0;
 	pa.pa_depth = 0;
 	pa.pa_maxdepth = opt_s;
+	pa.pa_nooutdepth = (uint_t)-1;
 
 	if ((flags & DCMD_ADDRSPEC) && !opt_i)
 		pa.pa_addr = opt_p ? mdb_get_dot() : addr;