1

I have multiple different processes communicating over IPC and when debugging a single process using gdb, whenever a breakpoint is hit, I am trying to send a message to other processes. Is there a way to automatically invoke a function/piece of code (NotifyAll()) whenever a breakpoint is hit without manually running commands and invoking the function in the gdb console.

Basically, whenever a gdb debugger is attached to one of these processes, I want gdb to know that it should invoke NotifyAll() whenever a breakpoint (application-wide) is hit.

Chenna V
  • 10,185
  • 11
  • 77
  • 104
  • http://stackoverflow.com/questions/6517423/do-specific-action-when-certain-breakpoint-hits-in-gdb – OldProgrammer Feb 24 '17 at 18:05
  • @OldProgrammer The link you provided is again explicitly defining a set of commands at a specific breakpoint. I am trying to see if I can have this application-wide i.e. not tied to a specific breakpoint – Chenna V Feb 24 '17 at 18:08

1 Answers1

0

Yes, this can be done using the Python scripting capabilities in gdb.

In particular you want to add a listener to gdb.events.stop that checks for a breakpoint stop event, then calls your function. It's possible (I don't know offhand) that you'll have to defer the calling of the function by posting an event to the gdb event loop.

To make this work with the minimum of manual intervention, use the gdb script auto-loading feature to associate this Python script with your application. This will require users to trust the script (read about add-auto-load-safe-path), but that's all.

Note that doing things like this is potentially confusing to people trying to debug your application. For example, setting a breakpoint in the RPC code will cause problems unless your script takes extra care.

Tom Tromey
  • 21,507
  • 2
  • 45
  • 63