One method you can use to attach to a process at a predictable location is to add a looping function to your program that keeps executing until the debugger takes control and you interrupt it.
Add code such as the following to your application:
volatile int endStallForDebugger=0; void stallForDebugger() { while (!endStallForDebugger) ; } int main() { … stallForDebugger(); … }
Run this version of your program.
Attach the debugger to the running process.
Stop the program with Ctrl+C or by using $stoponattach.
Use the set variable debugger command to assign a non-zero value to the stallForDebugger variable, and continue executing the process, so that it exits from the loop. For example:
(idb) set variable endStallForDebugger = 1 (idb) # set any needed breakpoints, and so on (idb) cont
Copyright © 2001-2011, Intel Corporation. All rights reserved.