2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
6 #include "FunctionInstance.h"
10 #include "DisassembledCode.h"
12 #include "FunctionID.h"
13 #include "ImageDebugInfo.h"
14 #include "LocatableFile.h"
17 FunctionInstance::FunctionInstance(ImageDebugInfo
* imageDebugInfo
,
18 FunctionDebugInfo
* functionDebugInfo
)
20 fImageDebugInfo(imageDebugInfo
),
22 fFunctionDebugInfo(functionDebugInfo
),
24 fSourceCodeState(FUNCTION_SOURCE_NOT_LOADED
)
26 fFunctionDebugInfo
->AcquireReference();
27 // TODO: What about fImageDebugInfo? We must be careful regarding cyclic
32 FunctionInstance::~FunctionInstance()
35 SetSourceCode(NULL
, FUNCTION_SOURCE_NOT_LOADED
);
36 fFunctionDebugInfo
->ReleaseReference();
41 FunctionInstance::GetFunctionID() const
43 if (LocatableFile
* file
= SourceFile()) {
46 return new(std::nothrow
) SourceFunctionID(path
, Name());
49 return new(std::nothrow
) ImageFunctionID(
50 GetImageDebugInfo()->GetImageInfo().Name(), Name());
55 FunctionInstance::SetFunction(Function
* function
)
57 if (fFunction
!= NULL
)
58 fFunction
->ReleaseReference();
62 if (fFunction
!= NULL
)
63 fFunction
->AcquireReference();
68 FunctionInstance::SetSourceCode(DisassembledCode
* source
,
69 function_source_state state
)
71 if (source
== fSourceCode
&& state
== fSourceCodeState
)
74 if (fSourceCode
!= NULL
)
75 fSourceCode
->ReleaseReference();
78 fSourceCodeState
= state
;
80 if (fSourceCode
!= NULL
)
81 fSourceCode
->AcquireReference();
83 if (fFunction
!= NULL
)
84 fFunction
->NotifySourceCodeChanged();