2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2014-2016, Rene Gollent, rene@gollent.com.
4 * Distributed under the terms of the MIT License.
6 #ifndef THREAD_HANDLER_H
7 #define THREAD_HANDLER_H
10 #include <Referenceable.h>
11 #include <util/OpenHashTable.h>
13 #include "Breakpoint.h"
14 #include "ImageDebugInfoProvider.h"
15 #include "model/Thread.h"
18 class BreakpointHitEvent
;
19 class BreakpointManager
;
21 class DebuggerCallEvent
;
22 class DebuggerInterface
;
23 class ExceptionOccurredEvent
;
24 class ExpressionResult
;
25 class ImageDebugInfoJobListener
;
27 class SignalReceivedEvent
;
28 class SingleStepEvent
;
31 class ThreadDebuggedEvent
;
32 class WatchpointHitEvent
;
36 class ThreadHandler
: public BReferenceable
, private ImageDebugInfoProvider
,
37 private BreakpointClient
{
39 ThreadHandler(::Thread
* thread
, Worker
* worker
,
40 DebuggerInterface
* debuggerInterface
,
41 JobListener
* listener
,
42 BreakpointManager
* breakpointManager
);
47 thread_id
ThreadID() const { return fThread
->ID(); }
48 ::Thread
* GetThread() const { return fThread
; }
50 status_t
SetBreakpointAndRun(target_addr_t address
);
53 // All Handle*() methods are invoked in team debugger thread,
55 bool HandleThreadDebugged(
56 ThreadDebuggedEvent
* event
,
57 const BString
& stoppedReason
= BString());
58 bool HandleDebuggerCall(
59 DebuggerCallEvent
* event
);
60 bool HandleBreakpointHit(
61 BreakpointHitEvent
* event
);
62 bool HandleWatchpointHit(
63 WatchpointHitEvent
* event
);
64 bool HandleSingleStep(
65 SingleStepEvent
* event
);
66 bool HandleExceptionOccurred(
67 ExceptionOccurredEvent
* event
);
68 bool HandleSignalReceived(
69 SignalReceivedEvent
* event
);
71 void HandleThreadAction(uint32 action
,
72 target_addr_t address
);
74 void HandleThreadStateChanged();
75 void HandleCpuStateChanged();
76 void HandleStackTraceChanged();
79 friend class ExpressionEvaluationListener
;
82 // ImageDebugInfoProvider
83 virtual status_t
GetImageDebugInfo(Image
* image
,
84 ImageDebugInfo
*& _info
);
86 bool _HandleThreadStopped(CpuState
* cpuState
,
88 const BString
& stoppedReasonInfo
91 bool _HandleSetAddress(CpuState
* cpuState
,
92 target_addr_t address
);
94 void _SetThreadState(uint32 state
,
95 CpuState
* cpuState
, uint32 stoppedReason
,
96 const BString
& stoppedReasonInfo
);
98 Statement
* _GetStatementAtInstructionPointer(
101 void _StepFallback();
102 bool _DoStepOver(CpuState
* cpuState
);
104 status_t
_InstallTemporaryBreakpoint(
105 target_addr_t address
);
106 void _UninstallTemporaryBreakpoint();
107 void _ClearContinuationState();
108 void _RunThread(target_addr_t instructionPointer
);
109 void _SingleStepThread(
110 target_addr_t instructionPointer
);
112 bool _HandleBreakpointConditionIfNeeded(
114 void _HandleBreakpointConditionEvaluated(
115 ExpressionResult
* value
);
116 bool _CheckStopCondition();
118 bool _HandleBreakpointHitStep(CpuState
* cpuState
);
119 bool _HandleSingleStepStep(CpuState
* cpuState
);
121 bool _HasExitedFrame(target_addr_t framePointer
)
127 DebuggerInterface
* fDebuggerInterface
;
128 JobListener
* fJobListener
;
129 BreakpointManager
* fBreakpointManager
;
131 Statement
* fStepStatement
;
132 target_addr_t fBreakpointAddress
;
133 target_addr_t fSteppedOverFunctionAddress
;
134 target_addr_t fPreviousInstructionPointer
;
135 target_addr_t fPreviousFrameAddress
;
136 bool fSingleStepping
;
137 sem_id fConditionWaitSem
;
138 ExpressionResult
* fConditionResult
;
141 ThreadHandler
* fNext
;
145 struct ThreadHandlerHashDefinition
{
146 typedef thread_id KeyType
;
147 typedef ThreadHandler ValueType
;
149 size_t HashKey(thread_id key
) const
154 size_t Hash(const ThreadHandler
* value
) const
156 return HashKey(value
->ThreadID());
159 bool Compare(thread_id key
, ThreadHandler
* value
) const
161 return value
->ThreadID() == key
;
164 ThreadHandler
*& GetLink(ThreadHandler
* value
) const
170 typedef BOpenHashTable
<ThreadHandlerHashDefinition
> ThreadHandlerTable
;
173 #endif // THREAD_HANDLER_H