0

Linux Eclipseを使用して、デバッガー(gdb)で実行していることをプログラムで通知できますか?

4

2 に答える 2

2

おそらく、あいまいなハッキングに頼る必要があります。

たとえば、/proc/<pid>/status ファイルの "TracerPid" を調べて、トレースされているかどうかを判断できます。

gdb によってトレースされているかどうかを実際に知りたい場合は、そのプロセスの exe リンクを調べてみることができます (ただし、これは信頼できません)。

于 2012-08-15T11:56:36.243 に答える
2
//=====================================================================
// effectively performs  `cat /proc/$pid/status | grep TracerPid`
//=====================================================================
bool     RunningInDebugger( pid_t pid )
{
   std::string       line        = "";
   std::string       pidFileName = "";
   size_t            y           = 0;
   size_t            x           = 0;
   bool              rc          = FALSE;

   pidFileName = "/proc/";
   pidFileName = pidFileName.append( NumToStr( pid ).c_str() );
   pidFileName = pidFileName.append( "/status" );

   std::ifstream     pidFile  (pidFileName.c_str() );

   if ( pidFile.is_open() )
   {
      while ( pidFile.good() )
      {
         getline (pidFile,line);
         x = line.find( "TracerPid:" );
         if ( x != std::string::npos )
         {
            line = line.substr( x+11 );                        // length of "TracerPid:" + 1
            x = line.find_first_not_of( " \t" );               // find first non whitespace character
            y = line.find_first_of( " ", x );                  // next whitespace
            if ( std::string::npos == y )                      // can't find trailing spaces that aren't there
               y = line.size() - 1;
            rc = atoi( line.substr( x, y-x+1 ).c_str() );
            pidFile.close();                                   // pidFile will no longer be "good"
         }
      }
      pidFile.close();
   }
   else     // File open failed
      rc = FALSE;

   return rc;
}
于 2012-08-15T15:11:38.860 に答える