NOTE: This is not the final version of this patch; I'd like to see if I
can find a simple way to solve the couple of FIXMEs that I added.
However, I'm submitting it so people can see the direction I'm taking,
and provide any feedback.
Checkin comment would be:
libconcord Python bindings: Implement tracing of all API calls, their
parameters, return values, and any exceptions thrown. Tracing is
requested via an environment variable.
? concordance/.deps
? concordance/.libs
? concordance/Makefile
? concordance/Makefile.in
? concordance/aclocal.m4
? concordance/autom4te.cache
? concordance/concordance
? concordance/config.guess
? concordance/config.h
? concordance/config.h.in
? concordance/config.log
? concordance/config.status
? concordance/config.sub
? concordance/configure
? concordance/depcomp
? concordance/install-sh
? concordance/libtool
? concordance/ltmain.sh
? concordance/missing
? concordance/stamp-h1
? libconcord/.deps
? libconcord/.libconcord.cpp.swp
? libconcord/.libs
? libconcord/.remote.h.swp
? libconcord/Makefile
? libconcord/Makefile.in
? libconcord/aclocal.m4
? libconcord/autom4te.cache
? libconcord/binaryfile.lo
? libconcord/config.guess
? libconcord/config.h
? libconcord/config.h.in
? libconcord/config.log
? libconcord/config.status
? libconcord/config.sub
? libconcord/configure
? libconcord/depcomp
? libconcord/install-sh
? libconcord/libconcord.la
? libconcord/libconcord.lo
? libconcord/libtool
? libconcord/libusbhid.lo
? libconcord/ltmain.sh
? libconcord/missing
? libconcord/remote.lo
? libconcord/remote_z.lo
? libconcord/stamp-h1
? libconcord/usblan.lo
? libconcord/web.lo
? libconcord/bindings/python/.README.swp
? libconcord/bindings/python/.libconcord.py.swp
? libconcord/bindings/python/build
? libconcord/bindings/python/libconcord.pyc
Index: libconcord/bindings/python/README
===================================================================
RCS file: /cvsroot/concordance/concordance/libconcord/bindings/python/README,v
retrieving revision 1.1
diff -u -p -r1.1 README
--- libconcord/bindings/python/README 15 Apr 2008 02:34:08 -0000 1.1
+++ libconcord/bindings/python/README 27 Jun 2008 07:10:32 -0000
@@ -32,3 +32,14 @@ the bindings to your PYTHONPATH. For exa
export PYTHONPATH=/path/to/libconcord/bindings/python
+Debugging
+====================
+
+If you set the environment variable LIBCONCORD_PY_TRACE to string "1", then
+libconcord.py will trace all function calls. This may prove helpful when
+debugging client applications.
+
+For example, in bash:
+
+LIBCONCORD_PY_TRACE=1 ./congruity /path/to/Connectivity.EZHex
+
Index: libconcord/bindings/python/libconcord.py
===================================================================
RCS file: /cvsroot/concordance/concordance/libconcord/bindings/python/libconcord.py,v
retrieving revision 1.1
diff -u -p -r1.1 libconcord.py
--- libconcord/bindings/python/libconcord.py 8 Apr 2008 09:50:29 -0000 1.1
+++ libconcord/bindings/python/libconcord.py 27 Jun 2008 07:10:32 -0000
@@ -21,7 +21,11 @@
from ctypes import *
import platform
+import os
import sys
+import traceback
+
+debug = (os.environ.get("LIBCONCORD_PY_TRACE", "0") == "1")
# Internal DLL handle
if platform.system() == 'Windows':
@@ -55,7 +59,28 @@ class _CheckRetCode(object):
result = args[0]
if result != 0:
raise LibConcordException(self.func_name, result)
-
+
+class _DebugWrapper(object):
+ def __init__(self, func_name, callable):
+ self.func_name = func_name
+ self.callable = callable
+
+ def __call__(self, *args, **kwargs):
+ # FIXME: Dump ctypes arguments in a more useful fashion
+ print "libconcord." + self.func_name + \
+ "() args=" + repr(args) + " kwargs=" + repr(kwargs)
+ try:
+ ret = self.callable(*args, **kwargs)
+ print " Returned: " + repr(ret)
+ # FIXME: Dump any output (ctypes byref) params here too
+ return ret
+ except:
+ print " Threw: "
+ s = traceback.format_exc()
+ for sl in s.split('\n'):
+ print " " + sl
+ raise
+
# Internal ctypes function wrapper creation
def _create_func(
func_name,
@@ -66,7 +91,10 @@ def _create_func(
f = ftype((func_name, _dll))
if error_checker:
f.errcheck = error_checker(func_name)
- return f
+ if debug:
+ return _DebugWrapper(func_name, f)
+ else:
+ return f
# typedef void (*lc_callback)(uint32_t, uint32_t, uint32_t, void*);
callback_type = CFUNCTYPE(None, c_uint, c_uint, c_uint, py_object)
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
concordance-devel mailing list
concordance-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/concordance-devel