From 1a7e0184f81fff7126e47f50bd915790afc118a9 Mon Sep 17 00:00:00 2001 From: Armin Weatherwax Date: Sun, 1 May 2011 15:41:03 +0200 Subject: show plugin debug messages also on windows --- linden/indra/llplugin/llpluginclassmedia.cpp | 9 ++++ linden/indra/llplugin/llpluginclassmedia.h | 5 +++ linden/indra/llplugin/llpluginprocesschild.cpp | 57 ++++++++++++++++++++++++++ linden/indra/llplugin/llpluginprocesschild.h | 6 ++- linden/indra/newview/llviewermedia.cpp | 7 ++++ 5 files changed, 83 insertions(+), 1 deletion(-) diff --git a/linden/indra/llplugin/llpluginclassmedia.cpp b/linden/indra/llplugin/llpluginclassmedia.cpp index f0a44f7..31a9d1d 100755 --- a/linden/indra/llplugin/llpluginclassmedia.cpp +++ b/linden/indra/llplugin/llpluginclassmedia.cpp @@ -1143,6 +1143,15 @@ void LLPluginClassMedia::setBrowserUserAgent(const std::string& user_agent) sendMessage(message); } +#if LL_WINDOWS +void LLPluginClassMedia::showConsole() +{ + LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_INTERNAL, "show_console"); + + sendMessage(message); +} +#endif + void LLPluginClassMedia::crashPlugin() { LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_INTERNAL, "crash"); diff --git a/linden/indra/llplugin/llpluginclassmedia.h b/linden/indra/llplugin/llpluginclassmedia.h index 0004971..098312d 100755 --- a/linden/indra/llplugin/llpluginclassmedia.h +++ b/linden/indra/llplugin/llpluginclassmedia.h @@ -229,6 +229,11 @@ public: std::string getMediaName() const { return mMediaName; }; std::string getMediaDescription() const { return mMediaDescription; }; + #if LL_WINDOWS + //Open a debug console for this plugin. + void showConsole(); + #endif + // Crash the plugin. If you use this outside of a testbed, you will be punished. void crashPlugin(); diff --git a/linden/indra/llplugin/llpluginprocesschild.cpp b/linden/indra/llplugin/llpluginprocesschild.cpp index 0d95cac..168236e 100755 --- a/linden/indra/llplugin/llpluginprocesschild.cpp +++ b/linden/indra/llplugin/llpluginprocesschild.cpp @@ -42,6 +42,14 @@ #include "llpluginmessagepipe.h" #include "llpluginmessageclasses.h" +#if LL_WINDOWS +#include +#include +#include +#include +#include +#endif + static const F32 HEARTBEAT_SECONDS = 1.0f; static const F32 PLUGIN_IDLE_SECONDS = 1.0f / 100.0f; // Each call to idle will give the plugin this much time. @@ -420,6 +428,12 @@ void LLPluginProcessChild::receiveMessageRaw(const std::string &message) { mSleepTime = parsed.getValueReal("time"); } + #if LL_WINDOWS + else if(message_name == "show_console") + { + createConsole(); + } + #endif else if(message_name == "crash") { // Crash the plugin @@ -569,3 +583,46 @@ void LLPluginProcessChild::deliverQueuedMessages() } } } + +#if LL_WINDOWS +void LLPluginProcessChild::createConsole() +{ + const S32 MAX_CONSOLE_LINES = 500; + + int h_con_handle; + long l_std_handle; + + CONSOLE_SCREEN_BUFFER_INFO coninfo; + FILE *fp; + + // allocate a console for this app + AllocConsole(); + + // set the screen buffer to be big enough to let us scroll text + GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo); + coninfo.dwSize.Y = MAX_CONSOLE_LINES; + SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize); + + // redirect unbuffered STDOUT to the console + l_std_handle = (long)GetStdHandle(STD_OUTPUT_HANDLE); + h_con_handle = _open_osfhandle(l_std_handle, _O_TEXT); + fp = _fdopen( h_con_handle, "w" ); + *stdout = *fp; + setvbuf( stdout, NULL, _IONBF, 0 ); + + // redirect unbuffered STDIN to the console + l_std_handle = (long)GetStdHandle(STD_INPUT_HANDLE); + h_con_handle = _open_osfhandle(l_std_handle, _O_TEXT); + fp = _fdopen( h_con_handle, "r" ); + *stdin = *fp; + setvbuf( stdin, NULL, _IONBF, 0 ); + + // redirect unbuffered STDERR to the console + l_std_handle = (long)GetStdHandle(STD_ERROR_HANDLE); + h_con_handle = _open_osfhandle(l_std_handle, _O_TEXT); + fp = _fdopen( h_con_handle, "w" ); + *stderr = *fp; + setvbuf( stderr, NULL, _IOFBF, 1024 ); //Assigning a buffer improves speed a LOT, esp on vista/win7 + //_IOLBF is borked. +} +#endif \ No newline at end of file diff --git a/linden/indra/llplugin/llpluginprocesschild.h b/linden/indra/llplugin/llpluginprocesschild.h index 5d643d7..6d864bb 100755 --- a/linden/indra/llplugin/llpluginprocesschild.h +++ b/linden/indra/llplugin/llpluginprocesschild.h @@ -76,7 +76,11 @@ public: // Inherited from LLPluginInstanceMessageListener /* virtual */ void receivePluginMessage(const std::string &message); - + +#if LL_WINDOWS + void createConsole(); +#endif + private: enum EState diff --git a/linden/indra/newview/llviewermedia.cpp b/linden/indra/newview/llviewermedia.cpp index c228468..84fd0ba 100644 --- a/linden/indra/newview/llviewermedia.cpp +++ b/linden/indra/newview/llviewermedia.cpp @@ -547,6 +547,13 @@ LLPluginClassMedia* LLViewerMediaImpl::newSourceFromMediaType(std::string media_ if (media_source->init(launcher_name, plugin_name, gSavedSettings.getBOOL("PluginAttachDebuggerToPlugins"))) { + #if LL_WINDOWS + if (gSavedSettings.getBOOL("ShowConsoleWindow")) + { + media_source->showConsole(); + } + #endif + return media_source; } else -- cgit v1.1