Make the sourcing of the local .lldbinit file quiet.

<rdar://problem/19065278>

llvm-svn: 222599
This commit is contained in:
Jim Ingham 2014-11-22 01:33:22 +00:00
parent 86903b70fc
commit 0f17c5570d
2 changed files with 38 additions and 22 deletions

View File

@ -438,7 +438,8 @@ Driver::OptionData::Clear ()
{ {
char path[2048]; char path[2048];
local_lldbinit.GetPath(path, 2047); local_lldbinit.GetPath(path, 2047);
m_after_file_commands.push_back (std::pair<bool, std::string> (true, path)); InitialCmdEntry entry(path, true, true);
m_after_file_commands.push_back (entry);
} }
m_debug_mode = false; m_debug_mode = false;
@ -456,9 +457,9 @@ Driver::OptionData::Clear ()
} }
void void
Driver::OptionData::AddInitialCommand (const char *command, CommandPlacement placement, bool is_file, SBError &error) Driver::OptionData::AddInitialCommand (const char *command, CommandPlacement placement, bool is_file, bool silent, SBError &error)
{ {
std::vector<std::pair<bool, std::string> > *command_set; std::vector<InitialCmdEntry> *command_set;
switch (placement) switch (placement)
{ {
case eCommandPlacementBeforeFile: case eCommandPlacementBeforeFile:
@ -476,19 +477,18 @@ Driver::OptionData::AddInitialCommand (const char *command, CommandPlacement pla
{ {
SBFileSpec file(command); SBFileSpec file(command);
if (file.Exists()) if (file.Exists())
command_set->push_back (std::pair<bool, std::string> (true, optarg)); command_set->push_back (InitialCmdEntry(command, is_file, silent));
else if (file.ResolveExecutableLocation()) else if (file.ResolveExecutableLocation())
{ {
char final_path[PATH_MAX]; char final_path[PATH_MAX];
file.GetPath (final_path, sizeof(final_path)); file.GetPath (final_path, sizeof(final_path));
std::string path_str (final_path); command_set->push_back (InitialCmdEntry(final_path, is_file, silent));
command_set->push_back (std::pair<bool, std::string> (true, path_str));
} }
else else
error.SetErrorStringWithFormat("file specified in --source (-s) option doesn't exist: '%s'", optarg); error.SetErrorStringWithFormat("file specified in --source (-s) option doesn't exist: '%s'", optarg);
} }
else else
command_set->push_back (std::pair<bool, std::string> (false, optarg)); command_set->push_back (InitialCmdEntry(command, is_file, silent));
} }
void void
@ -522,7 +522,7 @@ Driver::GetScriptLanguage() const
void void
Driver::WriteCommandsForSourcing (CommandPlacement placement, SBStream &strm) Driver::WriteCommandsForSourcing (CommandPlacement placement, SBStream &strm)
{ {
std::vector<std::pair<bool, std::string> > *command_set; std::vector<OptionData::InitialCmdEntry> *command_set;
switch (placement) switch (placement)
{ {
case eCommandPlacementBeforeFile: case eCommandPlacementBeforeFile:
@ -536,11 +536,14 @@ Driver::WriteCommandsForSourcing (CommandPlacement placement, SBStream &strm)
break; break;
} }
for (const auto &command_pair : *command_set) for (const auto &command_entry : *command_set)
{ {
const char *command = command_pair.second.c_str(); const char *command = command_entry.contents.c_str();
if (command_pair.first) if (command_entry.is_file)
strm.Printf("command source -s %i '%s'\n", m_option_data.m_source_quietly, command); {
bool source_quietly = m_option_data.m_source_quietly || command_entry.source_quietly;
strm.Printf("command source -s %i '%s'\n", source_quietly, command);
}
else else
strm.Printf("%s\n", command); strm.Printf("%s\n", command);
} }
@ -748,10 +751,10 @@ Driver::ParseArgs (int argc, const char *argv[], FILE *out_fh, bool &exiting)
break; break;
case 'K': case 'K':
m_option_data.AddInitialCommand(optarg, eCommandPlacementAfterCrash, true, error); m_option_data.AddInitialCommand(optarg, eCommandPlacementAfterCrash, true, true, error);
break; break;
case 'k': case 'k':
m_option_data.AddInitialCommand(optarg, eCommandPlacementAfterCrash, false, error); m_option_data.AddInitialCommand(optarg, eCommandPlacementAfterCrash, false, true, error);
break; break;
case 'n': case 'n':
@ -772,16 +775,16 @@ Driver::ParseArgs (int argc, const char *argv[], FILE *out_fh, bool &exiting)
} }
break; break;
case 's': case 's':
m_option_data.AddInitialCommand(optarg, eCommandPlacementAfterFile, true, error); m_option_data.AddInitialCommand(optarg, eCommandPlacementAfterFile, true, true, error);
break; break;
case 'o': case 'o':
m_option_data.AddInitialCommand(optarg, eCommandPlacementAfterFile, false, error); m_option_data.AddInitialCommand(optarg, eCommandPlacementAfterFile, false, true, error);
break; break;
case 'S': case 'S':
m_option_data.AddInitialCommand(optarg, eCommandPlacementBeforeFile, true, error); m_option_data.AddInitialCommand(optarg, eCommandPlacementBeforeFile, true, true, error);
break; break;
case 'O': case 'O':
m_option_data.AddInitialCommand(optarg, eCommandPlacementBeforeFile, false, error); m_option_data.AddInitialCommand(optarg, eCommandPlacementBeforeFile, false, true, error);
break; break;
default: default:
m_option_data.m_print_help = true; m_option_data.m_print_help = true;

View File

@ -75,17 +75,30 @@ public:
Clear(); Clear();
void void
AddInitialCommand (const char *command, CommandPlacement placement, bool is_file, lldb::SBError &error); AddInitialCommand (const char *command, CommandPlacement placement, bool is_file, bool quietly, lldb::SBError &error);
//static OptionDefinition m_cmd_option_table[]; //static OptionDefinition m_cmd_option_table[];
struct InitialCmdEntry
{
InitialCmdEntry (const char *in_contents, bool in_is_file, bool in_quiet = false) :
contents (in_contents),
is_file (in_is_file),
source_quietly(in_quiet)
{}
std::string contents;
bool is_file;
bool source_quietly;
};
std::vector<std::string> m_args; std::vector<std::string> m_args;
lldb::ScriptLanguage m_script_lang; lldb::ScriptLanguage m_script_lang;
std::string m_core_file; std::string m_core_file;
std::string m_crash_log; std::string m_crash_log;
std::vector<std::pair<bool,std::string> > m_initial_commands; std::vector<InitialCmdEntry> m_initial_commands;
std::vector<std::pair<bool,std::string> > m_after_file_commands; std::vector<InitialCmdEntry> m_after_file_commands;
std::vector<std::pair<bool,std::string> > m_after_crash_commands; std::vector<InitialCmdEntry> m_after_crash_commands;
bool m_debug_mode; bool m_debug_mode;
bool m_source_quietly; bool m_source_quietly;
bool m_print_version; bool m_print_version;