From 2044e2185129886a57192672c5b5a878b2c6ab47 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Mon, 5 Aug 2013 18:24:41 +0300 Subject: [PATCH] Remove the ancient DebugStack framework - it hasn't turned out to be useful enough. --- minetest.conf.example | 1 - src/client.cpp | 14 ----- src/clientmap.cpp | 4 -- src/debug.cpp | 153 ----------------------------------------------- src/debug.h | 56 +++-------------- src/defaultsettings.cpp | 1 - src/emerge.cpp | 1 - src/environment.cpp | 6 -- src/game.cpp | 11 ---- src/guiKeyChangeMenu.cpp | 1 - src/inventory.cpp | 4 -- src/inventorymanager.cpp | 2 - src/main.cpp | 5 -- src/map.cpp | 34 ----------- src/porting.cpp | 11 ---- src/server.cpp | 62 +------------------ src/test.cpp | 4 -- 17 files changed, 10 insertions(+), 360 deletions(-) diff --git a/minetest.conf.example b/minetest.conf.example index 4c049f8..4f6448f 100644 --- a/minetest.conf.example +++ b/minetest.conf.example @@ -56,7 +56,6 @@ # If false aux1 is used to fly fast #always_fly_fast = true # Some (temporary) keys for debugging -#keymap_print_debug_stacks = KEY_KEY_P #keymap_quicktune_prev = KEY_HOME #keymap_quicktune_next = KEY_END #keymap_quicktune_dec = KEY_NEXT diff --git a/src/client.cpp b/src/client.cpp index f9908ad..e333e7b 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -101,8 +101,6 @@ static std::string getMediaCacheDir() */ void MeshUpdateQueue::addBlock(v3s16 p, MeshMakeData *data, bool ack_block_to_server, bool urgent) { - DSTACK(__FUNCTION_NAME); - assert(data); JMutexAutoLock lock(m_mutex); @@ -171,7 +169,6 @@ void * MeshUpdateThread::Thread() log_register_thread("MeshUpdateThread"); - DSTACK(__FUNCTION_NAME); BEGIN_DEBUG_EXCEPTION_HANDLER @@ -227,8 +224,6 @@ void * MediaFetchThread::Thread() log_register_thread("MediaFetchThread"); - DSTACK(__FUNCTION_NAME); - BEGIN_DEBUG_EXCEPTION_HANDLER #if USE_CURL @@ -378,7 +373,6 @@ void * MediaFetchThread::Thread() void Client::connect(Address address) { - DSTACK(__FUNCTION_NAME); //JMutexAutoLock lock(m_con_mutex); //bulk comment-out m_con.SetTimeoutMs(0); m_con.Connect(address); @@ -399,7 +393,6 @@ bool Client::connectedAndInitialized() void Client::step(float dtime) { - DSTACK(__FUNCTION_NAME); // Limit a bit if(dtime > 2.0) @@ -1068,7 +1061,6 @@ void Client::request_media(const std::list &file_requests) void Client::ReceiveAll() { - DSTACK(__FUNCTION_NAME); u32 start_ms = porting::getTimeMs(); for(;;) { @@ -1096,7 +1088,6 @@ void Client::ReceiveAll() void Client::Receive() { - DSTACK(__FUNCTION_NAME); SharedBuffer data; u16 sender_peer_id; u32 datasize; @@ -1114,8 +1105,6 @@ void Client::Receive() */ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id) { - DSTACK(__FUNCTION_NAME); - // Ignore packets that don't even fit a command if(datasize < 2) { @@ -2361,7 +2350,6 @@ void Client::sendChangePassword(const std::wstring oldpassword, void Client::sendDamage(u8 damage) { - DSTACK(__FUNCTION_NAME); std::ostringstream os(std::ios_base::binary); writeU16(os, TOSERVER_DAMAGE); @@ -2376,7 +2364,6 @@ void Client::sendDamage(u8 damage) void Client::sendBreath(u16 breath) { - DSTACK(__FUNCTION_NAME); std::ostringstream os(std::ios_base::binary); writeU16(os, TOSERVER_BREATH); @@ -2390,7 +2377,6 @@ void Client::sendBreath(u16 breath) void Client::sendRespawn() { - DSTACK(__FUNCTION_NAME); std::ostringstream os(std::ios_base::binary); writeU16(os, TOSERVER_RESPAWN); diff --git a/src/clientmap.cpp b/src/clientmap.cpp index e0c41c7..98b29e2 100644 --- a/src/clientmap.cpp +++ b/src/clientmap.cpp @@ -70,7 +70,6 @@ MapSector * ClientMap::emergeSector(v2s16 p2d) { - DSTACK(__FUNCTION_NAME); // Check that it doesn't exist already try{ return getSectorNoGenerate(p2d); @@ -93,7 +92,6 @@ MapSector * ClientMap::emergeSector(v2s16 p2d) #if 0 void ClientMap::deSerializeSector(v2s16 p2d, std::istream &is) { - DSTACK(__FUNCTION_NAME); ClientMapSector *sector = NULL; //JMutexAutoLock lock(m_sector_mutex); // Bulk comment-out @@ -406,8 +404,6 @@ struct MeshBufListList void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) { - DSTACK(__FUNCTION_NAME); - bool is_transparent_pass = pass == scene::ESNRP_TRANSPARENT; std::string prefix; diff --git a/src/debug.cpp b/src/debug.cpp index 2e4992a..eba4015 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -71,163 +71,12 @@ void assert_fail(const char *assertion, const char *file, (unsigned long)get_current_thread_id(), file, line, function, assertion); - debug_stacks_print(); - if(g_debugstreams[1]) fclose(g_debugstreams[1]); abort(); } -/* - DebugStack -*/ - -DebugStack::DebugStack(threadid_t id) -{ - threadid = id; - stack_i = 0; - stack_max_i = 0; - memset(stack, 0, DEBUG_STACK_SIZE*DEBUG_STACK_TEXT_SIZE); -} - -void DebugStack::print(FILE *file, bool everything) -{ - fprintf(file, "DEBUG STACK FOR THREAD %lx:\n", - (unsigned long)threadid); - - for(int i=0; i g_debug_stacks; -JMutex g_debug_stacks_mutex; - -void debug_stacks_init() -{ - g_debug_stacks_mutex.Init(); -} - -void debug_stacks_print_to(std::ostream &os) -{ - JMutexAutoLock lock(g_debug_stacks_mutex); - - os<<"Debug stacks:"<::iterator - i = g_debug_stacks.begin(); - i != g_debug_stacks.end(); ++i) - { - i->second->print(os, false); - } -} - -void debug_stacks_print() -{ - JMutexAutoLock lock(g_debug_stacks_mutex); - - DEBUGPRINT("Debug stacks:\n"); - - for(std::map::iterator - i = g_debug_stacks.begin(); - i != g_debug_stacks.end(); ++i) - { - DebugStack *stack = i->second; - - for(int i=0; iprint(g_debugstreams[i], true); - } - } -} - -DebugStacker::DebugStacker(const char *text) -{ - threadid_t threadid = get_current_thread_id(); - - JMutexAutoLock lock(g_debug_stacks_mutex); - - std::map::iterator n; - n = g_debug_stacks.find(threadid); - if(n != g_debug_stacks.end()) - { - m_stack = n->second; - } - else - { - /*DEBUGPRINT("Creating new debug stack for thread %x\n", - (unsigned int)threadid);*/ - m_stack = new DebugStack(threadid); - g_debug_stacks[threadid] = m_stack; - } - - if(m_stack->stack_i >= DEBUG_STACK_SIZE) - { - m_overflowed = true; - } - else - { - m_overflowed = false; - - snprintf(m_stack->stack[m_stack->stack_i], - DEBUG_STACK_TEXT_SIZE, "%s", text); - m_stack->stack_i++; - if(m_stack->stack_i > m_stack->stack_max_i) - m_stack->stack_max_i = m_stack->stack_i; - } -} - -DebugStacker::~DebugStacker() -{ - JMutexAutoLock lock(g_debug_stacks_mutex); - - if(m_overflowed == true) - return; - - m_stack->stack_i--; - - if(m_stack->stack_i == 0) - { - threadid_t threadid = m_stack->threadid; - /*DEBUGPRINT("Deleting debug stack for thread %x\n", - (unsigned int)threadid);*/ - delete m_stack; - g_debug_stacks.erase(threadid); - } -} - - #ifdef _MSC_VER #if CATCH_UNHANDLED_EXCEPTIONS == 1 void se_trans_func(unsigned int u, EXCEPTION_POINTERS* pExp) @@ -257,5 +106,3 @@ void se_trans_func(unsigned int u, EXCEPTION_POINTERS* pExp) #endif #endif - - diff --git a/src/debug.h b/src/debug.h index 31855cc..1049086 100644 --- a/src/debug.h +++ b/src/debug.h @@ -148,52 +148,6 @@ __NORETURN extern void assert_fail( #define assert(expr) ASSERT(expr) /* - DebugStack -*/ - -#define DEBUG_STACK_SIZE 50 -#define DEBUG_STACK_TEXT_SIZE 300 - -struct DebugStack -{ - DebugStack(threadid_t id); - void print(FILE *file, bool everything); - void print(std::ostream &os, bool everything); - - threadid_t threadid; - char stack[DEBUG_STACK_SIZE][DEBUG_STACK_TEXT_SIZE]; - int stack_i; // Points to the lowest empty position - int stack_max_i; // Highest i that was seen -}; - -extern std::map g_debug_stacks; -extern JMutex g_debug_stacks_mutex; - -extern void debug_stacks_init(); -extern void debug_stacks_print_to(std::ostream &os); -extern void debug_stacks_print(); - -class DebugStacker -{ -public: - DebugStacker(const char *text); - ~DebugStacker(); - -private: - DebugStack *m_stack; - bool m_overflowed; -}; - -#define DSTACK(msg)\ - DebugStacker __debug_stacker(msg); - -#define DSTACKF(...)\ - char __buf[DEBUG_STACK_TEXT_SIZE];\ - snprintf(__buf,\ - DEBUG_STACK_TEXT_SIZE, __VA_ARGS__);\ - DebugStacker __debug_stacker(__buf); - -/* Packet counter */ @@ -245,7 +199,15 @@ class PacketCounter }; /* - These should be put into every thread + These should be put into the beginning and end of every thread: + + BEGIN_PORTABLE_DEBUG_EXCEPTION_HANDLER + END_DEBUG_EXCEPTION_HANDLER(errorstream) + + The debug exception handlers will print out any fall-through exception in + RELEASE builds, and will not do anything in DEBUG builds so that a debugger + can instead more helpfully provide a backtrace and other facilities. On + Windows they also catch certain kinds of OS-level failures. */ #if CATCH_UNHANDLED_EXCEPTIONS == 1 diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 326e11b..33bba94 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -61,7 +61,6 @@ void set_default_settings(Settings *settings) settings->setDefault("always_fly_fast", "true"); // Some (temporary) keys for debugging - settings->setDefault("keymap_print_debug_stacks", "KEY_KEY_P"); settings->setDefault("keymap_quicktune_prev", "KEY_HOME"); settings->setDefault("keymap_quicktune_next", "KEY_END"); settings->setDefault("keymap_quicktune_dec", "KEY_NEXT"); diff --git a/src/emerge.cpp b/src/emerge.cpp index f977637..2ad69a8 100644 --- a/src/emerge.cpp +++ b/src/emerge.cpp @@ -398,7 +398,6 @@ bool EmergeThread::getBlockOrStartGen(v3s16 p, MapBlock **b, void *EmergeThread::Thread() { ThreadStarted(); log_register_thread("EmergeThread" + itos(id)); - DSTACK(__FUNCTION_NAME); BEGIN_DEBUG_EXCEPTION_HANDLER v3s16 last_tried_pos(-32768,-32768,-32768); // For error output diff --git a/src/environment.cpp b/src/environment.cpp index 57fdfd7..2a8abb6 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -68,7 +68,6 @@ void Environment::addPlayer(Player *player) { - DSTACK(__FUNCTION_NAME); /* Check that peer_ids are unique. Also check that names are unique. @@ -85,7 +84,6 @@ void Environment::addPlayer(Player *player) void Environment::removePlayer(u16 peer_id) { - DSTACK(__FUNCTION_NAME); re_search: for(std::list::iterator i = m_players.begin(); i != m_players.end(); ++i) @@ -1038,7 +1036,6 @@ void ServerEnvironment::clearAllObjects() void ServerEnvironment::step(float dtime) { - DSTACK(__FUNCTION_NAME); //TimeTaker timer("ServerEnv step"); @@ -2013,7 +2010,6 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete) void ClientEnvironment::addPlayer(Player *player) { - DSTACK(__FUNCTION_NAME); /* It is a failure if player is local and there already is a local player @@ -2037,8 +2033,6 @@ LocalPlayer * ClientEnvironment::getLocalPlayer() void ClientEnvironment::step(float dtime) { - DSTACK(__FUNCTION_NAME); - /* Step time of day */ stepTimeOfDay(dtime); diff --git a/src/game.cpp b/src/game.cpp index 205c345..b3c6a30 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2065,17 +2065,6 @@ void the_game( } } - // Print debug stacks - if(input->wasKeyDown(getKeySetting("keymap_print_debug_stacks"))) - { - dstream<<"-----------------------------------------" - <add_key(GUI_ID_KEY_FAST_BUTTON, wgettext("Toggle fast"), "keymap_fastmove"); this->add_key(GUI_ID_KEY_NOCLIP_BUTTON, wgettext("Toggle noclip"), "keymap_noclip"); this->add_key(GUI_ID_KEY_RANGE_BUTTON, wgettext("Range select"), "keymap_rangeselect"); - this->add_key(GUI_ID_KEY_DUMP_BUTTON, wgettext("Print stacks"), "keymap_print_debug_stacks"); } diff --git a/src/inventory.cpp b/src/inventory.cpp index 2ce50e0..cbaa44a 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -126,8 +126,6 @@ static std::string deSerializeJsonStringIfNeeded(std::istream &is) void ItemStack::serialize(std::ostream &os) const { - DSTACK(__FUNCTION_NAME); - if(empty()) return; @@ -151,8 +149,6 @@ void ItemStack::serialize(std::ostream &os) const void ItemStack::deSerialize(std::istream &is, IItemDefManager *itemdef) { - DSTACK(__FUNCTION_NAME); - clear(); // Read name diff --git a/src/inventorymanager.cpp b/src/inventorymanager.cpp index 6187675..b3a04fc 100644 --- a/src/inventorymanager.cpp +++ b/src/inventorymanager.cpp @@ -763,8 +763,6 @@ void ICraftAction::clientApply(InventoryManager *mgr, IGameDef *gamedef) bool getCraftingResult(Inventory *inv, ItemStack& result, bool decrementInput, IGameDef *gamedef) { - DSTACK(__FUNCTION_NAME); - result.clear(); // Get the InventoryList in which we will operate diff --git a/src/main.cpp b/src/main.cpp index b3aa9c9..686955a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -866,10 +866,6 @@ int main(int argc, char *argv[]) infostream<<"path_share = "<ndef()->get(block->getNodeNoCheck(relpos)).name <<"\" at "<setNodeNoCheck(relpos, n); @@ -1639,7 +1638,6 @@ void Map::transformLiquidsFinite(std::map & modified_blocks) { INodeDefManager *nodemgr = m_gamedef->ndef(); - DSTACK(__FUNCTION_NAME); //TimeTaker timer("transformLiquids()"); u32 loopcount = 0; @@ -1998,7 +1996,6 @@ void Map::transformLiquids(std::map & modified_blocks) INodeDefManager *nodemgr = m_gamedef->ndef(); - DSTACK(__FUNCTION_NAME); //TimeTaker timer("transformLiquids()"); u32 loopcount = 0; @@ -2834,10 +2831,6 @@ MapBlock* ServerMap::finishBlockMake(BlockMakeData *data, ServerMapSector * ServerMap::createSector(v2s16 p2d) { - DSTACKF("%s: p2d=(%d,%d)", - __FUNCTION_NAME, - p2d.X, p2d.Y); - /* Check if it exists already in memory */ @@ -2900,8 +2893,6 @@ MapBlock * ServerMap::generateBlock( std::map &modified_blocks ) { - DSTACKF("%s: p=(%d,%d,%d)", __FUNCTION_NAME, p.X, p.Y, p.Z); - /*infostream<<"generateBlock(): " <<"("<isDummy() == false) @@ -3326,7 +3310,6 @@ v3s16 ServerMap::getBlockPos(std::string sectordir, std::string blockfile) void ServerMap::save(ModifiedState save_level) { - DSTACK(__FUNCTION_NAME); if(m_map_saving_enabled == false) { infostream<<"WARNING: Not saving map, saving disabled."< &dst) void ServerMap::saveMapMeta() { - DSTACK(__FUNCTION_NAME); - /*infostream<<"ServerMap::saveMapMeta(): " <<"seed="< &dest) { - DSTACK(__FUNCTION_NAME); - /*u32 timer_result; TimeTaker timer("RemoteClient::GetNextBlocks", &timer_result);*/ @@ -946,7 +942,6 @@ void PlayerInfo::PrintLine(std::ostream *s) void Server::start(unsigned short port) { - DSTACK(__FUNCTION_NAME); infostream<<"Starting server on port "< 2.0) dtime = 2.0; @@ -1007,8 +999,6 @@ void Server::step(float dtime) void Server::AsyncRunStep() { - DSTACK(__FUNCTION_NAME); - g_profiler->add("Server::AsyncRunStep (num)", 1); float dtime; @@ -1697,7 +1687,6 @@ void Server::AsyncRunStep() void Server::Receive() { - DSTACK(__FUNCTION_NAME); SharedBuffer data; u16 peer_id; u32 datasize; @@ -1738,7 +1727,6 @@ void Server::Receive() void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) { - DSTACK(__FUNCTION_NAME); // Environment is locked first. JMutexAutoLock envlock(m_env_mutex); JMutexAutoLock conlock(m_con_mutex); @@ -3231,8 +3219,7 @@ void Server::setInventoryModified(const InventoryLocation &loc) //std::list Server::getPlayerInfo() //{ -// DSTACK(__FUNCTION_NAME); -// JMutexAutoLock envlock(m_env_mutex); +//// JMutexAutoLock envlock(m_env_mutex); // JMutexAutoLock conlock(m_con_mutex); // // std::list list; @@ -3273,7 +3260,6 @@ void Server::setInventoryModified(const InventoryLocation &loc) void Server::peerAdded(con::Peer *peer) { - DSTACK(__FUNCTION_NAME); verbosestream<<"Server::peerAdded(): peer->id=" <id<id=" <id<<", timeout="<m_hp_not_sent = false; @@ -3788,7 +3753,6 @@ void Server::SendPlayerHP(u16 peer_id) void Server::SendPlayerBreath(u16 peer_id) { - DSTACK(__FUNCTION_NAME); PlayerSAO *playersao = getPlayerSAO(peer_id); assert(playersao); playersao->m_breath_not_sent = false; @@ -3797,7 +3761,6 @@ void Server::SendPlayerBreath(u16 peer_id) void Server::SendMovePlayer(u16 peer_id) { - DSTACK(__FUNCTION_NAME); Player *player = m_env->getPlayer(peer_id); assert(player); @@ -4081,8 +4044,6 @@ void Server::setBlockNotSent(v3s16 p) void Server::SendBlockNoLock(u16 peer_id, MapBlock *block, u8 ver, u16 net_proto_version) { - DSTACK(__FUNCTION_NAME); - v3s16 p = block->getPos(); #if 0 @@ -4135,8 +4096,6 @@ void Server::SendBlockNoLock(u16 peer_id, MapBlock *block, u8 ver, u16 net_proto void Server::SendBlocks(float dtime) { - DSTACK(__FUNCTION_NAME); - JMutexAutoLock envlock(m_env_mutex); JMutexAutoLock conlock(m_con_mutex); @@ -4206,8 +4165,6 @@ void Server::SendBlocks(float dtime) void Server::fillMediaCache() { - DSTACK(__FUNCTION_NAME); - infostream<<"Server: Calculating media file checksums"< &tosend) { - DSTACK(__FUNCTION_NAME); - verbosestream<<"Server::sendRequestedMedia(): " <<"Sending files to client"<::iterator i = m_clients.begin(); i != m_clients.end(); ++i){ @@ -4525,8 +4476,6 @@ void Server::sendDetachedInventoryToAll(const std::string &name) void Server::sendDetachedInventories(u16 peer_id) { - DSTACK(__FUNCTION_NAME); - for(std::map::iterator i = m_detached_inventories.begin(); i != m_detached_inventories.end(); i++){ @@ -4542,8 +4491,6 @@ void Server::sendDetachedInventories(u16 peer_id) void Server::DiePlayer(u16 peer_id) { - DSTACK(__FUNCTION_NAME); - PlayerSAO *playersao = getPlayerSAO(peer_id); assert(playersao); @@ -4562,8 +4509,6 @@ void Server::DiePlayer(u16 peer_id) void Server::RespawnPlayer(u16 peer_id) { - DSTACK(__FUNCTION_NAME); - PlayerSAO *playersao = getPlayerSAO(peer_id); assert(playersao); @@ -4582,8 +4527,6 @@ void Server::RespawnPlayer(u16 peer_id) void Server::UpdateCrafting(u16 peer_id) { - DSTACK(__FUNCTION_NAME); - Player* player = m_env->getPlayer(peer_id); assert(player); @@ -4600,7 +4543,6 @@ void Server::UpdateCrafting(u16 peer_id) RemoteClient* Server::getClient(u16 peer_id) { - DSTACK(__FUNCTION_NAME); //JMutexAutoLock lock(m_con_mutex); std::map::iterator n; n = m_clients.find(peer_id); @@ -5340,8 +5282,6 @@ void Server::handlePeerChanges() void dedicated_server_loop(Server &server, bool &kill) { - DSTACK(__FUNCTION_NAME); - verbosestream<<"dedicated_server_loop()"<