[Lldb-commits] [PATCH] D39199: [lldbtests] Handle errors instead of crashing

Davide Italiano via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Oct 23 11:08:30 PDT 2017


davide created this revision.

If you pass an invalid compiler/debugger path on the cmdline to `dotest.py`  this is what you get.

  $ python dotest.py --executable /home/davide/work/build-lldb/bin/lldb --compiler /home/davide/work/build-lldb/bin/clandasfaasdfsg
  Traceback (most recent call last):
    File "dotest.py", line 7, in <module>
      lldbsuite.test.run_suite()
    File "/home/davide/work/llvm-lldb/tools/lldb/packages/Python/lldbsuite/test/dotest.py", line 1099, in run_suite
      parseOptionsAndInitTestdirs()
    File "/home/davide/work/llvm-lldb/tools/lldb/packages/Python/lldbsuite/test/dotest.py", line 282, in parseOptionsAndInitTestdirs
      if not is_exe(configuration.compiler):
    File "/home/davide/work/llvm-lldb/tools/lldb/packages/Python/lldbsuite/test/dotest.py", line 54, in is_exe
      return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
    File "/usr/lib64/python2.7/genericpath.py", line 37, in isfile
      st = os.stat(path)
  TypeError: coercing to Unicode: need string or buffer, NoneType found

And with the patch applied:

  $ python dotest.py --executable /home/davide/work/build-lldb/bin/lldb --compiler /home/davide/work/build-lldb/bin/clandasfasg
  /home/davide/work/build-lldb/bin/clandasfasg is not a valid path, exiting

Please let me know what you think.


Repository:
  rL LLVM

https://reviews.llvm.org/D39199

Files:
  packages/Python/lldbsuite/test/dotest.py


Index: packages/Python/lldbsuite/test/dotest.py
===================================================================
--- packages/Python/lldbsuite/test/dotest.py
+++ packages/Python/lldbsuite/test/dotest.py
@@ -50,7 +50,11 @@


 def is_exe(fpath):
-    """Returns true if fpath is an executable."""
+    """Returns true if fpath is an executable.
+       Exits with an error code if the specified path is invalid"""
+    if not os.path.exists(fpath):
+        print(fpath  + " is not a valid path, exiting")
+        sys.exit(-1)
     return os.path.isfile(fpath) and os.access(fpath, os.X_OK)




-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39199.119905.patch
Type: text/x-patch
Size: 595 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20171023/ac59c936/attachment.bin>


More information about the lldb-commits mailing list