btrfs: [] on the end of a struct field is a variable length array.
[haiku.git] / headers / private / debugger / controllers / ThreadHandler.h
blob11c8f22a46443e630cf71d1d1d7d0429478f41c9
1 /*
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.
5 */
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;
20 class DebugEvent;
21 class DebuggerCallEvent;
22 class DebuggerInterface;
23 class ExceptionOccurredEvent;
24 class ExpressionResult;
25 class ImageDebugInfoJobListener;
26 class JobListener;
27 class SignalReceivedEvent;
28 class SingleStepEvent;
29 class StackFrame;
30 class Statement;
31 class ThreadDebuggedEvent;
32 class WatchpointHitEvent;
33 class Worker;
36 class ThreadHandler : public BReferenceable, private ImageDebugInfoProvider,
37 private BreakpointClient {
38 public:
39 ThreadHandler(::Thread* thread, Worker* worker,
40 DebuggerInterface* debuggerInterface,
41 JobListener* listener,
42 BreakpointManager* breakpointManager);
43 ~ThreadHandler();
45 void Init();
47 thread_id ThreadID() const { return fThread->ID(); }
48 ::Thread* GetThread() const { return fThread; }
50 status_t SetBreakpointAndRun(target_addr_t address);
51 // team lock held
53 // All Handle*() methods are invoked in team debugger thread,
54 // looper lock held.
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();
78 private:
79 friend class ExpressionEvaluationListener;
81 private:
82 // ImageDebugInfoProvider
83 virtual status_t GetImageDebugInfo(Image* image,
84 ImageDebugInfo*& _info);
86 bool _HandleThreadStopped(CpuState* cpuState,
87 uint32 stoppedReason,
88 const BString& stoppedReasonInfo
89 = BString());
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(
99 StackFrame* frame);
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(
113 CpuState* cpuState);
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)
122 const;
124 private:
125 ::Thread* fThread;
126 Worker* fWorker;
127 DebuggerInterface* fDebuggerInterface;
128 JobListener* fJobListener;
129 BreakpointManager* fBreakpointManager;
130 uint32 fStepMode;
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;
140 public:
141 ThreadHandler* fNext;
145 struct ThreadHandlerHashDefinition {
146 typedef thread_id KeyType;
147 typedef ThreadHandler ValueType;
149 size_t HashKey(thread_id key) const
151 return (size_t)key;
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
166 return value->fNext;
170 typedef BOpenHashTable<ThreadHandlerHashDefinition> ThreadHandlerTable;
173 #endif // THREAD_HANDLER_H