Exemple #1
0
void OneshotTracer::tick(std::map<pid_t, std::vector<Frame>> stacktraces) {
    for (const auto& kv: stacktraces) {
        std::cout << boost::format("Thread %d:\n") % kv.first;
        for (const auto& frame: kv.second) {
            std::cout << str(boost::format("0x%x %s\n") %
                        frame.ip %
                        abbrev(demangle(frame.procName)));
        }
        std::cout << std::endl;
    }
}
Exemple #2
0
const string_t type_string(const std::type_info& Info)
{
	detail::initialize_types();

	detail::type_to_name_map_t::iterator type = detail::type_to_name_map.find(detail::type_info(Info));
	if(type != detail::type_to_name_map.end())
		return type->second;

	log() << error << k3d_file_reference << ": unknown type: " << demangle(Info) << std::endl;
	return "";
}
Exemple #3
0
std::string
Transient::getTimeStepperName()
{
  if (_time_stepper)
  {
    TimeStepper & ts = *_time_stepper;
    return demangle(typeid(ts).name());
  }
  else
    return std::string();
}
Exemple #4
0
static void _ex_terminate()
{
    static bool already_tried = false;

    Log::setLogHandler(NULL);

    try
    {
        // try once to re-throw currently active exception
        if( !already_tried )
        {
        	already_tried = true;
        	throw;
        }
    }
    catch( const RuntimeError &e )
    {
    	e.Log();
    }
    catch (const std::exception &e)
    {
        do_log_msg( LOG_PRIORITY_ERROR, NULL, typeid(e).name(), e.what() );
    }
    catch (...) {
        do_log_msg( LOG_PRIORITY_ERROR, NULL, "Unknown", "Unknown exception" );
    }

	fprintf( stderr, "Unhandled exception, program terminated\n" );

#ifndef SMART_LOG_NO_BACKTRACE

	fprintf( stderr, "Backtrace:\n" );

    void* fnAddr[UTIL_LOG_BACKTRACE_SIZE];
    int size = backtrace(fnAddr, UTIL_LOG_BACKTRACE_SIZE);

    char** fnSyms = backtrace_symbols(fnAddr, size);

    if( fnSyms != NULL )
    {
		// We skip the first call in the stack, which is the call to this
    	// function
		for (int i=1; i < size; i++)
		{
		    fprintf( stderr,"[%d]: %s\n", i, demangle(fnSyms[i]).c_str() );
		}

		free(fnSyms);
    }

#endif // SMART_LOG_NO_BACKTRACE

    abort();
}
Exemple #5
0
int main() {
  struct {
    const char* raw;
    const char* expect;
  } TestCases[] = {
      {typeid(int).name(), "i"}, // FIXME
      {typeid(MyType).name(), "MyType"},
      {typeid(ArgumentListID<int, MyType>).name(), "ArgumentListID<int, MyType>"}
  };
  const size_t size = sizeof(TestCases) / sizeof(TestCases[0]);
  for (size_t i=0; i < size; ++i) {
    const char* raw = TestCases[i].raw;
    const char* expect = TestCases[i].expect;
#ifdef TEST_HAS_NO_DEMANGLE
    assert(demangle(raw) == raw);
#else
    assert(demangle(raw) == expect);
#endif
  }
}
Exemple #6
0
void FSEventsService::rename(std::vector<std::string> *paths) {
  auto *binNamesByPath = new std::map<std::string, std::vector<std::string> *>;

  for (auto pathIterator = paths->begin(); pathIterator != paths->end(); ++pathIterator) {
    std::string directory, name;
    splitFilePath(directory, name, *pathIterator);
    if (binNamesByPath->find(directory) == binNamesByPath->end()) {
      (*binNamesByPath)[directory] = new std::vector<std::string>;
    }
    (*binNamesByPath)[directory]->push_back(name);
  }

  for (auto binIterator = binNamesByPath->begin(); binIterator != binNamesByPath->end(); ++binIterator) {
    if (binIterator->second->size() == 2) {
      std::string sideA = (*binIterator->second)[0],
                  sideB = (*binIterator->second)[1];
      std::string fullSideA = binIterator->first + "/" + sideA,
                  fullSideB = binIterator->first + "/" + sideB;
      struct stat renameSideA, renameSideB;
      bool sideAExists = stat(fullSideA.c_str(), &renameSideA) == 0,
           sideBExists = stat(fullSideB.c_str(), &renameSideB) == 0;

      if (sideAExists && !sideBExists) {
        mQueue.enqueue(RENAMED, binIterator->first, sideB, sideA);
      } else if (!sideAExists && sideBExists) {
        mQueue.enqueue(RENAMED, binIterator->first, sideA, sideB);
      } else {
        demangle(fullSideA);
        demangle(fullSideB);
      }

    } else {
      for (auto pathIterator = binIterator->second->begin(); pathIterator != binIterator->second->end(); ++pathIterator) {
        demangle(binIterator->first + "/" + *pathIterator);
      }
    }
    delete binIterator->second;
    binIterator->second = NULL;
  }
  delete binNamesByPath;
}
Exemple #7
0
int main(int argc, char **argv) {
#if defined(__CYGWIN__)
  // Cygwin clang 3.5.2 with '-O3' generates CRASHING BINARY,
  // if main()'s first function call is passing argv[0].
  std::rand();
#endif  
  llvm::cl::ParseCommandLineOptions(argc, argv);

  swift::Demangle::DemangleOptions options;
  options.SynthesizeSugarOnTypes = !DisableSugar;
  if (Simplified)
    options = swift::Demangle::DemangleOptions::SimplifiedUIDemangleOptions();

  if (InputNames.empty()) {
    CompactMode = true;
    auto input = llvm::MemoryBuffer::getSTDIN();
    if (!input) {
      llvm::errs() << input.getError().message() << '\n';
      return EXIT_FAILURE;
    }
    llvm::StringRef inputContents = input.get()->getBuffer();

    // This doesn't handle Unicode symbols, but maybe that's okay.
    llvm::Regex maybeSymbol("_T[_a-zA-Z0-9$]+");
    llvm::SmallVector<llvm::StringRef, 1> matches;
    while (maybeSymbol.match(inputContents, &matches)) {
      llvm::outs() << substrBefore(inputContents, matches.front());
      demangle(llvm::outs(), matches.front(), options);
      inputContents = substrAfter(inputContents, matches.front());
    }
    llvm::outs() << inputContents;

  } else {
    for (llvm::StringRef name : InputNames) {
      demangle(llvm::outs(), name, options);
      llvm::outs() << '\n';
    }
  }

  return EXIT_SUCCESS;
}
Exemple #8
0
static int print_sym(void *user_data, const char *name, address_t value)
{
	(void)user_data;

	char demangled[MAX_SYMBOL_LENGTH];
	if (demangle(name, demangled, sizeof(demangled)) > 0)
		printc("0x%04x: %s (%s)\n", value, name, demangled);
	else
		printc("0x%04x: %s\n", value, name);

	return 0;
}
	void main() {
		#if 0
			// Utilisation incorrecte avec zéro argument
			std::cout << max() << std::endl;
			// => Ne compile pas : error: static_assert failed "max needs at least 1 argument"
		#endif

		#if 0
			// Utilisation incorrecte avec zéro argument (bypasse le point d'entrée et appel direct de l'implantation max_impl)
			std::cout << max_impl() << std::endl;
			// => Ne compile pas : error: no matching function for call to 'max_impl'
		#endif

		std::cout << max(2) << std::endl;
		// => Affiche "2"

		std::cout << max(2, 1) << std::endl;
		// => Affiche "2"

		std::cout << max(2, 1, 6) << std::endl;
		// => Affiche "6"

		// Fonctionne avec tout type qui implante l'opérateur >
		std::string s1{"def"}, s2{"abc"};
		std::cout << max(s1, s2) << std::endl;
		// => Affiche "def"

		// Attention tout de même! l'opérateur > ici compare les adresses
		std::cout << max(s1.c_str(), s2.c_str()) << std::endl;
		// => Affiche "abc" sur ma machine

		// Attention tout de même! l'opérateur > ici compare les adresses
		char a1[]{"abc"}, a2[]{"def"}, a3[]{"abc"};
		std::cout << max(a1, a2) << std::endl;
		// => Affiche "abc" sur ma machine
		std::cout << max(a2, a3) << std::endl;
		// => Affiche "def" sur ma machine

		// Fonctionne très bien avec des types hétérogènes
		std::cout << max(2, 1.0, 6.0f, 4ull) << std::endl;
		// => Affiche "6"

		// Voyons quel est le type du résultat ...
		auto result = max(2, 1.0, 6.0f, 4ull);
		std::cout << demangle(typeid(result).name()) << std::endl;
		// => Affiche "double"

		#if 0
			// Vérification statique (à la compilation) que les types sont compatibles
			std::cout << max(s1, 123) << std::endl;
			// => Ne compile pas : error: invalid operands to binary expression ('std::basic_string<char>' and 'int')
		#endif
	}
