summaryrefslogtreecommitdiff
path: root/usr/src/cmd/sgs/liblddbg/common/dlfcns.c
blob: 62a076ebd2e233b1919bfd7f97b07db4db02043b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#include	"msg.h"
#include	"_debug.h"
#include	"libld.h"

void
Dbg_dl_iphdr_enter(Rt_map *clmp, u_longlong_t cnt_map, u_longlong_t cnt_unmap)
{
	Lm_list	*lml = LIST(clmp);

	if (DBG_NOTCLASS(DBG_C_DL))
		return;

	Dbg_util_nl(lml, DBG_NL_STD);
	dbg_print(lml, MSG_INTL(MSG_DL_IPHDR_ENTER), NAME(clmp));
	dbg_print(lml, MSG_INTL(MSG_DL_IPHDR_MAPCNT), cnt_map, cnt_unmap);
}

void
Dbg_dl_iphdr_callback(Lm_list *lml, struct dl_phdr_info *info)
{
	if (DBG_NOTCLASS(DBG_C_DL))
		return;

	dbg_print(lml, MSG_INTL(MSG_DL_IPHDR_CALLBACK));
	dbg_print(lml, MSG_INTL(MSG_DL_IPHDR_NAME), info->dlpi_name);
	dbg_print(lml, MSG_INTL(MSG_DL_IPHDR_ADDR), EC_ADDR(info->dlpi_addr));
	dbg_print(lml, MSG_INTL(MSG_DL_IPHDR_PHDR),
	    EC_ADDR(CAST_PTRINT(Addr, info->dlpi_phdr)),
	    EC_WORD(info->dlpi_phnum));
}

void
Dbg_dl_iphdr_mapchange(Lm_list *lml, u_longlong_t cnt_map,
    u_longlong_t cnt_unmap)
{
	if (DBG_NOTCLASS(DBG_C_DL))
		return;

	dbg_print(lml, MSG_INTL(MSG_DL_IPHDR_MAPCNG));
	dbg_print(lml, MSG_INTL(MSG_DL_IPHDR_MAPCNT), cnt_map, cnt_unmap);
}

void
Dbg_dl_iphdr_unmap_ret(Lm_list *lml)
{
	if (DBG_NOTCLASS(DBG_C_DL))
		return;

	dbg_print(lml, MSG_INTL(MSG_DL_IPHDR_UNMAP));
}

void
Dbg_dl_dlopen(Rt_map *clmp, const char *name, int *in_nfavl, int mode)
{
	Conv_dl_mode_buf_t	dl_mode_buf;
	Lm_list			*lml = LIST(clmp);
	const char		*retry;

	if (DBG_NOTCLASS(DBG_C_FILES | DBG_C_DL))
		return;

	/*
	 * The core functionality of dlopen() can be called twice.  The first
	 * attempt can be affected by path names that exist in the "not-found"
	 * AVL tree.  Should a "not-found" path name be found, a second attempt
	 * is made to locate the required file (in_nfavl is NULL).  This fall-
	 * back provides for file system changes while a process executes.
	 */
	if (in_nfavl)
		retry = MSG_ORIG(MSG_STR_EMPTY);
	else
		retry = MSG_INTL(MSG_STR_RETRY);

	Dbg_util_nl(lml, DBG_NL_STD);
	dbg_print(lml, MSG_INTL(MSG_DL_DLOPEN), name, NAME(clmp), retry,
	    conv_dl_mode(mode, 0, &dl_mode_buf));
}

void
Dbg_dl_dlclose(Rt_map *clmp, const char *name, int flag)
{
	const char	*str;
	Lm_list		*lml = LIST(clmp);

	if (DBG_NOTCLASS(DBG_C_FILES | DBG_C_DL))
		return;

	if (flag == DBG_DLCLOSE_IGNORE)
		str = MSG_INTL(MSG_STR_IGNORE);
	else
		str = MSG_ORIG(MSG_STR_EMPTY);

	Dbg_util_nl(lml, DBG_NL_STD);
	dbg_print(lml, MSG_INTL(MSG_DL_DLCLOSE), name, NAME(clmp), str);
}

