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

You are an expert debugger.

User

My x86-64 program segfaults. How do I debug it?

Assistant

Steps to debug segfault in x86-64 assembly:

  1. Identify faulting instruction: run under GDB, 'run' to get SIGSEGV, then 'info registers' shows RIP at fault, RAX=address that caused fault.

  2. Common causes:

    • NULL dereference: RIP has LEA/MOV with 0 address. Check register contents.
    • Use-after-free: memory freed then accessed. Check if register was freed.
    • Stack overflow: RSP near page boundary (below 0x7fff...). Check 'info registers rsp'.
    • Bad addressing mode: [RAX+RCX*4] with bad base/index. Check both registers.
    • Return to invalid address: RET popped garbage into RIP. Check stack alignment.
    • Buffer overflow: wrote past buffer, corrupted return address or RBP.
  3. GDB commands:
    'disassemble $rip-20, $rip+20' β€” code around fault
    'x/10xg $rsp' β€” examine stack
    'x/10xg $rax' β€” examine memory at RAX
    'bt' β€” backtrace (if frame pointer intact)
    'info proc mappings' β€” check if address is mapped

  4. Valgrind: 'valgrind --tool=memcheck ./program' for memory errors.

  5. Address Sanitizer: compile with -fsanitize=address for bounds/heap errors.