One small step in my long running quest to improve python exception handling in
LLDB. Replace GetInteger() which just returns an int with As<long long> and
friends, which return Expected types that can track python exceptions
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp | ||
---|---|---|
55 | obj->AsUnsignedLongLong() ? | |
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp | ||
3153–3159 | This converts the Expected into a python exception, only to clear (and print) it at the next line. Is there a more direct way of doing it? | |
lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp | ||
126–132 | EXPECT_THAT_EXPECTED(As<long long>(major_version_field), llvm::HasValue(PY_MAJOR_VERSION)) (and similarly in other tests too) |
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp | ||
---|---|---|
3153–3159 | I don't know, what did you have in mind? It could just call the Python C API directly and not bother converting it into an Expected, but would that be better? |
Looks good. I'll leave it up to you to consider whether the PySys_WriteStderr thingy is a good idea.
lldb/bindings/python/python-typemaps.swig | ||
---|---|---|
72 | it looks like this line needs wrapping | |
lldb/bindings/python/python-wrapper.swig | ||
585–597 | If you don't print this, then you could definitely do something like: Expected<long long> result = As<long long>(pfunc.Call(PythonString(child_name)); if (result) return std::max<long long>(*result, 0); consumeError(result.takeError()); return UINT32_MAX; | |
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp | ||
3153–3159 | I was thinking if theres some function to print to stderr directly without doing the PyErr dance. PySys_WriteStderr maybe? if (Expected<long long> py_return = As<long long>(implementor.CallMethod(callee_name))) result = *py_return; else PySys_WriteStderr("%s", toString(py_return.takeError()).c_str()); ? |
wrap long line
lldb/bindings/python/python-wrapper.swig | ||
---|---|---|
585–597 | aparently this function is not even used... I'll put up a new diff to remove it |
This causes multiple test failures on LLDB AArch64 Linux buildbot.
http://lab.llvm.org:8011/builders/lldb-aarch64-ubuntu/builds/3695
@omjavaid sorry I didn't catch that on pre-submit testing. PyLong_AsLongLong and friends do not automatically convert on python2 like they do on python3. It's fixed now.
it looks like this line needs wrapping