dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / sgs / liblddbg / common / dlfcns.c
blob62a076ebd2e233b1919bfd7f97b07db4db02043b
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #include "msg.h"
28 #include "_debug.h"
29 #include "libld.h"
31 void
32 Dbg_dl_iphdr_enter(Rt_map *clmp, u_longlong_t cnt_map, u_longlong_t cnt_unmap)
34 Lm_list *lml = LIST(clmp);
36 if (DBG_NOTCLASS(DBG_C_DL))
37 return;
39 Dbg_util_nl(lml, DBG_NL_STD);
40 dbg_print(lml, MSG_INTL(MSG_DL_IPHDR_ENTER), NAME(clmp));
41 dbg_print(lml, MSG_INTL(MSG_DL_IPHDR_MAPCNT), cnt_map, cnt_unmap);
44 void
45 Dbg_dl_iphdr_callback(Lm_list *lml, struct dl_phdr_info *info)
47 if (DBG_NOTCLASS(DBG_C_DL))
48 return;
50 dbg_print(lml, MSG_INTL(MSG_DL_IPHDR_CALLBACK));
51 dbg_print(lml, MSG_INTL(MSG_DL_IPHDR_NAME), info->dlpi_name);
52 dbg_print(lml, MSG_INTL(MSG_DL_IPHDR_ADDR), EC_ADDR(info->dlpi_addr));
53 dbg_print(lml, MSG_INTL(MSG_DL_IPHDR_PHDR),
54 EC_ADDR(CAST_PTRINT(Addr, info->dlpi_phdr)),
55 EC_WORD(info->dlpi_phnum));
58 void
59 Dbg_dl_iphdr_mapchange(Lm_list *lml, u_longlong_t cnt_map,
60 u_longlong_t cnt_unmap)
62 if (DBG_NOTCLASS(DBG_C_DL))
63 return;
65 dbg_print(lml, MSG_INTL(MSG_DL_IPHDR_MAPCNG));
66 dbg_print(lml, MSG_INTL(MSG_DL_IPHDR_MAPCNT), cnt_map, cnt_unmap);
69 void
70 Dbg_dl_iphdr_unmap_ret(Lm_list *lml)
72 if (DBG_NOTCLASS(DBG_C_DL))
73 return;
75 dbg_print(lml, MSG_INTL(MSG_DL_IPHDR_UNMAP));
78 void
79 Dbg_dl_dlopen(Rt_map *clmp, const char *name, int *in_nfavl, int mode)
81 Conv_dl_mode_buf_t dl_mode_buf;
82 Lm_list *lml = LIST(clmp);
83 const char *retry;
85 if (DBG_NOTCLASS(DBG_C_FILES | DBG_C_DL))
86 return;
89 * The core functionality of dlopen() can be called twice. The first
90 * attempt can be affected by path names that exist in the "not-found"
91 * AVL tree. Should a "not-found" path name be found, a second attempt
92 * is made to locate the required file (in_nfavl is NULL). This fall-
93 * back provides for file system changes while a process executes.
95 if (in_nfavl)
96 retry = MSG_ORIG(MSG_STR_EMPTY);
97 else
98 retry = MSG_INTL(MSG_STR_RETRY);
100 Dbg_util_nl(lml, DBG_NL_STD);
101 dbg_print(lml, MSG_INTL(MSG_DL_DLOPEN), name, NAME(clmp), retry,
102 conv_dl_mode(mode, 0, &dl_mode_buf));
105 void
106 Dbg_dl_dlclose(Rt_map *clmp, const char *name, int flag)
108 const char *str;
109 Lm_list *lml = LIST(clmp);
111 if (DBG_NOTCLASS(DBG_C_FILES | DBG_C_DL))
112 return;
114 if (flag == DBG_DLCLOSE_IGNORE)
115 str = MSG_INTL(MSG_STR_IGNORE);
116 else
117 str = MSG_ORIG(MSG_STR_EMPTY);
119 Dbg_util_nl(lml, DBG_NL_STD);
120 dbg_print(lml, MSG_INTL(MSG_DL_DLCLOSE), name, NAME(clmp), str);
123 void
124 Dbg_dl_dldump(Rt_map *clmp, const char *ipath, const char *opath, int flags)
126 Conv_dl_flag_buf_t dl_flag_buf;
127 Lm_list *lml = LIST(clmp);
129 if (DBG_NOTCLASS(DBG_C_FILES | DBG_C_DL))
130 return;
132 Dbg_util_nl(lml, DBG_NL_STD);
133 dbg_print(lml, MSG_INTL(MSG_DL_DLDUMP), ipath, NAME(clmp),
134 opath ? opath : MSG_INTL(MSG_STR_NULL),
135 conv_dl_flag(flags, 0, &dl_flag_buf));
138 void
139 Dbg_dl_dlerror(Rt_map *clmp, const char *str)
141 Lm_list *lml = LIST(clmp);
143 if (DBG_NOTCLASS(DBG_C_DL))
144 return;
146 Dbg_util_nl(lml, DBG_NL_STD);
147 dbg_print(lml, MSG_INTL(MSG_DL_DLERROR), NAME(clmp),
148 str ? str : MSG_INTL(MSG_STR_NULL));
151 void
152 Dbg_dl_dladdr(Rt_map *clmp, void *addr)
154 Lm_list *lml = LIST(clmp);
156 if (DBG_NOTCLASS(DBG_C_DL))
157 return;
159 Dbg_util_nl(lml, DBG_NL_STD);
160 dbg_print(lml, MSG_INTL(MSG_DL_DLADDR), NAME(clmp), EC_NATPTR(addr));
163 void
164 Dbg_dl_dlsym(Rt_map *clmp, const char *sym, int *in_nfavl, const char *next,
165 int type)
167 const char *str, *retry, *from = NAME(clmp);
168 Lm_list *lml = LIST(clmp);
170 static const Msg dlsym_msg[DBG_DLSYM_NUM] = {
171 MSG_STR_EMPTY, /* MSG_ORIG(MSG_STR_EMPTY) */
172 MSG_DLSYM_NEXT, /* MSG_ORIG(MSG_DLSYM_NEXT) */
173 MSG_DLSYM_DEFAULT, /* MSG_ORIG(MSG_DLSYM_DEFAULT) */
174 MSG_DLSYM_SELF, /* MSG_ORIG(MSG_DLSYM_SELF) */
175 MSG_DLSYM_PROBE, /* MSG_ORIG(MSG_DLSYM_PROBE) */
176 MSG_DLSYM_SINGLETON /* MSG_ORIG(MSG_DLSYM_SINGLETON) */
178 #if DBG_DLSYM_NUM != (DBG_DLSYM_SINGLETON + 1)
179 #error DBG_DLSYM_NUM has grown
180 #endif
181 if (DBG_NOTCLASS(DBG_C_SYMBOLS | DBG_C_DL))
182 return;
185 * The core functionality of dlsym() can be called twice. The first
186 * attempt can be affected by path names that exist in the "not-found"
187 * AVL tree. Should a "not-found" path name be found, a second attempt
188 * is made to locate the required file (in_nfavl is NULL). This fall-
189 * back provides for file system changes while a process executes.
191 if (in_nfavl)
192 retry = MSG_ORIG(MSG_STR_EMPTY);
193 else
194 retry = MSG_INTL(MSG_STR_RETRY);
196 if (type >= DBG_DLSYM_NUM)
197 type = 0;
198 str = MSG_ORIG(dlsym_msg[type]);
200 Dbg_util_nl(lml, DBG_NL_STD);
201 if (next == 0)
202 dbg_print(lml, MSG_INTL(MSG_DLSYM_1), Dbg_demangle_name(sym),
203 from, retry, str);
204 else
205 dbg_print(lml, MSG_INTL(MSG_DLSYM_2), Dbg_demangle_name(sym),
206 from, next, retry, str);
209 void
210 Dbg_dl_dlinfo(Rt_map *clmp, const char *name, int request, void *addr)
212 Lm_list *lml = LIST(clmp);
214 if (DBG_NOTCLASS(DBG_C_DL))
215 return;
217 Dbg_util_nl(lml, DBG_NL_STD);
218 dbg_print(lml, MSG_INTL(MSG_DL_DLINFO), NAME(clmp), name,
219 conv_dl_info(request), EC_NATPTR(addr));