Skip to content

Commit 175df18

Browse files
committed
[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. llvm-svn=348894
1 parent 5fb67c7 commit 175df18

File tree

2 files changed

+36
-68
lines changed

2 files changed

+36
-68
lines changed

lldb/tools/driver/Driver.cpp

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -120,53 +120,22 @@ Driver::Driver()
120120

121121
Driver::~Driver() { g_driver = NULL; }
122122

123-
Driver::OptionData::OptionData()
124-
: m_args(), m_script_lang(lldb::eScriptLanguageDefault), m_core_file(),
125-
m_crash_log(), m_initial_commands(), m_after_file_commands(),
126-
m_after_crash_commands(), m_debug_mode(false), m_source_quietly(false),
127-
m_print_version(false), m_print_python_path(false), m_wait_for(false),
128-
m_repl(false), m_repl_lang(eLanguageTypeUnknown), m_repl_options(),
129-
m_process_name(), m_process_pid(LLDB_INVALID_PROCESS_ID),
130-
m_use_external_editor(false), m_batch(false), m_seen_options() {}
131-
132-
Driver::OptionData::~OptionData() {}
133-
134-
void Driver::OptionData::Clear() {
135-
m_args.clear();
136-
m_script_lang = lldb::eScriptLanguageDefault;
137-
m_initial_commands.clear();
138-
m_after_file_commands.clear();
139-
140-
// If there is a local .lldbinit, add that to the
141-
// list of things to be sourced, if the settings
142-
// permit it.
123+
void Driver::OptionData::AddLocalLLDBInit() {
124+
// If there is a local .lldbinit, add that to the list of things to be
125+
// sourced, if the settings permit it.
143126
SBFileSpec local_lldbinit(".lldbinit", true);
144-
145127
SBFileSpec homedir_dot_lldb = SBHostOS::GetUserHomeDirectory();
146128
homedir_dot_lldb.AppendPathComponent(".lldbinit");
147129

148-
// Only read .lldbinit in the current working directory
149-
// if it's not the same as the .lldbinit in the home
150-
// directory (which is already being read in).
130+
// Only read .lldbinit in the current working directory if it's not the same
131+
// as the .lldbinit in the home directory (which is already being read in).
151132
if (local_lldbinit.Exists() && strcmp(local_lldbinit.GetDirectory(),
152133
homedir_dot_lldb.GetDirectory()) != 0) {
153-
char path[2048];
154-
local_lldbinit.GetPath(path, 2047);
134+
char path[PATH_MAX];
135+
local_lldbinit.GetPath(path, sizeof(path));
155136
InitialCmdEntry entry(path, true, true, true);
156137
m_after_file_commands.push_back(entry);
157138
}
158-
159-
m_debug_mode = false;
160-
m_source_quietly = false;
161-
m_print_version = false;
162-
m_print_python_path = false;
163-
m_use_external_editor = false;
164-
m_wait_for = false;
165-
m_process_name.erase();
166-
m_batch = false;
167-
m_after_crash_commands.clear();
168-
169-
m_process_pid = LLDB_INVALID_PROCESS_ID;
170139
}
171140

172141
void Driver::OptionData::AddInitialCommand(std::string command,
@@ -201,8 +170,6 @@ void Driver::OptionData::AddInitialCommand(std::string command,
201170
command_set->push_back(InitialCmdEntry(command, is_file, false));
202171
}
203172

204-
void Driver::ResetOptionValues() { m_option_data.Clear(); }
205-
206173
const char *Driver::GetFilename() const {
207174
if (m_option_data.m_args.empty())
208175
return NULL;
@@ -284,7 +251,7 @@ bool Driver::GetDebugMode() const { return m_option_data.m_debug_mode; }
284251
// user only wanted help or version information.
285252
SBError Driver::ProcessArgs(const opt::InputArgList &args, bool &exiting) {
286253
SBError error;
287-
ResetOptionValues();
254+
m_option_data.AddLocalLLDBInit();
288255

289256
// This is kind of a pain, but since we make the debugger in the Driver's
290257
// constructor, we can't know at that point whether we should read in init

lldb/tools/driver/Driver.h

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -57,50 +57,53 @@ class Driver : public lldb::SBBroadcaster {
5757

5858
bool GetDebugMode() const;
5959

60-
class OptionData {
61-
public:
62-
OptionData();
63-
~OptionData();
64-
65-
void Clear();
66-
60+
struct OptionData {
61+
void AddLocalLLDBInit();
6762
void AddInitialCommand(std::string command, CommandPlacement placement,
6863
bool is_file, lldb::SBError &error);
6964

7065
struct InitialCmdEntry {
7166
InitialCmdEntry(std::string contents, bool in_is_file,
7267
bool is_cwd_lldbinit_file_read, bool in_quiet = false)
7368
: contents(std::move(contents)), is_file(in_is_file),
74-
is_cwd_lldbinit_file_read(is_cwd_lldbinit_file_read),
75-
source_quietly(in_quiet) {}
69+
source_quietly(in_quiet),
70+
is_cwd_lldbinit_file_read(is_cwd_lldbinit_file_read) {}
7671

7772
std::string contents;
7873
bool is_file;
79-
bool is_cwd_lldbinit_file_read; // if this is reading ./.lldbinit - so we
80-
// may skip if not permitted
8174
bool source_quietly;
75+
76+
/// Remember if this is reading the local lldbinit file so we can skip it
77+
/// if not permitted.
78+
bool is_cwd_lldbinit_file_read;
8279
};
8380

8481
std::vector<std::string> m_args;
85-
lldb::ScriptLanguage m_script_lang;
82+
83+
lldb::ScriptLanguage m_script_lang = lldb::eScriptLanguageDefault;
84+
lldb::LanguageType m_repl_lang = lldb::eLanguageTypeUnknown;
85+
lldb::pid_t m_process_pid = LLDB_INVALID_PROCESS_ID;
86+
8687
std::string m_core_file;
8788
std::string m_crash_log;
89+
std::string m_repl_options;
90+
std::string m_process_name;
91+
8892
std::vector<InitialCmdEntry> m_initial_commands;
8993
std::vector<InitialCmdEntry> m_after_file_commands;
9094
std::vector<InitialCmdEntry> m_after_crash_commands;
91-
bool m_debug_mode;
92-
bool m_source_quietly;
93-
bool m_print_version;
94-
bool m_print_python_path;
95-
bool m_wait_for;
96-
bool m_repl;
97-
lldb::LanguageType m_repl_lang;
98-
std::string m_repl_options;
99-
std::string m_process_name;
100-
lldb::pid_t m_process_pid;
101-
bool m_use_external_editor; // FIXME: When we have set/show variables we can
102-
// remove this from here.
103-
bool m_batch;
95+
96+
bool m_debug_mode = false;
97+
bool m_source_quietly = false;
98+
bool m_print_version = false;
99+
bool m_print_python_path = false;
100+
bool m_wait_for = false;
101+
bool m_repl = false;
102+
bool m_batch = false;
103+
104+
// FIXME: When we have set/show variables we can remove this from here.
105+
bool m_use_external_editor = false;
106+
104107
typedef std::set<char> OptionSet;
105108
OptionSet m_seen_options;
106109
};
@@ -112,8 +115,6 @@ class Driver : public lldb::SBBroadcaster {
112115
private:
113116
lldb::SBDebugger m_debugger;
114117
OptionData m_option_data;
115-
116-
void ResetOptionValues();
117118
};
118119

119120
#endif // lldb_Driver_h_

0 commit comments

Comments
 (0)