Exemple #10
0
SEXP exception_to_r_condition( const std::exception& ex){
    std::string ex_class = demangle( typeid(ex).name() ) ;
    std::string ex_msg   = ex.what() ; 
    
    SEXP cppstack = PROTECT( rcpp_get_stack_trace() ) ;
    SEXP call = PROTECT( get_last_call() ) ;
    SEXP classes = PROTECT( get_exception_classes(ex_class) ) ;
    SEXP condition = PROTECT( make_condition( ex_msg, call, cppstack, classes ) ) ; 
    rcpp_set_stack_trace( R_NilValue ) ;
    UNPROTECT(4) ;
    return condition ;
}
Exemple #11
0
    std::string __type_of(typename std::remove_reference<Tp>::type &)
    {
        auto name = demangle(typeid(Tp).name());
        if (std::is_const<
             typename std::remove_reference<Tp>::type>::value)
            name.append(" const");

        if (std::is_volatile<
             typename std::remove_reference<Tp>::type>::value)
            name.append(" volatile");

        return name.append("&");
    }
Exemple #12
0
    template <class T> inline Matrix<T>&
	Get              (const std::string& name) {

		reflist::iterator it = m_ref.find(name);

        if (it == m_ref.end())
            printf ("**WARNING**: Matrix %s could not be found in workspace!\n", name.c_str());

        const boost::any& ba = m_store[it->second[0]];

        try {
			boost::any_cast<boost::shared_ptr<Matrix<T> > >(m_store[it->second[0]]);
		} catch (const boost::bad_any_cast& e) {
			printf ("**WARNING**: Failed to retrieve %s - %s.\n             Requested %s - have %s.\n",
					name.c_str(), e.what(),
                    demangle(typeid(boost::shared_ptr<Matrix<T> >).name()).c_str(),
                    demangle(ba.type().name()).c_str());
		}

		return *boost::any_cast<boost::shared_ptr<Matrix<T> > >(m_store[it->second[0]]);

	}
