So I have a really large pointer, p, pointing to roughly 40 bytes.
I also know that these 40 bytes enclose ints, chars, and other pointers. I know how to hop across these 40 bytes too.
For debug purposes I want to print out these contents. How do I do that?
For example, lets say I know that at p+16 there is an int and I want to print this int. Is there a way to “print 4 bytes from this address and format that as an int” in C?
Yes, just cast & dereference. Assuming you have
palready set up:Watch out for potential alignment issues – for example, this code:
might cause an exception on some processors (assuming
pis safely aligned for anint, that is). In that case, you’ll need to assemble the bytes yourself. Here’s an example assuming a 4-byte integer and 8-bit bytes. Make sure to watch out for endianness: