Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LLDB][Linux]Can not load the right module when loading a module having same name but different path with a loaded module #95107

Open
LeoJialiang opened this issue Jun 11, 2024 · 1 comment

Comments

@LeoJialiang
Copy link

Some dynamic linker support to load module with the same name under different directories, like bionic.

When debugging a program which will link /PathA/liba.so by default, and it will dlopen /PathB/liba.so during runtime, the /PathB/liba.so can not be loaded correctly. LLDB will use /PathA/liba.so as the module of /PathB/liba.so. But /PathA/liba.so and /PathB/liba.so are different.

I find that, in Status NativeProcessLinux::GetLoadedModuleFileSpec , lldb will look for the module_path in the m_mem_region_cache, and just check the Filename without checking directory. This logic let lldb think two different so with same name the same.

Shall we change the NativeProcessLinux::GetLoadedModuleFileSpe to:
`Status NativeProcessLinux::GetLoadedModuleFileSpec(const char *module_path,
FileSpec &file_spec) {
Status error = PopulateMemoryRegionCache();
if (error.Fail())
return error;

FileSpec module_file_spec(module_path);
FileSystem::Instance().Resolve(module_file_spec);

file_spec.Clear();
for (const auto &it : m_mem_region_cache) {
if (it.second.GetFilename() == module_file_spec.GetFilename() &&
it.second.GetDirectory() == module_file_spec.GetDirectory()) {
file_spec = it.second;
return Status();
}
}
return Status("Module file (%s) not found in /proc/%" PRIu64 "/maps file!",
module_file_spec.GetFilename().AsCString(), GetID());
}`

I am not sure whether this change will make some other bug. Please take a look.

@llvmbot
Copy link
Collaborator

llvmbot commented Jun 11, 2024

@llvm/issue-subscribers-lldb

Author: None (LeoJialiang)

Some dynamic linker support to load module with the same name under different directories, like bionic.

When debugging a program which will link /PathA/liba.so by default, and it will dlopen /PathB/liba.so during runtime, the /PathB/liba.so can not be loaded correctly. LLDB will use /PathA/liba.so as the module of /PathB/liba.so. But /PathA/liba.so and /PathB/liba.so are different.

I find that, in Status NativeProcessLinux::GetLoadedModuleFileSpec , lldb will look for the module_path in the m_mem_region_cache, and just check the Filename without checking directory. This logic let lldb think two different so with same name the same.

Shall we change the NativeProcessLinux::GetLoadedModuleFileSpe to:
`Status NativeProcessLinux::GetLoadedModuleFileSpec(const char *module_path,
FileSpec &file_spec) {
Status error = PopulateMemoryRegionCache();
if (error.Fail())
return error;

FileSpec module_file_spec(module_path);
FileSystem::Instance().Resolve(module_file_spec);

file_spec.Clear();
for (const auto &it : m_mem_region_cache) {
if (it.second.GetFilename() == module_file_spec.GetFilename() &&
it.second.GetDirectory() == module_file_spec.GetDirectory()) {
file_spec = it.second;
return Status();
}
}
return Status("Module file (%s) not found in /proc/%" PRIu64 "/maps file!",
module_file_spec.GetFilename().AsCString(), GetID());
}`

I am not sure whether this change will make some other bug. Please take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants