return *m_command_interpreter_up;
}
+ ScriptInterpreter *GetScriptInterpreter(bool can_create = true);
+
lldb::ListenerSP GetListener() { return m_listener_sp; }
// This returns the Debugger's scratch source manager. It won't be able to
// source file cache.
std::unique_ptr<CommandInterpreter> m_command_interpreter_up;
+ lldb::ScriptInterpreterSP m_script_interpreter_sp;
+ std::recursive_mutex m_script_interpreter_mutex;
+
IOHandlerStack m_input_reader_stack;
llvm::StringMap<std::weak_ptr<llvm::raw_ostream>> m_log_streams;
std::shared_ptr<llvm::raw_ostream> m_log_callback_stream_sp;
int GetOptionArgumentPosition(const char *in_string);
- ScriptInterpreter *GetScriptInterpreter(bool can_create = true);
-
- void SetScriptInterpreter();
-
void SkipLLDBInitFiles(bool skip_lldbinit_files) {
m_skip_lldbinit_files = skip_lldbinit_files;
}
CommandHistory m_command_history;
std::string m_repeat_command; // Stores the command that will be executed for
// an empty command string.
- lldb::ScriptInterpreterSP m_script_interpreter_sp;
- std::recursive_mutex m_script_interpreter_mutex;
lldb::IOHandlerSP m_command_io_handler_sp;
char m_comment_char;
bool m_batch_command_mode;
GetArgumentDescriptionAsCString(const lldb::CommandArgumentType arg_type);
CommandInterpreter &GetCommandInterpreter() { return m_interpreter; }
+ Debugger &GetDebugger();
virtual llvm::StringRef GetHelp();
BreakpointOptions *bp_options = bkpt_sp->GetOptions();
bkpt_sp->GetTarget()
.GetDebugger()
- .GetCommandInterpreter()
.GetScriptInterpreter()
->SetBreakpointCommandCallbackFunction(bp_options,
callback_function_name);
Status error =
bkpt_sp->GetTarget()
.GetDebugger()
- .GetCommandInterpreter()
.GetScriptInterpreter()
->SetBreakpointCommandCallback(bp_options, callback_body_text);
sb_error.SetError(error);
loc_sp->GetBreakpoint()
.GetTarget()
.GetDebugger()
- .GetCommandInterpreter()
.GetScriptInterpreter()
->SetBreakpointCommandCallbackFunction(bp_options,
callback_function_name);
loc_sp->GetBreakpoint()
.GetTarget()
.GetDebugger()
- .GetCommandInterpreter()
.GetScriptInterpreter()
->SetBreakpointCommandCallback(bp_options, callback_body_text);
sb_error.SetError(error);
BreakpointOptions &bp_options = bp_name->GetOptions();
m_impl_up->GetTarget()
->GetDebugger()
- .GetCommandInterpreter()
.GetScriptInterpreter()
->SetBreakpointCommandCallbackFunction(&bp_options,
callback_function_name);
Status error =
m_impl_up->GetTarget()
->GetDebugger()
- .GetCommandInterpreter()
.GetScriptInterpreter()
->SetBreakpointCommandCallback(&bp_options, callback_body_text);
sb_error.SetError(error);
DebuggerSP debugger_sp = lldb_private::Debugger::GetDebuggerAtIndex(j);
if (debugger_sp) {
ScriptInterpreter *interpreter_ptr =
- debugger_sp->GetCommandInterpreter().GetScriptInterpreter();
+ debugger_sp->GetScriptInterpreter();
if (interpreter_ptr) {
std::string output;
if (interpreter_ptr->GenerateTypeScriptFunction(input, output,
DebuggerSP debugger_sp = lldb_private::Debugger::GetDebuggerAtIndex(j);
if (debugger_sp) {
ScriptInterpreter *interpreter_ptr =
- debugger_sp->GetCommandInterpreter().GetScriptInterpreter();
+ debugger_sp->GetScriptInterpreter();
if (interpreter_ptr) {
std::string output;
if (interpreter_ptr->GenerateTypeSynthClass(input, output,
if (cmd_data_up->interpreter == eScriptLanguageNone)
bp_options->SetCommandDataCallback(cmd_data_up);
else {
- ScriptInterpreter *interp =
- target.GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
+ ScriptInterpreter *interp = target.GetDebugger().GetScriptInterpreter();
if (!interp) {
error.SetErrorStringWithFormat(
"Can't set script commands - no script interpreter");
if (m_breakpoint) {
TargetSP target_sp = m_breakpoint->GetTargetSP();
ScriptInterpreter *script_interp = target_sp->GetDebugger()
- .GetCommandInterpreter()
.GetScriptInterpreter();
if (!script_interp)
return;
}
ScriptInterpreter *script_interp = bkpt->GetTarget()
.GetDebugger()
- .GetCommandInterpreter()
.GetScriptInterpreter();
return new BreakpointResolverScripted(bkpt, class_name, depth, args_data_impl,
*script_interp);
}
ScriptInterpreter *BreakpointResolverScripted::GetScriptInterpreter() {
- return m_breakpoint->GetTarget().GetDebugger().GetCommandInterpreter()
- .GetScriptInterpreter();
+ return m_breakpoint->GetTarget().GetDebugger().GetScriptInterpreter();
}
Searcher::CallbackReturn
// to set or collect command callback. Otherwise, call the methods
// associated with this object.
if (m_options.m_use_script_language) {
- ScriptInterpreter *script_interp = m_interpreter.GetScriptInterpreter();
+ ScriptInterpreter *script_interp = GetDebugger().GetScriptInterpreter();
// Special handling for one-liner specified inline.
if (m_options.m_use_one_liner) {
script_interp->SetBreakpointCommandCallback(
if (m_fetched_help_long)
return CommandObjectRaw::GetHelpLong();
- ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter();
+ ScriptInterpreter *scripter = GetDebugger().GetScriptInterpreter();
if (!scripter)
return CommandObjectRaw::GetHelpLong();
protected:
bool DoExecute(llvm::StringRef raw_command_line,
CommandReturnObject &result) override {
- ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter();
+ ScriptInterpreter *scripter = GetDebugger().GetScriptInterpreter();
Status error;
StreamString stream;
stream.Printf("For more information run 'help %s'", name.c_str());
SetHelp(stream.GetString());
- if (ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter())
+ if (ScriptInterpreter *scripter = GetDebugger().GetScriptInterpreter())
GetFlags().Set(scripter->GetFlagsForCommandObject(cmd_obj_sp));
}
llvm::StringRef GetHelp() override {
if (m_fetched_help_short)
return CommandObjectRaw::GetHelp();
- ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter();
+ ScriptInterpreter *scripter = GetDebugger().GetScriptInterpreter();
if (!scripter)
return CommandObjectRaw::GetHelp();
std::string docstring;
if (m_fetched_help_long)
return CommandObjectRaw::GetHelpLong();
- ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter();
+ ScriptInterpreter *scripter = GetDebugger().GetScriptInterpreter();
if (!scripter)
return CommandObjectRaw::GetHelpLong();
protected:
bool DoExecute(llvm::StringRef raw_command_line,
CommandReturnObject &result) override {
- ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter();
+ ScriptInterpreter *scripter = GetDebugger().GetScriptInterpreter();
Status error;
// won't stomp on each other (wrt to execution contents, options, and
// more)
m_exe_ctx.Clear();
- if (m_interpreter.GetScriptInterpreter()->LoadScriptingModule(
+ if (GetDebugger().GetScriptInterpreter()->LoadScriptingModule(
entry.c_str(), m_options.m_allow_reload, init_session, error)) {
result.SetStatus(eReturnStatusSuccessFinishNoResult);
} else {
std::string &data) override {
StreamFileSP error_sp = io_handler.GetErrorStreamFile();
- ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
+ ScriptInterpreter *interpreter = GetDebugger().GetScriptInterpreter();
if (interpreter) {
StringList lines;
}
}
} else {
- ScriptInterpreter *interpreter =
- GetCommandInterpreter().GetScriptInterpreter();
+ ScriptInterpreter *interpreter = GetDebugger().GetScriptInterpreter();
if (!interpreter) {
result.AppendError("cannot find ScriptInterpreter");
result.SetStatus(eReturnStatusFailed);
return false;
}
- ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
+ ScriptInterpreter *interpreter = GetDebugger().GetScriptInterpreter();
if (interpreter &&
!interpreter->CheckObjectExists(m_options.m_class_name.c_str())) {
result.AppendErrorWithFormat("empty class name for scripted step.");
result.SetStatus(eReturnStatusFailed);
return false;
- } else if (!m_interpreter.GetScriptInterpreter()->CheckObjectExists(
+ } else if (!GetDebugger().GetScriptInterpreter()->CheckObjectExists(
m_options.m_class_name.c_str())) {
result.AppendErrorWithFormat(
"class for scripted step: \"%s\" does not exist.",
StreamFileSP error_sp = io_handler.GetErrorStreamFile();
#ifndef LLDB_DISABLE_PYTHON
- ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
+ ScriptInterpreter *interpreter = GetDebugger().GetScriptInterpreter();
if (interpreter) {
StringList lines;
lines.SplitIntoLines(data);
options_ptr); // this will ensure that we get rid of the pointer
// when going out of scope
- ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
+ ScriptInterpreter *interpreter = GetDebugger().GetScriptInterpreter();
if (interpreter) {
std::string funct_name_str;
if (interpreter->GenerateTypeScriptFunction(lines,
StreamFileSP error_sp = io_handler.GetErrorStreamFile();
#ifndef LLDB_DISABLE_PYTHON
- ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
+ ScriptInterpreter *interpreter = GetDebugger().GetScriptInterpreter();
if (interpreter) {
StringList lines;
lines.SplitIntoLines(data);
options_ptr); // this will ensure that we get rid of the pointer
// when going out of scope
- ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
+ ScriptInterpreter *interpreter = GetDebugger().GetScriptInterpreter();
if (interpreter) {
std::string class_name_str;
if (interpreter->GenerateTypeSynthClass(lines, class_name_str)) {
script_format = std::make_shared<ScriptSummaryFormat>(
m_options.m_flags, funct_name, code.c_str());
- ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
+ ScriptInterpreter *interpreter = GetDebugger().GetScriptInterpreter();
if (interpreter && !interpreter->CheckObjectExists(funct_name))
result.AppendWarningWithFormat(
} else if (!m_options.m_python_script
.empty()) // we have a quick 1-line script, just use it
{
- ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
+ ScriptInterpreter *interpreter = GetDebugger().GetScriptInterpreter();
if (!interpreter) {
result.AppendError("script interpreter missing - unable to generate "
"function wrapper.\n");
entry.reset(impl);
- ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
+ ScriptInterpreter *interpreter = GetDebugger().GetScriptInterpreter();
if (interpreter &&
!interpreter->CheckObjectExists(impl->GetPythonClassName()))
if (m_options.m_use_script_language) {
// Special handling for one-liner specified inline.
if (m_options.m_use_one_liner) {
- m_interpreter.GetScriptInterpreter()->SetWatchpointCommandCallback(
+ GetDebugger().GetScriptInterpreter()->SetWatchpointCommandCallback(
wp_options, m_options.m_one_liner.c_str());
}
// Special handling for using a Python function by name instead of
else if (!m_options.m_function_name.empty()) {
std::string oneliner(m_options.m_function_name);
oneliner += "(frame, wp, internal_dict)";
- m_interpreter.GetScriptInterpreter()->SetWatchpointCommandCallback(
+ GetDebugger().GetScriptInterpreter()->SetWatchpointCommandCallback(
wp_options, oneliner.c_str());
} else {
- m_interpreter.GetScriptInterpreter()
+ GetDebugger()
+ .GetScriptInterpreter()
->CollectDataForWatchpointCommandCallback(wp_options, result);
}
} else {
m_source_manager_up(), m_source_file_cache(),
m_command_interpreter_up(
llvm::make_unique<CommandInterpreter>(*this, false)),
- m_input_reader_stack(), m_instance_name(), m_loaded_plugins(),
- m_event_handler_thread(), m_io_handler_thread(),
+ m_script_interpreter_sp(), m_input_reader_stack(), m_instance_name(),
+ m_loaded_plugins(), m_event_handler_thread(), m_io_handler_thread(),
m_sync_broadcaster(nullptr, "lldb.debugger.sync"),
m_forward_listener_sp(), m_clear_once() {
char instance_cstr[256];
if (!out_file.IsValid())
out_file.SetStream(stdout, false);
- // do not create the ScriptInterpreter just for setting the output file
- // handle as the constructor will know how to do the right thing on its own
- const bool can_create = false;
- ScriptInterpreter *script_interpreter =
- GetCommandInterpreter().GetScriptInterpreter(can_create);
- if (script_interpreter)
+ // Do not create the ScriptInterpreter just for setting the output file
+ // handle as the constructor will know how to do the right thing on its own.
+ if (ScriptInterpreter *script_interpreter =
+ GetScriptInterpreter(/*can_create=*/false))
script_interpreter->ResetOutputFileHandle(fh);
}
error_stream);
}
+ScriptInterpreter *Debugger::GetScriptInterpreter(bool can_create) {
+ std::lock_guard<std::recursive_mutex> locker(m_script_interpreter_mutex);
+
+ if (!m_script_interpreter_sp) {
+ if (!can_create)
+ return nullptr;
+ m_script_interpreter_sp = PluginManager::GetScriptInterpreterForLanguage(
+ GetScriptLanguage(), *this);
+ }
+
+ return m_script_interpreter_sp.get();
+}
+
SourceManager &Debugger::GetSourceManager() {
if (!m_source_manager_up)
m_source_manager_up = llvm::make_unique<SourceManager>(shared_from_this());
if (target) {
ScriptInterpreter *script_interpreter =
- target->GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
+ target->GetDebugger().GetScriptInterpreter();
if (script_interpreter) {
Status error;
std::string script_output;
const uint32_t num_specs = file_specs.GetSize();
if (num_specs) {
- ScriptInterpreter *script_interpreter =
- debugger.GetCommandInterpreter().GetScriptInterpreter();
+ ScriptInterpreter *script_interpreter = debugger.GetScriptInterpreter();
if (script_interpreter) {
for (uint32_t i = 0; i < num_specs; ++i) {
FileSpec scripting_fspec(file_specs.GetFileSpecAtIndex(i));
}
ScriptInterpreter *script_interpreter =
- target_sp->GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
+ target_sp->GetDebugger().GetScriptInterpreter();
if (!script_interpreter) {
retval.assign("error: no ScriptInterpreter");
if (!target_sp)
return;
- m_interpreter =
- target_sp->GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
+ m_interpreter = target_sp->GetDebugger().GetScriptInterpreter();
if (m_interpreter != NULL)
m_wrapper_sp = m_interpreter->CreateSyntheticScriptedProvider(
IOHandlerDelegate(IOHandlerDelegate::Completion::LLDBCommand),
m_debugger(debugger), m_synchronous_execution(synchronous_execution),
m_skip_lldbinit_files(false), m_skip_app_init_files(false),
- m_script_interpreter_sp(), m_command_io_handler_sp(), m_comment_char('#'),
+ m_command_io_handler_sp(), m_comment_char('#'),
m_batch_command_mode(false), m_truncation_warning(eNoTruncation),
m_command_source_depth(0), m_num_errors(0), m_quit_requested(false),
m_stopped_for_crash(false) {
void CommandInterpreter::Clear() {
m_command_io_handler_sp.reset();
-
- if (m_script_interpreter_sp)
- m_script_interpreter_sp->Clear();
}
const char *CommandInterpreter::ProcessEmbeddedScriptCommands(const char *arg) {
debugger.SetAsyncExecution(old_async_execution);
}
-ScriptInterpreter *CommandInterpreter::GetScriptInterpreter(bool can_create) {
- std::lock_guard<std::recursive_mutex> locker(m_script_interpreter_mutex);
- if (!m_script_interpreter_sp) {
- if (!can_create)
- return nullptr;
- lldb::ScriptLanguage script_lang = GetDebugger().GetScriptLanguage();
- m_script_interpreter_sp =
- PluginManager::GetScriptInterpreterForLanguage(script_lang, m_debugger);
- }
- return m_script_interpreter_sp.get();
-}
-
bool CommandInterpreter::GetSynchronous() { return m_synchronous_execution; }
void CommandInterpreter::SetSynchronous(bool value) {
}
}
- ScriptInterpreter *script_interpreter = GetScriptInterpreter(false);
+ ScriptInterpreter *script_interpreter =
+ m_debugger.GetScriptInterpreter(false);
if (script_interpreter) {
if (script_interpreter->Interrupt())
return true;
CommandObject::~CommandObject() {}
+Debugger &CommandObject::GetDebugger() { return m_interpreter.GetDebugger(); }
+
llvm::StringRef CommandObject::GetHelp() { return m_cmd_help_short; }
llvm::StringRef CommandObject::GetHelpLong() { return m_cmd_help_long; }
return false;
}
- ScriptInterpreter *script_interpreter = m_interpreter.GetScriptInterpreter();
+ ScriptInterpreter *script_interpreter = GetDebugger().GetScriptInterpreter();
if (script_interpreter == nullptr) {
result.AppendError("no script interpreter");
TargetSP target_sp = process->CalculateTarget();
if (!target_sp)
return;
- m_interpreter =
- target_sp->GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
+ m_interpreter = target_sp->GetDebugger().GetScriptInterpreter();
if (m_interpreter) {
std::string os_plugin_class_name(
std::replace(module_basename.begin(), module_basename.end(),
'-', '_');
ScriptInterpreter *script_interpreter =
- target->GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
+ target->GetDebugger().GetScriptInterpreter();
if (script_interpreter &&
script_interpreter->IsReservedWord(
module_basename.c_str())) {
bool ProcessGDBRemote::ParsePythonTargetDefinition(
const FileSpec &target_definition_fspec) {
ScriptInterpreter *interpreter =
- GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
+ GetTarget().GetDebugger().GetScriptInterpreter();
Status error;
StructuredData::ObjectSP module_object_sp(
interpreter->LoadPluginModule(target_definition_fspec, error));
std::string oneliner("return ");
oneliner += function_name;
oneliner += "(frame, bp_loc, internal_dict)";
- m_debugger.GetCommandInterpreter()
- .GetScriptInterpreter()
- ->SetBreakpointCommandCallback(bp_options, oneliner.c_str());
+ m_debugger.GetScriptInterpreter()->SetBreakpointCommandCallback(
+ bp_options, oneliner.c_str());
}
Status ScriptInterpreterPythonImpl::SetBreakpointCommandCallback(
return StructuredData::ObjectSP();
Debugger &debugger = thread_plan_sp->GetTarget().GetDebugger();
- ScriptInterpreter *script_interpreter =
- debugger.GetCommandInterpreter().GetScriptInterpreter();
+ ScriptInterpreter *script_interpreter = debugger.GetScriptInterpreter();
ScriptInterpreterPythonImpl *python_interpreter =
static_cast<ScriptInterpreterPythonImpl *>(script_interpreter);
return StructuredData::GenericSP();
Debugger &debugger = bkpt_sp->GetTarget().GetDebugger();
- ScriptInterpreter *script_interpreter =
- debugger.GetCommandInterpreter().GetScriptInterpreter();
+ ScriptInterpreter *script_interpreter = debugger.GetScriptInterpreter();
ScriptInterpreterPythonImpl *python_interpreter =
static_cast<ScriptInterpreterPythonImpl *>(script_interpreter);
return StructuredData::ObjectSP();
Debugger &debugger = target->GetDebugger();
- ScriptInterpreter *script_interpreter =
- debugger.GetCommandInterpreter().GetScriptInterpreter();
+ ScriptInterpreter *script_interpreter = debugger.GetScriptInterpreter();
ScriptInterpreterPythonImpl *python_interpreter =
(ScriptInterpreterPythonImpl *)script_interpreter;
return true;
Debugger &debugger = target->GetDebugger();
- ScriptInterpreter *script_interpreter =
- debugger.GetCommandInterpreter().GetScriptInterpreter();
+ ScriptInterpreter *script_interpreter = debugger.GetScriptInterpreter();
ScriptInterpreterPythonImpl *python_interpreter =
(ScriptInterpreterPythonImpl *)script_interpreter;
return true;
Debugger &debugger = target->GetDebugger();
- ScriptInterpreter *script_interpreter =
- debugger.GetCommandInterpreter().GetScriptInterpreter();
+ ScriptInterpreter *script_interpreter = debugger.GetScriptInterpreter();
ScriptInterpreterPythonImpl *python_interpreter =
(ScriptInterpreterPythonImpl *)script_interpreter;
StructuredDataImpl *extra_args_impl = new StructuredDataImpl();
if (extra_args_sp)
extra_args_impl->SetObjectSP(extra_args_sp);
-
- BreakpointResolverSP resolver_sp(new
- BreakpointResolverScripted(nullptr, class_name,
- depth,
- extra_args_impl,
- *GetDebugger().GetCommandInterpreter()
- .GetScriptInterpreter()));
+
+ BreakpointResolverSP resolver_sp(new BreakpointResolverScripted(
+ nullptr, class_name, depth, extra_args_impl,
+ *GetDebugger().GetScriptInterpreter()));
return CreateBreakpoint(filter_sp, resolver_sp, internal, false, true);
}
ScriptInterpreter *script_interp = m_thread.GetProcess()
->GetTarget()
.GetDebugger()
- .GetCommandInterpreter()
.GetScriptInterpreter();
if (script_interp) {
m_implementation_sp = script_interp->CreateScriptedThreadPlan(
ScriptInterpreter *script_interp = m_thread.GetProcess()
->GetTarget()
.GetDebugger()
- .GetCommandInterpreter()
.GetScriptInterpreter();
if (script_interp) {
bool script_error;
ScriptInterpreter *script_interp = m_thread.GetProcess()
->GetTarget()
.GetDebugger()
- .GetCommandInterpreter()
.GetScriptInterpreter();
if (script_interp) {
bool script_error;
ScriptInterpreter *script_interp = m_thread.GetProcess()
->GetTarget()
.GetDebugger()
- .GetCommandInterpreter()
.GetScriptInterpreter();
if (script_interp) {
bool script_error;
ScriptInterpreter *script_interp = m_thread.GetProcess()
->GetTarget()
.GetDebugger()
- .GetCommandInterpreter()
.GetScriptInterpreter();
if (script_interp) {
bool script_error;