Skip to contentSkip to conversation

scripts/gdb: fix lx-timerlist for Python3

PATCH In review [email protected] 2 participants 11 messages Jul 20, 2022 – Sep 1, 2022 1 message not in the archive GDB kernel debugging helper scripts

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 2/3 scripts/gdb: fix lx-timerlist for Python3

From: Peng Liu <[email protected]>

Below incompatibilities between Python2 and Python3 made lx-timerlist fail to run under Python3.

o xrange() is replaced by range() in Python3
o bytes and str are different types in Python3
o the return value of Inferior.read_memory() is memoryview object in Python3

---
 scripts/gdb/linux/timerlist.py | 4 +++-
 scripts/gdb/linux/utils.py     | 5 ++++-
 2 files changed, 7 insertions(+), 2 deletions(-)
scripts/gdb/linux/timerlist.py +3 -1
index 44e39dc3eb64..8281da068c5b 100644
@@ -72,7 +72,7 @@ def print_cpu(hrtimer_bases, cpu, max_clock_bases):
     ts = cpus.per_cpu(tick_sched_ptr, cpu)
 
     text = "cpu: {}\n".format(cpu)
-    for i in xrange(max_clock_bases):
+    for i in range(max_clock_bases):
         text += " clock {}:\n".format(i)
         text += print_base(cpu_base['clock_base'][i])
 
@@ -157,6 +157,8 @@ def pr_cpumask(mask):
     num_bytes = (nr_cpu_ids + 7) / 8
     buf = utils.read_memoryview(inf, bits, num_bytes).tobytes()
     buf = binascii.b2a_hex(buf)
+    if type(buf) is not str:
+        buf=buf.decode()
 
     chunks = []
     i = num_bytes
scripts/gdb/linux/utils.py +4 -1
index ff7c1799d588..db59f986c7fd 100644
@@ -89,7 +89,10 @@ def get_target_endianness():
 
 
 def read_memoryview(inf, start, length):
-    return memoryview(inf.read_memory(start, length))
+    m = inf.read_memory(start, length)
+    if type(m) is memoryview:
+        return m
+    return memoryview(m)
 
 
 def read_u16(buffer, offset):
Signature · 1 line
2.25.1
author
#2 lore raw

ping

Quoted 54 lines · On 2022/7/20 20:27, [email protected] wrote:

From: Peng Liu <[email protected]>

Below incompatibilities between Python2 and Python3 made lx-timerlist fail to run under Python3.

o xrange() is replaced by range() in Python3
o bytes and str are different types in Python3
o the return value of Inferior.read_memory() is memoryview object in Python3

---
  scripts/gdb/linux/timerlist.py | 4 +++-
  scripts/gdb/linux/utils.py     | 5 ++++-
  2 files changed, 7 insertions(+), 2 deletions(-)
scripts/gdb/linux/timerlist.py +3 -1
index 44e39dc3eb64..8281da068c5b 100644
@@ -72,7 +72,7 @@ def print_cpu(hrtimer_bases, cpu, max_clock_bases):
      ts = cpus.per_cpu(tick_sched_ptr, cpu)
 
      text = "cpu: {}\n".format(cpu)
-    for i in xrange(max_clock_bases):
+    for i in range(max_clock_bases):
          text += " clock {}:\n".format(i)
          text += print_base(cpu_base['clock_base'][i])
 
@@ -157,6 +157,8 @@ def pr_cpumask(mask):
      num_bytes = (nr_cpu_ids + 7) / 8
      buf = utils.read_memoryview(inf, bits, num_bytes).tobytes()
      buf = binascii.b2a_hex(buf)
+    if type(buf) is not str:
+        buf=buf.decode()
 
      chunks = []
      i = num_bytes
scripts/gdb/linux/utils.py +4 -1
index ff7c1799d588..db59f986c7fd 100644
@@ -89,7 +89,10 @@ def get_target_endianness():
 
 
  def read_memoryview(inf, start, length):
