mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-28 07:44:06 +01:00
Common: improves reliability of FF_DEBUG
This commit is contained in:
+1
-1
@@ -474,6 +474,7 @@ file(GENERATE OUTPUT logo_builtin.h CONTENT "${LOGO_BUILTIN_H}")
|
|||||||
|
|
||||||
set(LIBFASTFETCH_SRC
|
set(LIBFASTFETCH_SRC
|
||||||
src/common/impl/commandoption.c
|
src/common/impl/commandoption.c
|
||||||
|
src/common/impl/debug.c
|
||||||
src/common/impl/duration.c
|
src/common/impl/duration.c
|
||||||
src/common/impl/font.c
|
src/common/impl/font.c
|
||||||
src/common/impl/format.c
|
src/common/impl/format.c
|
||||||
@@ -1106,7 +1107,6 @@ elseif(WIN32)
|
|||||||
src/common/impl/processing_windows.c
|
src/common/impl/processing_windows.c
|
||||||
src/common/impl/FFPlatform_windows.c
|
src/common/impl/FFPlatform_windows.c
|
||||||
src/common/impl/binary_windows.c
|
src/common/impl/binary_windows.c
|
||||||
src/common/impl/debug_windows.c
|
|
||||||
src/common/impl/kmod_windows.c
|
src/common/impl/kmod_windows.c
|
||||||
src/common/windows/getline.c
|
src/common/windows/getline.c
|
||||||
src/common/windows/com.c
|
src/common/windows/com.c
|
||||||
|
|||||||
+9
-25
@@ -1,34 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
#include "fastfetch.h"
|
#include "fastfetch.h"
|
||||||
#include "common/time.h"
|
#include "common/time.h"
|
||||||
|
|
||||||
[[gnu::nonnull(1), gnu::pure, nodiscard]] static inline const char* ffFindFileName(const char* file) {
|
[[gnu::nonnull(1, 3), gnu::format(printf, 3, 4)]]
|
||||||
const char* lastSlash = __builtin_strrchr(file, '/');
|
void ffDebugPrint(const char* file, int line, const char* format, ...);
|
||||||
#ifdef _WIN32
|
|
||||||
if (lastSlash == nullptr) {
|
|
||||||
lastSlash = __builtin_strrchr(file, '\\');
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (lastSlash != nullptr) {
|
|
||||||
return lastSlash + 1;
|
|
||||||
}
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#define FF_DEBUG(format, ...) ffDebugPrint(__FILE__, __LINE__, format, ##__VA_ARGS__)
|
||||||
#define FF_DEBUG_PRINT(file_, line_, format_, ...) \
|
|
||||||
do { \
|
|
||||||
if (instance.config.display.debugMode) \
|
|
||||||
fprintf(stderr, "[%s%4d, %s] " format_ "\n", ffFindFileName(file_), line_, ffTimeToTimeStr(ffTimeGetNow()), ##__VA_ARGS__); \
|
|
||||||
} while (0)
|
|
||||||
#else
|
|
||||||
#define FF_DEBUG_PRINT(file_, line_, format_, ...) \
|
|
||||||
do { \
|
|
||||||
} while (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define FF_DEBUG(format, ...) FF_DEBUG_PRINT(__FILE__, __LINE__, format, ##__VA_ARGS__)
|
|
||||||
|
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
const char* ffDebugWin32Error(DWORD errorCode);
|
const char* ffDebugWin32Error(DWORD errorCode);
|
||||||
@@ -36,3 +15,8 @@ const char* ffDebugNtStatus(NTSTATUS status);
|
|||||||
const char* ffDebugConfigRet(unsigned long /*CONFIGRET*/ ret);
|
const char* ffDebugConfigRet(unsigned long /*CONFIGRET*/ ret);
|
||||||
const char* ffDebugHResult(HRESULT hr);
|
const char* ffDebugHResult(HRESULT hr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define FF_DEBUG(format, ...) ((void) 0)
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,4 +1,46 @@
|
|||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
|
#include "common/thread.h"
|
||||||
|
|
||||||
|
[[gnu::nonnull(1), gnu::pure, gnu::always_inline, nodiscard]]
|
||||||
|
static inline const char* ffFindFileName(const char* file) {
|
||||||
|
const char* lastSlash = __builtin_strrchr(file, '/');
|
||||||
|
#ifdef _WIN32
|
||||||
|
if (lastSlash == nullptr) {
|
||||||
|
lastSlash = __builtin_strrchr(file, '\\');
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (lastSlash != nullptr) {
|
||||||
|
return lastSlash + 1;
|
||||||
|
}
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if __GNUC__ && !__clang__
|
||||||
|
[[gnu::optimize("O2")]]
|
||||||
|
#endif
|
||||||
|
void ffDebugPrint(const char* file, int line, const char* format, ...) {
|
||||||
|
if (!instance.config.display.debugMode) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static FFThreadMutex debugMutex = FF_THREAD_MUTEX_INITIALIZER;
|
||||||
|
ffThreadMutexLock(&debugMutex);
|
||||||
|
int errno_ = errno;
|
||||||
|
static char errmsg_[1024];
|
||||||
|
va_list args;
|
||||||
|
va_start(args, format);
|
||||||
|
vsnprintf(errmsg_, sizeof(errmsg_), format, args);
|
||||||
|
va_end(args);
|
||||||
|
fprintf(stderr, "[%s%4d, %s] %s\n", ffFindFileName(file), line, ffTimeToTimeStr(ffTimeGetNow()), errmsg_);
|
||||||
|
errno = errno_;
|
||||||
|
ffThreadMutexUnlock(&debugMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if _WIN32
|
||||||
#include "common/windows/nt.h"
|
#include "common/windows/nt.h"
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
@@ -58,3 +100,6 @@ static inline DWORD HRESULTToWin32Error(HRESULT hr) {
|
|||||||
const char* ffDebugHResult(HRESULT hr) {
|
const char* ffDebugHResult(HRESULT hr) {
|
||||||
return ffDebugWin32Error(HRESULTToWin32Error(hr));
|
return ffDebugWin32Error(HRESULTToWin32Error(hr));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
#define INITGUID
|
#define INITGUID
|
||||||
|
|
||||||
#include "battery.h"
|
#include "battery.h"
|
||||||
#include "common/endian.h"
|
|
||||||
|
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
|
#include "common/endian.h"
|
||||||
#include "common/mallocHelper.h"
|
#include "common/mallocHelper.h"
|
||||||
|
#include "common/windows/nt.h"
|
||||||
#include "common/windows/unicode.h"
|
#include "common/windows/unicode.h"
|
||||||
#include "common/windows/wmi.h"
|
#include "common/windows/wmi.h"
|
||||||
|
|
||||||
|
|||||||
@@ -60,8 +60,7 @@
|
|||||||
snprintf(path, sizeof(path), "/dev/i2c-%d", cache->devices[i]);
|
snprintf(path, sizeof(path), "/dev/i2c-%d", cache->devices[i]);
|
||||||
FF_AUTO_CLOSE_FD int fd = open(path, O_RDWR | O_CLOEXEC);
|
FF_AUTO_CLOSE_FD int fd = open(path, O_RDWR | O_CLOEXEC);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
int error = errno;
|
FF_DEBUG("Brightness DDC/CI: cached bus %d is unavailable (errno=%d: %s)", cache->devices[i], errno, strerror(errno));
|
||||||
FF_DEBUG("Brightness DDC/CI: cached bus %d is unavailable (errno=%d: %s)", cache->devices[i], error, strerror(error));
|
|
||||||
valid = false;
|
valid = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -119,8 +118,7 @@
|
|||||||
|
|
||||||
int ioctlResult = ioctl(fd, I2C_RDWR, &data);
|
int ioctlResult = ioctl(fd, I2C_RDWR, &data);
|
||||||
if (ioctlResult != 1) {
|
if (ioctlResult != 1) {
|
||||||
int error = errno;
|
FF_DEBUG("Brightness DDC/CI: write request failed (fd=%d, result=%d, errno=%d: %s)", fd, ioctlResult, errno, strerror(errno));
|
||||||
FF_DEBUG("Brightness DDC/CI: write request failed (fd=%d, result=%d, errno=%d: %s)", fd, ioctlResult, error, strerror(error));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,8 +129,7 @@
|
|||||||
msg.buf = response;
|
msg.buf = response;
|
||||||
ioctlResult = ioctl(fd, I2C_RDWR, &data);
|
ioctlResult = ioctl(fd, I2C_RDWR, &data);
|
||||||
if (ioctlResult != 1) {
|
if (ioctlResult != 1) {
|
||||||
int error = errno;
|
FF_DEBUG("Brightness DDC/CI: read response failed (fd=%d, result=%d, errno=%d: %s)", fd, ioctlResult, errno, strerror(errno));
|
||||||
FF_DEBUG("Brightness DDC/CI: read response failed (fd=%d, result=%d, errno=%d: %s)", fd, ioctlResult, error, strerror(error));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user