4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
28 #define UMEM_OBJNAME "libumem.so.1"
30 int umem_debug_level
= 0;
31 int umem_is_standalone
= 0;
35 umem_debug(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
37 umem_debug_level
^= 1;
39 mdb_printf("umem: debugging is now %s\n",
40 umem_debug_level
? "on" : "off");
46 * To further confuse the issue, this dmod can run against either
47 * libumem.so.1 *or* the libstandumem.so linked into kmdb(1M). To figure
48 * out which one we are working against, we look up "umem_alloc" in both
49 * libumem.so and the executable.
51 * A further wrinkle is that libumem.so may not yet be loaded into the
52 * process' address space. That can lead to either the lookup failing, or
53 * being unable to read from the data segment. We treat either case as
57 umem_set_standalone(void)
62 if (mdb_lookup_by_obj(UMEM_OBJNAME
, "umem_alloc", &sym
) == 0)
63 umem_is_standalone
= 0;
64 else if (mdb_lookup_by_obj(MDB_OBJ_EXEC
, "umem_alloc", &sym
) == 0)
65 umem_is_standalone
= 1;
70 * now that we know where things should be, make sure we can actually
73 if (umem_readvar(&ready
, "umem_ready") == -1)
79 umem_lookup_by_name(const char *name
, GElf_Sym
*sym
)
81 return (mdb_lookup_by_obj((umem_is_standalone
? MDB_OBJ_EXEC
:
82 UMEM_OBJNAME
), name
, sym
));
85 /* This is like mdb_readvar, only for libumem.so's symbols */
87 umem_readvar(void *buf
, const char *name
)
91 if (umem_lookup_by_name(name
, &sym
))
94 if (mdb_vread(buf
, sym
.st_size
, (uintptr_t)sym
.st_value
)
96 return ((ssize_t
)sym
.st_size
);
102 is_umem_sym(const char *sym
, const char *prefix
)
104 char *tick_p
= strrchr(sym
, '`');
106 return (strncmp(sym
, "libumem", 7) == 0 && tick_p
!= NULL
&&
107 strncmp(tick_p
+ 1, prefix
, strlen(prefix
)) == 0);