-    return memoryview(inf.read_memory(start, length))
+    m = inf.read_memory(start, length)
+    if type(m) is memoryview:
+        return m
+    return memoryview(m)
 
 
  def read_u16(buffer, offset):
author
#3 lore raw

ping

Quoted 50 lines · Peng Liu

ping

Quoted 47 lines · On 2022/7/20 20:27, [email protected] wrote:

From: Peng Liu <[email protected]>

Below incompatibilities between Python2 and Python3 made lx-timerlist fail to run under Python3.

o xrange() is replaced by range() in Python3
o bytes and str are different types in Python3
o the return value of Inferior.read_memory() is memoryview object in Python3

---
  scripts/gdb/linux/timerlist.py | 4 +++-
  scripts/gdb/linux/utils.py     | 5 ++++-

  2 files changed, 7 insertions(+), 2 deletions(-)
scripts/gdb/linux/timerlist.py +1 -1
index 44e39dc3eb64..8281da068c5b 100644
@@ -72,7 +72,7 @@ def print_cpu(hrtimer_bases, cpu, max_clock_bases):
       ts = cpus.per_cpu(tick_sched_ptr, cpu)
         text = "cpu: {}\n".format(cpu)
-    for i in xrange(max_clock_bases):
+    for i in range(max_clock_bases):
           text += " clock {}:\n".format(i)
           text += print_base(cpu_base['clock_base'][i])

  @@ -157,6 +157,8 @@ def pr_cpumask(mask):
      num_bytes = (nr_cpu_ids + 7) / 8
      buf = utils.read_memoryview(inf, bits, num_bytes).tobytes() buf = binascii.b2a_hex(buf)
+    if type(buf) is not str:
+        buf=buf.decode()
        chunks = []
      i = num_bytes

scripts/gdb/linux/utils.py +0 -0
index ff7c1799d588..db59f986c7fd 100644
@@ -89,7 +89,10 @@ def get_target_endianness():

      def read_memoryview(inf, start, length):
-    return memoryview(inf.read_memory(start, length)) +    m = inf.read_memory(start, length)
+    if type(m) is memoryview:
+        return m
+    return memoryview(m)
      def read_u16(buffer, offset):

author
#4 lore raw

ping

Quoted 53 lines · Peng Liu

ping

Quoted 50 lines · Peng Liu

ping

Quoted 47 lines · On 2022/7/20 20:27, [email protected] wrote:

From: Peng Liu <[email protected]>

Below incompatibilities between Python2 and Python3 made lx-timerlist fail to run under Python3.

o xrange() is replaced by range() in Python3
o bytes and str are different types in Python3
o the return value of Inferior.read_memory() is memoryview object in Python3

---
  scripts/gdb/linux/timerlist.py | 4 +++-
  scripts/gdb/linux/utils.py     | 5 ++++-

  2 files changed, 7 insertions(+), 2 deletions(-)
scripts/gdb/linux/timerlist.py +1 -1
index 44e39dc3eb64..8281da068c5b 100644
@@ -72,7 +72,7 @@ def print_cpu(hrtimer_bases, cpu, max_clock_bases):
       ts = cpus.per_cpu(tick_sched_ptr, cpu)
         text = "cpu: {}\n".format(cpu)
-    for i in xrange(max_clock_bases):
+    for i in range(max_clock_bases):
           text += " clock {}:\n".format(i)
           text += print_base(cpu_base['clock_base'][i])

  @@ -157,6 +157,8 @@ def pr_cpumask(mask):
      num_bytes = (nr_cpu_ids + 7) / 8
      buf = utils.read_memoryview(inf, bits, num_bytes).tobytes() buf = binascii.b2a_hex(buf)
+    if type(buf) is not str:
+        buf=buf.decode()
        chunks = []
      i = num_bytes

