public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] Update symbol domain and location values for Python
  2018-09-15 18:46 [PATCH 0/2] two more Python paper-cuts Tom Tromey
  2018-09-15 18:46 ` [PATCH 2/2] Add Inferior.architecture method Tom Tromey
@ 2018-09-15 18:46 ` Tom Tromey
  2018-09-15 19:58   ` Eli Zaretskii
  2018-10-07  5:21 ` [PATCH 0/2] two more Python paper-cuts Tom Tromey
  2 siblings, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2018-09-15 18:46 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

In the distant past, there was no distinction between domain_enum and
search_domain.  At that point, there were two sets of enumerators in a
single enum -- which is why these were eventually split.  This
confusion leaked out to the Python API as well, as noted in
PR python/21765.

This patch deprecates the constants that aren't useful to the Python
API.  They are left in place for now, but removed from the
documentation.  Also, their values are changed so that, if used, they
might work.  Finally, missing domains and location constants are
added.

gdb/ChangeLog
2018-09-15  Tom Tromey  <tom@tromey.com>

	PR python/21765:
	* python/py-symbol.c (gdbpy_initialize_symbols): Redefine
	SYMBOL_VARIABLES_DOMAIN, SYMBOL_FUNCTIONS_DOMAIN,
	SYMBOL_TYPES_DOMAIN.  Define SYMBOL_MODULE_DOMAIN,
	SYMBOL_COMMON_BLOCK_DOMAIN, SYMBOL_LOC_COMMON_BLOCK.

gdb/doc/ChangeLog
2018-09-15  Tom Tromey  <tom@tromey.com>

	PR python/21765:
	* python.texi (Symbols In Python): Document the module and
	common-block domains.  Remove documentation for incorrect
	domains.
---
 gdb/ChangeLog          |  8 ++++++++
 gdb/NEWS               |  8 ++++++++
 gdb/doc/ChangeLog      |  7 +++++++
 gdb/doc/python.texi    | 24 ++++++++++++------------
 gdb/python/py-symbol.c | 24 ++++++++++++++++++------
 5 files changed, 53 insertions(+), 18 deletions(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index 2a89569bdbc..54059672ccb 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -92,6 +92,14 @@ CSKY GNU/LINUX			csky*-*-linux
   ** The gdb.Progspace type has a new 'objfiles' method, which returns the list
      of objfiles associated to that program space.
 
+  ** gdb.SYMBOL_LOC_COMMON_BLOCK, gdb.SYMBOL_MODULE_DOMAIN, and
+     gdb.SYMBOL_COMMON_BLOCK_DOMAIN were added to reflect changes to
+     the gdb core.
+
+  ** gdb.SYMBOL_VARIABLES_DOMAIN, gdb.SYMBOL_FUNCTIONS_DOMAIN, and
+     gdb.SYMBOL_TYPES_DOMAIN are now deprecated.  These were never
+     correct and did not work properly.
+
 *** Changes in GDB 8.2
 
 * The 'set disassembler-options' command now supports specifying options
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index aca6ec858cf..bd444daff5a 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -4733,18 +4733,13 @@ This domain holds struct, union and enum type names.
 @item gdb.SYMBOL_LABEL_DOMAIN
 This domain contains names of labels (for gotos).
 
-@vindex SYMBOL_VARIABLES_DOMAIN
-@item gdb.SYMBOL_VARIABLES_DOMAIN
-This domain holds a subset of the @code{SYMBOLS_VAR_DOMAIN}; it
-contains everything minus functions and types.
-
-@vindex SYMBOL_FUNCTIONS_DOMAIN
-@item gdb.SYMBOL_FUNCTIONS_DOMAIN
-This domain contains all functions.
-
-@vindex SYMBOL_TYPES_DOMAIN
-@item gdb.SYMBOL_TYPES_DOMAIN
-This domain contains all types.
+@vindex SYMBOL_MODULE_DOMAIN
+@item gdb.SYMBOL_MODULE_DOMAIN
+This domain contains names of Fortran module types.
+
+@vindex SYMBOL_COMMON_BLOCK_DOMAIN
+@item gdb.SYMBOL_COMMON_BLOCK_DOMAIN
+This domain contains names of Fortran common blocks.
 @end vtable
 
 The available address class categories in @code{gdb.Symbol} are represented
@@ -4815,6 +4810,11 @@ The value does not actually exist in the program.
 @vindex SYMBOL_LOC_COMPUTED
 @item gdb.SYMBOL_LOC_COMPUTED
 The value's address is a computed location.
+
+@vindex SYMBOL_LOC_COMPUTED
+@item gdb.SYMBOL_LOC_COMPUTED
+The value's address is a symbol.  This is only used for Fortran common
+blocks.
 @end vtable
 
 @node Symbol Tables In Python
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index 881ab299714..8ae5658eb4e 100644
--- a/gdb/python/py-symbol.c
+++ b/gdb/python/py-symbol.c
@@ -537,6 +537,8 @@ gdbpy_initialize_symbols (void)
 				  LOC_OPTIMIZED_OUT) < 0
       || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_COMPUTED",
 				  LOC_COMPUTED) < 0
