Cython 3.2.0__cp39-abi3-win32.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- Cython/Build/BuildExecutable.py +169 -0
- Cython/Build/Cache.py +199 -0
- Cython/Build/Cythonize.py +350 -0
- Cython/Build/Dependencies.py +1314 -0
- Cython/Build/Distutils.py +1 -0
- Cython/Build/Inline.py +463 -0
- Cython/Build/IpythonMagic.py +560 -0
- Cython/Build/SharedModule.py +94 -0
- Cython/Build/Tests/TestCyCache.py +194 -0
- Cython/Build/Tests/TestCythonizeArgsParser.py +481 -0
- Cython/Build/Tests/TestDependencies.py +133 -0
- Cython/Build/Tests/TestInline.py +177 -0
- Cython/Build/Tests/TestIpythonMagic.py +287 -0
- Cython/Build/Tests/TestRecythonize.py +212 -0
- Cython/Build/Tests/TestStripLiterals.py +155 -0
- Cython/Build/Tests/__init__.py +1 -0
- Cython/Build/__init__.py +11 -0
- Cython/CodeWriter.py +815 -0
- Cython/Compiler/AnalysedTreeTransforms.py +97 -0
- Cython/Compiler/Annotate.py +328 -0
- Cython/Compiler/AutoDocTransforms.py +320 -0
- Cython/Compiler/Buffer.py +680 -0
- Cython/Compiler/Builtin.py +984 -0
- Cython/Compiler/CmdLine.py +263 -0
- Cython/Compiler/Code.pxd +149 -0
- Cython/Compiler/Code.py +3746 -0
- Cython/Compiler/Code.pyd +0 -0
- Cython/Compiler/CodeGeneration.py +33 -0
- Cython/Compiler/CythonScope.py +191 -0
- Cython/Compiler/Dataclass.py +864 -0
- Cython/Compiler/DebugFlags.py +24 -0
- Cython/Compiler/Errors.py +297 -0
- Cython/Compiler/ExprNodes.py +15562 -0
- Cython/Compiler/FlowControl.pxd +97 -0
- Cython/Compiler/FlowControl.py +1451 -0
- Cython/Compiler/FlowControl.pyd +0 -0
- Cython/Compiler/FusedNode.py +971 -0
- Cython/Compiler/FusedNode.pyd +0 -0
- Cython/Compiler/Future.py +16 -0
- Cython/Compiler/Interpreter.py +57 -0
- Cython/Compiler/Lexicon.py +421 -0
- Cython/Compiler/LineTable.py +114 -0
- Cython/Compiler/LineTable.pyd +0 -0
- Cython/Compiler/Main.py +857 -0
- Cython/Compiler/MatchCaseNodes.py +259 -0
- Cython/Compiler/MemoryView.py +905 -0
- Cython/Compiler/ModuleNode.py +4235 -0
- Cython/Compiler/Naming.py +363 -0
- Cython/Compiler/Nodes.py +10831 -0
- Cython/Compiler/Optimize.py +5288 -0
- Cython/Compiler/Options.py +843 -0
- Cython/Compiler/ParseTreeTransforms.pxd +78 -0
- Cython/Compiler/ParseTreeTransforms.py +4638 -0
- Cython/Compiler/Parsing.pxd +9 -0
- Cython/Compiler/Parsing.py +4775 -0
- Cython/Compiler/Parsing.pyd +0 -0
- Cython/Compiler/Pipeline.py +439 -0
- Cython/Compiler/PyrexTypes.py +5870 -0
- Cython/Compiler/Pythran.py +232 -0
- Cython/Compiler/Scanning.pxd +48 -0
- Cython/Compiler/Scanning.py +701 -0
- Cython/Compiler/Scanning.pyd +0 -0
- Cython/Compiler/StringEncoding.py +298 -0
- Cython/Compiler/Symtab.py +3073 -0
- Cython/Compiler/Tests/TestBuffer.py +105 -0
- Cython/Compiler/Tests/TestBuiltin.py +72 -0
- Cython/Compiler/Tests/TestCmdLine.py +586 -0
- Cython/Compiler/Tests/TestCode.py +144 -0
- Cython/Compiler/Tests/TestFlowControl.py +65 -0
- Cython/Compiler/Tests/TestGrammar.py +202 -0
- Cython/Compiler/Tests/TestMemView.py +71 -0
- Cython/Compiler/Tests/TestParseTreeTransforms.py +285 -0
- Cython/Compiler/Tests/TestScanning.py +134 -0
- Cython/Compiler/Tests/TestSignatureMatching.py +73 -0
- Cython/Compiler/Tests/TestStringEncoding.py +21 -0
- Cython/Compiler/Tests/TestTreeFragment.py +63 -0
- Cython/Compiler/Tests/TestTreePath.py +103 -0
- Cython/Compiler/Tests/TestTypes.py +75 -0
- Cython/Compiler/Tests/TestUtilityLoad.py +112 -0
- Cython/Compiler/Tests/TestVisitor.py +61 -0
- Cython/Compiler/Tests/Utils.py +36 -0
- Cython/Compiler/Tests/__init__.py +1 -0
- Cython/Compiler/TreeFragment.py +278 -0
- Cython/Compiler/TreePath.py +303 -0
- Cython/Compiler/TypeInference.py +591 -0
- Cython/Compiler/TypeSlots.py +1174 -0
- Cython/Compiler/UFuncs.py +311 -0
- Cython/Compiler/UtilNodes.py +389 -0
- Cython/Compiler/UtilityCode.py +344 -0
- Cython/Compiler/Version.py +8 -0
- Cython/Compiler/Visitor.pxd +53 -0
- Cython/Compiler/Visitor.py +861 -0
- Cython/Compiler/Visitor.pyd +0 -0
- Cython/Compiler/__init__.py +1 -0
- Cython/Coverage.py +448 -0
- Cython/Debugger/Cygdb.py +177 -0
- Cython/Debugger/DebugWriter.py +82 -0
- Cython/Debugger/Tests/TestLibCython.py +275 -0
- Cython/Debugger/Tests/__init__.py +1 -0
- Cython/Debugger/Tests/cfuncs.c +8 -0
- Cython/Debugger/Tests/codefile +49 -0
- Cython/Debugger/Tests/test_libcython_in_gdb.py +578 -0
- Cython/Debugger/Tests/test_libpython_in_gdb.py +90 -0
- Cython/Debugger/__init__.py +1 -0
- Cython/Debugger/libcython.py +1548 -0
- Cython/Debugger/libpython.py +2821 -0
- Cython/Debugging.py +20 -0
- Cython/Distutils/__init__.py +2 -0
- Cython/Distutils/build_ext.py +139 -0
- Cython/Distutils/extension.py +96 -0
- Cython/Distutils/old_build_ext.py +351 -0
- Cython/Includes/cpython/__init__.pxd +173 -0
- Cython/Includes/cpython/array.pxd +178 -0
- Cython/Includes/cpython/bool.pxd +37 -0
- Cython/Includes/cpython/buffer.pxd +112 -0
- Cython/Includes/cpython/bytearray.pxd +33 -0
- Cython/Includes/cpython/bytes.pxd +200 -0
- Cython/Includes/cpython/cellobject.pxd +35 -0
- Cython/Includes/cpython/ceval.pxd +8 -0
- Cython/Includes/cpython/codecs.pxd +121 -0
- Cython/Includes/cpython/complex.pxd +60 -0
- Cython/Includes/cpython/contextvars.pxd +145 -0
- Cython/Includes/cpython/conversion.pxd +36 -0
- Cython/Includes/cpython/datetime.pxd +395 -0
- Cython/Includes/cpython/descr.pxd +26 -0
- Cython/Includes/cpython/dict.pxd +187 -0
- Cython/Includes/cpython/exc.pxd +263 -0
- Cython/Includes/cpython/fileobject.pxd +57 -0
- Cython/Includes/cpython/float.pxd +47 -0
- Cython/Includes/cpython/function.pxd +65 -0
- Cython/Includes/cpython/genobject.pxd +25 -0
- Cython/Includes/cpython/getargs.pxd +12 -0
- Cython/Includes/cpython/instance.pxd +25 -0
- Cython/Includes/cpython/iterator.pxd +36 -0
- Cython/Includes/cpython/iterobject.pxd +24 -0
- Cython/Includes/cpython/list.pxd +92 -0
- Cython/Includes/cpython/long.pxd +149 -0
- Cython/Includes/cpython/longintrepr.pxd +14 -0
- Cython/Includes/cpython/mapping.pxd +63 -0
- Cython/Includes/cpython/marshal.pxd +66 -0
- Cython/Includes/cpython/mem.pxd +120 -0
- Cython/Includes/cpython/memoryview.pxd +50 -0
- Cython/Includes/cpython/method.pxd +49 -0
- Cython/Includes/cpython/module.pxd +208 -0
- Cython/Includes/cpython/number.pxd +258 -0
- Cython/Includes/cpython/object.pxd +433 -0
- Cython/Includes/cpython/pycapsule.pxd +143 -0
- Cython/Includes/cpython/pylifecycle.pxd +68 -0
- Cython/Includes/cpython/pyport.pxd +8 -0
- Cython/Includes/cpython/pystate.pxd +95 -0
- Cython/Includes/cpython/pythread.pxd +53 -0
- Cython/Includes/cpython/ref.pxd +141 -0
- Cython/Includes/cpython/sequence.pxd +134 -0
- Cython/Includes/cpython/set.pxd +119 -0
- Cython/Includes/cpython/slice.pxd +70 -0
- Cython/Includes/cpython/time.pxd +129 -0
- Cython/Includes/cpython/tuple.pxd +72 -0
- Cython/Includes/cpython/type.pxd +53 -0
- Cython/Includes/cpython/unicode.pxd +639 -0
- Cython/Includes/cpython/version.pxd +32 -0
- Cython/Includes/cpython/weakref.pxd +78 -0
- Cython/Includes/libc/__init__.pxd +1 -0
- Cython/Includes/libc/complex.pxd +35 -0
- Cython/Includes/libc/errno.pxd +127 -0
- Cython/Includes/libc/float.pxd +43 -0
- Cython/Includes/libc/limits.pxd +28 -0
- Cython/Includes/libc/locale.pxd +46 -0
- Cython/Includes/libc/math.pxd +209 -0
- Cython/Includes/libc/setjmp.pxd +10 -0
- Cython/Includes/libc/signal.pxd +64 -0
- Cython/Includes/libc/stddef.pxd +9 -0
- Cython/Includes/libc/stdint.pxd +105 -0
- Cython/Includes/libc/stdio.pxd +80 -0
- Cython/Includes/libc/stdlib.pxd +72 -0
- Cython/Includes/libc/string.pxd +50 -0
- Cython/Includes/libc/threads.pxd +234 -0
- Cython/Includes/libc/time.pxd +52 -0
- Cython/Includes/libcpp/__init__.pxd +4 -0
- Cython/Includes/libcpp/algorithm.pxd +320 -0
- Cython/Includes/libcpp/any.pxd +16 -0
- Cython/Includes/libcpp/atomic.pxd +59 -0
- Cython/Includes/libcpp/barrier.pxd +22 -0
- Cython/Includes/libcpp/bit.pxd +29 -0
- Cython/Includes/libcpp/cast.pxd +12 -0
- Cython/Includes/libcpp/cmath.pxd +518 -0
- Cython/Includes/libcpp/complex.pxd +106 -0
- Cython/Includes/libcpp/condition_variable.pxd +322 -0
- Cython/Includes/libcpp/deque.pxd +165 -0
- Cython/Includes/libcpp/exception.pxd +86 -0
- Cython/Includes/libcpp/execution.pxd +15 -0
- Cython/Includes/libcpp/forward_list.pxd +63 -0
- Cython/Includes/libcpp/functional.pxd +26 -0
- Cython/Includes/libcpp/future.pxd +103 -0
- Cython/Includes/libcpp/iterator.pxd +34 -0
- Cython/Includes/libcpp/latch.pxd +17 -0
- Cython/Includes/libcpp/limits.pxd +61 -0
- Cython/Includes/libcpp/list.pxd +117 -0
- Cython/Includes/libcpp/map.pxd +252 -0
- Cython/Includes/libcpp/memory.pxd +115 -0
- Cython/Includes/libcpp/mutex.pxd +387 -0
- Cython/Includes/libcpp/numbers.pxd +15 -0
- Cython/Includes/libcpp/numeric.pxd +131 -0
- Cython/Includes/libcpp/optional.pxd +34 -0
- Cython/Includes/libcpp/pair.pxd +1 -0
- Cython/Includes/libcpp/queue.pxd +25 -0
- Cython/Includes/libcpp/random.pxd +166 -0
- Cython/Includes/libcpp/semaphore.pxd +43 -0
- Cython/Includes/libcpp/set.pxd +228 -0
- Cython/Includes/libcpp/shared_mutex.pxd +96 -0
- Cython/Includes/libcpp/span.pxd +87 -0
- Cython/Includes/libcpp/stack.pxd +11 -0
- Cython/Includes/libcpp/stop_token.pxd +117 -0
- Cython/Includes/libcpp/string.pxd +355 -0
- Cython/Includes/libcpp/string_view.pxd +183 -0
- Cython/Includes/libcpp/typeindex.pxd +15 -0
- Cython/Includes/libcpp/typeinfo.pxd +10 -0
- Cython/Includes/libcpp/unordered_map.pxd +193 -0
- Cython/Includes/libcpp/unordered_set.pxd +152 -0
- Cython/Includes/libcpp/utility.pxd +30 -0
- Cython/Includes/libcpp/vector.pxd +186 -0
- Cython/Includes/numpy/math.pxd +150 -0
- Cython/Includes/openmp.pxd +50 -0
- Cython/Includes/posix/__init__.pxd +1 -0
- Cython/Includes/posix/dlfcn.pxd +14 -0
- Cython/Includes/posix/fcntl.pxd +86 -0
- Cython/Includes/posix/ioctl.pxd +4 -0
- Cython/Includes/posix/mman.pxd +101 -0
- Cython/Includes/posix/resource.pxd +57 -0
- Cython/Includes/posix/select.pxd +21 -0
- Cython/Includes/posix/signal.pxd +73 -0
- Cython/Includes/posix/stat.pxd +98 -0
- Cython/Includes/posix/stdio.pxd +37 -0
- Cython/Includes/posix/stdlib.pxd +29 -0
- Cython/Includes/posix/strings.pxd +9 -0
- Cython/Includes/posix/time.pxd +71 -0
- Cython/Includes/posix/types.pxd +30 -0
- Cython/Includes/posix/uio.pxd +26 -0
- Cython/Includes/posix/unistd.pxd +271 -0
- Cython/Includes/posix/wait.pxd +38 -0
- Cython/Plex/Actions.pxd +24 -0
- Cython/Plex/Actions.py +119 -0
- Cython/Plex/Actions.pyd +0 -0
- Cython/Plex/DFA.pxd +14 -0
- Cython/Plex/DFA.py +164 -0
- Cython/Plex/DFA.pyd +0 -0
- Cython/Plex/Errors.py +48 -0
- Cython/Plex/Lexicons.py +178 -0
- Cython/Plex/Machines.pxd +36 -0
- Cython/Plex/Machines.py +238 -0
- Cython/Plex/Machines.pyd +0 -0
- Cython/Plex/Regexps.py +535 -0
- Cython/Plex/Scanners.pxd +45 -0
- Cython/Plex/Scanners.py +328 -0
- Cython/Plex/Scanners.pyd +0 -0
- Cython/Plex/Transitions.pxd +14 -0
- Cython/Plex/Transitions.py +239 -0
- Cython/Plex/Transitions.pyd +0 -0
- Cython/Plex/__init__.py +34 -0
- Cython/Runtime/__init__.py +1 -0
- Cython/Runtime/refnanny.pyd +0 -0
- Cython/Runtime/refnanny.pyx +237 -0
- Cython/Shadow.py +690 -0
- Cython/Shadow.pyi +521 -0
- Cython/StringIOTree.py +170 -0
- Cython/StringIOTree.pyd +0 -0
- Cython/Tempita/__init__.py +4 -0
- Cython/Tempita/_looper.py +154 -0
- Cython/Tempita/_tempita.py +1091 -0
- Cython/Tempita/_tempita.pyd +0 -0
- Cython/TestUtils.py +422 -0
- Cython/Tests/TestCodeWriter.py +128 -0
- Cython/Tests/TestCythonUtils.py +202 -0
- Cython/Tests/TestJediTyper.py +223 -0
- Cython/Tests/TestShadow.py +114 -0
- Cython/Tests/TestStringIOTree.py +67 -0
- Cython/Tests/TestTestUtils.py +90 -0
- Cython/Tests/__init__.py +1 -0
- Cython/Tests/xmlrunner.py +390 -0
- Cython/Utility/AsyncGen.c +1031 -0
- Cython/Utility/Buffer.c +865 -0
- Cython/Utility/BufferFormatFromTypeInfo.pxd +2 -0
- Cython/Utility/Builtins.c +810 -0
- Cython/Utility/CConvert.pyx +134 -0
- Cython/Utility/CMath.c +104 -0
- Cython/Utility/CommonStructures.c +226 -0
- Cython/Utility/Complex.c +378 -0
- Cython/Utility/Coroutine.c +2300 -0
- Cython/Utility/CpdefEnums.pyx +103 -0
- Cython/Utility/CppConvert.pyx +282 -0
- Cython/Utility/CppSupport.cpp +151 -0
- Cython/Utility/CythonFunction.c +1832 -0
- Cython/Utility/Dataclasses.c +101 -0
- Cython/Utility/Embed.c +121 -0
- Cython/Utility/Exceptions.c +1016 -0
- Cython/Utility/ExtensionTypes.c +996 -0
- Cython/Utility/FunctionArguments.c +1043 -0
- Cython/Utility/FusedFunction.pyx +44 -0
- Cython/Utility/ImportExport.c +907 -0
- Cython/Utility/MemoryView.pxd +188 -0
- Cython/Utility/MemoryView.pyx +1482 -0
- Cython/Utility/MemoryView_C.c +927 -0
- Cython/Utility/ModuleSetupCode.c +3203 -0
- Cython/Utility/NumpyImportArray.c +46 -0
- Cython/Utility/ObjectHandling.c +3273 -0
- Cython/Utility/Optimize.c +1603 -0
- Cython/Utility/Overflow.c +384 -0
- Cython/Utility/Printing.c +86 -0
- Cython/Utility/Profile.c +732 -0
- Cython/Utility/StringTools.c +1379 -0
- Cython/Utility/Synchronization.c +399 -0
- Cython/Utility/TString.c +356 -0
- Cython/Utility/TestCyUtilityLoader.pyx +8 -0
- Cython/Utility/TestCythonScope.pyx +75 -0
- Cython/Utility/TestUtilityLoader.c +12 -0
- Cython/Utility/TypeConversion.c +1385 -0
- Cython/Utility/UFuncs.pyx +50 -0
- Cython/Utility/UFuncs_C.c +89 -0
- Cython/Utility/__init__.py +28 -0
- Cython/Utility/arrayarray.h +167 -0
- Cython/Utils.py +687 -0
- Cython/Utils.pyd +0 -0
- Cython/__init__.py +10 -0
- Cython/__init__.pyi +7 -0
- Cython/py.typed +0 -0
- cython-3.2.0.dist-info/METADATA +85 -0
- cython-3.2.0.dist-info/RECORD +333 -0
- cython-3.2.0.dist-info/WHEEL +5 -0
- cython-3.2.0.dist-info/entry_points.txt +4 -0
- cython-3.2.0.dist-info/top_level.txt +3 -0
- cython.py +29 -0
- pyximport/__init__.py +4 -0
- pyximport/pyxbuild.py +160 -0
- pyximport/pyximport.py +482 -0
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# empty file
|
Cython/Coverage.py
ADDED
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
"""
|
|
2
|
+
A Cython plugin for coverage.py
|
|
3
|
+
|
|
4
|
+
Requires the coverage package at least in version 4.0 (which added the plugin API).
|
|
5
|
+
|
|
6
|
+
This plugin requires the generated C sources to be available, next to the extension module.
|
|
7
|
+
It parses the C file and reads the original source files from it, which are stored in C comments.
|
|
8
|
+
It then reports a source file to coverage.py when it hits one of its lines during line tracing.
|
|
9
|
+
|
|
10
|
+
Basically, Cython can (on request) emit explicit trace calls into the C code that it generates,
|
|
11
|
+
and as a general human debugging helper, it always copies the current source code line
|
|
12
|
+
(and its surrounding context) into the C files before it generates code for that line, e.g.
|
|
13
|
+
|
|
14
|
+
::
|
|
15
|
+
|
|
16
|
+
/* "line_trace.pyx":147
|
|
17
|
+
* def cy_add_with_nogil(a,b):
|
|
18
|
+
* cdef int z, x=a, y=b # 1
|
|
19
|
+
* with nogil: # 2 # <<<<<<<<<<<<<<
|
|
20
|
+
* z = 0 # 3
|
|
21
|
+
* z += cy_add_nogil(x, y) # 4
|
|
22
|
+
*/
|
|
23
|
+
__Pyx_TraceLine(147,6,1,__PYX_ERR(0, 147, __pyx_L4_error))
|
|
24
|
+
[C code generated for file line_trace.pyx, line 147, follows here]
|
|
25
|
+
|
|
26
|
+
The crux is that multiple source files can contribute code to a single C (or C++) file
|
|
27
|
+
(and thus, to a single extension module) besides the main module source file (.py/.pyx),
|
|
28
|
+
usually shared declaration files (.pxd) but also literally included files (.pxi).
|
|
29
|
+
|
|
30
|
+
Therefore, the coverage plugin doesn't actually try to look at the file that happened
|
|
31
|
+
to contribute the current source line for the trace call, but simply looks up the single
|
|
32
|
+
.c file from which the extension was compiled (which usually lies right next to it after
|
|
33
|
+
the build, having the same name), and parses the code copy comments from that .c file
|
|
34
|
+
to recover the original source files and their code as a line-to-file mapping.
|
|
35
|
+
|
|
36
|
+
That mapping is then used to report the ``__Pyx_TraceLine()`` calls to the coverage tool.
|
|
37
|
+
The plugin also reports the line of source code that it found in the C file to the coverage
|
|
38
|
+
tool to support annotated source representations. For this, again, it does not look at the
|
|
39
|
+
actual source files but only reports the source code that it found in the C code comments.
|
|
40
|
+
|
|
41
|
+
Apart from simplicity (read one file instead of finding and parsing many), part of the
|
|
42
|
+
reasoning here is that any line in the original sources for which there is no comment line
|
|
43
|
+
(and trace call) in the generated C code cannot count as executed, really, so the C code
|
|
44
|
+
comments are a very good source for coverage reporting. They already filter out purely
|
|
45
|
+
declarative code lines that do not contribute executable code, and such (missing) lines
|
|
46
|
+
can then be marked as excluded from coverage analysis.
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
import re
|
|
51
|
+
import os.path
|
|
52
|
+
import sys
|
|
53
|
+
from collections import defaultdict
|
|
54
|
+
|
|
55
|
+
from coverage.plugin import CoveragePlugin, FileTracer, FileReporter # requires coverage.py 4.0+
|
|
56
|
+
from coverage.files import canonical_filename
|
|
57
|
+
try:
|
|
58
|
+
import coverage.tracer # we mainly do this so that runtests can identify if coverage won't work
|
|
59
|
+
except ImportError:
|
|
60
|
+
raise ImportError("Installed 'coverage' does not support plugins. "
|
|
61
|
+
"See https://coverage.readthedocs.io/en/latest/install.html#c-extension")
|
|
62
|
+
|
|
63
|
+
from .Utils import find_root_package_dir, is_package_dir, is_cython_generated_file, open_source_file
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
from . import __version__
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
C_FILE_EXTENSIONS = ['.c', '.cpp', '.cc', '.cxx']
|
|
70
|
+
MODULE_FILE_EXTENSIONS = set(['.py', '.pyx', '.pxd'] + C_FILE_EXTENSIONS)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _find_c_source(base_path):
|
|
74
|
+
file_exists = os.path.exists
|
|
75
|
+
for ext in C_FILE_EXTENSIONS:
|
|
76
|
+
file_name = base_path + ext
|
|
77
|
+
if file_exists(file_name):
|
|
78
|
+
return file_name
|
|
79
|
+
return None
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _find_dep_file_path(main_file, file_path, relative_path_search=False):
|
|
83
|
+
abs_path = os.path.abspath(file_path)
|
|
84
|
+
if not os.path.exists(abs_path) and (file_path.endswith('.pxi') or
|
|
85
|
+
relative_path_search):
|
|
86
|
+
# files are looked up relative to the main source file
|
|
87
|
+
rel_file_path = os.path.join(os.path.dirname(main_file), file_path)
|
|
88
|
+
if os.path.exists(rel_file_path):
|
|
89
|
+
abs_path = os.path.abspath(rel_file_path)
|
|
90
|
+
|
|
91
|
+
abs_no_ext = os.path.splitext(abs_path)[0]
|
|
92
|
+
file_no_ext, extension = os.path.splitext(file_path)
|
|
93
|
+
# We check if the paths match by matching the directories in reverse order.
|
|
94
|
+
# pkg/module.pyx /long/absolute_path/bla/bla/site-packages/pkg/module.c should match.
|
|
95
|
+
# this will match the pairs: module-module and pkg-pkg. After which there is nothing left to zip.
|
|
96
|
+
abs_no_ext = os.path.normpath(abs_no_ext)
|
|
97
|
+
file_no_ext = os.path.normpath(file_no_ext)
|
|
98
|
+
matching_paths = zip(reversed(abs_no_ext.split(os.sep)), reversed(file_no_ext.split(os.sep)))
|
|
99
|
+
for one, other in matching_paths:
|
|
100
|
+
if one != other:
|
|
101
|
+
break
|
|
102
|
+
else: # No mismatches detected
|
|
103
|
+
matching_abs_path = os.path.splitext(main_file)[0] + extension
|
|
104
|
+
if os.path.exists(matching_abs_path):
|
|
105
|
+
return canonical_filename(matching_abs_path)
|
|
106
|
+
|
|
107
|
+
# search sys.path for external locations if a valid file hasn't been found
|
|
108
|
+
if not os.path.exists(abs_path):
|
|
109
|
+
for sys_path in sys.path:
|
|
110
|
+
test_path = os.path.realpath(os.path.join(sys_path, file_path))
|
|
111
|
+
if os.path.exists(test_path):
|
|
112
|
+
return canonical_filename(test_path)
|
|
113
|
+
return canonical_filename(abs_path)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _offset_to_line(offset):
|
|
117
|
+
return offset >> 9
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
class Plugin(CoveragePlugin):
|
|
121
|
+
# map from traced file paths to absolute file paths
|
|
122
|
+
_file_path_map = None
|
|
123
|
+
# map from traced file paths to corresponding C files
|
|
124
|
+
_c_files_map = None
|
|
125
|
+
# map from parsed C files to their content
|
|
126
|
+
_parsed_c_files = None
|
|
127
|
+
# map from traced files to lines that are excluded from coverage
|
|
128
|
+
_excluded_lines_map = None
|
|
129
|
+
# list of regex patterns for lines to exclude
|
|
130
|
+
_excluded_line_patterns = ()
|
|
131
|
+
|
|
132
|
+
def sys_info(self):
|
|
133
|
+
return [('Cython version', __version__)]
|
|
134
|
+
|
|
135
|
+
def configure(self, config):
|
|
136
|
+
# Entry point for coverage "configurer".
|
|
137
|
+
# Read the regular expressions from the coverage config that match lines to be excluded from coverage.
|
|
138
|
+
self._excluded_line_patterns = config.get_option("report:exclude_lines")
|
|
139
|
+
|
|
140
|
+
def file_tracer(self, filename):
|
|
141
|
+
"""
|
|
142
|
+
Try to find a C source file for a file path found by the tracer.
|
|
143
|
+
"""
|
|
144
|
+
if filename.startswith('<') or filename.startswith('memory:'):
|
|
145
|
+
return None
|
|
146
|
+
c_file = py_file = None
|
|
147
|
+
filename = canonical_filename(os.path.abspath(filename))
|
|
148
|
+
if self._c_files_map and filename in self._c_files_map:
|
|
149
|
+
c_file = self._c_files_map[filename][0]
|
|
150
|
+
|
|
151
|
+
if c_file is None:
|
|
152
|
+
c_file, py_file = self._find_source_files(filename)
|
|
153
|
+
if not c_file:
|
|
154
|
+
return None # unknown file
|
|
155
|
+
|
|
156
|
+
# parse all source file paths and lines from C file
|
|
157
|
+
# to learn about all relevant source files right away (pyx/pxi/pxd)
|
|
158
|
+
# FIXME: this might already be too late if the first executed line
|
|
159
|
+
# is not from the main .pyx file but a file with a different
|
|
160
|
+
# name than the .c file (which prevents us from finding the
|
|
161
|
+
# .c file)
|
|
162
|
+
_, code = self._read_source_lines(c_file, filename)
|
|
163
|
+
if code is None:
|
|
164
|
+
return None # no source found
|
|
165
|
+
|
|
166
|
+
if self._file_path_map is None:
|
|
167
|
+
self._file_path_map = {}
|
|
168
|
+
return CythonModuleTracer(filename, py_file, c_file, self._c_files_map, self._file_path_map)
|
|
169
|
+
|
|
170
|
+
def file_reporter(self, filename):
|
|
171
|
+
# TODO: let coverage.py handle .py files itself
|
|
172
|
+
#ext = os.path.splitext(filename)[1].lower()
|
|
173
|
+
#if ext == '.py':
|
|
174
|
+
# from coverage.python import PythonFileReporter
|
|
175
|
+
# return PythonFileReporter(filename)
|
|
176
|
+
|
|
177
|
+
filename = canonical_filename(os.path.abspath(filename))
|
|
178
|
+
if self._c_files_map and filename in self._c_files_map:
|
|
179
|
+
c_file, rel_file_path, code = self._c_files_map[filename]
|
|
180
|
+
else:
|
|
181
|
+
c_file, _ = self._find_source_files(filename)
|
|
182
|
+
if not c_file:
|
|
183
|
+
return None # unknown file
|
|
184
|
+
rel_file_path, code = self._read_source_lines(c_file, filename)
|
|
185
|
+
if code is None:
|
|
186
|
+
return None # no source found
|
|
187
|
+
return CythonModuleReporter(
|
|
188
|
+
c_file,
|
|
189
|
+
filename,
|
|
190
|
+
rel_file_path,
|
|
191
|
+
code,
|
|
192
|
+
self._excluded_lines_map.get(rel_file_path, frozenset())
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
def _find_source_files(self, filename):
|
|
196
|
+
basename, ext = os.path.splitext(filename)
|
|
197
|
+
ext = ext.lower()
|
|
198
|
+
if ext in MODULE_FILE_EXTENSIONS:
|
|
199
|
+
pass
|
|
200
|
+
elif ext == '.pyd':
|
|
201
|
+
# Windows extension module
|
|
202
|
+
platform_suffix = re.search(r'[.]cp[0-9]+-win[_a-z0-9]*$', basename, re.I)
|
|
203
|
+
if platform_suffix:
|
|
204
|
+
basename = basename[:platform_suffix.start()]
|
|
205
|
+
elif ext == '.so':
|
|
206
|
+
# Linux/Unix/Mac extension module
|
|
207
|
+
platform_suffix = re.search(r'[.](?:cpython|pypy)-[0-9]+[-_a-z0-9]*$', basename, re.I)
|
|
208
|
+
if platform_suffix:
|
|
209
|
+
basename = basename[:platform_suffix.start()]
|
|
210
|
+
elif ext == '.pxi':
|
|
211
|
+
# if we get here, it means that the first traced line of a Cython module was
|
|
212
|
+
# not in the main module but in an include file, so try a little harder to
|
|
213
|
+
# find the main source file
|
|
214
|
+
self._find_c_source_files(os.path.dirname(filename), filename)
|
|
215
|
+
if filename in self._c_files_map:
|
|
216
|
+
return self._c_files_map[filename][0], None
|
|
217
|
+
else:
|
|
218
|
+
# none of our business
|
|
219
|
+
return None, None
|
|
220
|
+
|
|
221
|
+
c_file = filename if ext in C_FILE_EXTENSIONS else _find_c_source(basename)
|
|
222
|
+
if c_file is None:
|
|
223
|
+
# a module "pkg/mod.so" can have a source file "pkg/pkg.mod.c"
|
|
224
|
+
package_root = find_root_package_dir.uncached(filename)
|
|
225
|
+
package_path = os.path.relpath(basename, package_root).split(os.path.sep)
|
|
226
|
+
if len(package_path) > 1:
|
|
227
|
+
test_basepath = os.path.join(os.path.dirname(filename), '.'.join(package_path))
|
|
228
|
+
c_file = _find_c_source(test_basepath)
|
|
229
|
+
|
|
230
|
+
py_source_file = None
|
|
231
|
+
if c_file:
|
|
232
|
+
py_source_file = os.path.splitext(c_file)[0] + '.py'
|
|
233
|
+
if not os.path.exists(py_source_file):
|
|
234
|
+
py_source_file = None
|
|
235
|
+
if not is_cython_generated_file(c_file, if_not_found=False):
|
|
236
|
+
if py_source_file and os.path.exists(c_file):
|
|
237
|
+
# if we did not generate the C file,
|
|
238
|
+
# then we probably also shouldn't care about the .py file.
|
|
239
|
+
py_source_file = None
|
|
240
|
+
c_file = None
|
|
241
|
+
|
|
242
|
+
return c_file, py_source_file
|
|
243
|
+
|
|
244
|
+
def _find_c_source_files(self, dir_path, source_file):
|
|
245
|
+
"""
|
|
246
|
+
Desperately parse all C files in the directory or its package parents
|
|
247
|
+
(not re-descending) to find the (included) source file in one of them.
|
|
248
|
+
"""
|
|
249
|
+
if not os.path.isdir(dir_path):
|
|
250
|
+
return
|
|
251
|
+
splitext = os.path.splitext
|
|
252
|
+
for filename in os.listdir(dir_path):
|
|
253
|
+
ext = splitext(filename)[1].lower()
|
|
254
|
+
if ext in C_FILE_EXTENSIONS:
|
|
255
|
+
self._read_source_lines(os.path.join(dir_path, filename), source_file)
|
|
256
|
+
if source_file in self._c_files_map:
|
|
257
|
+
return
|
|
258
|
+
# not found? then try one package up
|
|
259
|
+
if is_package_dir(dir_path):
|
|
260
|
+
self._find_c_source_files(os.path.dirname(dir_path), source_file)
|
|
261
|
+
|
|
262
|
+
def _read_source_lines(self, c_file, sourcefile):
|
|
263
|
+
"""
|
|
264
|
+
Parse a Cython generated C/C++ source file and find the executable lines.
|
|
265
|
+
Each executable line starts with a comment header that states source file
|
|
266
|
+
and line number, as well as the surrounding range of source code lines.
|
|
267
|
+
"""
|
|
268
|
+
if self._parsed_c_files is None:
|
|
269
|
+
self._parsed_c_files = {}
|
|
270
|
+
if c_file in self._parsed_c_files:
|
|
271
|
+
code_lines = self._parsed_c_files[c_file]
|
|
272
|
+
else:
|
|
273
|
+
code_lines = self._parse_cfile_lines(c_file)
|
|
274
|
+
self._parsed_c_files[c_file] = code_lines
|
|
275
|
+
|
|
276
|
+
if self._c_files_map is None:
|
|
277
|
+
self._c_files_map = {}
|
|
278
|
+
|
|
279
|
+
for filename, code in code_lines.items():
|
|
280
|
+
abs_path = _find_dep_file_path(c_file, filename,
|
|
281
|
+
relative_path_search=True)
|
|
282
|
+
self._c_files_map[abs_path] = (c_file, filename, code)
|
|
283
|
+
|
|
284
|
+
if sourcefile not in self._c_files_map:
|
|
285
|
+
return (None,) * 2 # e.g. shared library file
|
|
286
|
+
return self._c_files_map[sourcefile][1:]
|
|
287
|
+
|
|
288
|
+
def _parse_cfile_lines(self, c_file):
|
|
289
|
+
"""
|
|
290
|
+
Parse a C file and extract all source file lines that generated executable code.
|
|
291
|
+
"""
|
|
292
|
+
match_source_path_line = re.compile(r' */[*] +"(.*)":([0-9]+)$').match
|
|
293
|
+
match_current_code_line = re.compile(r' *[*] (.*) # <<<<<<+$').match
|
|
294
|
+
match_comment_end = re.compile(r' *[*]/$').match
|
|
295
|
+
match_trace_line = re.compile(r' *__Pyx_TraceLine\(([0-9]+),').match
|
|
296
|
+
not_executable = re.compile(
|
|
297
|
+
r'\s*c(?:type)?def\s+'
|
|
298
|
+
r'(?:(?:public|external)\s+)?'
|
|
299
|
+
r'(?:struct|union|enum|class)'
|
|
300
|
+
r'(\s+[^:]+|)\s*:'
|
|
301
|
+
).match
|
|
302
|
+
if self._excluded_line_patterns:
|
|
303
|
+
line_is_excluded = re.compile("|".join(["(?:%s)" % regex for regex in self._excluded_line_patterns])).search
|
|
304
|
+
else:
|
|
305
|
+
line_is_excluded = lambda line: False
|
|
306
|
+
|
|
307
|
+
code_lines = defaultdict(dict)
|
|
308
|
+
executable_lines = defaultdict(set)
|
|
309
|
+
current_filename = None
|
|
310
|
+
if self._excluded_lines_map is None:
|
|
311
|
+
self._excluded_lines_map = defaultdict(set)
|
|
312
|
+
|
|
313
|
+
with open(c_file, encoding='utf8') as lines:
|
|
314
|
+
lines = iter(lines)
|
|
315
|
+
for line in lines:
|
|
316
|
+
match = match_source_path_line(line)
|
|
317
|
+
if not match:
|
|
318
|
+
if '__Pyx_TraceLine(' in line and current_filename is not None:
|
|
319
|
+
trace_line = match_trace_line(line)
|
|
320
|
+
if trace_line:
|
|
321
|
+
lineno = int(trace_line.group(1))
|
|
322
|
+
executable_lines[current_filename].add(lineno)
|
|
323
|
+
continue
|
|
324
|
+
filename, lineno = match.groups()
|
|
325
|
+
current_filename = filename
|
|
326
|
+
lineno = int(lineno)
|
|
327
|
+
for comment_line in lines:
|
|
328
|
+
match = match_current_code_line(comment_line)
|
|
329
|
+
if match:
|
|
330
|
+
code_line = match.group(1).rstrip()
|
|
331
|
+
if not_executable(code_line):
|
|
332
|
+
break
|
|
333
|
+
if line_is_excluded(code_line):
|
|
334
|
+
self._excluded_lines_map[filename].add(lineno)
|
|
335
|
+
break
|
|
336
|
+
code_lines[filename][lineno] = code_line
|
|
337
|
+
break
|
|
338
|
+
elif match_comment_end(comment_line):
|
|
339
|
+
# unexpected comment format - false positive?
|
|
340
|
+
break
|
|
341
|
+
|
|
342
|
+
# Remove lines that generated code but are not traceable.
|
|
343
|
+
for filename, lines in code_lines.items():
|
|
344
|
+
dead_lines = set(lines).difference(executable_lines.get(filename, ()))
|
|
345
|
+
for lineno in dead_lines:
|
|
346
|
+
del lines[lineno]
|
|
347
|
+
return code_lines
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
class CythonModuleTracer(FileTracer):
|
|
351
|
+
"""
|
|
352
|
+
Find the Python/Cython source file for a Cython module.
|
|
353
|
+
"""
|
|
354
|
+
def __init__(self, module_file, py_file, c_file, c_files_map, file_path_map):
|
|
355
|
+
super().__init__()
|
|
356
|
+
self.module_file = module_file
|
|
357
|
+
self.py_file = py_file
|
|
358
|
+
self.c_file = c_file
|
|
359
|
+
self._c_files_map = c_files_map
|
|
360
|
+
self._file_path_map = file_path_map
|
|
361
|
+
|
|
362
|
+
def has_dynamic_source_filename(self):
|
|
363
|
+
return True
|
|
364
|
+
|
|
365
|
+
def dynamic_source_filename(self, filename, frame):
|
|
366
|
+
"""
|
|
367
|
+
Determine source file path. Called by the function call tracer.
|
|
368
|
+
"""
|
|
369
|
+
source_file = frame.f_code.co_filename
|
|
370
|
+
try:
|
|
371
|
+
return self._file_path_map[source_file]
|
|
372
|
+
except KeyError:
|
|
373
|
+
pass
|
|
374
|
+
abs_path = _find_dep_file_path(filename, source_file)
|
|
375
|
+
|
|
376
|
+
if self.py_file and source_file[-3:].lower() == '.py':
|
|
377
|
+
# always let coverage.py handle this case itself
|
|
378
|
+
self._file_path_map[source_file] = self.py_file
|
|
379
|
+
return self.py_file
|
|
380
|
+
|
|
381
|
+
assert self._c_files_map is not None
|
|
382
|
+
if abs_path not in self._c_files_map:
|
|
383
|
+
self._c_files_map[abs_path] = (self.c_file, source_file, None)
|
|
384
|
+
self._file_path_map[source_file] = abs_path
|
|
385
|
+
return abs_path
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
class CythonModuleReporter(FileReporter):
|
|
389
|
+
"""
|
|
390
|
+
Provide detailed trace information for one source file to coverage.py.
|
|
391
|
+
"""
|
|
392
|
+
def __init__(self, c_file, source_file, rel_file_path, code, excluded_lines):
|
|
393
|
+
super().__init__(source_file)
|
|
394
|
+
self.name = rel_file_path
|
|
395
|
+
self.c_file = c_file
|
|
396
|
+
self._code = code
|
|
397
|
+
self._excluded_lines = excluded_lines
|
|
398
|
+
|
|
399
|
+
def lines(self):
|
|
400
|
+
"""
|
|
401
|
+
Return set of line numbers that are possibly executable.
|
|
402
|
+
"""
|
|
403
|
+
return set(self._code)
|
|
404
|
+
|
|
405
|
+
def excluded_lines(self):
|
|
406
|
+
"""
|
|
407
|
+
Return set of line numbers that are excluded from coverage.
|
|
408
|
+
"""
|
|
409
|
+
return self._excluded_lines
|
|
410
|
+
|
|
411
|
+
def _iter_source_tokens(self):
|
|
412
|
+
current_line = 1
|
|
413
|
+
for line_no, code_line in sorted(self._code.items()):
|
|
414
|
+
while line_no > current_line:
|
|
415
|
+
yield []
|
|
416
|
+
current_line += 1
|
|
417
|
+
yield [('txt', code_line)]
|
|
418
|
+
current_line += 1
|
|
419
|
+
|
|
420
|
+
def source(self):
|
|
421
|
+
"""
|
|
422
|
+
Return the source code of the file as a string.
|
|
423
|
+
"""
|
|
424
|
+
if os.path.exists(self.filename):
|
|
425
|
+
with open_source_file(self.filename) as f:
|
|
426
|
+
return f.read()
|
|
427
|
+
else:
|
|
428
|
+
return '\n'.join(
|
|
429
|
+
(tokens[0][1] if tokens else '')
|
|
430
|
+
for tokens in self._iter_source_tokens())
|
|
431
|
+
|
|
432
|
+
def source_token_lines(self):
|
|
433
|
+
"""
|
|
434
|
+
Iterate over the source code tokens.
|
|
435
|
+
"""
|
|
436
|
+
if os.path.exists(self.filename):
|
|
437
|
+
with open_source_file(self.filename) as f:
|
|
438
|
+
for line in f:
|
|
439
|
+
yield [('txt', line.rstrip('\n'))]
|
|
440
|
+
else:
|
|
441
|
+
for line in self._iter_source_tokens():
|
|
442
|
+
yield [('txt', line)]
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
def coverage_init(reg, options):
|
|
446
|
+
plugin = Plugin()
|
|
447
|
+
reg.add_configurer(plugin)
|
|
448
|
+
reg.add_file_tracer(plugin)
|
Cython/Debugger/Cygdb.py
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
The Cython debugger
|
|
5
|
+
|
|
6
|
+
The current directory should contain a directory named 'cython_debug', or a
|
|
7
|
+
path to the cython project directory should be given (the parent directory of
|
|
8
|
+
cython_debug).
|
|
9
|
+
|
|
10
|
+
Additional gdb args can be provided only if a path to the project directory is
|
|
11
|
+
given.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import os
|
|
15
|
+
import sys
|
|
16
|
+
import glob
|
|
17
|
+
import tempfile
|
|
18
|
+
import textwrap
|
|
19
|
+
import subprocess
|
|
20
|
+
import argparse
|
|
21
|
+
import logging
|
|
22
|
+
|
|
23
|
+
logger = logging.getLogger(__name__)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def make_command_file(path_to_debug_info, prefix_code='',
|
|
27
|
+
no_import=False, skip_interpreter=False):
|
|
28
|
+
if not no_import:
|
|
29
|
+
pattern = os.path.join(path_to_debug_info,
|
|
30
|
+
'cython_debug',
|
|
31
|
+
'cython_debug_info_*')
|
|
32
|
+
debug_files = glob.glob(pattern)
|
|
33
|
+
|
|
34
|
+
if not debug_files:
|
|
35
|
+
sys.exit('No cython debug files were found in %s. Aborting.' % (
|
|
36
|
+
os.path.abspath(path_to_debug_info)))
|
|
37
|
+
|
|
38
|
+
fd, tempfilename = tempfile.mkstemp()
|
|
39
|
+
f = os.fdopen(fd, 'w')
|
|
40
|
+
try:
|
|
41
|
+
f.write(prefix_code)
|
|
42
|
+
f.write(textwrap.dedent('''\
|
|
43
|
+
# This is a gdb command file
|
|
44
|
+
# See https://sourceware.org/gdb/onlinedocs/gdb/Command-Files.html
|
|
45
|
+
|
|
46
|
+
set breakpoint pending on
|
|
47
|
+
set print pretty on
|
|
48
|
+
|
|
49
|
+
python
|
|
50
|
+
try:
|
|
51
|
+
# Activate virtualenv, if we were launched from one
|
|
52
|
+
import os
|
|
53
|
+
import sys
|
|
54
|
+
virtualenv = os.getenv('VIRTUAL_ENV')
|
|
55
|
+
if virtualenv:
|
|
56
|
+
scripts_dir = 'Scripts' if sys.platform == "win32" else 'bin'
|
|
57
|
+
path_to_activate_this_py = os.path.join(virtualenv, scripts_dir, 'activate_this.py')
|
|
58
|
+
print("gdb command file: Activating virtualenv: %s; path_to_activate_this_py: %s" % (
|
|
59
|
+
virtualenv, path_to_activate_this_py))
|
|
60
|
+
with open(path_to_activate_this_py) as f:
|
|
61
|
+
exec(f.read(), dict(__file__=path_to_activate_this_py))
|
|
62
|
+
from Cython.Debugger import libcython, libpython
|
|
63
|
+
except Exception as ex:
|
|
64
|
+
from traceback import print_exc
|
|
65
|
+
print("There was an error in Python code originating from the file " + ''' + repr(__file__) + ''')
|
|
66
|
+
print("It used the Python interpreter " + str(sys.executable))
|
|
67
|
+
print_exc()
|
|
68
|
+
exit(1)
|
|
69
|
+
end
|
|
70
|
+
'''))
|
|
71
|
+
|
|
72
|
+
if no_import:
|
|
73
|
+
# don't do this, this overrides file command in .gdbinit
|
|
74
|
+
# f.write("file %s\n" % sys.executable)
|
|
75
|
+
pass
|
|
76
|
+
else:
|
|
77
|
+
if not skip_interpreter:
|
|
78
|
+
# Point Cygdb to the interpreter that was used to generate
|
|
79
|
+
# the debugging information.
|
|
80
|
+
path = os.path.join(path_to_debug_info, "cython_debug", "interpreter")
|
|
81
|
+
interpreter_file = open(path)
|
|
82
|
+
try:
|
|
83
|
+
interpreter = interpreter_file.read()
|
|
84
|
+
finally:
|
|
85
|
+
interpreter_file.close()
|
|
86
|
+
f.write("file %s\n" % interpreter)
|
|
87
|
+
|
|
88
|
+
f.write('\n'.join('cy import %s\n' % fn for fn in debug_files))
|
|
89
|
+
|
|
90
|
+
if not skip_interpreter:
|
|
91
|
+
f.write(textwrap.dedent('''\
|
|
92
|
+
python
|
|
93
|
+
import sys
|
|
94
|
+
# Check if the Python executable provides a symbol table.
|
|
95
|
+
if not hasattr(gdb.selected_inferior().progspace, "symbol_file"):
|
|
96
|
+
sys.stderr.write(
|
|
97
|
+
"''' + interpreter + ''' was not compiled with debug symbols (or it was "
|
|
98
|
+
"stripped). Some functionality may not work (properly).\\n")
|
|
99
|
+
end
|
|
100
|
+
'''))
|
|
101
|
+
|
|
102
|
+
f.write("source .cygdbinit\n")
|
|
103
|
+
finally:
|
|
104
|
+
f.close()
|
|
105
|
+
|
|
106
|
+
return tempfilename
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def main():
|
|
110
|
+
"""
|
|
111
|
+
Start the Cython debugger. This tells gdb to import the Cython and Python
|
|
112
|
+
extensions (libcython.py and libpython.py) and it enables gdb's pending
|
|
113
|
+
breakpoints.
|
|
114
|
+
"""
|
|
115
|
+
parser = argparse.ArgumentParser(
|
|
116
|
+
prog="cygdb",
|
|
117
|
+
description="Cython debugger",
|
|
118
|
+
)
|
|
119
|
+
parser.add_argument("gdb_argv", nargs="*",
|
|
120
|
+
help="Arguments to forward to gdb; specified after --")
|
|
121
|
+
parser.add_argument("--build-dir", dest="build_dir", default=None,
|
|
122
|
+
help="Directory containing cython_build/ files")
|
|
123
|
+
parser.add_argument("--gdb-executable",
|
|
124
|
+
dest="gdb", default='gdb',
|
|
125
|
+
help="gdb executable to use [default: gdb]")
|
|
126
|
+
parser.add_argument("--verbose", "-v",
|
|
127
|
+
dest="verbosity", action="count", default=0,
|
|
128
|
+
help="Verbose mode. Multiple -v options increase the verbosity")
|
|
129
|
+
parser.add_argument("--skip-interpreter",
|
|
130
|
+
dest="skip_interpreter", default=False, action="store_true",
|
|
131
|
+
help="Do not automatically point GDB to the same interpreter "
|
|
132
|
+
"used to generate debugging information")
|
|
133
|
+
|
|
134
|
+
options = parser.parse_args()
|
|
135
|
+
path_to_debug_info = options.build_dir
|
|
136
|
+
gdb_argv = options.gdb_argv
|
|
137
|
+
no_import = path_to_debug_info is None
|
|
138
|
+
|
|
139
|
+
if options.build_dir is None and gdb_argv and os.path.isdir(gdb_argv[0]):
|
|
140
|
+
import warnings
|
|
141
|
+
gdb_argv = options.gdb_argv[1:]
|
|
142
|
+
path_to_debug_info = options.gdb_argv[0]
|
|
143
|
+
warnings.warn(f'Using deprecated positional parameter to find build directory. Use "--build-dir {path_to_debug_info}" argument instead.')
|
|
144
|
+
|
|
145
|
+
logging_level = logging.WARN
|
|
146
|
+
if options.verbosity == 1:
|
|
147
|
+
logging_level = logging.INFO
|
|
148
|
+
if options.verbosity >= 2:
|
|
149
|
+
logging_level = logging.DEBUG
|
|
150
|
+
logging.basicConfig(level=logging_level)
|
|
151
|
+
|
|
152
|
+
skip_interpreter = options.skip_interpreter
|
|
153
|
+
|
|
154
|
+
logger.debug("options = %r", options)
|
|
155
|
+
tempfilename = make_command_file(path_to_debug_info,
|
|
156
|
+
no_import=no_import,
|
|
157
|
+
skip_interpreter=skip_interpreter)
|
|
158
|
+
logger.info("Launching %s with command file: %s and gdb_argv: %s",
|
|
159
|
+
options.gdb, tempfilename, gdb_argv)
|
|
160
|
+
with open(tempfilename) as tempfile:
|
|
161
|
+
logger.debug('Command file (%s) contains: """\n%s"""', tempfilename, tempfile.read())
|
|
162
|
+
logger.info("Spawning %s...", options.gdb)
|
|
163
|
+
p = subprocess.Popen([options.gdb, '-command', tempfilename] + gdb_argv)
|
|
164
|
+
logger.info("Spawned %s (pid %d)", options.gdb, p.pid)
|
|
165
|
+
while True:
|
|
166
|
+
try:
|
|
167
|
+
logger.debug("Waiting for gdb (pid %d) to exit...", p.pid)
|
|
168
|
+
ret = p.wait()
|
|
169
|
+
logger.debug("Wait for gdb (pid %d) to exit is done. Returned: %r", p.pid, ret)
|
|
170
|
+
except KeyboardInterrupt:
|
|
171
|
+
pass
|
|
172
|
+
else:
|
|
173
|
+
break
|
|
174
|
+
logger.debug("Closing temp command file with fd: %s", tempfile.fileno())
|
|
175
|
+
logger.debug("Removing temp command file: %s", tempfilename)
|
|
176
|
+
os.remove(tempfilename)
|
|
177
|
+
logger.debug("Removed temp command file: %s", tempfilename)
|