scripts/gdb/linux/utils.py +0 -0
index ff7c1799d588..db59f986c7fd 100644
@@ -89,7 +89,10 @@ def get_target_endianness():

      def read_memoryview(inf, start, length):
-    return memoryview(inf.read_memory(start, length)) +    m = inf.read_memory(start, length)
+    if type(m) is memoryview:
+        return m
+    return memoryview(m)
      def read_u16(buffer, offset):

maintainer
#5 lore raw
In reply to [email protected]
Quoted 9 lines · On 20.07.22 14:27, [email protected] wrote:

From: Peng Liu <[email protected]>

Below incompatibilities between Python2 and Python3 made lx-timerlist fail to run under Python3.

o xrange() is replaced by range() in Python3
o bytes and str are different types in Python3
o the return value of Inferior.read_memory() is memoryview object in Python3

Means this only ever worked with Python2? And we now hard-switch it to Python3? Not voting against this, just confused if it was like this so far.

Jan

Quoted 45 lines
---
 scripts/gdb/linux/timerlist.py | 4 +++-
 scripts/gdb/linux/utils.py     | 5 ++++-
 2 files changed, 7 insertions(+), 2 deletions(-)
scripts/gdb/linux/timerlist.py +3 -1
index 44e39dc3eb64..8281da068c5b 100644
@@ -72,7 +72,7 @@ def print_cpu(hrtimer_bases, cpu, max_clock_bases):
     ts = cpus.per_cpu(tick_sched_ptr, cpu)
 
     text = "cpu: {}\n".format(cpu)
-    for i in xrange(max_clock_bases):
+    for i in range(max_clock_bases):
         text += " clock {}:\n".format(i)
         text += print_base(cpu_base['clock_base'][i])
 
@@ -157,6 +157,8 @@ def pr_cpumask(mask):
     num_bytes = (nr_cpu_ids + 7) / 8
     buf = utils.read_memoryview(inf, bits, num_bytes).tobytes()
     buf = binascii.b2a_hex(buf)
+    if type(buf) is not str:
+        buf=buf.decode()
 
     chunks = []
     i = num_bytes
scripts/gdb/linux/utils.py +4 -1
index ff7c1799d588..db59f986c7fd 100644
@@ -89,7 +89,10 @@ def get_target_endianness():
 
 
 def read_memoryview(inf, start, length):
-    return memoryview(inf.read_memory(start, length))
+    m = inf.read_memory(start, length)
+    if type(m) is memoryview:
+        return m
+    return memoryview(m)
 
 
 def read_u16(buffer, offset):
Signature · 2 lines
Siemens AG, Technology
Competence Center Embedded Linux
author
#6 lore raw
Quoted 6 lines · Jan Kiszka
Quoted 5 lines · On 20.07.22 14:27, [email protected] wrote:

From: Peng Liu <[email protected]>

Below incompatibilities between Python2 and Python3 made lx-timerlist fail to run under Python3.

Quoted 8 lines
Quoted 4 lines

o xrange() is replaced by range() in Python3
o bytes and str are different types in Python3
o the return value of Inferior.read_memory() is memoryview object in Python3

Means this only ever worked with Python2? And we now hard-switch it to Python3? Not voting against this, just confused if it was like this so far.

Jan

I think so. I tried the other gdb scripts and they worked for both python2 and python3. I guess timerlist.py was initially tested only with a gdb with python2 support built in but not one with python3 support built in.

Quoted 44 lines
Quoted 44 lines
---
  scripts/gdb/linux/timerlist.py | 4 +++-
  scripts/gdb/linux/utils.py     | 5 ++++-
  2 files changed, 7 insertions(+), 2 deletions(-)
scripts/gdb/linux/timerlist.py +3 -1
index 44e39dc3eb64..8281da068c5b 100644
@@ -72,7 +72,7 @@ def print_cpu(hrtimer_bases, cpu, max_clock_bases):
      ts = cpus.per_cpu(tick_sched_ptr, cpu)
 
      text = "cpu: {}\n".format(cpu)
