This file is indexed.

/usr/share/gps/library/debugger.py is in gnat-gps-common 5.0-6.

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
"""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
   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, re, 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() != None
   except:
      return False

def print_in_console (debug, txt):
   Console ("Debugger Console").write (txt)

######################################
# Display all local vars in graph    #
######################################

def display_local_vars (menu):
   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)

Menu.create (
   path = "/Debug/Data/Graph display local variables",
   on_activate = display_local_vars)
 
######################################
# Printing as decimal                #
######################################

def print_as_dec_label (context):
   return "Debug/Print <b> " + context.entity().name() + "</b> as decimal"

def print_as_dec_run (context):
   Debugger.get().send ("print/d " + context.entity().name(),
                        show_in_console=True)

def in_debugger_on_entity (context):
   try:
     return in_debugger (context) and context.entity() != None 
   except:
     return False

Contextual ("debug print as decimal").create (
   label       = print_as_dec_label,
   on_activate = print_as_dec_run,
   filter      = in_debugger_on_entity)

####################################
# Continuing till a specific line
####################################

@interactive (name="continue till line", category="Debugger",
              filter="Debugger active", key="control-b",
              menu="/Debug/Continue to current line", after="Continue")
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 " + context.file().name() + ":" + `context.location().line()`)
     debug.send ("cont")
  except:
     pass  # No debugger active

####################################
# Breakpoint exceptions            #
####################################

def debug_add_br_exception_label (context):
   f = os.path.basename (context.file().name())\
       + ":" + `context.location().line()`
   if f in autocont_br:
     return "Debug/Do not ignore exception breakpoints on line <b>" \
        + `context.location().line ()` + "</b>"
   else:
     return "Debug/Ignore exception breakpoints on line <b>" \
        + `context.location().line ()` + "</b>"

autocont_br = set ()

def on_debugger_stopped (h, debug):
   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")

def add_breakpoint_exception (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 = 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 ()

Contextual ("debug add breakpoint exception").create (
   label       = debug_add_br_exception_label,
   on_activate = add_breakpoint_exception,
   filter      = in_debugger)

Hook ("debugger_process_stopped").add (on_debugger_stopped)
Hook ("project_view_changed").add (on_project_view_changed)