My Project
Macros | Functions | Variables
sdb.h File Reference
#include "kernel/structs.h"

Go to the source code of this file.

Macros

#define HAVE_SDB
 

Functions

void sdb_edit (procinfo *pi)
 
void sdb_show_bp ()
 
BOOLEAN sdb_set_breakpoint (const char *p, int lineno=0)
 
void sdb (Voice *currentVoice, const char *currLine, int len)
 

Variables

EXTERN_VAR int sdb_lines []
 
EXTERN_VAR char * sdb_files []
 
EXTERN_VAR int sdb_flags
 

Macro Definition Documentation

◆ HAVE_SDB

#define HAVE_SDB

Definition at line 10 of file sdb.h.

Function Documentation

◆ sdb()

void sdb ( Voice currentVoice,
const char *  currLine,
int  len 
)

Definition at line 198 of file sdb.cc.

199 {
200  int bp=0;
201  if ((len>1)
202  && ((currentVoice->pi->trace_flag & 1)
204  )
205  {
206  loop
207  {
208  char gdb[80];
209  char *p=(char *)currLine+len-1;
210  while ((*p<=' ') && (p!=currLine))
211  {
212  p--; len--;
213  }
214  if (p==currLine) return;
215 
216  currentVoice->pi->trace_flag&= ~1; // delete flag for "all lines"
217  Print("(%s,%d) >>",currentVoice->filename,yylineno);
218  fwrite(currLine,1,len,stdout);
219  Print("<<\nbreakpoint %d (press ? for list of commands)\n",bp);
220  p=fe_fgets_stdin(">>",gdb,80);
221  while (*p==' ') p++;
222  if (*p >' ')
223  {
224  sdb_lastcmd=*p;
225  }
226  Print("command:%c\n",sdb_lastcmd);
227  switch(sdb_lastcmd)
228  {
229  case '?':
230  case 'h':
231  {
232  PrintS(
233  "b - print backtrace of calling stack\n"
234  "B <proc> [<line>] - define breakpoint\n"
235  "c - continue\n"
236  "d - delete current breakpoint\n"
237  "D - show all breakpoints\n"
238  "e - edit the current procedure (current call will be aborted)\n"
239  "h,? - display this help screen\n"
240  "n - execute current line, break at next line\n"
241  "p <var> - display type and value of the variable <var>\n"
242  "q <flags> - quit debugger, set debugger flags(0,1,2)\n"
243  " 0: stop debug, 1:continue, 2: throw an error, return to toplevel\n"
244  "Q - quit Singular\n");
245  int i;
246  for(i=0;i<7;i++)
247  {
248  if (sdb_lines[i] != -1)
249  Print("breakpoint %d at line %d in %s\n",
250  i,sdb_lines[i],sdb_files[i]);
251  }
252  break;
253  }
254  case 'd':
255  {
256  Print("delete break point %d\n",bp);
257  currentVoice->pi->trace_flag &= (~Sy_bit(bp));
258  if (bp!=0)
259  {
260  sdb_lines[bp-1]=-1;
261  }
262  break;
263  }
264  case 'D':
265  sdb_show_bp();
266  break;
267  #if 0
268  case 'l':
269  {
270  extern void listall(int showproc);
271  listall(FALSE);
272  break;
273  }
274  #endif
275  case 'n':
276  currentVoice->pi->trace_flag|= 1;
277  return;
278  case 'e':
279  {
281  sdb_flags=2;
282  return;
283  }
284  case 'p':
285  {
286  p=sdb_find_arg(p);
287  EXTERN_VAR int myynest;
288  Print("variable `%s`at level %d",p,myynest);
289  idhdl h=ggetid(p);
290  if (h==NULL)
291  PrintS(" not found\n");
292  else
293  {
294  sleftv tmp;
295  memset(&tmp,0,sizeof(tmp));
296  tmp.rtyp=IDHDL;
297  tmp.data=h;
298  Print("(type %s):\n",Tok2Cmdname(tmp.Typ()));
299  tmp.Print();
300  }
301  break;
302  }
303  case 'b':
304  VoiceBackTrack();
305  break;
306  case 'B':
307  {
308  p=sdb_find_arg(p);
309  Print("procedure `%s` ",p);
311  break;
312  }
313  case 'q':
314  {
315  p=sdb_find_arg(p);
316  if (*p!='\0')
317  {
318  sdb_flags=atoi(p);
319  Print("new sdb_flags:%d\n",sdb_flags);
320  }
321  return;
322  }
323  case 'Q':
324  m2_end(999);
325  case 'c':
326  default:
327  return;
328  }
329  }
330  }
331 }
#define FALSE
Definition: auxiliary.h:96
int i
Definition: cfEzgcd.cc:132
int p
Definition: cfModGcd.cc:4078
procinfo * pi
Definition: fevoices.h:64
char * filename
Definition: fevoices.h:63
Definition: idrec.h:35
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
int Typ()
Definition: subexpr.cc:1011
int rtyp
Definition: subexpr.h:91
void * data
Definition: subexpr.h:88
void Print(leftv store=NULL, int spaces=0)
Called by type_cmd (e.g. "r;") or as default in jPRINT.
Definition: subexpr.cc:63
#define Print
Definition: emacs.cc:80
VAR int yylineno
Definition: febase.cc:40
VAR int myynest
Definition: febase.cc:41
char *(* fe_fgets_stdin)(const char *pr, char *s, int size)
Definition: feread.cc:32
VAR Voice * currentVoice
Definition: fevoices.cc:49
void VoiceBackTrack()
Definition: fevoices.cc:77
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:140
#define EXTERN_VAR
Definition: globaldefs.h:6
idhdl ggetid(const char *n)
Definition: ipid.cc:581
STATIC_VAR Poly * h
Definition: janet.cc:971
void m2_end(int i)
Definition: misc_ip.cc:1097
#define NULL
Definition: omList.c:12
#define Sy_bit(x)
Definition: options.h:31
void PrintS(const char *s)
Definition: reporter.cc:284
BOOLEAN sdb_set_breakpoint(const char *pp, int given_lineno)
Definition: sdb.cc:64
VAR int sdb_flags
Definition: sdb.cc:31
void sdb_edit(procinfo *pi)
Definition: sdb.cc:109
VAR char * sdb_files[6]
Definition: sdb.cc:30
static char * sdb_find_arg(char *p)
Definition: sdb.cc:47
void sdb_show_bp()
Definition: sdb.cc:57
VAR int sdb_lines[]
Definition: sdb.cc:29
int sdb_checkline(char f)
Definition: sdb.cc:33
STATIC_VAR char sdb_lastcmd
Definition: sdb.cc:196
#define loop
Definition: structs.h:75
char trace_flag
Definition: subexpr.h:62
#define IDHDL
Definition: tok.h:31

◆ sdb_edit()

void sdb_edit ( procinfo pi)

Definition at line 109 of file sdb.cc.

110 {
111  char * filename = omStrDup("/tmp/sdXXXXXX");
112  int f=mkstemp(filename);
113  if (f==-1)
114  {
115  Print("cannot open %s\n",filename);
116  omFree(filename);
117  return;
118  }
119  if (pi->language!= LANG_SINGULAR)
120  {
121  Print("cannot edit type %d\n",pi->language);
122  close(f);
123  }
124  else
125  {
126  const char *editor=getenv("EDITOR");
127  if (editor==NULL)
128  editor=getenv("VISUAL");
129  if (editor==NULL)
130  editor="vi";
131  editor=omStrDup(editor);
132 
133  if (pi->data.s.body==NULL)
134  {
136  if (pi->data.s.body==NULL)
137  {
138  PrintS("cannot get the procedure body\n");
139  close(f);
140  si_unlink(filename);
141  omFree(filename);
142  return;
143  }
144  }
145 
146  write(f,pi->data.s.body,strlen(pi->data.s.body));
147  close(f);
148 
149  int pid=fork();
150  if (pid!=0)
151  {
152  si_wait(&pid);
153  }
154  else if(pid==0)
155  {
156  if (strchr(editor,' ')==NULL)
157  {
158  execlp(editor,editor,filename,NULL);
159  Print("cannot exec %s\n",editor);
160  }
161  else
162  {
163  char *p=(char *)omAlloc(strlen(editor)+strlen(filename)+2);
164  sprintf(p,"%s %s",editor,filename);
165  system(p);
166  }
167  exit(0);
168  }
169  else
170  {
171  PrintS("cannot fork\n");
172  }
173 
174  FILE* fp=fopen(filename,"r");
175  if (fp==NULL)
176  {
177  Print("cannot read from %s\n",filename);
178  }
179  else
180  {
181  fseek(fp,0L,SEEK_END);
182  long len=ftell(fp);
183  fseek(fp,0L,SEEK_SET);
184 
185  omFree((ADDRESS)pi->data.s.body);
186  pi->data.s.body=(char *)omAlloc((int)len+1);
187  myfread( pi->data.s.body, len, 1, fp);
188  pi->data.s.body[len]='\0';
189  fclose(fp);
190  }
191  }
192  si_unlink(filename);
193  omFree(filename);
194 }
void * ADDRESS
Definition: auxiliary.h:119
CanonicalForm fp
Definition: cfModGcd.cc:4102
FILE * f
Definition: checklibs.c:9
size_t myfread(void *ptr, size_t size, size_t nmemb, FILE *stream)
Definition: feFopen.cc:195
char * getenv()
char * iiGetLibProcBuffer(procinfo *pi, int part)
Definition: iplib.cc:197
#define pi
Definition: libparse.cc:1145
#define SEEK_SET
Definition: mod2.h:115
#define SEEK_END
Definition: mod2.h:111
#define omStrDup(s)
Definition: omAllocDecl.h:263
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define omFree(addr)
Definition: omAllocDecl.h:261
int status int void size_t count write
Definition: si_signals.h:67
@ LANG_SINGULAR
Definition: subexpr.h:22

◆ sdb_set_breakpoint()

BOOLEAN sdb_set_breakpoint ( const char *  p,
int  lineno = 0 
)

Definition at line 64 of file sdb.cc.

65 {
66  idhdl h=ggetid(pp);
67  if ((h==NULL)||(IDTYP(h)!=PROC_CMD))
68  {
69  PrintS(" not found\n");
70  return TRUE;
71  }
72  else
73  {
75  #ifdef HAVE_DYNAMIC_LOADING
76  if (p->language!=LANG_SINGULAR)
77  {
78  PrintS("is not a Singular procedure\n");
79  return TRUE;
80  }
81  #endif
82  int lineno;
83  if (given_lineno >0) lineno=given_lineno;
84  else lineno=p->data.s.body_lineno;
85  int i;
86  if (given_lineno== -1)
87  {
88  i=p->trace_flag;
89  p->trace_flag &=1;
90  Print("breakpoints in %s deleted(%#x)\n",p->procname,i &255);
91  return FALSE;
92  }
93  i=0;
94  while((i<7) && (sdb_lines[i]!=-1)) i++;
95  if (sdb_lines[i]!= -1)
96  {
97  PrintS("too many breakpoints set, max is 7\n");
98  return TRUE;
99  }
100  sdb_lines[i]=lineno;
101  sdb_files[i]=p->libname;
102  i++;
103  p->trace_flag|=(1<<i);
104  Print("breakpoint %d, at line %d in %s\n",i,lineno,p->procname);
105  return FALSE;
106  }
107 }
#define TRUE
Definition: auxiliary.h:100
CanonicalForm FACTORY_PUBLIC pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f )
Definition: cf_gcd.cc:676
@ PROC_CMD
Definition: grammar.cc:280
#define IDDATA(a)
Definition: ipid.h:126
#define IDTYP(a)
Definition: ipid.h:119
procinfo * procinfov
Definition: structs.h:60

◆ sdb_show_bp()

void sdb_show_bp ( )

Definition at line 57 of file sdb.cc.

58 {
59  for(int i=0; i<7;i++)
60  if (sdb_lines[i]!= -1)
61  Print("Breakpoint %d: %s::%d\n",i+1,sdb_files[i],sdb_lines[i]);
62 }

Variable Documentation

◆ sdb_files

EXTERN_VAR char* sdb_files[]

Definition at line 16 of file sdb.h.

◆ sdb_flags

EXTERN_VAR int sdb_flags

Definition at line 17 of file sdb.h.

◆ sdb_lines

EXTERN_VAR int sdb_lines[]

Definition at line 15 of file sdb.h.