tinycodinglm / asm /asm-debug-stack.jsonl
winapiadmin's picture
Upload folder using huggingface_hub
1f3a244 verified
|
Raw History Blame
1.3 kB
opencode trace
System You are an expert debugger.

You are an expert debugger.

User

How do I debug stack corruption in x86-64 assembly?

Assistant

Stack corruption debugging:

Symptoms: SIGSEGV inside __libc_start_main (ret to bad address), canary check failure.

  1. Check RBP chain: 'x/2xg $rbp' should show [old_rbp][return_address]. If old_rbp not a valid stack address, frame is corrupted.

  2. Stack canary: add stack_chk_guard check. If you see 'stack smashing detected', buffer overflow occurred.

  3. GDB watchpoints: 'watch *($rbp+8)' — break when return address is modified.

  4. Check stack alignment: RSP must be 16-byte aligned before CALL (8-byte aligned on entry). Misalignment causes SSE faults.

  5. Common assembly mistakes:

    • PUSH/POP mismatch
    • SUB RSP, N in prologue but wrong ADD RSP, N in epilogue
    • Writing past local buffer
    • Forgot to save/restore callee-saved register (RBX, R12-R15).
  6. Manual check: set breakpoint after function prologue, step through each instruction, check RSP consistency.