2019-05-03 11:24:48

by Leonard Crestez

[permalink] [raw]
Subject: [PATCH 0/2] gdb/scripts: Improve lx-clk-summary

The earlier series adding clk support to gdb/scripts was quickly
accepted but some concerns were raised by Stephen Boyd so this series
attempts to address them.

Link to previous series: https://lkml.org/lkml/2019/4/22/55

This is not a v2 and squashing is not expected.

Fields other than clk rate not covered because they're much more rarely
used and cache logic can get more complicated and brittle.

LX_GDBPARSED is used in constants.py.in because python does not
understand C integer literal suffixes like the "1UL" from the definition
of BIT() used by CLK_GET_RATE_NOCACHE. Alternative workarounds would be
hacking away UL suffixes with sed or redefining BIT&co but relying on
gdb evaluation is easier and much more flexible.

Leonard Crestez (2):
scripts/gdb: Cleanup error handling in list helpers
scripts/gdb: Print cached rate in lx-clk-summary

scripts/gdb/linux/clk.py | 21 ++++++++++++++-------
scripts/gdb/linux/constants.py.in | 4 ++++
scripts/gdb/linux/lists.py | 10 ++--------
3 files changed, 20 insertions(+), 15 deletions(-)

--
2.17.1


2019-05-03 12:38:50

by Leonard Crestez

[permalink] [raw]
Subject: [PATCH 1/2] scripts/gdb: Cleanup error handling in list helpers

An incorrect argument to list_for_each is an internal error in gdb
scripts so a TypeError should be raised. The gdb.GdbError exception type
is intended for user errors such as incorrect invocation.

Drop the type assertion in list_for_each_entry because list_for_each isn't
going to suddenly yield something else.

Applies to both list and hlist

Signed-off-by: Leonard Crestez <[email protected]>
---
scripts/gdb/linux/lists.py | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/scripts/gdb/linux/lists.py b/scripts/gdb/linux/lists.py
index 55356b66f8ea..c487ddf09d38 100644
--- a/scripts/gdb/linux/lists.py
+++ b/scripts/gdb/linux/lists.py
@@ -22,45 +22,39 @@ hlist_node = utils.CachedType("struct hlist_node")

def list_for_each(head):
if head.type == list_head.get_type().pointer():
head = head.dereference()
elif head.type != list_head.get_type():
- raise gdb.GdbError("Must be struct list_head not {}"
+ raise TypeError("Must be struct list_head not {}"
.format(head.type))

node = head['next'].dereference()
while node.address != head.address:
yield node.address
node = node['next'].dereference()


def list_for_each_entry(head, gdbtype, member):
for node in list_for_each(head):
- if node.type != list_head.get_type().pointer():
- raise TypeError("Type {} found. Expected struct list_head *."
- .format(node.type))
yield utils.container_of(node, gdbtype, member)


def hlist_for_each(head):
if head.type == hlist_head.get_type().pointer():
head = head.dereference()
elif head.type != hlist_head.get_type():
- raise gdb.GdbError("Must be struct hlist_head not {}"
+ raise TypeError("Must be struct hlist_head not {}"
.format(head.type))

node = head['first'].dereference()
while node.address:
yield node.address
node = node['next'].dereference()


def hlist_for_each_entry(head, gdbtype, member):
for node in hlist_for_each(head):
- if node.type != hlist_node.get_type().pointer():
- raise TypeError("Type {} found. Expected struct hlist_head *."
- .format(node.type))
yield utils.container_of(node, gdbtype, member)


def list_check(head):
nb = 0
--
2.17.1

2019-05-03 18:38:13

by Stephen Boyd

[permalink] [raw]
Subject: Re: [PATCH 1/2] scripts/gdb: Cleanup error handling in list helpers

Quoting Leonard Crestez (2019-05-03 04:19:31)
> An incorrect argument to list_for_each is an internal error in gdb
> scripts so a TypeError should be raised. The gdb.GdbError exception type
> is intended for user errors such as incorrect invocation.
>
> Drop the type assertion in list_for_each_entry because list_for_each isn't
> going to suddenly yield something else.
>
> Applies to both list and hlist

This should be done to other "type errors" in the gdb scripts too.

>
> Signed-off-by: Leonard Crestez <[email protected]>
> ---

Either way,

Reviewed-by: Stephen Boyd <[email protected]>