1*d13dc62bSJohn Levon /*
2*d13dc62bSJohn Levon  * This file and its contents are supplied under the terms of the
3*d13dc62bSJohn Levon  * Common Development and Distribution License ("CDDL"), version 1.0.
4*d13dc62bSJohn Levon  * You may only use this file in accordance with the terms of version
5*d13dc62bSJohn Levon  * 1.0 of the CDDL.
6*d13dc62bSJohn Levon  *
7*d13dc62bSJohn Levon  * A full copy of the text of the CDDL should have accompanied this
8*d13dc62bSJohn Levon  * source.  A copy of the CDDL is also available via the Internet at
9*d13dc62bSJohn Levon  * http://www.illumos.org/license/CDDL.
10*d13dc62bSJohn Levon  */
11*d13dc62bSJohn Levon 
12*d13dc62bSJohn Levon /*
13*d13dc62bSJohn Levon  * Copyright 2019 Joyent, Inc.
14*d13dc62bSJohn Levon  */
15*d13dc62bSJohn Levon 
16*d13dc62bSJohn Levon #include <mdb/mdb_modapi.h>
17*d13dc62bSJohn Levon #include <mdb/mdb_ks.h>
18*d13dc62bSJohn Levon #include <sys/refstr.h>
19*d13dc62bSJohn Levon 
20*d13dc62bSJohn Levon #define	REFSTR_LEN (1024)
21*d13dc62bSJohn Levon 
22*d13dc62bSJohn Levon int
cmd_refstr(uintptr_t addr,uint_t flags __unused,int argc,const mdb_arg_t * argv)23*d13dc62bSJohn Levon cmd_refstr(uintptr_t addr, uint_t flags __unused,
24*d13dc62bSJohn Levon     int argc, const mdb_arg_t *argv)
25*d13dc62bSJohn Levon {
26*d13dc62bSJohn Levon 	if (!(flags & DCMD_ADDRSPEC)) {
27*d13dc62bSJohn Levon 		mdb_warn("address is required\n");
28*d13dc62bSJohn Levon 		return (DCMD_ERR);
29*d13dc62bSJohn Levon 	}
30*d13dc62bSJohn Levon 
31*d13dc62bSJohn Levon 	if (mdb_getopts(argc, argv, NULL) != argc)
32*d13dc62bSJohn Levon 		return (DCMD_USAGE);
33*d13dc62bSJohn Levon 
34*d13dc62bSJohn Levon 	char *buf = mdb_alloc(REFSTR_LEN, UM_SLEEP | UM_GC);
35*d13dc62bSJohn Levon 
36*d13dc62bSJohn Levon 	if (mdb_read_refstr(addr, buf, REFSTR_LEN) < 0) {
37*d13dc62bSJohn Levon 		mdb_warn("couldn't read refstr from %p", addr);
38*d13dc62bSJohn Levon 		return (DCMD_ERR);
39*d13dc62bSJohn Levon 	}
40*d13dc62bSJohn Levon 
41*d13dc62bSJohn Levon 	mdb_printf("%s\n", buf);
42*d13dc62bSJohn Levon 	return (DCMD_OK);
43*d13dc62bSJohn Levon }
44