Debugging and error checking.
[Hints and documentation for developers]

Depending on configure options (--enable-debug, --enable-release) and system state (valgrind found) various debug and error check functions are compiled out. More...

Defines

#define DEBUGP(...)   do { if (debuglevel) _DEBUGP(__FILE__, __LINE__, __PRETTY_FUNCTION__, __VA_ARGS__); } while (0)
 The macro used for printing debug messages.

Functions

void _DEBUGP (const char *file, int line, const char *func, char *format,...) __attribute__((format(printf
 Declaration of the debug function.

Error-printing and -handling functions.

Except for the subversion-library wrapper macros they need exactly this function layout:

   int some_function( ... some args ... )
   {
     int status;

     STOPIF( function_call(1, 2, "a"), 
       "String describing the error situation with %s",
       "parameters as needed");

   ex:
     cleanups();
     return status;
   }

It works by checking the return value; if it is not zero, a goto ex is done. At this mark some cleanup is possible.



int make_STOP_silent
 A flag to turn error printing temporarily off.
int _STOP (const char *file, int line, const char *function, int errl, const char *format,...) __attribute__((format(printf
 Master error function.
#define STOPIF_FULLPARM(cond, status, code, go,...)
 Completely customizable error call macro.
#define STOPIF_CODE_ERR_GOTO(cond, code, ex,...)   STOPIF_FULLPARM(cond, status, code, ex, __VA_ARGS__)
 Another error call macro.
#define STOPIF_CODE_ERR(cond, code,...)   STOPIF_CODE_ERR_GOTO(cond, code, ex, __VA_ARGS__)
 Error call macro for system functions.
#define STOPIF(code,...)
#define STOPIF_ENOMEM(cond)   STOPIF_CODE_ERR(cond, ENOMEM, NULL)
 A simplified error call macro for returning ENOMEM.
#define STOPIF_CODE_EPIPE(code,...)
 An error return macro that is used for user output - special handling EPIPE to get a silent return.
#define STOPIF_SVNERR_TEXT(func, parm, fmt,...)
 The master error macro for calling subversion functions.
#define STOPIF_SVNERR(func, parm)   STOPIF_SVNERR_TEXT(func, parm, #func)
#define STOP_HANDLE_SVNERR(svnerr)   STOPIF_CODE_ERR_GOTO(svnerr, svnerr->apr_err, ex2, (const char*)svnerr->message)
 Convert the svn_error_t into a message and a returnable integer.
#define RETURN_SVNERR(status)
 The opposite to STOP_HANDLE_SVNERR(); this converts an status to the svn_error_t.

Runtime check macros



#define BUG(...)   do { fflush(NULL); debuglevel=1; DEBUGP(__VA_ARGS__); *(int*)42=__LINE__; } while (0)
 Makes the program abort.
#define BUG_ON(cond,...)   do { if (cond) BUG( "INTERNAL BUG\n " #cond "\n " __VA_ARGS__); } while (0)
 The same as BUG(), but conditionalized.

Valgrind memory addressing checking.

These are copied from valgrind/memcheck.h; they will be overridden by the correct valgrind definitions if the valgrind headers are found and fsvs is configured with --enable-debug.



#define VALGRIND_MAKE_MEM_NOACCESS(_qzz_addr, _qzz_len)   do { } while(0)
#define VALGRIND_MAKE_MEM_UNDEFINED(_qzz_addr, _qzz_len)   do { } while(0)
#define VALGRIND_MAKE_MEM_DEFINED(_qzz_addr, _qzz_len)   do { } while(0)

Detailed Description

Depending on configure options (--enable-debug, --enable-release) and system state (valgrind found) various debug and error check functions are compiled out.

Makes the binary much smaller, but leaves no chance for debugging.

Subversion library calls wrapper.

If this is used in some function, an additional variable is needed:

   int some_function( <em> ... some args ... </em> )
   {
     int status;
     svn_error_t *status_svn;

     STOPIF_SVNERR( <em>svn_function</em>, 
       (<em>parameters ...</em>) );

   ex:
     STOP_HANDLE_SVNERR(status_svn);
   ex2:
     <em> ... cleanups here ... </em>
     return status;
   }

Define Documentation

#define BUG ( ...   )     do { fflush(NULL); debuglevel=1; DEBUGP(__VA_ARGS__); *(int*)42=__LINE__; } while (0)

Makes the program abort.

If the configure had --enable-debug and gdb is in the path, try to use gdb to debug this problem (only if STDIN and STDOUT are ttys).

Definition at line 807 of file global.h.

Referenced by ci__nondir(), df___repos_repos(), df___type_def_diff(), df__work(), ign__compile_pattern(), ign__is_ignore(), log__work(), ops__build_path(), ops__traverse(), rev___undo_change(), rev__install_file(), wa__warn(), and waa__get_waa_directory().

#define BUG_ON ( cond,
...   )     do { if (cond) BUG( "INTERNAL BUG\n " #cond "\n " __VA_ARGS__); } while (0)

The same as BUG(), but conditionalized.

   BUG_ON(a == b, "HELP")

would print INTERNAL BUG a == b HELP and try to start gdb or abort.

Definition at line 817 of file global.h.

Referenced by ac__dispatch(), au__action(), cb___remover(), cb__init(), cch__set_active(), ci___base_dirs(), ci__nondir(), cm___absolute_path(), cm___get_base_source(), cm___get_sub_source_rek(), cm___make_copy(), cm___match(), cm___match_children(), cm___output_pct(), cm___rev_path_to_string(), cs___manber_data_init(), cs___update_manber(), cs__read_manber_hashes(), df___print_meta(), dir__enumerator(), dir__sortbyinode(), hlp__format_path(), hlp__rev_to_string(), hlp__strmnalloc(), hsh__insert_pointer(), hsh__list_get(), ign___load_group(), ign___test_all_patterns(), ign___test_single_pattern(), ign__new_pattern(), log__receiver(), ops___dev_to_string(), ops__allocate(), ops__allowed_by_filter(), ops__apply_group(), ops__delete_entry(), ops__find_entry_byinode(), ops__find_entry_byname(), ops__free_entry(), ops__free_marked(), ops__link_to_string(), ops__load_1entry(), ops__make_shadow_entry(), ops__save_1entry(), ops__stat_to_action(), ops__traverse(), prp__fetch(), prp__first(), prp__next(), prp__set(), res__remove_aux_files(), rev__install_file(), st__print_status(), st__status(), up__change_file_prop(), up__close_file(), up__parse_prop(), url__canonical_rev(), url__close_session(), url__open_session(), url__output_list(), waa___find_position(), waa___finish_directory(), waa__create_working_copy(), waa__delete_byext(), waa__find_common_base2(), waa__get_tmp_name(), waa__get_waa_directory(), waa__input_tree(), waa__mkdir_mask(), waa__open(), waa__output_tree(), waa__partial_update(), and waa__set_working_copy().

#define DEBUGP ( ...   )     do { if (debuglevel) _DEBUGP(__FILE__, __LINE__, __PRETTY_FUNCTION__, __VA_ARGS__); } while (0)

The macro used for printing debug messages.

Includes time, file, line number and function name. Allows filtering via opt_debugprefix.

Note:
Check for argument sizes.

Definition at line 651 of file global.h.

Referenced by _DEBUGP(), _DEBUGP_open_output(), _st___string_from_bits(), ac___up_set_paths(), ac__dispatch(), au__action(), au__prepare_for_added(), bld__work(), cb___absent_directory(), cb___absent_file(), cb___close_file(), cb___delete_entry(), cb___remover(), cb___report_path_rev(), cb___set_target_revision(), cb___store_prop(), cb__add_entry(), cb__record_changes_mixed(), cch__hash_find(), ci___base_dirs(), ci___send_user_props(), ci__nondir(), ci__work(), cm___absolute_path(), cm___get_base_source(), cm___get_sub_source_rek(), cm___ignore_impl_copied(), cm___match(), cm___match_children(), cm___register_entry(), cm___string_to_rev_path(), cm__detect(), cm__find_copied(), cm__find_file_source(), cm__get_source(), cm__uncopy(), cm__work(), co__work(), cs___end_of_block(), cs___update_manber(), cs__compare_file(), cs__new_manber_filter(), cs__read_manber_hashes(), DEBUGP_dump_estat(), delay__work(), df___cleanup(), df___colordiff(), df___direct_diff(), df___print_meta(), df___repos_repos(), df___signal(), df__do_diff(), df__work(), dir__enumerator(), hlp___do_convert(), hlp___encode_close(), hlp___encode_read(), hlp___encode_write(), hlp__chrooter(), hlp__delay(), hlp__encode_filter(), hlp__format_path(), hlp__fstat(), hlp__lstat(), hlp__match_path_envs(), hlp__pathcopy(), hlp__rename_to_unique(), hlp__stream_md5(), hlp__string_from_filep(), hsh__close(), hsh__collect_garbage(), hsh__register_delete(), ign___init_pattern_into(), ign___load_group(), ign___new_group(), ign__compile_pattern(), ign__is_ignore(), ign__load_list(), ign__new_pattern(), ign__save_ignorelist(), ign__work(), log__receiver(), log__work(), main(), ops__allocate(), ops__apply_group(), ops__build_path(), ops__correlate_dirs(), ops__delete_entry(), ops__find_entry_byname(), ops__free_entry(), ops__read_special_entry(), ops__save_1entry(), ops__set_todo_bits(), ops__stat_to_action(), ops__update_filter_set_bits(), ops__update_single_entry(), opt___strings2bitmap(), opt__load_env(), opt__load_settings(), opt__parse(), prp__fetch(), prp__g_work(), prp__l_work(), prp__s_work(), prp__set_from_aprhash(), prp__store(), rev___handle_dir_mtime(), rev___local_revert(), rev___revert_to_base(), rev___undo_change(), rev__do_changed(), rev__get_text_to_stream(), rev__install_file(), rev__merge(), sigPipe(), sigUSR1(), sigUSR2(), st__print_status(), st__progress(), st__status(), sync___recurse(), up__absent_directory(), up__absent_file(), up__apply_textdelta(), up__close_file(), up__handle_special(), up__parse_prop(), up__rmdir(), up__set_meta_data(), up__unlink(), up__work(), url___set_internal_nums(), url__canonical_rev(), url__close_session(), url__find_by_intnum(), url__find_by_name(), url__find_by_url_in_list(), url__iterator2(), url__load_list(), url__mark_todo(), url__open_session(), url__output_list(), url__parse(), url__work(), wa__set_warn_option(), wa__summary(), waa___check_dir_for_update(), waa___find_position(), waa___finish_directory(), waa___get_path_md5(), waa__build_tree(), waa__close(), waa__delete_byext(), waa__dir_enum(), waa__find_common_base2(), waa__get_waa_directory(), waa__init(), waa__input_tree(), waa__mkdir_mask(), waa__open(), waa__output_tree(), waa__partial_update(), waa__read_or_build_tree(), waa__update_dir(), and waa__update_tree().

#define RETURN_SVNERR ( status   ) 
#define STOP_HANDLE_SVNERR ( svnerr   )     STOPIF_CODE_ERR_GOTO(svnerr, svnerr->apr_err, ex2, (const char*)svnerr->message)

Convert the svn_error_t into a message and a returnable integer.

Definition at line 791 of file global.h.

Referenced by ci__work(), exp__do(), log__work(), sync__work(), and up__work().

#define STOPIF ( code,
...   ) 
Value:
do                                                \
{                                                   \
    status=(code);                                    \
    if (status)                                                         \
    {                                                                                                   \
        _STOP(__FILE__, __LINE__, __PRETTY_FUNCTION__, status, __VA_ARGS__);   \
        goto ex;                                        \
    }                                                                                                   \
} while (0)

Definition at line 720 of file global.h.

Referenced by _st___string_from_bits(), ac___up_set_paths(), ac__dispatch(), ac__Usage(), au__action(), au__prepare_for_added(), au__work(), bld__work(), cat__work(), cb___add_directory(), cb___add_file(), cb___change_dir_prop(), cb___change_file_prop(), cb___close(), cb___close_directory(), cb___close_file(), cb___delete_entry(), cb___open_directory(), cb___open_file(), cb___remover(), cb___report_path_rev(), cb___store_prop(), cb__add_entry(), cb__init(), cb__open_tmp(), cb__record_changes(), cb__record_changes_mixed(), cb__remove_from_url(), cb__remove_url(), cch__entry_set(), cch__hash_add(), ci___send_user_props(), ci__action(), ci__getmsg(), ci__nondir(), ci__work(), cm___absolute_path(), cm___dump_list(), cm___get_base_source(), cm___get_sub_source(), cm___make_copy(), cm___match(), cm___match_children(), cm___register_entry(), cm___rev_path_to_string(), cm__detect(), cm__find_copied(), cm__find_dir_source(), cm__find_file_source(), cm__uncopy(), cm__work(), co__work(), cs___finish_manber(), cs___manber_data_init(), cs___mnbs_close(), cs___mnbs_read(), cs___mnbs_write(), cs___update_manber(), cs__compare_file(), cs__new_manber_filter(), cs__read_manber_hashes(), delay__work(), df___cleanup(), df___diff_wc_remote(), df___direct_diff(), df___repos_repos(), df___type_def_diff(), df__do_diff(), df__work(), dir__enumerator(), dir__get_dir_size(), dir__sortbyname(), exp__do(), exp__work(), hlp___do_convert(), hlp___dummy_convert(), hlp___encode_read(), hlp___encode_write(), hlp__encode_filter(), hlp__format_path(), hlp__get_gid(), hlp__get_uid(), hlp__local2utf8(), hlp__match_path_envs(), hlp__rename_to_unique(), hlp__stream_md5(), hlp__string_from_filep(), hlp__strmnalloc(), hlp__strnalloc(), hlp__utf82local(), hsh___new_bare(), hsh__close(), hsh__insert_pointer(), hsh__list_get(), hsh__new(), hsh__register_delete(), ign___init_pattern_into(), ign___load_group(), ign___new_group(), ign___test_all_patterns(), ign___test_single_pattern(), ign___translate_bracketed_expr(), ign__compile_pattern(), ign__is_ignore(), ign__load_list(), ign__new_pattern(), ign__rign(), ign__save_ignorelist(), ign__work(), info__action(), info__work(), log__receiver(), log__work(), main(), ops__allocate(), ops__apply_group(), ops__build_path(), ops__correlate_dirs(), ops__delete_entry(), ops__find_entry_byinode(), ops__find_entry_byname(), ops__free_entry(), ops__free_marked(), ops__link_to_string(), ops__load_1entry(), ops__make_shadow_entry(), ops__new_entries(), ops__read_special_entry(), ops__save_1entry(), ops__traverse(), ops__update_filter_set_bits(), ops__update_single_entry(), opt___debug_buffer(), opt___parse_warnings(), opt___store_string(), opt___string2val(), opt__load_env(), opt__load_settings(), opt__parse(), opt__parse_option(), prp__g_work(), prp__l_work(), prp__open_byestat(), prp__open_byname(), prp__open_get_close(), prp__s_work(), prp__set(), prp__set_from_aprhash(), prp__store(), prp__unlink_db_for_estat(), res__action(), res__mark_conflict(), res__remove_aux_files(), res__work(), rev___handle_dir_mtime(), rev___local_revert(), rev___revert_to_base(), rev___undo_change(), rev__do_changed(), rev__get_props(), rev__get_text_into_buffer(), rev__get_text_to_stream(), rev__get_text_to_tmpfile(), rev__install_file(), rev__merge(), rev__work(), st__action(), st__print_entry_info(), st__print_status(), st__rm_status(), st__status(), st__work(), sync___recurse(), sync__progress(), sync__work(), up__add_directory(), up__add_file(), up__apply_textdelta(), up__change_dir_prop(), up__change_file_prop(), up__close_directory(), up__close_file(), up__fetch_decoder(), up__handle_special(), up__parse_prop(), up__rmdir(), up__set_meta_data(), up__unlink(), up__work(), url__allocate(), url__close_sessions(), url__full_url(), url__insert_or_replace(), url__iterator2(), url__load_list(), url__mark_todo(), url__open_session(), url__other_full_url(), url__output_list(), url__parse(), url__store_url_name(), url__work(), wa__split_process(), waa___check_dir_for_update(), waa___finish_directory(), waa___get_path_md5(), waa___recurse_tree(), waa__build_tree(), waa__close(), waa__copy_entries(), waa__create_working_copy(), waa__delete_byext(), waa__dir_enum(), waa__do_sorted_tree(), waa__find_base(), waa__find_common_base2(), waa__get_tmp_name(), waa__get_waa_directory(), waa__given_or_current_wd(), waa__init(), waa__input_tree(), waa__make_info_link(), waa__mkdir(), waa__mkdir_mask(), waa__new_entry_block(), waa__open(), waa__open_byext(), waa__output_tree(), waa__partial_update(), waa__read_or_build_tree(), waa__save_cwd(), waa__set_working_copy(), waa__update_dir(), and waa__update_tree().

#define STOPIF_CODE_EPIPE ( code,
...   ) 
Value:
do                                                   \
{                                                      \
    if ((code) < 0)                                      \
    {                                                    \
        status=errno;                                      \
        if (status == EPIPE) status= -EPIPE;               \
        STOPIF(status, "Error writing output");          \
    }                                                    \
} while (0)

An error return macro that is used for user output - special handling EPIPE to get a silent return.

If code returns something negative (like printf, puts, putc ... do; EOF is defined as -1), and error is EPIPE, go on with -EPIPE.

Definition at line 744 of file global.h.

Referenced by cm___match(), cm__detect(), df___diff_wc_remote(), df___direct_diff(), df___print_meta(), df___repos_repos(), df___type_def_diff(), df__do_diff(), hlp__safe_print(), ign___test_all_patterns(), ign___test_single_pattern(), ign__print_group_stats(), log__receiver(), prp__g_work(), prp__l_work(), rev___undo_change(), st__print_entry_info(), st__print_status(), url___dump(), url__open_session(), and wa__summary().

#define STOPIF_CODE_ERR ( cond,
code,
...   )     STOPIF_CODE_ERR_GOTO(cond, code, ex, __VA_ARGS__)

Error call macro for system functions.

Parameters:
cond The condition; TRUE means an error happened.
code The error code to return. Normally an E* value. This error macro is used mainly for system calls, where a certain value specifies that an error has happened and some other data (mostly errno) stores the detailed error code.

   STOPIF_CODE_ERR( fork("ls -la") == -1, errno, 
     "Fork() failed!");

Definition at line 715 of file global.h.

Referenced by act__find_action_by_name(), au__prepare_for_added(), cat__work(), cb__add_entry(), ci__action(), ci__getmsg(), ci__work(), cm___dump_list(), cm___make_copy(), cm__detect(), cm__uncopy(), cm__work(), co__work(), cs___update_manber(), cs__char2md5(), cs__compare_file(), cs__read_manber_hashes(), df___cheap_colordiff(), df___cleanup(), df___colordiff(), df___print_meta(), df___type_def_diff(), df__do_diff(), df__work(), dir__close(), dir__enumerator(), dir__start_enum(), exp__invalid(), exp__work(), hlp___do_convert(), hlp___encode_close(), hlp___encode_filter_child(), hlp___encode_read(), hlp___encode_write(), hlp___encoder_waiter(), hlp___get_conv_handle(), hlp__calloc(), hlp__chrooter(), hlp__encode_filter(), hlp__parse_rev(), hlp__realloc(), hsh___new_bare(), hsh__collect_garbage(), hsh__register_delete(), hsh__store(), ign___init_pattern_into(), ign___load_group(), ign___parse_position(), ign___translate_bracketed_expr(), ign__compile_pattern(), ign__is_ignore(), ign__load_list(), ign__save_ignorelist(), info__work(), log__receiver(), log__work(), ops__link_to_string(), ops__read_special_entry(), ops__save_1entry(), ops__string_to_dev(), ops__traverse(), opt__parse(), res__mark_conflict(), res__remove_aux_files(), rev___undo_change(), rev__install_file(), rev__merge(), rev__work(), st__progress(), st__progress_uninit(), sync__work(), up__add_directory(), up__apply_textdelta(), up__close_file(), up__handle_special(), up__set_meta_data(), up__unlink(), up__work(), url___dump(), url___set_internal_nums(), url__insert_or_replace(), url__load_list(), url__load_nonempty_list(), url__output_list(), url__parse(), url__work(), wa__set_warn_option(), wa__summary(), wa__warn(), waa__build_tree(), waa__close(), waa__find_base(), waa__find_common_base2(), waa__init(), waa__input_tree(), waa__make_info_link(), waa__mkdir_mask(), waa__output_tree(), waa__partial_update(), waa__save_cwd(), and waa__update_dir().

#define STOPIF_CODE_ERR_GOTO ( cond,
code,
ex,
...   )     STOPIF_FULLPARM(cond, status, code, ex, __VA_ARGS__)

Another error call macro.

Normally not used.

Definition at line 704 of file global.h.

Referenced by df___colordiff(), and url__work().

#define STOPIF_ENOMEM ( cond   )     STOPIF_CODE_ERR(cond, ENOMEM, NULL)

A simplified error call macro for returning ENOMEM.

   void *x;

   x=malloc(1024);
   STOPIF_ENOMEM(!x);

Definition at line 738 of file global.h.

Referenced by cs__new_manber_filter(), and hlp__encode_filter().

#define STOPIF_FULLPARM ( cond,
status,
code,
go,
...   ) 
Value:
do                                                  \
{                                                   \
    if (cond)                                         \
    {                                                 \
        status=code;                                                                        \
        _STOP(__FILE__, __LINE__, __PRETTY_FUNCTION__, code, __VA_ARGS__);   \
        goto go;                                        \
    }                                                 \
} while (0)

Completely customizable error call macro.

Seldom used, as all things are parametrized.

Note:
This is like SVN_ERR(), but has one difference: The function is not simply ended (via return), cleanup is still possible.
Putting the make_STOP_silent check here enlarges the .text section of FSVS for about 3kByte!

Definition at line 692 of file global.h.

#define STOPIF_SVNERR ( func,
parm   )     STOPIF_SVNERR_TEXT(func, parm, #func)
#define STOPIF_SVNERR_TEXT ( func,
parm,
fmt,
...   ) 
Value:
do                                                       \
{                                                          \
    status_svn=func parm;                                    \
    STOPIF_CODE_ERR( status_svn, status_svn->apr_err,   \
            fmt ": %s", ## __VA_ARGS__, status_svn->message);  \
} while (0)

The master error macro for calling subversion functions.

Definition at line 775 of file global.h.

Referenced by rev__get_text_to_stream(), and url__open_session().

#define VALGRIND_MAKE_MEM_DEFINED ( _qzz_addr,
_qzz_len   )     do { } while(0)

Definition at line 829 of file global.h.

Referenced by ops__allocate(), and ops__free_entry().

#define VALGRIND_MAKE_MEM_NOACCESS ( _qzz_addr,
_qzz_len   )     do { } while(0)

Definition at line 827 of file global.h.

Referenced by ops__free_entry().

#define VALGRIND_MAKE_MEM_UNDEFINED ( _qzz_addr,
_qzz_len   )     do { } while(0)

Definition at line 828 of file global.h.


Function Documentation

void _DEBUGP ( const char *  file,
int  line,
const char *  func,
char *  format,
  ... 
)

Declaration of the debug function.

int _STOP ( const char *  file,
int  line,
const char *  function,
int  errl,
const char *  format,
  ... 
)

Master error function.


Variable Documentation

A flag to turn error printing temporarily off.

This is useful where entire calltrees would have to be equipped with some silent parameter.

A flag to turn error printing temporarily off.

Is there some better way? And I don't want to hear about using C++ templates and generating each function twice - once with output and once without! Maybe with some call that encapsulates this functionality, and uses some stack? Although we can simply increment/decrement this value.

Definition at line 342 of file fsvs.c.

Referenced by _STOP(), and co__work().


Generated for fsvs by  doxygen 1.6.1