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


C++ SymSetOptions函数代码示例

本文整理汇总了C++中SymSetOptions函数的典型用法代码示例。如果您正苦于以下问题:C++ SymSetOptions函数的具体用法?C++ SymSetOptions怎么用?C++ SymSetOptions使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: GetInstance

//static
void MemoryManager::DumpMemory()
{
	static int dumpCount = 0;
	MemoryManager* instance = GetInstance();
	DWORD64  dwDisplacement = 0;
	DWORD64  dwAddress;
	IMAGEHLP_LINE64 line;
	DWORD	 dwLineDisplacement;
	DWORD  error;
	HANDLE hProcess;

	char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)];
	PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer;

	SymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS | SYMOPT_LOAD_LINES);

	hProcess = GetCurrentProcess();

	if (!SymInitialize(hProcess, NULL, TRUE))
	{
		error = GetLastError();
		LogError("SymInitialize returned error : %d\n", error);
	}

	std::stringstream filename;
	filename << "MemDump" << dumpCount++ << ".txt";

	FILE *myFile = nullptr;
	errno_t openResult = fopen_s(&myFile, filename.str().c_str(), "w");
	XTVERIFY(openResult == 0);

	if (myFile)
	{
		fprintf(myFile, "Total Memory Used:%u\n\n", (uint32)instance->m_totalAlloc);


		Alloc* currentAlloc = instance->m_head;
		while(currentAlloc != NULL)
		{
			dwAddress = (DWORD64)currentAlloc->m_stack[2];
			line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);

			fprintf(myFile, "Size: %u\n", (uint32)currentAlloc->m_size);

			if (currentAlloc->m_stackDepth >= 3 && SymGetLineFromAddr64(hProcess, dwAddress, &dwLineDisplacement, &line))
			{
				fprintf(myFile, "%s:%u\n", line.FileName, line.LineNumber);
			}
			else
			{
				fprintf(myFile, "Unknown File\n");
			}

			fprintf(myFile, "Callstack:\n");
		
			for(int i = 0; i < currentAlloc->m_stackDepth; i++)
			{
				dwAddress = (DWORD64)currentAlloc->m_stack[i];

				pSymbol->SizeOfStruct = 88; //sizeof(SYMBOL_INFO);
				pSymbol->MaxNameLen = MAX_SYM_NAME;

				if (SymFromAddr(hProcess, dwAddress, &dwDisplacement, pSymbol))
				{
					const char* name = pSymbol->Name;
					fprintf(myFile, "\t%i: %s\n", i, name);
				}
				else
				{
					fprintf(myFile, "\t%i: Unknown\n", i);
				}
			}

			fprintf(myFile, "\n");

			currentAlloc = currentAlloc->m_next;
		}

		_flushall();

		CONTEXT Context;
		memset(&Context, 0, sizeof(Context));
		RtlCaptureContext(&Context);


		fclose(myFile);
	}

	SymCleanup(hProcess);
}
开发者ID:Darrenbydesign,项目名称:HoloToolkit,代码行数:91,代码来源:MemoryManager.cpp

示例2: m_hProcess

 FunctionResolver::FunctionResolver(HANDLE processHandle)
     : m_hProcess(processHandle)
 {
     SymSetOptions(SYMOPT_DEBUG | SYMOPT_LOAD_ANYTHING);
 }
开发者ID:mazong1123,项目名称:injectorpp,代码行数:5,代码来源:functionresolver.cpp

示例3: main

