[New-bugs-announce] [issue9919] gdbinit lineno result is one line in excess

qpatata report at bugs.python.org
Wed Sep 22 12:34:36 CEST 2010


New submission from qpatata <qpatata at gmail.com>:

Thanks a lot to all python teams for your excel.lent work.

When latest version of gdbinit macros is used to debug with gdb a python 2.4 session, the result from lineno macro seems one line more than the correct one.

If we compare the gdb macro:

define lineno
    set $__continue = 1
    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 && $__continue)
      set $__sz = $__sz - 1
      set $__ad = $__ad + *$__p
      set $__p = $__p + 1
      if ($__ad > $__lasti)
	set $__continue = 0
      end
      set $__li = $__li + *$__p
      set $__p = $__p + 1
    end
    printf "%d", $__li
end

with the related C source code in libpython.py

    def addr2line(self, addrq):
        '''
        Get the line number for a given bytecode offset

        Analogous to PyCode_Addr2Line; translated from pseudocode in
        Objects/lnotab_notes.txt
        '''
        co_lnotab = self.pyop_field('co_lnotab').proxyval(set())

        # Initialize lineno to co_firstlineno as per PyCode_Addr2Line
        # not 0, as lnotab_notes.txt has it:
        lineno = int_from_int(self.field('co_firstlineno'))

        addr = 0
        for addr_incr, line_incr in zip(co_lnotab[::2], co_lnotab[1::2]):
            addr += ord(addr_incr)
            if addr > addrq:
                return lineno
            lineno += ord(line_incr)
        return lineno

we see that if addr  is greater than addrq, the python codes returns immedialty, but the gdb macro adds a new delta of lines before exit the loop.

Kind regards.

----------
messages: 117133
nosy: qpatata
priority: normal
severity: normal
status: open
title: gdbinit lineno result is one line in excess
type: behavior
versions: Python 2.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9919>
_______________________________________


More information about the New-bugs-announce mailing list