コード例 #1
0
void InstanceFieldsLayoutPass::mangle_fields( ClassType* ctype ) {
  BasicSymbolTable* symtab =
    ctype->get_group_symbol_table();
  Iter<SymbolTableObject*> iter =
    symtab->get_symbol_table_object_iterator();

  while( iter.is_valid() ) {
    InstanceFieldSymbol* fsym =
      to<InstanceFieldSymbol>( iter.current() );

    if ( _verbose ) {
      //      cout << fsym->get_name().c_str() << " -> "
      //	   << mangled_name(fsym).c_str() << endl;
    }

    symtab->change_name( fsym, mangled_name(fsym) );
    iter.next();
  }
}
コード例 #2
0
ファイル: exceptionobj.C プロジェクト: svarshavchik/libcxx
stacktrace::stacktrace() noexcept
{
#if HAVE_BACKTRACE
	int n=32;

	while (1)
	{
		void *funcaddrs[n];

		int nn=::backtrace(funcaddrs, n);

		if (nn == n)
		{
			n *= 2;
			continue;
		}

		std::ostringstream o;

		char **syms=backtrace_symbols(funcaddrs, nn);

		if (!syms)
			break;

		std::string syms_s[nn];

		for (n=0; n<nn; n++)
		{
			try {
				syms_s[n]=syms[n];
			} catch (...)
			{
				free(syms);
				return;
			}
		}

		free(syms);

		for (n=0; n<nn; n++)
		{
			std::string::iterator b=syms_s[n].begin();
			std::string::iterator e=syms_s[n].end();

			std::string::iterator p=std::find(b, e, ' ');
			std::string::iterator q;

			// glibc: {exename}({symbol}+{0xHEXOFFSET}){space}...

			if (p == e)
				continue;

			if ((q=std::find(b, p, '(')) != p)
			{
				if (*--p != ')')
					continue;
				++q;
			}

			p=std::find(q, p, '+');

			std::string mangled_name(q, p);

			int status;
			char *t=abi::__cxa_demangle(mangled_name.c_str(),
						    0, 0, &status);

			if (status == 0)
			{
				try {
					syms_s[n]=std::string(syms_s[n].begin(),
							      q) + t +
						std::string(p, syms_s[n].end());
					free(t);
				} catch (...)
				{
					free(t);
				}
			}
		}

		size_t buf_s=1;

		for (n=0; n<nn; n++)
		{
			buf_s += syms_s[n].size()+1;
		}

		char buf[buf_s];

		buf[0]=0;

		// Toss away the last stack frame -- this function.

		for (n=1; n<nn; n++)
		{
			strcat(strcat(buf, syms_s[n].c_str()), "\n");
		}

		backtrace=buf;
		break;
	}
#endif

#if HAVE_LIBUNWIND

	std::ostringstream o;
	o << std::hex << std::setfill('0');

	unw_cursor_t cursor;
	unw_context_t uc;
	unw_word_t ip;

	unw_getcontext(&uc);
	unw_init_local(&cursor, &uc);
	while (unw_step(&cursor) > 0)
	{
		Dl_info info;

		unw_get_reg(&cursor, UNW_REG_IP, &ip);

		if (dladdr((void *)ip, &info))
		{
			unw_word_t diff = ip - (unw_word_t)info.dli_saddr;

			o << info.dli_fname << "(";

			int status;
			char *t=abi::__cxa_demangle(info.dli_sname,
						    0, 0, &status);

			if (t)
			{
				o << t;
				free(t);
			}
			else
			{
				o << info.dli_sname;
			}

			if (diff)
			{
				o << "+0x"
				  << std::setw(0)
				  << diff;
			}
			o << ")";
		}
		else
		{
			o << "<unknown>";
		}

		o << " [0x" << std::setw(sizeof(ip)*2) << std::hex
		  << ip << "]" << std::endl;
	}

	backtrace=o.str();
#endif
}