From 366e25a6d1caa30d8d336ce556f90f9ee46ca531 Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Sun, 4 Jun 2017 19:05:46 +0200 Subject: 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. --- src/dynlib.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'src/dynlib.c') 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 . */ #include "dynlib.h" +#include + #ifdef WINDOWSNT /* MS-Windows systems. */ @@ -120,7 +122,7 @@ dynlib_sym (dynlib_handle_ptr h, const char *sym) return (void *)sym_addr; } -bool +void dynlib_addr (void *addr, const char **fname, const char **symname) { static char dll_filename[MAX_UTF8_PATH]; @@ -128,7 +130,6 @@ dynlib_addr (void *addr, const char **fname, const char **symname) static GetModuleHandleExA_Proc s_pfn_Get_Module_HandleExA = NULL; char *dll_fn = NULL; HMODULE hm_kernel32 = NULL; - bool result = false; HMODULE hm_dll = NULL; wchar_t mfn_w[MAX_PATH]; char mfn_a[MAX_PATH]; @@ -206,23 +207,18 @@ dynlib_addr (void *addr, const char **fname, const char **symname) dynlib_last_err = GetLastError (); } if (dll_fn) - { - dostounix_filename (dll_fn); - /* We cannot easily produce the function name, since - typically all of the module functions will be unexported, - and probably even static, which means the symbols can be - obtained only if we link against libbfd (and the DLL can - be stripped anyway). So we just show the address and the - file name; they can use that with addr2line or GDB to - recover the symbolic name. */ - sprintf (addr_str, "at 0x%x", (DWORD_PTR)addr); - *symname = addr_str; - result = true; - } + dostounix_filename (dll_fn); } *fname = dll_fn; - return result; + + /* We cannot easily produce the function name, since typically all + of the module functions will be unexported, and probably even + static, which means the symbols can be obtained only if we link + against libbfd (and the DLL can be stripped anyway). So we just + show the address and the file name; they can use that with + addr2line or GDB to recover the symbolic name. */ + *symname = NULL; } const char * @@ -283,19 +279,19 @@ dynlib_sym (dynlib_handle_ptr h, const char *sym) return dlsym (h, sym); } -bool +void dynlib_addr (void *ptr, const char **path, const char **sym) { + *path = NULL; + *sym = NULL; #ifdef HAVE_DLADDR Dl_info info; if (dladdr (ptr, &info) && info.dli_fname && info.dli_sname) { *path = info.dli_fname; *sym = info.dli_sname; - return true; } #endif - return false; } const char * -- cgit v1.2.1