[libcamera-devel] [PATCH v4 5/6] libcamera: internal: log: Report function on asserts
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Wed Apr 21 00:05:44 CEST 2021
Hi Kieran,
Thank you for the patch.
On Tue, Apr 20, 2021 at 02:07:40PM +0100, Kieran Bingham wrote:
> Report the function which fails an assertion as well as the actual
> assertion.
>
> This now reports as:
>
> [30:08:53.218816270] [226567] FATAL default request.cpp:150 assertion "d" failed in reuse()
> rather than:
> [30:11:05.271888926] [228531] FATAL default request.cpp:150 assertion "d" failed
>
> Signed-off-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
>
> ---
> We could use __PRETTY_FUNCTION__ instead to get:
> [30:17:16.736265045] [232054] FATAL default request.cpp:150 assertion "d" failed in void libcamera::Request::reuse(libcamera::Request::ReuseFlag)
Is this feature useful for an ASSERT() only, or should we print the
function name in all log messages ? The short function name has limited
value, while the pretty function name is likely too long :-S
Given that debugging an assertion failure involves open the source
anyway, I wonder if there's an actual value in printing the function
name as we have the file name and line number.
> include/libcamera/internal/log.h | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/include/libcamera/internal/log.h b/include/libcamera/internal/log.h
> index be0bab3c1272..b66bf55bc57d 100644
> --- a/include/libcamera/internal/log.h
> +++ b/include/libcamera/internal/log.h
> @@ -117,9 +117,10 @@ LogMessage _log(const LogCategory *category, LogSeverity severity,
> #endif /* __DOXYGEN__ */
>
> #ifndef NDEBUG
> -#define ASSERT(condition) static_cast<void>(({ \
> - if (!(condition)) \
> - LOG(Fatal) << "assertion \"" #condition "\" failed"; \
> +#define ASSERT(condition) static_cast<void>(({ \
> + if (!(condition)) \
> + LOG(Fatal) << "assertion \"" #condition "\" failed in " \
> + << __func__ << "()"; \
> }))
> #else
> #define ASSERT(condition) static_cast<void>(false && (condition))
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list