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 π
libunwind(3libunwind)unw_get_proc_info(3libunwind)unw_get_proc_name(3libunwind)unw_get_elf_filename_by_ip(3libunwind)addr2line(1addr2line)
π 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. π β¨
π¦ where this page comes from
- alpine 3.22: libunwind-doc 1.8.1-r0 Β· MIT
- alpine 3.23: libunwind-doc 1.8.1-r0 Β· MIT
- alpine 3.24: libunwind-doc 1.8.3-r0 Β· MIT
- arch rolling: libunwind 1.8.3-1 Β· MIT
- epel 10: libunwind-devel 1.8.0-4.el10_0 Β· MIT
- epel 9: libunwind-devel 1.8.0-4.el9 Β· MIT
- fedora 43: libunwind-devel 1.8.1-3.fc43 Β· MIT
- fedora 43: libunwind-devel 1.8.1-3.fc43 Β· MIT
- fedora 43: libunwind-devel 1.8.3-4.fc43 Β· MIT
- fedora 43: libunwind-devel 1.8.3-4.fc43 Β· MIT
- fedora 44: libunwind-devel 1.8.3-1.fc44 Β· MIT
- fedora 44: libunwind-devel 1.8.3-1.fc44 Β· MIT
- fedora 44: libunwind-devel 1.8.3-4.fc44 Β· MIT
- fedora 44: libunwind-devel 1.8.3-4.fc44 Β· MIT
- nixpkgs unstable: libunwind 1.8.3-devman
- opensuse-leap 16.0: libunwind-devel 1.8.1-160000.2.2 Β· MIT
- opensuse-leap 16.0: libunwind-devel 1.8.1-160000.2.2 Β· MIT
- opensuse-leap 16.0: libunwind-devel 1.8.1-160000.2.2 Β· MIT
- opensuse-leap 16.0: libunwind-devel 1.8.1-160000.2.2 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms