public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] gdb/python: add gdb.Breakpoint.source_locations property
@ 2022-03-29 21:27 Simon Farre
  2022-03-29 21:27 ` [PATCH 2/2] gdb/python: add gdb.Breakpoint.addresses property Simon Farre
  2022-03-30  8:58 ` [PATCH 1/2] gdb/python: add gdb.Breakpoint.source_locations property Andrew Burgess
  0 siblings, 2 replies; 5+ messages in thread
From: Simon Farre @ 2022-03-29 21:27 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Farre

This attribute returns the source locations where
this breakpoint was installed. It's returned as a list
of tuples of type (file path: string, line: long).

Currently it's not possible from the Python API to know
where a breakpoint has been installed.

The rationale for this patch is for IDE or debug adapters
as they are called, for instance for VSCode, to be able
to fetch Breakpoint related data directly from Python,
but also makes it possible to get this data for plugins
without having the parse the string output of the command
`info breakpoints`.
---
 gdb/NEWS                   |  5 +++++
 gdb/doc/python.texi        |  8 ++++++++
 gdb/python/py-breakpoint.c | 31 +++++++++++++++++++++++++++++++
 3 files changed, 44 insertions(+)

diff --git a/gdb/NEWS b/gdb/NEWS
index e10062752d0..9e7e41d3bd6 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -16,6 +16,11 @@
      This is the same format that GDB uses when printing address, symbol,
      and offset information from the disassembler.
 
+  ** Added attribute Breakpoint.source_locations
+     This returns a list of (file path, line number) tuples where the
+     Breakpoint was installed. This is the information displayed
+     by the 'info breakpoints' command.
+
 *** Changes in GDB 12
 
 * DBX mode is deprecated, and will be removed in GDB 13
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index 7c414b01d70..0d842af6229 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -6066,6 +6066,14 @@ commands, separated by newlines.  If there are no commands, this
 attribute is @code{None}.  This attribute is writable.
 @end defvar
 
+@defvar Breakpoint.source_locations
+This attribute holds the source locations where the breakpoint installed.
+It returns a list of tuples containing the file path and the line number.
+If the breakpoint has no source location(s), either because it's a pending
+breakpoint or is of a type that doesn't have a source location related to it
+it returns @code{None}. This attribute is not writable.
+@end defvar
+
 @node Finish Breakpoints in Python
 @subsubsection Finish Breakpoints
 
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 5891c3a9735..1b9ac6957a5 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -692,6 +692,35 @@ bppy_get_ignore_count (PyObject *self, void *closure)
   return gdb_py_object_from_longest (self_bp->bp->ignore_count).release ();
 }
 
+/* Python function to get all source locations where this breakpoint is set.
+   returns a list of tuples containing the file path and the line number.  */
+
+static PyObject* bppy_get_source_locations(PyObject *self, void* closure)
+{
+  gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
+  struct breakpoint* bp = self_bp->bp;
+
+  BPPY_REQUIRE_VALID (self_bp);
+
+  if (!is_breakpoint (bp) || pending_breakpoint_p(bp))
+    Py_RETURN_NONE;
+
+  gdbpy_ref<> list (PyList_New (0));
+
+  for (const bp_location* it = bp->loc; it != nullptr; it = it->next)
+    {
+      PyObject* tuple = PyTuple_New(2);
+      if(PyTuple_SetItem(tuple, 0, host_string_to_python_string (it->symtab->filename).release ()) != 0)
+        return nullptr;
+      if(PyTuple_SetItem(tuple, 1, PyLong_FromLong(it->line_number)) != 0)
+        return nullptr;
+      if(PyList_Append(list.get(), tuple) != 0)
+        return nullptr;
+    }
+
+  return list.release();
+}
+
 /* Internal function to validate the Python parameters/keywords
    provided to bppy_init.  */
 
@@ -1264,6 +1293,8 @@ or None if no condition set."},
     "Whether this breakpoint is a temporary breakpoint."},
   { "pending", bppy_get_pending, NULL,
     "Whether this breakpoint is a pending breakpoint."},
+  { "source_locations", bppy_get_source_locations, NULL,
+    "Source file locations where this breakpoint is installed"},
   { NULL }  /* Sentinel.  */
 };
 

