mirror of
https://github.com/linux-can/can-utils.git
synced 2026-08-05 06:20:00 +02:00
lib: add pr_debug() macro
Add the pr_debug() macro so that:
#ifdef DEBUG
printf("foo");
#endif
can be replaced by:
pr_debug("foo");
Apply the pr_debug() macro wherever relevant.
Currently, there is no consensus whether debug messages should be
printed on stdout or stderr. Most of the modules: canbusload.c,
candump.c and canlogserver.c use stdout but
mcp251xfd/mcp251xfd-dev-coredump.c uses stderr. Harmonize the behavior
by following the major trend and make
mcp251xfd/mcp251xfd-dev-coredump.c also output to stdout.
slcanpty.c does a #define DEBUG, meaning that debug is always turned
on for this file. Remove this and make debug an option like every
other files.
Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://lore.kernel.org/all/20221114163848.3398-5-mailhol.vincent@wanadoo.fr
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
This commit is contained in:
committed by
Marc Kleine-Budde
parent
21fb43532e
commit
0cfd56d613
@@ -46,6 +46,7 @@ MAKEFLAGS := -k
|
|||||||
CFLAGS := -O2 -Wall -Wno-parentheses
|
CFLAGS := -O2 -Wall -Wno-parentheses
|
||||||
|
|
||||||
CPPFLAGS += \
|
CPPFLAGS += \
|
||||||
|
-I. \
|
||||||
-Iinclude \
|
-Iinclude \
|
||||||
-DAF_CAN=PF_CAN \
|
-DAF_CAN=PF_CAN \
|
||||||
-DPF_CAN=29 \
|
-DPF_CAN=29 \
|
||||||
|
|||||||
+3
-6
@@ -61,6 +61,7 @@
|
|||||||
#include <linux/can.h>
|
#include <linux/can.h>
|
||||||
#include <linux/can/raw.h>
|
#include <linux/can/raw.h>
|
||||||
|
|
||||||
|
#include "lib.h"
|
||||||
#include "terminal.h"
|
#include "terminal.h"
|
||||||
#include "canframelen.h"
|
#include "canframelen.h"
|
||||||
|
|
||||||
@@ -310,9 +311,7 @@ int main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
pr_debug("open %d '%s'.\n", i, ptr);
|
||||||
printf("open %d '%s'.\n", i, ptr);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
s[i] = socket(PF_CAN, SOCK_RAW, CAN_RAW);
|
s[i] = socket(PF_CAN, SOCK_RAW, CAN_RAW);
|
||||||
if (s[i] < 0) {
|
if (s[i] < 0) {
|
||||||
@@ -358,10 +357,8 @@ int main(int argc, char **argv)
|
|||||||
if (nbytes > max_bitrate_len)
|
if (nbytes > max_bitrate_len)
|
||||||
max_bitrate_len = nbytes; /* for nice printing */
|
max_bitrate_len = nbytes; /* for nice printing */
|
||||||
|
|
||||||
|
pr_debug("using interface name '%s'.\n", ifr.ifr_name);
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
printf("using interface name '%s'.\n", ifr.ifr_name);
|
|
||||||
#endif
|
|
||||||
/* try to switch the socket into CAN FD mode */
|
/* try to switch the socket into CAN FD mode */
|
||||||
const int canfd_on = 1;
|
const int canfd_on = 1;
|
||||||
setsockopt(s[i], SOL_CAN_RAW, CAN_RAW_FD_FRAMES, &canfd_on, sizeof(canfd_on));
|
setsockopt(s[i], SOL_CAN_RAW, CAN_RAW_FD_FRAMES, &canfd_on, sizeof(canfd_on));
|
||||||
|
|||||||
@@ -216,9 +216,7 @@ static int idx2dindex(int ifidx, int socket)
|
|||||||
|
|
||||||
strcpy(devname[i], ifr.ifr_name);
|
strcpy(devname[i], ifr.ifr_name);
|
||||||
|
|
||||||
#ifdef DEBUG
|
pr_debug("new index %d (%s)\n", i, devname[i]);
|
||||||
printf("new index %d (%s)\n", i, devname[i]);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@@ -477,9 +475,7 @@ int main(int argc, char **argv)
|
|||||||
ptr = argv[optind+i];
|
ptr = argv[optind+i];
|
||||||
nptr = strchr(ptr, ',');
|
nptr = strchr(ptr, ',');
|
||||||
|
|
||||||
#ifdef DEBUG
|
pr_debug("open %d '%s'.\n", i, ptr);
|
||||||
printf("open %d '%s'.\n", i, ptr);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
obj->s = socket(PF_CAN, SOCK_RAW, CAN_RAW);
|
obj->s = socket(PF_CAN, SOCK_RAW, CAN_RAW);
|
||||||
if (obj->s < 0) {
|
if (obj->s < 0) {
|
||||||
@@ -513,9 +509,7 @@ int main(int argc, char **argv)
|
|||||||
memset(&ifr.ifr_name, 0, sizeof(ifr.ifr_name));
|
memset(&ifr.ifr_name, 0, sizeof(ifr.ifr_name));
|
||||||
strncpy(ifr.ifr_name, ptr, nbytes);
|
strncpy(ifr.ifr_name, ptr, nbytes);
|
||||||
|
|
||||||
#ifdef DEBUG
|
pr_debug("using interface name '%s'.\n", ifr.ifr_name);
|
||||||
printf("using interface name '%s'.\n", ifr.ifr_name);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (strcmp(ANYDEV, ifr.ifr_name) != 0) {
|
if (strcmp(ANYDEV, ifr.ifr_name) != 0) {
|
||||||
if (ioctl(obj->s, SIOCGIFINDEX, &ifr) < 0) {
|
if (ioctl(obj->s, SIOCGIFINDEX, &ifr) < 0) {
|
||||||
@@ -605,9 +599,7 @@ int main(int argc, char **argv)
|
|||||||
/* try SO_RCVBUFFORCE first, if we run with CAP_NET_ADMIN */
|
/* try SO_RCVBUFFORCE first, if we run with CAP_NET_ADMIN */
|
||||||
if (setsockopt(obj->s, SOL_SOCKET, SO_RCVBUFFORCE,
|
if (setsockopt(obj->s, SOL_SOCKET, SO_RCVBUFFORCE,
|
||||||
&rcvbuf_size, sizeof(rcvbuf_size)) < 0) {
|
&rcvbuf_size, sizeof(rcvbuf_size)) < 0) {
|
||||||
#ifdef DEBUG
|
pr_debug("SO_RCVBUFFORCE failed so try SO_RCVBUF ...\n");
|
||||||
printf("SO_RCVBUFFORCE failed so try SO_RCVBUF ...\n");
|
|
||||||
#endif
|
|
||||||
if (setsockopt(obj->s, SOL_SOCKET, SO_RCVBUF,
|
if (setsockopt(obj->s, SOL_SOCKET, SO_RCVBUF,
|
||||||
&rcvbuf_size, sizeof(rcvbuf_size)) < 0) {
|
&rcvbuf_size, sizeof(rcvbuf_size)) < 0) {
|
||||||
perror("setsockopt SO_RCVBUF");
|
perror("setsockopt SO_RCVBUF");
|
||||||
|
|||||||
+4
-8
@@ -145,9 +145,7 @@ int idx2dindex(int ifidx, int socket)
|
|||||||
|
|
||||||
strcpy(devname[i], ifr.ifr_name);
|
strcpy(devname[i], ifr.ifr_name);
|
||||||
|
|
||||||
#ifdef DEBUG
|
pr_debug("new index %d (%s)\n", i, devname[i]);
|
||||||
printf("new index %d (%s)\n", i, devname[i]);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@@ -310,11 +308,9 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
for (i=0; i<currmax; i++) {
|
for (i=0; i<currmax; i++) {
|
||||||
|
|
||||||
#ifdef DEBUG
|
pr_debug("open %d '%s' m%08X v%08X i%d e%d.\n",
|
||||||
printf("open %d '%s' m%08X v%08X i%d e%d.\n",
|
i, argv[optind+i], mask[i], value[i],
|
||||||
i, argv[optind+i], mask[i], value[i],
|
inv_filter[i], err_mask[i]);
|
||||||
inv_filter[i], err_mask[i]);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if ((s[i] = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
|
if ((s[i] = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
|
||||||
perror("socket");
|
perror("socket");
|
||||||
|
|||||||
@@ -47,6 +47,13 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
#define pr_debug(fmt, args...) printf(fmt, ##args)
|
||||||
|
#else
|
||||||
|
__attribute__((format (printf, 1, 2)))
|
||||||
|
static inline int pr_debug(const char* fmt, ...) {return 0;}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* buffer sizes for CAN frame string representations */
|
/* buffer sizes for CAN frame string representations */
|
||||||
|
|
||||||
#define CL_ID (sizeof("12345678##1"))
|
#define CL_ID (sizeof("12345678##1"))
|
||||||
|
|||||||
@@ -17,18 +17,10 @@
|
|||||||
|
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
|
|
||||||
|
#include "lib.h"
|
||||||
#include "mcp251xfd.h"
|
#include "mcp251xfd.h"
|
||||||
#include "mcp251xfd-dump-userspace.h"
|
#include "mcp251xfd-dump-userspace.h"
|
||||||
|
|
||||||
#define pr_err(fmt, args...) fprintf(stderr, fmt, ##args)
|
|
||||||
#define pr_no(fmt, args...) while (0) { fprintf(stdout, fmt, ##args); }
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
#define pr_debug(fmt, args...) pr_err(fmt, ##args)
|
|
||||||
#else
|
|
||||||
#define pr_debug(fmt, args...) pr_no(fmt, ##args)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
struct mcp251xfd_dump_iter {
|
struct mcp251xfd_dump_iter {
|
||||||
const void *start;
|
const void *start;
|
||||||
|
|||||||
+3
-7
@@ -49,8 +49,6 @@
|
|||||||
#define SLC_MTU (sizeof("T1111222281122334455667788EA5F\r")+1)
|
#define SLC_MTU (sizeof("T1111222281122334455667788EA5F\r")+1)
|
||||||
#define DEVICE_NAME_PTMX "/dev/ptmx"
|
#define DEVICE_NAME_PTMX "/dev/ptmx"
|
||||||
|
|
||||||
#define DEBUG
|
|
||||||
|
|
||||||
/* read data from pty, send CAN frames to CAN socket and answer commands */
|
/* read data from pty, send CAN frames to CAN socket and answer commands */
|
||||||
int pty2can(int pty, int socket, struct can_filter *fi,
|
int pty2can(int pty, int socket, struct can_filter *fi,
|
||||||
int *is_open, int *tstamp)
|
int *is_open, int *tstamp)
|
||||||
@@ -106,14 +104,12 @@ rx_restart:
|
|||||||
cmd = buf[0];
|
cmd = buf[0];
|
||||||
buf[nbytes] = 0;
|
buf[nbytes] = 0;
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
for (tmp = 0; tmp < nbytes; tmp++)
|
for (tmp = 0; tmp < nbytes; tmp++)
|
||||||
if (buf[tmp] == '\r')
|
if (buf[tmp] == '\r')
|
||||||
putchar('@');
|
pr_debug("@");
|
||||||
else
|
else
|
||||||
putchar(buf[tmp]);
|
pr_debug("%c", buf[tmp]);
|
||||||
printf("\n");
|
pr_debug("\n");
|
||||||
#endif
|
|
||||||
|
|
||||||
/* check for filter configuration commands */
|
/* check for filter configuration commands */
|
||||||
if (cmd == 'm' || cmd == 'M') {
|
if (cmd == 'm' || cmd == 'M') {
|
||||||
|
|||||||
Reference in New Issue
Block a user