/usr/share/gps/library/debugger.py is in gnat-gps-common 6.1.2016-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | """
Various extensions to the visual debugger support in GPS.
This is mostly intended as a template for your own custom commands.
This plug-in adds:
- an entry in the Debug contextual menu so that you can display the entity
with its full expanded name (e.g. Foo.Bar.Var). In particular, this is
useful when you have lots of partial name qualification in your code, such
as Bar.Var to refer to Foo.Bar.Var, where the underlying debugger cannot
resolve the value by itself.
- an entry in the Debug contextual menu so that you can display the entity
under the cursor as a decimal. In particular, this is useful when you click
on an enumeration literal or a variable of an enumeration type if you want
to see the actual value instead of the literal value.
- /Debug/Data/Graph Display Local Variables menu, which
displays all local variables in the data window, one box per variable.
This is different from the /Debug/Data/Display Local Variables menu
which does not pretty-print the variables.
- a way to ignore exceptions raised at specific source locations,
while still stopping on all other exceptions. The source locations are
set through the contextual menu "Ignore exception breakpoints" (and removed
likewise), and are preserved between GPS sessions if the preference is set
appropriately.
- a GPS action (to which key bindings can be set) called
"Continue till line" (in the General category of the key shortcut manager).
This allows you through a simple key shortcut to automatically continue the
debugger till the current line.
"""
###########################################################################
# No user customization below this line
###########################################################################
from GPS import *
from gps_utils import *
import text_utils
import re
import os.path
Preference("Plugins/debugger/save_autocont_br").create(
"Preserve auto-cont breakpoints", "boolean",
"If set, the source locations where the debugger should not stop on an" +
" exception are preserved across GPS sessions. If unset, you'll have to" +
" reset them the next time you start the debugger, but on the other" +
" hand this might work better when the source code has changed", True)
def in_debugger(context):
try:
return Debugger.get() is not None
except:
return False
def in_debugger_and_file(context):
try:
return Debugger.get() is not None and context.file() is not None
except:
return False
def print_in_console(debug, txt):
Console("Debugger Console").write(txt)
###################################
# Display all local vars in graph #
###################################
@interactive(name="debug graph display local variables",
category="Debug",
filter="Debugger active")
def display_local_vars(menu):
"""
Show in the Data Window the value for each all local variables
(one box per variable).
"""
buffer = EditorBuffer.get()
subp = text_utils.goto_subprogram_start(buffer.current_view().cursor())
if subp:
entity = Entity(subp.block_name(), buffer.file(), subp.line())
vars = text_utils.get_local_vars(entity)
debug = Debugger.get()
for v in vars:
debug.send("graph display " + v.name(), False)
#####################
# Display full name #
#####################
def in_debugger_on_entity(context):
try:
return in_debugger(context) and context.entity() is not None
except:
return False
@interactive(
name='debug display full name',
contextual=lambda context:
"Debug/Display <b>" + context.entity().full_name() + "</b>",
filter=in_debugger_on_entity)
def display_full_name_run():
context = GPS.current_context()
Debugger.get().send("graph display " + context.entity().full_name(),
show_in_console=True)
#######################
# Printing as decimal #
#######################
@interactive(
name='debug print as decimal',
contextual=lambda context:
"Debug/Print <b>" + context.entity().name() + "</b> as decimal",
filter=in_debugger_on_entity)
def print_as_dec_run():
context = GPS.current_context()
Debugger.get().send("print/d " + context.entity().name(),
show_in_console=True)
###################################
# Continuing till a specific line #
###################################
@interactive(name="continue till line", category="Debug",
filter="Debugger active")
def continue_till_line():
"""
Continue executing the debuggee until it reaches the current editor line.
If this line is never reached, the debugger will not stop.
"""
context = current_context()
try:
debug = Debugger.get()
debug.send("tbreak %s:%s" %
(context.file().name(), context.location().line()))
debug.send("cont")
except:
pass # No debugger active
#########################
# Breakpoint exceptions #
#########################
def debug_add_br_exception_label(context):
f = "%s:%s" % (os.path.basename(context.file().name()),
context.location().line())
if f in autocont_br:
return ("Debug/Do not ignore exception breakpoints on line <b>%d</b>" %
(context.location().line(), ))
else:
return "Debug/Ignore exception breakpoints on line <b>%d</b>" % (
context.location().line(), )
autocont_br = set()
@with_save_current_window
def on_debugger_stopped(h, debug):
# This will give the focus to the editor for the current frame, so with
# the call to save_current_window we make sure the Debugger console keeps
# the focus.
frame = debug.send("frame", False)
# Process terminated ?
if frame.find("No stack.") != -1:
return
# The only case where we don't stop at frame 0 is for exceptions. So
# if we are on frame 0, we are in an exception
if re.search("^#0\s", frame):
return
m = re.search("at (.+):(\d+)", frame)
file = os.path.basename(m.group(1)) + ":" + m.group(2)
if file in autocont_br:
debug.non_blocking_send("cont")
@interactive(
name='debug add breakpoint exception',
contextual=debug_add_br_exception_label,
filter=in_debugger_and_file)
def add_breakpoint_exception():
context = GPS.current_context()
global autocont_br
# Only consider base names of files, since the debugger does not always
# show the full name in the "frame" command
f = "%s:%s" % (os.path.basename(context.file().name()),
context.location().line())
if f in autocont_br:
autocont_br.remove(f)
else:
autocont_br.add(f)
if Preference("Plugins/debugger/save_autocont_br").get():
Project.root().set_property(
"autocont_br", "--".join(autocont_br), True)
def on_project_view_changed(h):
global autocont_br
try:
autocont_br = set(
Project.root().get_property("autocont_br").split("--"))
Console().write(
"The debugger will not stop when an exception is raised at " +
"\n".join(autocont_br))
except:
autocont_br = set()
Hook("debugger_process_stopped").add(on_debugger_stopped)
Hook("project_view_changed").add(on_project_view_changed)
|