Exemple #13
0
stk::diag::Writer &
Registry::verbose_print(
  stk::diag::Writer &		dout) const
{
  if (dout.shouldPrint()) {
    dout << "Registry, size " << getRegistryMap().size() << stk::diag::push << stk::diag::dendl;

    for (RegistryMap::const_iterator it = getRegistryMap().begin(); it != getRegistryMap().end(); ++it)
      dout << (*it).first.second << " of type " << demangle((*it).first.first->name()) << " at " << (*it).second << stk::diag::dendl;
    dout << stk::diag::pop;
  }
  return dout;
}
Exemple #14
0
void print_backtrace(char const* label)
{
	void* stack[50];
	int size = backtrace(stack, 50);
	char** symbols = backtrace_symbols(stack, size);

	fprintf(stderr, "%s\n", label);
	for (int i = 1; i < size; ++i)
	{
		fprintf(stderr, "%d: %s\n", i, demangle(symbols[i]).c_str());
	}

	free(symbols);
}
Exemple #15
0
	Metatype &
	metatype( const std::string& pname ) {
		std::string name = pname;
#ifdef __BORLANDC__
		if ( name[name.length()-1]=='&' ) {
			name = name.substr( 0, name.length()-2 );
		}
#endif
		TypeMap::iterator it = _meta_types.find( name );
		if ( it == _meta_types.end() ) {
			throw Error( "Metatype '" + demangle( name ) + "' not declared" );
		}
		return *it->second;
	}
