예제 #1
0
std::string Eddie::generateCommand(std::string str1, int num1, int num2)
{
  std::stringstream ss;
  ss << str1 << PARAMETER_DELIMITER << 
    intToHexString(num1) << PARAMETER_DELIMITER <<
    intToHexString(num2) << PACKET_TERMINATOR;
  return ss.str();
}
예제 #2
0
void TwoDSceneSVGRenderer::renderSolidCircle( std::fstream& file, const Vector2s& center, const scalar& r, const renderingutils::Color& color ) const
{
    file << "<circle fill=\"#";
    file << intToHexString(floor(255.0*color.r+0.5)) << intToHexString(floor(255.0*color.g+0.5)) << intToHexString(floor(255.0*color.b+0.5)) << "\"" << " stroke=\"#";
    file << intToHexString(floor(255.0*color.r+0.5)) << intToHexString(floor(255.0*color.g+0.5)) << intToHexString(floor(255.0*color.b+0.5)) << "\"" << " stroke-width=\"0\" cx=\"";
    file << center.x();
    file << "\" cy=\"";
    file << center.y();
    file << "\" r=\"";
    file << r;
    file << "\"/>" << std::endl;
}
예제 #3
0
/**
 * Finds the base memory address in the running process for all the libraries
 * involved in the crash.
 */
