The Battle for Wesnoth  1.17.10+dev
debugger.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2022
3  by Yurii Chernyi <terraninfo@terraninfo.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /**
17  * @file
18  * Formula AI debugger
19  *
20  */
21 
22 #pragma once
23 
24 #include "formula/variant.hpp"
25 #include "formula/debugger_fwd.hpp"
26 #include <list>
27 
28 namespace wfl {
29 
30 class formula_expression;
31 class formula_callable;
32 class formula;
33 class formula_debugger;
34 
35 class debug_info {
36 public:
37  debug_info(int arg_number, int counter, int level, const std::string &name, const std::string &str, const variant &value, bool evaluated);
38  virtual ~debug_info();
39  int counter() const;
40  int level() const;
41  const std::string& name() const;
42  const std::string& str() const;
43  const variant& value() const;
44  const std::string& value_str() const;
45  bool evaluated() const;
46  void set_evaluated(bool evaluated);
47  void set_value(const variant &value);
48 private:
50  int counter_;
51  int level_;
52  std::string name_;
53  std::string str_;
55  bool evaluated_;
56 
57 };
58 
60 public:
61  base_breakpoint(formula_debugger &fdb, const std::string &name, bool one_time_only);
62  virtual ~base_breakpoint();
63  virtual bool is_break_now() const = 0;
64  bool is_one_time_only() const;
65  const std::string &name() const;
66 protected:
68  std::string name_;
70 
71 };
72 
73 
75 public:
77 
78 
79  virtual ~formula_debugger();
80 
81 
82  void add_debug_info(int arg_number, const std::string& f_name);
83 
84 
85  void call_stack_push(const std::string &str);
86 
87 
88  void call_stack_pop();
89 
90 
91  void call_stack_set_evaluated(bool evaluated);
92 
93 
94  void call_stack_set_value(const variant &v);
95 
96 
97  void check_breakpoints();
98 
99 
100  const std::list<debug_info>& get_call_stack() const;
101 
102 
103  const breakpoint_ptr get_current_breakpoint() const;
104 
105 
106  const std::list<debug_info>& get_execution_trace() const;
107 
108 
109  variant evaluate_arg_callback(const formula_expression &expression, const formula_callable &variables);
110 
111 
112  variant evaluate_formula_callback(const formula &f, const formula_callable &variables);
113 
114 
116 
117 
118  void show_gui();
119 
120 
121  void add_breakpoint_continue_to_end();
122 
123 
124  void add_breakpoint_step_into();
125 
126 
127  void add_breakpoint_step_out();
128 
129 
130  void add_breakpoint_next();
131 
132 
133  //static functions
134 
135  static formula_debugger* add_debug_info(formula_debugger *fdb, int arg_number, const std::string& f_name)
136  {
137  if (fdb==nullptr) {
138  return nullptr;
139  }
140  fdb->add_debug_info(arg_number,f_name);
141  return fdb;
142  }
143 
144 private:
145  std::list<debug_info> call_stack_;
146  int counter_;
148  std::list< breakpoint_ptr > breakpoints_;
149  std::list<debug_info> execution_trace_;
152 
153 
154 };
155 
156 
157 
158 } // end of namespace wfl
int level() const
Definition: debugger.cpp:50
void add_debug_info(int arg_number, const std::string &f_name)
Definition: debugger.cpp:116
static formula_debugger * add_debug_info(formula_debugger *fdb, int arg_number, const std::string &f_name)
Definition: debugger.hpp:135
formula_debugger * add_debug_info(formula_debugger *fdb, int arg_number, const std::string &f_name)
std::list< debug_info > call_stack_
Definition: debugger.hpp:145
debug_info(int arg_number, int counter, int level, const std::string &name, const std::string &str, const variant &value, bool evaluated)
Definition: debugger.cpp:39
variant value_
Definition: debugger.hpp:54
Formula AI debugger, forward.
std::list< breakpoint_ptr > breakpoints_
Definition: debugger.hpp:148
void set_evaluated(bool evaluated)
Definition: debugger.cpp:85
formula_debugger & fdb_
Definition: debugger.hpp:67
std::shared_ptr< base_breakpoint > breakpoint_ptr
breakpoint_ptr current_breakpoint_
Definition: debugger.hpp:147
std::string f_name_extra_debug_info
Definition: debugger.hpp:151
void set_value(const variant &value)
Definition: debugger.cpp:73
variant evaluate_arg_callback(formula_debugger &fdb, const formula_expression &expression, const formula_callable &variables)
virtual ~debug_info()
Definition: debugger.cpp:45
const variant & value() const
Definition: debugger.cpp:67
int counter() const
Definition: debugger.cpp:61
variant evaluate_formula_callback(formula_debugger &fdb, const formula &f, const formula_callable &variables)
std::list< debug_info > execution_trace_
Definition: debugger.hpp:149
std::string str_
Definition: debugger.hpp:53
std::string name_
Definition: debugger.hpp:52
std::string name_
Definition: debugger.hpp:68
bool evaluated() const
Definition: debugger.cpp:79
#define f
Definition: contexts.hpp:44
const std::string & str() const
Definition: debugger.cpp:91
const std::string & value_str() const
const std::string & name() const
Definition: debugger.cpp:55