Skip to content

Commit 6d9ce4e

Browse files
authored
Merge pull request #3760 from apple/🍒/austria/f75885977cef
Fix error reporting for "process load" and add a test for it.
2 parents 1d23ea9 + 68283ec commit 6d9ce4e

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,8 @@ PlatformPOSIX::MakeLoadImageUtilityFunction(ExecutionContext &exe_ctx,
589589
result_ptr->image_ptr = dlopen(name, RTLD_LAZY);
590590
if (result_ptr->image_ptr)
591591
result_ptr->error_str = nullptr;
592+
else
593+
result_ptr->error_str = dlerror();
592594
return nullptr;
593595
}
594596

lldb/test/API/functionalities/load_unload/TestLoadUnload.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,15 @@ def run_lldb_process_load_and_unload_commands(self):
240240
else:
241241
remoteDylibPath = localDylibPath
242242

243+
# First make sure that we get some kind of error if process load fails.
244+
# We print some error even if the load fails, which isn't formalized.
245+
# The only plugin at present (Posix) that supports this says "unknown reasons".
246+
# If another plugin shows up, let's require it uses "unknown error" as well.
247+
non_existant_shlib = "/NoSuchDir/NoSuchSubdir/ReallyNo/NotAFile"
248+
self.expect("process load %s"%(non_existant_shlib), error=True, matching=False,
249+
patterns=["unknown reasons"])
250+
251+
243252
# Make sure that a_function does not exist at this point.
244253
self.expect(
245254
"image lookup -n a_function",

lldb/test/API/functionalities/load_using_paths/TestLoadUsingPaths.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ def test_load_using_paths(self):
6565
# First try with no correct directories on the path, and make sure that doesn't blow up:
6666
token = process.LoadImageUsingPaths(lib_spec, paths, out_spec, error)
6767
self.assertEqual(token, lldb.LLDB_INVALID_IMAGE_TOKEN, "Only looked on the provided path.")
68-
68+
# Make sure we got some error back in this case. Since we don't actually know what
69+
# the error will look like, let's look for the absence of "unknown reasons".
70+
error_str = error.description
71+
self.assertNotEqual(len(error_str), 0, "Got an empty error string")
72+
self.assertNotIn("unknown reasons", error_str, "Error string had unknown reasons")
73+
6974
# Now add the correct dir to the paths list and try again:
7075
paths.AppendString(self.hidden_dir)
7176
token = process.LoadImageUsingPaths(lib_spec, paths, out_spec, error)
@@ -121,8 +126,6 @@ def test_load_using_paths(self):
121126

122127
process.UnloadImage(token)
123128

124-
125-
126129
# Finally, passing in an absolute path should work like the basename:
127130
# This should NOT work because we've taken hidden_dir off the paths:
128131
abs_spec = lldb.SBFileSpec(os.path.join(self.hidden_dir, self.lib_name))
@@ -137,5 +140,3 @@ def test_load_using_paths(self):
137140

138141
self.assertNotEqual(token, lldb.LLDB_INVALID_IMAGE_TOKEN, "Got a valid token")
139142
self.assertEqual(out_spec, lldb.SBFileSpec(self.hidden_lib), "Found the expected library")
140-
141-

0 commit comments

Comments
 (0)