Skip to content

Commit 763361d

Browse files
committed
Fix binding of breakpoints in authored files when enabling debugging.
Breakpoints in non-authored files still do not bind when enabling debugging because add_breakpoints_to_file ignores them if source maps are enabled.
1 parent 05c5120 commit 763361d

File tree

1 file changed

+44
-22
lines changed

1 file changed

+44
-22
lines changed

swi.py

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,9 @@ def add_breakpoints_to_file(self, file):
394394

395395
position = mapping.get_generated_position(file_name, int(line), column)
396396
if position:
397-
location = webkit.Debugger.Location({'lineNumber': position.zero_based_line(), 'scriptId': scriptId})
398-
channel.send(webkit.Debugger.setBreakpoint(location), self.updateAuthoredDocument)
397+
location = webkit.Debugger.Location({'lineNumber': position.zero_based_line(), 'columnNumber': position.zero_based_column(), 'scriptId': scriptId})
398+
params = {'authoredLocation': { 'lineNumber': line, 'columnNumber': column, 'file': file_name }}
399+
channel.send(webkit.Debugger.setBreakpoint(location), self.breakpointAdded, params)
399400
else:
400401
breakpoints = get_breakpoints_by_full_path(file)
401402
if breakpoints:
@@ -404,7 +405,7 @@ def add_breakpoints_to_file(self, file):
404405
if 'column' in breakpoints[line] and int(breakpoints[line]['column']) >= 0:
405406
column = int(breakpoints[line]['column'])
406407

407-
location = webkit.Debugger.Location({'lineNumber': int(line), 'scriptId': scriptId})
408+
location = webkit.Debugger.Location({'lineNumber': int(line), 'columnNumber': int(column), 'scriptId': scriptId})
408409
channel.send(webkit.Debugger.setBreakpoint(location), self.breakpointAdded)
409410

410411
def updateAuthoredDocument(self, command):
@@ -419,25 +420,46 @@ def breakpointAdded(self, command):
419420

420421
breakpointId = command.data['breakpointId']
421422
scriptId = command.data['actualLocation'].scriptId
422-
lineNumber = command.data['actualLocation'].lineNumber
423-
try:
424-
breakpoint = get_breakpoints_by_scriptId(str(scriptId))[str(lineNumber)]
425-
breakpoint['status'] = 'enabled'
426-
breakpoint['breakpointId'] = str(breakpointId)
427-
except:
428-
pass
429-
430-
try:
431-
breaks = get_breakpoints_by_scriptId(str(scriptId))
432-
lineNumber = str(lineNumber)
433-
lineNumberSend = str(command.params['location']['lineNumber'])
434-
if lineNumberSend in breaks and lineNumber != lineNumberSend:
435-
breaks[lineNumber] = breaks[lineNumberSend].copy()
436-
del breaks[lineNumberSend]
437-
breaks[lineNumber]['status'] = 'enabled'
438-
breaks[lineNumber]['breakpointId'] = str(breakpointId)
439-
except:
440-
pass
423+
file = find_script(str(scriptId))
424+
425+
lineNumberActual = command.data['actualLocation'].lineNumber
426+
columnNumberActual = command.data['actualLocation'].columnNumber
427+
428+
# we persist in terms of the authored file if any, so translate
429+
positionActual = get_authored_position_if_necessary(file, lineNumberActual, columnNumberActual)
430+
if positionActual:
431+
file = positionActual.file_name()
432+
lineNumberActual = str(positionActual.zero_based_line())
433+
columnNumberActual = str(positionActual.zero_based_column())
434+
435+
# the breakpoint might have been set before debugging starts
436+
# in that case it might be stored under a different line number
437+
# to the true actual number we get back. check both.
438+
439+
lineNumberSent = command.params['location']['lineNumber']
440+
columnNumberSent = command.params['location']['columnNumber']
441+
442+
# again, prefer the authored location.
443+
# we could use the source maps again to get it, but those don't
444+
# always round trip to the original location. instead, pass them through
445+
if 'authoredLocation' in command.options:
446+
assert(file == command.options['authoredLocation']['file'])
447+
lineNumberSent = command.options['authoredLocation']['lineNumber']
448+
columnNumberSent = command.options['authoredLocation']['columnNumber']
449+
450+
breakpoints = get_breakpoints_by_full_path(file)
451+
452+
# delete anything persisted under the original line number and
453+
# move it to the correct line number
454+
if lineNumberSent != lineNumberActual:
455+
if lineNumberSent in breakpoints:
456+
breakpoints[lineNumberActual] = breakpoints[lineNumberSent].copy()
457+
del breakpoints[lineNumberSent]
458+
459+
# finish updating the persisted breakpoint
460+
breakpoints[lineNumberActual]['status'] = 'enabled'
461+
breakpoints[lineNumberActual]['breakpointId'] = str(breakpointId)
462+
441463
save_breaks()
442464
update_overlays()
443465

0 commit comments

Comments
 (0)