Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better debug macros and iio_info output #1086

Merged
merged 14 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ add_library(iio
context.c
device.c
events.c
library.c
mask.c
scan.c
sort.c
Expand Down Expand Up @@ -169,16 +170,26 @@ option(WITH_EXAMPLES "Build examples" OFF)
option(WITH_UTILS "Build the Libiio utility programs" ON)

if (NOT LOG_LEVEL)
set(LOG_LEVEL Info CACHE STRING "Log level" FORCE)
set(LOG_LEVEL Info CACHE STRING "Default log level" FORCE)
set_property(CACHE LOG_LEVEL PROPERTY STRINGS NoLog Error Warning Info Debug)
endif()

if (NOT MAX_LOG_LEVEL)
set(MAX_LOG_LEVEL Debug CACHE STRING "Maximum log level supported" FORCE)
set_property(CACHE MAX_LOG_LEVEL PROPERTY STRINGS NoLog Error Warning Info Debug)
endif()

set(LEVEL_NoLog 1)
set(LEVEL_Error 2)
set(LEVEL_Warning 3)
set(LEVEL_Info 4)
set(LEVEL_Debug 5)
set(DEFAULT_LOG_LEVEL ${LEVEL_${LOG_LEVEL}})
set(MAX_LOG_LEVEL_VALUE ${LEVEL_${MAX_LOG_LEVEL}})

if (DEFAULT_LOG_LEVEL GREATER MAX_LOG_LEVEL_VALUE)
message(SEND_ERROR "Default log level cannot be more than the maximum log level.")
endif()

if (MSVC)
target_compile_options(iio PRIVATE /Zi /W4 /wd4200 /wd4127 /wd4100)
Expand Down
6 changes: 2 additions & 4 deletions attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ int iio_device_add_attr(struct iio_device *dev,
if (ret < 0)
return ret;

dev_dbg(dev, "Added%s attr \'%s\' to device \'%s\'\n",
attr_type_string[type], name, dev->id);
dev_dbg(dev, "Added%s attr \'%s\'\n", attr_type_string[type], name);
return 0;
}

Expand All @@ -249,8 +248,7 @@ int iio_channel_add_attr(struct iio_channel *chn,
if (ret < 0)
return ret;

chn_dbg(chn, "Added attr \'%s\' (\'%s\') to channel \'%s\'\n",
name, filename, chn->id);
chn_dbg(chn, "Added attr \'%s\' (\'%s\')\n", name, filename);
return 0;
}

Expand Down
3 changes: 3 additions & 0 deletions context.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ static const struct iio_context_params default_params = {
.err = NULL, /* stderr */
.log_level = (enum iio_log_level)DEFAULT_LOG_LEVEL,
.stderr_level = LEVEL_WARNING,
.timestamp_level = LEVEL_DEBUG,
};

const struct iio_context_params *get_default_params(void)
Expand Down Expand Up @@ -459,6 +460,8 @@ struct iio_context * iio_create_context(const struct iio_context_params *params,
params2.log_level = default_params.log_level;
if (!params2.stderr_level)
params2.stderr_level = default_params.stderr_level;
if (!params2.timestamp_level)
params2.timestamp_level = default_params.timestamp_level;

if (!uri) {
uri_dup = iio_getenv("IIOD_REMOTE");
Expand Down
1 change: 1 addition & 0 deletions iio-config.h.cmakein
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#define LOG_LEVEL @LOG_LEVEL@_L
#define DEFAULT_LOG_LEVEL @DEFAULT_LOG_LEVEL@
#define MAX_LOG_LEVEL @MAX_LOG_LEVEL_VALUE@

#define IIO_MODULES_DIR "@IIO_MODULES_DIR@"
#define IIO_LIBRARY_SUFFIX "@CMAKE_SHARED_LIBRARY_SUFFIX@"
Expand Down
3 changes: 3 additions & 0 deletions iio-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ extern const struct iio_backend iio_xml_backend;
extern const struct iio_backend * const iio_backends[];
extern const unsigned int iio_backends_size;

extern uint64_t library_startup_time_us;

ssize_t iio_xml_print_and_sanitized_param(char *ptr, ssize_t len,
const char *before,
const char *param,
Expand All @@ -255,5 +257,6 @@ static inline void iio_update_xml_indexes(ssize_t ret, char **ptr, ssize_t *len,
bool iio_channel_is_hwmon(const char *id);

int iio_block_io(struct iio_block *block);
void libiio_cleanup_xml_backend(void);

#endif /* __IIO_PRIVATE_H__ */
42 changes: 9 additions & 33 deletions iiod/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,23 @@
#ifndef __IIOD_DEBUG_H__
#define __IIOD_DEBUG_H__

#include "../iio-config.h"
#include <iio/iio-debug.h>

#include <stdio.h>
extern struct iio_context_params iiod_params;

#define NoLog_L 0
#define Error_L 1
#define Warning_L 2
#define Info_L 3
#define Debug_L 4

/* -------------------- */

/* Many of these debug printf include a Flawfinder: ignore, this is because,
* according to https://cwe.mitre.org/data/definitions/134.html which describes
* functions that accepts a format string as an argument, but the format
* string originates from an external source. All the IIO_DEBUG, IIO_INFO,
* IIO_WARNING, and IIO_ERRRO functions are called internally from the
* library, have fixed format strings and can not be modified externally.
*/
#define IIO_DEBUG(...) \
do { \
if (LOG_LEVEL >= Debug_L) \
fprintf(stdout, "DEBUG: " __VA_ARGS__); /* Flawfinder: ignore */ \
} while (0)
prm_dbg(&iiod_params, __VA_ARGS__)

#define IIO_INFO(...) \
do { \
if (LOG_LEVEL >= Info_L) \
fprintf(stdout, __VA_ARGS__); /* Flawfinder: ignore */ \
} while (0)
prm_info(&iiod_params, __VA_ARGS__)

#define IIO_WARNING(...) \
do { \
if (LOG_LEVEL >= Warning_L) \
fprintf(stderr, "WARNING: " __VA_ARGS__); /* Flawfinder: ignore */ \
} while (0)
prm_warn(&iiod_params, __VA_ARGS__)

#define IIO_ERROR(...) \
do { \
if (LOG_LEVEL >= Error_L) \
fprintf(stderr, "ERROR: " __VA_ARGS__); /* Flawfinder: ignore */ \
} while (0)
prm_err(&iiod_params, __VA_ARGS__)

#define IIO_PERROR(err, ...) \
prm_perror(&iiod_params, err, __VA_ARGS__)

#endif /* __IIOD_DEBUG_H__ */
Loading
Loading