Serene Runtime 1.0.0-dev
C runtime for the Serene programming language
Loading...
Searching...
No Matches
srn_dbg_sym.c File Reference
#include "serene/utils/srn_dbg_sym.h"
#include <dlfcn.h>
#include <string.h>
Include dependency graph for srn_dbg_sym.c:

Go to the source code of this file.

Functions

const char * srn_dbg_sym_name (void *addr, char *buf, size_t buflen)
 Resolve addr to a symbol name and write it into buf (null-terminated, at most buflen bytes including the terminator).

Function Documentation

◆ srn_dbg_sym_name()

const char * srn_dbg_sym_name ( void * addr,
char * buf,
size_t buflen )

Resolve addr to a symbol name and write it into buf (null-terminated, at most buflen bytes including the terminator).

Returns buf on success, nullptr when resolution fails or buflen is zero.

Definition at line 26 of file srn_dbg_sym.c.

26 {
27 if (buflen == 0) {
28 return nullptr;
29 }
30
31 Dl_info info;
32 if (dladdr(addr, &info) && info.dli_sname != nullptr) {
33 strncpy(buf, info.dli_sname, buflen - 1);
34 buf[buflen - 1] = '\0';
35 return buf;
36 }
37
38 return nullptr;
39}
Here is the caller graph for this function: