Lots of work on debugging diff xmit

This commit is contained in:
2021-11-21 13:35:39 -05:00
parent 0881e33c6f
commit b19825aaca
23 changed files with 338 additions and 99 deletions

View File

@@ -247,31 +247,42 @@ static std::string diff_tables_debug_string(StreamBuffer *sb) {
return oss.str();
}
static void set_transmitted_value(LuaStack &LS, LuaSlot tangibles, LuaSlot ntmap, LuaSlot target, StreamBuffer *sb) {
static void set_transmitted_value(LuaStack &LS, LuaSlot tangibles, LuaSlot ntmap, LuaSlot target, StreamBuffer *sb, const char *dbinfo, DebugCollector *dbc) {
int kind = sb->read_uint8();
switch (kind) {
case LUA_TBOOLEAN: {
LS.set(target, sb->read_bool());
bool value = sb->read_bool();
DebugLine(dbc) << dbinfo << (value ? "true" : "false");
LS.set(target, value);
return;
}
case LUA_TNUMBER: {
LS.set(target, sb->read_double());
double value = sb->read_double();
DebugLine(dbc) << dbinfo << value;
LS.set(target, value);
return;
}
case LUA_TSTRING: {
LS.set(target, sb->read_string());
std::string value = sb->read_string();
DebugLine(dbc) << dbinfo << "'" << value << "'";
LS.set(target, value);
return;
}
case LUA_TT_GENERAL: {
LS.rawget(target, ntmap, sb->read_int32());
int index = sb->read_int32();
DebugLine(dbc) << dbinfo << "table " << index;
LS.rawget(target, ntmap, index);
return;
}
case LUA_TT_CLASS: {
LS.makeclass(target, sb->read_string());
std::string value = sb->read_string();
DebugLine(dbc) << dbinfo << "class " << value;
LS.makeclass(target, value);
return;
}
case LUA_TT_TANGIBLE: {
int64_t id = sb->read_int64();
DebugLine(dbc) << dbinfo << "tan " << id;
LS.rawget(target, tangibles, id);
if (LS.isnil(target)) {
World *w = World::fetch_global_pointer(LS.state());
@@ -281,10 +292,12 @@ static void set_transmitted_value(LuaStack &LS, LuaSlot tangibles, LuaSlot ntmap
return;
}
case LUA_TT_GLOBALENV: {
DebugLine(dbc) << dbinfo << "global env";
LS.getglobaltable(target);
return;
}
case LUA_TNIL: {
DebugLine(dbc) << dbinfo << "nil";
LS.set(target, LuaNil);
return;
}
@@ -293,13 +306,13 @@ static void set_transmitted_value(LuaStack &LS, LuaSlot tangibles, LuaSlot ntmap
}
}
static void patch_table(LuaStack &LS0, LuaSlot tangibles, LuaSlot ntmap, LuaSlot tab, StreamBuffer *sb) {
static void patch_table(LuaStack &LS0, LuaSlot tangibles, LuaSlot ntmap, LuaSlot tab, StreamBuffer *sb, DebugCollector *dbc) {
LuaVar key, val;
LuaStack LS(LS0.state(), key, val);
int ndiffs = sb->read_int32();
for (int i = 0; i < ndiffs; i++) {
set_transmitted_value(LS, tangibles, ntmap, key, sb);
set_transmitted_value(LS, tangibles, ntmap, val, sb);
set_transmitted_value(LS, tangibles, ntmap, key, sb, "key=", dbc);
set_transmitted_value(LS, tangibles, ntmap, val, sb, "val=", dbc);
if (LS.isnil(key)) {
LS.setmetatable(tab, val);
} else {
@@ -309,7 +322,7 @@ static void patch_table(LuaStack &LS0, LuaSlot tangibles, LuaSlot ntmap, LuaSlot
LS.result();
}
void World::patch_numbered_tables(StreamBuffer *sb) {
void World::patch_numbered_tables(StreamBuffer *sb, DebugCollector *dbc) {
lua_State *L = state();
LuaVar tangibles, ntmap, tab;
LuaStack LS(L, tangibles, ntmap, tab);
@@ -323,7 +336,8 @@ void World::patch_numbered_tables(StreamBuffer *sb) {
int index = sb->read_int32();
LS.rawget(tab, ntmap, index);
assert(LS.istable(tab));
patch_table(LS, tangibles, ntmap, tab, sb);
DebugHeader(dbc) << "Lua Table " << index << ":";
patch_table(LS, tangibles, ntmap, tab, sb, dbc);
}
LS.result();
}
@@ -367,7 +381,7 @@ void World::diff_numbered_tables(lua_State *master, StreamBuffer *sb) {
MLS.result();
}
void World::patch_tangible_databases(StreamBuffer *sb) {
void World::patch_tangible_databases(StreamBuffer *sb, DebugCollector *dbc) {
lua_State *L = state();
LuaVar tangibles, ntmap, tab;
LuaStack LS(L, tangibles, ntmap, tab);
@@ -381,7 +395,8 @@ void World::patch_tangible_databases(StreamBuffer *sb) {
int64_t id = sb->read_int64();
LS.rawget(tab, tangibles, id);
assert(LS.istable(tab));
patch_table(LS, tangibles, ntmap, tab, sb);
DebugHeader(dbc) << "Tangible DB " << id << ":";
patch_table(LS, tangibles, ntmap, tab, sb, dbc);
}
LS.result();
}
@@ -483,7 +498,7 @@ LuaDefine(table_diffapply, "c") {
StreamBuffer sb;
diff_tables(SLS, stnmap, stab, MLS, mtnmap, mtab, true, &sb);
patch_table(MLS, tangibles, mntmap, mstab, &sb);
patch_table(MLS, tangibles, mntmap, mstab, &sb, nullptr);
bool eq = table_equal(MLS, mstab, mtab);
MLS.set(eql, eq);