summaryrefslogtreecommitdiff
path: root/lldb/tools
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2018-12-11 20:19:53 +0000
committerJonas Devlieghere <jonas@devlieghere.com>2018-12-11 20:19:53 +0000
commit5e781dd77dda461972a9fe0b46c3a1038b092e3d (patch)
treea0d38e62d3be384614d8495911749709473ea876 /lldb/tools
parent029778108f533210112b1980bd27adb8741ab3b7 (diff)
[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.
Diffstat (limited to 'lldb/tools')
-rw-r--r--lldb/tools/driver/Driver.cpp49
-rw-r--r--lldb/tools/driver/Driver.h55
2 files changed, 36 insertions, 68 deletions
diff --git a/lldb/tools/driver/Driver.cpp b/lldb/tools/driver/Driver.cpp
index cd61cf66833..8a86fe0bf44 100644
--- a/lldb/tools/driver/Driver.cpp
+++ b/lldb/tools/driver/Driver.cpp
@@ -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::AddInitialCommand(std::string command,
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 { return m_option_data.m_debug_mode; }
// 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
diff --git a/lldb/tools/driver/Driver.h b/lldb/tools/driver/Driver.h
index 39a20e96e26..235e265ce77 100644
--- a/lldb/tools/driver/Driver.h
+++ b/lldb/tools/driver/Driver.h
@@ -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_