intel/tools: refactor logging to be easier to follow by static analyzers
Refactor out the part of fail_if function that never returns into NORETURN function and put the condition check outside. Addresses many false positive warnings by Coverity. Signed-off-by: Marcin Ślusarz <marcin.slusarz@intel.com> Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7449>
This commit is contained in:
parent
f0061277c0
commit
c323d7c2a7
|
@ -56,20 +56,7 @@ static void mem_trace_memory_write_header_out(struct aub_file *aub, uint64_t add
|
||||||
uint32_t len, uint32_t addr_space,
|
uint32_t len, uint32_t addr_space,
|
||||||
const char *desc);
|
const char *desc);
|
||||||
|
|
||||||
static void __attribute__ ((format(__printf__, 2, 3)))
|
#define fail_if(cond, ...) _fail_if(cond, NULL, __VA_ARGS__)
|
||||||
fail_if(int cond, const char *format, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
|
|
||||||
if (!cond)
|
|
||||||
return;
|
|
||||||
|
|
||||||
va_start(args, format);
|
|
||||||
vfprintf(stderr, format, args);
|
|
||||||
va_end(args);
|
|
||||||
|
|
||||||
raise(SIGTRAP);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint32_t
|
static inline uint32_t
|
||||||
align_u32(uint32_t v, uint32_t a)
|
align_u32(uint32_t v, uint32_t a)
|
||||||
|
|
|
@ -25,8 +25,10 @@
|
||||||
#ifndef INTEL_AUB_WRITE
|
#ifndef INTEL_AUB_WRITE
|
||||||
#define INTEL_AUB_WRITE
|
#define INTEL_AUB_WRITE
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "drm-uapi/i915_drm.h"
|
#include "drm-uapi/i915_drm.h"
|
||||||
|
|
||||||
|
@ -37,6 +39,25 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static inline void PRINTFLIKE(2, 3) NORETURN
|
||||||
|
_fail(const char *prefix, const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
|
||||||
|
va_start(args, format);
|
||||||
|
if (prefix)
|
||||||
|
fprintf(stderr, "%s: ", prefix);
|
||||||
|
vfprintf(stderr, format, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
#define _fail_if(cond, prefix, ...) do { \
|
||||||
|
if (cond) \
|
||||||
|
_fail(prefix, __VA_ARGS__); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#define MAX_CONTEXT_COUNT 64
|
#define MAX_CONTEXT_COUNT 64
|
||||||
|
|
||||||
struct aub_ppgtt_table {
|
struct aub_ppgtt_table {
|
||||||
|
|
|
@ -38,20 +38,7 @@
|
||||||
#include "drm-uapi/i915_drm.h"
|
#include "drm-uapi/i915_drm.h"
|
||||||
#include "intel_aub.h"
|
#include "intel_aub.h"
|
||||||
|
|
||||||
static void __attribute__ ((format(__printf__, 2, 3)))
|
#define fail_if(cond, ...) _fail_if(cond, NULL, __VA_ARGS__)
|
||||||
fail_if(int cond, const char *format, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
|
|
||||||
if (!cond)
|
|
||||||
return;
|
|
||||||
|
|
||||||
va_start(args, format);
|
|
||||||
vfprintf(stderr, format, args);
|
|
||||||
va_end(args);
|
|
||||||
|
|
||||||
raise(SIGTRAP);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define fail(...) fail_if(true, __VA_ARGS__)
|
#define fail(...) fail_if(true, __VA_ARGS__)
|
||||||
|
|
||||||
|
|
|
@ -92,21 +92,7 @@ static struct bo *bos;
|
||||||
#define IS_USERPTR(p) ((uintptr_t) (p) & USERPTR_FLAG)
|
#define IS_USERPTR(p) ((uintptr_t) (p) & USERPTR_FLAG)
|
||||||
#define GET_PTR(p) ( (void *) ((uintptr_t) p & ~(uintptr_t) 1) )
|
#define GET_PTR(p) ( (void *) ((uintptr_t) p & ~(uintptr_t) 1) )
|
||||||
|
|
||||||
static void __attribute__ ((format(__printf__, 2, 3)))
|
#define fail_if(cond, ...) _fail_if(cond, "intel_dump_gpu", __VA_ARGS__)
|
||||||
fail_if(int cond, const char *format, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
|
|
||||||
if (!cond)
|
|
||||||
return;
|
|
||||||
|
|
||||||
va_start(args, format);
|
|
||||||
fprintf(stderr, "intel_dump_gpu: ");
|
|
||||||
vfprintf(stderr, format, args);
|
|
||||||
va_end(args);
|
|
||||||
|
|
||||||
raise(SIGTRAP);
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct bo *
|
static struct bo *
|
||||||
get_bo(unsigned fd, uint32_t handle)
|
get_bo(unsigned fd, uint32_t handle)
|
||||||
|
|
Loading…
Reference in New Issue