+      || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_COMMON_BLOCK",
+				  LOC_COMMON_BLOCK) < 0
       || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REGPARM_ADDR",
 				  LOC_REGPARM_ADDR) < 0
       || PyModule_AddIntConstant (gdb_module, "SYMBOL_UNDEF_DOMAIN",
@@ -545,14 +547,24 @@ gdbpy_initialize_symbols (void)
 				  VAR_DOMAIN) < 0
       || PyModule_AddIntConstant (gdb_module, "SYMBOL_STRUCT_DOMAIN",
 				  STRUCT_DOMAIN) < 0
-      || PyModule_AddIntConstant (gdb_module, "SYMBOL_LABEL_DOMAIN",
-				  LABEL_DOMAIN) < 0
-      || PyModule_AddIntConstant (gdb_module, "SYMBOL_VARIABLES_DOMAIN",
-				  VARIABLES_DOMAIN) < 0
+      || PyModule_AddIntConstant (gdb_module, "SYMBOL_MODULE_DOMAIN",
+				  MODULE_DOMAIN) < 0
+      || PyModule_AddIntConstant (gdb_module, "SYMBOL_COMMON_BLOCK_DOMAIN",
+				  COMMON_BLOCK_DOMAIN) < 0)
+    return -1;
+
+  /* These remain defined for compatibility, but as they were never
+     correct, they are no longer documented.  Eventually we can remove
+     them.  These exist because at one time, enum search_domain and
+     enum domain_enum_tag were combined -- but different values were
+     used differently.  Here we try to give them values that will make
+     sense if they are passed to gdb.lookup_symbol.  */
+  if (PyModule_AddIntConstant (gdb_module, "SYMBOL_VARIABLES_DOMAIN",
+			       VAR_DOMAIN) < 0
       || PyModule_AddIntConstant (gdb_module, "SYMBOL_FUNCTIONS_DOMAIN",
-				  FUNCTIONS_DOMAIN) < 0
+				  VAR_DOMAIN) < 0
       || PyModule_AddIntConstant (gdb_module, "SYMBOL_TYPES_DOMAIN",
-				  TYPES_DOMAIN) < 0)
+				  VAR_DOMAIN) < 0)
     return -1;
 
   return gdb_pymodule_addobject (gdb_module, "Symbol",
-- 
2.17.1

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

* [PATCH 0/2] two more Python paper-cuts
@ 2018-09-15 18:46 Tom Tromey
  2018-09-15 18:46 ` [PATCH 2/2] Add Inferior.architecture method Tom Tromey
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Tom Tromey @ 2018-09-15 18:46 UTC (permalink / raw)
  To: gdb-patches

This fixes a couple more small Python bugs.

Tested on x86-64 Fedora 28.

Tom


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

* [PATCH 2/2] Add Inferior.architecture method
  2018-09-15 18:46 [PATCH 0/2] two more Python paper-cuts Tom Tromey
@ 2018-09-15 18:46 ` Tom Tromey
  2018-09-15 19:58   ` Eli Zaretskii
  2018-10-08  7:59   ` [Committed] Python doc build fixes Andreas Krebbel
  2018-09-15 18:46 ` [PATCH 1/2] Update symbol domain and location values for Python Tom Tromey
  2018-10-07  5:21 ` [PATCH 0/2] two more Python paper-cuts Tom Tromey
  2 siblings, 2 replies; 8+ messages in thread
From: Tom Tromey @ 2018-09-15 18:46 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

I've written a couple of gdb unwinders in Python, and while doing so,
I wanted to find the architecture of the inferior.  (In an unwinder in
particular, one can't use the frame's architecture, because there is
no frame.)

This patch adds Inferior.architecture to allow this.  Normally I think
I would have chosen an attribute and not a method here, but seeing
that Frame.architecture is a method, I chose a method as well, for
consistency.

gdb/ChangeLog
2018-09-15  Tom Tromey  <tom@tromey.com>

	PR python/19399:
	* python/py-inferior.c: Add "architecture" entry.
	(infpy_architecture): New function.

gdb/doc/ChangeLog
2018-09-15  Tom Tromey  <tom@tromey.com>

	PR python/19399:
	* python.texi (Inferiors In Python): Document
	Inferior.Architecture.

gdb/testsuite/ChangeLog
2018-09-15  Tom Tromey  <tom@tromey.com>

	PR python/19399:
	* gdb.python/py-inferior.exp: Add architecture test.
---
 gdb/ChangeLog                            |  6 ++++++
 gdb/doc/ChangeLog                        |  6 ++++++
 gdb/doc/python.texi                      |  7 +++++++
 gdb/python/py-inferior.c                 | 15 +++++++++++++++
 gdb/testsuite/ChangeLog                  |  5 +++++
 gdb/testsuite/gdb.python/py-inferior.exp |  8 ++++++++
 6 files changed, 47 insertions(+)

diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index bd444daff5a..751c400bf32 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -2856,6 +2856,13 @@ when it is called.  If there are no valid threads, the method will
 return an empty tuple.
 @end defun
 
+@defun Inferior.architecture ()
+Return the @code{gdb.Architecture} (@pxref{Architectures In Python})
+for this inferior.  This represents the architecture of the inferior
+as a whole.  Some platforms can have multiple architectures in a
+single address space, so this may not match the architecture of a
+particular frame (@pxref{Frames in Python}).
+
 @findex Inferior.read_memory
 @defun Inferior.read_memory (address, length)
 Read @var{length} addressable memory units from the inferior, starting at
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 6db3df412eb..539c9958ec1 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -877,6 +877,18 @@ infpy_thread_from_thread_handle (PyObject *self, PyObject *args, PyObject *kw)
   return result;
 }
 
