dtrace_lookup_by_addr, dtrace_lookup_by_name - Look up symbols by name or address
cc [ flag… ] file… –ldtrace [ library… ] #include dtrace.h int dtrace_lookup_by_name(dtrace_hdl_t *dtp, const char *object, const char *name, GElf_Sym *symp, dtrace_syminfo_t *sip); int dtrace_lookup_by_addr(dtrace_hdl_t *dtp, GElf_Addr addr, GElf_Sym *symp, dtrace_syminfo_t *sip);
The dtrace_lookup_by_name() function performs a lookup of the symbol name in the module object. The ELF information for the symbol is returned in the symp argument. The DTrace information is returned in the sip argument.
The dtrace_lookup_by_addr() function performs a lookup of the symbol at the specified address, addr. The ELF information for the symbol is returned in the symp argument. The DTrace information is returned in sip.
On successful completion, these functions return 0. Otherwise these functions return -1 and set the DTrace error number to indicate the reason for the failure. See the dtrace_errno(3DTRACE) man page for more information.
The dtrace_lookup_by_name() function will fail if:
dtp or name is NULL.
The named module, object does not exist.
The symbol does not exist in the specified module.
The system failed to allocate memory while processing this function.
The dtrace_lookup_by_addr() function will fail if:
dtp is NULL.
No symbol corresponds to the given address.
The system failed to allocate memory while processing this function.
The object argument to the dtrace_lookup_by_name() function can take the following special values:
Primary executable file
Runtime link-editor
C include definitions
D program definitions
All known objects
All kernel objects
All user objects
Both functions return DTrace information in the sip argument, which has the dtrace_syminfo_t data structure, defined as follows:
typedef struct dtrace_syminfo { const char *dts_object; /* object name */ const char *dts_name; /* symbol name */ ulong_t dts_id; /* symbol id */ } dtrace_syminfo_t;
The following example shows how you can use the dtrace_lookup_by_name() and dtrace_lookup_by_addr() functions:
#include <dtrace.h> #include <stdio.h> #include <stdlib.h> static dtrace_hdl_t *g_dtp; static void fatal(const char *fmt, ...) { va_list ap; va_start(ap, fmt); (void) vfprintf(stderr, fmt, ap); if (fmt[strlen(fmt) - 1] != '\n') (void) fprintf(stderr, ": %s\n", dtrace_errmsg(g_dtp, dtrace_errno(g_dtp))); exit(EXIT_FAILURE); } int main(int argc, char **argv) { int err; GElf_Sym sym; Elf64_Addr addr; dtrace_syminfo_t sip; if ((g_dtp = dtrace_open(DTRACE_VERSION, 0, &err)) == NULL) fatal("cannot open dtrace library: %s\n", dtrace_errmsg(NULL, err)); if (dtrace_lookup_by_name(g_dtp, DTRACE_OBJ_EVERY, "hz", &sym, &sip) < 0) fatal("dtrace_lookup_by_name()"); addr = sym.st_value; printf("hz at 0x%llx in object '%s'\n\n", addr, sip.dts_object); if (dtrace_lookup_by_addr(g_dtp, addr, &sym, &sip) < 0) fatal("dtrace_lookup_by_addr()"); printf("object at 0x%llx is '%s' in module '%s'o\n", addr, sip.dts_name, sip.dts_object); dtrace_close(g_dtp); return (0); }
See attributes(7) for descriptions of the following attributes:
|