UNW_GET_PROC_NAME(3libunwind)
π UNW_GET_PROC_NAME π
okay bestie, welcome to libunwind's programming library corner of the world β this one's UNW_GET_PROC_NAME(3libunwind) and she's here to tell you whose function you're staring at. no cap. π¦
β¨ NAME β¨
unw_get_proc_name β get the name of the current procedure. that's it. that's the whole job. she's an icon, she's a legend, and she's the moment. π
πΈ SYNOPSIS πΈ
#include <libunwind.h>
int unw_get_proc_name(unw_cursor_t *cp, char *bufp, size_t len,
unw_word_t *offp);
π DESCRIPTION π
so, the tea: unw_get_proc_name() hands you back the name of the procedure that created the stack frame your cursor cp is pointing at. main character energy fr.
let's break down the little squad of arguments:
cpβ the cursor, aka the pointer to the stack frame we're investigating. this is the one you came here for.bufpβ a pointer to a character buffer that's at leastlenbytes long. this is where the procedure name gets written. she's the delivery vessel. π«Άlenβ how big that buffer is, in bytes. don't be stingy.offpβ a pointer to a word where we stash the byte offset of the instruction-pointer saved in the stack frame identified bycp, measured relative to the start of the procedure.
and here's the example that makes it click, lowkey iconic:
say procedurefoo()starts at address0x40003000. if you invokeunw_get_proc_name()on a stack frame whose instruction pointer value is0x40003080, then the word pointed to byoffpgets0x80β that's assuming the procedure is at least0x80bytes long. math is mathing. β¨
now for the caveats, because bestie we gotta be real:
on some platforms there is no reliable way to tell the difference between procedure names and ordinary labels. and if symbol information has been stripped from a program, procedure names may be completely unavailable, or limited to just the ones exported via a dynamic symbol table. in those cases unw_get_proc_name() may return the name of a label, or of a preceding (nearby) procedure. kinda giving "close enough" energy, ngl.
BUT β and this part is important, don't skip it β the offset returned through offp is always relative to the returned name. which means the value (address) of the returned name plus the returned offset will always equal the instruction pointer of the stack frame identified by cp. so the math stays valid even when the name is a little sus. periodt. π
π₯ RETURN VALUE π₯
on successful completion, unw_get_proc_name() returns 0. slay.
otherwise, she returns the negative value of one of the error codes listed below. not a vibe, but forewarned is forearmed.
π§ THREAD AND SIGNAL SAFETY π§
unw_get_proc_name() is thread safe. π
and if cursor cp is in the local address space, this routine is also safe to use from a signal handler. so yes, she can handle chaos.
β ERRORS β
UNW_EUNSPECβ an unspecified error occurred. mysterious. cryptic. unhelpful but valid. πUNW_ENOINFOβ libunwind was unable to determine the name of the procedure. she tried, bestie, she really did. πUNW_ENOMEMβ the procedure name is too long to fit in the buffer you provided. a truncated version of the name has been returned. (yes, she still gave you something. generous queen.) π
in addition, unw_get_proc_name() may return any error returned by the access_mem() callback β see unw_create_addr_space(3libunwind) for that whole situation.
π SEE ALSO π
π AUTHOR π
David Mosberger-Tang
- Email:
dmosberger@gmail.com - WWW:
http://www.nongnu.org/libunwind/
and that's the whole page, bestie!! this was the Programming Library manual, dated 29 August 2023, and you just read UNW_GET_PROC_NAME(3libunwind) β go forth and get those procedure names, you absolute legend. π¦πβ¨
π¦ where this page comes from
- debian trixie: libunwind-dev 1.8.1-0.1 Β· MIT
- ubuntu questing: libunwind-dev 1.8.1-0.1ubuntu1
- ubuntu resolute: libunwind-dev 1.8.3-0ubuntu1 Β· MIT
- ubuntu stonking: libunwind-dev 1.8.3-0ubuntu1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms