headers/bsd: Add sys/queue.h.
[haiku.git] / src / kits / debugger / dwarf / DwarfManager.cpp
blob9f36611e8c1efca91d98fb281aab9c1f65696d07
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 */
7 #include "DwarfManager.h"
9 #include <new>
11 #include <AutoDeleter.h>
12 #include <AutoLocker.h>
14 #include "DwarfFile.h"
15 #include "DwarfFileLoadingState.h"
18 DwarfManager::DwarfManager(uint8 addressSize)
20 fAddressSize(addressSize),
21 fLock("dwarf manager")
26 DwarfManager::~DwarfManager()
31 status_t
32 DwarfManager::Init()
34 return fLock.InitCheck();
38 status_t
39 DwarfManager::LoadFile(const char* fileName, DwarfFileLoadingState& _state)
41 AutoLocker<DwarfManager> locker(this);
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);
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;
65 return error;
69 error = file->Load(fAddressSize, _state.locatedExternalInfoPath);
70 if (error != B_OK) {
71 _state.state = DWARF_FILE_LOADING_STATE_FAILED;
72 return error;
75 fFiles.Add(file);
77 fileReference.Detach();
78 // keep a reference for ourselves in the list.
80 _state.state = DWARF_FILE_LOADING_STATE_SUCCEEDED;
82 return B_OK;
86 status_t
87 DwarfManager::FinishLoading()
89 AutoLocker<DwarfManager> locker(this);
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;
98 return B_OK;