static void findBaseMemoryAddresses(std::map<std::string,uintptr_t>& binPath_baseMemAddr) {

	// store all paths which we have to find
	std::set<std::string> paths_notFound;
	std::map<std::string,uintptr_t>::const_iterator bpbmai;
	for (bpbmai = binPath_baseMemAddr.begin(); bpbmai != binPath_baseMemAddr.end(); ++bpbmai) {
		paths_notFound.insert(bpbmai->first);
	}

	FILE* mapsFile = NULL; 
	// /proc/self/maps contains the base addresses for all loaded dynamic
	// libaries of the current process + other stuff (which we are not interested in)
	mapsFile = fopen("/proc/self/maps", "rb");
	if (mapsFile != NULL) {
		std::set<std::string>::const_iterator pi;
		// format of /proc/self/maps:
		// (column names)  address           perms offset  dev   inode      pathname
		// (example 32bit) 08048000-08056000 r-xp 00000000 03:0c 64593      /usr/sbin/gpm
		// (example 64bit) ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0   [vsyscall]
		unsigned long int mem_start;
		unsigned long int binAddr_offset;
		char              binPathName[512];

		char line[512];
		int red;
		// read all lines
		while (!paths_notFound.empty() && (fgets(line, 511, mapsFile) != NULL)) {
			// parse the line
			red = sscanf(line, "%lx-%*x %*s %lx %*s %*u %s",
					&mem_start, &binAddr_offset, binPathName);

			if (red == 3) {
				if (binAddr_offset == 0) {
					//-> start of binary's memory space
					std::string matchingPath = "";
					// go through all paths of the binaries involved in the stack trace
					for (pi = paths_notFound.begin(); pi != paths_notFound.end(); ++pi) {
						// does the current line contain this binary?
						if (*pi == binPathName) {
							matchingPath = *pi;
							break;
						}
					}
					if (matchingPath != "") {
						const std::string mem_start_str = intToHexString(mem_start);
						binPath_baseMemAddr[matchingPath] = mem_start;
						paths_notFound.erase(matchingPath);
					}
				}
			}
		}
		fclose(mapsFile);
	}
}
예제 #4
0
void TwoDSceneSVGRenderer::renderScene( const std::string& filename ) const
{
    const VectorXs& x = m_scene.getX();
    assert( x.size()%2 == 0 );
    assert( 2*m_scene.getNumParticles() == x.size() );
    int numparticles = x.size()/2;
    const std::vector<scalar>& radii = m_scene.getRadii();
    assert( numparticles == (int) radii.size() );

    std::fstream file(filename.c_str(), std::fstream::out);
    if(!file)
    {
        std::cerr << "Failure writing SVG file!" << std::endl;
        exit(1);
    }

    scalar scale, xmin, ymin, xshift, yshift;
    computeSimToImageMap( scale, xmin, ymin, xshift, yshift );

    file << "<?xml version=\"1.0\" encoding=\"utf-8\"?> <!-- Generator: Adobe Illustrator 13.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 14948)  --> <svg version=\"1.2\" baseProfile=\"tiny\" id=\"Layer_1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0px\" y=\"0px\" width=\"";
    file << m_w;
    file << "px\" height=\"";
    file << m_h;
    file << "px\" viewBox=\"0 0 ";
    file << m_w << " " << m_h;
    file << "\" xml:space=\"preserve\">" << std::endl;

    // Simulate a background color by rendering a large colored quad
    file << "<polygon points=\"" << 0 << "," << 0 << " " << m_w << "," << 0 << " " << m_w << "," << m_h << " " << 0 << "," << m_h;
    file << "\" style=\"fill:#" << intToHexString(floor(255.0*m_bgcolor.r+0.5)) << intToHexString(floor(255.0*m_bgcolor.g+0.5)) << intToHexString(floor(255.0*m_bgcolor.b+0.5));
    file << "; stroke:#000000;stroke-width:0\"/>" << std::endl;


    const std::vector<std::pair<int,int> >& edges = m_scene.getEdges();
    const std::vector<scalar>& edgeradii = m_scene.getEdgeRadii();
    renderShared( file, x, edges, radii, edgeradii, scale, xmin, ymin, xshift, yshift );

    file << "</svg>" << std::endl;

    file.close();
}
예제 #5
0
void TwoDSceneSVGRenderer::renderSweptEdge( std::fstream& file, const Vector2s& x0, const Vector2s& x1, const scalar& r, const renderingutils::Color& color ) const
{
    scalar theta = atan2(x1.y()-x0.y(),x1.x()-x0.x());

    scalar rx = -r*sin(theta);
    scalar ry =  r*cos(theta);

    scalar p0x = x0.x() + rx;
    scalar p0y = x0.y() + ry;
    scalar p1x = x0.x() - rx;
    scalar p1y = x0.y() - ry;
    scalar p2x = x1.x() - rx;
    scalar p2y = x1.y() - ry;
    scalar p3x = x1.x() + rx;
    scalar p3y = x1.y() + ry;

    file << "<polygon points=\"" << p0x << "," << p0y << " " << p1x << "," << p1y << " " << p2x << "," << p2y << " " << p3x << "," << p3y;
    file << "\" style=\"fill:#" << intToHexString(floor(255.0*color.r+0.5)) << intToHexString(floor(255.0*color.g+0.5)) << intToHexString(floor(255.0*color.b+0.5));
    file << "; stroke:#000000;stroke-width:0\"/>" << std::endl;

    renderSolidCircle( file, x0, r, color );
    renderSolidCircle( file, x1, r, color );
}
예제 #6
0
	void HandleSignal(int signal)
	{
		static const std::string INVALID_LINE_INDICATOR = "#####";
		const std::string logFileName = logOutput.GetFilename();

		std::string error;
		std::queue<std::string> paths;
		std::queue<uintptr_t> addresses;
		std::map<std::string,uintptr_t> binPath_baseMemAddr;

		logOutput.RemoveAllSubscribers();
		{
			LogObject log;
			if (signal == SIGSEGV) {
				error = "Segmentation fault (SIGSEGV)";
			} else if (signal == SIGILL) {
				error = "Illegal instruction (SIGILL)";
			} else if (signal == SIGPIPE) {
				error = "Broken pipe (SIGPIPE)";
			} else if (signal == SIGIO) {
				error = "IO-Error (SIGIO)";
			} else if (signal == SIGABRT) {
				error = "Aborted (SIGABRT)";
			} else {
				// we should never get here
				error = "Unknown signal";
			}
			log << error << " in spring " << SpringVersion::GetFull() << "\nStacktrace:\n";

			std::vector<void*> buffer(128);
			const int numLines = backtrace(&buffer[0], buffer.size());    // stack pointers
			char** lines       = backtrace_symbols(&buffer[0], numLines); // give them meaningfull names
			if (lines == NULL) {
				log << "Unable to create stacktrace\n";
			} else {
				for (int l = 0; l < numLines; l++) {
					const std::string line(lines[l]);
					log << line;

					// example paths: "./spring" "/usr/lib/AI/Skirmish/NTai/0.666/libSkirmishAI.so"
					std::string path;
					size_t begin = 0;
					size_t end   = line.find_last_of('('); // if there is a function name
					if (end == std::string::npos) {
						end      = line.find_last_of('['); // if there is only the memory address
						if ((end != std::string::npos) && (end > 0)) {
							end--; // to get rid of the ' ' before the '['
						}
					}
					if (end == std::string::npos) {
						path = INVALID_LINE_INDICATOR;
					} else {
						path = line.substr(begin, end-begin);
					}

					// example address: "0x89a8206"
					std::string addr;
					begin = line.find_last_of('[');
					end = std::string::npos;
					if (begin != std::string::npos) {
						end = line.find_last_of(']');
					}
					if ((begin == std::string::npos) || (end == std::string::npos)) {
						addr = INVALID_LINE_INDICATOR;
					} else {
						addr = line.substr(begin+1, end-begin-1);
					}

					if (path == "") {
						log << " # NOTE: no path -> not translating";
					} else if ((path == INVALID_LINE_INDICATOR)
							|| (addr == INVALID_LINE_INDICATOR)) {
						log << " # NOTE: invalid stack-trace line -> not translating";
					} else {
						const std::string absPath = createAbsolutePath(path);
						binPath_baseMemAddr[absPath] = 0;
						paths.push(absPath);
						const uintptr_t addr_num = hexToInt(addr.c_str());
						addresses.push(addr_num);
					}
					log << "\n";
				}
				delete lines;
				lines = NULL;
			}
			log << "Translated Stacktrace:\n";
		}
		logOutput.End(); // Stop writing to log.

		findBaseMemoryAddresses(binPath_baseMemAddr);

		std::string lastPath;
		while (!paths.empty()) {
			std::ostringstream buf;
			lastPath = paths.front();
			const std::string symbolFile = locateSymbolFile(lastPath);
			const uintptr_t baseAddress = binPath_baseMemAddr[lastPath];
			buf << "addr2line " << "--exe=\"" << symbolFile << "\"";
			// add addresses as long as the path stays the same
			while (!paths.empty() && (lastPath == paths.front())) {
				uintptr_t addr_num = addresses.front();
				if (paths.front() != Platform::GetBinaryFile() && (addr_num > baseAddress)) {
					// shift the stack trace address by the value of
					// the libraries base address in process memory
					// for all binaries that are not the processes main binary
					// (which could be spring or spring-dedicated for example)
					addr_num -= baseAddress;
				}
				buf << " 0x" << intToHexString(addr_num);
				lastPath = paths.front();
				paths.pop();
				addresses.pop();
			}
			buf << " >> " << logFileName; // pipe to infolog (which will be in CWD)
			system(buf.str().c_str());
		}

		ErrorMessageBox(error, "Spring crashed", 0);
	}
