[Lldb-commits] [PATCH] D83840: [lldb][test] Prevent infinite loop while looking for use_lldb_suite_root.py.
Jordan Rupprecht via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Tue Jul 14 18:45:53 PDT 2020
rupprecht created this revision.
rupprecht added reviewers: labath, JDevlieghere.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.
use_lldb_suite.py looks for use_lldb_suite_root.py by checking parent directories. If for some reason it doesn't exist, it keeps checking parent directories until it finds it.
However, this only breaks when the parent directory is None, but at least on Linux, dirname('/') == '/', so this will never be None.
This changes the lookup to stop if the dirname(lldb_root) is unchanged. It still stops if dirname returns None on some systems.
Additionally, this makes the failure mode more visible -- if the root is not found, it complains loudly instead of silently failing, having later modules that need lldb_root fail.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D83840
Files:
lldb/test/API/use_lldb_suite.py
Index: lldb/test/API/use_lldb_suite.py
===================================================================
--- lldb/test/API/use_lldb_suite.py
+++ lldb/test/API/use_lldb_suite.py
@@ -7,22 +7,25 @@
lldb_root = os.path.dirname(
os.path.abspath(inspect.getfile(inspect.currentframe()))
)
+ # On Linux, dirname('/') == '/', so we keep looking in parent directories
+ # until the parent directory doesn't change.
+ prev_lldb_root = None
while True:
+ prev_lldb_root = lldb_root
lldb_root = os.path.dirname(lldb_root)
- if lldb_root is None:
- return None
+ if lldb_root is None or lldb_root == prev_lldb_root:
+ raise Exception("use_lldb_suite_root.py not found")
test_path = os.path.join(lldb_root, "use_lldb_suite_root.py")
if os.path.isfile(test_path):
return lldb_root
- return None
lldb_root = find_lldb_root()
-if lldb_root is not None:
- import imp
- fp, pathname, desc = imp.find_module("use_lldb_suite_root", [lldb_root])
- try:
- imp.load_module("use_lldb_suite_root", fp, pathname, desc)
- finally:
- if fp:
- fp.close()
+
+import imp
+fp, pathname, desc = imp.find_module("use_lldb_suite_root", [lldb_root])
+try:
+ imp.load_module("use_lldb_suite_root", fp, pathname, desc)
+finally:
+ if fp:
+ fp.close()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83840.278042.patch
Type: text/x-patch
Size: 1388 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200715/d8c5ffac/attachment-0001.bin>
More information about the lldb-commits
mailing list