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