Add debug trunc flags for parsing and message

This commit is contained in:
Olof hagsand 2025-02-17 09:05:37 +01:00
parent 7394958453
commit 9df084958e
12 changed files with 61 additions and 26 deletions

View file

@ -85,6 +85,11 @@
#define CLIXON_DBG_APP3 0x00400000 /* External application 3 */
#define CLIXON_DBG_SMASK 0x00ffffff /* Subject mask */
/* Misc */
#define CLIXON_DBG_TRUNC 0x10000000 /* Explicit truncate debug message.
* Note Implicit: log_string_limit overrides
*/
/*
* Macros
*/

View file

@ -257,6 +257,8 @@ clixon_debug_fn(clixon_handle h,
/* Truncate long debug strings */
if ((trunc = clixon_log_string_limit_get()) && trunc < cbuf_len(cb))
cbuf_trunc(cb, trunc);
else if ((dbglevel & CLIXON_DBG_TRUNC) && 80 < cbuf_len(cb))
cbuf_trunc(cb, 80);
clixon_log_str(LOG_DEBUG, cbuf_get(cb));
ok:
retval = 0;

View file

@ -1455,7 +1455,10 @@ _json_parse(char *str,
int i;
int failed = 0; /* yang assignment */
clixon_debug(CLIXON_DBG_PARSE, "%s", str);
if (clixon_debug_get() & CLIXON_DBG_DETAIL)
clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL, "%s", str);
else
clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_TRUNC, "%s", str);
jy.jy_parse_string = str;
jy.jy_linenum = 1;
jy.jy_current = xt;
@ -1541,7 +1544,7 @@ _json_parse(char *str,
goto done;
retval = 1;
done:
clixon_debug(CLIXON_DBG_PARSE, "retval:%d", retval);
clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL, "retval:%d", retval);
if (cberr)
cbuf_free(cberr);
json_parse_exit(&jy);

View file

@ -240,6 +240,8 @@ clixon_logflags_set(uint16_t flags)
}
/*! Truncate log/debug string length
*
* @see CLICON_LOG_STRING_LIMIT option
*/
int
clixon_log_string_limit_set(size_t sz)

View file

@ -2299,7 +2299,7 @@ netconf_output(int s,
if (clixon_debug_detail())
clixon_debug(CLIXON_DBG_MSG | CLIXON_DBG_DETAIL, "Send ext: %s", cbuf_get(cb));
else
clixon_debug(CLIXON_DBG_MSG, "Send ext len: %lu", cbuf_len(cb));
clixon_debug(CLIXON_DBG_MSG | CLIXON_DBG_TRUNC, "Send ext: %s", cbuf_get(cb));
#if 0 // Extra sanity check for debugging
{
cxobj *xt = NULL;

View file

@ -132,7 +132,10 @@ api_path_parse(char *api_path,
int retval = -1;
clixon_api_path_yacc ay = {0,};
clixon_debug(CLIXON_DBG_PARSE, "%s", api_path);
if (clixon_debug_get() & CLIXON_DBG_DETAIL)
clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL, "%s", api_path);
else
clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_TRUNC, "%s", api_path);
ay.ay_parse_string = api_path;
ay.ay_name = "api-path parser";
ay.ay_linenum = 1;
@ -151,7 +154,7 @@ api_path_parse(char *api_path,
*cplist = ay.ay_top;
retval = 0;
done:
clixon_debug(CLIXON_DBG_PARSE, "retval: %d", retval);
clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL, "retval: %d", retval);
return retval;
}
@ -178,7 +181,10 @@ instance_id_parse(char *path,
int retval = -1;
clixon_instance_id_yacc iy = {0,};
clixon_debug(CLIXON_DBG_PARSE, "%s", path);
if (clixon_debug_get() & CLIXON_DBG_DETAIL)
clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL, "%s", path);
else
clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_TRUNC, "%s", path);
iy.iy_parse_string = path;
iy.iy_name = "instance-id parser";
iy.iy_linenum = 1;
@ -197,7 +203,7 @@ instance_id_parse(char *path,
*cplist = iy.iy_top;
retval = 0;
done:
clixon_debug(CLIXON_DBG_PARSE, "retval: %d", retval);
clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL, "retval: %d", retval);
return retval;
}

