Debugger: Split into core library and application.
[haiku.git] / src / kits / debugger / debug_info / FunctionInstance.cpp
blobb7398f78878257a567a48ece932d0f87598398e2
1 /*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
6 #include "FunctionInstance.h"
8 #include <new>
10 #include "DisassembledCode.h"
11 #include "Function.h"
12 #include "FunctionID.h"
13 #include "ImageDebugInfo.h"
14 #include "LocatableFile.h"
17 FunctionInstance::FunctionInstance(ImageDebugInfo* imageDebugInfo,
18 FunctionDebugInfo* functionDebugInfo)
20 fImageDebugInfo(imageDebugInfo),
21 fFunction(NULL),
22 fFunctionDebugInfo(functionDebugInfo),
23 fSourceCode(NULL),
24 fSourceCodeState(FUNCTION_SOURCE_NOT_LOADED)
26 fFunctionDebugInfo->AcquireReference();
27 // TODO: What about fImageDebugInfo? We must be careful regarding cyclic
28 // references.
32 FunctionInstance::~FunctionInstance()
34 SetFunction(NULL);
35 fFunctionDebugInfo->ReleaseReference();
39 FunctionID*
40 FunctionInstance::GetFunctionID() const
42 if (LocatableFile* file = SourceFile()) {
43 BString path;
44 file->GetPath(path);
45 return new(std::nothrow) SourceFunctionID(path, Name());
48 return new(std::nothrow) ImageFunctionID(
49 GetImageDebugInfo()->GetImageInfo().Name(), Name());
53 void
54 FunctionInstance::SetFunction(Function* function)
56 if (fFunction != NULL)
57 fFunction->ReleaseReference();
59 fFunction = function;
61 if (fFunction != NULL)
62 fFunction->AcquireReference();
66 void
67 FunctionInstance::SetSourceCode(DisassembledCode* source,
68 function_source_state state)
70 if (source == fSourceCode && state == fSourceCodeState)
71 return;
73 if (fSourceCode != NULL)
74 fSourceCode->ReleaseReference();
76 fSourceCode = source;
77 fSourceCodeState = state;
79 if (fSourceCode != NULL)
80 fSourceCode->AcquireReference();
82 if (fFunction != NULL)
83 fFunction->NotifySourceCodeChanged();