-    for i in xrange(max_clock_bases):
+    for i in range(max_clock_bases):
          text += " clock {}:\n".format(i)
          text += print_base(cpu_base['clock_base'][i])
 
@@ -157,6 +157,8 @@ def pr_cpumask(mask):
      num_bytes = (nr_cpu_ids + 7) / 8
      buf = utils.read_memoryview(inf, bits, num_bytes).tobytes()
      buf = binascii.b2a_hex(buf)
+    if type(buf) is not str:
+        buf=buf.decode()
 
      chunks = []
      i = num_bytes
scripts/gdb/linux/utils.py +4 -1
index ff7c1799d588..db59f986c7fd 100644
@@ -89,7 +89,10 @@ def get_target_endianness():
 
 
  def read_memoryview(inf, start, length):
-    return memoryview(inf.read_memory(start, length))
+    m = inf.read_memory(start, length)
+    if type(m) is memoryview:
+        return m
+    return memoryview(m)
 
 
  def read_u16(buffer, offset):
#7 lore raw

PATCH 3/3 scripts/gdb: fix lx-timerlist for HRTIMER_MAX_CLOCK_BASES printing

In reply to a message not in the archive

From: Peng Liu <[email protected]>

HRTIMER_MAX_CLOCK_BASES is of enum type hrtimer_base_type. To print it as an integer, HRTIMER_MAX_CLOCK_BASES should be converted first.

---
 scripts/gdb/linux/timerlist.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/gdb/linux/timerlist.py +2 -1
index 8281da068c5b..249f0e804b24 100644
@@ -188,7 +188,8 @@ class LxTimerList(gdb.Command):
         max_clock_bases = gdb.parse_and_eval("HRTIMER_MAX_CLOCK_BASES")
 
         text = "Timer List Version: gdb scripts\n"
-        text += "HRTIMER_MAX_CLOCK_BASES: {}\n".format(max_clock_bases)
+        text += "HRTIMER_MAX_CLOCK_BASES: {}\n".format(
+            max_clock_bases.type.fields()[max_clock_bases].enumval)
         text += "now at {} nsecs\n".format(ktime_get())
 
         for cpu in cpus.each_online_cpu():
Signature · 1 line
2.25.1
author
#8 lore raw

Re: [PATCH 3/3] scripts/gdb: fix lx-timerlist for HRTIMER_MAX_CLOCK_BASES printing

Quoted 24 lines · On 2022/7/20 20:27, [email protected] wrote:

From: Peng Liu <[email protected]>

HRTIMER_MAX_CLOCK_BASES is of enum type hrtimer_base_type. To print it as an integer, HRTIMER_MAX_CLOCK_BASES should be converted first.

---
  scripts/gdb/linux/timerlist.py | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
scripts/gdb/linux/timerlist.py +2 -1
index 8281da068c5b..249f0e804b24 100644
@@ -188,7 +188,8 @@ class LxTimerList(gdb.Command):
          max_clock_bases = gdb.parse_and_eval("HRTIMER_MAX_CLOCK_BASES")
 
          text = "Timer List Version: gdb scripts\n"
-        text += "HRTIMER_MAX_CLOCK_BASES: {}\n".format(max_clock_bases)
+        text += "HRTIMER_MAX_CLOCK_BASES: {}\n".format(
+            max_clock_bases.type.fields()[max_clock_bases].enumval)
          text += "now at {} nsecs\n".format(ktime_get())
 
          for cpu in cpus.each_online_cpu():
author
#9 lore raw

Re: [PATCH 3/3] scripts/gdb: fix lx-timerlist for HRTIMER_MAX_CLOCK_BASES printing

ping

Quoted 24 lines · Peng Liu
Quoted 22 lines · On 2022/7/20 20:27, [email protected] wrote:

From: Peng Liu <[email protected]>

HRTIMER_MAX_CLOCK_BASES is of enum type hrtimer_base_type. To print it as an integer, HRTIMER_MAX_CLOCK_BASES should be converted first.

