Bug 24186 - making a breakpoint conditional on the type at the breakpoint site
Summary: making a breakpoint conditional on the type at the breakpoint site
Status: RESOLVED INVALID
Alias: None
Product: gdb
Classification: Unclassified
Component: breakpoints (show other bugs)
Version: 8.2
: P2 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-02-07 13:49 UTC by Noel Grandin
Modified: 2019-02-08 09:50 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Noel Grandin 2019-02-07 13:49:18 UTC
If I have

  class Foo {
      bar() {
          stuff(); // line 120
      }
      virtual ~Foo() {}
  };
  class FooSubclass : public Foo {
  };

I want to be able to do something like

  $ br foo.cxx:120 if ptype(*this) == "FooSubclass*"

so that I can filter breakpoints on the subtype of Foo

thanks
Comment 1 Tom Tromey 2019-02-07 15:11:10 UTC
You can use the typeof convenience function:

https://github.com/tromey/gdb-helpers/blob/master/gdbhelpers/typeof.py

This could be upstreamed I suppose.


In this particular case you can probably use dynamic_cast though.
Could you try:

break foo.cxx:120 if dynamic_cast<FooSubclass*>(this)

?
Comment 2 Noel Grandin 2019-02-08 06:48:54 UTC
Note: I'm debugging LibreOffice.

doing this
  $ br VclReferenceBase::acquire if dynamic_cast<ToolBox*>(this)
will stop at every acquire regardless of the type of this

doing this
  $ br VclReferenceBase::acquire if dynamic_cast<ToolBox*>(this) != nullptr
will never stop
Comment 3 Noel Grandin 2019-02-08 09:50:22 UTC
And I reboot my machine, and for some reason

   $ br VclReferenceBase::acquire if dynamic_cast<ToolBox*>(this)

starts working, hmmmm

thanks for the suggestion!