base-commit: b8e92c571baed4e794bd62b7bf417fa8bbaf5c95
-- 
2.32.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] gdb/python: add gdb.Breakpoint.addresses property
  2022-03-29 21:27 [PATCH 1/2] gdb/python: add gdb.Breakpoint.source_locations property Simon Farre
@ 2022-03-29 21:27 ` Simon Farre
  2022-03-30  8:56   ` Andrew Burgess
  2022-03-30  8:58 ` [PATCH 1/2] gdb/python: add gdb.Breakpoint.source_locations property Andrew Burgess
  1 sibling, 1 reply; 5+ messages in thread
From: Simon Farre @ 2022-03-29 21:27 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Farre

Currently it's not possible from the Python API to know
where a breakpoint has been installed in memory.

This attribute returns a list of the addresses where
this breakpoint has been installed. This reflects
the same information shown by the command `info b`.

If the breakpoint is pending it will return None,
but also if the breakpoint is not of type "breakpoint"
or "watchpoint" it will also return none.

The rationale for this patch is for IDE or debug adapters
as they are called, for instance for VSCode, to be able
to fetch breakpoint related data directly from Python,
but also useful for plugins that need to query information
about breakpoints.
---
 gdb/NEWS                   |  5 +++++
 gdb/doc/python.texi        |  6 ++++++
 gdb/python/py-breakpoint.c | 26 ++++++++++++++++++++++++++
 3 files changed, 37 insertions(+)

diff --git a/gdb/NEWS b/gdb/NEWS
index 9e7e41d3bd6..1410c7027e8 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -21,6 +21,11 @@
      Breakpoint was installed. This is the information displayed
      by the 'info breakpoints' command.
 
+  ** Added attribute Breakpoint.addresses
+     This returns a list of addresses (as longs) where the
+     breakpoint was installed. This is the same address information
+     displayed by the 'info breakpoint' command
+
 *** Changes in GDB 12
 
 * DBX mode is deprecated, and will be removed in GDB 13
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index 0d842af6229..3511b8b00a4 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -6074,6 +6074,12 @@ breakpoint or is of a type that doesn't have a source location related to it
 it returns @code{None}. This attribute is not writable.
 @end defvar
 
+@defvar Breakpoint.addresses
+This attribute holds the address(es) where the breakpoint was installed.
+If the breakpoint is a pending breakpoint, it returns @code{None}.
+This attribute is not writable.
+@end defvar
+
 @node Finish Breakpoints in Python
 @subsubsection Finish Breakpoints
 
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 1b9ac6957a5..19c7cec815c 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -721,6 +721,30 @@ static PyObject* bppy_get_source_locations(PyObject *self, void* closure)
   return list.release();
 }
 
+/* Python function to get all addresses where this breakpoint is set  */
+
+static PyObject* bppy_get_addresses(PyObject *self, void* closure)
+{
+  gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
+  struct breakpoint* bp = self_bp->bp;
+
+  BPPY_REQUIRE_VALID (self_bp);
+
+  if (pending_breakpoint_p(bp))
+    Py_RETURN_NONE;
+
+  if (!is_breakpoint(bp) && !is_watchpoint(bp))
+    Py_RETURN_NONE;
+
+  gdbpy_ref<> list (PyList_New (0));
+
+  for (const bp_location* it = bp->loc; it != nullptr; it = it->next)
+    if(PyList_Append(list.get(), PyLong_FromLong(it->address)) != 0)
+      return nullptr;
+
+  return list.release();
+}
+
 /* Internal function to validate the Python parameters/keywords
    provided to bppy_init.  */
 
@@ -1295,6 +1319,8 @@ or None if no condition set."},
     "Whether this breakpoint is a pending breakpoint."},
   { "source_locations", bppy_get_source_locations, NULL,
     "Source file locations where this breakpoint is installed"},
+  { "addresses", bppy_get_addresses, NULL,
+    "Get addresses of where this breakpoint is set" },
   { NULL }  /* Sentinel.  */
 };
 
-- 
2.32.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] gdb/python: add gdb.Breakpoint.addresses property
  2022-03-29 21:27 ` [PATCH 2/2] gdb/python: add gdb.Breakpoint.addresses property Simon Farre
