aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPhilipp Stephani2017-06-04 19:05:46 +0200
committerPhilipp Stephani2017-06-04 19:50:50 +0200
commit366e25a6d1caa30d8d336ce556f90f9ee46ca531 (patch)
treecb9f9e423e07fa4c122ae3ddb86b2de9230103ec /src
parent045d21c20a60e2c336568516d620d6f98ca3642d (diff)
downloademacs-366e25a6d1caa30d8d336ce556f90f9ee46ca531.tar.gz
emacs-366e25a6d1caa30d8d336ce556f90f9ee46ca531.zip
Simplify interface of dynlib_attr.
Instead of returning bool, set the argument pointers to NULL if the information is not available. * src/dynlib.c (dynlib_addr): Don't return bool.
Diffstat (limited to 'src')
-rw-r--r--src/dynlib.c34
-rw-r--r--src/dynlib.h5
2 files changed, 19 insertions, 20 deletions
diff --git a/src/dynlib.c b/src/dynlib.c
index 95619236d43..79e98b0f288 100644
--- a/src/dynlib.c
+++ b/src/dynlib.c
@@ -28,6 +28,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
28 28
29#include "dynlib.h" 29#include "dynlib.h"
30 30
31#include <stddef.h>
32
31#ifdef WINDOWSNT 33#ifdef WINDOWSNT
32 34
33/* MS-Windows systems. */ 35/* MS-Windows systems. */
@@ -120,7 +122,7 @@ dynlib_sym (dynlib_handle_ptr h, const char *sym)
120 return (void *)sym_addr; 122 return (void *)sym_addr;
121} 123}
122 124
123bool 125void
124dynlib_addr (void *addr, const char **fname, const char **symname) 126dynlib_addr (void *addr, const char **fname, const char **symname)
125{ 127{
126 static char dll_filename[MAX_UTF8_PATH]; 128 static char dll_filename[MAX_UTF8_PATH];
@@ -128,7 +130,6 @@ dynlib_addr (void *addr, const char **fname, const char **symname)
128 static GetModuleHandleExA_Proc s_pfn_Get_Module_HandleExA = NULL; 130 static GetModuleHandleExA_Proc s_pfn_Get_Module_HandleExA = NULL;
129 char *dll_fn = NULL; 131 char *dll_fn = NULL;
130 HMODULE hm_kernel32 = NULL; 132 HMODULE hm_kernel32 = NULL;
131 bool result = false;
132 HMODULE hm_dll = NULL; 133 HMODULE hm_dll = NULL;
133 wchar_t mfn_w[MAX_PATH]; 134 wchar_t mfn_w[MAX_PATH];
134 char mfn_a[MAX_PATH]; 135 char mfn_a[MAX_PATH];
@@ -206,23 +207,18 @@ dynlib_addr (void *addr, const char **fname, const char **symname)
206 dynlib_last_err = GetLastError (); 207 dynlib_last_err = GetLastError ();
207 } 208 }
208 if (dll_fn) 209 if (dll_fn)
209 { 210 dostounix_filename (dll_fn);
210 dostounix_filename (dll_fn);
211 /* We cannot easily produce the function name, since
212 typically all of the module functions will be unexported,
213 and probably even static, which means the symbols can be
214 obtained only if we link against libbfd (and the DLL can
215 be stripped anyway). So we just show the address and the
216 file name; they can use that with addr2line or GDB to
217 recover the symbolic name. */
218 sprintf (addr_str, "at 0x%x", (DWORD_PTR)addr);
219 *symname = addr_str;
220 result = true;
221 }
222 } 211 }
223 212
224 *fname = dll_fn; 213 *fname = dll_fn;
225 return result; 214
215 /* We cannot easily produce the function name, since typically all
216 of the module functions will be unexported, and probably even
217 static, which means the symbols can be obtained only if we link
218 against libbfd (and the DLL can be stripped anyway). So we just
219 show the address and the file name; they can use that with
220 addr2line or GDB to recover the symbolic name. */
221 *symname = NULL;
226} 222}
227 223
228const char * 224const char *
@@ -283,19 +279,19 @@ dynlib_sym (dynlib_handle_ptr h, const char *sym)
283 return dlsym (h, sym); 279 return dlsym (h, sym);
284} 280}
285 281
286bool 282void
287dynlib_addr (void *ptr, const char **path, const char **sym) 283dynlib_addr (void *ptr, const char **path, const char **sym)
288{ 284{
285 *path = NULL;
286 *sym = NULL;
289#ifdef HAVE_DLADDR 287#ifdef HAVE_DLADDR
290 Dl_info info; 288 Dl_info info;
291 if (dladdr (ptr, &info) && info.dli_fname && info.dli_sname) 289 if (dladdr (ptr, &info) && info.dli_fname && info.dli_sname)
292 { 290 {
293 *path = info.dli_fname; 291 *path = info.dli_fname;
294 *sym = info.dli_sname; 292 *sym = info.dli_sname;
295 return true;
296 } 293 }
297#endif 294#endif
298 return false;
299} 295}
300 296
301const char * 297const char *
diff --git a/src/dynlib.h b/src/dynlib.h
index 5ccec11bc79..6246c6a6642 100644
--- a/src/dynlib.h
+++ b/src/dynlib.h
@@ -27,8 +27,11 @@ dynlib_handle_ptr dynlib_open (const char *path);
27void *dynlib_sym (dynlib_handle_ptr h, const char *sym); 27void *dynlib_sym (dynlib_handle_ptr h, const char *sym);
28typedef struct dynlib_function_ptr_nonce *(*dynlib_function_ptr) (void); 28typedef struct dynlib_function_ptr_nonce *(*dynlib_function_ptr) (void);
29dynlib_function_ptr dynlib_func (dynlib_handle_ptr h, const char *sym); 29dynlib_function_ptr dynlib_func (dynlib_handle_ptr h, const char *sym);
30bool dynlib_addr (void *ptr, const char **path, const char **sym);
31const char *dynlib_error (void); 30const char *dynlib_error (void);
32int dynlib_close (dynlib_handle_ptr h); 31int dynlib_close (dynlib_handle_ptr h);
32/* Sets *FILE to the file name from which PTR was loaded, and *SYM to
33 its symbol name. If the file or symbol name could not be
34 determined, set the corresponding argument to NULL. */
35void dynlib_addr (void *ptr, const char **file, const char **sym);
33 36
34#endif /* DYNLIB_H */ 37#endif /* DYNLIB_H */