7 * with the License.
8 *
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.
13 *
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]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2001-2002 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #pragma ident "%Z%%M% %I% %E% SMI"
28
29 #include <mdb/mdb_modapi.h>
30 #include <mdb/mdb_demangle.h>
31 #include <mdb/mdb_err.h>
32 #include <mdb/mdb.h>
33
34 #include <demangle.h>
35 #include <strings.h>
36 #include <unistd.h>
37 #include <dlfcn.h>
38 #include <link.h>
39
40 #ifdef _LP64
41 static const char LIB_DEMANGLE[] = "/usr/lib/64/libdemangle.so.1";
42 #else
43 static const char LIB_DEMANGLE[] = "/usr/lib/libdemangle.so.1";
44 #endif
45
46 mdb_demangler_t *
47 mdb_dem_load(const char *path)
246 mdb_warn("failed to allocate memory for demangling");
247 return (name); /* just return original name */
248 }
249
250 mdb_free(dmp->dm_buf, dmp->dm_len);
251 dmp->dm_buf = buf;
252 dmp->dm_len = len;
253 }
254
255 if (err != 0 || strcmp(dmp->dm_buf, name) == 0)
256 return (name); /* return original name if not mangled */
257
258 return (mdb_dem_filter(dmp, name));
259 }
260
261 /*ARGSUSED*/
262 int
263 cmd_demangle(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
264 {
265 mdb_demangler_t *dmp = mdb.m_demangler;
266 const char *path = LIB_DEMANGLE;
267
268 if (argc > 1 || (argc > 0 && argv->a_type != MDB_TYPE_STRING))
269 return (DCMD_USAGE);
270
271 if (argc > 0) {
272 if (dmp != NULL)
273 mdb_dem_unload(mdb.m_demangler);
274 path = argv->a_un.a_str;
275 }
276
277 if (dmp != NULL && argc == 0 && !(mdb.m_flags & MDB_FL_DEMANGLE)) {
278 mdb_printf("C++ symbol demangling enabled\n");
279 mdb.m_flags |= MDB_FL_DEMANGLE;
280
281 } else if (dmp == NULL || argc > 0) {
282 if ((mdb.m_demangler = mdb_dem_load(path)) != NULL) {
283 mdb_printf("C++ symbol demangling enabled\n");
284 mdb.m_flags |= MDB_FL_DEMANGLE;
285 } else {
286 mdb_warn("failed to load C++ demangler %s", path);
287 mdb.m_flags &= ~MDB_FL_DEMANGLE;
288 }
289
290 } else {
291 mdb_dem_unload(mdb.m_demangler);
292 mdb.m_flags &= ~MDB_FL_DEMANGLE;
293 mdb.m_demangler = NULL;
294 mdb_printf("C++ symbol demangling disabled\n");
|
7 * with the License.
8 *
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.
13 *
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]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2001-2002 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /*
28 * Copyright (c) 2014, Joyent, Inc. All rights reserved.
29 */
30
31 #include <mdb/mdb_modapi.h>
32 #include <mdb/mdb_demangle.h>
33 #include <mdb/mdb_err.h>
34 #include <mdb/mdb.h>
35
36 #include <demangle.h>
37 #include <strings.h>
38 #include <unistd.h>
39 #include <dlfcn.h>
40 #include <link.h>
41
42 #ifdef _LP64
43 static const char LIB_DEMANGLE[] = "/usr/lib/64/libdemangle.so.1";
44 #else
45 static const char LIB_DEMANGLE[] = "/usr/lib/libdemangle.so.1";
46 #endif
47
48 mdb_demangler_t *
49 mdb_dem_load(const char *path)
248 mdb_warn("failed to allocate memory for demangling");
249 return (name); /* just return original name */
250 }
251
252 mdb_free(dmp->dm_buf, dmp->dm_len);
253 dmp->dm_buf = buf;
254 dmp->dm_len = len;
255 }
256
257 if (err != 0 || strcmp(dmp->dm_buf, name) == 0)
258 return (name); /* return original name if not mangled */
259
260 return (mdb_dem_filter(dmp, name));
261 }
262
263 /*ARGSUSED*/
264 int
265 cmd_demangle(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
266 {
267 mdb_demangler_t *dmp = mdb.m_demangler;
268 const char *path;
269 char buf[MAXPATHLEN];
270
271 if (argc > 1 || (argc > 0 && argv->a_type != MDB_TYPE_STRING))
272 return (DCMD_USAGE);
273
274 if (argc > 0) {
275 if (dmp != NULL)
276 mdb_dem_unload(mdb.m_demangler);
277 path = argv->a_un.a_str;
278 } else {
279 (void) snprintf(buf, MAXPATHLEN,
280 "%s/%s", mdb.m_root, LIB_DEMANGLE);
281 path = buf;
282 }
283
284 if (dmp != NULL && argc == 0 && !(mdb.m_flags & MDB_FL_DEMANGLE)) {
285 mdb_printf("C++ symbol demangling enabled\n");
286 mdb.m_flags |= MDB_FL_DEMANGLE;
287
288 } else if (dmp == NULL || argc > 0) {
289 if ((mdb.m_demangler = mdb_dem_load(path)) != NULL) {
290 mdb_printf("C++ symbol demangling enabled\n");
291 mdb.m_flags |= MDB_FL_DEMANGLE;
292 } else {
293 mdb_warn("failed to load C++ demangler %s", path);
294 mdb.m_flags &= ~MDB_FL_DEMANGLE;
295 }
296
297 } else {
298 mdb_dem_unload(mdb.m_demangler);
299 mdb.m_flags &= ~MDB_FL_DEMANGLE;
300 mdb.m_demangler = NULL;
301 mdb_printf("C++ symbol demangling disabled\n");
|