UNW_GET...E_BY_IP(3libunwind)

✨ unw_get_elf_filename_by_ip β€” bestie edition ✨

okay so you wanna know which elf file some instruction pointer came from? say less. this is from libunwind, manual section 3libunwind, and it's giving detective energy but for addresses. πŸ•΅οΈβ™€οΈπŸ’–


🌸 NAME 🌸

unw_get_elf_filename_by_ip β€” get the backing elf filename by instruction pointer. literally that's the whole job. no cap.


πŸŽ€ SYNOPSIS πŸŽ€

#include <libunwind.h>

int unw_get_elf_filename_by_ip(unw_addr_space_t as, unw_word_t ip, char
*bufp, size_t len, unw_word_t *offp, void *arg);

πŸ¦‹ DESCRIPTION πŸ¦‹

so unw_get_elf_filename_by_ip() hands you the backing elf filename for an instruction pointer β€” exactly like unw_get_elf_filename() does, bestie, with one glow-up: the name gets looked up by instruction pointer (IP) instead of by a cursor. same vibe, different lookup key. πŸ’…

here's what you gotta feed it, argument by argument:

  • as β€” the address-space where the instruction pointer should be looked up. if you're looking things up in the local address-space, you can just pass unw_local_addr_space here and call it a day.
  • ip β€” the instruction-pointer you want the elf filename for. the main character of this whole operation, honestly. ✨
  • bufp β€” a pointer to a character buffer that's at least len bytes long. this is where the elf filename gets returned. make sure it's big enough or things get spicy (see UNW_ENOMEM below πŸ‘€).
  • len β€” how long that buffer is, in bytes.
  • offp β€” a pointer to a word used to return the byte offset of the instruction-pointer relative to the start of the elf filename. cute little positional receipt. 🧾
  • arg β€” the address space argument used when accessing the address space. it has the same purpose as the argument of the same name for unw_init_remote().
⚠️ important bestie moment: when you're accessing the local address space (i.e. the first argument is unw_local_addr_space), you must pass NULL for arg. not optional. NULL. periodt.

πŸ’– RETURN VALUE πŸ’–

on successful completion, unw_get_elf_filename_by_ip() returns 0. slay. πŸŽ‰

otherwise, it returns the negative value of one of the error codes listed below. so like, negative. remember that.


πŸ”₯ THREAD AND SIGNAL SAFETY πŸ”₯

unw_get_elf_filename_by_ip() is thread safe. πŸ‘‘

and if the local address-space is passed in argument as, this routine is also safe to use from a signal handler. iconic behaviour, truly.


πŸ’€ ERRORS πŸ’€

  • UNW_EUNSPEC β€” an unspecified error occurred. mystery error, no further info, we move. πŸ™ˆ
  • UNW_ENOINFO β€” libunwind was unable to determine the elf filename of the instruction pointer. it tried, bestie. it just doesn't know. 😭
  • UNW_ENOMEM β€” the elf filename is too long to fit in the buffer you provided. heads up: a truncated version of the name has been returned. so you got something, just not all of it. πŸ“

🌈 SEE ALSO 🌈


πŸ‘‘ AUTHOR πŸ‘‘

Xiang Lin Email: myd.xia@gmail.com


Programming Library Β· 15 September 2023 Β· UNW_GET...E_BY_IP(3libunwind)

and that's the whole page, bestie β€” go look up some elf filenames, you've got this πŸ’…πŸ«Άβœ¨