2013-07-16 01:43:32 +00:00
|
|
|
/*
|
2013-07-19 17:29:33 +00:00
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
2013-07-16 01:43:32 +00:00
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
2013-07-19 17:29:33 +00:00
|
|
|
Author: Leonardo de Moura
|
2013-07-16 01:43:32 +00:00
|
|
|
*/
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <set>
|
|
|
|
#include <string>
|
|
|
|
#include <memory>
|
2013-07-17 00:38:51 +00:00
|
|
|
#include <cstdlib>
|
2013-07-16 01:43:32 +00:00
|
|
|
#ifndef _WINDOWS
|
|
|
|
// Support for pid
|
|
|
|
#include<unistd.h>
|
|
|
|
#endif
|
2013-09-13 10:35:29 +00:00
|
|
|
#include "util/debug.h"
|
2013-07-16 01:43:32 +00:00
|
|
|
|
|
|
|
namespace lean {
|
2014-09-23 15:00:21 +00:00
|
|
|
static volatile bool g_has_violations = false;
|
|
|
|
static volatile bool g_enable_assertions = true;
|
|
|
|
static std::set<std::string> * g_enabled_debug_tags = nullptr;
|
|
|
|
|
|
|
|
void initialize_debug() {
|
|
|
|
// lazy initialization
|
|
|
|
}
|
|
|
|
|
|
|
|
void finalize_debug() {
|
2015-03-28 19:16:39 +00:00
|
|
|
delete g_enabled_debug_tags;
|
2014-09-23 15:00:21 +00:00
|
|
|
}
|
2013-07-16 01:43:32 +00:00
|
|
|
|
2013-07-18 18:10:15 +00:00
|
|
|
bool has_violations() {
|
|
|
|
return g_has_violations;
|
|
|
|
}
|
2013-08-22 15:48:52 +00:00
|
|
|
// LCOV_EXCL_START
|
2013-07-16 01:43:32 +00:00
|
|
|
void enable_assertions(bool f) {
|
|
|
|
g_enable_assertions = f;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool assertions_enabled() {
|
|
|
|
return g_enable_assertions;
|
|
|
|
}
|
|
|
|
|
|
|
|
void notify_assertion_violation(const char * fileName, int line, const char * condition) {
|
|
|
|
std::cerr << "LEAN ASSERTION VIOLATION\n";
|
|
|
|
std::cerr << "File: " << fileName << "\n";
|
|
|
|
std::cerr << "Line: " << line << "\n";
|
|
|
|
std::cerr << condition << "\n";
|
|
|
|
std::cerr.flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
void enable_debug(char const * tag) {
|
|
|
|
if (!g_enabled_debug_tags)
|
2014-09-23 15:00:21 +00:00
|
|
|
g_enabled_debug_tags = new std::set<std::string>();
|
2013-07-16 01:43:32 +00:00
|
|
|
g_enabled_debug_tags->insert(tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
void disable_debug(char const * tag) {
|
|
|
|
if (g_enabled_debug_tags)
|
|
|
|
g_enabled_debug_tags->erase(tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_debug_enabled(const char * tag) {
|
|
|
|
return g_enabled_debug_tags && g_enabled_debug_tags->find(tag) != g_enabled_debug_tags->end();
|
|
|
|
}
|
|
|
|
|
|
|
|
void invoke_debugger() {
|
2013-07-18 18:10:15 +00:00
|
|
|
g_has_violations = true;
|
2013-07-16 01:43:32 +00:00
|
|
|
int * x = 0;
|
|
|
|
for (;;) {
|
2014-01-13 01:20:35 +00:00
|
|
|
if (std::cin.eof())
|
|
|
|
exit(1);
|
2013-07-16 01:43:32 +00:00
|
|
|
#ifdef _WINDOWS
|
|
|
|
std::cerr << "(C)ontinue, (A)bort, (S)top\n";
|
|
|
|
#else
|
|
|
|
std::cerr << "(C)ontinue, (A)bort, (S)top, Invoke (G)DB\n";
|
|
|
|
#endif
|
|
|
|
char result;
|
|
|
|
std::cin >> result;
|
2013-09-13 23:14:24 +00:00
|
|
|
switch (result) {
|
2013-07-16 01:43:32 +00:00
|
|
|
case 'C':
|
|
|
|
case 'c':
|
|
|
|
return;
|
|
|
|
case 'A':
|
|
|
|
case 'a':
|
2014-01-13 01:20:35 +00:00
|
|
|
case EOF:
|
2013-07-16 01:43:32 +00:00
|
|
|
exit(1);
|
|
|
|
case 'S':
|
|
|
|
case 's':
|
|
|
|
// force seg fault...
|
|
|
|
*x = 0;
|
|
|
|
return;
|
|
|
|
#ifndef _WINDOWS
|
|
|
|
case 'G':
|
|
|
|
case 'g': {
|
|
|
|
std::cerr << "INVOKING GDB...\n";
|
|
|
|
std::ostringstream buffer;
|
|
|
|
buffer << "gdb -nw /proc/" << getpid() << "/exe " << getpid();
|
|
|
|
if (system(buffer.str().c_str()) == 0) {
|
|
|
|
std::cerr << "continuing the execution...\n";
|
2013-08-07 15:17:33 +00:00
|
|
|
} else {
|
2013-07-16 01:43:32 +00:00
|
|
|
std::cerr << "ERROR STARTING GDB...\n";
|
|
|
|
// forcing seg fault.
|
|
|
|
*x = 0;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
std::cerr << "INVALID COMMAND\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-08-22 15:48:52 +00:00
|
|
|
// LCOV_EXCL_STOP
|
2013-07-16 01:43:32 +00:00
|
|
|
}
|