@ 2022-03-30  8:56   ` Andrew Burgess
  2022-03-30 10:04     ` Simon Farre
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Burgess @ 2022-03-30  8:56 UTC (permalink / raw)
  To: Simon Farre via Gdb-patches, gdb-patches

Simon Farre via Gdb-patches <gdb-patches@sourceware.org> writes:

> Currently it's not possible from the Python API to know
> where a breakpoint has been installed in memory.
>
> This attribute returns a list of the addresses where
> this breakpoint has been installed. This reflects
> the same information shown by the command `info b`.
>
> If the breakpoint is pending it will return None,
> but also if the breakpoint is not of type "breakpoint"
> or "watchpoint" it will also return none.
>
> The rationale for this patch is for IDE or debug adapters
> as they are called, for instance for VSCode, to be able
> to fetch breakpoint related data directly from Python,
> but also useful for plugins that need to query information
> about breakpoints.

I agree that this is a problem that needs to be solved.  Unfortunately,
I don't think this is the right approach to take here.

I think that we should introduce a BreakpointLocation object, which
should encapsulate the information here.

The reason is that GDB has the ability to enable and disable breakpoints
at the individual location level, so we would at a minimum support:

  BreakpointLocation.address : read-only, a single address, which
  corresponds to what you're adding here,

  BreakpointLocation.enabled : read/write, can enable/disable a single
  location,

  BreapointLocation.breakpoint : read-only, the parent breakpoint
  object,

I'm sure we would probably end up adding more functionality over time,
but I think once the we've got the object in place then we have the
framework for future work in place.

Then we'd obviously want to add:

  Breakpoint.locations : read-only, a list of BreakpointLocation
  objects.

I know this is initially much more work, but I think it will give a
better solution in the end.

Thanks,
Andrew
  



> ---
>  gdb/NEWS                   |  5 +++++
>  gdb/doc/python.texi        |  6 ++++++
>  gdb/python/py-breakpoint.c | 26 ++++++++++++++++++++++++++
>  3 files changed, 37 insertions(+)
>
> diff --git a/gdb/NEWS b/gdb/NEWS
> index 9e7e41d3bd6..1410c7027e8 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -21,6 +21,11 @@
>       Breakpoint was installed. This is the information displayed
>       by the 'info breakpoints' command.
>  
> +  ** Added attribute Breakpoint.addresses
> +     This returns a list of addresses (as longs) where the
> +     breakpoint was installed. This is the same address information
> +     displayed by the 'info breakpoint' command
> +
>  *** Changes in GDB 12
>  
>  * DBX mode is deprecated, and will be removed in GDB 13
> diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
> index 0d842af6229..3511b8b00a4 100644
> --- a/gdb/doc/python.texi
> +++ b/gdb/doc/python.texi
> @@ -6074,6 +6074,12 @@ breakpoint or is of a type that doesn't have a source location related to it
>  it returns @code{None}. This attribute is not writable.
>  @end defvar
>  
> +@defvar Breakpoint.addresses
> +This attribute holds the address(es) where the breakpoint was installed.
> +If the breakpoint is a pending breakpoint, it returns @code{None}.
> +This attribute is not writable.
> +@end defvar
> +
>  @node Finish Breakpoints in Python
>  @subsubsection Finish Breakpoints
>  
> diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
> index 1b9ac6957a5..19c7cec815c 100644
> --- a/gdb/python/py-breakpoint.c
> +++ b/gdb/python/py-breakpoint.c
> @@ -721,6 +721,30 @@ static PyObject* bppy_get_source_locations(PyObject *self, void* closure)
>    return list.release();
>  }
>  
> +/* Python function to get all addresses where this breakpoint is set  */
> +
> +static PyObject* bppy_get_addresses(PyObject *self, void* closure)
> +{
> +  gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
> +  struct breakpoint* bp = self_bp->bp;
> +
> +  BPPY_REQUIRE_VALID (self_bp);
> +
> +  if (pending_breakpoint_p(bp))
> +    Py_RETURN_NONE;
> +
> +  if (!is_breakpoint(bp) && !is_watchpoint(bp))
> +    Py_RETURN_NONE;
> +
> +  gdbpy_ref<> list (PyList_New (0));
> +
> +  for (const bp_location* it = bp->loc; it != nullptr; it = it->next)
> +    if(PyList_Append(list.get(), PyLong_FromLong(it->address)) != 0)
> +      return nullptr;
> +
> +  return list.release();
> +}
> +
>  /* Internal function to validate the Python parameters/keywords
>     provided to bppy_init.  */
>  
> @@ -1295,6 +1319,8 @@ or None if no condition set."},
>      "Whether this breakpoint is a pending breakpoint."},
>    { "source_locations", bppy_get_source_locations, NULL,
>      "Source file locations where this breakpoint is installed"},
> +  { "addresses", bppy_get_addresses, NULL,
> +    "Get addresses of where this breakpoint is set" },
>    { NULL }  /* Sentinel.  */
>  };
>  
> -- 
> 2.32.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] gdb/python: add gdb.Breakpoint.source_locations property
  2022-03-29 21:27 [PATCH 1/2] gdb/python: add gdb.Breakpoint.source_locations property Simon Farre
  2022-03-29 21:27 ` [PATCH 2/2] gdb/python: add gdb.Breakpoint.addresses property Simon Farre
@ 2022-03-30  8:58 ` Andrew Burgess
  1 sibling, 0 replies; 5+ messages in thread
