This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Fix break on Python 2


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=cee59b3feac9a8f6300a5b788e3db4e15af2a894

commit cee59b3feac9a8f6300a5b788e3db4e15af2a894
Author: Tim Wiederhake <tim.wiederhake@intel.com>
Date:   Tue Mar 21 08:19:59 2017 +0100

    Fix break on Python 2
    
    This changes the return type of "gdb.BtraceInstruction.data ()" from
    "memoryview" to "buffer" on Python 2.7 and below, similar to what
    "gdb.Inferior.read_memory ()" does.

Diff:
---
 gdb/ChangeLog                                 | 5 +++++
 gdb/doc/ChangeLog                             | 5 +++++
 gdb/doc/python.texi                           | 3 ++-
 gdb/python/py-record-btrace.c                 | 5 +++++
 gdb/testsuite/ChangeLog                       | 5 +++++
 gdb/testsuite/gdb.python/py-record-btrace.exp | 6 +++++-
 6 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 02ab32c..95c847b 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2017-03-21  Tim Wiederhake  <tim.wiederhake@intel.com>
+
+	* python/py-record-btrace.c (btpy_insn_data): Change return type
+	for Python 2.
+
 2017-03-20  Simon Marchi  <simon.marchi@polymtl.ca>
 
 	* spu-linux-nat.c (spu_fetch_inferior_registers,
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 1657ab8..8253cbe 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@
+2017-03-21  Tim Wiederhake  <tim.wiederhake@intel.com>
+
+	* python.texi (Recordings In Python): Document return type of
+	gdb.BtraceInstruction.data.
+
 2017-03-20  Marc-Andre Laperle  <marc-andre.laperle@ericsson.com>
 
 	* gdb.texinfo (gdb/mi Symbol Query Commands): Document new MI
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index f6ec08c..1fb8b25 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -3185,7 +3185,8 @@ if the instruction is a gap or the debug symbols could not be read.
 
 @defvar BtraceInstruction.data
 A buffer with the raw instruction data.  May be @code{None} if the
-instruction is a gap.
+instruction is a gap.  In Python 3, the return value is a @code{memoryview}
+object.
 @end defvar
 
 @defvar BtraceInstruction.decoded
diff --git a/gdb/python/py-record-btrace.c b/gdb/python/py-record-btrace.c
index 6158f31..c816332 100644
--- a/gdb/python/py-record-btrace.c
+++ b/gdb/python/py-record-btrace.c
@@ -330,7 +330,12 @@ btpy_insn_data (PyObject *self, void *closure)
   if (object == NULL)
     return NULL;
 
+#ifdef IS_PY3K
   return PyMemoryView_FromObject (object);
+#else
+  return PyBuffer_FromObject (object, 0, Py_END_OF_BUFFER);
+#endif
+
 }
 
 /* Implementation of BtraceInstruction.decode [str].  Returns
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 2853d8a..7937ee8 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2017-03-21  Tim Wiederhake  <tim.wiederhake@intel.com>
+
+	* gdb.python/py-record-btrace.exp: Check for buffer on Python 2
+	and memory view on Python 3.
+
 2017-03-20  Artemiy Volkov  <artemiyv@acm.org>
 	    Keith Seitz  <keiths@redhat.com>
 
diff --git a/gdb/testsuite/gdb.python/py-record-btrace.exp b/gdb/testsuite/gdb.python/py-record-btrace.exp
index 65a3e7d..7752cac 100644
--- a/gdb/testsuite/gdb.python/py-record-btrace.exp
+++ b/gdb/testsuite/gdb.python/py-record-btrace.exp
@@ -85,7 +85,11 @@ with_test_prefix "instruction " {
     gdb_test "python print(i.error)" "None"
     gdb_test "python print(i.sal)" "symbol and line for .*"
     gdb_test "python print(i.pc)" "$decimal"
-    gdb_test "python print(i.data)" "<memory at $hex>"
+    if { $gdb_py_is_py3k == 0 } {
+	gdb_test "python print(repr(i.data))" "<read-only buffer for $hex,.*>"
+    } else {
+	gdb_test "python print(repr(i.data))" "<memory at $hex>"
+    }
     gdb_test "python print(i.decoded)" ".*"
     gdb_test "python print(i.size)" "$decimal"
     gdb_test "python print(i.is_speculative)" "False"


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]