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