debugging fixes
authoralex <[email protected]>
Thu, 15 Jul 2021 00:59:10 +0000 (17:59 -0700)
committeralex <[email protected]>
Thu, 15 Jul 2021 01:13:12 +0000 (18:13 -0700)
added "verbose" flag to seederd to allow for debugging
added --enable-debug ./configure flag to disable optimizations

configure.ac
seederd/inc/main.h
seederd/src/main.cpp

index b4a41683e11c043e6366c85fe5fee62efa425e1b..9a010ad04d71e1980578aecccf98d1cf7a917d32 100644 (file)
@@ -34,6 +34,8 @@ if test -z "$INOTIFYWAIT"; then
        AC_MSG_ERROR("inotifywait required");
 fi
 
+AC_ARG_VAR(SEEDER_DOMAIN,[hostname from which seeder is serving])
+
 dnl disable memcheck if valgrind not found
 if test "x$enable_memcheck" != "xno"; then
   if test -z "$VALGRIND"; then
@@ -48,10 +50,25 @@ else
   AC_MSG_RESULT(no)
 fi
 
-AC_ARG_VAR(SEEDER_DOMAIN,[hostname from which seeder is serving])
-
 AM_CONDITIONAL([ENABLE_MEMCHECK],[test x$enable_memcheck = xyes])
 
+dnl Enable debug
+AC_ARG_ENABLE([debug],
+    [AS_HELP_STRING([--enable-debug],
+                    [use compiler flags and macros suited for debugging (default is no)])],
+    [enable_debug=$enableval],
+    [enable_debug=no])
+
+AC_MSG_CHECKING([if debugging])
+if test x$enable_debug != xno; then
+  AC_MSG_RESULT(yes)
+  CFLAGS="-ggdb -O0"
+  CXXFLAGS="-ggdb -O0"
+else
+  AC_MSG_RESULT(no)
+fi
+
+AM_CONDITIONAL([ENABLE_DEBUG],[test x$enable_debug = xyes])
 
 # Checks for programs.
 AC_PROG_CC
index dcdcb49223a5b52143ca0cbea1b8df77e638ef6e..5d2b81bed442cf4c7e3f52f1cf8c2b66902c6cc7 100644 (file)
@@ -3,6 +3,7 @@
 
 #include<cstdlib>
 #include<filesystem>
+#include<getopt.h>
 #include<iostream>
 #include<signal.h>
 
index 35fb8d5b9376d7ea9c2b2aabc6c8d485e3ad450b..5604ebe4652fbaaff51683206ba8069a3f015368 100644 (file)
@@ -25,7 +25,35 @@ int setup_signal_handler() {
        return 1;
 }
 
+static struct option long_options[] = {
+       {"verbose", no_argument, 0, 'v'},
+       {0,0,0,0}
+};
+
 int main(int argc, char **argv) try {
+       char c;
+       bool verbose_flag = false;
+
+       while(1) {
+               int option_index = 0;
+
+               if((c = getopt_long(argc,argv,"v",long_options,&option_index))==-1) { break; }
+
+               switch(c) {
+                       case 0:
+                               break;
+                       case 'v':
+                               verbose_flag = true;
+                               std::cerr << "verbose mode enabled" << std::endl;
+
+                               break;
+                       case '?':
+                       default:
+                               std::cerr << "invalid option" << std::endl;
+                               return EXIT_FAILURE;
+               }
+       }
+
        if(setup_signal_handler()<0) { return EXIT_FAILURE; }
 
        std::cout << "creating required directories" << std::endl;
@@ -40,7 +68,22 @@ int main(int argc, char **argv) try {
        settings.set_int(lt::settings_pack::active_limit,-1);
        settings.set_str(lt::settings_pack::listen_interfaces,"0.0.0.0:6881,[::]:6881");
        settings.set_str(lt::settings_pack::user_agent,PACKAGE_STRING);
-//     settings.set_int(lt::settings_pack::alert_mask,(lt::alert::session_log_notification + lt::alert::torrent_log_notification));
+
+       if(verbose_flag) {
+               settings.set_int(lt::settings_pack::alert_mask, lt::alert::all_categories
+                       & ~(lt::alert::dht_notification
+                       + lt::alert::piece_progress_notification
+                       + lt::alert::block_progress_notification
+                       + lt::alert::progress_notification
+                       + lt::alert::stats_notification
+                       + lt::alert::session_log_notification
+                       + lt::alert::torrent_log_notification
+                       + lt::alert::peer_log_notification
+                       + lt::alert::dht_log_notification
+                       + lt::alert::picker_log_notification
+               ));
+       }
+
        lt::session session(settings);
 
        init(session);