Adding debugging screen output - BrentBaccala/Singular GitHub Wiki

Here we discuss how to add debugging screen output to an already present Singular function.

We assume that you are in the Sources directory.

  • We add a screen output to the function n_Add (which adds two numbers):

    To do this, in the file libpolys/coeffs/coeffs.h change

    static inline number n_Add(number a, number b, const coeffs r) 
       { 
           assume(r != NULL); 
           assume(r->cfAdd!=NULL);  
           return r->cfAdd(a, b, r); 
       }
    

    into

    static inline number n_Add(number a, number b, const coeffs r)
       { 
            assume(r != NULL);
            assume(r->cfAdd!=NULL);
            Print("n_Add(a,b,r) called with argument a = ");
            n_Print(a,r); 
            PrintLn(); 
            return r->cfAdd(a, b, r); 
        }
    
  • Compile Singular by doing make

  • Start Singular by ./Singular/Singular

  • Try out the screen output by doing

      ring r;
      number n=1;
      number m=2;
      n+m;
    

Warnings, why you should do this only for testing purposes and remove afterwards:

  • one should never add such code the the n_-routines but to the specific npAdd, nlAdd etc.
  • if one really want to catch all additions, patch jjPLUS_N in Singular/iparith.cc
  • n_Print is a bad hack - it destroys the current output buffer, the correct routine for writing numbers is n_Write (which is a little bit uneasy to use because it outputs into a buffer, not the screen)