UNW_GET...ILENAME(3libunwind)

πŸ’– UNW_GET_ELF_FILENAME πŸ’–

okay so bestie, we're in the libunwind manual, section 3libunwind, and today's main character is unw_get_elf_filename β€” the "get backing elf filename" girlie. she's niche, she's powerful, she's giving debug-info rescue energy. let's go ✨


✨ NAME ✨

unw_get_elf_filename β€” get backing elf filename πŸ¦‹


🌸 SYNOPSIS 🌸

#include <libunwind.h>

int unw_get_elf_filename(unw_cursor_t *cp, char *bufp, size_t len,
unw_word_t *offp);

πŸ’… DESCRIPTION πŸ’…

so basically, unw_get_elf_filename() hands you back the backing elf filename of the current instruction pointer β€” the one that created the stack frame identified by the argument cp. no cap. πŸ‘‘

the bufp argument is a pointer to a character buffer that is at least len bytes long. that buffer is where the name of the procedure gets returned. lowkey important, don't skimp on the buffer size.

the offp argument is a pointer to a word that gets used to return the byte offset of the instruction pointer saved in the stack frame identified by cp, relative to the start of the elf file. so like, filename in one hand, offset in the other. iconic. πŸŽ€

and here's the scenario that makes this whole thing pop off: for an embedded system, the symbol information may has been stripped from a program, and then unw_get_proc_name() may be completely unavailable. πŸ’€ like, gone. but if the host side have the unstripped program with debuginfo, then you can use the addr2line command tool on the host to get the source file name and line number of the instruction pointer β€” using the elf filename in bufp and the address in offp. bestie, that's the glow-up arc right there. 🌈


⭐ RETURN VALUE ⭐

on successful completion, unw_get_elf_filename() returns 0. 🫢 otherwise it returns the negative value of one of the error codes listed below. not me getting a negative number and knowing exactly what it means, iykyk.


🧚 THREAD AND SIGNAL SAFETY 🧚

unw_get_elf_filename() is thread safe. πŸ’œ

if cursor cp is in the local address space, this routine is also safe to use from a signal handler. multitasking queen behavior, fr fr. ✨


πŸ”₯ ERRORS πŸ”₯

  • UNW_EUNSPEC β€” an unspecified error occurred. πŸ™ˆ the classic "something happened, we're not saying what" moment.
  • UNW_ENOINFO β€” libunwind was unable to determine the elf filename of the instruction pointer. 😭 she tried, she really did.
  • UNW_ENOMEM β€” the elf filename is too long to fit in the buffer provided. a truncated version of the name has been returned, so like… you got a name, just not the whole name. πŸ’€
heads up bestie: UNW_ENOMEM still gives you something back β€” a truncated version of the name. don't act like you got the full thing, okay? πŸŽ€

πŸ‘‘ SEE ALSO πŸ‘‘


πŸ’– AUTHOR πŸ’–

Xiang Lin Email: myd.xia@gmail.com


and that's the whole page, bestie!! πŸ¦‹ this was the Programming Library manual, dated 15 September 2023, and it lives in the 3libunwind section. go forth and resolve your elf filenames, you absolute legend. periodt. πŸ’…βœ¨