Skip to content
Permalink
Browse files

Remove DSTACK support (#6346)

Debugstacks is not useful, we don't really use it, the DebugStack is not pertinent, gdb and lldb are better if we really want to debug.
  • Loading branch information...
nerzhul committed Aug 30, 2017
1 parent 43f9e94 commit bd6b90359c654f4c75964755e476a8bfd90114ba
@@ -252,8 +252,6 @@ Client::~Client()

void Client::connect(Address address, bool is_local_server)
{
DSTACK(FUNCTION_NAME);

initLocalMapSaving(address, m_address_name, is_local_server);

m_con->SetTimeoutMs(0);
@@ -262,8 +260,6 @@ void Client::connect(Address address, bool is_local_server)

void Client::step(float dtime)
{
DSTACK(FUNCTION_NAME);

// Limit a bit
if(dtime > 2.0)
dtime = 2.0;
@@ -773,7 +769,6 @@ void Client::initLocalMapSaving(const Address &address,

void Client::ReceiveAll()
{
DSTACK(FUNCTION_NAME);
u64 start_ms = porting::getTimeMs();
for(;;)
{
@@ -799,7 +794,6 @@ void Client::ReceiveAll()

void Client::Receive()
{
DSTACK(FUNCTION_NAME);
NetworkPacket pkt;
m_con->Receive(&pkt);
ProcessData(&pkt);
@@ -816,8 +810,6 @@ inline void Client::handleCommand(NetworkPacket* pkt)
*/
void Client::ProcessData(NetworkPacket *pkt)
{
DSTACK(FUNCTION_NAME);

ToClientCommand command = (ToClientCommand) pkt->getCommand();
u32 sender_peer_id = pkt->getPeerId();

@@ -1235,17 +1227,13 @@ void Client::sendChangePassword(const std::string &oldpassword,

void Client::sendDamage(u8 damage)
{
DSTACK(FUNCTION_NAME);

NetworkPacket pkt(TOSERVER_DAMAGE, sizeof(u8));
pkt << damage;
Send(&pkt);
}

void Client::sendBreath(u16 breath)
{
DSTACK(FUNCTION_NAME);

// Protocol v29 make this obsolete
if (m_proto_ver >= 29)
return;
@@ -1257,16 +1245,12 @@ void Client::sendBreath(u16 breath)

void Client::sendRespawn()
{
DSTACK(FUNCTION_NAME);

NetworkPacket pkt(TOSERVER_RESPAWN, 0);
Send(&pkt);
}

void Client::sendReady()
{
DSTACK(FUNCTION_NAME);

NetworkPacket pkt(TOSERVER_CLIENT_READY,
1 + 1 + 1 + 1 + 2 + sizeof(char) * strlen(g_version_hash));

@@ -73,8 +73,6 @@ class KeyType
QUICKTUNE_INC,
QUICKTUNE_DEC,

DEBUG_STACKS,

// hotbar
SLOT_1,
SLOT_2,
@@ -79,7 +79,6 @@ ClientMap & ClientEnvironment::getClientMap()

void ClientEnvironment::setLocalPlayer(LocalPlayer *player)
{
DSTACK(FUNCTION_NAME);
/*
It is a failure if already is a local player
*/
@@ -91,8 +90,6 @@ void ClientEnvironment::setLocalPlayer(LocalPlayer *player)

void ClientEnvironment::step(float dtime)
{
DSTACK(FUNCTION_NAME);

/* Step time of day */
stepTimeOfDay(dtime);

@@ -66,9 +66,6 @@ void RemoteClient::GetNextBlocks (
float dtime,
std::vector<PrioritySortedBlockTransfer> &dest)
{
DSTACK(FUNCTION_NAME);


// Increment timers
m_nothing_to_send_pause_timer -= dtime;
m_nearest_unsent_reset_timer += dtime;
@@ -62,7 +62,6 @@ ClientMap::ClientMap(

MapSector * ClientMap::emergeSector(v2s16 p2d)
{
DSTACK(FUNCTION_NAME);
// Check that it doesn't exist already
try {
return getSectorNoGenerate(p2d);
@@ -303,8 +302,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;
@@ -56,8 +56,6 @@ void sanity_check_fn(const char *assertion, const char *file,
errorstream << file << ":" << line << ": " << function
<< ": An engine assumption '" << assertion << "' failed." << std::endl;

debug_stacks_print_to(errorstream);

abort();
}

@@ -73,140 +71,9 @@ void fatal_error_fn(const char *msg, const char *file,
errorstream << file << ":" << line << ": " << function
<< ": A fatal error occured: " << msg << std::endl;

debug_stacks_print_to(errorstream);

abort();
}

/*
DebugStack
*/

struct DebugStack
{
DebugStack(std::thread::id id);
void print(FILE *file, bool everything);
void print(std::ostream &os, bool everything);

std::thread::id thread_id;
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
};

DebugStack::DebugStack(std::thread::id id)
{
thread_id = 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)
{
std::ostringstream os;
os << thread_id;
fprintf(file, "DEBUG STACK FOR THREAD %s:\n",
os.str().c_str());

for (int i = 0; i < stack_max_i; i++) {
if (i == stack_i && !everything)
break;

if (i < stack_i)
fprintf(file, "#%d %s\n", i, stack[i]);
else
fprintf(file, "(Leftover data: #%d %s)\n", i, stack[i]);
}

if (stack_i == DEBUG_STACK_SIZE)
fprintf(file, "Probably overflown.\n");
}

void DebugStack::print(std::ostream &os, bool everything)
{
os<<"DEBUG STACK FOR THREAD "<<thread_id<<": "<<std::endl;

for(int i = 0; i < stack_max_i; i++) {
if(i == stack_i && !everything)
break;

if (i < stack_i)
os<<"#"<<i<<" "<<stack[i]<<std::endl;
else
os<<"(Leftover data: #"<<i<<" "<<stack[i]<<")"<<std::endl;
}

if (stack_i == DEBUG_STACK_SIZE)
os<<"Probably overflown."<<std::endl;
}

std::map<std::thread::id, DebugStack*> g_debug_stacks;
std::mutex g_debug_stacks_mutex;

void debug_stacks_print_to(std::ostream &os)
{
MutexAutoLock lock(g_debug_stacks_mutex);

os<<"Debug stacks:"<<std::endl;

for (auto it : g_debug_stacks) {
it.second->print(os, false);
}
}

void debug_stacks_print()
{
debug_stacks_print_to(errorstream);
}

DebugStacker::DebugStacker(const char *text)
{
std::thread::id thread_id = std::this_thread::get_id();

MutexAutoLock lock(g_debug_stacks_mutex);

auto n = g_debug_stacks.find(thread_id);
if (n != g_debug_stacks.end()) {
m_stack = n->second;
} else {
/*DEBUGPRINT("Creating new debug stack for thread %x\n",
(unsigned int)thread_id);*/
m_stack = new DebugStack(thread_id);
g_debug_stacks[thread_id] = 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()
{
MutexAutoLock lock(g_debug_stacks_mutex);

if (m_overflowed)
return;

m_stack->stack_i--;

if (m_stack->stack_i == 0) {
std::thread::id thread_id = m_stack->thread_id;
/*DEBUGPRINT("Deleting debug stack for thread %x\n",
(unsigned int)thread_id);*/
delete m_stack;
g_debug_stacks.erase(thread_id);
}
}

#ifdef _MSC_VER

const char *Win32ExceptionCodeToString(DWORD exception_code)
@@ -83,36 +83,6 @@ NORETURN extern void sanity_check_fn(

void debug_set_exception_handler();

/*
DebugStack
*/

#define DEBUG_STACK_SIZE 50
#define DEBUG_STACK_TEXT_SIZE 300

extern void debug_stacks_print_to(std::ostream &os);
extern void debug_stacks_print();

struct DebugStack;
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);

/*
These should be put into every thread
*/
@@ -598,7 +598,6 @@ MapBlock *EmergeThread::finishGen(v3s16 pos, BlockMakeData *bmdata,

void *EmergeThread::run()
{
DSTACK(FUNCTION_NAME);
BEGIN_DEBUG_EXCEPTION_HANDLER

v3s16 pos;
@@ -1099,8 +1099,6 @@ void KeyCache::populate()
key[KeyType::QUICKTUNE_INC] = getKeySetting("keymap_quicktune_inc");
key[KeyType::QUICKTUNE_DEC] = getKeySetting("keymap_quicktune_dec");

key[KeyType::DEBUG_STACKS] = getKeySetting("keymap_print_debug_stacks");

for (int i = 0; i < 23; i++) {
std::string slot_key_name = "keymap_slot" + std::to_string(i + 1);
key[KeyType::SLOT_1 + i] = getKeySetting(slot_key_name.c_str());
@@ -2609,14 +2607,6 @@ void Game::processKeyInput()
quicktune->inc();
} else if (wasKeyDown(KeyType::QUICKTUNE_DEC)) {
quicktune->dec();
} else if (wasKeyDown(KeyType::DEBUG_STACKS)) {
// Print debug stacks
dstream << "-----------------------------------------"
<< std::endl;
dstream << "Printing debug stacks:" << std::endl;
dstream << "-----------------------------------------"
<< std::endl;
debug_stacks_print();
}

if (!isKeyDown(KeyType::JUMP) && runData.reset_jump_timer) {
@@ -63,7 +63,6 @@ enum
GUI_ID_KEY_MUTE_BUTTON,
GUI_ID_KEY_DEC_VOLUME_BUTTON,
GUI_ID_KEY_INC_VOLUME_BUTTON,
GUI_ID_KEY_DUMP_BUTTON,
GUI_ID_KEY_RANGE_BUTTON,
GUI_ID_KEY_ZOOM_BUTTON,
GUI_ID_KEY_CAMERA_BUTTON,
@@ -433,6 +432,5 @@ void GUIKeyChangeMenu::init_keys()
this->add_key(GUI_ID_KEY_HUD_BUTTON, wgettext("Toggle HUD"), "keymap_toggle_hud");
this->add_key(GUI_ID_KEY_CHATLOG_BUTTON, wgettext("Toggle chat log"), "keymap_toggle_chat");
this->add_key(GUI_ID_KEY_FOG_BUTTON, wgettext("Toggle fog"), "keymap_toggle_force_fog_off");
this->add_key(GUI_ID_KEY_DUMP_BUTTON, wgettext("Print stacks"), "keymap_print_debug_stacks");
}

@@ -642,8 +642,6 @@ class CurlFetchThread : public Thread

void *run()
{
DSTACK(FUNCTION_NAME);

CurlHandlePool pool;

m_multi = curl_multi_init();
@@ -57,9 +57,7 @@ ItemStack::ItemStack(const std::string &name_, u16 count_,

void ItemStack::serialize(std::ostream &os) const
{
DSTACK(FUNCTION_NAME);

if(empty())
if (empty())
return;

// Check how many parts of the itemstring are needed
@@ -84,8 +82,6 @@ void ItemStack::serialize(std::ostream &os) const

void ItemStack::deSerialize(std::istream &is, IItemDefManager *itemdef)
{
DSTACK(FUNCTION_NAME);

clear();

// Read name
Oops, something went wrong.

0 comments on commit bd6b903

Please sign in to comment.
You can’t perform that action at this time.