Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* RFA, doc RFA: add symbol.type attribute
@ 2011-08-12  0:57 Doug Evans
  2011-08-12  6:56 ` Eli Zaretskii
  2011-08-12 16:59 ` Tom Tromey
  0 siblings, 2 replies; 3+ messages in thread
From: Doug Evans @ 2011-08-12  0:57 UTC (permalink / raw)
  To: gdb-patches, eliz

Hi.

It seems an oversight to not export the type attribute of symbols,
and I have a need of it.

Ok to check in?

2011-08-11  Doug Evans  <dje@google.com>

	* NEWS: Mention new "type" attribute of python gdb.Symbol objects.
	* python/py-symbol.c (sympy_get_type): New function.
	(symbol_object_getset): Add "type".

	doc/
	* gdb.texinfo (Symbols In Python): Document symbol.type.

	testsuite/
	* gdb.python/py-symbol.exp: Add test for symbol.type.

Index: NEWS
===================================================================
RCS file: /cvs/src/src/gdb/NEWS,v
retrieving revision 1.447
diff -u -p -r1.447 NEWS
--- NEWS	9 Aug 2011 12:45:39 -0000	1.447
+++ NEWS	12 Aug 2011 00:55:37 -0000
@@ -28,6 +28,8 @@
     'data-directory'/python/gdb/function are now automatically loaded
      on GDB start-up.
 
+  ** Symbols now provide the "type" attribute, the type of the symbol.
+
 * libthread-db-search-path now supports two special values: $sdir and $pdir.
   $sdir specifies the default system locations of shared libraries.
   $pdir specifies the directory where the libpthread used by the application
Index: doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.852
diff -u -p -r1.852 gdb.texinfo
--- doc/gdb.texinfo	9 Aug 2011 12:45:39 -0000	1.852
+++ doc/gdb.texinfo	12 Aug 2011 00:55:39 -0000
@@ -23198,6 +23198,12 @@ is not found.
 A @code{gdb.Symbol} object has the following attributes:
 
 @table @code
+@defivar Symbol type
+The type of the symbol or None if no type is recorded.
+This attribute is represented as a @code{gdb.Type} object.
+@xref{Types In Python}.  This attribute is not writable.
+@end defivar
+
 @defivar Symbol symtab
 The symbol table in which the symbol appears.  This attribute is
 represented as a @code{gdb.Symtab} object.  @xref{Symbol Tables In
Index: python/py-symbol.c
===================================================================
RCS file: /cvs/src/src/gdb/python/py-symbol.c,v
retrieving revision 1.7
diff -u -p -r1.7 py-symbol.c
--- python/py-symbol.c	17 Apr 2011 14:14:22 -0000	1.7
+++ python/py-symbol.c	12 Aug 2011 00:55:39 -0000
@@ -66,6 +66,22 @@ sympy_str (PyObject *self)
 }
 
 static PyObject *
+sympy_get_type (PyObject *self, void *closure)
+{
+  struct symbol *symbol = NULL;
+
+  SYMPY_REQUIRE_VALID (self, symbol);
+
+  if (SYMBOL_TYPE (symbol) == NULL)
+    {
+      Py_INCREF (Py_None);
+      return Py_None;
+    }
+
+  return type_to_type_object (SYMBOL_TYPE (symbol));
+}
+
+static PyObject *
 sympy_get_symtab (PyObject *self, void *closure)
 {
   struct symbol *symbol = NULL;
@@ -412,6 +428,8 @@ gdbpy_initialize_symbols (void)
 \f
 
 static PyGetSetDef symbol_object_getset[] = {
+  { "type", sympy_get_type, NULL,
+    "Type of the symbol.", NULL },
   { "symtab", sympy_get_symtab, NULL,
     "Symbol table in which the symbol appears.", NULL },
   { "name", sympy_get_name, NULL,
Index: testsuite/gdb.python/py-symbol.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.python/py-symbol.exp,v
retrieving revision 1.8
diff -u -p -r1.8 py-symbol.exp
--- testsuite/gdb.python/py-symbol.exp	26 Jul 2011 18:38:55 -0000	1.8
+++ testsuite/gdb.python/py-symbol.exp	12 Aug 2011 00:55:39 -0000
@@ -95,6 +95,11 @@ gdb_test "python print t\[0\].is_constan
 gdb_test "python print t\[0\].is_argument" "False" "Test t.is_argument"
 gdb_test "python print t\[0\].is_function" "False" "Test t.is_function"
 gdb_test "python print t\[0\].addr_class == gdb.SYMBOL_LOC_CONST" "True" "Test t.addr_class"
+
+# Test type attribute.
+gdb_test "python print t\[0\].type" "enum tag" "Get type"
+
+# Test symtab attribute.
 gdb_test "python print t\[0\].symtab" "gdb.python/py-symbol.c.*" "Get symtab"
 
 # C++ tests


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

* Re: RFA, doc RFA: add symbol.type attribute
  2011-08-12  0:57 RFA, doc RFA: add symbol.type attribute Doug Evans
@ 2011-08-12  6:56 ` Eli Zaretskii
  2011-08-12 16:59 ` Tom Tromey
  1 sibling, 0 replies; 3+ messages in thread
From: Eli Zaretskii @ 2011-08-12  6:56 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb-patches

> Date: Thu, 11 Aug 2011 17:57:35 -0700 (PDT)
> From: dje@google.com (Doug Evans)
> 
> It seems an oversight to not export the type attribute of symbols,
> and I have a need of it.
> 
> Ok to check in?

With the comment below, the doco part os okay.

> +@defivar Symbol type
> +The type of the symbol or None if no type is recorded.

@code{None}, I think: it's a program symbol, right?

Thanks.


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

* Re: RFA, doc RFA: add symbol.type attribute
  2011-08-12  0:57 RFA, doc RFA: add symbol.type attribute Doug Evans
  2011-08-12  6:56 ` Eli Zaretskii
@ 2011-08-12 16:59 ` Tom Tromey
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2011-08-12 16:59 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb-patches, eliz

>>>>> "Doug" == Doug Evans <dje@google.com> writes:

Doug> It seems an oversight to not export the type attribute of symbols,
Doug> and I have a need of it.

Doug> Ok to check in?

Looks good to me; thanks for doing this.

Tom


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

end of thread, other threads:[~2011-08-12 16:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-12  0:57 RFA, doc RFA: add symbol.type attribute Doug Evans
2011-08-12  6:56 ` Eli Zaretskii
2011-08-12 16:59 ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox