[Lldb-commits] [lldb] r348894 - [Driver] Simplify OptionData. NFC

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Tue Dec 11 12:19:53 PST 2018


Author: jdevlieghere
Date: Tue Dec 11 12:19:53 2018
New Revision: 348894

URL: http://llvm.org/viewvc/llvm-project?rev=348894&view=rev
Log:
[Driver] Simplify OptionData. NFC

Hopefully this makes the option data easier to understand and maintain.

 - Group the member variables.
 - Do the initialization in the header as it's less error prone.
 - Rename the Clean method. It was called only once and was
   re-initializing some but not all (?) members. The only useful thing it
   does is dealing with the local lldbinit file so keep that and make the
   name reflect that.

Modified:
    lldb/trunk/tools/driver/Driver.cpp
    lldb/trunk/tools/driver/Driver.h

Modified: lldb/trunk/tools/driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Driver.cpp?rev=348894&r1=348893&r2=348894&view=diff
==============================================================================
--- lldb/trunk/tools/driver/Driver.cpp (original)
+++ lldb/trunk/tools/driver/Driver.cpp Tue Dec 11 12:19:53 2018
@@ -120,53 +120,22 @@ Driver::Driver()
 
 Driver::~Driver() { g_driver = NULL; }
 
-Driver::OptionData::OptionData()
-    : m_args(), m_script_lang(lldb::eScriptLanguageDefault), m_core_file(),
-      m_crash_log(), m_initial_commands(), m_after_file_commands(),
-      m_after_crash_commands(), m_debug_mode(false), m_source_quietly(false),
-      m_print_version(false), m_print_python_path(false), m_wait_for(false),
-      m_repl(false), m_repl_lang(eLanguageTypeUnknown), m_repl_options(),
-      m_process_name(), m_process_pid(LLDB_INVALID_PROCESS_ID),
-      m_use_external_editor(false), m_batch(false), m_seen_options() {}
-
-Driver::OptionData::~OptionData() {}
-
-void Driver::OptionData::Clear() {
-  m_args.clear();
-  m_script_lang = lldb::eScriptLanguageDefault;
-  m_initial_commands.clear();
-  m_after_file_commands.clear();
-
-  // If there is a local .lldbinit, add that to the
-  // list of things to be sourced, if the settings
-  // permit it.
+void Driver::OptionData::AddLocalLLDBInit() {
+  // If there is a local .lldbinit, add that to the list of things to be
+  // sourced, if the settings permit it.
   SBFileSpec local_lldbinit(".lldbinit", true);
-
   SBFileSpec homedir_dot_lldb = SBHostOS::GetUserHomeDirectory();
   homedir_dot_lldb.AppendPathComponent(".lldbinit");
 
-  // Only read .lldbinit in the current working directory
-  // if it's not the same as the .lldbinit in the home
-  // directory (which is already being read in).
+  // Only read .lldbinit in the current working directory if it's not the same
+  // as the .lldbinit in the home directory (which is already being read in).
   if (local_lldbinit.Exists() && strcmp(local_lldbinit.GetDirectory(),
                                         homedir_dot_lldb.GetDirectory()) != 0) {
-    char path[2048];
-    local_lldbinit.GetPath(path, 2047);
+    char path[PATH_MAX];
+    local_lldbinit.GetPath(path, sizeof(path));
     InitialCmdEntry entry(path, true, true, true);
     m_after_file_commands.push_back(entry);
   }
-
-  m_debug_mode = false;
-  m_source_quietly = false;
-  m_print_version = false;
-  m_print_python_path = false;
-  m_use_external_editor = false;
-  m_wait_for = false;
-  m_process_name.erase();
-  m_batch = false;
-  m_after_crash_commands.clear();
-
-  m_process_pid = LLDB_INVALID_PROCESS_ID;
 }
 
 void Driver::OptionData::AddInitialCommand(std::string command,
@@ -201,8 +170,6 @@ void Driver::OptionData::AddInitialComma
     command_set->push_back(InitialCmdEntry(command, is_file, false));
 }
 
-void Driver::ResetOptionValues() { m_option_data.Clear(); }
-
 const char *Driver::GetFilename() const {
   if (m_option_data.m_args.empty())
     return NULL;
@@ -284,7 +251,7 @@ bool Driver::GetDebugMode() const { retu
 // user only wanted help or version information.
 SBError Driver::ProcessArgs(const opt::InputArgList &args, bool &exiting) {
   SBError error;
-  ResetOptionValues();
+  m_option_data.AddLocalLLDBInit();
 
   // This is kind of a pain, but since we make the debugger in the Driver's
   // constructor, we can't know at that point whether we should read in init

Modified: lldb/trunk/tools/driver/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Driver.h?rev=348894&r1=348893&r2=348894&view=diff
==============================================================================
--- lldb/trunk/tools/driver/Driver.h (original)
+++ lldb/trunk/tools/driver/Driver.h Tue Dec 11 12:19:53 2018
@@ -57,13 +57,8 @@ public:
 
   bool GetDebugMode() const;
 
-  class OptionData {
-  public:
-    OptionData();
-    ~OptionData();
-
-    void Clear();
-
+  struct OptionData {
+    void AddLocalLLDBInit();
     void AddInitialCommand(std::string command, CommandPlacement placement,
                            bool is_file, lldb::SBError &error);
 
@@ -71,36 +66,44 @@ public:
       InitialCmdEntry(std::string contents, bool in_is_file,
                       bool is_cwd_lldbinit_file_read, bool in_quiet = false)
           : contents(std::move(contents)), is_file(in_is_file),
-            is_cwd_lldbinit_file_read(is_cwd_lldbinit_file_read),
-            source_quietly(in_quiet) {}
+            source_quietly(in_quiet),
+            is_cwd_lldbinit_file_read(is_cwd_lldbinit_file_read) {}
 
       std::string contents;
       bool is_file;
-      bool is_cwd_lldbinit_file_read; // if this is reading ./.lldbinit - so we
-                                      // may skip if not permitted
       bool source_quietly;
+
+      /// Remember if this is reading the local lldbinit file so we can skip it
+      /// if not permitted.
+      bool is_cwd_lldbinit_file_read;
     };
 
     std::vector<std::string> m_args;
-    lldb::ScriptLanguage m_script_lang;
+
+    lldb::ScriptLanguage m_script_lang = lldb::eScriptLanguageDefault;
+    lldb::LanguageType m_repl_lang = lldb::eLanguageTypeUnknown;
+    lldb::pid_t m_process_pid = LLDB_INVALID_PROCESS_ID;
+
     std::string m_core_file;
     std::string m_crash_log;
+    std::string m_repl_options;
+    std::string m_process_name;
+
     std::vector<InitialCmdEntry> m_initial_commands;
     std::vector<InitialCmdEntry> m_after_file_commands;
     std::vector<InitialCmdEntry> m_after_crash_commands;
-    bool m_debug_mode;
-    bool m_source_quietly;
-    bool m_print_version;
-    bool m_print_python_path;
-    bool m_wait_for;
-    bool m_repl;
-    lldb::LanguageType m_repl_lang;
-    std::string m_repl_options;
-    std::string m_process_name;
-    lldb::pid_t m_process_pid;
-    bool m_use_external_editor; // FIXME: When we have set/show variables we can
-                                // remove this from here.
-    bool m_batch;
+
+    bool m_debug_mode = false;
+    bool m_source_quietly = false;
+    bool m_print_version = false;
+    bool m_print_python_path = false;
+    bool m_wait_for = false;
+    bool m_repl = false;
+    bool m_batch = false;
+
+    // FIXME: When we have set/show variables we can remove this from here.
+    bool m_use_external_editor = false;
+
     typedef std::set<char> OptionSet;
     OptionSet m_seen_options;
   };
@@ -112,8 +115,6 @@ public:
 private:
   lldb::SBDebugger m_debugger;
   OptionData m_option_data;
-
-  void ResetOptionValues();
 };
 
 #endif // lldb_Driver_h_




More information about the lldb-commits mailing list