Exemplo n.º 1
0
void DebugInfoXmlWriter::WriteDebuggeeInfo(const Debug::DebugeeInfo& debuggeeInfo)
{
   m_spWriter->WriteStartElement(_T("running-processes"));
   m_spWriter->WriteStartElementEnd();
   {
      const Debug::DebugeeInfo::T_mapCurrentProcesses& mapRunningProcesses = debuggeeInfo.GetRunningProcesses();

      Debug::DebugeeInfo::T_mapCurrentProcesses::const_iterator iter = mapRunningProcesses.begin(), stop = mapRunningProcesses.end();
      for (;iter != stop; iter++)
         WriteProcessInfo(iter->second);
   }
   m_spWriter->WriteEndElement();

   m_spWriter->WriteStartElement(_T("abandoned-processes"));
   m_spWriter->WriteStartElementEnd();
   {
      const Debug::DebugeeInfo::T_setAbandonedProcesses& setAbandonedProcesses = debuggeeInfo.GetAbandonedProcesses();

      Debug::DebugeeInfo::T_setAbandonedProcesses::const_iterator iter = setAbandonedProcesses.begin(), stop = setAbandonedProcesses.end();
      for (;iter != stop; iter++)
         WriteProcessInfo(*iter);
   }
   m_spWriter->WriteEndElement();
}
Exemplo n.º 2
0
void Buddhabrot::DrawFrame(cv::Mat frame)
{





    double pointX = px.Get(), pointY = py.Get();
    double scale = s.Get();

    double frameRatio = (double)width / (double)height;

    double cwidth = 0, cheight = 0;

    cwidth = 3.0 * scale;
    cheight =  cwidth / frameRatio;

    double minRe, maxRe;
    double minIm, maxIm;

    minRe = pointX - cwidth / 2.0;
    maxRe = pointX + cwidth / 2.0;

    minIm = pointY - cheight / 2.0;
    maxIm = pointY + cheight / 2.0;


    unsigned int maxIterations = max_iter.Get();

    //std::cout<<"minRe: "<<minRe<<"; maxRe: "<<maxRe<<std::endl;
    //std::cout<<"minIm: "<<minIm<<"; maxIm: "<<maxIm<<std::endl;


    bool classic = false;

    double radius = r.Get();

    if(coloring == "classic")
        classic = true;

    bool black_hole = true;

    double xxx = 0;

     int points = calc_points.Get();//;50000000
     // radius = 2;


     double odl_x = (maxRe - minRe) / width;
     double odl_y = (maxIm - minIm) / height;


     double **licznik = new double*[width];
     for(int x = 0 ; x < width; x++)
     {
         licznik[x] = new double[height];
         for(int y = 0; y < height; y++)
         {
             licznik[x][y] = 0;
         }
     }

     double * offRe = new double[maxIterations];
     double * offIm = new double[maxIterations];

     WriteProcessInfo();

    double d2 = 1.0 / (double) points;

    for(int po = 0; po < points; po++)
    {

        //coal++;
       // if(coal >  koks)
       // {

            //std::cout<<(double)po/(double)points*100<<" %"<<std::endl;
            //coal = 0;
       // }
        double pRe = RandomDouble(minRe, maxRe);
        double pIm = RandomDouble(minIm, maxIm);

         double cIm = pIm;//maxIm - (double)y*(double)(  (maxIm-minIm)/(height-1) );
         double cRe = pRe;//minRe + (double)x*(double)  (  (maxRe-minRe)/(width-1) );

         double zRe = 0;
         double zIm = 0;

         double abs2;
         bool hop = true;



         int nnn = 0;
         for(int i = 0; i < maxIterations ; i++)
         {
             nnn = i;

             // normalnie
             double zIm2 = zIm*zIm;
             zIm = 2 * zRe*zIm + cIm;
             zRe = zRe*zRe - zIm2 + cRe;

             //abs = sqrt( zRe*zRe + zIm*zIm );
             abs2 = zRe*zRe + zIm*zIm ;

             offRe[i] = zRe;
             offIm[i] = zIm;

             if(abs2 > radius*radius) //4
             {
                 hop = false;
                 break;
             }
         }

         double *tmpx = new double;
         double *tmpy = new double;

       if(hop == false)
       {
           for(int i = 0; i < nnn; i++)
           {

               double x = offRe[i];
               double y = offIm[i];

               int xx, yy;

               modf((x - minRe) / odl_x , tmpx);

               xx = (*tmpx) ;

               modf((y - minIm) / odl_y, tmpy);
               yy = (*tmpy) ;
              // std::cout<<"#       SONDA( "<<*tmpx<<", "<<*tmpy<<");"<<std::endl;
               double errorx = (x - minRe) / odl_x - xx;
               double errory = (y - minIm) / odl_y - yy;
//log2( (licznik[x][y] - mini) / (maxi - mini)) ;
               //std::cout<<"SONDA( "<<xx<<", "<<yy<<");"<<std::endl;
               if(xx < width && yy < height)
                   licznik[xx][yy] +=  ( ( 1 - errorx) * (1 - errory))   ;
               if(xx +1< width && yy < height)
                   licznik[xx+1][yy] += ( ( 1 - errorx) * (errory));
               if(xx < width && yy+1 < height)
                   licznik[xx][yy+1] += ( (  errorx) * (1 - errory));
               if(xx + 1 < width && yy + 1< height)
                   licznik[xx+1][yy+1] += (  (  errorx) * ( errory));

            //   licznik[xx][yy] = log2( licznik[xx][yy]) / log2(i+2);
             //  licznik[xx+1][yy] = log2( licznik[xx+1][yy]) / log2(i+2);
              // licznik[xx][yy+1] = log2( licznik[xx][yy+1]) / log2(i+2);
              // licznik[xx+1][yy+1] = log2( licznik[xx+1][yy+1]) / log2(i+2);
           }

       }


       if(filetype == "image")
       {
           ReadProcessInfo(d2);
           WriteProcessInfo();
       }

   }
   //std::cout<<"cześć 2."; int kro= 0;
  // std::cin>>kro;

   long double  maxi = 0, mini= 0, sumi = 0;
   for(int y = 0; y < height; ++y)
   {
       for(int x = 0; x < width; ++x)
       {
           if(licznik[x][y] < mini)
               mini = licznik[x][y];
           if(licznik[x][y] > maxi)
               maxi = licznik[x][y];
           sumi += licznik[x][y];
       }
   }
   sumi /= height * width; // śrendia




//    Argument<double> color_r ;
//    Argument<double> color_g ;
//    Argument<double> color_b;

//    for(int i = 0; i < 100 ;i++)
//    {
//        double p = (double) i / 100.0;
//        color_r.Set(Key<double>( 255.0 * p, p));
//        color_g.Set(Key<double>( 255.0 * p , p));
//        color_b.Set(Key<double>( 255.0*log(p) / log(100), p));
//    }


       Argument<double> color_r ;// = c_r;
       Argument<double> color_g ;// = c_g;
       Argument<double> color_b  ;//= c_b;

       unsigned int color_level_num = 100;
       for(unsigned int i = 0 ; i <= color_level_num; i++)
       {
           double p = (double) i / (double) color_level_num;


           //color_r.Set(Key<double>( c_r.GetAbsolute(p) *   log(i) / log(color_level_num), p ));
           //color_g.Set(Key<double>( c_g.GetAbsolute(p) *    log(i) / log(color_level_num), p ));
           //color_b.Set(Key<double>( c_b.GetAbsolute(p) *    log(i) / log(color_level_num) , p ));



// TO JEST BARADZO WAŻNE
            color_r.Set(Key<double>( 255.0 *   p, p ));
           color_g.Set(Key<double>( 255.0 *    p, p ));
           color_b.Set(Key<double>( 255.0 *    log(i) / log(color_level_num) , p ));

       }

   color_r.Prepare();
   color_g.Prepare();
   color_b.Prepare();



   std::cout<<mini<<" > "<<maxi<<std::endl;
   for(int y = 0; y < height; ++y)
   {
       for(int x = 0; x < width; ++x)
       {



              //abs = licznik;



             //  m =0.5+ 0.5* sin (  nnn -   (  log2 (  abs ) / log2(radius)      ))  ;
                //m =0.5+ 0.5* sin (  nnn - log (  abs )  );




           // !!! 2 *
           double m = 2 * (licznik[x][y]-mini) / (maxi - mini);





          /*
           double m = 0;
           if(licznik[x][y] < sumi)
           {
               m = (licznik[x][y]-mini) / (sumi - mini);
           } else
           {
                m = (licznik[x][y]-sumi) / (maxi - sumi);
           }
               */


           //
          // std::cout<<"SONDA( "<<x<<", "<<y<<") = "<<m<<std::endl;
                frame.data[frame.step*y + frame.channels()* x + 0] = color_b.GetAbsolute(m);
                frame.data[frame.step*y + frame.channels()* x +1] = color_g.GetAbsolute(m);
                frame.data[frame.step*y + frame.channels()* x + 2] = color_r.GetAbsolute(m);

       }
   }
  // std::cout<<"XXX: "<<xxx<<std::endl;


}
Exemplo n.º 3
0
// Write the core dump file:
//   ELF header
//   Single section header (Shdr) for 64 bit program header count
//   Phdr for the PT_NOTE
//   PT_LOAD
//   PT_NOTEs
//      process info (prpsinfo_t)
//      NT_FILE entries
//      threads
//      alignment
//   memory blocks
bool
DumpWriter::WriteDump()
{
    // Write the ELF header
    Ehdr ehdr;
    memset(&ehdr, 0, sizeof(Ehdr));
    ehdr.e_ident[0] = ELFMAG0;
    ehdr.e_ident[1] = ELFMAG1;
    ehdr.e_ident[2] = ELFMAG2;
    ehdr.e_ident[3] = ELFMAG3;
    ehdr.e_ident[4] = ELF_CLASS;

    // Note: The sex is the current system running minidump-2-core
    //       Big or Little endian.  This means you have to create
    //       the core (minidump-2-core) on the system that matches
    //       your intent to debug properly.
    ehdr.e_ident[5] = sex() ? ELFDATA2MSB : ELFDATA2LSB;
    ehdr.e_ident[6] = EV_CURRENT;
    ehdr.e_ident[EI_OSABI] = ELFOSABI_LINUX;

    ehdr.e_type = ET_CORE;
    ehdr.e_machine = ELF_ARCH;
    ehdr.e_version = EV_CURRENT;
    ehdr.e_shoff = sizeof(Ehdr);
    ehdr.e_phoff = sizeof(Ehdr) + sizeof(Shdr);

    ehdr.e_ehsize = sizeof(Ehdr);
    ehdr.e_phentsize = sizeof(Phdr);
    ehdr.e_shentsize = sizeof(Shdr);

    // The ELF header only allows UINT16 for the number of program
    // headers. In a core dump this equates to PT_NODE and PT_LOAD.
    //
    // When more program headers than 65534 the first section entry
    // is used to store the actual program header count.

    // PT_NOTE + number of memory regions
    uint64_t phnum = 1 + m_crashInfo.MemoryRegions().size();

    if (phnum < PH_HDR_CANARY) {
        ehdr.e_phnum = phnum;
    }
    else {
        ehdr.e_phnum = PH_HDR_CANARY;
    }

    if (!WriteData(&ehdr, sizeof(Ehdr))) {
        return false;
    }

    size_t offset = sizeof(Ehdr) + sizeof(Shdr) + (phnum * sizeof(Phdr));
    size_t filesz = GetProcessInfoSize() + GetAuxvInfoSize() + GetThreadInfoSize() + GetNTFileInfoSize();

    // Add single section containing the actual count
    // of the program headers to be written.
    Shdr shdr;
    memset(&shdr, 0, sizeof(shdr));
    shdr.sh_info = phnum;
    // When section header offset is present but ehdr section num = 0
    // then is is expected that the sh_size indicates the size of the
    // section array or 1 in our case.
    shdr.sh_size = 1;
    if (!WriteData(&shdr, sizeof(shdr))) {
        return false;
    }

    // PT_NOTE header
    Phdr phdr;
    memset(&phdr, 0, sizeof(Phdr));
    phdr.p_type = PT_NOTE;
    phdr.p_offset = offset;
    phdr.p_filesz = filesz;

    if (!WriteData(&phdr, sizeof(phdr))) {
        return false;
    }

    // PT_NOTE sections must end on 4 byte boundary
    // We output the NT_FILE, AUX and Thread entries
    // AUX is aligned, NT_FILE is aligned and then we
    // check to pad end of the thread list
    phdr.p_type = PT_LOAD;
    phdr.p_align = 4096;

    size_t finalNoteAlignment = phdr.p_align - ((offset + filesz) % phdr.p_align);
    if (finalNoteAlignment == phdr.p_align) {
        finalNoteAlignment = 0;
    }
    offset += finalNoteAlignment;

    TRACE("Writing memory region headers to core file\n");

    // Write memory region note headers
    for (const MemoryRegion& memoryRegion : m_crashInfo.MemoryRegions())
    {
        phdr.p_flags = memoryRegion.Permissions();
        phdr.p_vaddr = memoryRegion.StartAddress();
        phdr.p_memsz = memoryRegion.Size();

        offset += filesz;
        phdr.p_filesz = filesz = memoryRegion.Size();
        phdr.p_offset = offset;

        if (!WriteData(&phdr, sizeof(phdr))) {
            return false;
        }
    }

    // Write process info data to core file
    if (!WriteProcessInfo()) {
        return false;
    }

    // Write auxv data to core file
    if (!WriteAuxv()) {
        return false;
    }

    // Write NT_FILE entries to the core file
    if (!WriteNTFileInfo()) {
        return false;
    }

    TRACE("Writing %ld thread entries to core file\n", m_crashInfo.Threads().size());

    // Write all the thread's state and registers
    for (const ThreadInfo* thread : m_crashInfo.Threads()) 
    {
        if (!WriteThread(*thread, SIGABRT)) {
            return false;
        }
    }

    // Zero out the end of the PT_NOTE section to the boundary
    // and then laydown the memory blocks
    if (finalNoteAlignment > 0) {
        assert(finalNoteAlignment < sizeof(m_tempBuffer));
        memset(m_tempBuffer, 0, finalNoteAlignment);
        if (!WriteData(m_tempBuffer, finalNoteAlignment)) {
            return false;
        }
    }

    TRACE("Writing %ld memory regions to core file\n", m_crashInfo.MemoryRegions().size());

    // Read from target process and write memory regions to core
    uint64_t total = 0;
    for (const MemoryRegion& memoryRegion : m_crashInfo.MemoryRegions())
    {
        uint32_t size = memoryRegion.Size();
        uint64_t address = memoryRegion.StartAddress();
        total += size;

        while (size > 0)
        {
            uint32_t bytesToRead = std::min(size, (uint32_t)sizeof(m_tempBuffer));
            uint32_t read = 0;

            if (FAILED(m_crashInfo.DataTarget()->ReadVirtual(address, m_tempBuffer, bytesToRead, &read))) {
                fprintf(stderr, "ReadVirtual(%016lx, %08x) FAILED\n", address, bytesToRead);
                return false;
            }

            if (!WriteData(m_tempBuffer, read)) {
                return false;
            }

            address += read;
            size -= read;
        }
    }

    printf("Written %ld bytes (%ld pages) to core file\n", total, total >> PAGE_SHIFT);

    return true;
}