The Battle for Wesnoth  1.19.0-dev
debugger.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2024
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 
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 
122 
123 
125 
126 
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
std::string name_
Definition: debugger.hpp:68
formula_debugger & fdb_
Definition: debugger.hpp:67
virtual ~base_breakpoint()
Definition: debugger.cpp:244
const std::string & name() const
Definition: debugger.cpp:255
base_breakpoint(formula_debugger &fdb, const std::string &name, bool one_time_only)
Definition: debugger.cpp:237
virtual bool is_break_now() const =0
bool is_one_time_only() const
Definition: debugger.cpp:249
variant value_
Definition: debugger.hpp:54
bool evaluated() const
Definition: debugger.cpp:78
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:38
const variant & value() const
Definition: debugger.cpp:66
virtual ~debug_info()
Definition: debugger.cpp:44
const std::string & value_str() const
std::string name_
Definition: debugger.hpp:52
int level() const
Definition: debugger.cpp:49
void set_evaluated(bool evaluated)
Definition: debugger.cpp:84
const std::string & name() const
Definition: debugger.cpp:54
std::string str_
Definition: debugger.hpp:53
const std::string & str() const
Definition: debugger.cpp:90
void set_value(const variant &value)
Definition: debugger.cpp:72
int counter() const
Definition: debugger.cpp:60
const std::list< debug_info > & get_execution_trace() const
Definition: debugger.cpp:133
void add_debug_info(int arg_number, const std::string &f_name)
Definition: debugger.cpp:115
std::list< debug_info > call_stack_
Definition: debugger.hpp:145
std::string f_name_extra_debug_info
Definition: debugger.hpp:151
void add_breakpoint_step_into()
Definition: debugger.cpp:367
virtual ~formula_debugger()
Definition: debugger.cpp:104
breakpoint_ptr current_breakpoint_
Definition: debugger.hpp:147
std::list< debug_info > execution_trace_
Definition: debugger.hpp:149
void call_stack_push(const std::string &str)
Definition: debugger.cpp:166
variant evaluate_formula_callback(const formula &f, const formula_callable &variables)
Definition: debugger.cpp:207
void add_breakpoint_continue_to_end()
Definition: debugger.cpp:360
variant evaluate_arg_callback(const formula_expression &expression, const formula_callable &variables)
Definition: debugger.cpp:192
void call_stack_set_value(const variant &v)
Definition: debugger.cpp:187
void add_breakpoint_step_out()
Definition: debugger.cpp:374
const std::list< debug_info > & get_call_stack() const
Definition: debugger.cpp:122
static formula_debugger * add_debug_info(formula_debugger *fdb, int arg_number, const std::string &f_name)
Definition: debugger.hpp:135
void call_stack_set_evaluated(bool evaluated)
Definition: debugger.cpp:182
std::list< breakpoint_ptr > breakpoints_
Definition: debugger.hpp:148
const breakpoint_ptr get_current_breakpoint() const
Definition: debugger.cpp:128
Formula AI debugger, forward.
Definition: contexts.hpp:43
std::shared_ptr< base_breakpoint > breakpoint_ptr
#define f