wallace created this revision.
Herald added a project: All.
wallace requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Some LLDB set ups need to hide certain commands for security reasons, so I'm 
adding a flag that allows removing non-user commands.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149312

Files:
  lldb/include/lldb/Interpreter/CommandInterpreter.h
  lldb/source/Interpreter/CommandInterpreter.cpp

Index: lldb/source/Interpreter/CommandInterpreter.cpp
===================================================================
--- lldb/source/Interpreter/CommandInterpreter.cpp
+++ lldb/source/Interpreter/CommandInterpreter.cpp
@@ -1374,10 +1374,10 @@
   return false;
 }
 
-bool CommandInterpreter::RemoveCommand(llvm::StringRef cmd) {
+bool CommandInterpreter::RemoveCommand(llvm::StringRef cmd, bool force) {
   auto pos = m_command_dict.find(std::string(cmd));
   if (pos != m_command_dict.end()) {
-    if (pos->second->IsRemovable()) {
+    if (force || pos->second->IsRemovable()) {
       // Only regular expression objects or python commands are removable
       m_command_dict.erase(pos);
       return true;
@@ -1689,19 +1689,19 @@
           return nullptr;
         }
         llvm::StringRef arg_text = entry.ref();
-        if (strpos - start_fudge + arg_text.size() + len_fudge 
+        if (strpos - start_fudge + arg_text.size() + len_fudge
             > raw_input_string.size()) {
           result.AppendError("Unmatched quote at command end.");
-          return nullptr;  
+          return nullptr;
         }
         raw_input_string = raw_input_string.erase(
-            strpos - start_fudge, 
+            strpos - start_fudge,
             strlen(cmd_args.GetArgumentAtIndex(index)) + len_fudge);
       }
       if (quote_char == '\0')
         result_str.Printf("%s", cmd_args.GetArgumentAtIndex(index));
       else
-        result_str.Printf("%c%s%c", quote_char, 
+        result_str.Printf("%c%s%c", quote_char,
                           entry.c_str(), quote_char);
     }
   }
@@ -1759,7 +1759,7 @@
     command.insert(start_backtick, std::string(expr_str));
     pos = start_backtick + expr_str.size();
   }
-  return error;                        
+  return error;
 }
 
 Status
@@ -1794,7 +1794,7 @@
           expr_result_valobj_sp->GetQualifiedRepresentationIfAvailable(
               expr_result_valobj_sp->GetDynamicValueType(), true);
     if (expr_result_valobj_sp->ResolveValue(scalar)) {
-      
+
       StreamString value_strm;
       const bool show_type = false;
       scalar.GetValue(&value_strm, show_type);
@@ -1982,11 +1982,11 @@
 
   CommandObject *cmd_obj = ResolveCommandImpl(command_string, result);
 
-  // We have to preprocess the whole command string for Raw commands, since we 
+  // We have to preprocess the whole command string for Raw commands, since we
   // don't know the structure of the command.  For parsed commands, we only
   // treat backticks as quote characters specially.
   // FIXME: We probably want to have raw commands do their own preprocessing.
-  // For instance, I don't think people expect substitution in expr expressions. 
+  // For instance, I don't think people expect substitution in expr expressions.
   if (cmd_obj && cmd_obj->WantsRawCommandString()) {
     Status error(PreprocessCommand(command_string));
 
@@ -3391,7 +3391,7 @@
     // If the current thread is not managed by a host thread, we won't detect
     // that this IS the CommandInterpreter IOHandler thread, so make it so:
     HostThread new_io_handler_thread(Host::GetCurrentThread());
-    HostThread old_io_handler_thread 
+    HostThread old_io_handler_thread
         = m_debugger.SetIOHandlerThread(new_io_handler_thread);
     m_debugger.RunIOHandlers();
     m_debugger.SetIOHandlerThread(old_io_handler_thread);
Index: lldb/include/lldb/Interpreter/CommandInterpreter.h
===================================================================
--- lldb/include/lldb/Interpreter/CommandInterpreter.h
+++ lldb/include/lldb/Interpreter/CommandInterpreter.h
@@ -240,7 +240,7 @@
     eCommandTypesAllThem = 0xFFFF  //< all commands
   };
 
-  // The CommandAlias and CommandInterpreter both have a hand in 
+  // The CommandAlias and CommandInterpreter both have a hand in
   // substituting for alias commands.  They work by writing special tokens
   // in the template form of the Alias command, and then detecting them when the
   // command is executed.  These are the special tokens:
@@ -324,8 +324,9 @@
                          lldb::CommandObjectSP &command_obj_sp,
                          llvm::StringRef args_string = llvm::StringRef());
 
-  // Remove a command if it is removable (python or regex command)
-  bool RemoveCommand(llvm::StringRef cmd);
+  /// Remove a command if it is removable (python or regex command). If \b force
+  /// is provided, the command is removed regardless of its removable status.
+  bool RemoveCommand(llvm::StringRef cmd, bool force);
 
   bool RemoveAlias(llvm::StringRef alias_name);
 
@@ -574,7 +575,7 @@
   void SetEchoCommentCommands(bool enable);
 
   bool GetRepeatPreviousCommand() const;
-  
+
   bool GetRequireCommandOverwrite() const;
 
   const CommandObject::CommandMap &GetUserCommands() const {
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to