当前位置: 首页>>代码示例>>C++>>正文


C++ SymbolTable::ForEachSymbol方法代码示例

本文整理汇总了C++中SymbolTable::ForEachSymbol方法的典型用法代码示例。如果您正苦于以下问题:C++ SymbolTable::ForEachSymbol方法的具体用法?C++ SymbolTable::ForEachSymbol怎么用?C++ SymbolTable::ForEachSymbol使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SymbolTable的用法示例。


在下文中一共展示了SymbolTable::ForEachSymbol方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ForEachSymbol

void MemoryUtils::ForEachSymbol(void *handle, const std::function<bool(Symbol *)>& functor)
{
	/* do a bogus symbol lookup to force everything into the symbol table cache */
	assert(ResolveSymbol(handle, "________________") == nullptr);
	
#ifdef PLATFORM_LINUX
	struct link_map *dlmap;
	LibSymbolTable *libtable;
	SymbolTable *table;

	dlmap = (struct link_map *)handle;
	table = NULL;
	
	/* See if we already have a symbol table for this library */
	for (size_t i = 0; i < m_SymTables.size(); i++)
	{
		libtable = m_SymTables[i];
		if (libtable->lib_base == dlmap->l_addr)
		{
			table = &libtable->table;
			break;
		}
	}

	/* If we don't have a symbol table for this library, then create one */
	if (table == NULL)
	{
		libtable = new LibSymbolTable();
		libtable->table.Initialize();
		libtable->lib_base = dlmap->l_addr;
		libtable->last_pos = 0;
		table = &libtable->table;
		m_SymTables.push_back(libtable);
	}
	
	table->ForEachSymbol(functor);
#elif defined PLATFORM_APPLE
	uintptr_t dlbase;
	uint32_t image_count;
	LibSymbolTable *libtable;
	SymbolTable *table;
	Symbol *symbol_entry;
	
	dlbase = 0;
	image_count = m_ImageList->infoArrayCount;
	table = NULL;
	
	/* Loop through mach-o images in process.
	 * We can skip index 0 since that is just the executable.
	 */
	for (uint32_t i = 1; i < image_count; i++)
	{
		const struct dyld_image_info &info = m_ImageList->infoArray[i];
		
		/* "Load" each one until we get a matching handle */
		void *h = dlopen(info.imageFilePath, RTLD_NOLOAD);
		if (h == handle)
		{
			dlbase = (uintptr_t)info.imageLoadAddress;
			dlclose(h);
			break;
		}
		
		dlclose(h);
	}
	
	if (!dlbase)
	{
		/* Uh oh, we couldn't find a matching handle */
		return;
	}
	
	/* See if we already have a symbol table for this library */
	for (size_t i = 0; i < m_SymTables.size(); i++)
	{
		libtable = m_SymTables[i];
		if (libtable->lib_base == dlbase)
		{
			table = &libtable->table;
			break;
		}
	}
	
	/* If we don't have a symbol table for this library, then create one */
	if (table == NULL)
	{
		libtable = new LibSymbolTable();
		libtable->table.Initialize();
		libtable->lib_base = dlbase;
		libtable->last_pos = 0;
		table = &libtable->table;
		m_SymTables.push_back(libtable);
	}
	
	table->ForEachSymbol(functor);
#endif
}
开发者ID:sigsegv-mvm,项目名称:sigsegv-mvm,代码行数:97,代码来源:MemoryUtils.cpp


注:本文中的SymbolTable::ForEachSymbol方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。