+/* Implementation of gdb.Inferior.architecture.  */
+
+static PyObject *
+infpy_architecture (PyObject *self, PyObject *args)
+{
+  inferior_object *inf = (inferior_object *) self;
+
+  INFPY_REQUIRE_VALID (inf);
+
+  return gdbarch_to_arch_object (inf->inferior->gdbarch);
+}
+
 /* Implement repr() for gdb.Inferior.  */
 
 static PyObject *
@@ -1010,6 +1022,9 @@ Return a long with the address of a match, or None." },
     METH_VARARGS | METH_KEYWORDS,
     "thread_from_thread_handle (handle) -> gdb.InferiorThread.\n\
 Return thread object corresponding to thread handle." },
+  { "architecture", (PyCFunction) infpy_architecture, METH_NOARGS,
+    "architecture () -> gdb.Architecture\n\
+Return architecture of this inferior." },
   { NULL }
 };
 
diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp
index 38f52573b19..7b1a01b3ea6 100644
--- a/gdb/testsuite/gdb.python/py-inferior.exp
+++ b/gdb/testsuite/gdb.python/py-inferior.exp
@@ -299,3 +299,11 @@ with_test_prefix "__repr__" {
 	"\\\(<gdb.Inferior num=1, pid=$decimal>, <gdb.Inferior \\\(invalid\\\)>\\\)" \
 	"print all inferiors 2"
 }
