diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -2134,6 +2134,14 @@ } } + // If we found a pre-existing module, just return it. + if (module_sp && !did_create_module && + m_images.FindModule(module_sp.get())) { + if (error_ptr) + *error_ptr = error; + return module_sp; + } + // We found a module that wasn't in our target list. Let's make sure that // there wasn't an equivalent module in the list already, and if there was, // let's remove it. diff --git a/lldb/test/Shell/Target/Inputs/main.c b/lldb/test/Shell/Target/Inputs/main.c new file mode 100644 --- /dev/null +++ b/lldb/test/Shell/Target/Inputs/main.c @@ -0,0 +1,2 @@ +__declspec(dllimport) void exportFunc(void); +int main() { exportFunc(); } diff --git a/lldb/test/Shell/Target/Inputs/shlib.c b/lldb/test/Shell/Target/Inputs/shlib.c new file mode 100644 --- /dev/null +++ b/lldb/test/Shell/Target/Inputs/shlib.c @@ -0,0 +1 @@ +__declspec(dllexport) void exportFunc(void) {} diff --git a/lldb/test/Shell/Target/dependent-modules-nodupe-windows.test b/lldb/test/Shell/Target/dependent-modules-nodupe-windows.test new file mode 100644 --- /dev/null +++ b/lldb/test/Shell/Target/dependent-modules-nodupe-windows.test @@ -0,0 +1,22 @@ +# REQUIRES: system-windows + +# Checks that dependent modules preloaded by LLDB are not duplicated when the +# process actually loads the DLL. + +# RUN: %clang_host -g0 -O0 -shared %S/Inputs/shlib.c -o %t.shlib.dll \ +# RUN: %if windows-msvc %{-Wl,-implib:%t.shlib.lib} \ +# RUN: %else %{-Wl,--out-implib=%t.shlib.lib%} +# RUN: %clang_host -g0 -O0 %S/Inputs/main.c %t.shlib.lib -o %t.main.exe +# RUN: %lldb -b -o "#before" -o "target modules list" -o "b main" -o run \ +# RUN: -o "#after" -o "target modules list" %t.main.exe | FileCheck %s + +# CHECK-LABEL: #before +# CHECK-NEXT: target modules list +# CHECK-NEXT: .main.exe +# CHECK-NEXT: .shlib.dll + +# CHECK-LABEL: #after +# CHECK-NEXT: target modules list +# CHECK-NEXT: .main.exe +# CHECK-NEXT: .shlib.dll +# CHECK-NOT: .shlib.dll