This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [rfc] fbreak (Finish Breakpoints by Name)
- From: Kevin Pouget <kevin dot pouget at gmail dot com>
- To: Tom Tromey <tromey at redhat dot com>
- Cc: Phil Muldoon <pmuldoon at redhat dot com>, "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>
- Date: Tue, 22 Oct 2013 13:14:15 +0200
- Subject: Re: [rfc] fbreak (Finish Breakpoints by Name)
- Authentication-results: sourceware.org; auth=none
- References: <52397B9C dot 1050002 at redhat dot com> <87r4bei95l dot fsf at fleche dot redhat dot com>
On Mon, Oct 21, 2013 at 11:52 PM, Tom Tromey <tromey@redhat.com> wrote:
>
> >>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:
>
> Phil> This command is a usability skin for finish breakpoints. The command,
> Phil> "fbreak" takes a location, and sets a breakpoint on that location.
> Phil> When the breakpoint is hit, the "stop" callback on the initial
> Phil> breakpoint is called. This initial breakpoint then turns on process
> Phil> record, and places a finish breakpoint in that function to catch
> Phil> function exit. When the function completes, the finish breakpoint
> Phil> will print a message.
>
> I think it is cool but I'm not sure about tying it to process record.
> Process record has a lot of limitations.
>
> It seems to me that it would really great as a user if I could attach
> commands to a breakpoint like this. However, right now such commands
> would attach to the initial breakpoint -- not the one that is hit when
> the internal finish breakpoint is hit.
>
> I suppose if we could set commands on both the initial and the finish
> breakpoints, then it would be easy to ask for "record" behavior by hand.
>
> Anyway I think maybe more experimentation is needed.
>
> We could use a place to keep things like this -- useful Python hacks
> that we think aren't quite fully baked enough to put in the core.
>
> Phil> + gdb.write("The finish breakpoint has triggered. If the target\n\
>
> I was under the impression we preferred normal "print" to the use of
> gdb.write.
>
> Phil> + def invoke (self, arg, from_tty):
> Phil> + if arg != "":
> Phil> + linespec = gdb.decode_line (str(arg))
>
> You shouldn't need 'str' here.
>
> Phil> + # Before we set the breakpoint, warn if there was anything
> Phil> + # unparsed.
> Phil> + if linespec[0] != None:
> Phil> + gdb.write("Warning: parts of the expression are unparsed.\n")
>
> IMO this ought to be an error.
>
> Tom
hello,
just my 2c,
> I suppose if we could set commands on both the initial and the finish
> breakpoints, then it would be easy to ask for "record" behavior by hand.
that looks like the way I use Breakpoints+FinishBreakpoints in
FunctionBreakpoints:
> class FunctionBreakpoint(gdb.Breakpoint):
> def __init__ (self, spec):
> gdb.Breakpoint.__init__ (self, spec, internal=True)
>
> self.silent = True
>
> def stop (self):
> ret = self.prepare_before()
> if ret is None:
> #spurious stop
> return False
>
> (fct_stop, fct_finish, fct_data) = ret
>
> if fct_finish:
> FunctionFinishBreakpoint(self, fct_data)
>
> return fct_stop
>
>
> # to override
> def prepare_before(self):
> return None
>
> # to override
> def prepare_after(self, data):
> return False
>
> class FunctionFinishBreakpoint (gdb.FinishBreakpoint):
> def __init__ (self, parent, fct_data):
> gdb.FinishBreakpoint.__init__(self, internal=True)
> self.silent = True
> self.parent = parent
> self.fct_data = fct_data
>
> def stop(self):
> return fct_stop = self.parent.prepare_after(self.fct_data)
>
> def out_of_scope(self):
> pass
you extend class FunctionBreakpoint and implement "prepare_before" and
"prepare_after". Method "prepare_before" should return a triplet (stop
the execution at this point ; do finish breakpoint stop at exit point
; and data to be passed to "prepare_after" ). Method "prepare_after"
returns true/false to stop or not the execution.
In my use-cases, "fct_data" is used to transmit function arguments to
check at the function exit, for instance in
> int MPI_Comm_size( MPI_Comm comm, int *size)
you read argument 2 (size) address, and at function exit you read its
actual value.
Cheers,
Kevin