public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] Improve types abstraction for gdb python scripts
@ 2016-05-04  3:12 buzdelabuz2
  2016-05-04  3:12 ` [PATCH 2/2] Fix issue with dmesg.py and python 3.X buzdelabuz2
  2016-05-04 12:37 ` [PATCH 1/2] Improve types abstraction for gdb python scripts Kieran Bingham
  0 siblings, 2 replies; 8+ messages in thread
From: buzdelabuz2 @ 2016-05-04  3:12 UTC (permalink / raw)
  To: kieran, jan.kiszka; +Cc: linux-kernel

From: Dom Cote <buzdelabuz2+git@gmail.com>

Change the read_u16 function so it accepts both 'str' and 'byte'
as type for the arguments.

When calling read_memory() from gdb API, depending on if
it was built with 2.7 or 3.X, the format used to return the
data will differ ( 'str' for 2.7, and 'byte' for 3.X ).

Add a function read_memoryview() to be able to get a
'memoryview' object back from read_memory() both with
python 2.7 and 3.X .

Tested with python 3.4 and 2.7
Tested with gdb 7.7

Signed-off-by: Dom Cote <buzdelabuz2+git@gmail.com>
---
 scripts/gdb/linux/utils.py | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/scripts/gdb/linux/utils.py b/scripts/gdb/linux/utils.py
index 0893b326a28b..dba6c88ea7b9 100644
--- a/scripts/gdb/linux/utils.py
+++ b/scripts/gdb/linux/utils.py
@@ -87,11 +87,24 @@ def get_target_endianness():
     return target_endianness
 
 
+def read_memoryview(inf, start, length):
+    return memoryview(inf.read_memory(start, length))
+
+
 def read_u16(buffer):
+    value = [0, 0]
+
+    if type(buffer[0]) is str:
+        value[0] = ord(buffer[0])
+        value[1] = ord(buffer[1])
+    else:
+        value[0] = buffer[0]
+        value[1] = buffer[1]
+
     if get_target_endianness() == LITTLE_ENDIAN:
-        return ord(buffer[0]) + (ord(buffer[1]) << 8)
+        return value[0] + (value[1] << 8)
     else:
-        return ord(buffer[1]) + (ord(buffer[0]) << 8)
+        return value[1] + (value[0] << 8)
 
 
 def read_u32(buffer):
-- 
2.8.2

^ permalink raw reply related	[flat|nested] 8+ messages in thread
* [PATCH 1/2] Improve types abstraction for gdb python scripts
@ 2016-05-04  3:08 buzdelabuz2
  2016-05-04  3:08 ` [PATCH 2/2] Fix issue with dmesg.py and python 3.X buzdelabuz2
  0 siblings, 1 reply; 8+ messages in thread
From: buzdelabuz2 @ 2016-05-04  3:08 UTC (permalink / raw)
  To: kieran.bingham, jan.kiszka; +Cc: linux-kernel

From: Dom Cote <buzdelabuz2+git@gmail.com>

Change the read_u16 function so it accepts both 'str' and 'byte'
as type for the arguments.

When calling read_memory() from gdb API, depending on if
it was built with 2.7 or 3.X, the format used to return the
data will differ ( 'str' for 2.7, and 'byte' for 3.X ).

Add a function read_memoryview() to be able to get a
'memoryview' object back from read_memory() both with
python 2.7 and 3.X .

Tested with python 3.4 and 2.7
Tested with gdb 7.7

Signed-off-by: Dom Cote <buzdelabuz2+git@gmail.com>
---
 scripts/gdb/linux/utils.py | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/scripts/gdb/linux/utils.py b/scripts/gdb/linux/utils.py
index 0893b326a28b..dba6c88ea7b9 100644
--- a/scripts/gdb/linux/utils.py
+++ b/scripts/gdb/linux/utils.py
@@ -87,11 +87,24 @@ def get_target_endianness():
     return target_endianness
 
 
+def read_memoryview(inf, start, length):
+    return memoryview(inf.read_memory(start, length))
+
+
 def read_u16(buffer):
+    value = [0, 0]
+
+    if type(buffer[0]) is str:
+        value[0] = ord(buffer[0])
+        value[1] = ord(buffer[1])
+    else:
+        value[0] = buffer[0]
+        value[1] = buffer[1]
+
     if get_target_endianness() == LITTLE_ENDIAN:
-        return ord(buffer[0]) + (ord(buffer[1]) << 8)
+        return value[0] + (value[1] << 8)
     else:
-        return ord(buffer[1]) + (ord(buffer[0]) << 8)
+        return value[1] + (value[0] << 8)
 
 
 def read_u32(buffer):
-- 
2.8.2

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

end of thread, other threads:[~2016-05-05 14:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-04  3:12 [PATCH 1/2] Improve types abstraction for gdb python scripts buzdelabuz2
2016-05-04  3:12 ` [PATCH 2/2] Fix issue with dmesg.py and python 3.X buzdelabuz2
2016-05-04  5:41   ` Jan Kiszka
2016-05-04 12:37   ` Kieran Bingham
2016-05-04 12:37   ` [PATCH] scripts/gdb: decode bytestream on dmesg for Python3 Kieran Bingham
2016-05-05 14:20     ` Dom Cote
2016-05-04 12:37 ` [PATCH 1/2] Improve types abstraction for gdb python scripts Kieran Bingham
  -- strict thread matches above, loose matches on Subject: below --
2016-05-04  3:08 buzdelabuz2
2016-05-04  3:08 ` [PATCH 2/2] Fix issue with dmesg.py and python 3.X buzdelabuz2

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