scripts/gdb: fix lx-timerlist for Python3
A message that is not in the archive (sent off-list or not yet received): [email protected]
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
@@ -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
@@ -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
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 byrange()in Python3
o bytes and str are different types in Python3
o the return value ofInferior.read_memory()is memoryview object in Python3Signed-off-by Peng Liu <[email protected]>--- 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@@ -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_bytesscripts/gdb/linux/utils.py +4
-1@@ -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):
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 byrange()in Python3
o bytes and str are different types in Python3
o the return value ofInferior.read_memory()is memoryview object in Python3Signed-off-by Peng Liu <[email protected]>---
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@@ -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_bytesscripts/gdb/linux/utils.py +0
-0@@ -89,7 +89,10 @@ def get_target_endianness():def
read_memoryview(inf, start, length):
- returnmemoryview(inf.read_memory(start, length))+ m =inf.read_memory(start, length)
+ if type(m) is memoryview:
+ return m
+ return memoryview(m)
defread_u16(buffer, offset):
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 byrange()in Python3
o bytes and str are different types in Python3
o the return value ofInferior.read_memory()is memoryview object in Python3Signed-off-by Peng Liu <[email protected]>---
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@@ -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_bytesscripts/gdb/linux/utils.py +0
-0@@ -89,7 +89,10 @@ def get_target_endianness():def
read_memoryview(inf, start, length):
- returnmemoryview(inf.read_memory(start, length))+ m =inf.read_memory(start, length)
+ if type(m) is memoryview:
+ return m
+ return memoryview(m)
defread_u16(buffer, offset):
Jan Kiszka
maintainerQuoted 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 byrange()in Python3
o bytes and str are different types in Python3
o the return value ofInferior.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
Signed-off-by Peng Liu <[email protected]>--- 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@@ -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_bytesscripts/gdb/linux/utils.py +4
-1@@ -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
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 byrange()in Python3
o bytes and str are different types in Python3
o the return value ofInferior.read_memory()is memoryview object in Python3Means 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
Signed-off-by Peng Liu <[email protected]>--- 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@@ -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_bytesscripts/gdb/linux/utils.py +4
-1@@ -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):
PATCH 3/3 scripts/gdb: fix lx-timerlist for HRTIMER_MAX_CLOCK_BASES printing
In reply to a message not in the archiveFrom: 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
@@ -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
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_BASESis of enum typehrtimer_base_type. To print it as an integer,HRTIMER_MAX_CLOCK_BASESshould be converted first.Signed-off-by Peng Liu <[email protected]>--- scripts/gdb/linux/timerlist.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)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():
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_BASESis of enum typehrtimer_base_type. To print it as an integer,HRTIMER_MAX_CLOCK_BASESshould be converted first.Signed-off-by Peng Liu <[email protected]>---
scripts/gdb/linux/timerlist.py| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)scripts/gdb/linux/timerlist.py +0
-0@@ -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 incpus.each_online_cpu():
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_BASESis of enum typehrtimer_base_type. To print it as an integer,HRTIMER_MAX_CLOCK_BASESshould be converted first.Signed-off-by Peng Liu <[email protected]>---
scripts/gdb/linux/timerlist.py| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)scripts/gdb/linux/timerlist.py +0
-0@@ -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 incpus.each_online_cpu():
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_BASESis of enum typehrtimer_base_type. To print it as an integer,HRTIMER_MAX_CLOCK_BASESshould be converted first.Signed-off-by Peng Liu <[email protected]>--- scripts/gdb/linux/timerlist.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)scripts/gdb/linux/timerlist.py +0
-0
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