14#include "arcane/utils/Iostream.h"
15#include "arcane/utils/Convert.h"
16#include "arcane/utils/StdHeader.h"
17#include "arcane/utils/PlatformUtils.h"
18#include "arcane/utils/FatalErrorException.h"
19#include "arcane/utils/SignalException.h"
20#include "arcane/utils/TimeoutException.h"
21#include "arcane/utils/ArithmeticException.h"
22#include "arcane/utils/IStackTraceService.h"
23#include "arcane/utils/TraceInfo.h"
24#include "arcane/utils/OStringStream.h"
25#include "arcane/utils/IThreadImplementation.h"
27#include "arcane/utils/NullThreadMng.h"
28#include "arcane/utils/CriticalSection.h"
32#ifndef ARCANE_OS_WIN32
38#ifndef ARCANE_OS_WIN32
42#define USE_SIGACTION 1
55 typedef void (*fSignalFunc)(int);
62static bool global_arcane_is_check =
true;
64static bool global_arcane_is_check =
false;
67extern "C++" ARCANE_UTILS_EXPORT
70 return global_arcane_is_check;
73extern "C++" ARCANE_UTILS_EXPORT
76 global_arcane_is_check = v;
79extern "C++" ARCANE_UTILS_EXPORT
95 bool global_arcane_has_thread =
true;
98extern "C++" ARCANE_UTILS_EXPORT
101 return global_arcane_has_thread;
104extern "C++" ARCANE_UTILS_EXPORT
108 global_arcane_has_thread = v;
116extern "C++" ARCANE_UTILS_EXPORT
122 return ti->currentThread();
130extern "C++" ARCANE_UTILS_EXPORT
void
131arcaneSetPauseOnError(
bool v)
136extern "C++" ARCANE_UTILS_EXPORT
void
145extern "C++" ARCANE_UTILS_EXPORT
void
149 cerr <<
"** FATAL: Trying to use a null pointer.\n";
151 throw FatalErrorException(A_FUNCINFO);
159void _doNoReferenceError(
const void* ptr)
161 cerr <<
"** FATAL: Null reference.\n";
162 cerr <<
"** FATAL: Trying to use an item not referenced.\n";
163 cerr <<
"** FATAL: Item is located at memory address " << ptr <<
".\n";
171extern "C++" ARCANE_UTILS_EXPORT
void
174 _doNoReferenceError(ptr);
181extern "C++" ARCANE_UTILS_EXPORT
void
184 _doNoReferenceError(ptr);
191extern "C++" ARCANE_UTILS_EXPORT
void
198 vsnprintf(buffer,256,format,ap);
200 cerr << buffer <<
"\n";
201 cout <<
"*E* " << buffer <<
"\n";
207extern "C++" ARCANE_UTILS_EXPORT
void
208arcaneObsolete(
const char* file,
const char* func,
unsigned long line,
const char* text)
210 cerr << file <<
':' << func <<
':' << line <<
'\n';
211 cerr <<
"usage of this function is deprecated";
213 cerr <<
": " << text;
222typedef void (*
fDoAssert)(
const char*,
const char*,
const char*,size_t);
234ARCANE_UTILS_EXPORT
void
235_doAssert(
const char* text,
const char* file,
const char* func,
size_t line)
237 if (g_do_assert_func)
238 (*g_do_assert_func)(text,file,func,line);
240 std::ostringstream ostr;
241 ostr << text <<
':' << file <<
':' << func <<
':' << line <<
": ";
251extern "C++" ARCANE_UTILS_EXPORT
bool
254 if (g_check_debug_func)
255 return (*g_check_debug_func)(val);
264static fSignalFunc g_signal_func = 0;
268setSignalFunc(fSignalFunc func)
270 fSignalFunc old = g_signal_func;
271 g_signal_func = func;
278#ifdef ARCANE_OS_LINUX
279#define STD_SIGNAL_TYPE 1
282#if STD_SIGNAL_TYPE == 1
283#include <sys/signal.h>
293 (*g_signal_func)(val);
297_MiscSigactionFunc(
int val, siginfo_t*,
void*)
300 (*g_signal_func)(val);
310fSignalFunc default_signal_func_sigsegv = 0;
311fSignalFunc default_signal_func_sigfpe = 0;
312fSignalFunc default_signal_func_sigbus = 0;
313fSignalFunc default_signal_func_sigalrm = 0;
314fSignalFunc default_signal_func_sigvtalrm = 0;
316bool global_already_in_signal =
false;
319extern "C++" ARCANE_UTILS_EXPORT
void
320arcaneRedirectSignals(fSignalFunc sig_func)
322 setSignalFunc(sig_func);
323#if STD_SIGNAL_TYPE == 1
327 sa.sa_flags = SA_SIGINFO | SA_NODEFER;
328 sigemptyset(&sa.sa_mask);
329 sa.sa_sigaction = _MiscSigactionFunc;
331 sigaction(SIGSEGV, &sa,
nullptr);
332 sigaction(SIGFPE, &sa,
nullptr);
333 sigaction(SIGBUS, &sa,
nullptr);
334 sigaction(SIGALRM, &sa,
nullptr);
335 sigaction(SIGVTALRM, &sa,
nullptr);
337 default_signal_func_sigsegv = sigset(SIGSEGV,_MiscSigFunc);
338 default_signal_func_sigfpe = sigset(SIGFPE ,_MiscSigFunc);
339 default_signal_func_sigbus = sigset(SIGBUS ,_MiscSigFunc);
342 default_signal_func_sigalrm = sigset(SIGALRM,_MiscSigFunc);
343 default_signal_func_sigvtalrm = sigset(SIGVTALRM,_MiscSigFunc);
348extern "C++" ARCANE_UTILS_EXPORT
void
349arcaneCallDefaultSignal(
int val)
351#if STD_SIGNAL_TYPE == 1
354 SignalException::eSignalType signal_type = SignalException::ST_Unknown;
358 signal_type = SignalException::ST_SegmentationFault;
361 signal_type = SignalException::ST_FloatingException;
364 signal_type = SignalException::ST_BusError;
368 signal_type = SignalException::ST_Alarm;
377 if (global_already_in_signal)
379 global_already_in_signal =
true;
386 StackTrace stack_trace;
387 IStackTraceService* stack_service = platform::getStackTraceService();
389 stack_trace = stack_service->stackTrace();
390 cerr <<
" Signal exception Stack: " << stack_trace.toString() <<
'\n';
393 cerr <<
" No stack trace service\n";
397 bool do_debug_stack =
false;
398 if (
auto v = Convert::Type<Int32>::tryParseFromEnvironment(
"ARCANE_DUMP_DEBUGGER_STACK_IN_SIGNAL",
true))
399 do_debug_stack = (v.value()!=0);
401 std::cerr <<
"GBDStack pid=" << platform::getProcessId() <<
" stack=" <<
platform::getGDBStack() <<
"\n";
404 std::cerr <<
"SignalCaught: You can dump full stacktrace of the process if environment "
405 "variable ARCANE_DUMP_DEBUGGER_STACK_IN_SIGNAL is set to 1\n";
407 if (signal_type==SignalException::ST_Alarm){
408 global_already_in_signal =
false;
409 throw TimeoutException(
"Arcane.Signal",stack_trace);
411 else if (signal_type==SignalException::ST_FloatingException){
412 global_already_in_signal =
false;
413 cerr <<
"** THROW ARITHMETIC EXCEPTION\n";
415 platform::enableFloatingException(
true);
416 throw ArithmeticException(A_FUNCINFO,stack_trace);
418 throw SignalException(
"Arcane.Signal",stack_trace,signal_type,val);
432 cerr <<
"** pure virtual method called\n";
442 void write(std::ostream& o)
const
444 char* v = (
char*)&m_v;
445 o << m_v <<
" HEXA(";
446 o << (int)v[0] <<
'-';
447 o << (int)v[1] <<
'-';
448 o << (int)v[2] <<
'-';
449 o << (int)v[3] <<
'-';
450 o << (int)v[4] <<
'-';
451 o << (int)v[5] <<
'-';
452 o << (int)v[6] <<
'-';
453 o << (int)v[7] <<
")";
458ARCANE_UTILS_EXPORT std::ostream&
Exception lorsqu'une erreur fatale est survenue.
Interface d'un service implémentant le support des threads.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
void arcaneNoReferenceErrorCallTerminate(const void *ptr)
Utilisation d'un objet non référencé.
Int64 arcaneCurrentThread()
Retourne l'identifiant du thread courant.
bool arcaneIsCheck()
Vrai si on est en mode vérification.
bool arcaneHasThread()
Vrai si arcane est compilé avec le support des threads ET qu'ils sont actifs.
void arcaneSetHasThread(bool v)
Active ou désactive le support des threads.
void arcaneNullPointerError()
Signalue l'utilisation d'un pointeur nul.
void arcanePrintf(const char *,...)
Encapsulation de la fonction C printf.
void(* fDoAssert)(const char *, const char *, const char *, size_t)
Fonction appelée lorsqu'une assertion échoue.
bool arcaneIsDebug()
Vrai si la macro ARCANE_DEBUG est définie.
void arcaneSetCheck(bool v)
Active ou désactive le mode vérification.
bool(* fCheckDebug)(unsigned int)
Fonction appelée pour indiquer s'il faut afficher l'information de débug.
void arcaneNoReferenceError(const void *ptr)
Utilisation d'un objet non référencé.
bool _checkDebug(unsigned int val)
void _doAssert(const char *text, const char *file, const char *func, size_t line)
void arcaneDebugPause(const char *msg)
Passe en mode pause ou lance une erreur fatale.
std::ostream & operator<<(std::ostream &ostr, eItemKind item_kind)
Opérateur de sortie sur un flot.
ARCCORE_BASE_EXPORT void arccoreDebugPause(const char *msg)
Passe en mode pause ou lance une erreur fatale.
ARCCORE_BASE_EXPORT void arccoreSetPauseOnError(bool v)
Indique si on l'appel à arccoreDebugPause() effectue une pause.