[Lldb-commits] [lldb] [lldb] Correctly invalidate unloaded image tokens (PR #65945)
David Spickett via lldb-commits
lldb-commits at lists.llvm.org
Mon Sep 11 03:52:28 PDT 2023
https://github.com/DavidSpickett created https://github.com/llvm/llvm-project/pull/65945:
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.
>From a2d71320d618cc3900c3d20e0ea9c5e7b0220561 Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Mon, 11 Sep 2023 10:46:53 +0000
Subject: [PATCH] [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.
---
lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp | 2 +-
lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp | 2 +-
lldb/source/Target/Process.cpp | 4 ++--
.../API/functionalities/load_unload/TestLoadUnload.py | 9 +++++++++
4 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
index 1e91f2ccd198259..b4f1b76c39dbebf 100644
--- a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
+++ b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
@@ -949,7 +949,7 @@ uint32_t PlatformPOSIX::DoLoadImage(lldb_private::Process *process,
Status PlatformPOSIX::UnloadImage(lldb_private::Process *process,
uint32_t image_token) {
const addr_t image_addr = process->GetImagePtrFromToken(image_token);
- if (image_addr == LLDB_INVALID_ADDRESS)
+ if (image_addr == LLDB_INVALID_IMAGE_TOKEN)
return Status("Invalid image token");
StreamString expr;
diff --git a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
index cbac14e2ccf7a92..88d543289a8470e 100644
--- a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
+++ b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
@@ -415,7 +415,7 @@ uint32_t PlatformWindows::DoLoadImage(Process *process,
Status PlatformWindows::UnloadImage(Process *process, uint32_t image_token) {
const addr_t address = process->GetImagePtrFromToken(image_token);
- if (address == LLDB_INVALID_ADDRESS)
+ if (address == LLDB_INVALID_IMAGE_TOKEN)
return Status("invalid image token");
StreamString expression;
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 2b0774588138881..f82ab05362fbee9 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -5911,12 +5911,12 @@ size_t Process::AddImageToken(lldb::addr_t image_ptr) {
lldb::addr_t Process::GetImagePtrFromToken(size_t token) const {
if (token < m_image_tokens.size())
return m_image_tokens[token];
- return LLDB_INVALID_ADDRESS;
+ return LLDB_INVALID_IMAGE_TOKEN;
}
void Process::ResetImageToken(size_t token) {
if (token < m_image_tokens.size())
- m_image_tokens[token] = LLDB_INVALID_ADDRESS;
+ m_image_tokens[token] = LLDB_INVALID_IMAGE_TOKEN;
}
Address
diff --git a/lldb/test/API/functionalities/load_unload/TestLoadUnload.py b/lldb/test/API/functionalities/load_unload/TestLoadUnload.py
index 7e8acfa3021acfc..2208e520f1d5612 100644
--- a/lldb/test/API/functionalities/load_unload/TestLoadUnload.py
+++ b/lldb/test/API/functionalities/load_unload/TestLoadUnload.py
@@ -307,6 +307,15 @@ def run_lldb_process_load_and_unload_commands(self):
patterns=["Unloading .* with index %s.*ok" % index],
)
+ # Confirm that we unloaded properly.
+ self.expect(
+ "image lookup -n a_function",
+ "a_function should not exist after unload",
+ error=True,
+ matching=False,
+ patterns=["1 match found"],
+ )
+
self.runCmd("process continue")
@expectedFailureAll(oslist=["windows"]) # breakpoint not hit
More information about the lldb-commits
mailing list