4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 * Copyright (c) 2015, Joyent, Inc.
29 * libctf open/close interposition layer
31 * This interposition layer serves two purposes. First, it allows the
32 * introduction of a kmdb-specific implementation of ctf_open(). The normal
33 * ctf_open() call open(2)s a file, and reads the CTF data directly from it.
34 * No such facility is available in kmdb, as kmdb does not run in userland. We
35 * can, however, observe that kmdb uses this interface only to read CTF data
36 * from dmods. dmods, as viewed by kmdb, do have CTF data, but they have it
37 * in a form that is best accessed by ctf_bufopen(). This interposition layer
38 * allows us to translate ctf_open() calls into ctf_bufopen() calls.
40 * The second purpose of the interposition layer is to reduce the work needed
41 * to call mdb_ctf_bufopen.
44 #include <sys/types.h>
49 #include <kmdb/kmdb_module.h>
50 #include <mdb/mdb_ctf.h>
51 #include <mdb/mdb_string.h>
52 #include <mdb/mdb_debug.h>
53 #include <mdb/mdb_err.h>
56 static kmdb_modctl_t
*
57 mdb_ctf_name2ctl(const char *pathname
)
61 if ((v
= mdb_nv_lookup(&mdb
.m_dmodctl
, strbasename(pathname
))) ==
65 return ((kmdb_modctl_t
*)MDB_NV_COOKIE(v
));
69 mdb_ctf_open(const char *pathname
, int *errp
)
75 if ((kmc
= mdb_ctf_name2ctl(pathname
)) == NULL
) {
81 mp
= kmc
->kmc_modctl
->mod_mp
;
82 if (mp
->ctfdata
== NULL
) {
84 *errp
= ECTF_NOCTFDATA
;
88 if ((ctfp
= mdb_ctf_bufopen(mp
->ctfdata
, mp
->ctfsize
, mp
->symtbl
,
89 mp
->symhdr
, mp
->strings
, mp
->strhdr
, errp
)) == NULL
)
92 mdb_dprintf(MDB_DBG_MODULE
, "loaded %lu bytes of CTF data for %s\n",
93 (ulong_t
)mp
->ctfsize
, kmc
->kmc_modname
);
99 mdb_ctf_close(ctf_file_t
*fp
)
106 mdb_ctf_write(const char *file
, ctf_file_t
*fp
)