Added a "--no-lldbinit" option (-n for short (which magically matches

what gdb uses)) so we can tell our "lldb" driver program to not automatically
parse any .lldbinit files. 

llvm-svn: 116179
This commit is contained in:
Greg Clayton 2010-10-11 01:05:37 +00:00
parent 46747022d2
commit 6eee5aa067
6 changed files with 98 additions and 66 deletions

View File

@ -41,6 +41,9 @@ public:
void
SetAsync (bool b);
void
SkipLLDBInitFiles (bool b);
void
SetInputFileHandle (FILE *f, bool transfer_ownership);

View File

@ -202,6 +202,12 @@ public:
ScriptInterpreter *
GetScriptInterpreter ();
void
SkipLLDBInitFiles (bool skip_lldbinit_files)
{
m_skip_lldbinit_files = skip_lldbinit_files;
}
bool
GetSynchronous ();
@ -239,6 +245,7 @@ private:
Debugger &m_debugger; // The debugger session that this interpreter is associated with
bool m_synchronous_execution;
bool m_skip_lldbinit_files;
CommandObject::CommandMap m_command_dict; // Stores basic built-in commands (they cannot be deleted, removed or overwritten).
CommandObject::CommandMap m_alias_dict; // Stores user aliases/abbreviations for commands
CommandObject::CommandMap m_user_dict; // Stores user-defined commands

View File

@ -10,11 +10,6 @@
#include "lldb/API/SBDebugger.h"
#include "lldb/lldb-include.h"
#include "lldb/Interpreter/Args.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/State.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/TargetList.h"
#include "lldb/API/SBListener.h"
#include "lldb/API/SBBroadcaster.h"
@ -29,6 +24,12 @@
#include "lldb/API/SBStringList.h"
#include "lldb/API/SBTarget.h"
#include "lldb/API/SBThread.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/State.h"
#include "lldb/Interpreter/Args.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/TargetList.h"
using namespace lldb;
using namespace lldb_private;
@ -82,6 +83,13 @@ SBDebugger::SetAsync (bool b)
m_opaque_sp->SetAsyncExecution(b);
}
void
SBDebugger::SkipLLDBInitFiles (bool b)
{
if (m_opaque_sp)
m_opaque_sp->GetCommandInterpreter().SkipLLDBInitFiles (b);
}
// Shouldn't really be settable after initialization as this could cause lots of problems; don't want users
// trying to switch modes in the middle of a debugging session.
void

View File

