Results 1 to 4 of 4

Thread: KDBG - debugger not printing value

  1. #1

    Default KDBG - debugger not printing value

    Using this function as part of the larger scanvirusbin code. If step I through the debugger, it will not print the value noted in the console window.

    When I run the command line, it displays and erases the counter. However, it skips numbers. I need to find out if it's working and the print buffer can't keep up.

    Command

    Code:
    Scan_Results_Filter("clamscan -r --follow-dir-symlinks=2 --follow-file-symlinks=2 --cross-fs=no /bin");

    Code:
    void Scan_Results_Filter(const char* cmd)
    {
         int filecounter;    
         int delete_line_flag;
         int scan_results_flag;
    
         FILE *FilePtr;
         #define LineSize 1024+1
         char cmdout[LineSize];
    
         filecounter = 0;    
         delete_line_flag= false;
         scan_results_flag= false;
         
         char ch;
    
     //noecho();
        //cbreak();    /* Line buffering disabled. pass on everything */
    
    
         if ((FilePtr = popen(cmd, "r")) == NULL)
              printf("clamscan: error opening pipe!\n");
              else
              {
                   while (fgets(cmdout, LineSize, FilePtr) != NULL)
                   {
                        if (delete_line_flag == true)  //break point
                        {
                             printf("\e[2K\r");
                             delete_line_flag= false;
                        }
    
                        //if scan summary then stop deleting lines
                        if (strstr(cmdout,"----------- SCAN SUMMARY -----------"))
                        {          
                             //printf("filecount= %d\n", filecounter);
                             scan_results_flag= true;
                        }
    
                        if (scan_results_flag == true)
                        {
                             printf("%s", cmdout);
                             continue;
                        }
                        else if (strstr(cmdout,": Symbolic"))
                             printf("%s\n", cmdout);
                        else if (strstr(cmdout,": FOUND"))
                        {
                             filecounter++;
                             printf("%s\n", cmdout);
                        }     
                        else if (strstr(cmdout,": MOVED TO"))
                             printf("%s\n", cmdout);
                        else if ( (strstr(cmdout,": OK")) || (strstr(cmdout,": EMPTY")) )
                        {
                             filecounter++;
                             if ((filecounter % 1) == 0)
                             {
                                  printf("%d", filecounter);  //no print
                                  delete_line_flag= true;
                                  //ch= getch();
                             }
                       }
                   }
    
                   if(pclose(FilePtr))
                        printf("clamscan: error closing pipe\n");
              }
    }
    #kdbg

    load source code --> opensource code --> run --> step into (repeat)

    Changing the printf statement still will not output text.

    Code:
    printf("%s", "filecounter");
    If I add a '\n', it will print the line. ??
    Last edited by lord_valarian; 13-Aug-2020 at 21:56. Reason: no tags

  2. #2
    Join Date
    Sep 2012
    Posts
    5,853

    Default Re: KDBG - debugger not printing value

    Quote Originally Posted by lord_valarian View Post
    If I add a '\n', it will print the line. ??
    output to terminal is line buffered by default. See "man stdio" and related manuals.

  3. #3

    Default Re: KDBG - debugger not printing value

    Quote Originally Posted by arvidjaar View Post
    output to terminal is line buffered by default. See "man stdio" and related manuals.
    https://linux.die.net/man/3/fflush

    Code:
    printf("%d", filecounter);  fflush(stdout);
    I was able to test scanvirus. Scan_Results_Filter now works. Now, I need create a string array of the filter names and use them to use mask folder names. Then, change the string as needed before it's called.

  4. #4

    Default Re: KDBG - debugger not printing value

    Thanks for the help....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •