Debugger: Further work on memory leak hunting.
[haiku.git] / src / kits / debugger / debug_info / FunctionInstance.cpp
blob1ecbd3af71b28322cca0d7be0ac7160e2eb35425
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 SetSourceCode(NULL, FUNCTION_SOURCE_NOT_LOADED);
36 fFunctionDebugInfo->ReleaseReference();
40 FunctionID*
41 FunctionInstance::GetFunctionID() const
43 if (LocatableFile* file = SourceFile()) {
44 BString path;
45 file->GetPath(path);
46 return new(std::nothrow) SourceFunctionID(path, Name());
49 return new(std::nothrow) ImageFunctionID(
50 GetImageDebugInfo()->GetImageInfo().Name(), Name());
54 void
55 FunctionInstance::SetFunction(Function* function)
57 if (fFunction != NULL)
58 fFunction->ReleaseReference();
60 fFunction = function;
62 if (fFunction != NULL)
63 fFunction->AcquireReference();
67 void
68 FunctionInstance::SetSourceCode(DisassembledCode* source,
69 function_source_state state)
71 if (source == fSourceCode && state == fSourceCodeState)
72 return;
74 if (fSourceCode != NULL)
75 fSourceCode->ReleaseReference();
77 fSourceCode = source;
78 fSourceCodeState = state;
80 if (fSourceCode != NULL)
81 fSourceCode->AcquireReference();
83 if (fFunction != NULL)
84 fFunction->NotifySourceCodeChanged();