Serene Runtime 1.0.0-dev
C runtime for the Serene programming language
Loading...
Searching...
No Matches
srn_dbg_sym.h File Reference

Portable symbol resolution for error trace printing. More...

#include <stddef.h>
Include dependency graph for srn_dbg_sym.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SRN_DBG_SYM_WIN32   0

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

Detailed Description

Portable symbol resolution for error trace printing.

Given a return address captured by __builtin_return_address(0), srn_dbg_sym_name writes the nearest symbol name into a caller-supplied buffer. On POSIX it uses dladdr; on Windows it uses SymFromAddr from DbgHelp.

Resolution is best-effort: when the binary is stripped or the platform has no debug info, the buffer is left empty and the function returns null. Raw addresses are still useful; the caller can pass them to llvm-symbolizer offline.

Definition in file srn_dbg_sym.h.

Macro Definition Documentation

◆ SRN_DBG_SYM_WIN32

#define SRN_DBG_SYM_WIN32   0

Definition at line 40 of file srn_dbg_sym.h.

Function Documentation

◆ srn_dbg_sym_name()

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

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: