From 72e75849477be501946f774c41e16423c110d677 Mon Sep 17 00:00:00 2001 From: ussrhero Date: Tue, 16 Jan 2018 14:22:11 +0300 Subject: [PATCH] fixed issue #8 (Traceback for py command is truncated) --- pykd_ext/version.h | 2 +- pykd_ext/windbgext.cpp | 90 +++++++++++++++++++++++++++++------------- 2 files changed, 63 insertions(+), 29 deletions(-) diff --git a/pykd_ext/version.h b/pykd_ext/version.h index ef86262..147e498 100644 --- a/pykd_ext/version.h +++ b/pykd_ext/version.h @@ -3,7 +3,7 @@ #define PYKDEXT_VERSION_MAJOR 2 #define PYKDEXT_VERSION_MINOR 0 #define PYKDEXT_VERSION_SUBVERSION 0 -#define PYKDEXT_VERSION_BUILDNO 15 +#define PYKDEXT_VERSION_BUILDNO 16 #define __VER_STR2__(x) #x #define __VER_STR1__(x) __VER_STR2__(x) diff --git a/pykd_ext/windbgext.cpp b/pykd_ext/windbgext.cpp index a105a2a..61880fb 100644 --- a/pykd_ext/windbgext.cpp +++ b/pykd_ext/windbgext.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -26,6 +27,7 @@ void handleException(); std::string getScriptFileName(const std::string &scriptName); void getPythonVersion(int& majorVersion, int& minorVersion); void getDefaultPythonVersion(int& majorVersion, int& minorVersion); +void printString(PDEBUG_CLIENT client, ULONG mask, const char* str); ////////////////////////////////////////////////////////////////////////////// @@ -179,25 +181,29 @@ info( sstr << std::endl; - CComQIPtr control = client; + printString(client, DEBUG_OUTPUT_NORMAL, sstr.str().c_str() ); - control->ControlledOutput( - DEBUG_OUTCTL_AMBIENT_TEXT, - DEBUG_OUTPUT_NORMAL, - "%s", - sstr.str().c_str() - ); + //CComQIPtr control = client; + + //control->ControlledOutput( + // DEBUG_OUTCTL_AMBIENT_TEXT, + // DEBUG_OUTPUT_NORMAL, + // "%s", + // sstr.str().c_str() + // ); } catch(std::exception &e) { - CComQIPtr control = client; + printString(client, DEBUG_OUTPUT_ERROR, e.what() ); - control->ControlledOutput( - DEBUG_OUTCTL_AMBIENT_TEXT, - DEBUG_OUTPUT_ERROR, - "%s", - e.what() - ); + //CComQIPtr control = client; + + //control->ControlledOutput( + // DEBUG_OUTCTL_AMBIENT_TEXT, + // DEBUG_OUTPUT_ERROR, + // "%s", + // e.what() + // ); } return S_OK; @@ -385,6 +391,8 @@ py( InterruptWatch interruptWatch(client); + PyRun_String("import sys\nsys.setrecursionlimit(500)\n", Py_file_input, globals, globals); + if (opts.args.empty()) { PyObjectRef result = PyRun_String("import pykd\nfrom pykd import *\n", Py_file_input, globals, globals); @@ -475,14 +483,16 @@ py( } catch (std::exception &e) { - CComQIPtr control = client; + printString(client, DEBUG_OUTPUT_ERROR, e.what() ); - control->ControlledOutput( - DEBUG_OUTCTL_AMBIENT_TEXT, - DEBUG_OUTPUT_ERROR, - "%s", - e.what() - ); + //CComQIPtr control = client; + + //control->ControlledOutput( + // DEBUG_OUTCTL_AMBIENT_TEXT, + // DEBUG_OUTPUT_ERROR, + // "%s", + // e.what() + // ); } client->SetOutputMask(oldMask); @@ -546,14 +556,16 @@ pip( } catch (std::exception &e) { - CComQIPtr control = client; + printString(client, DEBUG_OUTPUT_ERROR, e.what() ); - control->ControlledOutput( - DEBUG_OUTCTL_AMBIENT_TEXT, - DEBUG_OUTPUT_ERROR, - "%s", - e.what() - ); + //CComQIPtr control = client; + + //control->ControlledOutput( + // DEBUG_OUTCTL_AMBIENT_TEXT, + // DEBUG_OUTPUT_ERROR, + // "%s", + // e.what() + // ); } --recursiveGuard; @@ -787,3 +799,25 @@ void getDefaultPythonVersion(int& majorVersion, int& minorVersion) } /////////////////////////////////////////////////////////////////////////////// + +void printString(PDEBUG_CLIENT client, ULONG mask, const char* str) +{ + std::stringstream sstr(str); + while( sstr.good() ) + { + std::string line; + std::getline(sstr, line); + + CComQIPtr control = client; + + control->ControlledOutput( + DEBUG_OUTCTL_AMBIENT_TEXT, + mask, + "%s\n", + line.c_str() + ); + } + +} + +///////////////////////////////////////////////////////////////////////////////