Permalink
Browse files

improve logging, add possibility to stop code execution and attach de…

…bugger when assertion fails
  • Loading branch information...
1 parent b2f7a8f commit 0298748b09dac02a6561b8d806e28a03e560e0df @SilverIce committed Oct 18, 2011
Showing with 34 additions and 19 deletions.
  1. +13 −4 Movement/ClientImpl.h
  2. +4 −8 Movement/ClientImpl.hpp
  3. +1 −1 Movement/TaskScheduler.cpp
  4. +1 −1 Movement/UnitMovementImpl.hpp
  5. +15 −5 Movement/typedefs_p.h
View
@@ -35,6 +35,11 @@ namespace Movement
MSTime ClientTime() const {return ServerToClientTime(ServerTime());}
MSTime ClientToServerTime(const MSTime& client_time) const { return client_time - m_time_diff;}
+ void assertInWorld() const{ assert_state(m_socket);}
+ void assertControlled() const {
+ assert_state(m_controlled && m_controlled->client() == this);
+ }
+
public:
TaskTarget_DEV commonTasks;
@@ -44,6 +49,8 @@ namespace Movement
void QueueState(ClientMoveStateChange& client_state)
{
+ assertInWorld();
+ assertControlled();
struct ApplyStateTask : Executor<ApplyStateTask,true>{
UnitMovementImpl * owner;
ClientMoveStateChange state;
@@ -117,15 +124,19 @@ namespace Movement
explicit RespHandler(uint32 _opcode, ClientImpl * client) : m_opcode(_opcode), m_client(client), m_wasHandled(false)
{
+ assert_state(m_client);
client->RegisterRespHandler(this);
}
~RespHandler() {
+ assert_state(m_client);
m_client->UnregisterRespHandler(this);
}
bool OnReply(WorldPacket& data)
{
+ assert_state(!m_wasHandled);
+ assert_state(m_client);
if (m_opcode != data.GetOpcode()) {
log_function("expected reply was: %s, but received instead: %s", LookupOpcodeName(m_opcode), LookupOpcodeName(data.GetOpcode()));
return false;
@@ -135,10 +146,8 @@ namespace Movement
}
void Execute(TaskExecutor_Args& args){
- if (!m_wasHandled) {
- log_function("Kick client due to response(opcode: %s) timeout", LookupOpcodeName(m_opcode));
- m_client->Kick();
- }
+ if (!m_wasHandled)
+ log_function("response timeout (opcode: %s)", LookupOpcodeName(m_opcode));
}
};
@@ -103,12 +103,7 @@ namespace Movement
void ClientImpl::Dereference(const UnitMovementImpl * m)
{
- if (m != m_controlled || m_controlled->client() != this)
- {
- log_function("wtf?");
- return;
- }
-
+ assert_state(m == m_controlled && m_controlled->client() == this)
LostControl();
}
@@ -127,7 +122,8 @@ namespace Movement
void ClientImpl::LostControl()
{
- if (m_controlled && m_controlled->client() == this)
+ assert_state(!m_controlled || (m_controlled->client() == this));
+ if (m_controlled)
m_controlled->client(NULL);
m_controlled = NULL;
}
@@ -167,7 +163,7 @@ namespace Movement
void ClientImpl::HandleResponse(WorldPacket& data)
{
- mov_assert(m_controlled); // wrong state
+ assert_state(m_controlled); // wrong state
if (m_resp_handlers.empty())
{
@@ -134,7 +134,7 @@ namespace Tasks
void TaskExecutor::RegisterObject(TaskTarget& obj)
{
if (obj.isRegistered()){
- log_function("object is already registered somewhere");
+ log_fatal("object is already registered somewhere");
return;
}
@@ -148,7 +148,7 @@ namespace Movement
{
if (SplineEnabled())
{
- log_function("while in server control");
+ log_fatal("while in server control");
return;
}
View
@@ -1,6 +1,7 @@
#pragma once
#include "typedefs.h"
+#include <intrin.h>
namespace Movement
{
@@ -18,16 +19,25 @@ namespace Movement
#define mov_assert(expr) \
if (!(expr)){ \
- log_write("%s:%i Error: Assertion '%s' in %s failed", __FILE__, __LINE__, #expr, __FUNCTION__);\
- log_write_trace(); \
+ log_write("In "__FUNCTION__":%i assertion '"#expr"' failed", __LINE__); \
+ __debugbreak(); \
}
-#define log_function(msg, ...) { \
+/** Use it to validate object state */
+#define assert_state(expr) mov_assert(expr)
+
+#define log_function(msg, ...) log_write(__FUNCTION__ ": " msg, __VA_ARGS__) \
+
+#define log_fatal(msg, ...) { \
log_write(__FUNCTION__ ": " msg, __VA_ARGS__); \
- log_write_trace(); \
+ __debugbreak(); \
}
-#define check(expr) if (bool(expr) == false) log_write("In "__FUNCTION__":%i check '"#expr"' failed", __LINE__);
+#define check(expr) \
+ if (bool(expr) == false) { \
+ log_write("In "__FUNCTION__":%i check '"#expr"' failed", __LINE__); \
+ __debugbreak(); \
+ }
template<class T, T limit>
class counter

0 comments on commit 0298748

Please sign in to comment.