From patchwork Thu May 7 13:50:19 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 26676 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 5A94DC32F6 for ; Thu, 7 May 2026 13:50:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D6BFF63022; Thu, 7 May 2026 15:50:25 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Rp++ssbl"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 48D0F62FE1 for ; Thu, 7 May 2026 15:50:23 +0200 (CEST) Received: from pb-laptop.local (185.221.140.217.nat.pool.zt.hu [185.221.140.217]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3381AB63 for ; Thu, 7 May 2026 15:50:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1778161819; bh=sGI/a0lFvnPtfKM87kQIP6yxhvAg5n9A8DchwYDg6GY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Rp++ssblMngR/4Jnp+xIQT644CqlXVmTehvVuFwtlqWtAXQkaEyDjomt9sZlE7oHa TyLVKsXTyUVOmZHwS/HB3us5kUZhVxy42jLxhp8y9YXx0WyRqk+FfqoksTvX91NXOa kueA+E6KkODYHG7yZVzwIA+4BCDYB3po/SobpAig= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [PATCH v1 2/2] libcamera: base: log: Move abort logic into separate type Date: Thu, 7 May 2026 15:50:19 +0200 Message-ID: <20260507135019.231615-2-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260507135019.231615-1-barnabas.pocze@ideasonboard.com> References: <20260507135019.231615-1-barnabas.pocze@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a `LogMessageAbortGuard` type that is templated on the severity of the log message. If it is not fatal, the type is empty and does nothing. However, if it is `LogFatal`, then its destructor will print the backtrace and abort. This type is instantiated for each log message and takes care of aborting the processing if necessary. This allows the removal of the abort logic from `~LogMessage()` and also makes it visible to static analysis tools that execution will not proceed beyond a `Fatal` message. Signed-off-by: Barnabás Pőcze Reviewed-by: Laurent Pinchart --- include/libcamera/base/log.h | 16 +++++++++++++++- src/libcamera/base/log.cpp | 16 +++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/include/libcamera/base/log.h b/include/libcamera/base/log.h index 5cb14311e..7bd43a423 100644 --- a/include/libcamera/base/log.h +++ b/include/libcamera/base/log.h @@ -88,6 +88,19 @@ private: std::string prefix_; }; +#ifndef __DOXYGEN__ +template +struct LogMessageAbortGuard { +}; + +template<> +struct LogMessageAbortGuard { + LogMessageAbortGuard() = default; + LIBCAMERA_DISABLE_COPY_AND_MOVE(LogMessageAbortGuard) + [[noreturn]] ~LogMessageAbortGuard(); +}; +#endif + class Loggable { public: @@ -124,7 +137,8 @@ constexpr int isLogSeverityEnabled(const LogCategory &category) switch (const auto &_logCategory = (cat); \ isLogSeverityEnabled(_logCategory)) \ case 1: \ - _log(_logCategory, Log##sev).stream() + (LogMessageAbortGuard(), \ + _log(_logCategory, Log##sev).stream()) #define _LOG1(severity) \ _LOG(LogCategory::defaultCategory(), severity) diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp index 0921e5485..3404471fc 100644 --- a/src/libcamera/base/log.cpp +++ b/src/libcamera/base/log.cpp @@ -869,11 +869,6 @@ LogMessage::~LogMessage() msgStream_ << std::endl; logger->write(*this); - - if (severity_ == LogSeverity::LogFatal) { - logger->backtrace(); - std::abort(); - } } /** @@ -922,6 +917,17 @@ LogMessage::~LogMessage() * \return The message text of the message, as a string */ +#ifndef __DOXYGEN__ +LogMessageAbortGuard::~LogMessageAbortGuard() +{ + Logger *logger = Logger::instance(); + if (logger) + logger->backtrace(); + + std::abort(); +} +#endif + /** * \class Loggable * \brief Base class to support log message extensions