@ -309,78 +309,79 @@ CommandObjectBreakpointSet::Execute
switch (break_type)
{
case eSetTypeFileAndLine: // Breakpoint by source position
{
FileSpec file;
if (m_options.m_filename.empty())
{
StackFrame *cur_frame = m_interpreter.GetDebugger().GetExecutionContext().frame;
if (cur_frame == NULL)
FileSpec file;
if (m_options.m_filename.empty())
{
result.AppendError ("Attempting to set breakpoint by line number alone with no selected frame.");
result.SetStatus (eReturnStatusFailed);
break;
}
else if (!cur_frame->HasDebugInformation())
{
result.AppendError ("Attempting to set breakpoint by line number alone but selected frame has no debug info.");
result.SetStatus (eReturnStatusFailed);
break;
}
else
{
const SymbolContext &context = cur_frame->GetSymbolContext(true);
if (context.line_entry.file)
StackFrame *cur_frame = m_interpreter.GetDebugger().GetExecutionContext().frame;
if (cur_frame == NULL)
{
file = context.line_entry.file;
}
else if (context.comp_unit != NULL)
{ file = context.comp_unit;
}
else
{
result.AppendError ("Attempting to set breakpoint by line number alone but can't find the file for the selected frame.");
result.AppendError ("Attempting to set breakpoint by line number alone with no selected frame.");
result.SetStatus (eReturnStatusFailed);
break;
}
}
}
else
{
file.SetFile(m_options.m_filename.c_str());
}
if (use_module)
{
for (int i = 0; i < num_modules; ++i)
{
module.SetFile(m_options.m_modules[i].c_str());
bp = target->CreateBreakpoint (&module,
file,
m_options.m_line_num,
m_options.m_ignore_inlines).get();
if (bp)
else if (!cur_frame->HasDebugInformation())
{
StreamString &output_stream = result.GetOutputStream();
output_stream.Printf ("Breakpoint created: ");
bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
output_stream.EOL();
result.SetStatus (eReturnStatusSuccessFinishResult);
result.AppendError ("Attempting to set breakpoint by line number alone but selected frame has no debug info.");
result.SetStatus (eReturnStatusFailed);
break;
}
else
{
result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n",
m_options.m_modules[i].c_str());
result.SetStatus (eReturnStatusFailed);
const SymbolContext &context = cur_frame->GetSymbolContext(true);
if (context.line_entry.file)
{
file = context.line_entry.file;
}
else if (context.comp_unit != NULL)
{ file = context.comp_unit;
}
else
{
result.AppendError ("Attempting to set breakpoint by line number alone but can't find the file for the selected frame.");
result.SetStatus (eReturnStatusFailed);
break;
}
}
}
else
{
file.SetFile(m_options.m_filename.c_str());
}
if (use_module)
{
for (int i = 0; i < num_modules; ++i)
{
module.SetFile(m_options.m_modules[i].c_str());
bp = target->CreateBreakpoint (&module,
file,
m_options.m_line_num,
m_options.m_ignore_inlines).get();
if (bp)
{
StreamString &output_stream = result.GetOutputStream();
output_stream.Printf ("Breakpoint created: ");
bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
output_stream.EOL();
result.SetStatus (eReturnStatusSuccessFinishResult);
}
else
{
result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n",
m_options.m_modules[i].c_str());
result.SetStatus (eReturnStatusFailed);
}
}
}
else
bp = target->CreateBreakpoint (NULL,
file,
m_options.m_line_num,
m_options.m_ignore_inlines).get();
}
else
bp = target->CreateBreakpoint (NULL,
file,
m_options.m_line_num,
m_options.m_ignore_inlines).get();
}
break;
break;
case eSetTypeAddress: // Breakpoint by address
bp = target->CreateBreakpoint (m_options.m_load_addr, false).get();
break;

View File

@ -59,7 +59,8 @@ CommandInterpreter::CommandInterpreter
) :
Broadcaster ("CommandInterpreter"),
m_debugger (debugger),
m_synchronous_execution (synchronous_execution)
m_synchronous_execution (synchronous_execution),
m_skip_lldbinit_files (false)
{
const char *dbg_name = debugger.GetInstanceName().AsCString();
std::string lang_name = ScriptInterpreter::LanguageToString (script_language);
@ -1060,6 +1061,10 @@ CommandInterpreter::GetOptionArgumentPosition (const char *in_string)
void
CommandInterpreter::SourceInitFile (bool in_cwd, CommandReturnObject &result)
{
// Don't parse any .lldbinit files if we were asked not to
if (m_skip_lldbinit_files)
return;
const char *init_file_path = in_cwd ? "./.lldbinit" : "~/.lldbinit";
FileSpec init_file (init_file_path);
// If the file exists, tell HandleCommand to 'source' it; this will do the actual broadcasting

View File

@ -75,6 +75,9 @@ static lldb::OptionDefinition g_options[] =
{ LLDB_OPT_SET_ALL, false, "editor", 'e', no_argument, NULL, NULL, eArgTypeNone,
"Tells the debugger to open source files using the host's \"external editor\" mechanism." },
{ LLDB_OPT_SET_ALL, false, "no-lldbinit", 'n', no_argument, NULL, NULL, eArgTypeNone,
"Do not automatically parse any '.lldbinit' files." },
// { LLDB_OPT_SET_4, true, "crash-log", 'c', required_argument, NULL, NULL, eArgTypeFilename,
// "Load executable images from a crash log for symbolication." },
@ -554,10 +557,15 @@ Driver::ParseArgs (int argc, const char *argv[], FILE *out_fh, bool &exit)
case 'c':
m_option_data.m_crash_log = optarg;
break;
case 'e':
m_option_data.m_use_external_editor = true;
break;
case 'n':
m_debugger.SkipLLDBInitFiles (true);
break;
case 'f':
{
SBFileSpec file(optarg);