+
+# Test architecture.
+with_test_prefix "architecture" {
+    gdb_test "inferior 1" ".*" "switch to first inferior"
+    gdb_test "python print(gdb.selected_frame().architecture() is gdb.selected_inferior().architecture())" \
+	"True" \
+	"inferior architecture matches frame architecture"
+}
-- 
2.17.1

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

* Re: [PATCH 1/2] Update symbol domain and location values for Python
  2018-09-15 18:46 ` [PATCH 1/2] Update symbol domain and location values for Python Tom Tromey
@ 2018-09-15 19:58   ` Eli Zaretskii
  0 siblings, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2018-09-15 19:58 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches, tom

> From: Tom Tromey <tom@tromey.com>
> Cc: Tom Tromey <tom@tromey.com>
> Date: Sat, 15 Sep 2018 12:45:29 -0600
> 
> gdb/ChangeLog
> 2018-09-15  Tom Tromey  <tom@tromey.com>
> 
> 	PR python/21765:
> 	* python/py-symbol.c (gdbpy_initialize_symbols): Redefine
> 	SYMBOL_VARIABLES_DOMAIN, SYMBOL_FUNCTIONS_DOMAIN,
> 	SYMBOL_TYPES_DOMAIN.  Define SYMBOL_MODULE_DOMAIN,
> 	SYMBOL_COMMON_BLOCK_DOMAIN, SYMBOL_LOC_COMMON_BLOCK.
> 
> gdb/doc/ChangeLog
> 2018-09-15  Tom Tromey  <tom@tromey.com>
> 
> 	PR python/21765:
> 	* python.texi (Symbols In Python): Document the module and
> 	common-block domains.  Remove documentation for incorrect
> 	domains.

OK for the documentation part.

Thanks.

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

* Re: [PATCH 2/2] Add Inferior.architecture method
  2018-09-15 18:46 ` [PATCH 2/2] Add Inferior.architecture method Tom Tromey
@ 2018-09-15 19:58   ` Eli Zaretskii
  2018-10-08  7:59   ` [Committed] Python doc build fixes Andreas Krebbel
  1 sibling, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2018-09-15 19:58 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

> From: Tom Tromey <tom@tromey.com>
> Cc: Tom Tromey <tom@tromey.com>
> Date: Sat, 15 Sep 2018 12:45:30 -0600
> 
> gdb/doc/ChangeLog
> 2018-09-15  Tom Tromey  <tom@tromey.com>
> 
> 	PR python/19399:
> 	* python.texi (Inferiors In Python): Document
> 	Inferior.Architecture.

OK for this part, thanks.

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

* Re: [PATCH 0/2] two more Python paper-cuts
  2018-09-15 18:46 [PATCH 0/2] two more Python paper-cuts Tom Tromey
  2018-09-15 18:46 ` [PATCH 2/2] Add Inferior.architecture method Tom Tromey
  2018-09-15 18:46 ` [PATCH 1/2] Update symbol domain and location values for Python Tom Tromey
@ 2018-10-07  5:21 ` Tom Tromey
  2 siblings, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2018-10-07  5:21 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:

Tom> This fixes a couple more small Python bugs.
Tom> Tested on x86-64 Fedora 28.

I'm checking these in now.

Tom

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

* [Committed] Python doc build fixes
  2018-09-15 18:46 ` [PATCH 2/2] Add Inferior.architecture method Tom Tromey
  2018-09-15 19:58   ` Eli Zaretskii
@ 2018-10-08  7:59   ` Andreas Krebbel
  2018-10-09 20:01     ` Tom Tromey
  1 sibling, 1 reply; 8+ messages in thread
From: Andreas Krebbel @ 2018-10-08  7:59 UTC (permalink / raw)
  To: tom; +Cc: gdb-patches, Andreas Krebbel

From: Andreas Krebbel <krebbel@linux.vnet.ibm.com>

I've just committed this patch to fix doc build for me.

gdb/doc/ChangeLog:

2018-10-08  Andreas Krebbel  <krebbel@linux.ibm.com>

	* python.texi (Inferior.Architecture): Add "@end defun". Rename
	ref target to "Unwinding Frames in Python".
