summaryrefslogtreecommitdiff
path: root/examples/find_symbol.py
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2018-02-03 21:10:11 +0100
committerUlf Magnusson <ulfalizer@gmail.com>2018-02-03 22:35:38 +0100
commit2fb1d811855162fe9d723806a7b5fb995b14ff7b (patch)
tree0495940b986f36422044d279b6fa3c114d71ce16 /examples/find_symbol.py
parent35e5a38035fe55ea28790d76876ea24262dea544 (diff)
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).
Diffstat (limited to 'examples/find_symbol.py')
-rw-r--r--examples/find_symbol.py57
1 files changed, 30 insertions, 27 deletions
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=<name>')
- 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=<name>')
+ 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)