[Patches] pdb patch for multi-line argument lists

Sjoerd Mullender sjoerd@oratrix.nl
Thu, 02 Mar 2000 17:50:22 +0100


When you set a breakpoint on a function with a multi-line argument
list, the breakpoint is actually set on the second line of the
arguments instead of the first line of the body.  This patch fixes
that.

Index: pdb.py
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Lib/pdb.py,v
retrieving revision 1.42
diff -u -r1.42 pdb.py
--- pdb.py	2000/02/04 15:39:30	1.42
+++ pdb.py	2000/03/02 16:44:29
@@ -329,29 +329,35 @@
 		# code parse time.  We don't want that, so all breakpoints
 		# set at 'def' statements are moved one line onward
 		if line[:3] == 'def':
-			incomment = ''
+			instr = ''
+			brackets = 0
 			while 1:
+				skipone = 0
+				for c in line:
+					if instr:
+						if skipone:
+							skipone = 0
+						elif c == '\\':
+							skipone = 1
+						elif c == instr:
+							instr = ''
+					elif c == '#':
+						break
+					elif c in ('"',"'"):
+						instr = c
+					elif c in ('(','{','['):
+						brackets = brackets + 1
+					elif c in (')','}',']'):
+						brackets = brackets - 1
 				lineno = lineno+1
 				line = linecache.getline(filename, lineno)
 				if not line:
 					print 'end of file'
 					return 0
 				line = string.strip(line)
-				if incomment:
-					if len(line) < 3: continue
-					if (line[-3:] == incomment):
-						incomment = ''
-					continue
 				if not line: continue	# Blank line
-				if len(line) >= 3:
-					if (line[:3] == '"""'
-					    or line[:3] == "'''"):
-						if line[-3:] == line[:3]:
-							# one-line string
-							continue
-						incomment = line[:3]
-						continue
-				if line[0] != '#': break
+				if brackets <= 0 and line[0] not in ('#','"',"'"):
+					break
 		return lineno
 
 	def do_enable(self, arg):

I confirm that, to the best of my knowledge and belief, this
contribution is free of any claims of third parties under copyright,
patent or other rights or interests ("claims").  To the extent that I
have any such claims, I hereby grant to CNRI a nonexclusive,
irrevocable, royalty-free, worldwide license to reproduce, distribute,
perform and/or display publicly, prepare derivative versions, and
otherwise use this contribution as part of the Python software and its
related documentation, or any derivative versions thereof, at no cost
to CNRI or its licensed users, and to authorize others to do so.

I acknowledge that CNRI may, at its sole discretion, decide whether or
not to incorporate this contribution in the Python software and its
related documentation.  I further grant CNRI permission to use my name
and other identifying information provided to CNRI by me for use in
connection with the Python software and its related documentation.

-- Sjoerd Mullender <sjoerd.mullender@oratrix.com>