int main(int argc, char *argv[]) {
  DWORD  error;
  HANDLE process;
  ULONG64 module_base;
  int i;
  char* search;
  char buf[256];   /* Enough to hold one hex address, I trust! */
  int rv = 0;
  /* We may add SYMOPT_UNDNAME if --demangle is specified: */
  DWORD symopts = SYMOPT_DEFERRED_LOADS | SYMOPT_DEBUG | SYMOPT_LOAD_LINES;
  char* filename = "a.out";         /* The default if -e isn't specified */
  int print_function_name = 0;      /* Set to 1 if -f is specified */

  for (i = 1; i < argc; i++) {
    if (strcmp(argv[i], "--functions") == 0 || strcmp(argv[i], "-f") == 0) {
      print_function_name = 1;
    } else if (strcmp(argv[i], "--demangle") == 0 ||
               strcmp(argv[i], "-C") == 0) {
      symopts |= SYMOPT_UNDNAME;
    } else if (strcmp(argv[i], "-e") == 0) {
      if (i + 1 >= argc) {
        fprintf(stderr, "FATAL ERROR: -e must be followed by a filename\n");
        return 1;
      }
      filename = argv[i+1];
      i++;     /* to skip over filename too */
    } else if (strcmp(argv[i], "--help") == 0) {
      usage();
      exit(0);
    } else {
      usage();
      exit(1);
    }
  }

  process = GetCurrentProcess();

  if (!SymInitialize(process, NULL, FALSE)) {
    error = GetLastError();
    fprintf(stderr, "SymInitialize returned error : %d\n", error);
    return 1;
  }

  search = malloc(SEARCH_CAP);
  if (SymGetSearchPath(process, search, SEARCH_CAP)) {
    if (strlen(search) + sizeof(";" WEBSYM) > SEARCH_CAP) {
      fprintf(stderr, "Search path too long\n");
      SymCleanup(process);
      return 1;
    }
    strcat(search, ";" WEBSYM);
  } else {
    error = GetLastError();
    fprintf(stderr, "SymGetSearchPath returned error : %d\n", error);
    rv = 1;                   /* An error, but not a fatal one */
    strcpy(search, WEBSYM);   /* Use a default value */
  }
  if (!SymSetSearchPath(process, search)) {
    error = GetLastError();
    fprintf(stderr, "SymSetSearchPath returned error : %d\n", error);
    rv = 1;                   /* An error, but not a fatal one */
  }

  SymSetOptions(symopts);
  module_base = SymLoadModuleEx(process, NULL, filename, NULL, 0, 0, NULL, 0);
  if (!module_base) {
    /* SymLoadModuleEx failed */
    error = GetLastError();
    fprintf(stderr, "SymLoadModuleEx returned error : %d for %s\n",
            error, filename);
    SymCleanup(process);
    return 1;
  }

  buf[sizeof(buf)-1] = '\0';  /* Just to be safe */
  while (fgets(buf, sizeof(buf)-1, stdin)) {
    /* GNU addr2line seems to just do a strtol and ignore any
     * weird characters it gets, so we will too.
     */
    unsigned __int64 addr = _strtoui64(buf, NULL, 16);
    ULONG64 buffer[(sizeof(SYMBOL_INFO) +
                    MAX_SYM_NAME*sizeof(TCHAR) +
                    sizeof(ULONG64) - 1)
                   / sizeof(ULONG64)];
    PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer;
    IMAGEHLP_LINE64 line;
    DWORD dummy;
    pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
    pSymbol->MaxNameLen = MAX_SYM_NAME;
    if (print_function_name) {
      if (SymFromAddr(process, (DWORD64)addr, NULL, pSymbol)) {
        printf("%s\n", pSymbol->Name);
      } else {
        printf("??\n");
      }
    }
    line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
    if (SymGetLineFromAddr64(process, (DWORD64)addr, &dummy, &line)) {
      printf("%s:%d\n", line.FileName, (int)line.LineNumber);
    } else {
//.........这里部分代码省略.........
开发者ID:01org,项目名称:linux-sgx,代码行数:101,代码来源:addr2line-pdb.c

示例4: backtrace

std::ostream& backtrace( std::ostream& os )
{
#ifdef _WIN32
    // Sym* functions from DbgHelp are not thread-safe...
    static Lock lock;
    ScopedMutex<> mutex( lock );
    
    typedef USHORT (WINAPI *CaptureStackBackTraceType)( __in ULONG, __in ULONG,
                                                        __out PVOID*,
                                                        __out_opt PULONG );
    CaptureStackBackTraceType backtraceFunc = (CaptureStackBackTraceType)
       GetProcAddress(LoadLibrary("kernel32.dll"), "RtlCaptureStackBackTrace");
    if( !backtraceFunc )
        return os;

    SymSetOptions( SYMOPT_UNDNAME | SYMOPT_LOAD_LINES );
    HANDLE hProcess = GetCurrentProcess();
    if( !SymInitialize( hProcess, 0, TRUE ))
        return os;  
    
    void* stack[ LB_BACKTRACE_DEPTH ];
    unsigned short frames = (backtraceFunc)( 0, LB_BACKTRACE_DEPTH, stack, 0 );
  
    SYMBOL_INFO* symbol = (SYMBOL_INFO*)calloc( sizeof(SYMBOL_INFO) +
                                         (LB_SYMBOL_LENGTH+-1)*sizeof(char), 1 );
    symbol->MaxNameLen   = LB_SYMBOL_LENGTH;
    symbol->SizeOfStruct = sizeof( SYMBOL_INFO );
    
    os << disableFlush << disableHeader << indent << std::endl;
    for( unsigned short i = 0; i < frames; ++i )
    {
        os << frames-i-1 << ": ";
        if ( !SymFromAddr( hProcess, (DWORD64)stack[i], 0, symbol ))
            os << "Unknown symbol";
        else
        {
            os << symbol->Name << " - ";            
            IMAGEHLP_LINE64 line = { sizeof(IMAGEHLP_LINE64) };
            if( !SymGetLineFromAddr64( hProcess, (DWORD64)stack[i], 0, &line ))
                os << std::hex << "0x" << symbol->Address << std::dec;
            else
                os << line.FileName << ":" << line.LineNumber;
        }
        os << std::endl;                
    }
    os << exdent << enableHeader << enableFlush;
    free( symbol );
    SymCleanup( hProcess );
#else
    void* callstack[ LB_BACKTRACE_DEPTH ];
    const int frames = ::backtrace( callstack, LB_BACKTRACE_DEPTH );
    char** names = ::backtrace_symbols( callstack, frames );
    os << disableFlush << disableHeader << indent << std::endl;
    for( int i = 1; i < frames; ++i )
    {
        std::string name = names[ i ];
#  ifdef __linux__
        const size_t symbolPos = name.find( "(_" );
#  else
        const size_t symbolPos = name.find( " _" );
#  endif
        if( symbolPos != std::string::npos )
            name = name.substr( symbolPos+1, name.length( ));

#  ifdef __linux__
        const size_t spacePos = name.find( '+' );
#  else
        const size_t spacePos = name.find( ' ' );
#  endif
        if( spacePos != std::string::npos )
            name = name.substr( 0, spacePos );

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

        if( symbolPos == std::string::npos || spacePos == std::string::npos )
            os << names[ i ] << std::endl;
        else
        {
            if( demangled )
            {
                os << demangled << std::endl;
                free( demangled );
            }
            else
                os << name << std::endl;
        }
    }
    os << exdent << enableHeader << enableFlush;
    ::free( names );
#endif

    return os;
}
开发者ID:ferol,项目名称:Lunchbox,代码行数:94,代码来源:debug.cpp

示例5: symbol_get_lvalue

/***********************************************************************
 *           symbol_get_lvalue
 *
 * Get the address of a named symbol.
 * Return values:
 *      sglv_found:   if the symbol is found
 *      sglv_unknown: if the symbol isn't found
 *      sglv_aborted: some error occurred (likely, many symbols of same name exist,
 *          and user didn't pick one of them)
 */
enum sym_get_lval symbol_get_lvalue(const char* name, const int lineno,
                                    struct dbg_lvalue* rtn, BOOL bp_disp)
{
    struct sgv_data             sgv;
    int		                i;
    char                        buffer[512];
    DWORD                       opt;
    IMAGEHLP_STACK_FRAME        ihsf;

    if (strlen(name) + 4 > sizeof(buffer))
    {
        WINE_WARN("Too long symbol (%s)\n", name);
        return sglv_unknown;
    }

    sgv.num        = 0;
    sgv.num_thunks = 0;
    sgv.name       = &buffer[2];
    sgv.do_thunks  = DBG_IVAR(AlwaysShowThunks);

    if (strchr(name, '!'))
    {
        strcpy(buffer, name);
    }
    else
    {
        buffer[0] = '*';
        buffer[1] = '!';
        strcpy(&buffer[2], name);
    }

    /* this is a wine specific options to return also ELF modules in the
     * enumeration
     */
    SymSetOptions((opt = SymGetOptions()) | 0x40000000);
    SymEnumSymbols(dbg_curr_process->handle, 0, buffer, sgv_cb, (void*)&sgv);

    if (!sgv.num)
    {
        const char*   ptr = strchr(name, '!');
        if ((ptr && ptr[1] != '_') || (!ptr && *name != '_'))
        {
            if (ptr)
            {
                int offset = ptr - name;
                memcpy(buffer, name, offset + 1);
                buffer[offset + 1] = '_';
                strcpy(&buffer[offset + 2], ptr + 1);
            }
            else
            {
                buffer[0] = '*';
                buffer[1] = '!';
                buffer[2] = '_';
                strcpy(&buffer[3], name);
            }
            SymEnumSymbols(dbg_curr_process->handle, 0, buffer, sgv_cb, (void*)&sgv);
        }
    }
    SymSetOptions(opt);

    /* now grab local symbols */
    if (stack_get_current_frame(&ihsf) && sgv.num < NUMDBGV)
    {
        sgv.frame_offset = ihsf.FrameOffset;
        SymEnumSymbols(dbg_curr_process->handle, 0, name, sgv_cb, (void*)&sgv);
    }

    if (!sgv.num)
    {
        dbg_printf("No symbols found for %s\n", name);
        return sglv_unknown;
    }

    /* recompute potential offsets for functions (linenumber, skip prolog) */
    for (i = 0; i < sgv.num; i++)
    {
        if (sgv.syms[i].flags & (SYMFLAG_REGISTER|SYMFLAG_REGREL|SYMFLAG_LOCAL|SYMFLAG_THUNK))
            continue;

        if (lineno == -1)
        {
            struct dbg_type     type;
            ULONG64             addr;

            type.module = sgv.syms[i].lvalue.type.module;
            type.id     = sgv.syms[i].sym_info;
            if (bp_disp && symbol_get_debug_start(&type, &addr))
                sgv.syms[i].lvalue.addr.Offset = addr;
        }
//.........这里部分代码省略.........
开发者ID:WASSUM,项目名称:longene_travel,代码行数:101,代码来源:symbol.c

示例6: symbol_get_line

/***********************************************************************
 *           symbol_get_line
 *
 * Find the symbol nearest to a given address.
 * Returns sourcefile name and line number in a format that the listing
 * handler can deal with.
 */
BOOL symbol_get_line(const char* filename, const char* name, IMAGEHLP_LINE* line)
{
    struct sgv_data     sgv;
    char                buffer[512];
    DWORD               opt, disp, linear;
    unsigned            i, found = FALSE;
    IMAGEHLP_LINE       il;

    sgv.num        = 0;
    sgv.num_thunks = 0;
    sgv.name       = &buffer[2];
    sgv.do_thunks  = FALSE;

    buffer[0] = '*';
    buffer[1] = '!';
    strcpy(&buffer[2], name);

    /* this is a wine specific options to return also ELF modules in the
     * enumeration
     */
    SymSetOptions((opt = SymGetOptions()) | 0x40000000);
    if (!SymEnumSymbols(dbg_curr_process->handle, 0, buffer, sgv_cb, (void*)&sgv))
    {
        SymSetOptions(opt);
        return FALSE;
    }

    if (!sgv.num && (name[0] != '_'))
    {
        buffer[2] = '_';
        strcpy(&buffer[3], name);
        if (!SymEnumSymbols(dbg_curr_process->handle, 0, buffer, sgv_cb, (void*)&sgv))
        {
            SymSetOptions(opt);
            return FALSE;
        }
    }
    SymSetOptions(opt);

    for (i = 0; i < sgv.num; i++)
    {
        linear = (DWORD)memory_to_linear_addr(&sgv.syms[i].lvalue.addr);

        il.SizeOfStruct = sizeof(il);
        if (!SymGetLineFromAddr(dbg_curr_process->handle, linear, &disp, &il))
            continue;
        if (filename && strcmp(line->FileName, filename)) continue;
        if (found)
        {
            WINE_FIXME("Several found, returning first (may not be what you want)...\n");
            break;
        }
        found = TRUE;
        *line = il;
    }
    if (!found)
    {
        if (filename)   dbg_printf("No such function %s in %s\n", name, filename);
	else            dbg_printf("No such function %s\n", name);
        return FALSE;
    }
    return TRUE;
}
开发者ID:WASSUM,项目名称:longene_travel,代码行数:70,代码来源:symbol.c

示例7: stack_trace

static void stack_trace( PEXCEPTION_POINTERS pInfo )
{
	char message[1024];
	int len = 0;
	size_t i;
	HANDLE process = GetCurrentProcess();
	HANDLE thread = GetCurrentThread();
	IMAGEHLP_LINE64 line;
	DWORD dline = 0;
	DWORD options;
	CONTEXT context;
	STACKFRAME64 stackframe;
	DWORD image;

	memcpy( &context, pInfo->ContextRecord, sizeof(CONTEXT) );
	options = SymGetOptions(); 
	options |= SYMOPT_DEBUG;
	options |= SYMOPT_LOAD_LINES;
	SymSetOptions( options ); 

	SymInitialize( process, NULL, TRUE );

	

	ZeroMemory( &stackframe, sizeof(STACKFRAME64) );

#ifdef _M_IX86
	image = IMAGE_FILE_MACHINE_I386;
	stackframe.AddrPC.Offset = context.Eip;
	stackframe.AddrPC.Mode = AddrModeFlat;
	stackframe.AddrFrame.Offset = context.Ebp;
	stackframe.AddrFrame.Mode = AddrModeFlat;
	stackframe.AddrStack.Offset = context.Esp;
	stackframe.AddrStack.Mode = AddrModeFlat;
#elif _M_X64
	image = IMAGE_FILE_MACHINE_AMD64;
	stackframe.AddrPC.Offset = context.Rip;
	stackframe.AddrPC.Mode = AddrModeFlat;
	stackframe.AddrFrame.Offset = context.Rsp;
	stackframe.AddrFrame.Mode = AddrModeFlat;
	stackframe.AddrStack.Offset = context.Rsp;
	stackframe.AddrStack.Mode = AddrModeFlat;
#elif _M_IA64
	image = IMAGE_FILE_MACHINE_IA64;
	stackframe.AddrPC.Offset = context.StIIP;
	stackframe.AddrPC.Mode = AddrModeFlat;
	stackframe.AddrFrame.Offset = context.IntSp;
	stackframe.AddrFrame.Mode = AddrModeFlat;
	stackframe.AddrBStore.Offset = context.RsBSP;
	stackframe.AddrBStore.Mode = AddrModeFlat;
	stackframe.AddrStack.Offset = context.IntSp;
	stackframe.AddrStack.Mode = AddrModeFlat;
#endif
	len += snprintf( message + len, 1024 - len, "Sys_Crash: address %p, code %p\n", pInfo->ExceptionRecord->ExceptionAddress, pInfo->ExceptionRecord->ExceptionCode );
	if( SymGetLineFromAddr64( process, (DWORD64)pInfo->ExceptionRecord->ExceptionAddress, &dline, &line ) )
	{
		len += snprintf(message + len, 1024 - len,"Exception: %s:%d:%d\n", (char*)line.FileName, (int)line.LineNumber, (int)dline);
	}
	if( SymGetLineFromAddr64( process, stackframe.AddrPC.Offset, &dline, &line ) )
	{
		len += snprintf(message + len, 1024 - len,"PC: %s:%d:%d\n", (char*)line.FileName, (int)line.LineNumber, (int)dline);
	}
	if( SymGetLineFromAddr64( process, stackframe.AddrFrame.Offset, &dline, &line ) )
	{
		len += snprintf(message + len, 1024 - len,"Frame: %s:%d:%d\n", (char*)line.FileName, (int)line.LineNumber, (int)dline);
	}
	for( i = 0; i < 25; i++ )
	{
		char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)];
		PSYMBOL_INFO symbol = (PSYMBOL_INFO)buffer;
		BOOL result = StackWalk64(
			image, process, thread,
			&stackframe, &context, NULL,
			SymFunctionTableAccess64, SymGetModuleBase64, NULL);

		DWORD64 displacement = 0;
		if( !result )
			break;

		
		symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
		symbol->MaxNameLen = MAX_SYM_NAME;

		len += snprintf( message + len, 1024 - len, "% 2d %p", i, (void*)stackframe.AddrPC.Offset );
		if( SymFromAddr( process, stackframe.AddrPC.Offset, &displacement, symbol ) )
		{
			len += snprintf( message + len, 1024 - len, " %s ", symbol->Name );
		}
		if( SymGetLineFromAddr64( process, stackframe.AddrPC.Offset, &dline, &line ) )
		{
			len += snprintf(message + len, 1024 - len,"(%s:%d:%d) ", (char*)line.FileName, (int)line.LineNumber, (int)dline);
		}
		len += snprintf( message + len, 1024 - len, "(");
		len += ModuleName( process, message + len, (void*)stackframe.AddrPC.Offset, 1024 - len );
		len += snprintf( message + len, 1024 - len, ")\n");
	}
#ifdef XASH_SDL
	if( host.type != HOST_DEDICATED ) // let system to restart server automaticly
		SDL_ShowSimpleMessageBox( SDL_MESSAGEBOX_ERROR,"Sys_Crash", message, host.hWnd );
#endif
//.........这里部分代码省略.........
开发者ID:nekonomicon,项目名称:xash3d,代码行数:101,代码来源:sys_win.c

示例8: CreateFile

int CMiniDumpReader::Open(CString sFileName, CString sSymSearchPath)
{  
    static DWORD dwProcessID = 0;

    if(m_bLoaded)
    {
        return 1;
    }

    m_sFileName = sFileName;
    m_sSymSearchPath = sSymSearchPath;

    m_hFileMiniDump = CreateFile(
        sFileName, 
        FILE_ALL_ACCESS, 
        0, 
        NULL, 
        OPEN_EXISTING, 
        NULL, 
        NULL);

    if(m_hFileMiniDump==INVALID_HANDLE_VALUE)
    {
        Close();
        return 1;
    }

    m_hFileMapping = CreateFileMapping(
        m_hFileMiniDump, 
        NULL, 
        PAGE_READONLY, 
        0, 
        0, 
        0);

    if(m_hFileMapping==NULL)
    {
        Close();
        return 2;
    }

    m_pMiniDumpStartPtr = MapViewOfFile(
        m_hFileMapping, 
        FILE_MAP_READ, 
        0, 
        0, 
        0);

    if(m_pMiniDumpStartPtr==NULL)
    {    
        Close();
        return 3;
    }

    m_DumpData.m_hProcess = (HANDLE)(++dwProcessID);  

    DWORD dwOptions = 0;
    //dwOptions |= SYMOPT_DEFERRED_LOADS; // Symbols are not loaded until a reference is made requiring the symbols be loaded.
    dwOptions |= SYMOPT_EXACT_SYMBOLS; // Do not load an unmatched .pdb file. 
    dwOptions |= SYMOPT_FAIL_CRITICAL_ERRORS; // Do not display system dialog boxes when there is a media failure such as no media in a drive.
    dwOptions |= SYMOPT_UNDNAME; // All symbols are presented in undecorated form.   
    SymSetOptions(dwOptions);

    strconv_t strconv;
    BOOL bSymInit = SymInitializeW(
        m_DumpData.m_hProcess,
        strconv.t2w(sSymSearchPath), 
        FALSE);

    if(!bSymInit)
    {
        m_DumpData.m_hProcess = NULL;
        Close();
        return 5;
    }

    /*SymRegisterCallbackW64(
    m_DumpData.m_hProcess, 
    SymRegisterCallbackProc64,
    (ULONG64)this);*/

    m_bReadSysInfoStream = !ReadSysInfoStream();  
    m_bReadModuleListStream = !ReadModuleListStream();
    m_bReadThreadListStream = !ReadThreadListStream();
    m_bReadMemoryListStream = !ReadMemoryListStream();    
    m_bReadExceptionStream = !ReadExceptionStream();    

    m_bLoaded = true;
    return 0;
}
开发者ID:McSimp,项目名称:Borderlands2SDK,代码行数:90,代码来源:MinidumpReader.cpp

示例9: julia_init

void julia_init(char *imageFile)
{
    jl_page_size = jl_getpagesize();
    jl_find_stack_bottom();
    jl_dl_handle = jl_load_dynamic_library(NULL, JL_RTLD_DEFAULT);
#ifdef _OS_WINDOWS_
    uv_dlopen("ntdll.dll",jl_ntdll_handle); //bypass julia's pathchecking for system dlls
    uv_dlopen("Kernel32.dll",jl_kernel32_handle);
    uv_dlopen("msvcrt.dll",jl_crtdll_handle);
    uv_dlopen("Ws2_32.dll",jl_winsock_handle);
    _jl_exe_handle.handle = GetModuleHandleA(NULL);
#if defined(_CPU_X86_64_)
    SymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS);
    SymInitialize(GetCurrentProcess(), NULL, 1);
    needsSymRefreshModuleList = 0;
#endif
#endif
    jl_io_loop = uv_default_loop(); //this loop will internal events (spawining process etc.)
    init_stdio();

#if defined(__linux__)
    int ncores = jl_cpu_cores();
    if (ncores > 1) {
        cpu_set_t cpumask;
        CPU_ZERO(&cpumask);
        for(int i=0; i < ncores; i++) {
            CPU_SET(i, &cpumask);
        }
        sched_setaffinity(0, sizeof(cpu_set_t), &cpumask);
    }
#endif

#ifdef JL_GC_MARKSWEEP
    jl_gc_init();
    jl_gc_disable();
#endif
    jl_init_frontend();
    jl_init_types();
    jl_init_tasks(jl_stack_lo, jl_stack_hi-jl_stack_lo);
    jl_init_codegen();
    jl_an_empty_cell = (jl_value_t*)jl_alloc_cell_1d(0);

    jl_init_serializer();

    if (!imageFile) {
        jl_main_module = jl_new_module(jl_symbol("Main"));
        jl_main_module->parent = jl_main_module;
        jl_core_module = jl_new_module(jl_symbol("Core"));
        jl_core_module->parent = jl_main_module;
        jl_set_const(jl_main_module, jl_symbol("Core"),
                     (jl_value_t*)jl_core_module);
        jl_module_using(jl_main_module, jl_core_module);
        jl_current_module = jl_core_module;
        jl_init_intrinsic_functions();
        jl_init_primitives();
        jl_load("boot.jl");
        jl_get_builtin_hooks();
        jl_boot_file_loaded = 1;
        jl_init_box_caches();
    }

    if (imageFile) {
        JL_TRY {
            jl_restore_system_image(imageFile);
        }
        JL_CATCH {
            JL_PRINTF(JL_STDERR, "error during init:\n");
            jl_show(jl_stderr_obj(), jl_exception_in_transit);
            JL_PRINTF(JL_STDERR, "\n");
            jl_exit(1);
        }
    }

    // set module field of primitive types
    int i;
    void **table = jl_core_module->bindings.table;
    for(i=1; i < jl_core_module->bindings.size; i+=2) {
        if (table[i] != HT_NOTFOUND) {
            jl_binding_t *b = (jl_binding_t*)table[i];
            if (b->value && jl_is_datatype(b->value)) {
                jl_datatype_t *tt = (jl_datatype_t*)b->value;
                tt->name->module = jl_core_module;
            }
        }
    }

    // the Main module is the one which is always open, and set as the
    // current module for bare (non-module-wrapped) toplevel expressions.
    // it does "using Base" if Base is available.
    if (jl_base_module != NULL) {
        jl_add_standard_imports(jl_main_module);
    }
    // eval() uses Main by default, so Main.eval === Core.eval
    jl_module_import(jl_main_module, jl_core_module, jl_symbol("eval"));
    jl_current_module = jl_main_module;

#ifndef _OS_WINDOWS_
    struct sigaction actf;
    memset(&actf, 0, sizeof(struct sigaction));
    sigemptyset(&actf.sa_mask);
//.........这里部分代码省略.........
开发者ID:GeorgeSalt,项目名称:julia,代码行数:101,代码来源:init.c

示例10: USHORT

//https://msdn.microsoft.com/en-us/library/windows/desktop/bb204633(v=vs.85).aspx
void Util::getStackTrace(std::string& stream)
{
#ifdef _WIN32
    stream = "===========Call stack===========\n";
    typedef USHORT(WINAPI *CaptureStackBackTraceType)(__in ULONG, __in ULONG, __out PVOID*, __out_opt PULONG);
    CaptureStackBackTraceType func = (CaptureStackBackTraceType)(GetProcAddress(LoadLibraryA("kernel32.dll"), "RtlCaptureStackBackTrace"));

    if (func == NULL)
    {
        stream += "[Error] Failed to resolve Call Stack print function\n";
        return;
    }

    //Set to get the full decorated function name
    DWORD options = SymGetOptions();
    DWORD newOptions = options & ~SYMOPT_UNDNAME;
    newOptions = newOptions | SYMOPT_PUBLICS_ONLY;
    SymSetOptions(newOptions);

    // Quote from Microsoft Documentation:
    // ## Windows Server 2003 and Windows XP:
    // ## The sum of the FramesToSkip and FramesToCapture parameters must be less than 63.
    const int kMaxCallers = 62;

    void         * callers_stack[kMaxCallers];
    unsigned short frames;
    SYMBOL_INFO  * symbol;
    HANDLE         process;
    process = GetCurrentProcess();
    SymInitialize(process, NULL, TRUE);
    frames = (func)(0, kMaxCallers, callers_stack, NULL);
    symbol = (SYMBOL_INFO*)calloc(sizeof(SYMBOL_INFO) + 256 * sizeof(char), 1);
    symbol->MaxNameLen = 255;
    symbol->SizeOfStruct = sizeof(SYMBOL_INFO);

    //printf("(%016I64LX):\n", sample_address);
    //out << "(" << sample_address << "): " << std::endl;
    const unsigned short  MAX_CALLERS_SHOWN = 6;
    frames = frames < MAX_CALLERS_SHOWN ? frames : MAX_CALLERS_SHOWN;
    for (unsigned int i = 0; i < frames; i++)
    {
        SymFromAddr(process, (DWORD64)(callers_stack[i]), 0, symbol);
        //printf("*** %d: %016I64LX %s - 0x%0X\n", i, callers_stack[i], symbol->Name, symbol->Address);

        char undecoratedName[MAX_SYM_NAME];
        //UnDecorateSymbolName(symbol->Name, undecoratedName, MAX_SYM_NAME, UNDNAME_COMPLETE);
        stream += std::string(symbol->Name, symbol->NameLen) + "\n";
        //stream += std::string(undecoratedName) + "\n";

    }

    free(symbol);
    stream += "=======End of Call stack========\n";
#else
    stream = "===========Call stack===========\n";
    void *array[10];
    size_t size = 0;

    size = backtrace(array, 10);
    char** symbols = backtrace_symbols(array, size);

    if(symbols == nullptr)
    {
        printLog(LogMessageType::Error, __FILE__, __LINE__, "Failed to get symbols.");
        return;
    }

    for(size_t i = 0; i < size; i++)
    {
        int status = 0;
        //char* name = abi::__cxa_demangle(symbols[i], tmp, &dms, &status);

        //We have to create the subsequence first
        std::string tmp(symbols[i]);
		size_t tmp_i = tmp.find_first_of('+');
		size_t end_index = tmp_i != std::string::npos ? tmp_i : tmp.length() - 1;
        std::string symbol(tmp.begin() + tmp.find_first_of('(') + 1, tmp.begin() + end_index);

        char* name = abi::__cxa_demangle(symbol.c_str(), nullptr, nullptr, &status);
        if(status != 0)
        {
            //printLog(LogMessageType::Error, __FILE__, __LINE__, "Failed to demangle name \"%s\" with code %d", symbol.c_str(), status);
        }
        if(name == nullptr)
        {
            stream += std::string(symbols[i]) + "\n";
        }
        else
        {
            stream += std::string(name) + "\n";
            free(name);
        }
    }
    stream += "=======End of Call stack========\n";
#endif
}
开发者ID:cwriter,项目名称:SFMLGame,代码行数:97,代码来源:Util.cpp

示例11: julia_init

void julia_init(char *imageFile)
{
    jl_page_size = jl_getpagesize();
    jl_find_stack_bottom();
    jl_dl_handle = jl_load_dynamic_library(NULL, JL_RTLD_DEFAULT);
#ifdef _OS_WINDOWS_
    uv_dlopen("ntdll.dll",jl_ntdll_handle); //bypass julia's pathchecking for system dlls
    uv_dlopen("Kernel32.dll",jl_kernel32_handle);
    uv_dlopen("msvcrt.dll",jl_crtdll_handle);
    uv_dlopen("Ws2_32.dll",jl_winsock_handle);
    _jl_exe_handle.handle = GetModuleHandleA(NULL);
    if (!DuplicateHandle( GetCurrentProcess(), GetCurrentThread(),
                          GetCurrentProcess(), (PHANDLE)&hMainThread, 0,
                          TRUE, DUPLICATE_SAME_ACCESS )) {
        JL_PRINTF(JL_STDERR, "Couldn't access handle to main thread\n");
    }
#if defined(_CPU_X86_64_)
    SymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS);
    SymInitialize(GetCurrentProcess(), NULL, 1);
    needsSymRefreshModuleList = 0;
#endif
#endif
    jl_io_loop = uv_default_loop(); //this loop will internal events (spawining process etc.)
    init_stdio();

#if defined(__linux__)
    int ncores = jl_cpu_cores();
    if (ncores > 1) {
        cpu_set_t cpumask;
        CPU_ZERO(&cpumask);
        for(int i=0; i < ncores; i++) {
            CPU_SET(i, &cpumask);
        }
        sched_setaffinity(0, sizeof(cpu_set_t), &cpumask);
    }
#endif

#ifdef JL_GC_MARKSWEEP
    jl_gc_init();
    jl_gc_disable();
#endif
    jl_init_frontend();
    jl_init_types();
    jl_init_tasks(jl_stack_lo, jl_stack_hi-jl_stack_lo);
    jl_init_codegen();
    jl_an_empty_cell = (jl_value_t*)jl_alloc_cell_1d(0);

    jl_init_serializer();

    if (!imageFile) {
        jl_main_module = jl_new_module(jl_symbol("Main"));
        jl_main_module->parent = jl_main_module;
        jl_core_module = jl_new_module(jl_symbol("Core"));
        jl_core_module->parent = jl_main_module;
        jl_set_const(jl_main_module, jl_symbol("Core"),
                     (jl_value_t*)jl_core_module);
        jl_module_using(jl_main_module, jl_core_module);
        jl_current_module = jl_core_module;
        jl_init_intrinsic_functions();
        jl_init_primitives();
        jl_load("boot.jl");
        jl_get_builtin_hooks();
        jl_boot_file_loaded = 1;
        jl_init_box_caches();
    }

    if (imageFile) {
        JL_TRY {
            jl_restore_system_image(imageFile);
        }
        JL_CATCH {
            JL_PRINTF(JL_STDERR, "error during init:\n");
            jl_show(jl_stderr_obj(), jl_exception_in_transit);
            JL_PRINTF(JL_STDERR, "\n");
            jl_exit(1);
        }
    }

    // set module field of primitive types
    int i;
    void **table = jl_core_module->bindings.table;
    for(i=1; i < jl_core_module->bindings.size; i+=2) {
        if (table[i] != HT_NOTFOUND) {
            jl_binding_t *b = (jl_binding_t*)table[i];
            if (b->value && jl_is_datatype(b->value)) {
                jl_datatype_t *tt = (jl_datatype_t*)b->value;
                tt->name->module = jl_core_module;
            }
        }
    }

    // the Main module is the one which is always open, and set as the
    // current module for bare (non-module-wrapped) toplevel expressions.
    // it does "using Base" if Base is available.
    if (jl_base_module != NULL) {
        jl_add_standard_imports(jl_main_module);
    }
    // eval() uses Main by default, so Main.eval === Core.eval
    jl_module_import(jl_main_module, jl_core_module, jl_symbol("eval"));
    jl_current_module = jl_main_module;
//.........这里部分代码省略.........
开发者ID:aviks,项目名称:julia,代码行数:101,代码来源:init.c

示例12: exceptionHandler

int exceptionHandler(unsigned int code, struct _EXCEPTION_POINTERS *e)
{
    char strCode[128];
    bool canContinue;
    int numException = 0;
    char szTemp[1024];
    PEXCEPTION_POINTERS eNext = e;
    PEXCEPTION_RECORD excRec;
    static DWORD numCall = 0;

    if (numCall++ >= 4)
        ExitProcess(0);

    _snprintf(szTemp, sizeof(szTemp), "!!! exceptionHandler(0x%08p)->0x%08p  [ %03d ] *************************** !!!",
        e, e->ExceptionRecord, numCall);
    // OutputDebugString(szTemp);
    deb(szTemp);

    _snprintf(szTemp, sizeof(szTemp),
        "eax=0x%08X ebx=0x%08X ecx=0x%08X edx=0x%08X\r\nesi=0x%08X edi=0x%08X esp=0x%08X ebp=0x%08X",
        eNext->ContextRecord->Eax, eNext->ContextRecord->Ebx, eNext->ContextRecord->Ecx, eNext->ContextRecord->Edx,
        eNext->ContextRecord->Esi, eNext->ContextRecord->Edi, eNext->ContextRecord->Esp, eNext->ContextRecord->Ebp);
    // OutputDebugString(szTemp);
    deb(szTemp);

    do
    {
        excRec = eNext->ExceptionRecord;

        numException++;

        // deb(" -> # %-4d 0x%08p", numException, excRec);
        // deb("code: %x", excRec->ExceptionCode);

        canContinue = excRec->ExceptionFlags == EXCEPTION_NONCONTINUABLE ? true:false;
        // deb("canContinue: %d", canContinue);

        if (excRec->ExceptionCode == EXCEPTION_ACCESS_VIOLATION)
        {
            _snprintf(strCode, sizeof(strCode), "Access violation (%s @ 0x%08p)",
                excRec->ExceptionInformation[0] ? "WRITE":"READ", excRec->ExceptionInformation[1]);
        }
        else
            if (excRec->ExceptionCode == EXCEPTION_IN_PAGE_ERROR)
            {
                _snprintf(strCode, sizeof(strCode), "Access in-page violation (%s @ 0x%08p) ntcode: %d",
                    excRec->ExceptionInformation[0] ? "READ":"WRITE", excRec->ExceptionInformation[1],
                    excRec->ExceptionInformation[2]);
            }
            else
            {
                _snprintf(strCode, sizeof(strCode), "<unkcode=%X> d0: 0x%08x d1: 0x%08x d2: 0x%08x",
                    excRec->ExceptionCode, excRec->ExceptionInformation[0], excRec->ExceptionInformation[1],
                    excRec->ExceptionInformation[2]);
            }

        _snprintf(szTemp, sizeof(szTemp), "Exception 0x%08X %s Address=0x%08X canContinue=%s", excRec->ExceptionCode,
            strCode, excRec->ExceptionAddress, canContinue ? "yes":"no");
        deb(szTemp);

        if (!eNext->ExceptionRecord->ExceptionRecord)
            break;

        excRec = eNext->ExceptionRecord->ExceptionRecord;
        eNext->ExceptionRecord = eNext->ExceptionRecord->ExceptionRecord;

    }
    while (excRec->ExceptionRecord);

    // find symbols
    LPAPI_VERSION av = ImagehlpApiVersion();
    // deb("dbghelp.dll: %d.%d rev:%d", av->MajorVersion, av->MinorVersion, av->Revision);

    int ret = SymInitialize(GetCurrentProcess(), "c:\\symbols", TRUE);
    SymSetOptions(SYMOPT_UNDNAME | SYMOPT_ALLOW_ABSOLUTE_SYMBOLS | SYMOPT_DEFERRED_LOADS | 0x01000000 |
        SYMOPT_CASE_INSENSITIVE | SYMOPT_LOAD_ANYTHING | SYMOPT_LOAD_LINES);
    if (!ret)
        deb("syminit failed: code=%d, %s", ret, fmterr());

    PSYMBOL_INFO si;
    unsigned long stackPtr = e->ContextRecord->Esp;
    DWORD dwDisp = false;
    unsigned __int64 dwDisp64 = false;
    LPVOID addr;

    si = (PSYMBOL_INFO)malloc(4096);

    for (int i = 0;i<100;i++)
    {
        memset(si, 0, 4096);
        // si.Name = (char*) a(128);
        si->MaxNameLen = 3000;
        si->SizeOfStruct = sizeof(SYMBOL_INFO) + 3000;

        memcpy((void*) &addr, (void*)stackPtr, 4);

        char szTemp[128];

        memset(szTemp, 0, sizeof(szTemp));
        si->Address = (unsigned __int64)addr;
//.........这里部分代码省略.........
开发者ID:kilitary,项目名称:mye,代码行数:101,代码来源:mye.cpp

示例13: mProcess

DbgHelp::DbgHelp(HANDLE process)
: mProcess(process)
, mDbgHelp(0)
, mMutex()
, mSymGetModuleInfo64(0)  
, mSymLoadModule64(0)   
, mSymInitialize(0)   
, mSymUnloadModule64(0)
, mSymEnumerateModules64(0)
, mSymCleanup(0)  
, mSymFunctionTableAccess64(0)
, mSymGetModuleBase64(0)
, mSymGetSymFromAddr64(0)
, mSymSetOptions(0)     
, mSymGetOptions(0)     
, mUnDecorateSymbolName(0)  
, mSymUnDName64(0)  
, mStackWalk64(0)
, mMiniDumpWriteDump(0)
//, mSymRegisterCallback64(0)
// currently not used:
//, mSymEnumSymbols(0)
//, mSymEnumTypes(0)
//, mSymSetContext(0)
//, mSymGetTypeInfo(0)
//, mImagehlpApiVersion(0)
{
  if(!mProcess)
  {
    throw StackDumpException(__FILE__, __LINE__, "DbgHelp: invalid process handle passed");
  }

  //
  // Load dbgHelp.dll and map the functions we need
  //
  if((mDbgHelp = ::LoadLibraryW(cDbgHelpDllPath)) == 0)
  {
    throw StackDumpException(__FILE__, __LINE__, "DbgHelp: Failed to load dbgHelp.dll");        
  }

  // Map function pointers
  if(0 == (mSymGetModuleInfo64    = reinterpret_cast<SymGetModuleInfo64Fnc>   (GetProcAddress(mDbgHelp, "SymGetModuleInfo64"))))      throw StackDumpException(__FILE__, __LINE__, "Function not found in dbghelp.dll: SymGetModuleInfo64");
  if(0 == (mSymLoadModule64     = reinterpret_cast<SymLoadModule64Fnc>      (GetProcAddress(mDbgHelp, "SymLoadModule64"))))       throw StackDumpException(__FILE__, __LINE__, "Function not found in dbghelp.dll: SymLoadModule64");     
  if(0 == (mSymInitialize       = reinterpret_cast<SymInitializeFnc>      (GetProcAddress(mDbgHelp, "SymInitialize"))))       throw StackDumpException(__FILE__, __LINE__, "Function not found in dbghelp.dll: SymInitialize");     
  if(0 == (mSymUnloadModule64     = reinterpret_cast<SymUnloadModule64Fnc>    (GetProcAddress(mDbgHelp, "SymUnloadModule64"))))     throw StackDumpException(__FILE__, __LINE__, "Function not found in dbghelp.dll: SymUnloadModule64");   
  if(0 == (mSymEnumerateModules64   = reinterpret_cast<SymEnumerateModules64Fnc>  (GetProcAddress(mDbgHelp, "SymEnumerateModules64"))))   throw StackDumpException(__FILE__, __LINE__, "Function not found in dbghelp.dll: SymEnumerateModules64");
  if(0 == (mSymCleanup        = reinterpret_cast<SymCleanupFnc>       (GetProcAddress(mDbgHelp, "SymCleanup"))))          throw StackDumpException(__FILE__, __LINE__, "Function not found in dbghelp.dll: SymCleanup");        
  if(0 == (mSymFunctionTableAccess64  = reinterpret_cast<SymFunctionTableAccess64Fnc> (GetProcAddress(mDbgHelp, "SymFunctionTableAccess64"))))  throw StackDumpException(__FILE__, __LINE__, "Function not found in dbghelp.dll: SymFunctionTableAccess64");  
  if(0 == (mSymGetModuleBase64    = reinterpret_cast<SymGetModuleBase64Fnc>   (GetProcAddress(mDbgHelp, "SymGetModuleBase64"))))      throw StackDumpException(__FILE__, __LINE__, "Function not found in dbghelp.dll: SymGetModuleBase64");    
  if(0 == (mSymGetSymFromAddr64   = reinterpret_cast<SymGetSymFromAddr64Fnc>    (GetProcAddress(mDbgHelp, "SymGetSymFromAddr64"))))     throw StackDumpException(__FILE__, __LINE__, "Function not found in dbghelp.dll: SymGetSymFromAddr64");   
  if(0 == (mSymSetOptions       = reinterpret_cast<SymSetOptionsFnc>      (GetProcAddress(mDbgHelp, "SymSetOptions"))))       throw StackDumpException(__FILE__, __LINE__, "Function not found in dbghelp.dll: SymSetOptions");     
  if(0 == (mSymGetOptions       = reinterpret_cast<SymGetOptionsFnc>      (GetProcAddress(mDbgHelp, "SymGetOptions"))))       throw StackDumpException(__FILE__, __LINE__, "Function not found in dbghelp.dll: SymGetOptions");     
  if(0 == (mUnDecorateSymbolName    = reinterpret_cast<UnDecorateSymbolNameFnc>   (GetProcAddress(mDbgHelp, "UnDecorateSymbolName"))))    throw StackDumpException(__FILE__, __LINE__, "Function not found in dbghelp.dll: UnDecorateSymbolName");    
  if(0 == (mSymUnDName64        = reinterpret_cast<SymUnDName64Fnc>       (GetProcAddress(mDbgHelp, "SymUnDName64"))))        throw StackDumpException(__FILE__, __LINE__, "Function not found in dbghelp.dll: SymUnDName64");        
  if(0 == (mStackWalk64       = reinterpret_cast<StackWalk64Fnc>        (GetProcAddress(mDbgHelp, "StackWalk64"))))         throw StackDumpException(__FILE__, __LINE__, "Function not found in dbghelp.dll: StackWalk64");       
  if(0 == (mMiniDumpWriteDump = reinterpret_cast<MiniDumpWriteDumpFnc>  (GetProcAddress(mDbgHelp, "MiniDumpWriteDump"))))         throw StackDumpException(__FILE__, __LINE__, "Function not found in dbghelp.dll: MiniDumpWriteDump");       
  //if(0 == (mSymRegisterCallback64   = reinterpret_cast<SymRegisterCallback64Fnc>  (GetProcAddress(mDbgHelp, "SymRegisterCallback64"))))   throw StackDumpException(__FILE__, __LINE__, "Function not found in dbghelp.dll: SymRegisterCallback64"); 
// currently not used:
//  if(0 == (mSymEnumSymbols      = reinterpret_cast<SymEnumTypesFnc>       (GetProcAddress(mDbgHelp, "SymEnumSymbols"))))        throw StackDumpException(__FILE__, __LINE__, "Function not found in dbghelp.dll: SymEnumSymbols");        
//  if(0 == (mSymEnumTypes        = reinterpret_cast<SymEnumSymbolsFnc>     (GetProcAddress(mDbgHelp, "SymEnumTypes"))))        throw StackDumpException(__FILE__, __LINE__, "Function not found in dbghelp.dll: SymEnumTypes");      
//  if(0 == (mSymSetContext       = reinterpret_cast<SymSetContextFnc>      (GetProcAddress(mDbgHelp, "SymSetContext"))))       throw StackDumpException(__FILE__, __LINE__, "Function not found in dbghelp.dll: SymSetContext");
//  if(0 == (mSymGetTypeInfo      = reinterpret_cast<SymGetTypeInfoFnc>     (GetProcAddress(mDbgHelp, "SymGetTypeInfo"))))        throw StackDumpException(__FILE__, __LINE__, "Function not found in dbghelp.dll: SymGetTypeInfo");      
//  if(0 == (mImagehlpApiVersion    = reinterpret_cast<ImagehlpApiVersionFnc>   (GetProcAddress(mDbgHelp, "ImagehlpApiVersion"))))      throw StackDumpException(__FILE__, __LINE__, "Function not found in dbghelp.dll: ImagehlpApiVersion");    

  //
  // Initialize dbgHelp lib
  //
  if(!SymInitialize(0, false))            // set no user path since we're manually loading all modules
  {
    ::FreeLibrary(mDbgHelp);
    // don't use NcErrorFacade to throw, since it would try to log a callstack
    throw StackDumpException(__FILE__, __LINE__, "DbgHelp: Failed to initialize");        
  }

  // Set options
  DWORD symOptions = SymGetOptions();
  symOptions &= ~SYMOPT_UNDNAME;        // We undecorate names manually since that enable us to get more info
  symOptions |= SYMOPT_PUBLICS_ONLY;      // Needed to get types of function parameters, sacrificing access to private and local info
//  symOptions |= SYMOPT_DEBUG;
  SymSetOptions(symOptions);
//  SymRegisterCallback64(traceEvents, 0);
}
开发者ID:jonaspersson,项目名称:utilib,代码行数:82,代码来源:DbgHelp.cpp

示例14: Lock

/**
 * Initializes the symbol engine if needed.
 */ 
bool FWindowsPlatformStackWalk::InitStackWalking()
{
	// DbgHelp functions are not thread safe, but this function can potentially be called from different
	// threads in our engine, so we take a critical section
	static FCriticalSection CriticalSection;
	FScopeLock Lock( &CriticalSection );

	// Only initialize once.
	if( !GStackWalkingInitialized )
	{
		void* DllHandle = FPlatformProcess::GetDllHandle( TEXT("PSAPI.DLL") );
		if( DllHandle == NULL )
		{
			return false;
		}

		// Load dynamically linked PSAPI routines.
		FEnumProcesses			= (TFEnumProcesses)			FPlatformProcess::GetDllExport( DllHandle,TEXT("EnumProcesses"));
		FEnumProcessModules		= (TFEnumProcessModules)	FPlatformProcess::GetDllExport( DllHandle,TEXT("EnumProcessModules"));
#if WINVER > 0x502
		FGetModuleFileNameEx	= (TFGetModuleFileNameEx)	FPlatformProcess::GetDllExport( DllHandle,TEXT("GetModuleFileNameExW"));
		FGetModuleBaseName		= (TFGetModuleBaseName)		FPlatformProcess::GetDllExport( DllHandle,TEXT("GetModuleBaseNameW"));
#else
		FGetModuleFileNameEx	= (TFGetModuleFileNameEx)	FPlatformProcess::GetDllExport( DllHandle,TEXT("GetModuleFileNameExA"));
		FGetModuleBaseName		= (TFGetModuleBaseName)		FPlatformProcess::GetDllExport( DllHandle,TEXT("GetModuleBaseNameA"));
#endif
		FGetModuleInformation	= (TFGetModuleInformation)	FPlatformProcess::GetDllExport( DllHandle,TEXT("GetModuleInformation"));

		// Abort if we can't look up the functions.
		if( !FEnumProcesses || !FEnumProcessModules || !FGetModuleFileNameEx || !FGetModuleBaseName || !FGetModuleInformation )
		{
			return false;
		}

		// Set up the symbol engine.
		uint32 SymOpts = SymGetOptions();

		SymOpts |= SYMOPT_LOAD_LINES;
		SymOpts |= SYMOPT_FAIL_CRITICAL_ERRORS;
		SymOpts |= SYMOPT_DEFERRED_LOADS;
		SymOpts |= SYMOPT_EXACT_SYMBOLS;

		// This option allows for undecorated names to be handled by the symbol engine.
		SymOpts |= SYMOPT_UNDNAME;

		// Disable by default as it can be very spammy/slow.  Turn it on if you are debugging symbol look-up!
		//		SymOpts |= SYMOPT_DEBUG;

		// Not sure these are important or desirable
		//		SymOpts |= SYMOPT_ALLOW_ABSOLUTE_SYMBOLS;
		//		SymOpts |= SYMOPT_CASE_INSENSITIVE;

		SymSetOptions( SymOpts );
	
		// Initialize the symbol engine.		
		const FString RemoteStorage = GetRemoteStorage(GetDownstreamStorage());
#if WINVER > 0x502
		SymInitializeW( GetCurrentProcess(), RemoteStorage.IsEmpty() ? nullptr : *RemoteStorage, true );
#else
		SymInitialize( GetCurrentProcess(), nullptr, true );
#endif
	
		GNeedToRefreshSymbols = false;
		GStackWalkingInitialized = true;

		if (!FPlatformProperties::IsMonolithicBuild() && FPlatformStackWalk::WantsDetailedCallstacksInNonMonolithicBuilds())
		{
			LoadProcessModules( RemoteStorage );
		}			
	}
#if WINVER > 0x502
	else if (GNeedToRefreshSymbols)
	{
		// Refresh and reload symbols
		SymRefreshModuleList( GetCurrentProcess() );
		if (!FPlatformProperties::IsMonolithicBuild() && FPlatformStackWalk::WantsDetailedCallstacksInNonMonolithicBuilds())
		{
			const FString RemoteStorage = GetRemoteStorage( GetDownstreamStorage() );
			LoadProcessModules( RemoteStorage );
		}
		GNeedToRefreshSymbols = false;
	}
#endif

	return GStackWalkingInitialized;
}
开发者ID:zhaoyizheng0930,项目名称:UnrealEngine,代码行数:89,代码来源:WindowsPlatformStackWalk.cpp

示例15: printCallStack

	void printCallStack()
	{
		SymInitialize(GetCurrentProcess(), NULL, TRUE);
		SymSetOptions(SYMOPT_LOAD_LINES | SYMOPT_UNDNAME);
		DWORD mtype;
		CONTEXT ctx;
		ZeroMemory(&ctx, sizeof(CONTEXT));
		ctx.ContextFlags = CONTEXT_CONTROL;
		RtlCaptureContext(&ctx);

		STACKFRAME64 stack;
		ZeroMemory(&stack, sizeof(STACKFRAME64));
#ifdef _M_IX86
		mtype = IMAGE_FILE_MACHINE_I386;
		stack.AddrPC.Offset = ctx.Eip;
		stack.AddrPC.Mode = AddrModeFlat;
		stack.AddrFrame.Offset = ctx.Ebp;
		stack.AddrFrame.Mode = AddrModeFlat;
		stack.AddrStack.Offset = ctx.Esp;
		stack.AddrStack.Mode = AddrModeFlat;
#elif _M_X64
		mtype = IMAGE_FILE_MACHINE_AMD64;
		stack.AddrPC.Offset = ctx.Rip;
		stack.AddrPC.Mode = AddrModeFlat;
		stack.AddrFrame.Offset = ctx.Rsp;
		stack.AddrFrame.Mode = AddrModeFlat;
		stack.AddrStack.Offset = ctx.Rsp;
		stack.AddrStack.Mode = AddrModeFlat;
#endif

		DWORD ldsp = 0;
		IMAGEHLP_LINE64 line;
		ZeroMemory(&line, sizeof(IMAGEHLP_LINE64));
		line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);

		char buf[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)];
		PSYMBOL_INFO sym = (PSYMBOL_INFO)buf;
		sym->SizeOfStruct = sizeof(SYMBOL_INFO);
		sym->MaxNameLen = MAX_SYM_NAME;

		UINT num = 0;
		while (StackWalk64(mtype,
			GetCurrentProcess(),
			GetCurrentThread(),
			&stack,
			&ctx,
			NULL,
			SymFunctionTableAccess64,
			SymGetModuleBase64,
			NULL))
		{

			if (stack.AddrPC.Offset == 0)
			{
				break;
			}

			++num;
			BOOL res = SymGetLineFromAddr64(GetCurrentProcess(), stack.AddrPC.Offset, &ldsp, &line);
			res = res && SymFromAddr(GetCurrentProcess(), stack.AddrPC.Offset, 0, sym);

			if (res == TRUE)
			{
				// TODO replace with inner
				printf("\t[%i] %s (%s:%d)\n", num, sym->Name, line.FileName, line.LineNumber);
			}
			else
			{
				// TODO replace with inner
				printf("\t[%i] 0x%p\n", num, stack.AddrPC.Offset);
			}
		}

		SymCleanup(GetCurrentProcess());
	}
开发者ID:XoDeR,项目名称:RE,代码行数:75,代码来源:StackTrace_Windows.cpp


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