This file is indexed.

/usr/share/gap/lib/debug.g is in gap-libs 4r6p5-3.

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
#############################################################################
##
#W  debug.g                      GAP library                    Thomas Breuer
#W                                                          & Max Neunhöffer
##
##
#Y  Copyright (C)  2003,  Lehrstuhl D für Mathematik,  RWTH Aachen,  Germany
#Y  (C) 2003 School Math and Comp. Sci., University of St Andrews, Scotland
#Y  Copyright (C) 2003 The GAP Group
##
##  This file contains some global variables and functions to support
##  debugging of functions in GAP. See `etc/debugvim.txt' for details.
##  As of now this is not automatically loaded and there is no documentation
##  apart from the above file. There is no support for other editors
##  than vim.
##

BindGlobal( "DEBUG", rec() );
DEBUG.debugvim_txt:= Filename( DirectoriesLibrary( "etc" ), "debugvim.txt" );
DEBUG.debug_vim:= Filename( DirectoriesLibrary( "etc" ), "debug.vim" );
DEBUG.LIST := [];
DEBUG.EDITORS := [ rec(
    name := "Vim",
    command := "vim",
    args := [ Concatenation("+map <f12> :split ", DEBUG.debugvim_txt, "<cr>"),
              Concatenation("+source ", DEBUG.debug_vim ),
              "+let @a=\"###\"" ] ) ];
DEBUG.EDITOR := DEBUG.EDITORS[1];
DEBUG.CURRENT_FUNC := fail;
DEBUG.FUNCTION := function() return 0; end;

Debug := function(arg)
  local execpath,f,i,j,l,name,oldversion,p,t;
 
  # evaluate arguments:
  if Length(arg) < 1 or Length(arg) > 2 then
    Print("Usage: Debug( <func> [ ,<name> ] );\n");
    Print("       where <func> is a function.\n");
    Print("       and   <name> is a string.\n");
    return;
  fi;
  
  # find the first argument: 
  #   our function (or a number of a previously debugged one)
  f := arg[1];
  if IsInt(f) then
    if f < 1 or f > Length(DEBUG.LIST) or not(IsBound(DEBUG.LIST[f])) then
      Print("Error: Do not know debugged function number ",f,".\n");
      return;
    fi;
    i := f;
    f := DEBUG.LIST[i].func;
  elif IsOperation( f ) or not(IsFunction(f)) then
    Print("Usage: Debug( <func>[, <name>] );\n");
    Print("       where <func> is a function but not an operation,\n");
    Print("       and   <name> is a string.\n");
    return;
  else
      
    # find function in the list of debugged functions:
    i := 1;
    while i <= Length(DEBUG.LIST) and 
          (not(IsBound(DEBUG.LIST[i])) or DEBUG.LIST[i].func <> f) do
      i := i + 1;
    od;
    # now i can be Length(DEBUG.LIST)+1
  fi;

  if Length(arg) > 1 then
    if not(IsString(name)) then
      Print("Usage: Debug( <func>[, <name>] );\n");
      Print("       where <func> is a function but not an operation,\n");
      Print("       and   <name> is a string.\n");
      return;
    fi;
    name := arg[2];
  else
    name := NAME_FUNC(f);
  fi;

  # Now ask the user to make debugging changes:
  t := TmpName();
  PrintTo(t,"# Type F12 for help!\nDEBUG.FUNCTION:=\n",f,";\n");

  # The following is necessary to preserve the old version:
  if i > Length(DEBUG.LIST) then
    Read(t);    
    oldversion := DEBUG.FUNCTION;
  fi;

  # Call the editor:
  execpath := Filename(DirectoriesSystemPrograms(),DEBUG.EDITOR.command);
  l:= List( DEBUG.EDITOR.args, x -> ReplacedString( x, "###", String( i ) ) );
  Add(l,t);   # append the temporary filename
  Process(DirectoryCurrent(),execpath,InputTextUser(),OutputTextUser(),l);
  Read(t);

  # Now copy this new version into the function:
  MakeReadWriteGVar("REREADING");
  REREADING := true;
  if i > Length(DEBUG.LIST) then
    INSTALL_METHOD_ARGS(oldversion,f);     # save the old version
  fi;
  INSTALL_METHOD_ARGS(f,DEBUG.FUNCTION);
  REREADING := false;
  MakeReadOnlyGVar("REREADING");

  # Now store what we did:
  if i > Length(DEBUG.LIST) then
    Add(DEBUG.LIST,rec(func := f,old := oldversion,name := name,count := 1));
    # i is now equal to Length(DEBUG.LIST)
  fi;
  
  Print("This is debug function #",i,".\n");
end;

DebugFind := function(f)
  local nr;

  if IsFunction(f) then
    # find function among debugged functions:
    nr := 1;
    while nr <= Length(DEBUG.LIST) and 
          (not(IsBound(DEBUG.LIST[nr])) or 
           not(IsIdenticalObj(DEBUG.LIST[nr].func,f))) do
      nr := nr + 1;
    od;
    if nr > Length(DEBUG.LIST) then
      Print("Error: This function is not debugged.\n");
      return fail;
    fi;
    return nr;
  elif IsInt(f) then
    if IsBound(DEBUG.LIST[f]) then
      return f;
    else
      Print("Error: Debugged function number ",f," is no longer debugged.\n");
      return fail;
    fi;
  else
    Print("Error: Argument must be a function or an integer.\n");
    return fail;
  fi;
end;

UnDebug := function(f)
  local nr;

  nr := DebugFind(f);
  if nr = fail then
    return;
  fi;

  # Copy the old version into the function:
  MakeReadWriteGVar("REREADING");
  REREADING := true;
  INSTALL_METHOD_ARGS(DEBUG.LIST[nr].func,DEBUG.LIST[nr].old);
  REREADING := false;
  MakeReadOnlyGVar("REREADING");
  Unbind(DEBUG.LIST[nr]);
  
  # Inform user:
  Print("Undebugging function #",nr,".\n");
end;

ShowDebug := function()
  local i;
  Print("Debug functions:\n");
  for i in [1..Length(DEBUG.LIST)] do
    Print("  ",String(i,2),": ");
    if IsBound(DEBUG.LIST[i]) then
      Print(DEBUG.LIST[i].name,"\n");
    else
      Print("No longer used.\n");
    fi;
  od;
end;

SetDebugCount := function(f,count)
  local nr;

  nr := DebugFind(f);
  if nr = fail then
    return;
  fi;

  DEBUG.LIST[nr].count := count;
end;


#############################################################################
##
#E