예제 #7
0
void TwoDSceneSVGRenderer::renderRigidBodyScene( const std::string& name, const RigidBodyScene& rbscene ) const
{
//  const VectorXs& x = m_scene.getX();
//  assert( x.size()%2 == 0 );
//  assert( 2*m_scene.getNumParticles() == x.size() );
//  int numparticles = x.size()/2;
//  const std::vector<scalar>& radii = m_scene.getRadii();
//  assert( numparticles == (int) radii.size() );

    std::fstream file(name.c_str(), std::fstream::out);
    if(!file)
    {
        std::cerr << "Failure writing SVG file!" << std::endl;
        exit(1);
    }

    scalar scale, xmin, ymin, xshift, yshift;
    computeSimToImageMap( scale, xmin, ymin, xshift, yshift );

    file << "<?xml version=\"1.0\" encoding=\"utf-8\"?> <!-- Generator: Adobe Illustrator 13.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 14948)  --> <svg version=\"1.2\" baseProfile=\"tiny\" id=\"Layer_1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0px\" y=\"0px\" width=\"";
    file << m_w;
    file << "px\" height=\"";
    file << m_h;
    file << "px\" viewBox=\"0 0 ";
    file << m_w << " " << m_h;
    file << "\" xml:space=\"preserve\">" << std::endl;

    // Simulate a background color by rendering a large colored quad
    file << "<polygon points=\"" << 0 << "," << 0 << " " << m_w << "," << 0 << " " << m_w << "," << m_h << " " << 0 << "," << m_h;
    file << "\" style=\"fill:#" << intToHexString(floor(255.0*m_bgcolor.r+0.5)) << intToHexString(floor(255.0*m_bgcolor.g+0.5)) << intToHexString(floor(255.0*m_bgcolor.b+0.5));
    file << "; stroke:#000000;stroke-width:0\"/>" << std::endl;

    const std::vector<RigidBody> rbs = rbscene.getRigidBodies();
    assert( m_particle_colors.size() == rbs.size() );

    // For each rigid body
    for( std::vector<RigidBody>::size_type i = 0; i < rbs.size(); ++i )
    {
        scalar r = rbs[i].getRadius();
        renderingutils::Color rbcolor = m_particle_colors[i];
        // Render each edge of each rigid body
        for( int j = 0; j < rbs[i].getNumVertices(); ++j )
        {
            const Vector2s& xi = rbs[i].getWorldSpaceVertex(j);
            const Vector2s& xj = rbs[i].getWorldSpaceVertex((j+1)%rbs[i].getNumVertices());

            Vector2s p0;
            p0 << scale*(xi.x()-xmin) + xshift, ((scalar)m_h) - scale*(xi.y()-ymin) - yshift;

            Vector2s p1;
            p1 << scale*(xj.x()-xmin) + xshift, ((scalar)m_h) - scale*(xj.y()-ymin) - yshift;

            renderSweptEdge( file, p0, p1, scale*r, rbcolor );
        }
    }

    // Render each spring force
    for( std::vector<RigidBody>::size_type i = 0; i < m_svg_renderers.size(); ++i )
    {
        renderingutils::Color clr = m_svg_renderers[i]->getColor();

        Vector2s xi = m_svg_renderers[i]->getVertexOne(rbs);
        Vector2s xj = m_svg_renderers[i]->getVertexTwo(rbs);

        Vector2s p0;
        p0 << scale*(xi.x()-xmin) + xshift, ((scalar)m_h) - scale*(xi.y()-ymin) - yshift;

        Vector2s p1;
        p1 << scale*(xj.x()-xmin) + xshift, ((scalar)m_h) - scale*(xj.y()-ymin) - yshift;

        renderSweptEdge( file, p0, p1, scale*0.03, clr );
    }


    file << "</svg>" << std::endl;

    file.close();
}
예제 #8
0
void TwoDSceneSVGRenderer::renderComparisonScene( const std::string& filename, const TwoDScene& otherscene, const std::vector<CollisionInfo> *impulses, const std::vector<CollisionInfo> *otherimpulses, const scalar &eps) const
{
    const VectorXs& x = m_scene.getX();
    const VectorXs& v = m_scene.getV();
    assert( x.size()%2 == 0 );
    assert( 2*m_scene.getNumParticles() == x.size() );
    int numparticles = x.size()/2;
    const std::vector<scalar>& radii = m_scene.getRadii();
    assert( numparticles == (int) radii.size() );

    std::fstream file(filename.c_str(), std::fstream::out);
    if(!file)
    {
        std::cerr << "Failure writing SVG file!" << std::endl;
        exit(1);
    }

    scalar scale, xmin, ymin, xshift, yshift;
    computeSimToImageMap(scale, xmin, ymin, xshift, yshift );

    file << "<?xml version=\"1.0\" encoding=\"utf-8\"?> <!-- Generator: Adobe Illustrator 13.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 14948)  --> <svg version=\"1.2\" baseProfile=\"tiny\" id=\"Layer_1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0px\" y=\"0px\" width=\"";
    file << m_w;
    file << "px\" height=\"";
    file << m_h;
    file << "px\" viewBox=\"0 0 ";
    file << m_w << " " << m_h;
    file << "\" xml:space=\"preserve\">" << std::endl;

    // Simulate a background color by rendering a large colored quad
    file << "<polygon points=\"" << 0 << "," << 0 << " " << m_w << "," << 0 << " " << m_w << "," << m_h << " " << 0 << "," << m_h;
    file << "\" style=\"fill:#" << intToHexString(floor(255.0*m_bgcolor.r+0.5)) << intToHexString(floor(255.0*m_bgcolor.g+0.5)) << intToHexString(floor(255.0*m_bgcolor.b+0.5));
    file << "; stroke:#000000;stroke-width:0\"/>" << std::endl;

    const std::vector<std::pair<int,int> >& edges = m_scene.getEdges();
    const std::vector<scalar>& edgeradii = m_scene.getEdgeRadii();
    renderShared( file, x, edges, radii, edgeradii, scale, xmin, ymin, xshift, yshift );



    const VectorXs& otherx = otherscene.getX();
    const VectorXs& otherv = otherscene.getV();

    for( int i = 0; i < numparticles; ++i )
    {
        scalar x_resid = (otherx.segment<2>(2*i)-x.segment<2>(2*i)).norm();
        scalar v_resid = (otherv.segment<2>(2*i)-v.segment<2>(2*i)).norm();
        if( x_resid > eps || v_resid > eps )
        {
            Vector2s center;
            center << scale*(x(2*i)-xmin) + xshift, ((scalar)m_h) - scale*(x(2*i+1)-ymin) - yshift;
            renderCircle( file, center, 1.5*scale*radii[i], renderingutils::Color(1.0,0.0,0.0) );
        }
    }

    if(impulses)
    {
        int i=0, j=0;

        // loop over the real impulses
        while(i < (int)impulses->size())
        {
            int curvert = (*impulses)[i].m_idx1;
            CollisionInfo::collisiontype curtype = (*impulses)[i].m_type;
            int curidx2 = (*impulses)[i].m_idx2;

            // all student impulses less than this correct impulse are buggy
            while(j < (int)otherimpulses->size()
                    && (*otherimpulses)[j].m_idx1 < curvert
                    && (*otherimpulses)[j].m_type < curtype
                    && (*otherimpulses)[j].m_idx2 < curidx2)
            {
                renderImpulse( file, otherscene, (*otherimpulses)[j], true);
                j++;
            }

            // check for missed collision
            if( ! (j < (int)otherimpulses->size()
                    && (*otherimpulses)[j].m_idx1 == curvert
                    && (*otherimpulses)[j].m_type == curtype
                    && (*otherimpulses)[j].m_idx2 == curidx2))
            {
                renderImpulse( file, otherscene, (*impulses)[i], false);
            }
            else
            {
                // check for buggy normal
                if( ((*otherimpulses)[j].m_n - (*impulses)[i].m_n).norm() > eps)
                {
                    renderImpulse( file, otherscene, (*impulses)[i], false);
                    renderImpulse( file, otherscene, (*otherimpulses)[j], true);
                }
                j++;
            }

            i++;
        }
        // Any remaining student impulses are buggy
        while(j < (int)otherimpulses->size())
        {
            renderImpulse( file, otherscene, (*otherimpulses)[j], true);
            j++;
        }
    }


    file << "</svg>" << std::endl;

    file.close();

}
예제 #9
0
void TwoDSceneSVGRenderer::renderShared( std::fstream& file, const VectorXs& x, const std::vector<std::pair<int,int> >& edges, const std::vector<scalar>& radii, const std::vector<scalar>& edgeradii, const scalar& scale, const scalar& xmin, const scalar& ymin, const scalar& xshift, const scalar& yshift  ) const
{
    int numparticles = x.size()/2;

    for( std::vector<renderingutils::ParticlePath>::size_type i = 0; i < m_particle_paths.size(); ++i )
    {
        const std::list<Vector2s>& ppath = m_particle_paths[i].getPath();
        const renderingutils::Color& pathcolor = m_particle_paths[i].getColor();

        file << "<polyline points=\"";

        for( std::list<Vector2s>::const_iterator itr = ppath.begin(); itr != ppath.end(); ++itr )
        {
            Vector2s point;
            point << scale*(itr->x()-xmin) + xshift, ((scalar)m_h) - scale*(itr->y()-ymin) - yshift;
            file << point.x() << "," << point.y() << " ";
        }

        file << "\" style=\"fill:none;stroke:#";
        file << intToHexString(floor(255.0*pathcolor.r+0.5)) << intToHexString(floor(255.0*pathcolor.g+0.5)) << intToHexString(floor(255.0*pathcolor.b+0.5));
        file << ";stroke-width:1\"/>" << std::endl;
    }

    // Render edges
    assert( edgeradii.size() == edges.size() );
    for( std::vector<std::pair<int,int> >::size_type i = 0; i < edges.size(); ++i )
    {
        assert( edges[i].first >= 0 );
        assert( edges[i].first < m_scene.getNumParticles() );
        assert( edges[i].second >= 0 );
        assert( edges[i].second < m_scene.getNumParticles() );

        int i0 = edges[i].first;
        int i1 = edges[i].second;

        Vector2s p0;
        p0 << scale*(x(2*i0)-xmin) + xshift, ((scalar)m_h) - scale*(x(2*i0+1)-ymin) - yshift;

        Vector2s p1;
        p1 << scale*(x(2*i1)-xmin) + xshift, ((scalar)m_h) - scale*(x(2*i1+1)-ymin) - yshift;

        renderSweptEdge( file, p0, p1, scale*edgeradii[i], m_edge_colors[i] );
    }

    // Render halfplanes
    for(int i=0; i < m_scene.getNumHalfplanes(); i++)
    {
        Vector2s p0;
        p0 << scale * (m_scene.getHalfplane(i).first[0]-xmin) + xshift, ((scalar)m_h) - scale*(m_scene.getHalfplane(i).first[1]-ymin) - yshift;
        Vector2s n0;
        n0 << m_scene.getHalfplane(i).second[0], -m_scene.getHalfplane(i).second[1];
        n0.normalize();
        renderHalfplane(file, p0, n0, m_halfplane_colors[i]);
    }

    // Render particles
    for( int i = 0; i < numparticles; ++i )
    {
        Vector2s center;
        center << scale*(x(2*i)-xmin) + xshift, ((scalar)m_h) - scale*(x(2*i+1)-ymin) - yshift;
        renderSolidCircle( file, center, scale*radii[i], m_particle_colors[i] );
    }
}
예제 #10
0
void TwoDSceneSVGRenderer::renderHalfplane( std::fstream &file, const VectorXs &x, const VectorXs &n, const renderingutils::Color &color) const
{
    double p0x = x[0] - 1000*n[1];
    double p0y = x[1] + 1000*n[0];
    double cx = x[0] - 1000*n[0];
    double cy = x[1] - 1000*n[1];
    double p1x = x[0] + 1000*n[1];
    double p1y = x[1] - 1000*n[0];

    file << "<polygon points=\"" << p0x << "," << p0y << " " << cx << "," << cy << " " << p1x << "," << p1y <<  "\" style=\"fill:#" << intToHexString(floor(255.0*color.r+0.5)) << intToHexString(floor(255.0*color.g+0.5)) << intToHexString(floor(255.0*color.b+0.5)) << "; stroke:#000000;stroke-width:0\"/>" << std::endl;
}