2011-09-09 21:24:18 +02:00
|
|
|
#include "assert.hh"
|
|
|
|
|
2012-10-17 17:01:08 +02:00
|
|
|
#include "exception.hh"
|
2013-11-17 14:25:58 +01:00
|
|
|
#include "debug.hh"
|
2012-10-17 17:01:08 +02:00
|
|
|
|
2014-01-08 20:22:58 +01:00
|
|
|
#if defined(__CYGWIN__)
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2013-01-23 13:45:44 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2011-09-09 21:24:18 +02:00
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2012-10-17 17:01:08 +02:00
|
|
|
struct assert_failed : logic_error
|
2011-09-09 21:24:18 +02:00
|
|
|
{
|
2014-10-20 20:18:38 +02:00
|
|
|
assert_failed(String message)
|
|
|
|
: m_message(std::move(message)) {}
|
2011-09-09 21:24:18 +02:00
|
|
|
|
2013-04-11 13:57:35 +02:00
|
|
|
const char* what() const override { return m_message.c_str(); }
|
2012-10-17 17:01:08 +02:00
|
|
|
private:
|
|
|
|
String m_message;
|
|
|
|
};
|
2011-09-09 21:24:18 +02:00
|
|
|
|
2012-10-17 17:01:08 +02:00
|
|
|
void on_assert_failed(const char* message)
|
2012-10-16 16:16:32 +02:00
|
|
|
{
|
2013-05-13 14:23:07 +02:00
|
|
|
String debug_info = "pid: " + to_string(getpid());
|
2013-11-17 14:25:58 +01:00
|
|
|
write_debug("assert failed: '"_str + message + "' " + debug_info);
|
|
|
|
|
2014-01-08 20:22:58 +01:00
|
|
|
const auto msg = message + "\n[Debug Infos]\n"_str + debug_info;
|
|
|
|
#if defined(__CYGWIN__)
|
|
|
|
int res = MessageBox(NULL, msg.c_str(), "Kakoune: assert failed",
|
|
|
|
MB_OKCANCEL | MB_ICONERROR);
|
|
|
|
switch (res)
|
|
|
|
{
|
|
|
|
case IDCANCEL:
|
|
|
|
throw assert_failed(message);
|
|
|
|
case IDOK:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#else
|
2014-04-01 19:54:46 +02:00
|
|
|
auto cmd = "xmessage -buttons 'quit:0,ignore:1' '" + msg + "'";
|
|
|
|
switch (system(cmd.c_str()))
|
2012-10-16 16:16:32 +02:00
|
|
|
{
|
2012-10-19 03:53:10 +02:00
|
|
|
case -1:
|
|
|
|
case 0:
|
2012-10-16 16:16:32 +02:00
|
|
|
throw assert_failed(message);
|
|
|
|
case 1:
|
|
|
|
return;
|
|
|
|
}
|
2014-01-08 20:22:58 +01:00
|
|
|
#endif
|
2012-10-16 16:16:32 +02:00
|
|
|
}
|
|
|
|
|
2011-09-09 21:24:18 +02:00
|
|
|
}
|