[Lldb-commits] [lldb] [LLDB] Add module hook implementation (PR #185465)
via lldb-commits
lldb-commits at lists.llvm.org
Tue Apr 7 16:34:44 PDT 2026
================
@@ -4243,6 +4307,407 @@ void Target::StopHookScripted::GetSubclassDescription(
as_dict->ForEach(print_one_element);
}
+// Hook
+
+Target::Hook::Hook(lldb::TargetSP target_sp, lldb::user_id_t uid)
+ : UserID(uid), m_target_sp(std::move(target_sp)) {}
+
+Target::Hook::Hook(const Hook &rhs)
+ : UserID(rhs.GetID()), m_target_sp(rhs.m_target_sp),
+ m_enabled(rhs.m_enabled), m_trigger_mask(rhs.m_trigger_mask),
+ m_sc_specifier_sp(rhs.m_sc_specifier_sp),
+ m_at_initial_stop(rhs.m_at_initial_stop),
+ m_auto_continue(rhs.m_auto_continue),
+ m_suppress_output(rhs.m_suppress_output) {
+ if (rhs.m_thread_spec_up)
+ m_thread_spec_up = std::make_unique<ThreadSpec>(*rhs.m_thread_spec_up);
+}
+
+void Target::Hook::SetSCSpecifier(SymbolContextSpecifier *specifier) {
+ m_sc_specifier_sp.reset(specifier);
+}
+
+void Target::Hook::SetThreadSpecifier(ThreadSpec *specifier) {
+ m_thread_spec_up.reset(specifier);
+}
+
+bool Target::Hook::ExecutionContextPasses(const ExecutionContext &exc_ctx) {
+ SymbolContextSpecifier *specifier = GetSCSpecifier();
+ if (!specifier)
+ return true;
+
+ bool will_run = true;
+ if (exc_ctx.GetFramePtr())
+ will_run = specifier->SymbolContextMatches(
+ exc_ctx.GetFramePtr()->GetSymbolContext(eSymbolContextEverything));
+ if (will_run && GetThreadSpecifier() != nullptr)
+ will_run =
+ GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx.GetThreadRef());
+
+ return will_run;
+}
+
+void Target::Hook::GetDescription(Stream &s,
+ lldb::DescriptionLevel level) const {
+ s.Printf("Hook: %" PRIu64 "\n", GetID());
+ if (level == eDescriptionLevelBrief)
+ return;
+ s.IndentMore();
+ s.Indent();
+ s.Printf("State: %s\n", m_enabled ? "enabled" : "disabled");
+
+ {
+ std::string fires_on;
+ if (m_trigger_mask & kModulesLoaded)
+ fires_on += "load";
+ if (m_trigger_mask & kModulesUnloaded) {
+ if (!fires_on.empty())
+ fires_on += ", ";
+ fires_on += "unload";
+ }
+ if (m_trigger_mask & kProcessStop) {
+ if (!fires_on.empty())
+ fires_on += ", ";
+ fires_on += "stop";
+ }
+ if (!fires_on.empty()) {
+ s.Indent();
+ s.Printf("Triggers: %s\n", fires_on.c_str());
+ }
+ }
+
+ if (m_auto_continue)
+ s.Indent("AutoContinue on\n");
+
+ if (m_sc_specifier_sp) {
+ s.Indent();
+ s.PutCString("Specifier:\n");
+ s.IndentMore();
+ m_sc_specifier_sp->GetDescription(&s, level);
+ s.IndentLess();
+ }
+
+ if (m_thread_spec_up) {
+ StreamString tmp;
+ s.Indent("Thread:\n");
+ m_thread_spec_up->GetDescription(&tmp, level);
+ s.IndentMore();
+ s.Indent(tmp.GetString());
+ s.PutCString("\n");
+ s.IndentLess();
+ }
+
+ s.IndentLess();
+}
+
+void Target::HookCommandLine::GetDescription(
+ Stream &s, lldb::DescriptionLevel level) const {
+ Hook::GetDescription(s, level);
----------------
jimingham wrote:
I think the features that define the hook - the class for scripted or the commands and triggers should come first, and then all the filters.
https://github.com/llvm/llvm-project/pull/185465
More information about the lldb-commits
mailing list