File size: 1,298 Bytes
1f3a244 | 1 2 3 4 5 | {"type": "session", "harness": "opencode", "id": "asm-debug-stack", "name": "Debugging x86-64 Stack Corruption"}
{"type": "message", "message": {"role": "system", "content": "You are an expert debugger."}}
{"type": "message", "message": {"role": "user", "content": "How do I debug stack corruption in x86-64 assembly?"}}
{"type": "message", "message": {"role": "assistant", "content": "Stack corruption debugging:\n\nSymptoms: SIGSEGV inside __libc_start_main (ret to bad address), canary check failure.\n\n1. Check RBP chain: 'x/2xg $rbp' should show [old_rbp][return_address]. If old_rbp not a valid stack address, frame is corrupted.\n\n2. Stack canary: add stack_chk_guard check. If you see 'stack smashing detected', buffer overflow occurred.\n\n3. GDB watchpoints: 'watch *($rbp+8)' — break when return address is modified.\n\n4. Check stack alignment: RSP must be 16-byte aligned before CALL (8-byte aligned on entry). Misalignment causes SSE faults.\n\n5. Common assembly mistakes:\n - PUSH/POP mismatch\n - SUB RSP, N in prologue but wrong ADD RSP, N in epilogue\n - Writing past local buffer\n - Forgot to save/restore callee-saved register (RBX, R12-R15).\n\n6. Manual check: set breakpoint after function prologue, step through each instruction, check RSP consistency."}}
|