void
Dbg_dl_dldump(Rt_map *clmp, const char *ipath, const char *opath, int flags)
{
	Conv_dl_flag_buf_t	dl_flag_buf;
	Lm_list			*lml = LIST(clmp);

	if (DBG_NOTCLASS(DBG_C_FILES | DBG_C_DL))
		return;

	Dbg_util_nl(lml, DBG_NL_STD);
	dbg_print(lml, MSG_INTL(MSG_DL_DLDUMP), ipath, NAME(clmp),
	    opath ? opath : MSG_INTL(MSG_STR_NULL),
	    conv_dl_flag(flags, 0, &dl_flag_buf));
}

void
Dbg_dl_dlerror(Rt_map *clmp, const char *str)
{
	Lm_list	*lml = LIST(clmp);

	if (DBG_NOTCLASS(DBG_C_DL))
		return;

	Dbg_util_nl(lml, DBG_NL_STD);
	dbg_print(lml, MSG_INTL(MSG_DL_DLERROR), NAME(clmp),
	    str ? str : MSG_INTL(MSG_STR_NULL));
}

void
Dbg_dl_dladdr(Rt_map *clmp, void *addr)
{
	Lm_list	*lml = LIST(clmp);

	if (DBG_NOTCLASS(DBG_C_DL))
		return;

	Dbg_util_nl(lml, DBG_NL_STD);
	dbg_print(lml, MSG_INTL(MSG_DL_DLADDR), NAME(clmp), EC_NATPTR(addr));
}

void
Dbg_dl_dlsym(Rt_map *clmp, const char *sym, int *in_nfavl, const char *next,
    int type)
{
	const char	*str, *retry, *from = NAME(clmp);
	Lm_list		*lml = LIST(clmp);

	static const Msg	dlsym_msg[DBG_DLSYM_NUM] = {
		MSG_STR_EMPTY,		/* MSG_ORIG(MSG_STR_EMPTY) */
		MSG_DLSYM_NEXT,		/* MSG_ORIG(MSG_DLSYM_NEXT) */
		MSG_DLSYM_DEFAULT,	/* MSG_ORIG(MSG_DLSYM_DEFAULT) */
		MSG_DLSYM_SELF,		/* MSG_ORIG(MSG_DLSYM_SELF) */
		MSG_DLSYM_PROBE,	/* MSG_ORIG(MSG_DLSYM_PROBE) */
		MSG_DLSYM_SINGLETON	/* MSG_ORIG(MSG_DLSYM_SINGLETON) */
	};
#if	DBG_DLSYM_NUM != (DBG_DLSYM_SINGLETON + 1)
#error	DBG_DLSYM_NUM has grown
#endif
	if (DBG_NOTCLASS(DBG_C_SYMBOLS | DBG_C_DL))
		return;

	/*
	 * The core functionality of dlsym() can be called twice.  The first
	 * attempt can be affected by path names that exist in the "not-found"
	 * AVL tree.  Should a "not-found" path name be found, a second attempt
	 * is made to locate the required file (in_nfavl is NULL).  This fall-
	 * back provides for file system changes while a process executes.
	 */
	if (in_nfavl)
		retry = MSG_ORIG(MSG_STR_EMPTY);
	else
		retry = MSG_INTL(MSG_STR_RETRY);

	if (type >= DBG_DLSYM_NUM)
		type = 0;
	str = MSG_ORIG(dlsym_msg[type]);

	Dbg_util_nl(lml, DBG_NL_STD);
	if (next == 0)
		dbg_print(lml, MSG_INTL(MSG_DLSYM_1), Dbg_demangle_name(sym),
		    from, retry, str);
	else
		dbg_print(lml, MSG_INTL(MSG_DLSYM_2), Dbg_demangle_name(sym),
		    from, next, retry, str);
}

void
Dbg_dl_dlinfo(Rt_map *clmp, const char *name, int request, void *addr)
{
	Lm_list	*lml = LIST(clmp);

	if (DBG_NOTCLASS(DBG_C_DL))
		return;

	Dbg_util_nl(lml, DBG_NL_STD);
	dbg_print(lml, MSG_INTL(MSG_DL_DLINFO), NAME(clmp), name,
	    conv_dl_info(request), EC_NATPTR(addr));
}