Avoiding a potentially memory allocating code path in the Python InputReader's CTRL+C handling code path - this can potentially cause a deadlock while interrupting a user-made Python command
llvm-svn: 180726
This commit is contained in:
		
							parent
							
								
									b39478e8ec
								
							
						
					
					
						commit
						d987cdf123
					
				| 
						 | 
					@ -277,8 +277,6 @@ ScriptInterpreterPython::PythonInputReaderManager::InputReaderCallback (void *ba
 | 
				
			||||||
    if (script_interpreter->m_script_lang != eScriptLanguagePython)
 | 
					    if (script_interpreter->m_script_lang != eScriptLanguagePython)
 | 
				
			||||||
        return 0;
 | 
					        return 0;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    switch (notification)
 | 
					    switch (notification)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        case eInputReaderActivate:
 | 
					        case eInputReaderActivate:
 | 
				
			||||||
| 
						 | 
					@ -843,13 +841,12 @@ ScriptInterpreterPython::InputReaderCallback
 | 
				
			||||||
    if (script_interpreter->m_script_lang != eScriptLanguagePython)
 | 
					    if (script_interpreter->m_script_lang != eScriptLanguagePython)
 | 
				
			||||||
        return 0;
 | 
					        return 0;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
 | 
					 | 
				
			||||||
    bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    switch (notification)
 | 
					    switch (notification)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    case eInputReaderActivate:
 | 
					    case eInputReaderActivate:
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
 | 
				
			||||||
 | 
					            bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
 | 
				
			||||||
            if (!batch_mode)
 | 
					            if (!batch_mode)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                out_stream->Printf ("Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.\n");
 | 
					                out_stream->Printf ("Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.\n");
 | 
				
			||||||
| 
						 | 
					@ -1263,13 +1260,13 @@ ScriptInterpreterPython::GenerateBreakpointOptionsCommandCallback
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    static StringList commands_in_progress;
 | 
					    static StringList commands_in_progress;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
 | 
					 | 
				
			||||||
    bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    switch (notification)
 | 
					    switch (notification)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    case eInputReaderActivate:
 | 
					    case eInputReaderActivate:
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
 | 
				
			||||||
 | 
					            bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
 | 
				
			||||||
            commands_in_progress.Clear();
 | 
					            commands_in_progress.Clear();
 | 
				
			||||||
            if (!batch_mode)
 | 
					            if (!batch_mode)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
| 
						 | 
					@ -1285,11 +1282,15 @@ ScriptInterpreterPython::GenerateBreakpointOptionsCommandCallback
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    case eInputReaderReactivate:
 | 
					    case eInputReaderReactivate:
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
 | 
				
			||||||
 | 
					            bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
 | 
				
			||||||
            if (reader.GetPrompt() && !batch_mode)
 | 
					            if (reader.GetPrompt() && !batch_mode)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                out_stream->Printf ("%s", reader.GetPrompt());
 | 
					                out_stream->Printf ("%s", reader.GetPrompt());
 | 
				
			||||||
                out_stream->Flush ();
 | 
					                out_stream->Flush ();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    case eInputReaderAsynchronousOutputWritten:
 | 
					    case eInputReaderAsynchronousOutputWritten:
 | 
				
			||||||
| 
						 | 
					@ -1297,6 +1298,8 @@ ScriptInterpreterPython::GenerateBreakpointOptionsCommandCallback
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
    case eInputReaderGotToken:
 | 
					    case eInputReaderGotToken:
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
 | 
				
			||||||
 | 
					            bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
 | 
				
			||||||
            std::string temp_string (bytes, bytes_len);
 | 
					            std::string temp_string (bytes, bytes_len);
 | 
				
			||||||
            commands_in_progress.AppendString (temp_string.c_str());
 | 
					            commands_in_progress.AppendString (temp_string.c_str());
 | 
				
			||||||
            if (!reader.IsDone() && reader.GetPrompt() && !batch_mode)
 | 
					            if (!reader.IsDone() && reader.GetPrompt() && !batch_mode)
 | 
				
			||||||
| 
						 | 
					@ -1320,6 +1323,9 @@ ScriptInterpreterPython::GenerateBreakpointOptionsCommandCallback
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    case eInputReaderDone:
 | 
					    case eInputReaderDone:
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            bool batch_mode = notification == eInputReaderDone ? 
 | 
				
			||||||
 | 
					                reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode() :
 | 
				
			||||||
 | 
					                true;
 | 
				
			||||||
            BreakpointOptions *bp_options = (BreakpointOptions *)baton;
 | 
					            BreakpointOptions *bp_options = (BreakpointOptions *)baton;
 | 
				
			||||||
            std::unique_ptr<BreakpointOptions::CommandData> data_ap(new BreakpointOptions::CommandData());
 | 
					            std::unique_ptr<BreakpointOptions::CommandData> data_ap(new BreakpointOptions::CommandData());
 | 
				
			||||||
            data_ap->user_source.AppendList (commands_in_progress);
 | 
					            data_ap->user_source.AppendList (commands_in_progress);
 | 
				
			||||||
| 
						 | 
					@ -1336,6 +1342,7 @@ ScriptInterpreterPython::GenerateBreakpointOptionsCommandCallback
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    else if (!batch_mode)
 | 
					                    else if (!batch_mode)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
 | 
					                        StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
 | 
				
			||||||
                        out_stream->Printf ("Warning: No command attached to breakpoint.\n");
 | 
					                        out_stream->Printf ("Warning: No command attached to breakpoint.\n");
 | 
				
			||||||
                        out_stream->Flush();
 | 
					                        out_stream->Flush();
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
| 
						 | 
					@ -1344,6 +1351,7 @@ ScriptInterpreterPython::GenerateBreakpointOptionsCommandCallback
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
		            if (!batch_mode)
 | 
							            if (!batch_mode)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
 | 
					                        StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
 | 
				
			||||||
                        out_stream->Printf ("Warning:  Unable to find script intepreter; no command attached to breakpoint.\n");
 | 
					                        out_stream->Printf ("Warning:  Unable to find script intepreter; no command attached to breakpoint.\n");
 | 
				
			||||||
                        out_stream->Flush();
 | 
					                        out_stream->Flush();
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
| 
						 | 
					@ -1369,13 +1377,13 @@ ScriptInterpreterPython::GenerateWatchpointOptionsCommandCallback
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    static StringList commands_in_progress;
 | 
					    static StringList commands_in_progress;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
 | 
					 | 
				
			||||||
    bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    switch (notification)
 | 
					    switch (notification)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    case eInputReaderActivate:
 | 
					    case eInputReaderActivate:
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
 | 
				
			||||||
 | 
					            bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            commands_in_progress.Clear();
 | 
					            commands_in_progress.Clear();
 | 
				
			||||||
            if (!batch_mode)
 | 
					            if (!batch_mode)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
| 
						 | 
					@ -1391,11 +1399,15 @@ ScriptInterpreterPython::GenerateWatchpointOptionsCommandCallback
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    case eInputReaderReactivate:
 | 
					    case eInputReaderReactivate:
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
 | 
				
			||||||
 | 
					            bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
 | 
				
			||||||
            if (reader.GetPrompt() && !batch_mode)
 | 
					            if (reader.GetPrompt() && !batch_mode)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                out_stream->Printf ("%s", reader.GetPrompt());
 | 
					                out_stream->Printf ("%s", reader.GetPrompt());
 | 
				
			||||||
                out_stream->Flush ();
 | 
					                out_stream->Flush ();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    case eInputReaderAsynchronousOutputWritten:
 | 
					    case eInputReaderAsynchronousOutputWritten:
 | 
				
			||||||
| 
						 | 
					@ -1403,6 +1415,8 @@ ScriptInterpreterPython::GenerateWatchpointOptionsCommandCallback
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
    case eInputReaderGotToken:
 | 
					    case eInputReaderGotToken:
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
 | 
				
			||||||
 | 
					            bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
 | 
				
			||||||
            std::string temp_string (bytes, bytes_len);
 | 
					            std::string temp_string (bytes, bytes_len);
 | 
				
			||||||
            commands_in_progress.AppendString (temp_string.c_str());
 | 
					            commands_in_progress.AppendString (temp_string.c_str());
 | 
				
			||||||
            if (!reader.IsDone() && reader.GetPrompt() && !batch_mode)
 | 
					            if (!reader.IsDone() && reader.GetPrompt() && !batch_mode)
 | 
				
			||||||
| 
						 | 
					@ -1426,6 +1440,9 @@ ScriptInterpreterPython::GenerateWatchpointOptionsCommandCallback
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    case eInputReaderDone:
 | 
					    case eInputReaderDone:
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            bool batch_mode = notification == eInputReaderDone ?
 | 
				
			||||||
 | 
					                reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode() :
 | 
				
			||||||
 | 
					                true;
 | 
				
			||||||
            WatchpointOptions *wp_options = (WatchpointOptions *)baton;
 | 
					            WatchpointOptions *wp_options = (WatchpointOptions *)baton;
 | 
				
			||||||
            std::unique_ptr<WatchpointOptions::CommandData> data_ap(new WatchpointOptions::CommandData());
 | 
					            std::unique_ptr<WatchpointOptions::CommandData> data_ap(new WatchpointOptions::CommandData());
 | 
				
			||||||
            data_ap->user_source.AppendList (commands_in_progress);
 | 
					            data_ap->user_source.AppendList (commands_in_progress);
 | 
				
			||||||
| 
						 | 
					@ -1442,6 +1459,7 @@ ScriptInterpreterPython::GenerateWatchpointOptionsCommandCallback
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    else if (!batch_mode)
 | 
					                    else if (!batch_mode)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
 | 
					                        StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
 | 
				
			||||||
                        out_stream->Printf ("Warning: No command attached to breakpoint.\n");
 | 
					                        out_stream->Printf ("Warning: No command attached to breakpoint.\n");
 | 
				
			||||||
                        out_stream->Flush();
 | 
					                        out_stream->Flush();
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
| 
						 | 
					@ -1450,6 +1468,7 @@ ScriptInterpreterPython::GenerateWatchpointOptionsCommandCallback
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
		            if (!batch_mode)
 | 
							            if (!batch_mode)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
 | 
					                        StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
 | 
				
			||||||
                        out_stream->Printf ("Warning:  Unable to find script intepreter; no command attached to breakpoint.\n");
 | 
					                        out_stream->Printf ("Warning:  Unable to find script intepreter; no command attached to breakpoint.\n");
 | 
				
			||||||
                        out_stream->Flush();
 | 
					                        out_stream->Flush();
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue