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"
13 #include "DebuggerInterface.h"
14 #include "ImageDebugInfo.h"
15 #include "StackTrace.h"
20 GetStackTraceJob::GetStackTraceJob(DebuggerInterface
* debuggerInterface
,
21 JobListener
* listener
, Architecture
* architecture
, ::Thread
* thread
)
23 fKey(thread
, JOB_TYPE_GET_STACK_TRACE
),
24 fDebuggerInterface(debuggerInterface
),
25 fJobListener(listener
),
26 fArchitecture(architecture
),
29 fThread
->AcquireReference();
31 fCpuState
= fThread
->GetCpuState();
32 if (fCpuState
!= NULL
)
33 fCpuState
->AcquireReference();
36 SetDescription("Retrieving stack trace for thread %" B_PRId32
, fThread
->ID());
40 GetStackTraceJob::~GetStackTraceJob()
42 if (fCpuState
!= NULL
)
43 fCpuState
->ReleaseReference();
45 fThread
->ReleaseReference();
50 GetStackTraceJob::Key() const
57 GetStackTraceJob::Do()
59 if (fCpuState
== NULL
)
62 // get the stack trace
63 StackTrace
* stackTrace
;
64 status_t error
= fArchitecture
->CreateStackTrace(fThread
->GetTeam(), this,
65 fCpuState
, stackTrace
, fThread
->ReturnValueInfos());
68 BReference
<StackTrace
> stackTraceReference(stackTrace
, true);
70 // set the stack trace, unless something has changed
71 AutoLocker
<Team
> locker(fThread
->GetTeam());
73 if (fThread
->GetCpuState() == fCpuState
)
74 fThread
->SetStackTrace(stackTrace
);
81 GetStackTraceJob::GetImageDebugInfo(Image
* image
, ImageDebugInfo
*& _info
)
83 AutoLocker
<Team
> teamLocker(fThread
->GetTeam());
85 while (image
->GetImageDebugInfo() == NULL
) {
86 // schedule a job, if not loaded
88 status_t error
= LoadImageDebugInfoJob::ScheduleIfNecessary(GetWorker(),
89 image
, fJobListener
, &info
);
100 // wait for the job to finish
101 switch (WaitFor(SimpleJobKey(image
, JOB_TYPE_LOAD_IMAGE_DEBUG_INFO
))) {
102 case JOB_DEPENDENCY_SUCCEEDED
:
103 case JOB_DEPENDENCY_NOT_FOUND
:
104 // "Not found" can happen due to a race condition between
105 // unlocking the worker and starting to wait.
107 case JOB_DEPENDENCY_FAILED
:
108 case JOB_DEPENDENCY_ABORTED
:
116 _info
= image
->GetImageDebugInfo();
117 _info
->AcquireReference();