0

错误是

Program terminated with signal 11, Segmentation fault.
#0  _M_lower_bound (this=0x7fff4982ad00, __k=<value optimized out>) at /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_tree.h:986
986             if (!_M_impl._M_key_compare(_S_key(__x), __k))
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.80.el6_3.6.x86_64 libgcc-4.4.6-4.el6.x86_64 libstdc++-4.4.6-4.el6.x86_64
(gdb) bt
#0  _M_lower_bound (this=0x7fff4982ad00, __k=<value optimized out>) at /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_tree.h:986
#1  lower_bound (this=0x7fff4982ad00, __k=<value optimized out>) at /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_tree.h:745
#2  lower_bound (this=0x7fff4982ad00, __k=<value optimized out>) at /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_map.h:701
#3  std::map<int, int, std::less<int>, std::allocator<std::pair<int const, int> > >::operator[] (this=0x7fff4982ad00, __k=<value optimized out>)
    at /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_map.h:447
#4  0x0000000000405148 in do_trace_loop () at main.cc:375
#5  0x0000000000407011 in main (argc=<value optimized out>, argv=<value optimized out>) at main.cc:727
(gdb)

但是源码很正常

    pid_t retpid;
  map<int, int,less<int> > incall;
  map<int, int,less<int> > last;
  int status = 0;

  struct pstate_t ps;

  int nsyscalls = 0, nfiltered = 0, child_cored = 0, child_exit = 0;
  gettimeofday(&initTime,0);
  for(;;) {
#ifdef TIMED
    timeval init;
    gettimeofday(&init,0);    
#endif
    retpid = wait4(-1, &status, __WALL, &ru);
#ifdef TIMED
    getelapsed(init, 1000000, "wait");
#endif

    if(retpid == -1) {
      FATAL("wait");

    } else if(retpid == 0) {
      FATAL("wait was not passed WNOHANG but returned 0");

    } else {
#ifndef DEBUG
    {
    stringstream s;
    s << "PID: " << retpid <<"-----------" ;      
    logger->log(s.str());
    }
#endif
      if(WIFEXITED(status)) {
          if(retpid == child) {
                stringstream s;
                s << "child exited with status " << WEXITSTATUS(status);
                logger->log(s.str());
                break;
          } else {
                stringstream s;
                s << "child thread " << retpid  << " exited with status " << WEXITSTATUS(status);
                debug(s.str());
                continue;
          }
      }

      //this was below
      if(WIFSIGNALED(status)) {
        for(int i = 0; i < initModulePlugins.size(); i++) {
              Initializer* c = initModulePlugins[i];
              c->signaled(WTERMSIG(status), signame(WTERMSIG(status)));
        }

        if(child == retpid) {

            break;
        }
        continue;
      }

      if(WIFSTOPPED(status)) {
        int sig = WSTOPSIG(status);

        /* stopped due to entering or leaving a system call? */
        if(sig == SIGTRAP) {

          /* note that my structure has extra fields and this doesn't fill them */
          if(ptrace(PTRACE_GETREGS, retpid, 0, &ps)) {
            //FATAL("ptrace(PTRACE_GETREGS, ...)");

            stringstream s;
            s << "PTRACE_GETREGS  " << retpid << " failed";
            logger->log(s.str());

            continue;
          }

          if(incall[(int)retpid] && ps.scno != last[(int)retpid]) {
            /* this can potentially happen if we get confused by a signal or if we see nested system calls...
               it also happens after a successful exec */
            stringstream s;
            s << "not in syscall " << scname(last[retpid]) << " as expected";
            logger->log(s.str());
            incall[retpid] = 0;
          }

          /* becomes true if entering, false if leaving */
          incall[retpid] = !incall[retpid];

          if(incall[retpid]) {
            nsyscalls++;
          }
4

0 回答 0