UNW_GET_REG(3libunwind)
π UNW_GET_REG π
okay bestie, welcome to unw_get_reg from the 3libunwind manual β this is the one that pulls a register's value out of a stack frame and hands it to you. it's giving "peek behind the curtain" energy, fr fr. β¨
β¨ NAME β¨
unw_get_reg β get register contents π«Ά
πΈ SYNOPSIS πΈ
#include <libunwind.h>
int unw_get_reg(unw_cursor_t *cp, unw_regnum_t reg, unw_word_t *valp);
π DESCRIPTION π
so, unw_get_reg() does the thing: it reads the value of register reg in the stack frame that cursor cp is pointing at, and it drops that value into the word that valp points to. literally just "gimme what's in this register rn" and it does. no cap. π
now, the register numbering is target dependent, and it's described in its own separate manual pages (like, for example, libunwind-ia64(3libunwind) for the IA-64 target). so don't assume the numbers mean the same thing everywhere, bestie, they do not. π
also β and this is important β the exact set of accessible registers can depend on what type of frame cp is referring to. for ordinary stack frames, you can normally only get at the preserved (aka "callee-saved") registers and the frame-related registers (like the stack-pointer). that's just how it is. but for signal frames (peep unw_is_signal_frame(3libunwind)), it's usually possible to access all the registers. slay. π
one more thing, and don't come for me: unw_get_reg() can only read the contents of registers whose values fit inside a single word. if you need a register that doesn't fit that constraint, go see unw_get_fpreg(3libunwind) β that's the one for you. π
β RETURN VALUE β
on successful completion, unw_get_reg() returns 0. π otherwise it returns the negative value of one of the error codes listed below. so like, success is zero, and everything else is sad and negative.
π¦ THREAD AND SIGNAL SAFETY π¦
unw_get_reg() is thread safe, and it's also safe to use from a signal handler. main character behaviour honestly. π
π ERRORS π
UNW_EUNSPECβ an unspecified error occurred. π we don't know what happened, and that's the whole report.UNW_EBADREGβ an attempt was made to read a register that is either invalid or not accessible in the current frame. π
on top of that, unw_get_reg() may return any error returned by the access_mem(), access_reg(), and access_fpreg() callbacks (check unw_create_addr_space(3libunwind) for those).
real talk: if you get an error back, it's a negative number, and the two named codes above aren't the only possibilities β the callbacks can hand you their own errors too. don't forget that part. π«Ά
π SEE ALSO π
libunwind(3libunwind)libunwind-ia64(3libunwind)unw_get_fpreg(3libunwind)unw_is_signal_frame(3libunwind)unw_set_reg(3libunwind)
π AUTHOR π
David Mosberger-Tang Email: dmosberger@gmail.com WWW: http://www.nongnu.org/libunwind/
and that's the whole page, bestie!! this one came from the Programming Library crew, dated 29 August 2023 β so if you're citing it or checking freshness, that's the version and date to remember. mwah, go read your registers responsibly. ππΈβ¨
π¦ 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