View file

@ -357,13 +357,13 @@ clixon_msg_send(int s,
if (clixon_debug_detail())
clixon_debug(CLIXON_DBG_MSG | CLIXON_DBG_DETAIL, "Send [%s] %s", descr, cbuf_get(cb));
else
clixon_debug(CLIXON_DBG_MSG, "Send [%s] len: %lu", descr, cbuf_len(cb));
clixon_debug(CLIXON_DBG_MSG | CLIXON_DBG_TRUNC, "Send [%s] %s", descr, cbuf_get(cb));
}
else{
if (clixon_debug_detail())
clixon_debug(CLIXON_DBG_MSG | CLIXON_DBG_DETAIL, "Send %s", cbuf_get(cb));
else
clixon_debug(CLIXON_DBG_MSG, "Send len: %lu", cbuf_len(cb));
clixon_debug(CLIXON_DBG_MSG | CLIXON_DBG_TRUNC, "Send %s", cbuf_get(cb));
}
if (atomicio((ssize_t (*)(int, void *, size_t))write,
@ -440,13 +440,13 @@ clixon_msg_rcv10(int s,
if (clixon_debug_detail())
clixon_debug(CLIXON_DBG_MSG | CLIXON_DBG_DETAIL, "Recv [%s]: %s", descr, cbuf_get(cb));
else
clixon_debug(CLIXON_DBG_MSG, "Recv [%s] len: %lu", descr, cbuf_len(cb));
clixon_debug(CLIXON_DBG_MSG | CLIXON_DBG_TRUNC, "Recv [%s]: %s", descr, cbuf_get(cb));
}
else{
if (clixon_debug_detail())
clixon_debug(CLIXON_DBG_MSG | CLIXON_DBG_DETAIL, "Recv: %s", cbuf_get(cb));
else
clixon_debug(CLIXON_DBG_MSG, "Recv len: %lu", cbuf_len(cb));
clixon_debug(CLIXON_DBG_MSG | CLIXON_DBG_TRUNC, "Recv: %s", cbuf_get(cb));
}
}
@ -622,14 +622,13 @@ clixon_msg_rcv11(int s,
if (clixon_debug_detail())
clixon_debug(CLIXON_DBG_MSG | CLIXON_DBG_DETAIL, "Recv [%s]: %s", descr, cbuf_get(cbmsg));
else
clixon_debug(CLIXON_DBG_MSG, "Recv [%s] len: %lu", descr, cbuf_len(cbmsg));
clixon_debug(CLIXON_DBG_MSG | CLIXON_DBG_TRUNC, "Recv [%s]: %s", descr, cbuf_get(cbmsg));
}
else{
if (clixon_debug_detail())
clixon_debug(CLIXON_DBG_MSG | CLIXON_DBG_DETAIL, "Recv: %s", cbuf_get(cbmsg));
else
clixon_debug(CLIXON_DBG_MSG, "Recv len: %lu", cbuf_len(cbmsg));
clixon_debug(CLIXON_DBG_MSG | CLIXON_DBG_TRUNC, "Recv: %s", cbuf_get(cbmsg));
}
}

View file