---
  scripts/gdb/linux/timerlist.py | 3 ++-

  1 file changed, 2 insertions(+), 1 deletion(-)
scripts/gdb/linux/timerlist.py +0 -0
index 8281da068c5b..249f0e804b24 100644
@@ -188,7 +188,8 @@ class LxTimerList(gdb.Command):
           max_clock_bases = gdb.parse_and_eval("HRTIMER_MAX_CLOCK_BASES")

            text = "Timer List Version: gdb scripts\n"
-        text += "HRTIMER_MAX_CLOCK_BASES: {}\n".format(max_clock_bases) +        text += "HRTIMER_MAX_CLOCK_BASES: {}\n".format(
+ max_clock_bases.type.fields()[max_clock_bases].enumval) text += "now at {} nsecs\n".format(ktime_get()) for cpu in cpus.each_online_cpu():

author
#10 lore raw

Re: [PATCH 3/3] scripts/gdb: fix lx-timerlist for HRTIMER_MAX_CLOCK_BASES printing

ping

Quoted 28 lines · Peng Liu

ping

Quoted 25 lines · Peng Liu
Quoted 23 lines · On 2022/7/20 20:27, [email protected] wrote:

From: Peng Liu <[email protected]>

HRTIMER_MAX_CLOCK_BASES is of enum type hrtimer_base_type. To print it as an integer, HRTIMER_MAX_CLOCK_BASES should be converted first.

---
  scripts/gdb/linux/timerlist.py | 3 ++-

  1 file changed, 2 insertions(+), 1 deletion(-)
scripts/gdb/linux/timerlist.py +0 -0
index 8281da068c5b..249f0e804b24 100644
@@ -188,7 +188,8 @@ class LxTimerList(gdb.Command):
           max_clock_bases = gdb.parse_and_eval("HRTIMER_MAX_CLOCK_BASES")

            text = "Timer List Version: gdb scripts\n" -        text += "HRTIMER_MAX_CLOCK_BASES:
{}\n".format(max_clock_bases)
+        text += "HRTIMER_MAX_CLOCK_BASES: {}\n".format(
+ max_clock_bases.type.fields()[max_clock_bases].enumval) text += "now at {} nsecs\n".format(ktime_get()) for cpu in cpus.each_online_cpu():

maintainer Reviewed-by on v1 3/3
#11 lore raw

Re: [PATCH 3/3] scripts/gdb: fix lx-timerlist for HRTIMER_MAX_CLOCK_BASES printing

In reply to [email protected]
Quoted 15 lines · On 20.07.22 14:27, [email protected] wrote:

From: Peng Liu <[email protected]>

HRTIMER_MAX_CLOCK_BASES is of enum type hrtimer_base_type. To print it as an integer, HRTIMER_MAX_CLOCK_BASES should be converted first.

---
 scripts/gdb/linux/timerlist.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/gdb/linux/timerlist.py +0 -0
index 8281da068c5b..249f0e804b24 100644

scripts/gdb/linux/timerlist.py class LxTimerList(gdb.Command): · line 195

Quoted 9 lines
scripts/gdb/linux/timerlist.py +2 -1
@@ -188,7 +188,8 @@ class LxTimerList(gdb.Command):
         max_clock_bases = gdb.parse_and_eval("HRTIMER_MAX_CLOCK_BASES")
 
         text = "Timer List Version: gdb scripts\n"
-        text += "HRTIMER_MAX_CLOCK_BASES: {}\n".format(max_clock_bases)
+        text += "HRTIMER_MAX_CLOCK_BASES: {}\n".format(
+            max_clock_bases.type.fields()[max_clock_bases].enumval)
         text += "now at {} nsecs\n".format(ktime_get())
 
         for cpu in cpus.each_online_cpu():

Jan

Signature · 2 lines
Siemens AG, Technology
Competence Center Embedded Linux