==== Running it ======= mahoney@cs test_bytes$ make test_bytes gcc -std=c99 -march=athlon64 -O2 test_bytes.c -o test_bytes mahoney@cs test_bytes$ ./test_bytes Using little_endian: This machine is Little-Endian Using big_endian: This machine is Little-Endian (int) 12345 0x 39 30 00 00 (long) 12345 0x 39 30 00 00 (short) 12345 0x 39 30 (float) 12345 0x 00 e4 40 46 (double) 12345 0x 00 00 00 00 80 1c c8 40 &ival 0x 4c a2 fe bf mahoney@cs test_bytes$ ==== Looking at the stack with gdb ===== == (very) short list of some gdb commands == start run l addr list, by default shows 10 lines, optional address b addr set breakpoint, e.g. "break main" or "break 10" p variable print, e.g. "p &x" x/16xb addr examine memory, 16 of hex bytes, e.g. "x/16xb &x" s step forward one line help set variable=value # Compile with debugging symbols $ mahoney@cs test_bytes$ gcc -g test_bytes.c -o test_bytes # gdb symbols $ mahoney@cs test_bytes$ gdb (gdb) start Temporary breakpoint 1 at 0x8048721: file test_bytes.c, line 92. 92 int val = 12345; (gdb) l 87 printf("&ival\n"); 88 show_pointer(pval); 89 } 90 91 int main(int argc, char *argv[]) { 92 int val = 12345; 93 94 if (argc > 1) 95 sscanf(argv[1], "%d", &val); 96 test(val); (gdb) p val -1208193036 (gdb) s 94 if (argc > 1) (gdb) p val $2 = 12345 (gdb) p &val $3 = (int *) 0xbffff82c (gdb) p (char) val $4 = 57 '9' (gdb) x/16xb &val 0xbffff82c: 0x39 0x30 0x00 0x00 0x80 0x87 0x04 0x08 0xbffff834: 0x00 0x00 0x00 0x00 0xb8 0xf8 0xff 0xbf (gdb) x/16ub &val 0xbffff82c: 57 48 0 0 128 135 4 8 0xbffff834: 0 0 0 0 184 248 255 191 ... and so on