@ -1011,7 +1011,10 @@ _text_syntax_parse(char *str,
int failed = 0; /* yang assignment */
cxobj *xc;
clixon_debug(CLIXON_DBG_PARSE, "%s", str);
if (clixon_debug_get() & CLIXON_DBG_DETAIL)
clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL, "%s", str);
else
clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_TRUNC, "%s", str);
if (yb != YB_MODULE && yb != YB_MODULE_NEXT){
clixon_err(OE_YANG, EINVAL, "yb must be YB_MODULE or YB_MODULE_NEXT");
return -1;
@ -1068,7 +1071,7 @@ _text_syntax_parse(char *str,
goto done;
retval = 1;
done:
clixon_debug(CLIXON_DBG_PARSE, "retval:%d", retval);
clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL, "retval:%d", retval);
if (cberr)
cbuf_free(cberr);
clixon_text_syntax_parsel_exit(&ts);

View file

@ -873,7 +873,10 @@ _xml_parse(const char *str,
int failed = 0; /* yang assignment */
int i;
clixon_debug(CLIXON_DBG_PARSE, "%s", str);
if (clixon_debug_get() & CLIXON_DBG_DETAIL)
clixon_debug(CLIXON_DBG_PARSE | CLIXON_DBG_DETAIL, "%s", str);
else
clixon_debug(CLIXON_DBG_PARSE & CLIXON_DBG_TRUNC, "%s", str);
if (strlen(str) == 0){
return 1; /* OK */
}
@ -951,7 +954,7 @@ _xml_parse(const char *str,
goto done;
retval = 1;
done:
clixon_debug(CLIXON_DBG_PARSE, "retval:%d", retval);
clixon_debug(CLIXON_DBG_PARSE | CLIXON_DBG_DETAIL, "retval:%d", retval);
clixon_xml_parsel_exit(&xy);
if (xy.xy_parse_string != NULL)
free(xy.xy_parse_string);

View file

@ -561,7 +561,10 @@ xpath_parse(const char *xpath,
clixon_xpath_yacc xpy = {0,};
cbuf *cb = NULL;
clixon_debug(CLIXON_DBG_PARSE, "%s", xpath);
if (clixon_debug_get() & CLIXON_DBG_DETAIL)
clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL, "%s", xpath);
else
clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_TRUNC, "%s", xpath);
if (xpath == NULL){
clixon_err(OE_XML, EINVAL, "XPath is NULL");
goto done;
@ -596,7 +599,7 @@ xpath_parse(const char *xpath,
}
retval = 0;
done:
clixon_debug(CLIXON_DBG_PARSE, "retval:%d", retval);
clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL, "retval:%d", retval);
if (cb)
cbuf_free(cb);
if (xpy.xpy_top)

View file

@ -866,7 +866,10 @@ yang_parse_str(char *str,
clixon_yang_yacc yy = {0,};
yang_stmt *ymod = NULL;
clixon_debug(CLIXON_DBG_PARSE, "%s", str);
if (clixon_debug_get() & CLIXON_DBG_DETAIL)
clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL, "%s", str);
else
clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_TRUNC, "%s", str);
if (yspec == NULL){
clixon_err(OE_YANG, 0, "Yang parse need top level yang spec");
goto done;
@ -907,7 +910,7 @@ yang_parse_str(char *str,
yspec_nscache_clear(yspec);
#endif
done:
clixon_debug(CLIXON_DBG_PARSE, "retval:%p", ymod);
clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL, "retval:%p", ymod);
ystack_pop(&yy);
if (yy.yy_stack)
free (yy.yy_stack);

View file

@ -83,7 +83,10 @@ yang_subparse(clixon_handle h,
int retval = -1;
clixon_yang_sub_parse_yacc ife = {0,};
clixon_debug(CLIXON_DBG_PARSE, "%s", str);
if (clixon_debug_get() & CLIXON_DBG_DETAIL)
clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL, "%s", str);
else
clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_TRUNC, "%s", str);
ife.if_parse_string = str;
ife.if_linenum = linenum;
if (enabled)
@ -102,7 +105,7 @@ yang_subparse(clixon_handle h,
*enabled = ife.if_enabled;
retval = 0;
done:
clixon_debug(CLIXON_DBG_PARSE, "retval:%d", retval);
clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL, "retval:%d", retval);
clixon_yang_sub_parsel_exit(&ife);
return retval;
}
@ -126,7 +129,10 @@ yang_schema_nodeid_subparse(char *str,
int retval = -1;
clixon_yang_schemanode_yacc ife = {0,};
clixon_debug(CLIXON_DBG_PARSE | CLIXON_DBG_DETAIL, "%s", str);
if (clixon_debug_get() & CLIXON_DBG_DETAIL)
clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL, "%s", str);
else
clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_TRUNC, "%s", str);
ife.if_parse_string = str;
ife.if_linenum = linenum;
ife.if_mainfile = mainfile;
@ -140,7 +146,7 @@ yang_schema_nodeid_subparse(char *str,
}
retval = 0;
done:
clixon_debug(CLIXON_DBG_PARSE | CLIXON_DBG_DETAIL, "retval:%d", retval);
clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL, "retval:%d", retval);
clixon_yang_schemanode_parsel_exit(&ife);
return retval;
}