[Lldb-commits] [lldb] [lldb] Add support for disabling frame recognizers (PR #109219)

via lldb-commits lldb-commits at lists.llvm.org
Thu Sep 19 15:25:25 PDT 2024


================
@@ -957,53 +962,43 @@ PrintRecognizerDetails(Stream &strm, const std::string &name,
   llvm::interleaveComma(symbols, strm);
 }
 
-class CommandObjectFrameRecognizerDelete : public CommandObjectParsed {
-public:
-  CommandObjectFrameRecognizerDelete(CommandInterpreter &interpreter)
-      : CommandObjectParsed(interpreter, "frame recognizer delete",
-                            "Delete an existing frame recognizer by id.",
-                            nullptr) {
-    AddSimpleArgumentList(eArgTypeRecognizerID);
-  }
-
-  ~CommandObjectFrameRecognizerDelete() override = default;
+// Base class for commands which accept a single frame recognizer as an argument
+class CommandObjectWithFrameRecognizerArg : public CommandObjectParsed {
+  public:
+    CommandObjectWithFrameRecognizerArg(CommandInterpreter &interpreter,
+                                        const char *name,
+                                        const char *help = nullptr,
+                                        const char *syntax = nullptr,
+                                        uint32_t flags = 0)
+        : CommandObjectParsed(interpreter, name, help, syntax, flags) {
+      AddSimpleArgumentList(eArgTypeRecognizerID);
+    }
 
   void
   HandleArgumentCompletion(CompletionRequest &request,
                            OptionElementVector &opt_element_vector) override {
+    std::cerr << request.GetCursorIndex() << std::endl;
     if (request.GetCursorIndex() != 0)
       return;
 
     GetTarget().GetFrameRecognizerManager().ForEach(
-        [&request](uint32_t rid, std::string rname, std::string module,
+        [&request](uint32_t rid, bool enabled, std::string rname, std::string module,
                    llvm::ArrayRef<lldb_private::ConstString> symbols,
                    Mangled::NamePreference symbol_mangling, bool regexp) {
           StreamString strm;
           if (rname.empty())
             rname = "(internal)";
 
-          PrintRecognizerDetails(strm, rname, module, symbols, symbol_mangling,
-                                 regexp);
+          PrintRecognizerDetails(strm, rname, enabled, module, symbols,
+                                 symbol_mangling, regexp);
 
           request.TryCompleteCurrentArg(std::to_string(rid), strm.GetString());
         });
   }
 
-protected:
-  void DoExecute(Args &command, CommandReturnObject &result) override {
-    if (command.GetArgumentCount() == 0) {
-      if (!m_interpreter.Confirm(
-              "About to delete all frame recognizers, do you want to do that?",
-              true)) {
-        result.AppendMessage("Operation cancelled...");
-        return;
-      }
-
-      GetTarget().GetFrameRecognizerManager().RemoveAllRecognizers();
-      result.SetStatus(eReturnStatusSuccessFinishResult);
-      return;
-    }
+  virtual void DoExecuteWithId(CommandReturnObject &result, uint32_t recognizer_id) = 0;
 
+  void DoExecute(Args &command, CommandReturnObject &result) override {
     if (command.GetArgumentCount() != 1) {
----------------
jimingham wrote:

You didn't add this part, so feel free to ignore this comment, but if you pass `eArgRepeatOptional` to defaulted second parameter to AddSimpleArgumentList, you shouldn't need to do this check here.

https://github.com/llvm/llvm-project/pull/109219


More information about the lldb-commits mailing list