nachos
Class Debug

java.lang.Object
  extended by nachos.Debug

public class Debug
extends java.lang.Object

This class contains debugging methods for generating user-selectable debugging printout and for placing assertions in the code that terminate execution and print debugging messages when they fail. The user can select which debugging printout will be generated by the command line argument (-d) passed to Nachos. See the comments in this class for a list of the pre-defined debugging flags. You are also encouraged to add your own debugging flags.


Nested Class Summary
static class Debug.AssertException
          Exception used to terminate Nachos when an assertion fails.
 
Field Summary
private static java.lang.String enableFlags
          List of debugging flags for which printing is enabled.
 
Constructor Summary
Debug()
           
 
Method Summary
static void ASSERT(boolean condition)
          Equivalent of the C++ Nachos ASSERT macro.
static void ASSERT(boolean condition, java.lang.String msg)
          An optional form of ASSERT which allows us to print our own message.
static void init(java.lang.String[] args)
          Process command-line arguments and initialize the list of debugging flags for which printing is enabled.
static boolean isEnabled(char flag)
          Query whether printing is enabled for a specified debugging flag.
private static void kprintn(long l, int base)
          Print an integer value in a specified base.
static void print(char flag, java.lang.String text)
          Print a debugging message if a specified flag is enabled.
static void printf(char flag, java.lang.String format, java.lang.Object o1)
          Convenience version of printf for printing one object.
static void printf(char flag, java.lang.String format, java.lang.Object[] o)
          A C-style printing function that uses a format string to control the printing of an array of objects.
static void printf(char flag, java.lang.String format, java.lang.Object o1, java.lang.Object o2)
          Convenience version of printf for printing two objects.
static void printf(char flag, java.lang.String format, java.lang.Object o1, java.lang.Object o2, java.lang.Object o3)
          Convenience version of printf for printing three objects.
static void printf(char flag, java.lang.String format, java.lang.Object o1, java.lang.Object o2, java.lang.Object o3, java.lang.Object o4)
          Convenience version of printf for printing four objects.
static void println(char flag, java.lang.String text)
          Print a debugging message, followed by a newline, if a specified flag is enabled.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

enableFlags

private static java.lang.String enableFlags
List of debugging flags for which printing is enabled.

Constructor Detail

Debug

public Debug()
Method Detail

ASSERT

public static void ASSERT(boolean condition)
Equivalent of the C++ Nachos ASSERT macro. Comes to a screeching halt when the condition is false. (Nifty thing about the JVM is that it'll print out a full stack trace, automatically. All we have to do is throw an exception.)

Parameters:
condition - If false, the assertion fails and an exception is thrown.

ASSERT

public static void ASSERT(boolean condition,
                          java.lang.String msg)
An optional form of ASSERT which allows us to print our own message.

Parameters:
condition - If false, the assertion fails and an exception is thrown.
msg - The message to be printed in case of failure.

init

public static void init(java.lang.String[] args)
Process command-line arguments and initialize the list of debugging flags for which printing is enabled.

Parameters:
args - Command-line arguments.

isEnabled

public static boolean isEnabled(char flag)
Query whether printing is enabled for a specified debugging flag.

Parameters:
flag - The flag to be queried.
Returns:
true if the flag is enabled, otherwise false.

print

public static void print(char flag,
                         java.lang.String text)
Print a debugging message if a specified flag is enabled.

Parameters:
flag - The flag.
text - The message.

println

public static void println(char flag,
                           java.lang.String text)
Print a debugging message, followed by a newline, if a specified flag is enabled.

Parameters:
flag - The flag.
text - The message.

printf

public static void printf(char flag,
                          java.lang.String format,
                          java.lang.Object o1)
Convenience version of printf for printing one object.


printf

public static void printf(char flag,
                          java.lang.String format,
                          java.lang.Object o1,
                          java.lang.Object o2)
Convenience version of printf for printing two objects.


printf

public static void printf(char flag,
                          java.lang.String format,
                          java.lang.Object o1,
                          java.lang.Object o2,
                          java.lang.Object o3)
Convenience version of printf for printing three objects.


printf

public static void printf(char flag,
                          java.lang.String format,
                          java.lang.Object o1,
                          java.lang.Object o2,
                          java.lang.Object o3,
                          java.lang.Object o4)
Convenience version of printf for printing four objects.


printf

public static void printf(char flag,
                          java.lang.String format,
                          java.lang.Object[] o)
A C-style printing function that uses a format string to control the printing of an array of objects.

Parameters:
flag - If true, then do the printing, otherwise don't.
format - C-style format string.
o - Array of objects to be printed.

kprintn

private static void kprintn(long l,
                            int base)
Print an integer value in a specified base.

Parameters:
l - The value to print.
base - The base in which to print the value.