Permalink
Browse files

Wrote test code and fixed BreakpointMap.

  • Loading branch information...
dennisferron committed Sep 6, 2012
1 parent a18b2e7 commit c3e65324c751013d6f01f0ba96792874aaa9da29
@@ -10,18 +10,33 @@ namespace Iocaste { namespace Debugger {
struct GdbBreakpoint
{
int number;
+
+ bool operator ==(GdbBreakpoint const& that)
+ {
+ return this->number == that.number;
+ }
};
struct IoBreakpoint
{
int number;
std::string file_name;
int line_number;
+
+ bool operator ==(IoBreakpoint const& that)
+ {
+ return this->number == that.number;
+ }
};
struct UserBreakpoint
{
int number;
+
+ bool operator ==(UserBreakpoint const& that)
+ {
+ return this->number == that.number;
+ }
};
struct OurBreakpoint
@@ -39,7 +54,13 @@ class BreakpointMap
private:
typedef boost::variant<UserBreakpoint, OurBreakpoint> breakpoint_user;
typedef boost::variant<GdbBreakpoint, IoBreakpoint> breakpoint_provider;
- typedef std::pair<breakpoint_user, breakpoint_provider> row_t;
+
+ struct row_t
+ {
+ breakpoint_user user_bkpt;
+ breakpoint_provider prov_bkpt;
+ };
+
std::vector<row_t> tbl;
template <typename Result>
@@ -53,7 +74,7 @@ class BreakpointMap
try
{
for (row_t row : tbl)
- if (Result* m = boost::get<Result>(&row.first))
+ if (Result* m = boost::get<Result>(&row.user_bkpt))
if (m->number > max)
max = m->number;
}
@@ -74,9 +95,14 @@ class BreakpointMap
try
{
for (row_t row : tbl)
- if (Result* m = boost::get<Result>(&row.first))
- if (m->number == t.number)
- return *m;
+ {
+ Source* p = boost::get<Source>(&row.prov_bkpt);
+ Result* u = boost::get<Result>(&row.user_bkpt);
+ if (p && !u && *p == t)
+ raiseError(LogicError("Wrong provider type for this user breakpoint."));
+ else if (p && u && *p == t)
+ return *u;
+ }
}
catch (std::exception const& e)
{
@@ -96,9 +122,12 @@ class BreakpointMap
try
{
for (row_t row : tbl)
- if (Result* m = boost::get<Result>(&row.first))
- if (m->number == t.number)
- return true;
+ {
+ Source* p = boost::get<Source>(&row.prov_bkpt);
+ Result* u = boost::get<Result>(&row.user_bkpt);
+ if (p && u && *p == t)
+ return true;
+ }
}
catch (std::exception const& e)
{
@@ -115,9 +144,14 @@ class BreakpointMap
try
{
for (row_t row : tbl)
- if (Result* m = boost::get<Result>(&row.second))
- if (m->number == t.number)
- return *m;
+ {
+ Source* u = boost::get<Source>(&row.user_bkpt);
+ Result* p = boost::get<Result>(&row.prov_bkpt);
+ if (u && !p && *u == t)
+ raiseError(LogicError("Wrong provider type for this user breakpoint number."));
+ else if (u && p && *u == t)
+ return *p;
+ }
}
catch (std::exception const& e)
{
@@ -127,6 +161,9 @@ class BreakpointMap
// If we don't find a provider breakpoint, that's an error.
raiseError(LogicError("No provider breakpoint for this user breakpoint number."));
+
+ // Never get here
+ return { -1 };
}
};
@@ -3,6 +3,7 @@
#include "AbstractInput.hpp"
#include "AbstractAdapter.hpp"
#include "StringWithPrompt.hpp"
+#include "boost/optional.hpp"
#include <iostream>
@@ -18,6 +19,13 @@ class LookForPrompt :
AbstractOutput<StringWithPrompt>& output;
AbstractInput<std::string>& end_marker_queue;
+ // Due to a race condition between "set prompt" and
+ // the dialog coming from GDB, when the prompt changes we need to keep the old
+ // end marker around until we get the first string with the new marker.
+ boost::optional<
+ std::string
+ > old_end_marker;
+
public:
LookForPrompt(AbstractOutput<StringWithPrompt>& output_, AbstractInput<std::string>& end_marker_queue_);
virtual void WriteData(std::string const& data);
@@ -3,10 +3,68 @@
using namespace Iocaste::Debugger;
#include "boost/algorithm/string/predicate.hpp"
+#include "boost/lexical_cast.hpp"
+
+using namespace std;
+
+#include <stdlib.h>
BreakpointManager::BreakpointManager(MainChannels const& channels_)
- : channels(channels_), gdb_prompt("(gdb) ") {}
+ : channels(channels_), gdb_prompt("(gdb) ")
+{
+ BreakpointMap bktest;
+
+ GdbBreakpoint gb_our_1 = { 101 };
+ GdbBreakpoint gb_our_2 = { 102 };
+ GdbBreakpoint gb_our_3 = { 103 };
+ GdbBreakpoint gb_usr_1 = { 201 };
+ GdbBreakpoint gb_usr_2 = { 202 };
+
+ IoBreakpoint ib_our_1 = { 301 };
+ IoBreakpoint ib_our_2 = { 302 };
+ IoBreakpoint ib_usr_1 = { 401 };
+ IoBreakpoint ib_usr_2 = { 402 };
+
+ OurBreakpoint ob_gdb_1 = bktest.get_user_breakpoint<OurBreakpoint>(gb_our_1); // 101 -> 1
+ OurBreakpoint ob_gdb_2 = bktest.get_user_breakpoint<OurBreakpoint>(gb_our_2); // 102 -> 2
+ OurBreakpoint ob_gdb_3 = bktest.get_user_breakpoint<OurBreakpoint>(gb_our_3); // 103 -> 3
+ UserBreakpoint ub_gdb_1 = bktest.get_user_breakpoint<UserBreakpoint>(gb_usr_1); // 201 -> 1
+ UserBreakpoint ub_gdb_2 = bktest.get_user_breakpoint<UserBreakpoint>(gb_usr_2); // 202 -> 2
+
+ OurBreakpoint ob_iob_1 = bktest.get_user_breakpoint<OurBreakpoint>(ib_our_1); // 301 -> 4
+ OurBreakpoint ob_iob_2 = bktest.get_user_breakpoint<OurBreakpoint>(ib_our_2); // 302 -> 5
+ UserBreakpoint ub_iob_1 = bktest.get_user_breakpoint<UserBreakpoint>(ib_usr_1); // 401 -> 3
+ UserBreakpoint ub_iob_2 = bktest.get_user_breakpoint<UserBreakpoint>(ib_usr_2); // 402 -> 4
+
+ // Test that we get the same result
+
+ OurBreakpoint ob_gdb_1x = bktest.get_user_breakpoint<OurBreakpoint>(gb_our_1); // 101 -> 1
+ OurBreakpoint ob_gdb_2x = bktest.get_user_breakpoint<OurBreakpoint>(gb_our_2); // 102 -> 2
+ OurBreakpoint ob_gdb_3x = bktest.get_user_breakpoint<OurBreakpoint>(gb_our_3); // 103 -> 3
+ UserBreakpoint ub_gdb_1x = bktest.get_user_breakpoint<UserBreakpoint>(gb_usr_1); // 201 -> 1
+ UserBreakpoint ub_gdb_2x = bktest.get_user_breakpoint<UserBreakpoint>(gb_usr_2); // 202 -> 2
+
+ OurBreakpoint ob_iob_1x = bktest.get_user_breakpoint<OurBreakpoint>(ib_our_1); // 301 -> 4
+ OurBreakpoint ob_iob_2x = bktest.get_user_breakpoint<OurBreakpoint>(ib_our_2); // 302 -> 5
+ UserBreakpoint ub_iob_1x = bktest.get_user_breakpoint<UserBreakpoint>(ib_usr_1); // 401 -> 3
+ UserBreakpoint ub_iob_2x = bktest.get_user_breakpoint<UserBreakpoint>(ib_usr_2); // 402 -> 4
+
+ // Test that we can get the provider breakpoints too
+
+ GdbBreakpoint gb_our_1x = bktest.get_provider_breakpoint<GdbBreakpoint>(ob_gdb_1); // { 101 };
+ GdbBreakpoint gb_our_2x = bktest.get_provider_breakpoint<GdbBreakpoint>(ob_gdb_2); // { 102 };
+ GdbBreakpoint gb_our_3x = bktest.get_provider_breakpoint<GdbBreakpoint>(ob_gdb_3); // { 103 };
+ GdbBreakpoint gb_usr_1x = bktest.get_provider_breakpoint<GdbBreakpoint>(ub_gdb_1); // { 201 };
+ GdbBreakpoint gb_usr_2x = bktest.get_provider_breakpoint<GdbBreakpoint>(ub_gdb_2); // { 202 };
+
+ IoBreakpoint ib_our_1x = bktest.get_provider_breakpoint<IoBreakpoint>(ob_iob_1); // { 301 };
+ IoBreakpoint ib_our_2x = bktest.get_provider_breakpoint<IoBreakpoint>(ob_iob_2); // { 302 };
+ IoBreakpoint ib_usr_1x = bktest.get_provider_breakpoint<IoBreakpoint>(ub_iob_1); // { 401 };
+ IoBreakpoint ib_usr_2x = bktest.get_provider_breakpoint<IoBreakpoint>(ub_iob_2); // { 402 };
+
+ cerr << "Done" << endl;
+}
void BreakpointManager::setPrompt(std::string new_prompt)
{
@@ -35,7 +93,10 @@ OurBreakpoint BreakpointManager::setIoDebuggerBreakpoint(std::string function_na
if (auto* bs = boost::get<GdbResponses::BreakpointSet>(&resp.values.at(0)))
{
GdbBreakpoint gb = { bs->breakpoint_number };
- return brkpts.get_user_breakpoint<OurBreakpoint>(gb);
+ OurBreakpoint result = brkpts.get_user_breakpoint<OurBreakpoint>(gb);
+ channels.info.WriteData("Mapped gdb breakpoint #" + boost::lexical_cast<string>(bs->breakpoint_number)
+ + " to our breakpoint #" + boost::lexical_cast<string>(result.number));
+ return result;
}
else
{
@@ -301,6 +362,8 @@ GdbResponseType BreakpointManager::gdbBreakpointHit(const GdbResponses::Breakpoi
if (brkpts.has_user_breakpoint<OurBreakpoint>(gb))
{
OurBreakpoint ob = brkpts.get_user_breakpoint<OurBreakpoint>(gb);
+ channels.info.WriteData("Mapped gdb breakpoint " + boost::lexical_cast<string>(gb.number)
+ + " to our breakpoint " + boost::lexical_cast<string>(ob.number));
if (ob == *io_init_breakpoint)
{
@@ -209,7 +209,7 @@ class NormalConfiguration : public Configuration
boost::shared_ptr<Configuration> Iocaste::Debugger::getConfiguration(int argc, char* argv[])
{
- return boost::shared_ptr<Configuration>(new ReplayConfiguration());
- //return boost::shared_ptr<Configuration>(new NormalConfiguration(argc, argv));
+ //return boost::shared_ptr<Configuration>(new ReplayConfiguration());
+ return boost::shared_ptr<Configuration>(new NormalConfiguration(argc, argv));
}
@@ -1,6 +1,5 @@
#include "LookForPrompt.hpp"
#include "boost/algorithm/string/predicate.hpp"
-#include "boost/optional.hpp"
using namespace std;
using namespace Iocaste::Debugger;
@@ -14,13 +13,6 @@ LookForPrompt::LookForPrompt(
void LookForPrompt::WriteData(string const& data)
{
- // Due to a race condition between "set prompt" and
- // the dialog coming from GDB, when the prompt changes we need to keep the old
- // end marker around until we get the first string with the new marker.
- boost::optional<
- std::string
- > old_end_marker;
-
buffer.append(data);
if (end_marker_queue.HasData())

0 comments on commit c3e6532

Please sign in to comment.