Exemple #16
0
DWORD WINAPI
MgwUnDecorateSymbolName(PCSTR DecoratedName, PSTR UnDecoratedName, DWORD UndecoratedLength, DWORD Flags)
{
    assert(DecoratedName != NULL);

    char *output_buffer = demangle(DecoratedName, Flags);
    if (output_buffer) {
        strncpy(UnDecoratedName, output_buffer, UndecoratedLength);
        free(output_buffer);
        return strlen(UnDecoratedName);
    }

    return UnDecorateSymbolName(DecoratedName, UnDecoratedName, UndecoratedLength, Flags);
}
char *
mpiPdemangle (const char *mangledSym)
{
  Name *ret;
  char *rest;
  unsigned long opts = 0x1;

  ret = demangle ((char *) mangledSym, &rest, opts);

  if (ret != NULL)
    return strdup (text (ret));
  else
    return NULL;
}
/**
 * \brief Common image info display function
 */
int	show_imageinfo(ImagePtr image) {
	if (fitsinfo) {
		std::cout << *image;
	}

	if (verbose) {
		std::cout << "bpp=" << image->bitsPerPixel();
		std::cout << " Bpp=" << image->bytesPerPixel();
		std::cout << " planes=" << image->planes();
		std::cout << " minvalue=" << image->minimum();
		std::cout << " maxvalue=" << image->maximum();
		std::cout << " pixel_type=";
		std::cout << demangle(image->pixel_type().name());
		std::cout << " ";
	}

	// find maximum, minimum, average and median values
	double	maximum = astro::image::filter::max(image);
	double	minimum = astro::image::filter::min(image);
	double	mean = astro::image::filter::mean(image);
	double	median = astro::image::filter::median(image);
	double	nans = -1;
	try {
		nans = astro::image::filter::countnans(image);
	} catch (...) {
		debug(LOG_DEBUG, DEBUG_LOG, 0, "ignoring nans");
	}
	
	std::cout << "min=" << minimum;
	if (median < mean) {
		std::cout << " median=" << median;
		std::cout << " mean=" << mean;
	} else {
		std::cout << " mean=" << mean;
		std::cout << " median=" << median;
	}
	std::cout << " max=" << maximum;
	if (nans >= 0) {
		std::cout << " nans=" << nans;
	}
	if (image->getMosaicType() != MosaicType()) {
		RGB<double>	meancolor
			= astro::image::filter::mean_color(image);
		std::cout << " red=" << meancolor.R;
		std::cout << " green=" << meancolor.G;
		std::cout << " blue=" << meancolor.B;
	}

	return EXIT_SUCCESS;
}
Exemple #19
0
std::string StackTrace::toString() const
{
    char ** symbols = backtrace_symbols(frames, frames_size);
    std::stringstream res;

    if (!symbols)
        return "Cannot get symbols for stack trace.\n";

    try
    {
        for (size_t i = 0, size = frames_size; i < size; ++i)
        {
            /// We do "demangling" of names. The name is in parenthesis, before the '+' character.

            char * name_start = nullptr;
            char * name_end = nullptr;
            std::string demangled_name;
            int status = 0;

            if (nullptr != (name_start = strchr(symbols[i], '('))
                && nullptr != (name_end = strchr(name_start, '+')))
            {
                ++name_start;
                *name_end = '\0';
                demangled_name = demangle(name_start, status);
                *name_end = '+';
            }

            res << i << ". ";

            if (0 == status && name_start && name_end)
            {
                res.write(symbols[i], name_start - symbols[i]);
                res << demangled_name << name_end;
            }
            else
                res << symbols[i];

            res << std::endl;
        }
    }
    catch (...)
    {
        free(symbols);
        throw;
    }

    free(symbols);
    return res.str();
}
Exemple #20
0
static bfd_boolean
cref_fill_array (struct cref_hash_entry *h, void *data)
{
  struct cref_hash_entry ***pph = data;

  ASSERT (h->demangled == NULL);
  h->demangled = demangle (h->root.string);

  **pph = h;

  ++*pph;

  return TRUE;
}
Exemple #21
0
Registry *
Registry::getFactoryPtr(
  const NamePair &      name_pair) const
{
  Registry *creator_function = (Registry *) getFuncPtr(name_pair);
  if (creator_function)
    return creator_function;
  else {
    std::ostringstream strout;
    strout << "Registry does not contain function with signature " << demangle(name_pair.first->name())
           << " and derived name '" << name_pair.second << "'";
    throw std::invalid_argument(strout.str());
  }
}
Exemple #22
0
	/*! \brief It pack any object checking that the object does not have pointers inside
	 *
	 * \param ext preallocated memory where to pack the objects
	 * \param obj object to pack
	 * \param sts pack-stat info
	 *
	 */
	static void pack(ExtPreAlloc<Mem> & ext, T & obj, Pack_stat & sts)
	{
#ifdef DEBUG
		if (ext.ref() == 0)
			std::cerr << "Error : " << __FILE__ << ":" << __LINE__ << " the reference counter of mem should never be zero when packing \n";

		if (obj.noPointers() == false)
			std::cerr << "Error: " << __FILE__ << ":" << __LINE__ << " the type " << demangle(typeid(T).name()) << " has pointers inside, sending pointers values has no sense\n";
#endif
		ext.allocate(sizeof(T));
		memcpy((T *)ext.getPointer(),&obj,sizeof(T));

		// Update statistic
		sts.incReq();
	}
