Go to main content

man pages section 3: Extended Library Functions, Volume 2

Exit Print View

Updated: Wednesday, July 27, 2022
 
 

dtrace_lookup_by_name(3DTRACE)

Name

dtrace_lookup_by_addr, dtrace_lookup_by_name - Look up symbols by name or address

Synopsis

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);

Description

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.

Return Values

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.

Errors

The dtrace_lookup_by_name() function will fail if:

EINVAL

dtp or name is NULL.

EDT_NOMOD

The named module, object does not exist.

EDT_NOSYM

The symbol does not exist in the specified module.

EDT_NOMEM

The system failed to allocate memory while processing this function.

The dtrace_lookup_by_addr() function will fail if:

EINVAL

dtp is NULL.

EDT_NOSYMADDR

No symbol corresponds to the given address.

EDT_NOMEM

The system failed to allocate memory while processing this function.

Usage

The object argument to the dtrace_lookup_by_name() function can take the following special values:

DTRACE_OBJ_EXEC

Primary executable file

DTRACE_OBJ_RTLD

Runtime link-editor

DTRACE_OBJ_CDEFS

C include definitions

DTRACE_OBJ_DDEFS

D program definitions

DTRACE_OBJ_EVERY

All known objects

DTRACE_OBJ_KMODS

All kernel objects

DTRACE_OBJ_UMODS

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;

Examples

Example 1 Using dtrace_lookup_by_name() and dtrace_lookup_by_addr()

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);
	}

Attributes

See attributes(7) for descriptions of the following attributes:

ATTRIBUTE TYPE
ATTRIBUTE VALUE
Architecture
All
Availability
system/dtrace
Interface Stability
Committed
MT-Level
Safe

See Also

libdtrace(3LIB), dtrace_errno(3DTRACE), gelf(3ELF)