Search code examples
xcodedebugginggdbbreakpoints

Xcode/GDB -- continue with a method call that is specified in the debugger?


Is this possible?

Basically, what I want to do is, when I am stopped at a breakpoint, I want to have it call [someObject someMethod], then continue. It is important that the method call happen as a part of the continue, rather than separately from it, because if it should hit another breakpoint as a part of the method call, I want it to stop at that breakpoint in the normal way.

Even if it were restricted to class methods, or C functions, this would be a big help.


Solution

  • Yes, this is possible, but unfortunately it is not straightforward.

    Basically, what you are wanting to do is change the execution context (to the function of your choice) of the running process at an arbitrary point in the program.

    You could theoretically create a new execution context by issuing GDB commands and calling functions in the process being debugged, but it will probably be more work than you originally intended it to be.

    I think your best bet if you really want this functionality is to use some sort of instrumentation library such as Valgrind or Pin. These libraries basically take care of all the nitty-gritty details of creating a new execution context at an arbitrary point in a process' execution, and they present a reasonable interface to operating on a running process.