--exception-handling now takes optional argument to choose between stdout and stderr for its output. stdout is new default value

This commit is contained in:
Alexander Mai 2014-05-25 08:47:37 +02:00
parent 97894c298c
commit 5198c05f35
4 changed files with 38 additions and 6 deletions

View File

@ -390,7 +390,7 @@ $(SRCDIR)/tokenlist.o: lib/tokenlist.cpp lib/cxx11emu.h lib/tokenlist.h lib/conf
$(SRCDIR)/valueflow.o: lib/valueflow.cpp lib/cxx11emu.h lib/valueflow.h lib/errorlogger.h lib/config.h lib/suppressions.h lib/mathlib.h lib/settings.h lib/library.h lib/path.h lib/token.h lib/standards.h lib/timer.h lib/symboldatabase.h lib/tokenlist.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -std=c++0x -c -o $(SRCDIR)/valueflow.o $(SRCDIR)/valueflow.cpp
cli/cmdlineparser.o: cli/cmdlineparser.cpp lib/cxx11emu.h cli/cmdlineparser.h lib/cppcheck.h lib/config.h lib/settings.h lib/library.h lib/path.h lib/mathlib.h lib/token.h lib/valueflow.h lib/suppressions.h lib/standards.h lib/timer.h lib/errorlogger.h cli/filelister.h lib/check.h lib/tokenize.h lib/tokenlist.h
cli/cmdlineparser.o: cli/cmdlineparser.cpp lib/cxx11emu.h cli/cmdlineparser.h lib/cppcheck.h lib/config.h lib/settings.h lib/library.h lib/path.h lib/mathlib.h lib/token.h lib/valueflow.h lib/suppressions.h lib/standards.h lib/timer.h lib/errorlogger.h cli/cppcheckexecutor.h cli/filelister.h lib/check.h lib/tokenize.h lib/tokenlist.h
$(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -std=c++0x -c -o cli/cmdlineparser.o cli/cmdlineparser.cpp
cli/cppcheckexecutor.o: cli/cppcheckexecutor.cpp lib/cxx11emu.h cli/cppcheckexecutor.h lib/errorlogger.h lib/config.h lib/suppressions.h cli/cmdlineparser.h lib/cppcheck.h lib/settings.h lib/library.h lib/path.h lib/mathlib.h lib/token.h lib/valueflow.h lib/standards.h lib/timer.h cli/filelister.h cli/pathmatch.h lib/preprocessor.h cli/threadexecutor.h

View File

@ -18,6 +18,7 @@
#include "cmdlineparser.h"
#include "cppcheck.h"
#include "cppcheckexecutor.h"
#include "filelister.h"
#include "path.h"
#include "settings.h"
@ -136,6 +137,11 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
// (Experimental) exception handling inside cppcheck client
else if (std::strcmp(argv[i], "--exception-handling") == 0)
_settings->exceptionHandling = true;
else if (std::strncmp(argv[i], "--exception-handling=", 21) == 0) {
_settings->exceptionHandling = true;
const std::string exceptionOutfilename=&(argv[i][21]);
CppCheckExecutor::setExceptionOutput(exceptionOutfilename);
}
// Inconclusive checking (still in testing phase)
else if (std::strcmp(argv[i], "--inconclusive") == 0)

View File

@ -292,7 +292,7 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * /*context*
const char * const signame = signal_name(signo);
const char * const sigtext = strsignal(signo);
bool bPrintCallstack=true;
FILE* f=stderr;
FILE* f=CppCheckExecutor::getExceptionOutput()=="stderr" ? stderr : stdout;
fputs("Internal error: cppcheck received signal ", f);
fputs(signame, f);
fputs(", ", f);
@ -334,15 +334,16 @@ static int filterException(int code, PEXCEPTION_POINTERS ex)
{
// TODO we should try to extract more information here
// - address, read/write
FILE *f = stdout;
switch (ex->ExceptionRecord->ExceptionCode) {
case EXCEPTION_ACCESS_VIOLATION:
fprintf(stderr, "Internal error (EXCEPTION_ACCESS_VIOLATION)\n");
fprintf(f, "Internal error (EXCEPTION_ACCESS_VIOLATION)\n");
break;
case EXCEPTION_IN_PAGE_ERROR:
fprintf(stderr, "Internal error (EXCEPTION_IN_PAGE_ERROR)\n");
fprintf(f, "Internal error (EXCEPTION_IN_PAGE_ERROR)\n");
break;
default:
fprintf(stderr, "Internal error (%d)\n",
fprintf(f, "Internal error (%d)\n",
code);
break;
}
@ -359,11 +360,12 @@ static int filterException(int code, PEXCEPTION_POINTERS ex)
int CppCheckExecutor::check_wrapper(CppCheck& cppcheck, int argc, const char* const argv[])
{
#ifdef USE_WINDOWS_SEH
FILE *f = stdout;
__try {
return check_internal(cppcheck, argc, argv);
} __except (filterException(GetExceptionCode(), GetExceptionInformation())) {
// reporting to stdout may not be helpful within a GUI application..
fprintf(stderr, "Please report this to the cppcheck developers!\n");
fprintf(f, "Please report this to the cppcheck developers!\n");
return -1;
}
#elif defined(USE_UNIX_SIGNAL_HANDLING)
@ -558,3 +560,13 @@ void CppCheckExecutor::reportErr(const ErrorLogger::ErrorMessage &msg)
reportErr(msg.toString(_settings->_verbose, _settings->_outputFormat));
}
}
void CppCheckExecutor::setExceptionOutput(const std::string& fn)
{
exceptionOutput=fn;
}
const std::string& CppCheckExecutor::getExceptionOutput()
{
return exceptionOutput;
}
std::string CppCheckExecutor::exceptionOutput;

View File

@ -87,6 +87,15 @@ public:
*/
static void reportStatus(std::size_t fileindex, std::size_t filecount, std::size_t sizedone, std::size_t sizetotal);
/**
* @param fn file name to be used from exception handler
*/
static void setExceptionOutput(const std::string& fn);
/**
* @return file name to be used for output from exception handler
*/
static const std::string& getExceptionOutput();
protected:
/**
@ -151,6 +160,11 @@ private:
*/
std::time_t time1;
/**
* Output file name for exception handler
*/
static std::string exceptionOutput;
/**
* Has --errorlist been given?
*/