fixed issue #8 (Traceback for py command is truncated)

This commit is contained in:
ussrhero 2018-01-16 14:22:11 +03:00
parent 147124d798
commit 72e7584947
2 changed files with 63 additions and 29 deletions

View File

@ -3,7 +3,7 @@
#define PYKDEXT_VERSION_MAJOR 2 #define PYKDEXT_VERSION_MAJOR 2
#define PYKDEXT_VERSION_MINOR 0 #define PYKDEXT_VERSION_MINOR 0
#define PYKDEXT_VERSION_SUBVERSION 0 #define PYKDEXT_VERSION_SUBVERSION 0
#define PYKDEXT_VERSION_BUILDNO 15 #define PYKDEXT_VERSION_BUILDNO 16
#define __VER_STR2__(x) #x #define __VER_STR2__(x) #x
#define __VER_STR1__(x) __VER_STR2__(x) #define __VER_STR1__(x) __VER_STR2__(x)

View File

@ -2,6 +2,7 @@
#include <algorithm> #include <algorithm>
#include <sstream> #include <sstream>
#include <string>
#include <fstream> #include <fstream>
#include <iomanip> #include <iomanip>
#include <regex> #include <regex>
@ -26,6 +27,7 @@ void handleException();
std::string getScriptFileName(const std::string &scriptName); std::string getScriptFileName(const std::string &scriptName);
void getPythonVersion(int& majorVersion, int& minorVersion); void getPythonVersion(int& majorVersion, int& minorVersion);
void getDefaultPythonVersion(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; sstr << std::endl;
CComQIPtr<IDebugControl> control = client; printString(client, DEBUG_OUTPUT_NORMAL, sstr.str().c_str() );
control->ControlledOutput( //CComQIPtr<IDebugControl> control = client;
DEBUG_OUTCTL_AMBIENT_TEXT,
DEBUG_OUTPUT_NORMAL, //control->ControlledOutput(
"%s", // DEBUG_OUTCTL_AMBIENT_TEXT,
sstr.str().c_str() // DEBUG_OUTPUT_NORMAL,
); // "%s",
// sstr.str().c_str()
// );
} }
catch(std::exception &e) catch(std::exception &e)
{ {
CComQIPtr<IDebugControl> control = client; printString(client, DEBUG_OUTPUT_ERROR, e.what() );
control->ControlledOutput( //CComQIPtr<IDebugControl> control = client;
DEBUG_OUTCTL_AMBIENT_TEXT,
DEBUG_OUTPUT_ERROR, //control->ControlledOutput(
"%s", // DEBUG_OUTCTL_AMBIENT_TEXT,
e.what() // DEBUG_OUTPUT_ERROR,
); // "%s",
// e.what()
// );
} }
return S_OK; return S_OK;
@ -385,6 +391,8 @@ py(
InterruptWatch interruptWatch(client); InterruptWatch interruptWatch(client);
PyRun_String("import sys\nsys.setrecursionlimit(500)\n", Py_file_input, globals, globals);
if (opts.args.empty()) if (opts.args.empty())
{ {
PyObjectRef result = PyRun_String("import pykd\nfrom pykd import *\n", Py_file_input, globals, globals); PyObjectRef result = PyRun_String("import pykd\nfrom pykd import *\n", Py_file_input, globals, globals);
@ -475,14 +483,16 @@ py(
} }
catch (std::exception &e) catch (std::exception &e)
{ {
CComQIPtr<IDebugControl> control = client; printString(client, DEBUG_OUTPUT_ERROR, e.what() );
control->ControlledOutput( //CComQIPtr<IDebugControl> control = client;
DEBUG_OUTCTL_AMBIENT_TEXT,
DEBUG_OUTPUT_ERROR, //control->ControlledOutput(
"%s", // DEBUG_OUTCTL_AMBIENT_TEXT,
e.what() // DEBUG_OUTPUT_ERROR,
); // "%s",
// e.what()
// );
} }
client->SetOutputMask(oldMask); client->SetOutputMask(oldMask);
@ -546,14 +556,16 @@ pip(
} }
catch (std::exception &e) catch (std::exception &e)
{ {
CComQIPtr<IDebugControl> control = client; printString(client, DEBUG_OUTPUT_ERROR, e.what() );
control->ControlledOutput( //CComQIPtr<IDebugControl> control = client;
DEBUG_OUTCTL_AMBIENT_TEXT,
DEBUG_OUTPUT_ERROR, //control->ControlledOutput(
"%s", // DEBUG_OUTCTL_AMBIENT_TEXT,
e.what() // DEBUG_OUTPUT_ERROR,
); // "%s",
// e.what()
// );
} }
--recursiveGuard; --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<IDebugControl> control = client;
control->ControlledOutput(
DEBUG_OUTCTL_AMBIENT_TEXT,
mask,
"%s\n",
line.c_str()
);
}
}
///////////////////////////////////////////////////////////////////////////////