Search code examples
processgdbcodeblockspid

Why won't CodeBlocks attach to a process?


I recently ran into an issue that I want to share Q&A style here. Hopefully it will help others, at minimum it is documented so I can find it later :)

When trying to run Ncurses in CodeBlocks it blows up when it hit initscr();. With VSCode this was not a problem, so I know there was something I am missing. With the help of StackOverflow it appears the best way to approach this with gdb (and CodeBlocks) is to attach to the process itself after it is running, rather than starting it in CodeBlocks. (Debugging ncurses application with gdb)

However, when I try to attach to the PID it just says that it was unable to attach to the process. Why is this?


Solution

  • I found that if I tried to run it through gdb on the commandline I also got this same issue. It comes from Kernal Hardening to prevent hacking. With this answer: https://stackoverflow.com/a/32274645/1770034

    I discovered I needed to switch over to the root user. Then run echo 0 > /proc/sys/kernel/yama/ptrace_scope Now Code blocks will happily attach to the process and you can use your break points.