Skip to content

Commit

Permalink
Fix bug in formula debugger
Browse files Browse the repository at this point in the history
The debugger used a deque, but added elements to it while iterating over it.
Since it didn't rely on the random access property, I simply replaced it with list.

Also, there was an incorrect use of erase().
  • Loading branch information
CelticMinstrel committed Apr 3, 2017
1 parent 9ec2403 commit 5767ca4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
18 changes: 9 additions & 9 deletions src/formula/debugger.cpp
Expand Up @@ -120,7 +120,7 @@ void formula_debugger::add_debug_info(int arg_number, const std::string& f_name)
}


const std::deque<debug_info>& formula_debugger::get_call_stack() const
const std::list<debug_info>& formula_debugger::get_call_stack() const
{
return call_stack_;
}
Expand All @@ -131,20 +131,20 @@ const breakpoint_ptr formula_debugger::get_current_breakpoint() const
return current_breakpoint_;
}

const std::deque<debug_info>& formula_debugger::get_execution_trace() const
const std::list<debug_info>& formula_debugger::get_execution_trace() const
{
return execution_trace_;
}

void formula_debugger::check_breakpoints()
{
for( std::deque< breakpoint_ptr >::iterator b = breakpoints_.begin(); b!= breakpoints_.end(); ++b) {
for(std::list<breakpoint_ptr>::iterator b = breakpoints_.begin(); b != breakpoints_.end(); ++b) {
if ((*b)->is_break_now()){
current_breakpoint_ = (*b);
show_gui();
current_breakpoint_ = breakpoint_ptr();
if ((*b)->is_one_time_only()) {
breakpoints_.erase(b);
b = breakpoints_.erase(b);
}
break;
}
Expand Down Expand Up @@ -272,8 +272,8 @@ class end_breakpoint : public base_breakpoint {

virtual bool is_break_now() const
{
const std::deque<debug_info> &call_stack = fdb_.get_call_stack();
if ((call_stack.size() == 1) && (call_stack[0].evaluated()) ) {
const std::list<debug_info> &call_stack = fdb_.get_call_stack();
if ((call_stack.size() == 1) && (call_stack.front().evaluated()) ) {
return true;
}
return false;
Expand All @@ -294,7 +294,7 @@ class step_in_breakpoint : public base_breakpoint {

virtual bool is_break_now() const
{
const std::deque<debug_info> &call_stack = fdb_.get_call_stack();
const std::list<debug_info> &call_stack = fdb_.get_call_stack();
if (call_stack.empty() || call_stack.back().evaluated()) {
return false;
}
Expand All @@ -317,7 +317,7 @@ class step_out_breakpoint : public base_breakpoint {

virtual bool is_break_now() const
{
const std::deque<debug_info> &call_stack = fdb_.get_call_stack();
const std::list<debug_info> &call_stack = fdb_.get_call_stack();
if (call_stack.empty() || call_stack.back().evaluated()) {
return false;
}
Expand Down Expand Up @@ -345,7 +345,7 @@ class next_breakpoint : public base_breakpoint {

virtual bool is_break_now() const
{
const std::deque<debug_info> &call_stack = fdb_.get_call_stack();
const std::list<debug_info> &call_stack = fdb_.get_call_stack();
if (call_stack.empty() || call_stack.back().evaluated()) {
return false;
}
Expand Down
12 changes: 6 additions & 6 deletions src/formula/debugger.hpp
Expand Up @@ -23,7 +23,7 @@

#include "formula/variant.hpp"
#include "formula/debugger_fwd.hpp"
#include <deque>
#include <list>

namespace game_logic {

Expand Down Expand Up @@ -97,13 +97,13 @@ class formula_debugger {
void check_breakpoints();


const std::deque<debug_info>& get_call_stack() const;
const std::list<debug_info>& get_call_stack() const;


const breakpoint_ptr get_current_breakpoint() const;


const std::deque<debug_info>& get_execution_trace() const;
const std::list<debug_info>& get_execution_trace() const;


variant evaluate_arg_callback(const formula_expression &expression, const formula_callable &variables);
Expand Down Expand Up @@ -142,11 +142,11 @@ class formula_debugger {
}

private:
std::deque<debug_info> call_stack_;
std::list<debug_info> call_stack_;
int counter_;
breakpoint_ptr current_breakpoint_;
std::deque< breakpoint_ptr > breakpoints_;
std::deque<debug_info> execution_trace_;
std::list< breakpoint_ptr > breakpoints_;
std::list<debug_info> execution_trace_;
int arg_number_extra_debug_info;
std::string f_name_extra_debug_info;

Expand Down

0 comments on commit 5767ca4

Please sign in to comment.