From: Andrew Burgess @ 2022-03-30  8:58 UTC (permalink / raw)
  To: Simon Farre via Gdb-patches, gdb-patches

Simon Farre via Gdb-patches <gdb-patches@sourceware.org> writes:

> This attribute returns the source locations where
> this breakpoint was installed. It's returned as a list
> of tuples of type (file path: string, line: long).
>
> Currently it's not possible from the Python API to know
> where a breakpoint has been installed.
>
> The rationale for this patch is for IDE or debug adapters
> as they are called, for instance for VSCode, to be able
> to fetch Breakpoint related data directly from Python,
> but also makes it possible to get this data for plugins
> without having the parse the string output of the command
> `info breakpoints`.

See my comments on patch 2/2.  I think the same applies for this patch
too.

Thanks,
Andrew

> ---
>  gdb/NEWS                   |  5 +++++
>  gdb/doc/python.texi        |  8 ++++++++
>  gdb/python/py-breakpoint.c | 31 +++++++++++++++++++++++++++++++
>  3 files changed, 44 insertions(+)
>
> diff --git a/gdb/NEWS b/gdb/NEWS
> index e10062752d0..9e7e41d3bd6 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -16,6 +16,11 @@
>       This is the same format that GDB uses when printing address, symbol,
>       and offset information from the disassembler.
>  
> +  ** Added attribute Breakpoint.source_locations
> +     This returns a list of (file path, line number) tuples where the
> +     Breakpoint was installed. This is the information displayed
> +     by the 'info breakpoints' command.
> +
>  *** Changes in GDB 12
>  
>  * DBX mode is deprecated, and will be removed in GDB 13
> diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
> index 7c414b01d70..0d842af6229 100644
> --- a/gdb/doc/python.texi
> +++ b/gdb/doc/python.texi
> @@ -6066,6 +6066,14 @@ commands, separated by newlines.  If there are no commands, this
>  attribute is @code{None}.  This attribute is writable.
>  @end defvar
>  
> +@defvar Breakpoint.source_locations
> +This attribute holds the source locations where the breakpoint installed.
> +It returns a list of tuples containing the file path and the line number.
> +If the breakpoint has no source location(s), either because it's a pending
> +breakpoint or is of a type that doesn't have a source location related to it
> +it returns @code{None}. This attribute is not writable.
> +@end defvar
> +
>  @node Finish Breakpoints in Python
>  @subsubsection Finish Breakpoints
>  
> diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
> index 5891c3a9735..1b9ac6957a5 100644
> --- a/gdb/python/py-breakpoint.c
> +++ b/gdb/python/py-breakpoint.c
> @@ -692,6 +692,35 @@ bppy_get_ignore_count (PyObject *self, void *closure)
>    return gdb_py_object_from_longest (self_bp->bp->ignore_count).release ();
>  }
>  
> +/* Python function to get all source locations where this breakpoint is set.
> +   returns a list of tuples containing the file path and the line number.  */
> +
> +static PyObject* bppy_get_source_locations(PyObject *self, void* closure)
> +{
> +  gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
> +  struct breakpoint* bp = self_bp->bp;
> +
> +  BPPY_REQUIRE_VALID (self_bp);
> +
> +  if (!is_breakpoint (bp) || pending_breakpoint_p(bp))
> +    Py_RETURN_NONE;
> +
> +  gdbpy_ref<> list (PyList_New (0));
> +
> +  for (const bp_location* it = bp->loc; it != nullptr; it = it->next)
> +    {
> +      PyObject* tuple = PyTuple_New(2);
> +      if(PyTuple_SetItem(tuple, 0, host_string_to_python_string (it->symtab->filename).release ()) != 0)
> +        return nullptr;
> +      if(PyTuple_SetItem(tuple, 1, PyLong_FromLong(it->line_number)) != 0)
> +        return nullptr;
> +      if(PyList_Append(list.get(), tuple) != 0)
> +        return nullptr;
> +    }
> +
> +  return list.release();
> +}
> +
>  /* Internal function to validate the Python parameters/keywords
>     provided to bppy_init.  */
>  
> @@ -1264,6 +1293,8 @@ or None if no condition set."},
>      "Whether this breakpoint is a temporary breakpoint."},
>    { "pending", bppy_get_pending, NULL,
>      "Whether this breakpoint is a pending breakpoint."},
> +  { "source_locations", bppy_get_source_locations, NULL,
> +    "Source file locations where this breakpoint is installed"},
>    { NULL }  /* Sentinel.  */
>  };
>  
>
> base-commit: b8e92c571baed4e794bd62b7bf417fa8bbaf5c95
> -- 
> 2.32.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] gdb/python: add gdb.Breakpoint.addresses property
  2022-03-30  8:56   ` Andrew Burgess
@ 2022-03-30 10:04     ` Simon Farre
  0 siblings, 0 replies; 5+ messages in thread
