% This is the dictionary file for C debugging. Dictionary entries are specified as % follows, where LIST means a list in standard prolog form: % % 1) For a new 'involves' classification: % % classify(, , ), % where is the name of the classification, % is a LIST of valid values for the classification, and % is the prompt to present to the user when asking about the classification. % % 2) For a new solution: % % solution :- involves(), suggest(''). % where is a LIST of CLASSLISTs. Each CLASSLIST consists of % a followed by acceptable values for this particular solution. % is the text you wish to present to the user as your solution. % % 3) For a new help entry: % % help(, ''). % Where is the text you wish to present to the user when prompted for help % on . % % See below for examples. classify(user, [beginner, intermediate, advanced], 'What is your level of experience with C programming?'). classify(error, [runtime, compilation], 'Is the error a runtime or compilation error (or warning)?'). classify(leak, [yes, no, maybe], 'Is your program leaking or using excessive memory?'). classify(malloc, [yes, no], 'Did you use malloc() or any similar memory allocation function?'). classify(pointers, [yes, no], 'Did you use any pointers in your program?'). classify(float, [yes, no], 'Did you use the float data type in your program?'). classify(function, [yes, maybe, no], 'Did you define a function in your program which is causing the problem?'). classify(parse_error, [yes, no], 'Did the compiler return a parse error?'). classify(warning, [yes, no], 'Did the compiler give you a warning message?'). classify(arguement_converted, [yes, no], 'Did the compiler warn you about an arguement type being converted?'). classify(recursion, [yes, no], 'Did you use recursion?'). classify(undefined_symbol, [yes, no], 'Did you receive an undefined symbol error from the compiler?'). classify(scanf, [yes, no], 'Did you use the scanf function?'). classify(input_crash, [yes, no], 'Does it crash after the user supplies input?'). classify(bad_output, [yes, no], 'Do you get garbage or incorrect output?'). classify(files, [yes, no], 'Does the problem involve opening a file?'). classify(null_file_pointer, [yes, no], 'Did an fopen() or similar function return a null file pointer?'). classify(security_issue, [yes, no], 'Is it a security related bug?'). classify(incompatible_assignment, [yes, no], 'Is the compiler warning you about incompatible data types?'). classify(will_not_run, [yes, no], 'Are you unable to execute the program at all?'). classify(char_array, [yes, no], 'Did you use a char array or string in your program?'). classify(bit_shifting, [yes, no], 'Did you do any bit level manipulation?'). classify(buffer_overrun, [yes, maybe, no], 'Is it possible you have a buffer overrun?'). help(user, 'A beginner is someone just starting out with C, who has little experience with the quirks of the C language. An intermediate user has experience with C, but is not expert at it. An advanced user has solid programming experience with C, and is assumed to have encountered a difficult problem.'). help(error, 'A runtime error occurs if you attempt to run your program. A compilation error occurs if the compiler issues warnings or errors.'). help(leak, 'A program is leaking memory if it appears to use more and more memory until it eventually runs out, or if it simply isn''t freeing memory that it should be freeing.'). help(security_issue, 'A security issue is something which involves the user intentionally attempting to crash your program.'). solution(missing_header) :- involves([[error, compilation], [user, beginner, intermediate], [warning, yes], [arguement_converted, yes], [function, no, maybe]]), suggest('It sounds like you are missing a header file. Make sure that all the header files for the C functions you''ve used are #include-d.'). solution(use_string_reference) :- involves([[error, compilation], [user, beginner, intermediate], [warning, yes], [arguement_converted, yes], [char_array, yes]]), suggest('You may be using a char instead of a pointer to a string of chars (which must be null terminated). For instance, use the name of the char array with no array index following it.'). solution(use_semicolon) :- involves([[error, compilation], [user, beginner], [parse_error, yes]]), suggest('You probably forgot a semi-colon at the end of a line, or added one where it didn''t belong.'). solution(check_parens) :- involves([[error, compilation], [user, beginner, intermediate], [parse_error, yes]]), suggest('You probably misplaced some () or {} pairs... double check them. Semicolons are another possibility, as are misplaced commas.'). solution(use_iterative) :- involves([[error, runtime], [function, yes, maybe], [recursion, yes]]), suggest('If your program is taking a very long time to solve a problem, or is crashing due to stack overflow or excessive memory usage, it is likely that the problem is your recursive function. Consider using an iterative solution instead if possible, or try using Dynamic Programming methods.'). solution(use_free) :- involves([[error, runtime], [leak, yes, maybe], [malloc, yes], [pointers, yes], [user, beginner, intermediate]]), suggest('Make sure you properly free() your malloc-ed memory BEFORE you reassign your last pointer to that memory block.'). solution(float_to_double) :- involves([[float, yes], [error, runtime], [user, beginner, intermediate]]), suggest('This expert recommends changing all instances of the float data type to the double data type, and replacing all instances of %f with %lf.'). solution(strcpy_or_strcat) :- involves([[error, runtime], [leak, yes, maybe], [malloc, no], [user, beginner, intermediate]]), suggest('You are probably making improper use of strcpy or strcat. Check documentation.'). solution(include_library) :- involves([[error, compiletime], [user, beginner, intermediate], [undefined_symbol, yes]]), suggest('Perhaps you forgot to include a library, such as the C math library, included with the -lm option.'). solution(dont_use_scanf) :- involves([[error, runtime], [scanf, yes], [user, beginner, intermediate], [input_crash, yes]]), suggest('You might want to try using fgets() or gets() instead of scanf(), and converting the result with the atof() or atoi() as necessary.'). solution(gets_returns_pointer) :- involves([[error, runtime], [scanf, no], [user, beginner, intermediate], [input_crash, yes]]), suggest('If you are using gets() or fgets() to read input, make sure that you are passing the function a valid pointer to malloc()ed memory or a char array large enough to hold the input.'). solution(check_post_input_code) :- involves([[error, runtime], [input_crash, yes], [user, beginner]]), suggest('You should check to make sure that the input from the user is being properly stored in the variable as expected by using a printf() to display the input, and then exiting. The crash most likely results from code following the input prompt.'). solution(use_fgets) :- involves([[error, runtime], [user, advanced], [security_issue, yes], [buffer_overrun, yes, maybe]]), suggest('Use fgets() rather than gets() or scanf() for all user input to prevent buffer overrun attacks.'). solution(file_badname) :- involves([[error, runtime], [files, yes], [user, beginner], [null_file_pointer, yes]]), suggest('Make sure that you have proper permissions for the file you are attempting to read or write to and that the filename is valid.'). solution(file_low_on_memory_or_handles) :- involves([[error, runtime], [files, yes], [null_file_pointer, yes]]), suggest('Make sure your program isn''t using too much memory. There may not be enough left to open your file. Also, make sure you haven''t exceeded the maximum number of open files supported by your OS.'). solution(check_algorithm) :- involves([[user, beginner], [bad_output, yes], [error, runtime]]), suggest('Add printf() statements at various points in your program to check your algorithm. Also, make sure your printf() statements use the correct % substitutions. Locate the exact place in your code where the error occurs.'). solution(type_cast) :- involves([[user, advanced], [error, compilation], [incompatible_assignment, yes]]), suggest('You should type cast before assigning different types to avoid unwanted warnings.'). solution(use_dot_slash) :- involves([[user, beginner], [error, runtime], [will_not_run, yes]]), suggest('Make sure you are compiling your program properly, that the name of your program does not conflict with another program name, and that you execute it properly from the command line. i.e. in UNIX, you may need to type: ./a.out'). solution(endian_problem) :- involves([[user, advanced], [error, runtime], [bad_output, yes], [bit_shifting, yes]]), suggest('Find out whether your machine is using a little endian or big endian data type.'). solution(make_global) :- involves([[user, beginner, intermediate], [error, compilation], [warning, yes], [pointers, yes]]), suggest('If the compiler is warning you about returning the address of a local variable, try making it global.').