2 * Copyright 2012-2016, Rene Gollent, rene@gollent.com.
3 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
4 * Distributed under the terms of the MIT License.
9 #include <AutoLocker.h>
11 #include "Architecture.h"
12 #include "DebuggerInterface.h"
13 #include "DisassembledCode.h"
15 #include "FunctionInstance.h"
16 #include "FileSourceCode.h"
18 #include "TeamDebugInfo.h"
21 LoadSourceCodeJob::LoadSourceCodeJob(
22 DebuggerInterface
* debuggerInterface
, Architecture
* architecture
,
23 Team
* team
, FunctionInstance
* functionInstance
, bool loadForFunction
)
25 fKey(functionInstance
, JOB_TYPE_LOAD_SOURCE_CODE
),
26 fDebuggerInterface(debuggerInterface
),
27 fArchitecture(architecture
),
29 fFunctionInstance(functionInstance
),
30 fLoadForFunction(loadForFunction
)
32 fFunctionInstance
->AcquireReference();
34 SetDescription("Loading source code for function %s",
35 fFunctionInstance
->PrettyName().String());
39 LoadSourceCodeJob::~LoadSourceCodeJob()
41 fFunctionInstance
->ReleaseReference();
46 LoadSourceCodeJob::Key() const
53 LoadSourceCodeJob::Do()
55 // if requested, try loading the source code for the function
56 Function
* function
= fFunctionInstance
->GetFunction();
57 if (fLoadForFunction
) {
58 FileSourceCode
* sourceCode
;
59 status_t error
= fTeam
->DebugInfo()->LoadSourceCode(
60 function
->SourceFile(), sourceCode
);
62 AutoLocker
<Team
> locker(fTeam
);
65 function
->SetSourceCode(sourceCode
, FUNCTION_SOURCE_LOADED
);
66 sourceCode
->ReleaseReference();
70 function
->SetSourceCode(NULL
, FUNCTION_SOURCE_UNAVAILABLE
);
73 // Only try to load the function instance code, if it's not overridden yet.
74 AutoLocker
<Team
> locker(fTeam
);
75 if (fFunctionInstance
->SourceCodeState() != FUNCTION_SOURCE_LOADING
)
79 // disassemble the function
80 DisassembledCode
* sourceCode
= NULL
;
81 status_t error
= fTeam
->DebugInfo()->DisassembleFunction(fFunctionInstance
,
87 if (fFunctionInstance
->SourceCodeState() == FUNCTION_SOURCE_LOADING
) {
88 // various parts of the debugger expect functions to have only
89 // one of source or disassembly available. As such, if the current
90 // function had source code previously active, unset it when
91 // explicitly asked for disassembly. This needs to be done first
92 // since Function will clear the disassembled code states of all
93 // its child instances.
94 function_source_state state
95 = fLoadForFunction
? FUNCTION_SOURCE_LOADED
96 : FUNCTION_SOURCE_SUPPRESSED
;
97 if (function
->SourceCodeState() == FUNCTION_SOURCE_LOADED
) {
98 FileSourceCode
* functionSourceCode
= function
->GetSourceCode();
99 function
->SetSourceCode(functionSourceCode
, state
);
102 fFunctionInstance
->SetSourceCode(sourceCode
, state
);
103 sourceCode
->ReleaseReference();
106 fFunctionInstance
->SetSourceCode(NULL
, FUNCTION_SOURCE_UNAVAILABLE
);