summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Stephani <phst@google.com>2017-06-04 19:05:46 +0200
committerPhilipp Stephani <phst@google.com>2017-06-04 19:50:50 +0200
commit366e25a6d1caa30d8d336ce556f90f9ee46ca531 (patch)
treecb9f9e423e07fa4c122ae3ddb86b2de9230103ec
parent045d21c20a60e2c336568516d620d6f98ca3642d (diff)
downloademacs-366e25a6d1caa30d8d336ce556f90f9ee46ca531.tar.gz
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.
-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/>. */
#include "dynlib.h"
+#include <stddef.h>
+
#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 *
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);
void *dynlib_sym (dynlib_handle_ptr h, const char *sym);
typedef struct dynlib_function_ptr_nonce *(*dynlib_function_ptr) (void);
dynlib_function_ptr dynlib_func (dynlib_handle_ptr h, const char *sym);
-bool dynlib_addr (void *ptr, const char **path, const char **sym);
const char *dynlib_error (void);
int dynlib_close (dynlib_handle_ptr h);
+/* Sets *FILE to the file name from which PTR was loaded, and *SYM to
+ its symbol name. If the file or symbol name could not be
+ determined, set the corresponding argument to NULL. */
+void dynlib_addr (void *ptr, const char **file, const char **sym);
#endif /* DYNLIB_H */