diff options
author | Adrian Prantl <aprantl@apple.com> | 2018-04-30 16:49:04 +0000 |
---|---|---|
committer | Adrian Prantl <aprantl@apple.com> | 2018-04-30 16:49:04 +0000 |
commit | 05097246f352eca76207c9ebb08656c88bdf751a (patch) | |
tree | bfc4ec8250a939aaf4ade6fc6c528726183e5367 /lldb/source/Plugins/ScriptInterpreter/Python | |
parent | add59c052dd6768fd54431e6a3bf045e7f25cb59 (diff) | |
download | bcm5719-llvm-05097246f352eca76207c9ebb08656c88bdf751a.tar.gz bcm5719-llvm-05097246f352eca76207c9ebb08656c88bdf751a.zip |
Reflow paragraphs in comments.
This is intended as a clean up after the big clang-format commit
(r280751), which unfortunately resulted in many of the comment
paragraphs in LLDB being very hard to read.
FYI, the script I used was:
import textwrap
import commands
import os
import sys
import re
tmp = "%s.tmp"%sys.argv[1]
out = open(tmp, "w+")
with open(sys.argv[1], "r") as f:
header = ""
text = ""
comment = re.compile(r'^( *//) ([^ ].*)$')
special = re.compile(r'^((([A-Z]+[: ])|([0-9]+ )).*)|(.*;)$')
for line in f:
match = comment.match(line)
if match and not special.match(match.group(2)):
# skip intentionally short comments.
if not text and len(match.group(2)) < 40:
out.write(line)
continue
if text:
text += " " + match.group(2)
else:
header = match.group(1)
text = match.group(2)
continue
if text:
filled = textwrap.wrap(text, width=(78-len(header)),
break_long_words=False)
for l in filled:
out.write(header+" "+l+'\n')
text = ""
out.write(line)
os.rename(tmp, sys.argv[1])
Differential Revision: https://reviews.llvm.org/D46144
llvm-svn: 331197
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python')
3 files changed, 157 insertions, 199 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp index 966bdff3ad9..f528dcf21be 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp @@ -123,21 +123,20 @@ PythonObject::ResolveNameWithDictionary(llvm::StringRef name, } PythonObject PythonObject::ResolveName(llvm::StringRef name) const { - // Resolve the name in the context of the specified object. If, - // for example, `this` refers to a PyModule, then this will look for - // `name` in this module. If `this` refers to a PyType, then it will - // resolve `name` as an attribute of that type. If `this` refers to - // an instance of an object, then it will resolve `name` as the value - // of the specified field. + // Resolve the name in the context of the specified object. If, for example, + // `this` refers to a PyModule, then this will look for `name` in this + // module. If `this` refers to a PyType, then it will resolve `name` as an + // attribute of that type. If `this` refers to an instance of an object, + // then it will resolve `name` as the value of the specified field. // // This function handles dotted names so that, for example, if `m_py_obj` - // refers to the `sys` module, and `name` == "path.append", then it - // will find the function `sys.path.append`. + // refers to the `sys` module, and `name` == "path.append", then it will find + // the function `sys.path.append`. size_t dot_pos = name.find_first_of('.'); if (dot_pos == llvm::StringRef::npos) { - // No dots in the name, we should be able to find the value immediately - // as an attribute of `m_py_obj`. + // No dots in the name, we should be able to find the value immediately as + // an attribute of `m_py_obj`. return GetAttributeValue(name); } @@ -230,8 +229,8 @@ bool PythonBytes::Check(PyObject *py_obj) { } void PythonBytes::Reset(PyRefType type, PyObject *py_obj) { - // Grab the desired reference type so that if we end up rejecting - // `py_obj` it still gets decremented if necessary. + // Grab the desired reference type so that if we end up rejecting `py_obj` it + // still gets decremented if necessary. PythonObject result(type, py_obj); if (!PythonBytes::Check(py_obj)) { @@ -240,8 +239,7 @@ void PythonBytes::Reset(PyRefType type, PyObject *py_obj) { } // Calling PythonObject::Reset(const PythonObject&) will lead to stack - // overflow since it calls - // back into the virtual implementation. + // overflow since it calls back into the virtual implementation. PythonObject::Reset(PyRefType::Borrowed, result.get()); } @@ -303,8 +301,8 @@ bool PythonByteArray::Check(PyObject *py_obj) { } void PythonByteArray::Reset(PyRefType type, PyObject *py_obj) { - // Grab the desired reference type so that if we end up rejecting - // `py_obj` it still gets decremented if necessary. + // Grab the desired reference type so that if we end up rejecting `py_obj` it + // still gets decremented if necessary. PythonObject result(type, py_obj); if (!PythonByteArray::Check(py_obj)) { @@ -313,8 +311,7 @@ void PythonByteArray::Reset(PyRefType type, PyObject *py_obj) { } // Calling PythonObject::Reset(const PythonObject&) will lead to stack - // overflow since it calls - // back into the virtual implementation. + // overflow since it calls back into the virtual implementation. PythonObject::Reset(PyRefType::Borrowed, result.get()); } @@ -378,8 +375,8 @@ bool PythonString::Check(PyObject *py_obj) { } void PythonString::Reset(PyRefType type, PyObject *py_obj) { - // Grab the desired reference type so that if we end up rejecting - // `py_obj` it still gets decremented if necessary. + // Grab the desired reference type so that if we end up rejecting `py_obj` it + // still gets decremented if necessary. PythonObject result(type, py_obj); if (!PythonString::Check(py_obj)) { @@ -394,8 +391,7 @@ void PythonString::Reset(PyRefType type, PyObject *py_obj) { result.Reset(PyRefType::Owned, PyUnicode_AsUTF8String(result.get())); #endif // Calling PythonObject::Reset(const PythonObject&) will lead to stack - // overflow since it calls - // back into the virtual implementation. + // overflow since it calls back into the virtual implementation. PythonObject::Reset(PyRefType::Borrowed, result.get()); } @@ -466,8 +462,8 @@ bool PythonInteger::Check(PyObject *py_obj) { return false; #if PY_MAJOR_VERSION >= 3 - // Python 3 does not have PyInt_Check. There is only one type of - // integral value, long. + // Python 3 does not have PyInt_Check. There is only one type of integral + // value, long. return PyLong_Check(py_obj); #else return PyLong_Check(py_obj) || PyInt_Check(py_obj); @@ -475,8 +471,8 @@ bool PythonInteger::Check(PyObject *py_obj) { } void PythonInteger::Reset(PyRefType type, PyObject *py_obj) { - // Grab the desired reference type so that if we end up rejecting - // `py_obj` it still gets decremented if necessary. + // Grab the desired reference type so that if we end up rejecting `py_obj` it + // still gets decremented if necessary. PythonObject result(type, py_obj); if (!PythonInteger::Check(py_obj)) { @@ -485,13 +481,13 @@ void PythonInteger::Reset(PyRefType type, PyObject *py_obj) { } #if PY_MAJOR_VERSION < 3 - // Always store this as a PyLong, which makes interoperability between - // Python 2.x and Python 3.x easier. This is only necessary in 2.x, - // since 3.x doesn't even have a PyInt. + // Always store this as a PyLong, which makes interoperability between Python + // 2.x and Python 3.x easier. This is only necessary in 2.x, since 3.x + // doesn't even have a PyInt. if (PyInt_Check(py_obj)) { // Since we converted the original object to a different type, the new - // object is an owned object regardless of the ownership semantics requested - // by the user. + // object is an owned object regardless of the ownership semantics + // requested by the user. result.Reset(PyRefType::Owned, PyLong_FromLongLong(PyInt_AsLong(py_obj))); } #endif @@ -500,8 +496,7 @@ void PythonInteger::Reset(PyRefType type, PyObject *py_obj) { "Couldn't get a PyLong from this PyObject"); // Calling PythonObject::Reset(const PythonObject&) will lead to stack - // overflow since it calls - // back into the virtual implementation. + // overflow since it calls back into the virtual implementation. PythonObject::Reset(PyRefType::Borrowed, result.get()); } @@ -513,10 +508,9 @@ int64_t PythonInteger::GetInteger() const { int overflow = 0; int64_t result = PyLong_AsLongLongAndOverflow(m_py_obj, &overflow); if (overflow != 0) { - // We got an integer that overflows, like 18446744072853913392L - // we can't use PyLong_AsLongLong() as it will return - // 0xffffffffffffffff. If we use the unsigned long long - // it will work as expected. + // We got an integer that overflows, like 18446744072853913392L we can't + // use PyLong_AsLongLong() as it will return 0xffffffffffffffff. If we + // use the unsigned long long it will work as expected. const uint64_t uval = PyLong_AsUnsignedLongLong(m_py_obj); result = static_cast<int64_t>(uval); } @@ -563,8 +557,8 @@ bool PythonList::Check(PyObject *py_obj) { } void PythonList::Reset(PyRefType type, PyObject *py_obj) { - // Grab the desired reference type so that if we end up rejecting - // `py_obj` it still gets decremented if necessary. + // Grab the desired reference type so that if we end up rejecting `py_obj` it + // still gets decremented if necessary. PythonObject result(type, py_obj); if (!PythonList::Check(py_obj)) { @@ -573,8 +567,7 @@ void PythonList::Reset(PyRefType type, PyObject *py_obj) { } // Calling PythonObject::Reset(const PythonObject&) will lead to stack - // overflow since it calls - // back into the virtual implementation. + // overflow since it calls back into the virtual implementation. PythonObject::Reset(PyRefType::Borrowed, result.get()); } @@ -668,8 +661,8 @@ bool PythonTuple::Check(PyObject *py_obj) { } void PythonTuple::Reset(PyRefType type, PyObject *py_obj) { - // Grab the desired reference type so that if we end up rejecting - // `py_obj` it still gets decremented if necessary. + // Grab the desired reference type so that if we end up rejecting `py_obj` it + // still gets decremented if necessary. PythonObject result(type, py_obj); if (!PythonTuple::Check(py_obj)) { @@ -678,8 +671,7 @@ void PythonTuple::Reset(PyRefType type, PyObject *py_obj) { } // Calling PythonObject::Reset(const PythonObject&) will lead to stack - // overflow since it calls - // back into the virtual implementation. + // overflow since it calls back into the virtual implementation. PythonObject::Reset(PyRefType::Borrowed, result.get()); } @@ -741,8 +733,8 @@ bool PythonDictionary::Check(PyObject *py_obj) { } void PythonDictionary::Reset(PyRefType type, PyObject *py_obj) { - // Grab the desired reference type so that if we end up rejecting - // `py_obj` it still gets decremented if necessary. + // Grab the desired reference type so that if we end up rejecting `py_obj` it + // still gets decremented if necessary. PythonObject result(type, py_obj); if (!PythonDictionary::Check(py_obj)) { @@ -751,8 +743,7 @@ void PythonDictionary::Reset(PyRefType type, PyObject *py_obj) { } // Calling PythonObject::Reset(const PythonObject&) will lead to stack - // overflow since it calls - // back into the virtual implementation. + // overflow since it calls back into the virtual implementation. PythonObject::Reset(PyRefType::Borrowed, result.get()); } @@ -833,8 +824,8 @@ bool PythonModule::Check(PyObject *py_obj) { } void PythonModule::Reset(PyRefType type, PyObject *py_obj) { - // Grab the desired reference type so that if we end up rejecting - // `py_obj` it still gets decremented if necessary. + // Grab the desired reference type so that if we end up rejecting `py_obj` it + // still gets decremented if necessary. PythonObject result(type, py_obj); if (!PythonModule::Check(py_obj)) { @@ -843,8 +834,7 @@ void PythonModule::Reset(PyRefType type, PyObject *py_obj) { } // Calling PythonObject::Reset(const PythonObject&) will lead to stack - // overflow since it calls - // back into the virtual implementation. + // overflow since it calls back into the virtual implementation. PythonObject::Reset(PyRefType::Borrowed, result.get()); } @@ -871,8 +861,8 @@ bool PythonCallable::Check(PyObject *py_obj) { } void PythonCallable::Reset(PyRefType type, PyObject *py_obj) { - // Grab the desired reference type so that if we end up rejecting - // `py_obj` it still gets decremented if necessary. + // Grab the desired reference type so that if we end up rejecting `py_obj` it + // still gets decremented if necessary. PythonObject result(type, py_obj); if (!PythonCallable::Check(py_obj)) { @@ -881,8 +871,7 @@ void PythonCallable::Reset(PyRefType type, PyObject *py_obj) { } // Calling PythonObject::Reset(const PythonObject&) will lead to stack - // overflow since it calls - // back into the virtual implementation. + // overflow since it calls back into the virtual implementation. PythonObject::Reset(PyRefType::Borrowed, result.get()); } @@ -963,9 +952,9 @@ bool PythonFile::Check(PyObject *py_obj) { #else // In Python 3, there is no `PyFile_Check`, and in fact PyFile is not even a // first-class object type anymore. `PyFile_FromFd` is just a thin wrapper - // over `io.open()`, which returns some object derived from `io.IOBase`. - // As a result, the only way to detect a file in Python 3 is to check whether - // it inherits from `io.IOBase`. Since it is possible for non-files to also + // over `io.open()`, which returns some object derived from `io.IOBase`. As a + // result, the only way to detect a file in Python 3 is to check whether it + // inherits from `io.IOBase`. Since it is possible for non-files to also // inherit from `io.IOBase`, we additionally verify that it has the `fileno` // attribute, which should guarantee that it is backed by the file system. PythonObject io_module(PyRefType::Owned, PyImport_ImportModule("io")); @@ -985,8 +974,8 @@ bool PythonFile::Check(PyObject *py_obj) { } void PythonFile::Reset(PyRefType type, PyObject *py_obj) { - // Grab the desired reference type so that if we end up rejecting - // `py_obj` it still gets decremented if necessary. + // Grab the desired reference type so that if we end up rejecting `py_obj` it + // still gets decremented if necessary. PythonObject result(type, py_obj); if (!PythonFile::Check(py_obj)) { diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonExceptionState.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/PythonExceptionState.cpp index 4d956d5dbe1..d28a8033820 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonExceptionState.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonExceptionState.cpp @@ -30,9 +30,9 @@ PythonExceptionState::~PythonExceptionState() { } void PythonExceptionState::Acquire(bool restore_on_exit) { - // If a state is already acquired, the user needs to decide whether they - // want to discard or restore it. Don't allow the potential silent - // loss of a valid state. + // If a state is already acquired, the user needs to decide whether they want + // to discard or restore it. Don't allow the potential silent loss of a + // valid state. assert(!IsError()); if (!HasErrorOccurred()) @@ -45,8 +45,7 @@ void PythonExceptionState::Acquire(bool restore_on_exit) { // PyErr_Fetch clears the error flag. assert(!HasErrorOccurred()); - // Ownership of the objects returned by `PyErr_Fetch` is transferred - // to us. + // Ownership of the objects returned by `PyErr_Fetch` is transferred to us. m_type.Reset(PyRefType::Owned, py_type); m_value.Reset(PyRefType::Owned, py_value); m_traceback.Reset(PyRefType::Owned, py_traceback); @@ -56,14 +55,14 @@ void PythonExceptionState::Acquire(bool restore_on_exit) { void PythonExceptionState::Restore() { if (m_type.IsValid()) { // The documentation for PyErr_Restore says "Do not pass a null type and - // non-null value or traceback. So only restore if type was non-null - // to begin with. In this case we're passing ownership back to Python - // so release them all. + // non-null value or traceback. So only restore if type was non-null to + // begin with. In this case we're passing ownership back to Python so + // release them all. PyErr_Restore(m_type.release(), m_value.release(), m_traceback.release()); } - // After we restore, we should not hold onto the exception state. Demand that - // it be re-acquired. + // After we restore, we should not hold onto the exception state. Demand + // that it be re-acquired. Discard(); } @@ -100,10 +99,10 @@ std::string PythonExceptionState::Format() const { if (!IsError()) return std::string(); - // It's possible that ReadPythonBacktrace generated another exception. - // If this happens we have to clear the exception, because otherwise - // PyObject_Str() will assert below. That's why we needed to do the - // save / restore at the beginning of this function. + // It's possible that ReadPythonBacktrace generated another exception. If + // this happens we have to clear the exception, because otherwise + // PyObject_Str() will assert below. That's why we needed to do the save / + // restore at the beginning of this function. PythonExceptionState bt_error_state(false); std::string error_string; @@ -114,8 +113,8 @@ std::string PythonExceptionState::Format() const { // If we were able to read the backtrace, just append it. error_stream << backtrace << "\n"; } else { - // Otherwise, append some information about why we were unable to - // obtain the backtrace. + // Otherwise, append some information about why we were unable to obtain + // the backtrace. PythonString bt_error = bt_error_state.GetValue().Str(); error_stream << "An error occurred while retrieving the backtrace: " << bt_error.GetString() << "\n"; diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp index 6c39690268c..5bb6e17c5f4 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -112,13 +112,12 @@ static bool g_initialized = false; namespace { -// Initializing Python is not a straightforward process. We cannot control what -// external code may have done before getting to this point in LLDB, including -// potentially having already initialized Python, so we need to do a lot of work -// to ensure that the existing state of the system is maintained across our -// initialization. We do this by using an RAII pattern where we save off -// initial -// state at the beginning, and restore it at the end +// Initializing Python is not a straightforward process. We cannot control +// what external code may have done before getting to this point in LLDB, +// including potentially having already initialized Python, so we need to do a +// lot of work to ensure that the existing state of the system is maintained +// across our initialization. We do this by using an RAII pattern where we +// save off initial state at the beginning, and restore it at the end struct InitializePythonRAII { public: InitializePythonRAII() @@ -210,12 +209,11 @@ bool ScriptInterpreterPython::Locker::DoAcquireLock() { LLDB_LOGV(log, "Ensured PyGILState. Previous state = {0}locked", m_GILState == PyGILState_UNLOCKED ? "un" : ""); - // we need to save the thread state when we first start the command - // because we might decide to interrupt it while some action is taking - // place outside of Python (e.g. printing to screen, waiting for the network, - // ...) - // in that case, _PyThreadState_Current will be NULL - and we would be unable - // to set the asynchronous exception - not a desirable situation + // we need to save the thread state when we first start the command because + // we might decide to interrupt it while some action is taking place outside + // of Python (e.g. printing to screen, waiting for the network, ...) in that + // case, _PyThreadState_Current will be NULL - and we would be unable to set + // the asynchronous exception - not a desirable situation m_python_interpreter->SetThreadState(PyThreadState_Get()); m_python_interpreter->IncrementLockCount(); return true; @@ -281,17 +279,16 @@ ScriptInterpreterPython::ScriptInterpreterPython( PyRun_SimpleString(run_string.GetData()); // Reloading modules requires a different syntax in Python 2 and Python 3. - // This provides - // a consistent syntax no matter what version of Python. + // This provides a consistent syntax no matter what version of Python. run_string.Clear(); run_string.Printf("run_one_line (%s, 'from six.moves import reload_module')", m_dictionary_name.c_str()); PyRun_SimpleString(run_string.GetData()); // WARNING: temporary code that loads Cocoa formatters - this should be done - // on a per-platform basis rather than loading the whole set - // and letting the individual formatter classes exploit APIs to check whether - // they can/cannot do their task + // on a per-platform basis rather than loading the whole set and letting the + // individual formatter classes exploit APIs to check whether they can/cannot + // do their task run_string.Clear(); run_string.Printf( "run_one_line (%s, 'import lldb.formatters, lldb.formatters.cpp, pydoc')", @@ -314,13 +311,11 @@ ScriptInterpreterPython::ScriptInterpreterPython( } ScriptInterpreterPython::~ScriptInterpreterPython() { - // the session dictionary may hold objects with complex state - // which means that they may need to be torn down with some level of smarts - // and that, in turn, requires a valid thread state - // force Python to procure itself such a thread state, nuke the session - // dictionary - // and then release it for others to use and proceed with the rest of the - // shutdown + // the session dictionary may hold objects with complex state which means + // that they may need to be torn down with some level of smarts and that, in + // turn, requires a valid thread state force Python to procure itself such a + // thread state, nuke the session dictionary and then release it for others + // to use and proceed with the rest of the shutdown auto gil_state = PyGILState_Ensure(); m_session_dict.Reset(); PyGILState_Release(gil_state); @@ -452,16 +447,16 @@ void ScriptInterpreterPython::ResetOutputFileHandle(FILE *fh) {} void ScriptInterpreterPython::SaveTerminalState(int fd) { // Python mucks with the terminal state of STDIN. If we can possibly avoid // this by setting the file handles up correctly prior to entering the - // interpreter we should. For now we save and restore the terminal state - // on the input file handle. + // interpreter we should. For now we save and restore the terminal state on + // the input file handle. m_terminal_state.Save(fd, false); } void ScriptInterpreterPython::RestoreTerminalState() { // Python mucks with the terminal state of STDIN. If we can possibly avoid // this by setting the file handles up correctly prior to entering the - // interpreter we should. For now we save and restore the terminal state - // on the input file handle. + // interpreter we should. For now we save and restore the terminal state on + // the input file handle. m_terminal_state.Restore(); } @@ -470,14 +465,11 @@ void ScriptInterpreterPython::LeaveSession() { if (log) log->PutCString("ScriptInterpreterPython::LeaveSession()"); - // checking that we have a valid thread state - since we use our own threading - // and locking - // in some (rare) cases during cleanup Python may end up believing we have no - // thread state - // and PyImport_AddModule will crash if that is the case - since that seems to - // only happen - // when destroying the SBDebugger, we can make do without clearing up stdout - // and stderr + // checking that we have a valid thread state - since we use our own + // threading and locking in some (rare) cases during cleanup Python may end + // up believing we have no thread state and PyImport_AddModule will crash if + // that is the case - since that seems to only happen when destroying the + // SBDebugger, we can make do without clearing up stdout and stderr // rdar://problem/11292882 // When the current thread state is NULL, PyThreadState_Get() issues a fatal @@ -526,8 +518,7 @@ bool ScriptInterpreterPython::SetStdHandle(File &file, const char *py_name, bool ScriptInterpreterPython::EnterSession(uint16_t on_entry_flags, FILE *in, FILE *out, FILE *err) { // If we have already entered the session, without having officially 'left' - // it, then there is no need to - // 'enter' it again. + // it, then there is no need to 'enter' it again. Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SCRIPT)); if (m_session_is_active) { if (log) @@ -560,8 +551,8 @@ bool ScriptInterpreterPython::EnterSession(uint16_t on_entry_flags, FILE *in, run_string.PutCString("; lldb.frame = lldb.thread.GetSelectedFrame ()"); run_string.PutCString("')"); } else { - // If we aren't initing the globals, we should still always set the debugger - // (since that is always unique.) + // If we aren't initing the globals, we should still always set the + // debugger (since that is always unique.) run_string.Printf("run_one_line (%s, 'lldb.debugger_unique_id = %" PRIu64, m_dictionary_name.c_str(), GetCommandInterpreter().GetDebugger().GetID()); @@ -702,12 +693,11 @@ bool ScriptInterpreterPython::ExecuteOneLine( if (command && command[0]) { // We want to call run_one_line, passing in the dictionary and the command - // string. We cannot do this through - // PyRun_SimpleString here because the command string may contain escaped - // characters, and putting it inside + // string. We cannot do this through PyRun_SimpleString here because the + // command string may contain escaped characters, and putting it inside // another string to pass to PyRun_SimpleString messes up the escaping. So - // we use the following more complicated - // method to pass the command string directly down to Python. + // we use the following more complicated method to pass the command string + // directly down to Python. Debugger &debugger = m_interpreter.GetDebugger(); StreamFileSP input_file_sp; @@ -773,17 +763,14 @@ bool ScriptInterpreterPython::ExecuteOneLine( FILE *err_file = error_file_sp->GetFile().GetStream(); bool success = false; { - // WARNING! It's imperative that this RAII scope be as tight as possible. - // In particular, the - // scope must end *before* we try to join the read thread. The reason for - // this is that a - // pre-requisite for joining the read thread is that we close the write - // handle (to break the - // pipe and cause it to wake up and exit). But acquiring the GIL as below - // will redirect Python's - // stdio to use this same handle. If we close the handle while Python is - // still using it, bad - // things will happen. + // WARNING! It's imperative that this RAII scope be as tight as + // possible. In particular, the scope must end *before* we try to join + // the read thread. The reason for this is that a pre-requisite for + // joining the read thread is that we close the write handle (to break + // the pipe and cause it to wake up and exit). But acquiring the GIL as + // below will redirect Python's stdio to use this same handle. If we + // close the handle while Python is still using it, bad things will + // happen. Locker locker( this, ScriptInterpreterPython::Locker::AcquireLock | @@ -827,12 +814,12 @@ bool ScriptInterpreterPython::ExecuteOneLine( } if (join_read_thread) { - // Close the write end of the pipe since we are done with our - // one line script. This should cause the read thread that - // output_comm is using to exit + // Close the write end of the pipe since we are done with our one line + // script. This should cause the read thread that output_comm is using to + // exit output_file_sp->GetFile().Close(); - // The close above should cause this thread to exit when it gets - // to the end of file, so let it get all its data + // The close above should cause this thread to exit when it gets to the + // end of file, so let it get all its data output_comm.JoinReadThread(); // Now we can close the read end of the pipe output_comm.Disconnect(); @@ -889,21 +876,18 @@ public: ScriptInterpreterPython::Locker::FreeAcquiredLock | ScriptInterpreterPython::Locker::TearDownSession); - // The following call drops into the embedded interpreter loop and stays - // there until the - // user chooses to exit from the Python interpreter. - // This embedded interpreter will, as any Python code that performs I/O, - // unlock the GIL before - // a system call that can hang, and lock it when the syscall has - // returned. + // The following call drops into the embedded interpreter loop and + // stays there until the user chooses to exit from the Python + // interpreter. This embedded interpreter will, as any Python code that + // performs I/O, unlock the GIL before a system call that can hang, and + // lock it when the syscall has returned. // We need to surround the call to the embedded interpreter with calls - // to PyGILState_Ensure and - // PyGILState_Release (using the Locker above). This is because Python - // has a global lock which must be held whenever we want - // to touch any Python objects. Otherwise, if the user calls Python - // code, the interpreter state will be off, - // and things could hang (it's happened before). + // to PyGILState_Ensure and PyGILState_Release (using the Locker + // above). This is because Python has a global lock which must be held + // whenever we want to touch any Python objects. Otherwise, if the user + // calls Python code, the interpreter state will be off, and things + // could hang (it's happened before). StreamString run_string; run_string.Printf("run_python_interpreter (%s)", @@ -934,12 +918,10 @@ void ScriptInterpreterPython::ExecuteInterpreterLoop() { Debugger &debugger = GetCommandInterpreter().GetDebugger(); // At the moment, the only time the debugger does not have an input file - // handle is when this is called - // directly from Python, in which case it is both dangerous and unnecessary - // (not to mention confusing) to - // try to embed a running interpreter loop inside the already running Python - // interpreter loop, so we won't - // do it. + // handle is when this is called directly from Python, in which case it is + // both dangerous and unnecessary (not to mention confusing) to try to embed + // a running interpreter loop inside the already running Python interpreter + // loop, so we won't do it. if (!debugger.GetInputFile()->GetFile().IsValid()) return; @@ -1174,10 +1156,8 @@ Status ScriptInterpreterPython::ExecuteMultipleLines( if (code_object.IsValid()) { // In Python 2.x, PyEval_EvalCode takes a PyCodeObject, but in Python 3.x, it -// takes -// a PyObject. They are convertible (hence the function -// PyCode_Check(PyObject*), so -// we have to do the cast for Python 2.x +// takes a PyObject. They are convertible (hence the function +// PyCode_Check(PyObject*), so we have to do the cast for Python 2.x #if PY_MAJOR_VERSION >= 3 PyObject *py_code_obj = code_object.get(); #else @@ -1243,10 +1223,9 @@ Status ScriptInterpreterPython::SetBreakpointCommandCallback( auto data_ap = llvm::make_unique<CommandDataPython>(); // Split the command_body_text into lines, and pass that to - // GenerateBreakpointCommandCallbackData. That will - // wrap the body in an auto-generated function, and return the function name - // in script_source. That is what - // the callback will actually invoke. + // GenerateBreakpointCommandCallbackData. That will wrap the body in an + // auto-generated function, and return the function name in script_source. + // That is what the callback will actually invoke. data_ap->user_source.SplitIntoLines(command_body_text); Status error = GenerateBreakpointCommandCallbackData(data_ap->user_source, @@ -1268,9 +1247,8 @@ void ScriptInterpreterPython::SetWatchpointCommandCallback( // It's necessary to set both user_source and script_source to the oneliner. // The former is used to generate callback description (as in watchpoint - // command list) - // while the latter is used for Python to interpret during the actual - // callback. + // command list) while the latter is used for Python to interpret during the + // actual callback. data_ap->user_source.AppendString(oneliner); data_ap->script_source.assign(oneliner); @@ -1365,8 +1343,7 @@ bool ScriptInterpreterPython::GenerateTypeScriptFunction( return false; // Take what the user wrote, wrap it all up inside one big auto-generated - // Python function, passing in the - // ValueObject as parameter to the function. + // Python function, passing in the ValueObject as parameter to the function. std::string auto_generated_function_name( GenerateUniqueName("lldb_autogen_python_type_print_func", @@ -1430,8 +1407,8 @@ bool ScriptInterpreterPython::GenerateTypeSynthClass(StringList &user_input, sstr.Printf("class %s:", auto_generated_class_name.c_str()); auto_generated_class.AppendString(sstr.GetString()); - // Wrap everything up inside the class, increasing the indentation. - // we don't need to play any fancy indentation tricks here because there is no + // Wrap everything up inside the class, increasing the indentation. we don't + // need to play any fancy indentation tricks here because there is no // surrounding code whose indentation we need to honor for (int i = 0; i < num_lines; ++i) { sstr.Clear(); @@ -1439,9 +1416,8 @@ bool ScriptInterpreterPython::GenerateTypeSynthClass(StringList &user_input, auto_generated_class.AppendString(sstr.GetString()); } - // Verify that the results are valid Python. - // (even though the method is ExportFunctionDefinitionToInterpreter, a class - // will actually be exported) + // Verify that the results are valid Python. (even though the method is + // ExportFunctionDefinitionToInterpreter, a class will actually be exported) // (TODO: rename that method to ExportDefinitionToInterpreter) if (!ExportFunctionDefinitionToInterpreter(auto_generated_class).Success()) return false; @@ -1585,8 +1561,8 @@ StructuredData::ArraySP ScriptInterpreterPython::OSPlugin_ThreadsInfo( // GetPythonValueFormatString provides a system independent type safe way to // convert a variable's type into a python value format. Python value formats -// are defined in terms of builtin C types and could change from system to -// as the underlying typedef for uint* types, size_t, off_t and other values +// are defined in terms of builtin C types and could change from system to as +// the underlying typedef for uint* types, size_t, off_t and other values // change. template <typename T> const char *GetPythonValueFormatString(T t); @@ -2044,8 +2020,7 @@ void ScriptInterpreterPython::Clear() { ScriptInterpreterPython::Locker::FreeAcquiredLock); // This may be called as part of Py_Finalize. In that case the modules are - // destroyed in random - // order and we can't guarantee that we can access these. + // destroyed in random order and we can't guarantee that we can access these. if (Py_IsInitialized()) PyRun_SimpleString("lldb.debugger = None; lldb.target = None; lldb.process " "= None; lldb.thread = None; lldb.frame = None"); @@ -2629,9 +2604,8 @@ bool ScriptInterpreterPython::LoadScriptingModule( command_stream.Clear(); command_stream.Printf("sys.modules.__contains__('%s')", basename.c_str()); bool does_contain = false; - // this call will succeed if the module was ever imported in any Debugger in - // the lifetime of the process - // in which this LLDB framework is living + // this call will succeed if the module was ever imported in any Debugger + // in the lifetime of the process in which this LLDB framework is living bool was_imported_globally = (ExecuteOneLineWithReturn( command_stream.GetData(), @@ -2705,8 +2679,8 @@ bool ScriptInterpreterPython::IsReservedWord(const char *word) { llvm::StringRef word_sr(word); - // filter out a few characters that would just confuse us - // and that are clearly not keyword material anyway + // filter out a few characters that would just confuse us and that are + // clearly not keyword material anyway if (word_sr.find_first_of("'\"") != llvm::StringRef::npos) return false; @@ -2834,9 +2808,9 @@ bool ScriptInterpreterPython::RunScriptBasedCommand( return ret_val; } -// 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 +// 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 bool ScriptInterpreterPython::GetDocumentationForItem(const char *item, std::string &dest) { dest.clear(); @@ -3106,10 +3080,9 @@ void ScriptInterpreterPython::InitializePrivate() { Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION); // RAII-based initialization which correctly handles multiple-initialization, - // version- - // specific differences among Python 2 and Python 3, and saving and restoring - // various - // other pieces of state that can get mucked with during initialization. + // version- specific differences among Python 2 and Python 3, and saving and + // restoring various other pieces of state that can get mucked with during + // initialization. InitializePythonRAII initialize_guard; if (g_swig_init_callback) @@ -3123,12 +3096,9 @@ void ScriptInterpreterPython::InitializePrivate() { FileSpec file_spec; // Don't denormalize paths when calling file_spec.GetPath(). On platforms - // that use - // a backslash as the path separator, this will result in executing python - // code containing - // paths with unescaped backslashes. But Python also accepts forward slashes, - // so to make - // life easier we just use that. + // that use a backslash as the path separator, this will result in executing + // python code containing paths with unescaped backslashes. But Python also + // accepts forward slashes, so to make life easier we just use that. if (HostInfo::GetLLDBPath(ePathTypePythonDir, file_spec)) AddToSysPath(AddLocation::Beginning, file_spec.GetPath(false)); if (HostInfo::GetLLDBPath(ePathTypeLLDBShlibDir, file_spec)) |