1 /* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Copyright 2014, Rene Gollent, rene@gollent.com. 4 * Distributed under the terms of the MIT License. 5 */ 6 7 #include "DwarfManager.h" 8 9 #include <new> 10 11 #include <AutoDeleter.h> 12 #include <AutoLocker.h> 13 14 #include "DwarfFile.h" 15 #include "DwarfFileLoadingState.h" 16 17 18 DwarfManager::DwarfManager(uint8 addressSize) 19 : 20 fAddressSize(addressSize), 21 fLock("dwarf manager") 22 { 23 } 24 25 26 DwarfManager::~DwarfManager() 27 { 28 } 29 30 31 status_t 32 DwarfManager::Init() 33 { 34 return fLock.InitCheck(); 35 } 36 37 38 status_t 39 DwarfManager::LoadFile(const char* fileName, DwarfFileLoadingState& _state) 40 { 41 AutoLocker<DwarfManager> locker(this); 42 43 DwarfFile* file = _state.dwarfFile; 44 BReference<DwarfFile> fileReference; 45 if (file == NULL) { 46 file = new(std::nothrow) DwarfFile; 47 if (file == NULL) 48 return B_NO_MEMORY; 49 fileReference.SetTo(file, true); 50 _state.dwarfFile = file; 51 } else 52 fileReference.SetTo(file); 53 54 status_t error; 55 if (_state.externalInfoFileName.IsEmpty()) { 56 error = file->StartLoading(fileName, _state.externalInfoFileName); 57 if (error != B_OK) { 58 // only preserve state in the failure case if an external 59 // debug information reference was found, but the corresponding 60 // file could not be located on disk. 61 _state.state = _state.externalInfoFileName.IsEmpty() 62 ? DWARF_FILE_LOADING_STATE_FAILED 63 : DWARF_FILE_LOADING_STATE_USER_INPUT_NEEDED; 64 65 return error; 66 } 67 } 68 69 error = file->Load(fAddressSize, _state.locatedExternalInfoPath); 70 if (error != B_OK) { 71 _state.state = DWARF_FILE_LOADING_STATE_FAILED; 72 return error; 73 } 74 75 fFiles.Add(file); 76 77 fileReference.Detach(); 78 // keep a reference for ourselves in the list. 79 80 _state.state = DWARF_FILE_LOADING_STATE_SUCCEEDED; 81 82 return B_OK; 83 } 84 85 86 status_t 87 DwarfManager::FinishLoading() 88 { 89 AutoLocker<DwarfManager> locker(this); 90 91 for (FileList::Iterator it = fFiles.GetIterator(); 92 DwarfFile* file = it.Next();) { 93 status_t error = file->FinishLoading(); 94 if (error != B_OK) 95 return error; 96 } 97 98 return B_OK; 99 } 100