Exemple #23
0
void *
Registry::getFunctionPtr(
  const NamePair &      name_pair) const
{
  void *creator_function = getFuncPtr(name_pair);
  if (creator_function)
    return creator_function;
  else {
    std::ostringstream strout;
    strout << "User subroutine " << name_pair.second << "\n"
           << " with signature " << demangle(name_pair.first->name()) << "\n"
           << " not found in registry";
    throw std::invalid_argument(strout.str());
  }
}
Exemple #24
0
std::string process_trace(const char *name)
{
  std::string fullname = name;
  std::string saved_begin, saved_end;
  size_t namestart, nameend;

  /**
   * The Apple backtrace function returns more information than the Linux version.
   * We need to pass only the function name to the demangler or it won't decode it for us.
   *
   * lineno: stackframeno                 address functionname + offset
   */

#ifdef __APPLE__
  namestart = fullname.find("0x");
  if (namestart != std::string::npos)
  {
    namestart = fullname.find(' ', namestart) + 1;
    saved_begin = fullname.substr(0, namestart);
  }
  else
    namestart = 0;
  nameend = fullname.find('+');
  if (nameend == std::string::npos ||
      nameend <= namestart)
    nameend = fullname.size();
  else
  {
    nameend -= 1;
    saved_end = fullname.substr(nameend, fullname.length());
  }
#else
  namestart = fullname.find('(');
  if (namestart == std::string::npos)
    return fullname;
  else
    namestart++;
  nameend = fullname.find('+');
  if (nameend == std::string::npos ||
      nameend <= namestart)
    return fullname;
#endif

  std::string type_name = fullname.substr(namestart, nameend - namestart);

  // Try to demangle now
  return saved_begin + demangle(type_name.c_str()) + saved_end;
}
__LIBC_HIDDEN__ void log_backtrace(uintptr_t* frames, size_t frame_count) {
  uintptr_t self_bt[16];
  if (frames == NULL) {
    frame_count = get_backtrace(self_bt, 16);
    frames = self_bt;
  }

  __libc_format_log(ANDROID_LOG_ERROR, "libc",
                    "*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***\n");

  for (size_t i = 0 ; i < frame_count; ++i) {
    uintptr_t offset = 0;
    const char* symbol = NULL;

    Dl_info info;
    if (dladdr((void*) frames[i], &info) != 0) {
      offset = reinterpret_cast<uintptr_t>(info.dli_saddr);
      symbol = info.dli_sname;
    }

    uintptr_t rel_pc;
    const mapinfo_t* mi = (gMapInfo != NULL) ? mapinfo_find(gMapInfo, frames[i], &rel_pc) : NULL;
    const char* soname = (mi != NULL) ? mi->name : info.dli_fname;
    if (soname == NULL) {
      soname = "<unknown>";
    }
    if (symbol != NULL) {
      // TODO: we might need a flag to say whether it's safe to allocate (demangling allocates).
      char* demangled_symbol = demangle(symbol);
      const char* best_name = (demangled_symbol != NULL) ? demangled_symbol : symbol;

      __libc_format_log(ANDROID_LOG_ERROR, "libc",
                        "          #%02zd  pc %0*" PRIxPTR "  %s (%s+%" PRIuPTR ")",
                        i,
                        static_cast<int>(2 * sizeof(void*)), rel_pc,
                        soname,
                        best_name, frames[i] - offset);

      free(demangled_symbol);
    } else {
      __libc_format_log(ANDROID_LOG_ERROR, "libc",
                        "          #%02zd  pc %0*" PRIxPTR "  %s",
                        i,
                        static_cast<int>(2 * sizeof(void*)), rel_pc,
                        soname);
    }
  }
}
Exemple #26
0
std::string getBacktraceString() {
	const static int MAX_FRAMES = 4096;
	void** buffer = new void*[MAX_FRAMES];
	int numTraced = backtrace(buffer, MAX_FRAMES);
	char** symbols = backtrace_symbols(buffer, numTraced); 

	std::stringstream ss;

	for(int i=numTraced-1; i>0; --i) {
		ss << format("%4d: %s\n", i, demangle(symbols[i]));
	}

	free(symbols); // malloc'ed by backtrace_symbols()

	return ss.str();
}
Exemple #27
0
TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth)
{
	void* stack[50];
	int size = backtrace(stack, 50);
	char** symbols = backtrace_symbols(stack, size);

	for (int i = 1; i < size && len > 0; ++i)
	{
		int ret = snprintf(out, len, "%d: %s\n", i, demangle(symbols[i]).c_str());
		out += ret;
		len -= ret;
		if (i - 1 == max_depth && max_depth > 0) break;
	}

	free(symbols);
}
void	AsynchronousAction::execute() {
	if (_action) {
		try {
			_action->execute();
		} catch (const std::exception& x) {
			debug(LOG_ERR, DEBUG_LOG, 0, "error %s in action: %s",
				demangle(typeid(x).name()).c_str(),
				x.what());
		} catch (...) {
			debug(LOG_ERR, DEBUG_LOG, 0, "error in action");
		}
	} else {
		debug(LOG_ERR, DEBUG_LOG, 0, "no action present");
	}
	busy(false);
}
std::string decode( char *message)
{
    std::string msg(message);
    std::string res(message);

    std::string::size_type popen = msg.find('(');
    if ( popen != std::string::npos )
    {
        std::string::size_type plus = msg.find('+');
        res = std::string(message,popen+1) + " ";
        std::string mangled( message, popen+1, plus -popen -1 );
        res += demangle(mangled) + " ";
        res += std::string( message + plus, message + strlen(message) );
    }
    return res;
}
Exemple #30
0
void *
Registry::getPluginPtr(
  const KeyPair &      key_pair) const
{
  void *creator_function = getFuncPtr(key_pair);
  if (creator_function)
    return creator_function;
  else {
    std::ostringstream strout;

    strout << "User plugin creator function with base class '" << demangle(name_pair.first->name())
           << "' and derived class name '" << name_pair.second
           << "' not found in registry";
    throw std::invalid_argument(strout.str());
  }
}