Toolchain, Debugging & Inline Assembly
Assemblers, linkers, objdump, GDB with QEMU, and inline assembly in C.
This lesson collects the practical tooling: how source becomes a binary, how to look inside binaries, how to debug at the instruction level, and how to put a few instructions inside C code when a whole assembly file is not needed. (No example output here: these are tool commands.)
Inline assembly
__asm__("msr primask, %0" :: "r"(x)); // no volatile, no memory clobber
__asm__ volatile("msr primask, %0" :: "r"(x) : "memory");
Without volatile and a memory clobber, the compiler may move or remove the statement, or reorder memory accesses across it.
How can you debug an AArch64 Linux program on an x86 PC?
Run it under QEMU user mode with a GDB stub (qemu-aarch64 -g 1234 ./prog) and connect gdb-multiarch to it (target remote :1234).