summaryrefslogtreecommitdiff
path: root/usr
diff options
context:
space:
mode:
authorRobert Mustacchi <rm@joyent.com>2015-02-18 23:52:30 +0000
committerRobert Mustacchi <rm@joyent.com>2015-09-01 11:41:39 -0700
commit2becb8cdf9cd77e1a76224f216be15d6ae3b9ec9 (patch)
tree084079be2a566553f6b57fe8cf70048143e3456a /usr
parentb3eeeb30c3479f68ec3696b60e4bd4e4f6059bd5 (diff)
downloadillumos-joyent-2becb8cdf9cd77e1a76224f216be15d6ae3b9ec9.tar.gz
6176 want ::typedef -w to write out CTF containers
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com> Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net> Reviewed by: Dan McDonald <danmcd@omniti.com> Approved by: Gordon Ross <gwr@nexenta.com>
Diffstat (limited to 'usr')
-rw-r--r--usr/src/cmd/mdb/common/kmdb/kmdb_ctf_open.c10
-rw-r--r--usr/src/cmd/mdb/common/mdb/mdb_cmds.c4
-rw-r--r--usr/src/cmd/mdb/common/mdb/mdb_ctf.c26
-rw-r--r--usr/src/cmd/mdb/common/mdb/mdb_ctf.h4
-rw-r--r--usr/src/cmd/mdb/common/mdb/mdb_ctf_open.c27
-rw-r--r--usr/src/cmd/mdb/common/mdb/mdb_typedef.c40
6 files changed, 97 insertions, 14 deletions
diff --git a/usr/src/cmd/mdb/common/kmdb/kmdb_ctf_open.c b/usr/src/cmd/mdb/common/kmdb/kmdb_ctf_open.c
index bfa1d1d072..24da420f6f 100644
--- a/usr/src/cmd/mdb/common/kmdb/kmdb_ctf_open.c
+++ b/usr/src/cmd/mdb/common/kmdb/kmdb_ctf_open.c
@@ -22,10 +22,9 @@
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
+ * Copyright (c) 2015, Joyent, Inc.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
/*
* libctf open/close interposition layer
*
@@ -101,3 +100,10 @@ mdb_ctf_close(ctf_file_t *fp)
{
ctf_close(fp);
}
+
+/*ARGSUSED*/
+int
+mdb_ctf_write(const char *file, ctf_file_t *fp)
+{
+ return (ENOTSUP);
+}
diff --git a/usr/src/cmd/mdb/common/mdb/mdb_cmds.c b/usr/src/cmd/mdb/common/mdb/mdb_cmds.c
index e9829bd6c2..95b216cfbe 100644
--- a/usr/src/cmd/mdb/common/mdb/mdb_cmds.c
+++ b/usr/src/cmd/mdb/common/mdb/mdb_cmds.c
@@ -26,7 +26,7 @@
/*
* Copyright (c) 2012 by Delphix. All rights reserved.
- * Copyright (c) 2013 Joyent, Inc. All rights reserved.
+ * Copyright (c) 2015 Joyent, Inc. All rights reserved.
* Copyright (c) 2013 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
*/
@@ -2977,7 +2977,7 @@ const mdb_dcmd_t mdb_dcmd_builtins[] = {
{ "status", NULL, "print summary of current target", cmd_notsup },
{ "term", NULL, "display current terminal type", cmd_term },
{ "typeset", "[+/-t] var ...", "set variable attributes", cmd_typeset },
- { "typedef", "[-c model | -d | -l | -r file ] [type] [name]",
+ { "typedef", "[-c model | -d | -l | -r file | -w file ] [type] [name]",
"create synthetic types", cmd_typedef, cmd_typedef_help },
{ "unset", "[name ...]", "unset variables", cmd_unset },
{ "vars", "[-npt]", "print listing of variables", cmd_vars },
diff --git a/usr/src/cmd/mdb/common/mdb/mdb_ctf.c b/usr/src/cmd/mdb/common/mdb/mdb_ctf.c
index 072ac9ef12..66a8b009a3 100644
--- a/usr/src/cmd/mdb/common/mdb/mdb_ctf.c
+++ b/usr/src/cmd/mdb/common/mdb/mdb_ctf.c
@@ -2142,3 +2142,29 @@ cleanup:
(void) ctf_discard(syn);
return (ret);
}
+
+int
+mdb_ctf_synthetics_to_file(const char *file)
+{
+ int err;
+ ctf_file_t *fp = mdb.m_synth;
+
+ if (fp == NULL) {
+ mdb_warn("synthetic types are disabled, not writing "
+ "anything\n");
+ return (DCMD_ERR);
+ }
+
+ err = mdb_ctf_write(file, fp);
+ if (err != 0) {
+ if (err == CTF_ERR)
+ (void) set_errno(ctf_to_errno(ctf_errno(fp)));
+ else
+ (void) set_errno(err);
+ err = DCMD_ERR;
+ } else {
+ err = DCMD_OK;
+ }
+
+ return (err);
+}
diff --git a/usr/src/cmd/mdb/common/mdb/mdb_ctf.h b/usr/src/cmd/mdb/common/mdb/mdb_ctf.h
index 2396145299..85e60494d0 100644
--- a/usr/src/cmd/mdb/common/mdb/mdb_ctf.h
+++ b/usr/src/cmd/mdb/common/mdb/mdb_ctf.h
@@ -24,7 +24,7 @@
*/
/*
* Copyright (c) 2013 by Delphix. All rights reserved.
- * Copyright (c) 2013, Joyent, Inc. All rights reserved.
+ * Copyright (c) 2015, Joyent, Inc.
*/
#ifndef _MDB_CTF_H
@@ -151,10 +151,12 @@ extern int mdb_ctf_readsym(void *, const char *, const char *, uint_t);
extern ctf_file_t *mdb_ctf_open(const char *, int *); /* Internal */
extern ctf_file_t *mdb_ctf_bufopen(const void *, size_t, /* Internal */
const void *, Shdr *, const void *, Shdr *, int *);
+extern int mdb_ctf_write(const char *, ctf_file_t *fp); /* Internal */
extern void mdb_ctf_close(ctf_file_t *fp); /* Internal */
extern int mdb_ctf_synthetics_init(void); /* Internal */
extern void mdb_ctf_synthetics_fini(void); /* Internal */
extern int mdb_ctf_synthetics_from_file(const char *); /* Internal */
+extern int mdb_ctf_synthetics_to_file(const char *); /* Internal */
#endif
diff --git a/usr/src/cmd/mdb/common/mdb/mdb_ctf_open.c b/usr/src/cmd/mdb/common/mdb/mdb_ctf_open.c
index 730a9a4599..525cb5e88a 100644
--- a/usr/src/cmd/mdb/common/mdb/mdb_ctf_open.c
+++ b/usr/src/cmd/mdb/common/mdb/mdb_ctf_open.c
@@ -22,10 +22,9 @@
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
+ * Copyright (c) 2015, Joyent, Inc.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
/*
* libctf open/close interposition layer
*
@@ -36,6 +35,11 @@
#include <mdb/mdb_ctf.h>
#include <libctf.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
ctf_file_t *
mdb_ctf_open(const char *filename, int *errp)
@@ -48,3 +52,22 @@ mdb_ctf_close(ctf_file_t *fp)
{
ctf_close(fp);
}
+
+int
+mdb_ctf_write(const char *filename, ctf_file_t *fp)
+{
+ int fd, ret;
+
+ if ((fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0644)) < 0)
+ return (errno);
+
+ if (ctf_write(fp, fd) == CTF_ERR) {
+ (void) close(fd);
+ return (CTF_ERR);
+ }
+
+ ret = close(fd);
+ if (ret != 0)
+ ret = errno;
+ return (ret);
+}
diff --git a/usr/src/cmd/mdb/common/mdb/mdb_typedef.c b/usr/src/cmd/mdb/common/mdb/mdb_typedef.c
index be6411596c..bff36274a3 100644
--- a/usr/src/cmd/mdb/common/mdb/mdb_typedef.c
+++ b/usr/src/cmd/mdb/common/mdb/mdb_typedef.c
@@ -10,7 +10,7 @@
*/
/*
- * Copyright (c) 2013 Joyent, Inc. All rights reserved.
+ * Copyright (c) 2015 Joyent, Inc. All rights reserved.
*/
/*
@@ -556,7 +556,18 @@ typedef_readfile(const char *file)
ret = mdb_ctf_synthetics_from_file(file);
if (ret != DCMD_OK)
- mdb_warn("failed to create synthetics from file\n");
+ mdb_warn("failed to create synthetics from file %s\n", file);
+ return (ret);
+}
+
+static int
+typedef_writefile(const char *file)
+{
+ int ret;
+
+ ret = mdb_ctf_synthetics_to_file(file);
+ if (ret != DCMD_OK)
+ mdb_warn("failed to write synthetics to file %s", file);
return (ret);
}
@@ -567,7 +578,7 @@ cmd_typedef(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
mdb_ctf_id_t id;
int i;
int destroy = 0, list = 0;
- const char *cmode = NULL, *rfile = NULL;
+ const char *cmode = NULL, *rfile = NULL, *wfile = NULL;
const char *dst, *src;
char *dup;
parse_root_t *pr;
@@ -579,7 +590,8 @@ cmd_typedef(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
'd', MDB_OPT_SETBITS, TRUE, &destroy,
'l', MDB_OPT_SETBITS, TRUE, &list,
'c', MDB_OPT_STR, &cmode,
- 'r', MDB_OPT_STR, &rfile, NULL);
+ 'r', MDB_OPT_STR, &rfile,
+ 'w', MDB_OPT_STR, &wfile, NULL);
argc -= i;
argv += i;
@@ -596,10 +608,13 @@ cmd_typedef(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
i++;
if (rfile != NULL)
i++;
+ if (wfile != NULL)
+ i++;
if (i > 1)
return (DCMD_USAGE);
- if ((destroy || cmode != NULL || list || rfile != NULL) && argc != 0)
+ if ((destroy || cmode != NULL || list || rfile != NULL ||
+ wfile != NULL) && argc != 0)
return (DCMD_USAGE);
if (destroy)
@@ -614,6 +629,9 @@ cmd_typedef(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
if (rfile)
return (typedef_readfile(rfile));
+ if (wfile)
+ return (typedef_writefile(wfile));
+
if (argc < 2)
return (DCMD_USAGE);
@@ -702,22 +720,29 @@ static char typedef_desc[] =
" o packed structures (all structures currently use their natural alignment)\n"
"\n"
"::typedef also allows you to read type definitions from a file. Definitions\n"
-"can be read from any ELF file that has a CTF section that libctf can parse.\n"
+"can be read from any ELF file that has a CTF section that libctf can parse\n"
+"or any raw CTF data files, such as those that can be created with ::typedef.\n"
"You can check if a file has such a section with elfdump(1). If a binary or\n"
"core dump does not have any type information, but you do have it elsewhere,\n"
"then you can use ::typedef -r to read in that type information.\n"
+"\n"
+"All built up definitions may be exported as a valid CTF container that can\n"
+"be used again with ::typedef -r or anything that uses libctf. To write them\n"
+"out, use ::typedef -w and specify the name of a file. For more information\n"
+"on the CTF file format, see ctf(4).\n"
"\n";
static char typedef_opts[] =
" -c model create intrinsic types based on the specified data model.\n"
" The INTRINSICS section lists the built-in types and typedefs.\n"
" The following data models are supported:\n"
-" o LP64 - Traditional illumos 64-bit program\n"
+" o LP64 - Traditional illumos 64-bit program.\n"
" o LP32 - Traditional illumos 32-bit program.\n"
" o ILP32 - An alternate name for LP32.\n"
" -d delete all synthetic types\n"
" -l list all synthetic types\n"
" -r file import type definitions (CTF) from another ELF file\n"
+" -w file write all synthetic type definitions out to file\n"
"\n";
static char typedef_examps[] =
@@ -729,6 +754,7 @@ static char typedef_examps[] =
" ::typedef \"struct list { struct list *l_next; struct list *l_prev; }\" "
"list_t\n"
" ::typedef -r /var/tmp/qemu-system-x86_64\n"
+" ::typedef -w defs.ctf"
"\n";
static char typedef_intrins[] =