Skip to content

Commit bab8853

Browse files
author
schram
committed
trying to catch signals
git-svn-id: svn+ssh://svn.cprover.org/srv/svn/cbmc/branches/peter-incremental-unwinding@3167 6afb6bc1-c8e4-404c-8f48-9ae832c5b171
1 parent c1e0b18 commit bab8853

File tree

4 files changed

+63
-10
lines changed

4 files changed

+63
-10
lines changed

src/cbmc/bmc.cpp

+6-10
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Author: Daniel Kroening, [email protected]
1616
#include <util/location.h>
1717
#include <util/time_stopping.h>
1818
#include <util/message_stream.h>
19+
#include <util/signal_exception.h>
1920

2021
#include <langapi/mode.h>
2122
#include <langapi/languages.h>
@@ -448,45 +449,40 @@ bool bmct::run(const goto_functionst &goto_functions)
448449
error(error_str);
449450
return true;
450451
}
451-
452452
catch(const char *error_str)
453453
{
454454
error(error_str);
455455
return true;
456456
}
457457

458-
catch(std::bad_alloc)
459-
{
460-
error() << "Out of memory" << eom;
461-
return true;
462-
}
463-
464458
} //while
465459

466460
return verification_result;
467461
}
468-
469462
catch(std::string &error_str)
470463
{
471464
message_streamt message_stream(get_message_handler());
472465
message_stream.err_location(symex.last_location);
473466
message_stream.error(error_str);
474467
return true;
475468
}
476-
477469
catch(const char *error_str)
478470
{
479471
message_streamt message_stream(get_message_handler());
480472
message_stream.err_location(symex.last_location);
481473
message_stream.error(error_str);
482474
return true;
483475
}
484-
485476
catch(std::bad_alloc)
486477
{
487478
error() << "Out of memory" << eom;
488479
return true;
489480
}
481+
catch(signal_exceptiont& e)
482+
{
483+
error() << e.what() << eom;
484+
return true;
485+
}
490486
}
491487

492488
/*******************************************************************\

src/cbmc/bmc.h

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Author: Daniel Kroening, [email protected]
1111

1212
#include <list>
1313
#include <map>
14+
#include <exception>
1415

1516
#include <util/hash_cont.h>
1617
#include <util/options.h>

src/cbmc/cbmc_main.cpp

+40
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ Author: Daniel Kroening, [email protected]
1414
1515
*/
1616

17+
#include <cstdlib>
18+
#include <csignal>
19+
#include <iostream>
20+
1721
#include <util/unicode.h>
22+
#include <util/signal_exception.h>
1823

1924
#include "cbmc_parseoptions.h"
2025

@@ -31,15 +36,50 @@ Function: main
3136
\*******************************************************************/
3237

3338
#ifdef _MSC_VER
39+
/*
40+
//prospective Windows signal handling code
41+
#include <windows.h>
42+
BOOL WINAPI CCHandler(DWORD);
43+
BOOL WINAPI kill_handler(DWORD dwType)
44+
{
45+
switch(dwType) {
46+
case CTRL_C_EVENT:
47+
case CTRL_BREAK_EVENT:
48+
std::cerr << "signal caught" << std::endl;
49+
exit(1);
50+
break;
51+
default:
52+
break;
53+
}
54+
return TRUE;
55+
}
56+
*/
3457
int wmain(int argc, const wchar_t **argv_wide)
3558
{
59+
/*
60+
if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE)CCHandler,TRUE)) {
61+
std::cerr << "Unable to install signal handler!" << std::endl;
62+
return 243;
63+
}
64+
*/
65+
3666
const char **argv=narrow_argv(argc, argv_wide);
3767
cbmc_parseoptionst parseoptions(argc, argv);
3868
return parseoptions.main();
3969
}
4070
#else
71+
//signal_exceptiont signal_exception;
72+
73+
void kill_handler(int s)
74+
{
75+
//std::cerr << "signal caught" << std::endl;
76+
//exit(1);
77+
throw signal_exceptiont(s);
78+
}
79+
4180
int main(int argc, const char **argv)
4281
{
82+
signal(SIGINT,kill_handler);
4383
cbmc_parseoptionst parseoptions(argc, argv);
4484
return parseoptions.main();
4585
}

src/util/signal_exception.h

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <util/i2string.h>
2+
3+
class signal_exceptiont: public std::exception
4+
{
5+
public:
6+
signal_exceptiont(int _s) {
7+
s = _s;
8+
}
9+
10+
virtual const char* what() const throw() {
11+
return (std::string("caught signal ")+i2string(s)).c_str();
12+
}
13+
14+
protected:
15+
int s;
16+
};

0 commit comments

Comments
 (0)