Esempio n. 1
0
bool MetricPPCustomer::HandleComment(clang::Preprocessor &PP, clang::SourceRange Loc) {

    clang::SourceLocation Start = Loc.getBegin();
    clang::SourceManager &SM = PP.getSourceManager();
	std::string fileName = SM.getFilename( Start ).str();

	/* Excude comments that are not:
	     - Not in the main file and
		 - Not in the file we're currently processing and
		 - Are in a file we've already processed comments for
    */
	if(( SM.getFileID( Start )  == SM.getMainFileID() ) ||
		( fileName == m_commentFile ) ||
		( m_commentFileList->find( fileName ) == m_commentFileList->end() ))
	{
		std::string C(SM.getCharacterData(Start),
					  SM.getCharacterData(Loc.getEnd()));

		if( m_options.ShouldIncludeFile( fileName ))
		{
			MetricUnit* unit = m_topUnit->getSubUnit(fileName, METRIC_UNIT_FILE);
			unit->increment(METRIC_TYPE_COMMENT_BYTE_COUNT, getFileAndLine( SM, &Start ), C.length());
			unit->increment(METRIC_TYPE_COMMENT_COUNT, getFileAndLine( SM, &Start ));
		}

		m_commentFile = fileName;
		m_commentFileList->insert( fileName );
	}
	else
	{
		m_commentFile = "";
	}

	return false;
}
void VSDebugLib::printStack() {

  unw_cursor_t cursor; 
  unw_context_t uc;
  unw_word_t ip, sp, off;
  unw_proc_info_t pi;
  char file[256], name[256];
  int line;
  int status;

  unw_getcontext(&uc);
  unw_init_local(&cursor, &uc);
  while (unw_step(&cursor) > 0) {
    unw_get_reg(&cursor, UNW_REG_IP, &ip);
    unw_get_reg(&cursor, UNW_REG_SP, &sp);

    unw_get_proc_name (&cursor, name, sizeof (name), &off);
    getFileAndLine((long)ip, file, 256, &line);

    if (line >= 0) {
      char *realname;
      realname = abi::__cxa_demangle(name, 0, 0, &status);
      
      if (realname) {
	printf("%s: %s, %d\n", realname, file, line);
	free(realname);
      } else {
	printf("%s: %s, %d\n", name, file, line);
      }
    }
  }
}
Esempio n. 3
0
void backtrace() {
  unw_cursor_t cursor;
  unw_context_t context;

  // Initialize cursor to current frame for local unwinding.
  unw_getcontext(&context);
  unw_init_local(&cursor, &context);

  // Unwind frames one by one, going up the frame stack.
  while (unw_step(&cursor) > 0) {
    unw_word_t offset, pc;
    unw_get_reg(&cursor, UNW_REG_IP, &pc);
    if (pc == 0) {
      break;
    }
    printf("0x%lx:", pc);

    char sym[256];
    if (unw_get_proc_name(&cursor, sym, sizeof(sym), &offset) == 0) {
      char* nameptr = sym;
      int status;
      char* demangled = abi::__cxa_demangle(sym, nullptr, nullptr, &status);
      if (status == 0) {
        nameptr = demangled;
      }
	char file[256];
	int line = 0;
	getFileAndLine((long)pc, file, 256, &line);
      printf(" (%s+0x%lx) in %s:%d\n", nameptr, offset, file, line);
      free(demangled);
    } else {
      printf(" -- error: unable to obtain symbol name for this frame\n");
    }
  }
}
Esempio n. 4
0
void show_backtrace(void) {
	char name[256];
	unw_cursor_t cursor; unw_context_t uc;
	unw_word_t ip, sp, offp;

	unw_getcontext(&uc);
	unw_init_local(&cursor, &uc);

	while (unw_step(&cursor) > 0)
	{
		char file[256];
		int line = 0;

		name[0] = '\0';
		unw_get_proc_name(&cursor, name, 256, &offp);
		unw_get_reg(&cursor, UNW_REG_IP, &ip);
		unw_get_reg(&cursor, UNW_REG_SP, &sp);

		//printf ("%s ip = %lx, sp = %lx\n", name, (long) ip, (long) sp);
		getFileAndLine((long)ip, file, 256, &line);
		printf("%s in file %s line %d\n", name, file, line);
	}
}
Esempio n. 5
0
string PlatformExceptionHandler::getStackTrace() {
	string errMsg = "\nStack Trace:\n";
	 if(PlatformExceptionHandler::disableBacktrace == true) {
		 errMsg += "disabled...";
		 return errMsg;
	 }

#if defined(HAS_GCC_BACKTRACE)
//        if(disableBacktrace == false && sdl_quitCalled == false) {
        //errMsg = "\nStack Trace:\n";
        //errMsg += "To find line #'s use:\n";
        //errMsg += "readelf --debug-dump=decodedline %s | egrep 0xaddress-of-stack\n";

        const size_t max_depth = 25;
        void *stack_addrs[max_depth];
        size_t stack_depth = backtrace(stack_addrs, max_depth);
        char **stack_strings = backtrace_symbols(stack_addrs, stack_depth);
        //for (size_t i = 1; i < stack_depth; i++) {
        //    errMsg += string(stack_strings[i]) + "\n";
        //}

        if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);

        char szBuf[8096]="";
        string strBuf = "";
        for(size_t i = 1; i < stack_depth; i++) {
            void *lineAddress = stack_addrs[i]; //getStackAddress(stackIndex);

            size_t sz = 8096; // just a guess, template names will go much wider
            char *function = static_cast<char *>(malloc(sz));
            function[0] = '\0';
            char *begin = 0;
            char *end = 0;

            // find the parentheses and address offset surrounding the mangled name
            for (char *j = stack_strings[i]; *j; ++j) {
                if (*j == '(') {
                    begin = j;
                }
                else if (*j == '+') {
                    end = j;
                }
            }
            if (begin && end) {
                *begin++ = '\0';
                *end = '\0';
                // found our mangled name, now in [begin, end)

                int status;
                char *ret = abi::__cxa_demangle(begin, function, &sz, &status);
                if (ret) {
                    // return value may be a realloc() of the input
                    function = ret;
                }
                else {
                    // demangling failed, just pretend it's a C function with no args
                    strncpy(function, begin, sz);
                    strncat(function, "()", sz);
                    function[sz-1] = '\0';
                }
                //fprintf(out, "    %s:%s\n", stack.strings[i], function);

                strBuf = string(stack_strings[i]) + ":" + string(function);
                snprintf(szBuf,8096,"address [%p]",lineAddress);
                strBuf += szBuf;
            }
            else {
                // didn't find the mangled name, just print the whole line
                //fprintf(out, "    %s\n", stack.strings[i]);
            	strBuf = stack_strings[i];
                snprintf(szBuf,8096,"address [%p]",lineAddress);
                strBuf += szBuf;
            }

            //errMsg += string(szBuf);
            errMsg += strBuf;
            char file[8096]="";
            int line = getFileAndLine(function, lineAddress, file, 8096);
            if(line >= 0) {
                errMsg += " line: " + intToStr(line);
            }
            errMsg += "\n";

            free(function);
        }

        free(stack_strings); // malloc()ed by backtrace_symbols
#endif

	return errMsg;
}