Commit d171e18c authored by frtabu's avatar frtabu

fix some cppcheck errors and warnings in config module and T Tracer

parent 974167b5
...@@ -171,7 +171,7 @@ int config_check_unknown_cmdlineopt(char *prefix) { ...@@ -171,7 +171,7 @@ int config_check_unknown_cmdlineopt(char *prefix) {
if (strcmp(prefix,CONFIG_CHECKALLSECTIONS) == 0) if (strcmp(prefix,CONFIG_CHECKALLSECTIONS) == 0)
finalcheck = 1; finalcheck = 1;
else if (strlen(prefix) > 0) { else if (strlen(prefix) > 0) {
sprintf(testprefix,"--%s.",prefix); sprintf(testprefix,"--%.*s.",CONFIG_MAXOPTLENGTH-1,prefix);
} }
} }
......
...@@ -345,7 +345,7 @@ void free_configmodule(void) { ...@@ -345,7 +345,7 @@ void free_configmodule(void) {
if( cfgptr->cfgmode != NULL) free(cfgptr->cfgmode); if( cfgptr->cfgmode != NULL) free(cfgptr->cfgmode);
printf ("[CONFIG] free %u config parameter pointers\n",cfgptr->num_cfgP); printf ("[CONFIG] free %i config parameter pointers\n",cfgptr->num_cfgP);
for (int i=0; i<cfgptr->num_cfgP; i++) { for (int i=0; i<cfgptr->num_cfgP; i++) {
if ( cfgptr->cfgP[i] != NULL) free(cfgptr->cfgP[i]); if ( cfgptr->cfgP[i] != NULL) free(cfgptr->cfgP[i]);
......
...@@ -202,9 +202,9 @@ void T_init(int remote_port, int wait_for_tracer, int dont_fork) { ...@@ -202,9 +202,9 @@ void T_init(int remote_port, int wait_for_tracer, int dont_fork) {
} }
void T_Config_Init(void) { void T_Config_Init(void) {
int T_port; /* by default we wait for the tracer */ int T_port=TTRACER_DEFAULT_PORTNUM; /* by default we wait for the tracer */
int T_nowait; /* default port to listen to to wait for the tracer */ int T_nowait=0; /* default port to listen to to wait for the tracer */
int T_dont_fork; /* default is to fork, see 'T_init' to understand */ int T_dont_fork=0; /* default is to fork, see 'T_init' to understand */
paramdef_t ttraceparams[] = CMDLINE_TTRACEPARAMS_DESC; paramdef_t ttraceparams[] = CMDLINE_TTRACEPARAMS_DESC;
/* for a cleaner config file, TTracer params should be defined in a /* for a cleaner config file, TTracer params should be defined in a
* specific section... * specific section...
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "T_defs.h" #include "T_defs.h"
#ifdef T_SEND_TIME #ifdef T_SEND_TIME
#include <time.h> #include <time.h>
#endif #endif
/* T message IDs */ /* T message IDs */
...@@ -76,13 +76,13 @@ ...@@ -76,13 +76,13 @@
T_BUFFER_MAX - T_LOCAL_size, T_PUT_printf_deref x); \ T_BUFFER_MAX - T_LOCAL_size, T_PUT_printf_deref x); \
if (T_PUT_len < 0) { \ if (T_PUT_len < 0) { \
printf("%s:%d:%s: you can't read this, or can you?", \ printf("%s:%d:%s: you can't read this, or can you?", \
__FILE__, __LINE__, __FUNCTION__); \ __FILE__, __LINE__, __FUNCTION__); \
abort(); \ abort(); \
} \ } \
if (T_PUT_len >= T_BUFFER_MAX - T_LOCAL_size) { \ if (T_PUT_len >= T_BUFFER_MAX - T_LOCAL_size) { \
printf("%s:%d:%s: cannot put argument %d in T macro, not enough space" \ printf("%s:%d:%s: cannot put argument %d in T macro, not enough space" \
", consider increasing T_BUFFER_MAX (%d)\n", \ ", consider increasing T_BUFFER_MAX (%d)\n", \
__FILE__, __LINE__, __FUNCTION__, argnum, T_BUFFER_MAX); \ __FILE__, __LINE__, __FUNCTION__, argnum, T_BUFFER_MAX); \
abort(); \ abort(); \
} \ } \
T_LOCAL_size += T_PUT_len + 1; \ T_LOCAL_size += T_PUT_len + 1; \
...@@ -97,9 +97,9 @@ struct T_header; ...@@ -97,9 +97,9 @@ struct T_header;
/* T macro tricks */ /* T macro tricks */
extern int T_stdout; extern int T_stdout;
#define TN(...) TN_N(__VA_ARGS__,33,32,31,30,29,28,27,26,25,24,23,22,21,\ #define TN(...) TN_N(__VA_ARGS__,33,32,31,30,29,28,27,26,25,24,23,22,21,\
20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)(__VA_ARGS__) 20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)(__VA_ARGS__)
#define TN_N(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n17,\ #define TN_N(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n17,\
n18,n19,n20,n21,n22,n23,n24,n25,n26,n27,n28,n29,n30,n31,n32,n,...) T##n n18,n19,n20,n21,n22,n23,n24,n25,n26,n27,n28,n29,n30,n31,n32,n,...) T##n
#define T(...) do { if (T_stdout == 0) TN(__VA_ARGS__); } while (0) #define T(...) do { if (T_stdout == 0) TN(__VA_ARGS__); } while (0)
/* type used to send arbitrary buffer data */ /* type used to send arbitrary buffer data */
...@@ -119,30 +119,30 @@ extern int *T_active; ...@@ -119,30 +119,30 @@ extern int *T_active;
*/ */
#if BASIC_SIMULATOR #if BASIC_SIMULATOR
# define T_GET_SLOT \ # define T_GET_SLOT \
do { \ do { \
extern volatile uint64_t T_next_id; \ extern volatile uint64_t T_next_id; \
extern volatile uint64_t T_active_id; \ extern volatile uint64_t T_active_id; \
uint64_t id; \ uint64_t id; \
/* get a ticket */ \ /* get a ticket */ \
id = __sync_fetch_and_add(&T_next_id, 1); \ id = __sync_fetch_and_add(&T_next_id, 1); \
/* wait for our turn */ \ /* wait for our turn */ \
while (id != __sync_fetch_and_add(&T_active_id, 0)) /* busy wait */; \ while (id != __sync_fetch_and_add(&T_active_id, 0)) /* busy wait */; \
/* this is our turn, try to acquire the slot until it's free */ \ /* this is our turn, try to acquire the slot until it's free */ \
do { \ do { \
T_LOCAL_busy = __sync_fetch_and_or(&T_cache[T_LOCAL_slot].busy, 0x01); \ T_LOCAL_busy = __sync_fetch_and_or(&T_cache[T_LOCAL_slot].busy, 0x01); \
if (T_LOCAL_busy & 0x01) usleep(100); \ if (T_LOCAL_busy & 0x01) usleep(100); \
} while (T_LOCAL_busy & 0x01); \ } while (T_LOCAL_busy & 0x01); \
/* check that there are still some tickets */ \ /* check that there are still some tickets */ \
if (__sync_fetch_and_add(&T_active_id, 0) == 0xffffffffffffffff) { \ if (__sync_fetch_and_add(&T_active_id, 0) == 0xffffffffffffffff) { \
printf("T: reached the end of times, bye...\n"); \ printf("T: reached the end of times, bye...\n"); \
abort(); \ abort(); \
} \ } \
/* free our ticket, which signals the next waiter that it's its turn */ \ /* free our ticket, which signals the next waiter that it's its turn */ \
(void)__sync_fetch_and_add(&T_active_id, 1); \ (void)__sync_fetch_and_add(&T_active_id, 1); \
} while (0) } while (0)
#else #else
# define T_GET_SLOT \ # define T_GET_SLOT \
T_LOCAL_busy = __sync_fetch_and_or(&T_cache[T_LOCAL_slot].busy, 0x01); T_LOCAL_busy = __sync_fetch_and_or(&T_cache[T_LOCAL_slot].busy, 0x01);
#endif #endif
/* used at header of Tn, allocates buffer */ /* used at header of Tn, allocates buffer */
...@@ -172,8 +172,8 @@ extern int *T_active; ...@@ -172,8 +172,8 @@ extern int *T_active;
#define T_CHECK_SIZE(len, argnum) \ #define T_CHECK_SIZE(len, argnum) \
if (T_LOCAL_size + (len) > T_BUFFER_MAX) { \ if (T_LOCAL_size + (len) > T_BUFFER_MAX) { \
printf("%s:%d:%s: cannot put argument %d in T macro, not enough space" \ printf("%s:%d:%s: cannot put argument %d in T macro, not enough space" \
", consider increasing T_BUFFER_MAX (%d)\n", \ ", consider increasing T_BUFFER_MAX (%d)\n", \
__FILE__, __LINE__, __FUNCTION__, argnum, T_BUFFER_MAX); \ __FILE__, __LINE__, __FUNCTION__, argnum, T_BUFFER_MAX); \
abort(); \ abort(); \
} }
...@@ -598,20 +598,21 @@ extern int *T_active; ...@@ -598,20 +598,21 @@ extern int *T_active;
#define TTRACER_CONFIG_PREFIX "TTracer" #define TTRACER_CONFIG_PREFIX "TTracer"
/*------------------------------------------------------------------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------------------------------------------------------------------------*/
/* configuration parameters for TTRACE utility */ /* configuration parameters for TTRACE utility */
/* optname helpstr paramflags XXXptr defXXXval type numelt */ /* optname helpstr paramflags XXXptr defXXXval type numelt */
/*------------------------------------------------------------------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------------------------------------------------------------------------*/
#define TTRACER_DEFAULT_PORTNUM 2021
#define CMDLINE_TTRACEPARAMS_DESC { \ #define CMDLINE_TTRACEPARAMS_DESC { \
{"T_port", CONFIG_HLP_TPORT, 0, iptr:&T_port, defintval:2021, TYPE_INT, 0}, \ {"T_port", CONFIG_HLP_TPORT, 0, iptr:&T_port, defintval:TTRACER_DEFAULT_PORTNUM, TYPE_INT, 0},\
{"T_nowait", CONFIG_HLP_NOTWAIT, PARAMFLAG_BOOL, iptr:&T_nowait, defintval:0, TYPE_INT, 0}, \ {"T_nowait", CONFIG_HLP_NOTWAIT, PARAMFLAG_BOOL, iptr:&T_nowait, defintval:0, TYPE_INT, 0},\
{"T_dont_fork", CONFIG_HLP_TNOFORK, PARAMFLAG_BOOL, iptr:&T_dont_fork, defintval:0, TYPE_INT, 0}, \ {"T_dont_fork", CONFIG_HLP_TNOFORK, PARAMFLAG_BOOL, iptr:&T_dont_fork, defintval:0, TYPE_INT, 0},\
{"T_stdout", CONFIG_HLP_STDOUT, PARAMFLAG_BOOL, iptr:&T_stdout, defintval:1, TYPE_INT, 0}, \ {"T_stdout", CONFIG_HLP_STDOUT, PARAMFLAG_BOOL, iptr:&T_stdout, defintval:1, TYPE_INT, 0},\
} }
/* log on stdout */ /* log on stdout */
void T_init(int remote_port, int wait_for_tracer, int dont_fork); void T_init(int remote_port, int wait_for_tracer, int dont_fork);
void T_Config_Init(void); void T_Config_Init(void);
#else /* T_TRACER */ #else /* T_TRACER */
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment