Skip to content

Commit b041cf0

Browse files
committed
[lldb] Correctly invalidate unloaded image tokens
Some functions in Process were using LLDB_INVALID_ADDRESS instead of LLDB_INVALID_TOKEN. The only visible effect of this appears to be that "process unload <tab>" would complete to 0 even after the image was unloaded. Since the command is checking for LLDB_INVALID_TOKEN. Everything else worked somehow. I've added a check to the existing load unload tests anyway. The tab completion cannot be checked as is, but when I make them more strict in a later patch it will be tested.
1 parent 2618154 commit b041cf0

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ uint32_t PlatformPOSIX::DoLoadImage(lldb_private::Process *process,
949949
Status PlatformPOSIX::UnloadImage(lldb_private::Process *process,
950950
uint32_t image_token) {
951951
const addr_t image_addr = process->GetImagePtrFromToken(image_token);
952-
if (image_addr == LLDB_INVALID_ADDRESS)
952+
if (image_addr == LLDB_INVALID_IMAGE_TOKEN)
953953
return Status("Invalid image token");
954954

955955
StreamString expr;

lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ uint32_t PlatformWindows::DoLoadImage(Process *process,
415415

416416
Status PlatformWindows::UnloadImage(Process *process, uint32_t image_token) {
417417
const addr_t address = process->GetImagePtrFromToken(image_token);
418-
if (address == LLDB_INVALID_ADDRESS)
418+
if (address == LLDB_INVALID_IMAGE_TOKEN)
419419
return Status("invalid image token");
420420

421421
StreamString expression;

lldb/source/Target/Process.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5911,12 +5911,12 @@ size_t Process::AddImageToken(lldb::addr_t image_ptr) {
59115911
lldb::addr_t Process::GetImagePtrFromToken(size_t token) const {
59125912
if (token < m_image_tokens.size())
59135913
return m_image_tokens[token];
5914-
return LLDB_INVALID_ADDRESS;
5914+
return LLDB_INVALID_IMAGE_TOKEN;
59155915
}
59165916

59175917
void Process::ResetImageToken(size_t token) {
59185918
if (token < m_image_tokens.size())
5919-
m_image_tokens[token] = LLDB_INVALID_ADDRESS;
5919+
m_image_tokens[token] = LLDB_INVALID_IMAGE_TOKEN;
59205920
}
59215921

59225922
Address

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,15 @@ def run_lldb_process_load_and_unload_commands(self):
307307
patterns=["Unloading .* with index %s.*ok" % index],
308308
)
309309

310+
# Confirm that we unloaded properly.
311+
self.expect(
312+
"image lookup -n a_function",
313+
"a_function should not exist after unload",
314+
error=True,
315+
matching=False,
316+
patterns=["1 match found"],
317+
)
318+
310319
self.runCmd("process continue")
311320

312321
@expectedFailureAll(oslist=["windows"]) # breakpoint not hit

0 commit comments

Comments
 (0)