mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-04-27 08:43:40 -07:00
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.
This commit is contained in:
parent
045d21c20a
commit
366e25a6d1
2 changed files with 19 additions and 20 deletions
34
src/dynlib.c
34
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 *
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue