HRESULT open( const char *input_file, const char *user_spath = NULL, ea_t load_address = BADADDR, input_exe_reader_t exe_reader = NULL, input_mem_reader_t mem_reader = NULL) { // Already open? if ( pSession != NULL ) return S_OK; // When the debugger is active, first try to load debug directory from the memory ea_t load_address_order[2]; // when remote debugging, don't use files on disk bool remote_debug = false; #ifndef BUILDING_EFD #ifndef PDBTOTIL if ( get_process_state() != DSTATE_NOTASK ) { load_address_order[0] = load_address; load_address_order[1] = BADADDR; remote_debug = dbg->is_remote(); } else #endif #endif { load_address_order[0] = BADADDR; load_address_order[1] = load_address; } HRESULT hr; do { // No interface was created? hr = create_dia_source(); if ( FAILED(hr) ) break; qwstring wpath, winput; get_input_and_sym_path(input_file, user_spath, winput, wpath); if ( exe_reader == NULL && mem_reader == NULL && !remote_debug ) // Try to load input file as PDB hr = pSource->loadDataFromPdb(winput.c_str()); else hr = E_FAIL; // Failed? Try to load as EXE if ( FAILED(hr) ) { CCallback callback(exe_reader, mem_reader); callback.AddRef(); if ( !remote_debug ) { // Open the executable callback.OpenExe(winput.c_str()); } for ( int i=0; i < qnumber(load_address_order); i++ ) { callback.SetLoadAddress(load_address_order[i]); hr = pSource->loadDataForExe(winput.c_str(), wpath.c_str(), (IDiaLoadCallback *)&callback); if ( SUCCEEDED(hr) ) break; } } // Failed? Then nothing else to try, quit if ( FAILED(hr) ) break; // Open a session for querying symbols hr = pSource->openSession(&pSession); if ( FAILED(hr) ) break; // Set load address if ( load_address != BADADDR ) pSession->put_loadAddress(load_address); // Retrieve a reference to the global scope hr = pSession->get_globalScope(&pGlobal); if ( FAILED(hr) ) break; hr = S_OK; } while ( false ); // Make sure we cleanup if ( FAILED(hr) ) close(); return hr; }
//------------------------------------------------------------------------- static bool dbg_can_query() { // Reject the request only if no debugger is set // or the debugger cannot be queried while not in suspended state return dbg != NULL && (dbg->may_disturb() || get_process_state() < DSTATE_NOTASK); }