ScummVM API documentation
debug.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef MTROPOLIS_DEBUG_H
23 #define MTROPOLIS_DEBUG_H
24 
25 #include "common/str.h"
26 #include "common/ptr.h"
27 #include "common/hashmap.h"
28 
29 #include "mtropolis/core.h"
30 
31 #define MTROPOLIS_DEBUG_VTHREAD_STACKS
32 
33 #define MTROPOLIS_DEBUG_ENABLE
34 #if defined(MTROPOLIS_DEBUG_ENABLE) && !defined(MTROPOLIS_DEBUG_VTHREAD_STACKS)
35 // VThread stack debugging is mandatory when debugging
36 #define MTROPOLIS_DEBUG_VTHREAD_STACKS
37 #endif
38 
39 namespace MTropolis {
40 
41 #ifdef MTROPOLIS_DEBUG_ENABLE
42 
43 class Runtime;
44 class Window;
45 class Structural;
46 class Modifier;
47 class DebugInspector;
48 class DebugToolWindowBase;
49 class RuntimeObject;
50 
51 struct IDebuggable;
52 
53 enum SupportStatus {
54  kSupportStatusNone, // Only loads, not functional
55  kSupportStatusPartial, // Partially-implemented, some use cases may silently fail
56  kSupportStatusDone, // Not necessarily "done" but "done" enough that unsupported cases will trigger errors
57 };
58 
60  // Attempts to declare a row with static contents. If this returns true, then declareStaticContents must be called.
61  virtual bool declareStatic(const char *name) = 0;
62 
63  // Declares the contents of a static row
64  virtual void declareStaticContents(const Common::String &data) = 0;
65 
66  // Declares the contents of a dynamic row
67  virtual void declareDynamic(const char *name, const Common::String &data) = 0;
68 
69  // Declares the contents of a loose row
70  virtual void declareLoose(const Common::String &data) = 0;
71 };
72 
73 struct IDebuggable : public IInterfaceBase {
74  virtual SupportStatus debugGetSupportStatus() const = 0;
75  virtual const char *debugGetTypeName() const = 0;
76  virtual const Common::String &debugGetName() const = 0;
77  virtual const Common::SharedPtr<DebugInspector> &debugGetInspector() = 0;
78  virtual void debugInspect(IDebugInspectionReport *report) const = 0;
79 };
80 
81 // The debug inspector link goes inside of a debuggable, it contains an inspector and
82 // will notify the inspector of the object's destruction
83 class Debuggable : public IDebuggable {
84 public:
85  Debuggable();
86  Debuggable(const Debuggable &other);
87  Debuggable(Debuggable &&other);
88  ~Debuggable();
89 
90 private:
91  const Common::SharedPtr<DebugInspector> &debugGetInspector() override;
92 
94 };
95 
97 public:
98  explicit DebugInspector(IDebuggable *debuggable);
99  virtual ~DebugInspector();
100 
101  void onDestroyed(IDebuggable *instance);
102  void changePrimaryInstance(IDebuggable *instance);
103 
104  IDebuggable *getDebuggable() const;
105 
106 private:
107  IDebuggable *_instance;
108 };
109 
111 public:
112  explicit DebugPrimaryTaskList(const Common::String &name);
113 
114  void addItem(IDebuggable *debuggable);
115  const Common::Array<IDebuggable *> &getItems() const;
116 
117  const Common::String &getName() const;
118 
119 private:
120  Common::String _name;
121  Common::Array<IDebuggable *> _primaryTasks;
122 };
123 
124 enum DebugSeverity {
125  kDebugSeverityInfo,
126  kDebugSeverityWarning,
127  kDebugSeverityError,
128 };
129 
131 public:
132 
133 private:
134  //Runtime *_runtime;
135 };
136 
137 enum DebuggerTool {
138  kDebuggerToolSceneTree,
139  kDebuggerToolInspector,
140  kDebuggerToolStepThrough,
141 
142  kDebuggerToolCount,
143 };
144 
145 class Debugger {
146 public:
147  explicit Debugger(Runtime *runtime);
148  ~Debugger();
149 
150  // runFrame runs after the frame, before rendering, and before event processing for the following frame
151  void runFrame(uint32 msec);
152 
153  void setPaused(bool paused);
154  bool isPaused() const;
155 
156  Runtime *getRuntime() const;
157 
158  void notify(DebugSeverity severity, const Common::String &str);
159  void notifyFmt(DebugSeverity severity, const char *fmt, ...);
160  void vnotifyFmt(DebugSeverity severity, const char *fmt, va_list args);
161 
162  void refreshSceneStatus();
163  void complainAboutUnfinished(Structural *structural);
164 
165  void openToolWindow(DebuggerTool tool);
166  void closeToolWindow(DebuggerTool tool);
167 
168  void inspectObject(IDebuggable *debuggable);
169  void tryInspectObject(RuntimeObject *object);
170 
171  const Common::SharedPtr<DebugInspector> &getInspector() const;
172 
173 private:
174  Debugger();
175 
176  static void scanStructuralStatus(Structural *structural, Common::HashMap<Common::String, SupportStatus> &unfinishedModifiers, Common::HashMap<Common::String, SupportStatus> &unfinishedElements);
177  static void scanModifierStatus(Modifier *modifier, Common::HashMap<Common::String, SupportStatus> &unfinishedModifiers, Common::HashMap<Common::String, SupportStatus> &unfinishedElements);
178  static void scanDebuggableStatus(IDebuggable *debuggable, Common::HashMap<Common::String, SupportStatus> &unfinished);
179 
180  struct ToastNotification {
181  ToastNotification();
182 
184  uint64 dismissTime;
185  };
186 
187  bool _paused;
188  Runtime *_runtime;
189  Common::SharedPtr<Window> _sceneStatusWindow;
190  Common::SharedPtr<Window> _toolsWindow;
191  Common::SharedPtr<DebugToolWindowBase> _toolWindows[kDebuggerToolCount];
192  Common::Array<ToastNotification> _toastNotifications;
194 };
195 
196 #else
197 
198 struct IDebuggable {
199 };
200 
201 struct Debuggable : public IDebuggable {
202 };
203 
204 #endif /* !MTROPOLIS_DEBUG_ENABLE */
205 
206 } // End of namespace MTropolis
207 
208 #endif /* MTROPOLIS_DEBUG_H */
Definition: debug.h:130
Definition: debug.h:73
Definition: str.h:59
Definition: array.h:52
Definition: debug.h:145
Definition: runtime.h:2195
Definition: runtime.h:1575
Definition: runtime.h:2052
Definition: runtime.h:3035
Definition: debug.h:83
Definition: hashmap.h:85
Definition: debug.h:96
Definition: debug.h:59
Definition: debug.h:110
Definition: actions.h:25
Definition: ptr.h:159
Definition: core.h:33