Package daikon

Class Debug


  • public final class Debug
    extends Object
    Debug class used with the logger to create standardized output. It can be setup to track combinations of classes, program points, and variables. The most common class to track is an invariant, but any class can be used.

    This allows detailed information about a particular class/ppt/variable combination to be printed without getting lost in a mass of other information (which is a particular problem in Daikon due to the volume of data considered).

    Note that each of the three items (class, ppt, variable) must match in order for printing to occur.

    • Field Detail

      • debugTrackClass

        public static String[] debugTrackClass
        List of classes for logging. Each name listed is compared to the fully qualified class name. If it matches (shows up anywhere in the class name) it will be included in debug prints. This is not a regular expression match
        See Also:
        log(Logger, Class, Ppt, String)
      • function_binary_method

        public static @Nullable String function_binary_method
        Restrict function binary prints to the specified method. Implementation is in the FunctionBinary specific log functions. If null, there is no restriction (all function binary methods are printed). See Functions.java for a list of function names.
      • debugTrackPpt

        public static String[] debugTrackPpt
        List of Ppts for logging. Each name listed is compared to the full program point name. If it matches (shows up anywhere in the ppt name) it will be included in the debug prints. This is not a regular expression match.
        See Also:
        log(Logger, Class, Ppt, String)
      • debugTrackVars

        public static String[][] debugTrackVars
        List of variable names for logging. Each name listed is compared to each variable in turn. If each matches exactly it will be included in track debug prints. This is not a regular expression match. Note that the number of variables must match the slice exactly.
        See Also:
        log(Logger, Class, Ppt, String)
      • cache_match

        public boolean cache_match
        True if the cached values should be printed --- that is, they match what is currently being debugged.
      • cache_class

        public @Nullable Class<?> cache_class
        cached class: class to use by default when calling variants of log() with few arguments
      • cache_ppt

        public @Nullable Ppt cache_ppt
        cached ppt: ppt to use by default when calling variants of log() with few arguments
      • cache_vis

        public VarInfo @Nullable [] cache_vis
        Cached variables: variables to use by default when calling variants of log() with few arguments.
      • dkconfig_internal_check

        public static boolean dkconfig_internal_check
        When true, perform detailed internal checking. These are essentially additional, possibly costly assert statements.
      • dkconfig_show_stack_trace

        public static boolean dkconfig_show_stack_trace
        If true, show stack traces for errors such as file format errors.
    • Constructor Detail

      • Debug

        public Debug​(Class<?> c,
                     Ppt ppt,
                     VarInfo[] vis)
        Ordinarily, a client would have to supply a Class, Ppt, and List<Varinfo> with each call to a log method. This constructor sets as defaults c, ppt, and whatever variable (if any) from vis that is on the debugTrackVar list. Essentially this creates a debug object that will print if any of the variables in vis are being tracked (and c and ppt match).
      • Debug

        public Debug​(Class<?> c,
                     Ppt ppt,
                     List<VarInfo> vis)
        Ordinarily, a client would have to supply a Class, Ppt, and List<Varinfo> with each call to a log method. This constructor sets as defaults c, ppt, and whatever variable (if any) from vis that is on the debugTrackVar list. Essentially this creates a debug object that will print if any of the variables in vis are being tracked (and c and ppt match).
    • Method Detail

      • newDebug

        public static @Nullable Debug newDebug​(Class<?> c,
                                               Ppt ppt,
                                               VarInfo[] vis)
        Returns a Debug object if the specified class, ppt, and vis match what is being tracked. Otherwise, return NULL. Preferred over calling the constructor directly, since it doesn't create the object if it doesn't have to.
      • visTracked

        public @Nullable VarInfo visTracked​(@UnknownInitialization Debug this,
                                            List<VarInfo> vis)
        Looks for each of the variables in vis in the DebugTrackVar list. If any match, returns that variable. Returns null if there are no matches.
      • logDetail

        public static final boolean logDetail()
        Returns whether or not detailed logging is on. Note that this check is not performed inside the logging calls themselves, it must be performed by the caller.
        See Also:
        log(Logger, Class, Ppt, String), logOn()
      • log

        public static void log​(Logger debug,
                               @Nullable Class<?> inv_class,
                               @Nullable Ppt ppt,
                               VarInfo @Nullable [] vis,
                               String msg)
        Logs a description of the class, ppt, variables and the specified msg via the logger. The class, ppt, and variables are checked against those described in debugTrackClass, debugTrackPpt, and debugTrackVars. Only those that match are printed. Variables will match if they are in the same equality set. The information is written as:

        class: ppt : var1 : var2 : var3 : msg

        Note that if debugTrack is not enabled then nothing is printed. It is somewhat faster to check logOn() directly rather than relying on the check here.

        Other versions of this method (noted below) work without the Logger parameter and take class, ppt, and vis from the cached values, which were set by the constructor or by the set() method.

        Parameters:
        debug - a second Logger to query if debug tracking is turned off or does not match. If this logger is enabled, the same information will be written to it. Note that the information is never written to both loggers.
        inv_class - the class. Can be obtained in a static context by ClassName.class
        ppt - program point
        vis - variables at the program point. These are sometimes different from the ones in the ppt itself.
        msg - string message to log
        See Also:
        logOn(), logDetail(), log(Class, Ppt, VarInfo[], String), log(Class, Ppt, String), log(Logger, String), log(String)
      • log

        public static boolean log​(@Nullable Class<?> inv_class,
                                  @Nullable @UnknownInitialization(PptTopLevel.class) Ppt ppt,
                                  VarInfo @Nullable [] vis,
                                  String msg)
        Logs a description of the class, ppt, variables and the specified msg via the logger as described in log(Logger, Class, Ppt, String). Accepts vis because sometimes the variables are different from those in the ppt.
        Returns:
        whether or not it logged anything
      • class_match

        public static boolean class_match​(@Nullable Class<?> inv_class)
        Returns whether or not the specified class matches the classes being tracked.
      • ppt_match

        public static boolean ppt_match​(@Nullable @UnknownInitialization(PptTopLevel.class) Ppt ppt)
        Returns whether or not the specified ppt matches the ppts being tracked.
      • var_match

        public static boolean var_match​(VarInfo @Nullable [] vis)
        Returns whether or not the specified vars match the ones being tracked. Also, sets Debug.ourvars with the names of the variables matched if they are not the leader of their equality sets.
      • check

        public static void check​(PptMap all_ppts,
                                 String msg)
        Looks through entire ppt tree and checks for any items we are interested in. If found, prints them out.
      • related_vars

        public static String related_vars​(PptTopLevel ppt,
                                          ValueTuple vt)
        Returns a string containing the variable values for any variables that are currently being tracked in ppt. The string is of the form 'v1 = val1: v2 = val2, etc.
      • toString

        public static String toString​(@Nullable Object val)
        Like Object.toString(), but handles null, and has special handling for arrays.
      • toString

        public static String toString​(VarInfo[] vis,
                                      ValueTuple vt)
        Returns a string containing each variable and its value.

        The string is of the form "v1 = val1: v2 = val2, ...".

      • add_track

        public static @Nullable String add_track​(String def)
        Parses the specified argument to --track and sets up the track arrays accordingly. The syntax of the argument is
        class|class|...<var,var,var>@ppt
        As shown, multiple class arguments can be specified separated by pipe symbols (|). The variables are specified in angle brackets (<>) and the program point is preceeded by an at sign (@). Each is optional and can be left out. The add_track routine can be called multiple times. An invariant that matches any of the specifications will be tracked.