kopia lustrzana https://gitlab.com/sane-project/backends
genesys: Add utility to print debug messages upon function exit
rodzic
397994b215
commit
bba75702b6
|
@ -2115,6 +2115,45 @@ void run_functions_at_backend_exit()
|
||||||
s_functions_run_at_backend_exit.release();
|
s_functions_run_at_backend_exit.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (defined(__GNUC__) || defined(__CLANG__)) && (defined(__linux__) || defined(__APPLE__))
|
||||||
|
extern "C" char* __cxa_get_globals();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static unsigned num_uncaught_exceptions()
|
||||||
|
{
|
||||||
|
#if __cplusplus >= 201703L
|
||||||
|
int count = std::uncaught_exceptions();
|
||||||
|
return count >= 0 ? count : 0;
|
||||||
|
#elif (defined(__GNUC__) || defined(__CLANG__)) && (defined(__linux__) || defined(__APPLE__))
|
||||||
|
// the format of the __cxa_eh_globals struct is enshrined into the Itanium C++ ABI and it's
|
||||||
|
// very unlikely we'll get issues referencing it directly
|
||||||
|
char* cxa_eh_globals_ptr = __cxa_get_globals();
|
||||||
|
return *reinterpret_cast<unsigned*>(cxa_eh_globals_ptr + sizeof(void*));
|
||||||
|
#else
|
||||||
|
return std::uncaught_exception() ? 1 : 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
DebugMessageHelper::DebugMessageHelper(const char* func)
|
||||||
|
{
|
||||||
|
func_ = func;
|
||||||
|
num_exceptions_on_enter_ = num_uncaught_exceptions();
|
||||||
|
DBG(DBG_proc, "%s: start", func_);
|
||||||
|
}
|
||||||
|
|
||||||
|
DebugMessageHelper::~DebugMessageHelper()
|
||||||
|
{
|
||||||
|
if (num_exceptions_on_enter_ < num_uncaught_exceptions()) {
|
||||||
|
if (status_) {
|
||||||
|
DBG(DBG_error, "%s: failed during %s", func_, status_);
|
||||||
|
} else {
|
||||||
|
DBG(DBG_error, "%s: failed", func_);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
DBG(DBG_proc, "%s: completed", func_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void debug_dump(unsigned level, const Genesys_Settings& settings)
|
void debug_dump(unsigned level, const Genesys_Settings& settings)
|
||||||
{
|
{
|
||||||
DBG(level, "settings:\n"
|
DBG(level, "settings:\n"
|
||||||
|
|
|
@ -1851,6 +1851,22 @@ extern void sanei_genesys_usleep(unsigned int useconds);
|
||||||
// same as sanei_genesys_usleep just that the duration is in milliseconds
|
// same as sanei_genesys_usleep just that the duration is in milliseconds
|
||||||
extern void sanei_genesys_sleep_ms(unsigned int milliseconds);
|
extern void sanei_genesys_sleep_ms(unsigned int milliseconds);
|
||||||
|
|
||||||
|
class DebugMessageHelper {
|
||||||
|
public:
|
||||||
|
DebugMessageHelper(const char* func);
|
||||||
|
~DebugMessageHelper();
|
||||||
|
|
||||||
|
void status(const char* status) { status_ = status; }
|
||||||
|
void clear() { status_ = nullptr; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
const char* func_ = nullptr;
|
||||||
|
const char* status_ = nullptr;
|
||||||
|
unsigned num_exceptions_on_enter_ = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define DBG_HELPER(var) DebugMessageHelper var(__func__)
|
||||||
|
|
||||||
template<class F>
|
template<class F>
|
||||||
SANE_Status wrap_exceptions_to_status_code(const char* func, F&& function)
|
SANE_Status wrap_exceptions_to_status_code(const char* func, F&& function)
|
||||||
{
|
{
|
||||||
|
|
Ładowanie…
Reference in New Issue