[Lldb-commits] [lldb] r170013 - in /lldb/trunk: include/lldb/Interpreter/ScriptInterpreter.h include/lldb/Interpreter/ScriptInterpreterPython.h source/Commands/CommandObjectType.cpp

Enrico Granata egranata at apple.com
Wed Dec 12 12:11:05 PST 2012


Author: enrico
Date: Wed Dec 12 14:11:05 2012
New Revision: 170013

URL: http://llvm.org/viewvc/llvm-project?rev=170013&view=rev
Log:
<rdar://problem/10898363>

Emitting a warning when defining a summary or a synthetic provider and the function/class name provided does not correspond to a valid scripting object

Also using this chance to edit a few error messages from weird "internal error" markers to actual user-legible data!


Modified:
    lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h
    lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h
    lldb/trunk/source/Commands/CommandObjectType.cpp

Modified: lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h?rev=170013&r1=170012&r2=170013&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h Wed Dec 12 14:11:05 2012
@@ -378,6 +378,12 @@
 		dest.clear();
         return false;
     }
+    
+    virtual bool
+    CheckObjectExists (const char* name)
+    {
+        return false;
+    }
 
     virtual bool
     LoadScriptingModule (const char* filename,

Modified: lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h?rev=170013&r1=170012&r2=170013&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h (original)
+++ lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h Wed Dec 12 14:11:05 2012
@@ -159,6 +159,15 @@
     GetDocumentationForItem (const char* item, std::string& dest);
     
     virtual bool
+    CheckObjectExists (const char* name)
+    {
+        if (!name || !name[0])
+            return false;
+        std::string temp;
+        return GetDocumentationForItem (name,temp);
+    }
+    
+    virtual bool
     LoadScriptingModule (const char* filename,
                          bool can_reload,
                          bool init_session,

Modified: lldb/trunk/source/Commands/CommandObjectType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectType.cpp?rev=170013&r1=170012&r2=170013&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectType.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectType.cpp Wed Dec 12 14:11:05 2012
@@ -818,7 +818,7 @@
         ScriptAddOptions *options_ptr = ((ScriptAddOptions*)data.baton);
         if (!options_ptr)
         {
-            out_stream->Printf ("Internal error #1: no script attached.\n");
+            out_stream->Printf ("internal synchronization information missing or invalid.\n");
             out_stream->Flush();
             return;
         }
@@ -828,7 +828,7 @@
         ScriptInterpreter *interpreter = data.reader.GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
         if (!interpreter)
         {
-            out_stream->Printf ("Internal error #2: no script attached.\n");
+            out_stream->Printf ("no script interprter.\n");
             out_stream->Flush();
             return;
         }
@@ -836,13 +836,13 @@
         if (!interpreter->GenerateTypeScriptFunction (options->m_user_source, 
                                                       funct_name_str))
         {
-            out_stream->Printf ("Internal error #3: no script attached.\n");
+            out_stream->Printf ("unable to generate a function.\n");
             out_stream->Flush();
             return;
         }
         if (funct_name_str.empty())
         {
-            out_stream->Printf ("Internal error #4: no script attached.\n");
+            out_stream->Printf ("unable to obtain a valid function name from the script interpreter.\n");
             out_stream->Flush();
             return;
         }
@@ -1037,17 +1037,10 @@
     
     if (!m_options.m_python_function.empty()) // we have a Python function ready to use
     {
-        ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
-        if (!interpreter)
-        {
-            result.AppendError ("Internal error #1N: no script attached.\n");
-            result.SetStatus (eReturnStatusFailed);
-            return false;
-        }
         const char *funct_name = m_options.m_python_function.c_str();
         if (!funct_name || !funct_name[0])
         {
-            result.AppendError ("Internal error #2N: no script attached.\n");
+            result.AppendError ("function name empty.\n");
             result.SetStatus (eReturnStatusFailed);
             return false;
         }
@@ -1057,13 +1050,18 @@
         script_format.reset(new ScriptSummaryFormat(m_options.m_flags,
                                                     funct_name,
                                                     code.c_str()));
+        
+        ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
+        
+        if (interpreter && interpreter->CheckObjectExists(funct_name) == false)
+            result.AppendWarning("The provided function does not exist - please define it before attempting to use this summary");
     }
     else if (!m_options.m_python_script.empty()) // we have a quick 1-line script, just use it
     {
         ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
         if (!interpreter)
         {
-            result.AppendError ("Internal error #1Q: no script attached.\n");
+            result.AppendError ("script interpreter missing - unable to generate function wrapper.\n");
             result.SetStatus (eReturnStatusFailed);
             return false;
         }
@@ -1073,13 +1071,13 @@
         if (!interpreter->GenerateTypeScriptFunction (funct_sl, 
                                                       funct_name_str))
         {
-            result.AppendError ("Internal error #2Q: no script attached.\n");
+            result.AppendError ("unable to generate function wrapper.\n");
             result.SetStatus (eReturnStatusFailed);
             return false;
         }
         if (funct_name_str.empty())
         {
-            result.AppendError ("Internal error #3Q: no script attached.\n");
+            result.AppendError ("script interpreter failed to generate a valid function name.\n");
             result.SetStatus (eReturnStatusFailed);
             return false;
         }
@@ -3353,7 +3351,7 @@
         SynthAddOptions *options_ptr = ((SynthAddOptions*)data.baton);
         if (!options_ptr)
         {
-            out_stream->Printf ("Internal error #1: no script attached.\n");
+            out_stream->Printf ("internal synchronization data missing.\n");
             out_stream->Flush();
             return;
         }
@@ -3363,7 +3361,7 @@
         ScriptInterpreter *interpreter = data.reader.GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
         if (!interpreter)
         {
-            out_stream->Printf ("Internal error #2: no script attached.\n");
+            out_stream->Printf ("no script interpreter.\n");
             out_stream->Flush();
             return;
         }
@@ -3371,13 +3369,13 @@
         if (!interpreter->GenerateTypeSynthClass (options->m_user_source, 
                                                   class_name_str))
         {
-            out_stream->Printf ("Internal error #3: no script attached.\n");
+            out_stream->Printf ("unable to generate a class.\n");
             out_stream->Flush();
             return;
         }
         if (class_name_str.empty())
         {
-            out_stream->Printf ("Internal error #4: no script attached.\n");
+            out_stream->Printf ("unable to obtain a proper name for the class.\n");
             out_stream->Flush();
             return;
         }
@@ -3415,7 +3413,7 @@
             }
             else
             {
-                out_stream->Printf ("Internal error #6: no script attached.\n");
+                out_stream->Printf ("invalid type name.\n");
                 out_stream->Flush();
                 return;
             }
@@ -3512,6 +3510,11 @@
     
     entry.reset(impl);
     
+    ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
+    
+    if (interpreter && interpreter->CheckObjectExists(impl->GetPythonClassName()) == false)
+        result.AppendWarning("The provided class does not exist - please define it before attempting to use this synthetic provider");
+    
     // now I have a valid provider, let's add it to every type
     
     lldb::TypeCategoryImplSP category;





More information about the lldb-commits mailing list