src/processor/bugsnag_stackwalk_wrapper.cc
// Get the details of the modules in a minidump
Get the details of the modules in a minidump
Get the details of the modules in a minidump
WrappedModuleDetails GetModuleDetails(const char* minidump_filename) {
  WrappedModuleDetails result = {{0}};
  try {
    Minidump dump(minidump_filename);
    if (!dump.Read()) {
      result.pstrErr = duplicate("failed to read minidump");
      return result;
    }
    MinidumpModuleList* module_list = dump.GetModuleList();
    if (!module_list) {
      result.pstrErr = duplicate("failed to get module list");
      return result;
    }
    result.moduleDetails.moduleCount = module_list->module_count();
    const MinidumpModule* mainModule = module_list->GetMainModule();
    if (!mainModule) {
      throw std::runtime_error("failed to get main module");
    }
    string mainModuleId = mainModule->debug_identifier();
    result.moduleDetails.mainModuleId = duplicate(mainModuleId);
    char** module_ids =
        (char**)malloc(sizeof(char*) * module_list->module_count());
    if (!module_ids) {
      throw std::bad_alloc();
    }
    char** module_names =
        (char**)malloc(sizeof(char*) * module_list->module_count());
    if (!module_names) {
      throw std::bad_alloc();
    }
    char** module_code_files =
        (char**)malloc(sizeof(char*) * module_list->module_count());
    if (!module_code_files) {
      throw std::bad_alloc();
    }
    for (unsigned int i = 0; i < module_list->module_count(); i++) {
      const MinidumpModule* module = module_list->GetModuleAtIndex(i);
      if (!module) {
        throw std::runtime_error("Bad module index");
      }
      string debug_identifier = module->debug_identifier();
      module_ids[i] = duplicate(debug_identifier);
      string debug_file = PathnameStripper::File(module->debug_file());
      module_names[i] = duplicate(debug_file);
      string code_file = module->code_file();
      module_code_files[i] = duplicate(code_file);
    };
    result.moduleDetails.moduleIds = module_ids;
    result.moduleDetails.moduleNames = module_names;
    result.moduleDetails.moduleCodeFiles = module_code_files;
  } catch (const std::exception& ex) {
    string errMsg = "encountered exception: " + string(ex.what());
    result.pstrErr = duplicate(errMsg);
  } catch (...) {
    result.pstrErr = duplicate("encountered unknown exception");
  }
  return result;
}
WrappedModuleDetails GetModuleDetails ( const char * minidump_filename ) { WrappedModuleDetails result = { { 0 } } ; try { Minidump dump ( minidump_filename ) ; if ( ! dump . Read ( ) ) { result . pstrErr = duplicate ( " " ) ; return result ; } MinidumpModuleList * module_list = dump . GetModuleList ( ) ; if ( ! module_list ) { result . pstrErr = duplicate ( " " ) ; return result ; } result . moduleDetails . moduleCount = module_list -> module_count ( ) ; const MinidumpModule * mainModule = module_list -> GetMainModule ( ) ; if ( ! mainModule ) { throw std :: runtime_error ( " " ) ; } string mainModuleId = mainModule -> debug_identifier ( ) ; result . moduleDetails . mainModuleId = duplicate ( mainModuleId ) ; char * * module_ids = ( char * * ) malloc ( sizeof ( char * ) * module_list -> module_count ( ) ) ; if ( ! module_ids ) { throw std :: bad_alloc ( ) ; } char * * module_names = ( char * * ) malloc ( sizeof ( char * ) * module_list -> module_count ( ) ) ; if ( ! module_names ) { throw std :: bad_alloc ( ) ; } char * * module_code_files = ( char * * ) malloc ( sizeof ( char * ) * module_list -> module_count ( ) ) ; if ( ! module_code_files ) { throw std :: bad_alloc ( ) ; } for ( unsigned int i = 0 ; i < module_list -> module_count ( ) ; i ++ ) { const MinidumpModule * module = module_list -> GetModuleAtIndex ( i ) ; if ( ! module ) { throw std :: runtime_error ( " " ) ; } string debug_identifier = module -> debug_identifier ( ) ; module_ids [ i ] = duplicate ( debug_identifier ) ; string debug_file = PathnameStripper :: File ( module -> debug_file ( ) ) ; module_names [ i ] = duplicate ( debug_file ) ; string code_file = module -> code_file ( ) ; module_code_files [ i ] = duplicate ( code_file ) ; } ; result . moduleDetails . moduleIds = module_ids ; result . moduleDetails . moduleNames = module_names ; result . moduleDetails . moduleCodeFiles = module_code_files ; } catch ( const std :: exception & ex ) { string errMsg = " " + string ( ex . what ( ) ) ; result . pstrErr = duplicate ( errMsg ) ; } catch ( ... ) { result . pstrErr = duplicate ( " " ) ; } return result ; }
Get the details of the modules in a minidump
Get the details of the modules in a minidump