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.
7 #include "DwarfManager.h"
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()
34 return fLock
.InitCheck();
39 DwarfManager::LoadFile(const char* fileName
, DwarfFileLoadingState
& _state
)
41 AutoLocker
<DwarfManager
> locker(this);
43 DwarfFile
* file
= _state
.dwarfFile
;
44 BReference
<DwarfFile
> fileReference
;
46 file
= new(std::nothrow
) DwarfFile
;
49 fileReference
.SetTo(file
, true);
50 _state
.dwarfFile
= file
;
52 fileReference
.SetTo(file
);
55 if (_state
.externalInfoFileName
.IsEmpty()) {
56 error
= file
->StartLoading(fileName
, _state
.externalInfoFileName
);
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
;
69 error
= file
->Load(fAddressSize
, _state
.locatedExternalInfoPath
);
71 _state
.state
= DWARF_FILE_LOADING_STATE_FAILED
;
77 fileReference
.Detach();
78 // keep a reference for ourselves in the list.
80 _state
.state
= DWARF_FILE_LOADING_STATE_SUCCEEDED
;
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();