From 2fb1d811855162fe9d723806a7b5fb995b14ff7b Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Sat, 3 Feb 2018 21:10:11 +0100 Subject: Add example that finds references to undefined symbols Does a global search over all architectures in the kernel, which should avoid false positives. Referencing an undefined symbol in a particular architecture can be fine in a Kconfig file that's shared by multiple architectures, but if the symbol isn't defined by any architecture, it's likely to be an error (or a potential cleanup). --- examples/find_symbol.py | 57 ++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 27 deletions(-) (limited to 'examples/find_symbol.py') diff --git a/examples/find_symbol.py b/examples/find_symbol.py index 63790c2..b490e4d 100644 --- a/examples/find_symbol.py +++ b/examples/find_symbol.py @@ -167,39 +167,42 @@ def nodes_referencing_sym(node, sym_name): return res -if len(sys.argv) < 3: - print('Pass symbol name (without "CONFIG_" prefix) with SCRIPT_ARG=') - sys.exit(1) +# find_undefined.py makes use nodes_referencing_sym(), so allow use to be +# imported +if __name__ == "__main__": + if len(sys.argv) < 3: + print('Pass symbol name (without "CONFIG_" prefix) with SCRIPT_ARG=') + sys.exit(1) -sym_name = sys.argv[2] + sym_name = sys.argv[2] -kconf = Kconfig(sys.argv[1]) -nodes = nodes_referencing_sym(kconf.top_node, sym_name) + kconf = Kconfig(sys.argv[1]) + nodes = nodes_referencing_sym(kconf.top_node, sym_name) -if not nodes: - print("No reference to '{}' found".format(sym_name)) - sys.exit() + if not nodes: + print("No reference to '{}' found".format(sym_name)) + sys.exit() -print("Found {} locations that reference '{}':\n".format(len(nodes), sym_name)) + print("Found {} locations that reference '{}':\n".format(len(nodes), sym_name)) -for i, node in enumerate(nodes, 1): - print("========== Location {} ({}:{}) ==========\n".format(i, node.filename, node.linenr)) - print(node) + for i, node in enumerate(nodes, 1): + print("========== Location {} ({}:{}) ==========\n".format(i, node.filename, node.linenr)) + print(node) - parent_i = 0 + parent_i = 0 - # Print the parents of the menu node too - while True: - node = node.parent - if node is kconf.top_node: - # Don't print the top node. Would say something like the following, - # which isn't that interesting: - # - # menu "Linux/$ARCH $KERNELVERSION Kernel Configuration" - break + # Print the parents of the menu node too + while True: + node = node.parent + if node is kconf.top_node: + # Don't print the top node. Would say something like the + # following, which isn't that interesting: + # + # menu "Linux/$ARCH $KERNELVERSION Kernel Configuration" + break - parent_i += 1 + parent_i += 1 - print("---------- Parent {} ({}:{}) ----------\n" - .format(parent_i, node.filename, node.linenr)) - print(node) + print("---------- Parent {} ({}:{}) ----------\n" + .format(parent_i, node.filename, node.linenr)) + print(node) -- cgit v1.2.3