@@ -1356,7 +1356,11 @@ class Target : public std::enable_shared_from_this<Target>,
13561356 StopHook (const StopHook &rhs);
13571357 virtual ~StopHook () = default ;
13581358
1359- enum class StopHookKind : uint32_t { CommandBased = 0 , ScriptBased };
1359+ enum class StopHookKind : uint32_t {
1360+ CommandBased = 0 ,
1361+ ScriptBased,
1362+ CodeBased,
1363+ };
13601364 enum class StopHookResult : uint32_t {
13611365 KeepStopped = 0 ,
13621366 RequestContinue,
@@ -1403,6 +1407,12 @@ class Target : public std::enable_shared_from_this<Target>,
14031407
14041408 bool GetRunAtInitialStop () const { return m_at_initial_stop; }
14051409
1410+ void SetSuppressOutput (bool suppress_output) {
1411+ m_suppress_output = suppress_output;
1412+ }
1413+
1414+ bool GetSuppressOutput () const { return m_suppress_output; }
1415+
14061416 void GetDescription (Stream &s, lldb::DescriptionLevel level) const ;
14071417 virtual void GetSubclassDescription (Stream &s,
14081418 lldb::DescriptionLevel level) const = 0;
@@ -1414,6 +1424,7 @@ class Target : public std::enable_shared_from_this<Target>,
14141424 bool m_active = true ;
14151425 bool m_auto_continue = false ;
14161426 bool m_at_initial_stop = true ;
1427+ bool m_suppress_output = false ;
14171428
14181429 StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid);
14191430 };
@@ -1433,8 +1444,8 @@ class Target : public std::enable_shared_from_this<Target>,
14331444
14341445 private:
14351446 StringList m_commands;
1436- // Use CreateStopHook to make a new empty stop hook. The GetCommandPointer
1437- // and fill it with commands, and SetSpecifier to set the specifier shared
1447+ // Use CreateStopHook to make a new empty stop hook. Use SetActionFromString
1448+ // to fill it with commands, and SetSpecifier to set the specifier shared
14381449 // pointer (can be null, that will match anything.)
14391450 StopHookCommandLine (lldb::TargetSP target_sp, lldb::user_id_t uid)
14401451 : StopHook(target_sp, uid) {}
@@ -1460,19 +1471,56 @@ class Target : public std::enable_shared_from_this<Target>,
14601471 StructuredDataImpl m_extra_args;
14611472 lldb::ScriptedStopHookInterfaceSP m_interface_sp;
14621473
1463- // / Use CreateStopHook to make a new empty stop hook. The GetCommandPointer
1464- // / and fill it with commands , and SetSpecifier to set the specifier shared
1465- // / pointer (can be null, that will match anything.)
1474+ // / Use CreateStopHook to make a new empty stop hook. Use SetScriptCallback
1475+ // / to set the script to execute , and SetSpecifier to set the specifier
1476+ // / shared pointer (can be null, that will match anything.)
14661477 StopHookScripted (lldb::TargetSP target_sp, lldb::user_id_t uid)
14671478 : StopHook(target_sp, uid) {}
14681479 friend class Target ;
14691480 };
14701481
1482+ class StopHookCoded : public StopHook {
1483+ public:
1484+ ~StopHookCoded () override = default ;
1485+
1486+ using HandleStopCallback = StopHookResult(ExecutionContext &exc_ctx,
1487+ lldb::StreamSP output);
1488+
1489+ void SetCallback (llvm::StringRef name, HandleStopCallback *callback) {
1490+ m_name = name;
1491+ m_callback = callback;
1492+ }
1493+
1494+ StopHookResult HandleStop (ExecutionContext &exc_ctx,
1495+ lldb::StreamSP output) override {
1496+ return m_callback (exc_ctx, output);
1497+ }
1498+
1499+ void GetSubclassDescription (Stream &s,
1500+ lldb::DescriptionLevel level) const override {
1501+ s.Indent ();
1502+ s.Printf (" %s (built-in)\n " , m_name.c_str ());
1503+ }
1504+
1505+ private:
1506+ std::string m_name;
1507+ HandleStopCallback *m_callback;
1508+
1509+ // / Use CreateStopHook to make a new empty stop hook. Use SetCallback to set
1510+ // / the callback to execute, and SetSpecifier to set the specifier shared
1511+ // / pointer (can be null, that will match anything.)
1512+ StopHookCoded (lldb::TargetSP target_sp, lldb::user_id_t uid)
1513+ : StopHook(target_sp, uid) {}
1514+ friend class Target ;
1515+ };
1516+
1517+ void RegisterInternalStopHooks ();
1518+
14711519 typedef std::shared_ptr<StopHook> StopHookSP;
14721520
14731521 // / Add an empty stop hook to the Target's stop hook list, and returns a
1474- // / shared pointer to it in new_hook. Returns the id of the new hook.
1475- StopHookSP CreateStopHook (StopHook::StopHookKind kind);
1522+ // / shared pointer to the new hook.
1523+ StopHookSP CreateStopHook (StopHook::StopHookKind kind, bool internal = false );
14761524
14771525 // / If you tried to create a stop hook, and that failed, call this to
14781526 // / remove the stop hook, as it will also reset the stop hook counter.
@@ -1484,8 +1532,6 @@ class Target : public std::enable_shared_from_this<Target>,
14841532 // control over the process for the first time.
14851533 bool RunStopHooks (bool at_initial_stop = false );
14861534
1487- size_t GetStopHookSize ();
1488-
14891535 bool SetSuppresStopHooks (bool suppress) {
14901536 bool old_value = m_suppress_stop_hooks;
14911537 m_suppress_stop_hooks = suppress;
@@ -1504,19 +1550,7 @@ class Target : public std::enable_shared_from_this<Target>,
15041550
15051551 void SetAllStopHooksActiveState (bool active_state);
15061552
1507- size_t GetNumStopHooks () const { return m_stop_hooks.size (); }
1508-
1509- StopHookSP GetStopHookAtIndex (size_t index) {
1510- if (index >= GetNumStopHooks ())
1511- return StopHookSP ();
1512- StopHookCollection::iterator pos = m_stop_hooks.begin ();
1513-
1514- while (index > 0 ) {
1515- pos++;
1516- index--;
1517- }
1518- return (*pos).second ;
1519- }
1553+ const std::vector<StopHookSP> GetStopHooks (bool internal = false ) const ;
15201554
15211555 lldb::PlatformSP GetPlatform () { return m_platform_sp; }
15221556
@@ -1656,6 +1690,7 @@ class Target : public std::enable_shared_from_this<Target>,
16561690 typedef std::map<lldb::user_id_t , StopHookSP> StopHookCollection;
16571691 StopHookCollection m_stop_hooks;
16581692 lldb::user_id_t m_stop_hook_next_id;
1693+ std::vector<StopHookSP> m_internal_stop_hooks;
16591694 uint32_t m_latest_stop_hook_id; // / This records the last natural stop at
16601695 // / which we ran a stop-hook.
16611696 bool m_valid;
0 commit comments