843
841
if (script_interpreter->m_script_lang != eScriptLanguagePython)
846
StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
847
bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
849
844
switch (notification)
851
846
case eInputReaderActivate:
848
StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
849
bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
855
852
out_stream->Printf ("Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.\n");
1252
1249
static const char *g_reader_instructions = "Enter your Python command(s). Type 'DONE' to end.";
1251
static const char *g_bkpt_command_reader_instructions = "Enter your Python command(s). Type 'DONE' to end.\n"
1252
"def function(frame,bp_loc,internal_dict):\n"
1253
" \"\"\"frame: the SBFrame for the location at which you stopped\n"
1254
" bp_loc: an SBBreakpointLocation for the breakpoint location information\n"
1255
" internal_dict: an LLDB support object not to be used\"\"\"";
1255
1258
ScriptInterpreterPython::GenerateBreakpointOptionsCommandCallback
1264
1267
static StringList commands_in_progress;
1266
StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
1267
bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
1269
1269
switch (notification)
1271
1271
case eInputReaderActivate:
1274
StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
1275
bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
1273
1276
commands_in_progress.Clear();
1274
1277
if (!batch_mode)
1276
out_stream->Printf ("%s\n", g_reader_instructions);
1279
out_stream->Printf ("%s\n", g_bkpt_command_reader_instructions);
1277
1280
if (reader.GetPrompt())
1278
1281
out_stream->Printf ("%s", reader.GetPrompt());
1279
1282
out_stream->Flush ();
2576
2601
FileSpec target_file(pathname, true);
2578
// TODO: would we want to reject any other value?
2579
if (target_file.GetFileType() == FileSpec::eFileTypeInvalid ||
2580
target_file.GetFileType() == FileSpec::eFileTypeUnknown)
2582
error.SetErrorString("invalid pathname");
2586
const char* directory = target_file.GetDirectory().GetCString();
2587
2602
std::string basename(target_file.GetFilename().GetCString());
2604
StreamString command_stream;
2589
2606
// Before executing Pyton code, lock the GIL.
2590
2607
Locker py_lock (this,
2591
2608
Locker::AcquireLock | (init_session ? Locker::InitSession : 0),
2592
2609
Locker::FreeAcquiredLock | (init_session ? Locker::TearDownSession : 0));
2594
// now make sure that Python has "directory" in the search path
2595
StreamString command_stream;
2596
command_stream.Printf("if not (sys.path.__contains__('%s')):\n sys.path.insert(1,'%s');\n\n",
2599
bool syspath_retval = ExecuteMultipleLines(command_stream.GetData(), ScriptInterpreter::ExecuteScriptOptions().SetEnableIO(false).SetSetLLDBGlobals(false));
2600
if (!syspath_retval)
2602
error.SetErrorString("Python sys.path handling failed");
2611
if (target_file.GetFileType() == FileSpec::eFileTypeInvalid ||
2612
target_file.GetFileType() == FileSpec::eFileTypeUnknown)
2614
// if not a valid file of any sort, check if it might be a filename still
2615
// dot can't be used but / and \ can, and if either is found, reject
2616
if (strchr(pathname,'\\') || strchr(pathname,'/'))
2618
error.SetErrorString("invalid pathname");
2621
basename = pathname; // not a filename, probably a package of some sort, let it go through
2623
else if (target_file.GetFileType() == FileSpec::eFileTypeDirectory ||
2624
target_file.GetFileType() == FileSpec::eFileTypeRegular ||
2625
target_file.GetFileType() == FileSpec::eFileTypeSymbolicLink)
2627
const char* directory = target_file.GetDirectory().GetCString();
2629
// now make sure that Python has "directory" in the search path
2630
StreamString command_stream;
2631
command_stream.Printf("if not (sys.path.__contains__('%s')):\n sys.path.insert(1,'%s');\n\n",
2634
bool syspath_retval = ExecuteMultipleLines(command_stream.GetData(), ScriptInterpreter::ExecuteScriptOptions().SetEnableIO(false).SetSetLLDBGlobals(false));
2635
if (!syspath_retval)
2637
error.SetErrorString("Python sys.path handling failed");
2641
// strip .py or .pyc extension
2642
ConstString extension = target_file.GetFileNameExtension();
2645
if (::strcmp(extension.GetCString(), "py") == 0)
2646
basename.resize(basename.length()-3);
2647
else if(::strcmp(extension.GetCString(), "pyc") == 0)
2648
basename.resize(basename.length()-4);
2653
error.SetErrorString("no known way to import this module specification");
2606
// strip .py or .pyc extension
2607
ConstString extension = target_file.GetFileNameExtension();
2610
if (::strcmp(extension.GetCString(), "py") == 0)
2611
basename.resize(basename.length()-3);
2612
else if(::strcmp(extension.GetCString(), "pyc") == 0)
2613
basename.resize(basename.length()-4);
2616
2657
// check if the module is already import-ed
2617
2658
command_stream.Clear();
2618
2659
command_stream.Printf("sys.getrefcount(%s)",basename.c_str());