mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
report true line number?
This commit is contained in:
parent
aa40b011f8
commit
138af95d58
@ -691,6 +691,22 @@ def describeException(backTrace = 4):
|
|||||||
# When called in an exception handler, returns a string describing
|
# When called in an exception handler, returns a string describing
|
||||||
# the current exception.
|
# the current exception.
|
||||||
|
|
||||||
|
def byteOffsetToLineno(code, byte):
|
||||||
|
# Returns the source line number corresponding to the given byte
|
||||||
|
# offset into the indicated Python code module.
|
||||||
|
|
||||||
|
import array
|
||||||
|
lnotab = array.array('B', code.co_lnotab)
|
||||||
|
|
||||||
|
line = code.co_firstlineno
|
||||||
|
for i in range(0, len(lnotab),2):
|
||||||
|
byte -= lnotab[i]
|
||||||
|
if byte <= 0:
|
||||||
|
return line
|
||||||
|
line += lnotab[i+1]
|
||||||
|
|
||||||
|
return line
|
||||||
|
|
||||||
infoArr = sys.exc_info()
|
infoArr = sys.exc_info()
|
||||||
exception = infoArr[0]
|
exception = infoArr[0]
|
||||||
exceptionName = getattr(exception, '__name__', None)
|
exceptionName = getattr(exception, '__name__', None)
|
||||||
@ -699,14 +715,18 @@ def describeException(backTrace = 4):
|
|||||||
|
|
||||||
stack = []
|
stack = []
|
||||||
while trace.tb_next:
|
while trace.tb_next:
|
||||||
module = trace.tb_frame.f_globals.get('__name__', None)
|
frame = trace.tb_frame
|
||||||
lineno = trace.tb_frame.f_lineno
|
module = frame.f_globals.get('__name__', None)
|
||||||
stack.append("%s:%s, " % (module, lineno))
|
lineno = frame.f_lineno
|
||||||
|
truelineno = byteOffsetToLineno(frame.f_code, frame.f_lasti)
|
||||||
|
stack.append("%s:%s(%s), " % (module, lineno, truelineno))
|
||||||
trace = trace.tb_next
|
trace = trace.tb_next
|
||||||
|
|
||||||
module = trace.tb_frame.f_globals.get('__name__', None)
|
frame = trace.tb_frame
|
||||||
lineno = trace.tb_frame.f_lineno
|
module = frame.f_globals.get('__name__', None)
|
||||||
stack.append("%s:%s, " % (module, lineno))
|
lineno = frame.f_lineno
|
||||||
|
truelineno = byteOffsetToLineno(frame.f_code, frame.f_lasti)
|
||||||
|
stack.append("%s:%s(%s), " % (module, lineno, truelineno))
|
||||||
|
|
||||||
description = ""
|
description = ""
|
||||||
for i in range(len(stack) - 1, max(len(stack) - backTrace, 0) - 1, -1):
|
for i in range(len(stack) - 1, max(len(stack) - backTrace, 0) - 1, -1):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user