Skip to content

Commit c009dda

Browse files
George Hukusmour
George Hu
authored andcommitted
Handle corner case of loading modules from NT_FILE section
Summary: In the NT_FILE section of a core file, the path to module list could be followed by "(deleted)" , also path like "/dev/zero" could be in the list. 1. Regex for removing parenthesized suffix, so trailing "(deleted)" will be removed. 2. Regex for filter out modules to load. Test Plan: Before change: ``` (lldb) target create --core "~/9s728w5ktv6jaraw" Core file '/home/hyubo/9s728w5ktv6jaraw' (x86_64) was loaded. (lldb) bt * thread #1, name = 'fbflow', stop reason = signal SIGSEGV * frame #0: 0x000000000974350e fbflow (deleted) frame #1: 0x0000000009744270 fbflow (deleted) frame #2: 0x000000000285b27e fbflow (deleted) frame llvm#3: 0x0000000008a47872 fbflow (deleted) frame llvm#4: 0x0000000008a46fe0 fbflow (deleted) frame llvm#5: 0x0000000008a45429 fbflow (deleted) frame llvm#6: 0x0000000008a46708 fbflow (deleted) frame llvm#7: 0x0000000008a45fb4 fbflow (deleted) frame llvm#8: 0x0000000008a44cf4 fbflow (deleted) frame llvm#9: 0x00000000027422c2 fbflow (deleted) frame llvm#10: 0x0000000002744b7e fbflow (deleted) frame llvm#11: 0x00007f6395a2c657 libc.so.6 (deleted) frame llvm#12: 0x00007f6395a2c718 libc.so.6 (deleted) ``` After change: ``` (lldb) target create --core "~/9s728w5ktv6jaraw" Core file '/home/hyubo/9s728w5ktv6jaraw' (x86_64) was loaded. (lldb) bt * thread #1, name = 'fbflow', stop reason = signal SIGSEGV * frame #0: 0x000000000974350e fbflow`void folly::futures::detail::coreDetachPromiseMaybeWithResult<facebook::cryptocat::store::SingleResult>(folly::futures::detail::Core<facebook::cryptocat::store::SingleResult>&) + 143 frame #1: 0x0000000009744270 fbflow`void folly::detail::function::FunctionTraits<void (folly::futures::detail::CoreBase&, folly::Executor::KeepAlive<folly::Executor>&&, folly::exception_wrapper*)>::callBig<void folly::futures::detail::Core<facebook::cryptocat::store::SingleResult>::setCallback<std::enable_if<folly::futures::detail::tryExecutorCallableResult<facebook::cryptocat::store::SingleResult, folly::Future<folly::futures::detail::tryCallableResult<facebook::cryptocat::store::SingleResult, facebook::cryptocat::store::SingleRequest, std::enable_if<is_invocable_v<facebook::cryptocat::store::SingleRequest, folly::Try<facebook::cryptocat::store::SingleResult>&&>, void>::type>::value_type> folly::Future<facebook::cryptocat::store::SingleResult>::thenTryInline<folly::SemiFuture<facebook::cryptocat::store::SingleResult> folly::SemiFuture<facebook::cryptocat::store::SingleResult>::deferError<folly::SemiFuture<facebook::cryptocat::store::SingleRequest::Result_t> facebook::cryptocat::store::DerivedCryptoStore::semifuture_loadImpl<facebook::cryptocat::store::SingleRequest>(facebook::cryptocat::store::SingleRequest const&) const::'lambda'(facebook::cryptocat::store::SingleRequest&&)>(facebook::cryptocat::store::SingleRequest&&) &&::'lambda'(folly::Try<facebook::cryptocat::store::SingleResult>)>(facebook::cryptocat::store::SingleRequest&&) &&::'lambda'(folly::Executor::KeepAlive<folly::Executor>&&, folly::Try<facebook::cryptocat::store::SingleResult>&&), void>::ReturnsFuture::value, folly::futures::detail::tryExecutorCallableResult<facebook::cryptocat::store::SingleResult, folly::Future<folly::futures::detail::tryCallableResult<facebook::cryptocat::store::SingleResult, facebook::cryptocat::store::SingleRequest, std::enable_if<is_invocable_v<facebook::cryptocat::store::SingleRequest, folly::Try<facebook::cryptocat::store::SingleResult>&&>, void>::type>::value_type> folly::Future<facebook::cryptocat::store::SingleResult>::thenTryInline<folly::SemiFuture<facebook::cryptocat::store::SingleResult> folly::SemiFuture<facebook::cryptocat::store::SingleResult>::deferError<folly::SemiFuture<facebook::cryptocat::store::SingleRequest::Result_t> facebook::cryptocat::store::DerivedCryptoStore::semifuture_loadImpl<facebook::cryptocat::store::SingleRequest>(facebook::cryptocat::store::SingleRequest const&) const::'lambda'(facebook::cryptocat::store::SingleRequest&&)>(facebook::cryptocat::store::SingleRequest&&) &&::'lambda'(folly::Try<facebook::cryptocat::store::SingleResult>)>(facebook::cryptocat::store::SingleRequest&&) &&::'lambda'(folly::Executor::KeepAlive<folly::Executor>&&, folly::Try<facebook::cryptocat::store::SingleResult>&&), void>::Return>::type folly::futures::detail::FutureBase<facebook::cryptocat::store::SingleResult>::thenImplementation<folly::Future<folly::futures::detail::tryCallableResult<facebook::cryptocat::store::SingleResult, facebook::cryptocat::store::SingleRequest, std::enable_if<is_invocable_v<facebook::cryptocat::store::SingleRequest, folly::Try<facebook::cryptocat::store::SingleResult>&&>, void>::type>::value_type> folly::Future<facebook::cryptocat::store::SingleResult>::thenTryInline<folly::SemiFuture<facebook::cryptocat::store::SingleResult> folly::SemiFuture<facebook::cryptocat::store::SingleResult>::deferError<folly::SemiFuture<facebook::cryptocat::store::SingleRequest::Result_t> facebook::cryptocat::store::DerivedCryptoStore::semifuture_loadImpl<facebook::cryptocat::store::SingleRequest>(facebook::cryptocat::store::SingleRequest const&) const::'lambda'(facebook::cryptocat::store::SingleRequest&&)>(facebook::cryptocat::store::SingleRequest&&) &&::'lambda'(folly::Try<facebook::cryptocat::store::SingleResult>)>(facebook::cryptocat::store::SingleRequest&&) &&::'lambda'(folly::Executor::KeepAlive<folly::Executor>&&, folly::Try<facebook::cryptocat::store::SingleResult>&&), folly::futures::detail::tryExecutorCallableResult<facebook::cryptocat::store::SingleResult, folly::Future<folly::futures::detail::tryCallableResult<facebook::cryptocat::store::SingleResult, facebook::cryptocat::store::SingleRequest, std::enable_if<is_invocable_v<facebook::cryptocat::store::SingleRequest, folly::Try<facebook::cryptocat::store::SingleResult>&&>, void>::type>::value_type> folly::Future<facebook::cryptocat::store::SingleResult>::thenTryInline<folly::SemiFuture<facebook::cryptocat::store::SingleResult> folly::SemiFuture<facebook::cryptocat::store::SingleResult>::deferError<folly::SemiFuture<facebook::cryptocat::store::SingleRequest::Result_t> facebook::cryptocat::store::DerivedCryptoStore::semifuture_loadImpl<facebook::cryptocat::store::SingleRequest>(facebook::cryptocat::store::SingleRequest const&) const::'lambda'(facebook::cryptocat::store::SingleRequest&&)>(facebook::cryptocat::store::SingleRequest&&) &&::'lambda'(folly::Try<facebook::cryptocat::store::SingleResult>)>(facebook::cryptocat::store::SingleRequest&&) &&::'lambda'(folly::Executor::KeepAlive<folly::Executor>&&, folly::Try<facebook::cryptocat::store::SingleResult>&&), void>>(facebook::cryptocat::store::SingleRequest&&, folly::futures::detail::tryExecutorCallableResult<facebook::cryptocat::store::SingleResult, folly::Future<folly::futures::detail::tryCallableResult<facebook::cryptocat::store::SingleResult, facebook::cryptocat::store::SingleRequest, std::enable_if<is_invocable_v<facebook::cryptocat::store::SingleRequest, folly::Try<facebook::cryptocat::store::SingleResult>&&>, void>::type>::value_type> folly::Future<facebook::cryptocat::store::SingleResult>::thenTryInline<folly::SemiFuture<facebook::cryptocat::store::SingleResult> folly::SemiFuture<facebook::cryptocat::store::SingleResult>::deferError<folly::SemiFuture<facebook::cryptocat::store::SingleRequest::Result_t> facebook::cryptocat::store::DerivedCryptoStore::semifuture_loadImpl<facebook::cryptocat::store::SingleRequest>(facebook::cryptocat::store::SingleRequest const&) const::'lambda'(facebook::cryptocat::store::SingleRequest&&)>(facebook::cryptocat::store::SingleRequest&&) &&::'lambda'(folly::Try<facebook::cryptocat::store::SingleResult>)>(facebook::cryptocat::store::SingleRequest&&) &&::'lambda'(folly::Executor::KeepAlive<folly::Executor>&&, folly::Try<facebook::cryptocat::store::SingleResult>&&), void>, folly::futures::detail::InlineContinuation)::'lambda'(folly::Executor::KeepAlive<folly::Executor>&&, folly::Try<facebook::cryptocat::store::SingleResult>&&)>(facebook::cryptocat::store::SingleRequest&&, std::shared_ptr<folly::RequestContext>&&, folly::futures::detail::InlineContinuation)::'lambda'(folly::futures::detail::CoreBase&, folly::Executor::KeepAlive<folly::Executor>&&, folly::exception_wrapper*)>(folly::futures::detail::CoreBase&, folly::Executor::KeepAlive<folly::Executor>&&, folly::exception_wrapper*, folly::detail::function::Data&) + 20 frame #2: 0x000000000285b27e fbflow`bool folly::fibers::Baton::try_wait_until<std::chrono::_V2::steady_clock, std::chrono::duration<long, std::ratio<1l, 1000000000l>>, bool folly::fibers::Baton::try_wait_until<std::chrono::_V2::steady_clock, std::chrono::duration<long, std::ratio<1l, 1000000000l>>>(std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long, std::ratio<1l, 1000000000l>>> const&)::'lambda'()>(std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long, std::ratio<1l, 1000000000l>>> const&, bool folly::fibers::Baton::try_wait_until<std::chrono::_V2::steady_clock, std::chrono::duration<long, std::ratio<1l, 1000000000l>>>(std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long, std::ratio<1l, 1000000000l>>> const&)::'lambda'()&&) + 342 frame llvm#3: 0x0000000008a47872 fbflow`facebook::logger::(anonymous namespace)::recordScubaSampleForTesting(facebook::logger::CippEventsV2UnsampledLogEntryInternal const&, long, folly::ReadMostlySharedPtr<facebook::logger::CippEventsV2UnsampledLogLineDefinition, folly::TLRefCount>, facebook::logger::WhenceScribeLogged const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) (.__uniq.66043386987841263013456630564440847059) + 3452 frame llvm#4: 0x0000000008a46fe0 fbflow`facebook::logger::(anonymous namespace)::recordScubaSampleForTesting(facebook::logger::CippEventsV2UnsampledLogEntryInternal const&, long, folly::ReadMostlySharedPtr<facebook::logger::CippEventsV2UnsampledLogLineDefinition, folly::TLRefCount>, facebook::logger::WhenceScribeLogged const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) (.__uniq.66043386987841263013456630564440847059) + 1258 frame llvm#5: 0x0000000008a45429 fbflow`int facebook::logger::CippEventsV2UnsampledLogger::invokeLog<std::nullptr_t, std::nullptr_t>(bool, std::nullptr_t, char const*, int, std::nullptr_t)::'lambda1'()::operator()() const + 2357 frame llvm#6: 0x0000000008a46708 fbflow`int facebook::logger::CippEventsV2UnsampledLogger::invokeLog<std::nullptr_t, std::nullptr_t>(bool, std::nullptr_t, char const*, int, std::nullptr_t)::'lambda3'()::operator()() const + 3060 frame llvm#7: 0x0000000008a45fb4 fbflow`int facebook::logger::CippEventsV2UnsampledLogger::invokeLog<std::nullptr_t, std::nullptr_t>(bool, std::nullptr_t, char const*, int, std::nullptr_t)::'lambda3'()::operator()() const + 1184 frame llvm#8: 0x0000000008a44cf4 fbflow`int facebook::logger::CippEventsV2UnsampledLogger::invokeLog<std::nullptr_t, std::nullptr_t>(bool, std::nullptr_t, char const*, int, std::nullptr_t)::'lambda1'()::operator()() const + 512 ... Reviewers: jeffreytan, gclayton Reviewed By: jeffreytan Subscribers: #lldb_team Differential Revision: https://phabricator.intern.facebook.com/D49565956 Tasks: T164491560
1 parent 939938e commit c009dda

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