From: Simon Farre @ 2022-03-30 10:04 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: Simon Farre via Gdb-patches

Seems perfectly reasonable to me and I will look into it right away.

I suppose it could be worth also adding an attribute to the
BreakpointLocation
that signals it's "minor" version number (like it's displayed when running
"info break")
although, I'm going to try and tackle what you've listed here, first.

Den ons 30 mars 2022 kl 10:56 skrev Andrew Burgess <aburgess@redhat.com>:

> Simon Farre via Gdb-patches <gdb-patches@sourceware.org> writes:
>
> > Currently it's not possible from the Python API to know
> > where a breakpoint has been installed in memory.
> >
> > This attribute returns a list of the addresses where
> > this breakpoint has been installed. This reflects
> > the same information shown by the command `info b`.
> >
> > If the breakpoint is pending it will return None,
> > but also if the breakpoint is not of type "breakpoint"
> > or "watchpoint" it will also return none.
> >
> > The rationale for this patch is for IDE or debug adapters
> > as they are called, for instance for VSCode, to be able
> > to fetch breakpoint related data directly from Python,
> > but also useful for plugins that need to query information
> > about breakpoints.
>
> I agree that this is a problem that needs to be solved.  Unfortunately,
> I don't think this is the right approach to take here.
>
> I think that we should introduce a BreakpointLocation object, which
> should encapsulate the information here.
>
> The reason is that GDB has the ability to enable and disable breakpoints
> at the individual location level, so we would at a minimum support:
>
>   BreakpointLocation.address : read-only, a single address, which
>   corresponds to what you're adding here,
>
>   BreakpointLocation.enabled : read/write, can enable/disable a single
>   location,
>
>   BreapointLocation.breakpoint : read-only, the parent breakpoint
>   object,
>
> I'm sure we would probably end up adding more functionality over time,
> but I think once the we've got the object in place then we have the
> framework for future work in place.
>
> Then we'd obviously want to add:
>
>   Breakpoint.locations : read-only, a list of BreakpointLocation
>   objects.
>
> I know this is initially much more work, but I think it will give a
> better solution in the end.
>
> Thanks,
> Andrew
>
>
>
>
> > ---
> >  gdb/NEWS                   |  5 +++++
> >  gdb/doc/python.texi        |  6 ++++++
> >  gdb/python/py-breakpoint.c | 26 ++++++++++++++++++++++++++
> >  3 files changed, 37 insertions(+)
> >
> > diff --git a/gdb/NEWS b/gdb/NEWS
> > index 9e7e41d3bd6..1410c7027e8 100644
> > --- a/gdb/NEWS
> > +++ b/gdb/NEWS
> > @@ -21,6 +21,11 @@
> >       Breakpoint was installed. This is the information displayed
> >       by the 'info breakpoints' command.
> >
> > +  ** Added attribute Breakpoint.addresses
> > +     This returns a list of addresses (as longs) where the
> > +     breakpoint was installed. This is the same address information
> > +     displayed by the 'info breakpoint' command
> > +
> >  *** Changes in GDB 12
> >
> >  * DBX mode is deprecated, and will be removed in GDB 13
> > diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
> > index 0d842af6229..3511b8b00a4 100644
> > --- a/gdb/doc/python.texi
> > +++ b/gdb/doc/python.texi
> > @@ -6074,6 +6074,12 @@ breakpoint or is of a type that doesn't have a
> source location related to it
> >  it returns @code{None}. This attribute is not writable.
> >  @end defvar
> >
> > +@defvar Breakpoint.addresses
> > +This attribute holds the address(es) where the breakpoint was installed.
> > +If the breakpoint is a pending breakpoint, it returns @code{None}.
> > +This attribute is not writable.
> > +@end defvar
> > +
> >  @node Finish Breakpoints in Python
> >  @subsubsection Finish Breakpoints
> >
> > diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
> > index 1b9ac6957a5..19c7cec815c 100644
> > --- a/gdb/python/py-breakpoint.c
> > +++ b/gdb/python/py-breakpoint.c
> > @@ -721,6 +721,30 @@ static PyObject* bppy_get_source_locations(PyObject
> *self, void* closure)
> >    return list.release();
> >  }
> >
> > +/* Python function to get all addresses where this breakpoint is set  */
> > +
> > +static PyObject* bppy_get_addresses(PyObject *self, void* closure)
> > +{
> > +  gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
> > +  struct breakpoint* bp = self_bp->bp;
> > +
> > +  BPPY_REQUIRE_VALID (self_bp);
> > +
> > +  if (pending_breakpoint_p(bp))
> > +    Py_RETURN_NONE;
> > +
> > +  if (!is_breakpoint(bp) && !is_watchpoint(bp))
> > +    Py_RETURN_NONE;
> > +
> > +  gdbpy_ref<> list (PyList_New (0));
> > +
> > +  for (const bp_location* it = bp->loc; it != nullptr; it = it->next)
> > +    if(PyList_Append(list.get(), PyLong_FromLong(it->address)) != 0)
> > +      return nullptr;
> > +
> > +  return list.release();
> > +}
> > +
> >  /* Internal function to validate the Python parameters/keywords
> >     provided to bppy_init.  */
> >
> > @@ -1295,6 +1319,8 @@ or None if no condition set."},
> >      "Whether this breakpoint is a pending breakpoint."},
> >    { "source_locations", bppy_get_source_locations, NULL,
> >      "Source file locations where this breakpoint is installed"},
> > +  { "addresses", bppy_get_addresses, NULL,
> > +    "Get addresses of where this breakpoint is set" },
> >    { NULL }  /* Sentinel.  */
> >  };
> >
> > --
> > 2.32.0
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-03-30 10:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-29 21:27 [PATCH 1/2] gdb/python: add gdb.Breakpoint.source_locations property Simon Farre
2022-03-29 21:27 ` [PATCH 2/2] gdb/python: add gdb.Breakpoint.addresses property Simon Farre
2022-03-30  8:56   ` Andrew Burgess
2022-03-30 10:04     ` Simon Farre
2022-03-30  8:58 ` [PATCH 1/2] gdb/python: add gdb.Breakpoint.source_locations property Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).