Skip to content

Commit ff43800

Browse files
author
George Hu
committed
Bug fix, reload modules before getting thread local storage
Summary: Debugged locally with 2 scenario: * Load core only, and then auto-load-debuginfo, then can reproduce the error: ``` (lldb) target var HPHP::s_stackSize (size_t) HPHP::s_stackSize = <No TLS data currently exists for this thread.> ``` * Load core with executable manually, thread local variable is able to be show: ``` (lldb) target var HPHP::s_stackSize (size_t) HPHP::s_stackSize = 0 ``` The root cause is that the [link_map](https://www.internalfb.com/code/osmeta-external-llvm-project/[toolchain%2Fllvm-sand%2Fmain%3A55d44adeadd8500af2335ac99a9b10d1414f47e4]/lldb/source/Plugins/DynamicLoader/ModuleList-DYLD/DynamicLoaderDumpWithModuleList.cpp?lines=284) in the first scenario was 0. Because when the target was created, [DYLDRenzdevous can not be resolved](https://www.internalfb.com/code/osmeta-external-llvm-project/[toolchain%2Fllvm-sand%2Fmain%3A55d44adeadd8500af2335ac99a9b10d1414f47e4]/lldb/source/Plugins/DynamicLoader/ModuleList-DYLD/DynamicLoaderDumpWithModuleList.cpp?lines=120) because of lacking main executable. After auto-load-debuginfo, even we called target module replace, we never have a chance to call DYLDRenzdevous again to resolve and update link map address. So calling DidAttach() if m_rendezvous is not valid at the very beginning of GetThreadLocalData function is the easiest fix, to have a chance to update the link_map_addr in m_loaded_modules after we have the executable object file replaced by the auto-load-debuginfo command. Test Plan: Before this diff: ``` (lldb) target create --core "k9vc79dn9h6pe2y9" Core file '/home/hyubo/test/k9vc79dn9h6pe2y9' (x86_64) was loaded. (lldb) auto-load-debuginfo ... (lldb) target var HPHP::s_stackSize (size_t) HPHP::s_stackSize = <No TLS data currently exists for this thread.> ``` After this diff: ``` (lldb) target create --core "k9vc79dn9h6pe2y9" Core file '/home/hyubo/test/k9vc79dn9h6pe2y9' (x86_64) was loaded. (lldb) auto-load-debuginfo ... (lldb) target var HPHP::s_stackSize (size_t) HPHP::s_stackSize = 0 ``` Reviewers: jeffreytan, gclayton, #lldb_team Reviewed By: jeffreytan Subscribers: michristensen, #lldb_team Differential Revision: https://phabricator.intern.facebook.com/D56793922 Tasks: T186207554 Tags: accept2ship
1 parent 494d207 commit ff43800

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lldb/source/Commands/CommandObjectTarget.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "lldb/Symbol/UnwindPlan.h"
4242
#include "lldb/Symbol/VariableList.h"
4343
#include "lldb/Target/ABI.h"
44+
#include "lldb/Target/DynamicLoader.h"
4445
#include "lldb/Target/Process.h"
4546
#include "lldb/Target/RegisterContext.h"
4647
#include "lldb/Target/SectionLoadList.h"
@@ -2962,8 +2963,14 @@ class CommandObjectTargetModulesReplace : public CommandObjectParsed {
29622963

29632964
if (flush) {
29642965
ProcessSP process = target.GetProcessSP();
2965-
if (process)
2966+
if (process) {
29662967
process->Flush();
2968+
// DYLD rendezvous might not be resolved, try to load all modules again
2969+
// as we might have main executable replaced.
2970+
DynamicLoader *dyld = process->GetDynamicLoader();
2971+
if (dyld)
2972+
dyld->DidAttach();
2973+
}
29672974
}
29682975
return;
29692976
}

0 commit comments

Comments
 (0)