<rdar://problem/12188843> Fixing a problem where a Python command created in the same module where the target function is defined causes the help string not to come out
llvm-svn: 164172
diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp
index a1a65ae..64f80a0 100644
--- a/lldb/source/Commands/CommandObjectCommands.cpp
+++ b/lldb/source/Commands/CommandObjectCommands.cpp
@@ -1162,6 +1162,7 @@
private:
std::string m_function_name;
ScriptedCommandSynchronicity m_synchro;
+ bool m_fetched_help_long;
public:
@@ -1174,15 +1175,9 @@
(std::string("Run Python function ") + funct).c_str(),
NULL),
m_function_name(funct),
- m_synchro(synch)
+ m_synchro(synch),
+ m_fetched_help_long(false)
{
- ScriptInterpreter* scripter = m_interpreter.GetScriptInterpreter();
- if (scripter)
- {
- std::string docstring = scripter->GetDocumentationForItem(funct.c_str());
- if (!docstring.empty())
- SetHelpLong(docstring);
- }
}
virtual
@@ -1208,6 +1203,23 @@
return m_synchro;
}
+ virtual const char *
+ GetHelpLong ()
+ {
+ if (!m_fetched_help_long)
+ {
+ ScriptInterpreter* scripter = m_interpreter.GetScriptInterpreter();
+ if (scripter)
+ {
+ std::string docstring;
+ m_fetched_help_long = scripter->GetDocumentationForItem(m_function_name.c_str(),docstring);
+ if (!docstring.empty())
+ SetHelpLong(docstring);
+ }
+ }
+ return CommandObjectRaw::GetHelpLong();
+ }
+
protected:
virtual bool
DoExecute (const char *raw_command_line, CommandReturnObject &result)
diff --git a/lldb/source/Interpreter/ScriptInterpreterPython.cpp b/lldb/source/Interpreter/ScriptInterpreterPython.cpp
index fec70e3..d085873 100644
--- a/lldb/source/Interpreter/ScriptInterpreterPython.cpp
+++ b/lldb/source/Interpreter/ScriptInterpreterPython.cpp
@@ -2542,9 +2542,12 @@
// in Python, a special attribute __doc__ contains the docstring
// for an object (function, method, class, ...) if any is defined
// Otherwise, the attribute's value is None
-std::string
-ScriptInterpreterPython::GetDocumentationForItem(const char* item)
+bool
+ScriptInterpreterPython::GetDocumentationForItem(const char* item, std::string& dest)
{
+ dest.clear();
+ if (!item || !*item)
+ return false;
std::string command(item);
command += ".__doc__";
@@ -2554,10 +2557,16 @@
ScriptInterpreter::eScriptReturnTypeCharStrOrNone,
&result_ptr, false) && result_ptr)
{
- return std::string(result_ptr);
+ dest.assign(result_ptr);
+ return true;
}
else
- return std::string("");
+ {
+ StreamString str_stream;
+ str_stream.Printf("Function %s was not found. Containing module might be missing.",item);
+ dest.assign(str_stream.GetData());
+ return false;
+ }
}
void