lldb/source/Plugins/DynamicLoader/ModuleList-DYLD/DynamicLoaderDumpWithModuleList.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "lldb/Utility/Log.h"
1717

1818
#include "Plugins/ObjectFile/Placeholder/ObjectFilePlaceholder.h"
19+
#include <regex>
1920

2021
using namespace lldb;
2122
using namespace lldb_private;
@@ -155,14 +156,28 @@ void DynamicLoaderDumpWithModuleList::LoadAllModules(
155156
addr_t base_addr, module_size;
156157
std::string name;
157158
if (!mod_info.get_base(base_addr) || !mod_info.get_name(name) ||
158-
!mod_info.get_size(module_size))
159+
!mod_info.get_size(module_size) || !ShouldLoadModule(name))
159160
continue;
160161

161-
callback(name, base_addr, module_size);
162+
callback(SanitizeName(name), base_addr, module_size);
162163
}
163164
}
164165
}
165166

167+
bool DynamicLoaderDumpWithModuleList::ShouldLoadModule(
168+
const std::string &module_name) {
169+
// Use a regular expression to match /dev/* path
170+
static const std::regex pattern("^/dev/.*$");
171+
return !std::regex_match(module_name, pattern);
172+
}
173+
174+
std::string
175+
DynamicLoaderDumpWithModuleList::SanitizeName(const std::string &input) {
176+
// Use a regular expression to match and remove the parenthesized substring
177+
static const std::regex pattern("\\s*\\(\\S+\\)\\s*$");
178+
return std::regex_replace(input, pattern, "");
179+
}
180+
166181
void DynamicLoaderDumpWithModuleList::DidAttach() {
167182
Log *log = GetLog(LLDBLog::DynamicLoader);
168183
LLDB_LOGF(log, "DynamicLoaderDumpWithModuleList::%s() pid %" PRIu64,

lldb/source/Plugins/DynamicLoader/ModuleList-DYLD/DynamicLoaderDumpWithModuleList.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ class DynamicLoaderDumpWithModuleList : public lldb_private::DynamicLoader {
7777
LoadModuleCallback;
7878
void LoadAllModules(LoadModuleCallback callback);
7979

80+
bool ShouldLoadModule(const std::string &module_name);
81+
82+
std::string SanitizeName(const std::string &input);
83+
8084
std::optional<const LoadedModuleInfoList::LoadedModuleInfo>
8185
GetModuleInfo(lldb::addr_t module_base_addr);
8286

0 commit comments

Comments
 (0)