---
 gdb/doc/python.texi | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index dc53cfa..2320be6 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -2865,7 +2865,8 @@ Return the @code{gdb.Architecture} (@pxref{Architectures In Python})
 for this inferior.  This represents the architecture of the inferior
 as a whole.  Some platforms can have multiple architectures in a
 single address space, so this may not match the architecture of a
-particular frame (@pxref{Frames in Python}).
+particular frame (@pxref{Unwinding Frames in Python}).
+@end defun
 
 @findex Inferior.read_memory
 @defun Inferior.read_memory (address, length)
-- 
2.7.4

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

* Re: [Committed] Python doc build fixes
  2018-10-08  7:59   ` [Committed] Python doc build fixes Andreas Krebbel
@ 2018-10-09 20:01     ` Tom Tromey
  0 siblings, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2018-10-09 20:01 UTC (permalink / raw)
  To: Andreas Krebbel; +Cc: tom, gdb-patches, Andreas Krebbel

>>>>> "Andreas" == Andreas Krebbel <krebbel@linux.ibm.com> writes:

Andreas> From: Andreas Krebbel <krebbel@linux.vnet.ibm.com>
Andreas> I've just committed this patch to fix doc build for me.

Thank you.  And, sorry about the breakage.

Andreas> 2018-10-08  Andreas Krebbel  <krebbel@linux.ibm.com>

Andreas> 	* python.texi (Inferior.Architecture): Add "@end defun". Rename
Andreas> 	ref target to "Unwinding Frames in Python".

I think you didn't commit the ChangeLog change.

Andreas> -particular frame (@pxref{Frames in Python}).
Andreas> +particular frame (@pxref{Unwinding Frames in Python}).

This was intended to link to the general information about gdb.Frame,
not to the node about how to write an unwinder, which seems less
relevant in context.

However, I typo'd the "in" -- it should have been "In".

I'm checking in the appended to change this to what was originally
intended.

Tom

commit 163cffefafb1d427ab46603d98bbfc45e813c9a0
Author: Tom Tromey <tom@tromey.com>
Date:   Tue Oct 9 13:57:10 2018 -0600

    Make @pxref for Inferior.architecture point to gdb.Frame documentation
    
    This fixes he @pxref in Inferior.architecture to point to the "Frames
    In Python" node, as originally intended; somewhat reverting an earlier
    build fix.  The initial patch had typod the "In".
    
    Tested by "make info".
    
    gdb/doc/ChangeLog
    2018-10-09  Tom Tromey  <tom@tromey.com>
    
            * python.texi (Inferiors In Python): Link to "Frames In Python",
            not "Unwinding Frames in Python".

diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index c67798399f..0cab170456 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@
+2018-10-09  Tom Tromey  <tom@tromey.com>
+
+	* python.texi (Inferiors In Python): Link to "Frames In Python",
+	not "Unwinding Frames in Python".
+
 2018-10-09  Tom Tromey  <tom@tromey.com>
 
 	* gdb.texinfo (Configure Options): Update --enable-ubsan
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index 2320be63dd..ff5fecea1b 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -2865,7 +2865,7 @@ Return the @code{gdb.Architecture} (@pxref{Architectures In Python})
 for this inferior.  This represents the architecture of the inferior
 as a whole.  Some platforms can have multiple architectures in a
 single address space, so this may not match the architecture of a
-particular frame (@pxref{Unwinding Frames in Python}).
+particular frame (@pxref{Frames In Python}).
 @end defun
 
 @findex Inferior.read_memory

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

end of thread, other threads:[~2018-10-09 20:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-15 18:46 [PATCH 0/2] two more Python paper-cuts Tom Tromey
2018-09-15 18:46 ` [PATCH 2/2] Add Inferior.architecture method Tom Tromey
2018-09-15 19:58   ` Eli Zaretskii
2018-10-08  7:59   ` [Committed] Python doc build fixes Andreas Krebbel
2018-10-09 20:01     ` Tom Tromey
2018-09-15 18:46 ` [PATCH 1/2] Update symbol domain and location values for Python Tom Tromey
2018-09-15 19:58   ` Eli Zaretskii
2018-10-07  5:21 ` [PATCH 0/2] two more Python paper-cuts Tom Tromey

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).