Tim Peters wrote at 2005-6-21 14:56 -0400:
> ...
>[Dieter Maurer]
>> If you happen to run your application on Linux (and use the "GDB"), I
>> can provide detailed instructions on how to find out where your code
>> hangs...
>
>That would be helpful!

Also you already solved the main problem, I will share
how I analyse "hanging problems" with "GDB" under Linux.

I attach the hanging progess with "GDB"

         gdb python <process id>

"info threads" tells me about the process' threads,
"thread <i>" allows me to switch into the context
of the various threads. "bt" shows me the call trace in current
thread. That's all C level information.

To relate that to the Python level, I use a ".gdbinit"
with the following definitions.
"ps" (for "Print String") outputs the value of a Python
string variable.
"pfr" (for "Print FRame") can be called in "eval_frame"
C level stack frames and tells filename, function name and line number
of the corresponding Python call.

With these commands I can reconstruct the Python call stack
for the given thread (although it is a bit cumbersome).

Would I know more about how Python stores its interpreter
state per thread, this reconstruction would probably be
even easier...


def ps
x/s ({PyStringObject}$arg0)->ob_sval
end

def pfr
ps f->f_code->co_filename
ps f->f_code->co_name
#p f->f_lineno
lineno
end

define lineno
    set $__co = f->f_code
    set $__lasti = f->f_lasti
    set $__sz = ((PyStringObject *)$__co->co_lnotab)->ob_size/2
    set $__p = (unsigned char *)((PyStringObject *)$__co->co_lnotab)->ob_sval
    set $__li = $__co->co_firstlineno
    set $__ad = 0
    while ($__sz-1 >= 0)
      set $__sz = $__sz - 1
      set $__ad = $__ad + *$__p
      set $__p = $__p + 1
      if ($__ad > $__lasti)
        # break -- interpreted as "breakpoint"
        set $__sz = -1
      end
      if ($__sz >= 0)
        set $__li = $__li + *$__p
        set $__p = $__p + 1
      end
    end
    printf "%d\n", $__li
end


-- 
Dieter
_______________________________________________
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zodb-dev

Reply via email to