Debug: Added PARSE debug flag

This commit is contained in:
Olof hagsand 2024-05-15 13:48:19 +02:00
parent 03a9c03b1c
commit c353c6dcab
21 changed files with 45 additions and 31 deletions

View file

@ -109,8 +109,8 @@
* Disable it to stop any calls to clixon_debug. Having it on by default would mean very large debug outputs. * Disable it to stop any calls to clixon_debug. Having it on by default would mean very large debug outputs.
*/ */
#if 0 #if 0
#define _PARSE_DEBUG(s) clixon_debug(1,(s)) #define _PARSE_DEBUG(s) clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL,(s))
#define _PARSE_DEBUG1(s, s1) clixon_debug(1,(s), (s1)) #define _PARSE_DEBUG1(s, s1) clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL,(s), (s1))
#else #else
#define _PARSE_DEBUG(s) #define _PARSE_DEBUG(s)
#define _PARSE_DEBUG1(s, s1) #define _PARSE_DEBUG1(s, s1)

View file

@ -93,7 +93,7 @@ _http1_parse(clixon_handle h,
clixon_http1_yacc hy = {0,}; clixon_http1_yacc hy = {0,};
int ret; int ret;
clixon_debug(CLIXON_DBG_RESTCONF, "\n%s", str); clixon_debug(CLIXON_DBG_PARSE, "%s", str);
if (strlen(str) == 0) if (strlen(str) == 0)
goto ok; goto ok;
hy.hy_parse_string = str; hy.hy_parse_string = str;
@ -122,7 +122,7 @@ _http1_parse(clixon_handle h,
ok: ok:
retval = 0; retval = 0;
done: done:
clixon_debug(CLIXON_DBG_RESTCONF, "retval:%d", retval); clixon_debug(CLIXON_DBG_PARSE, "retval:%d", retval);
return retval; return retval;
} }

View file

@ -103,6 +103,12 @@ Get restconf daemon status:
curl -Ssik -X POST -H "Content-Type: application/yang-data+json" http://localhost/restconf/operations/clixon-lib:process-control -d '{"clixon-lib:input":{"name":"restconf","operation":"status"}}' curl -Ssik -X POST -H "Content-Type: application/yang-data+json" http://localhost/restconf/operations/clixon-lib:process-control -d '{"clixon-lib:input":{"name":"restconf","operation":"status"}}'
``` ```
### Debug parsing
Yacc: Enable _PARSE_DEBUG macro in corresponding yacc file.
Lex: Add -d in Makefile for corresponding lex file.
Run program with -D parse -D detail
### Make your own simplified yang and configuration file. ### Make your own simplified yang and configuration file.
``` ```
cat <<EOF > /tmp/my.yang cat <<EOF > /tmp/my.yang

View file

@ -75,6 +75,7 @@
#define CLIXON_DBG_EVENT 0x00004000 /* Event processing */ #define CLIXON_DBG_EVENT 0x00004000 /* Event processing */
#define CLIXON_DBG_RPC 0x00008000 /* RPC handling */ #define CLIXON_DBG_RPC 0x00008000 /* RPC handling */
#define CLIXON_DBG_STREAM 0x00010000 /* Notification streams */ #define CLIXON_DBG_STREAM 0x00010000 /* Notification streams */
#define CLIXON_DBG_PARSE 0x00020000 /* Parser */
/* External applications */ /* External applications */
#define CLIXON_DBG_APP 0x00100000 /* External application */ #define CLIXON_DBG_APP 0x00100000 /* External application */

View file

@ -121,8 +121,8 @@
* Disable it to stop any calls to clixon_debug. Having it on by default would mean very large debug outputs. * Disable it to stop any calls to clixon_debug. Having it on by default would mean very large debug outputs.
*/ */
#if 0 #if 0
#define _PARSE_DEBUG(s) clixon_debug(1,(s)) #define _PARSE_DEBUG(s) clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL,(s))
#define _PARSE_DEBUG1(s, s1) clixon_debug(1,(s), (s1)) #define _PARSE_DEBUG1(s, s1) clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL,(s), (s1))
#else #else
#define _PARSE_DEBUG(s) #define _PARSE_DEBUG(s)
#define _PARSE_DEBUG1(s, s1) #define _PARSE_DEBUG1(s, s1)

View file

@ -101,6 +101,7 @@ static const map_str2int dbgmap[] = {
{"event", CLIXON_DBG_EVENT}, {"event", CLIXON_DBG_EVENT},
{"rpc", CLIXON_DBG_RPC}, {"rpc", CLIXON_DBG_RPC},
{"stream", CLIXON_DBG_STREAM}, {"stream", CLIXON_DBG_STREAM},
{"parse", CLIXON_DBG_PARSE},
{"app", CLIXON_DBG_APP}, {"app", CLIXON_DBG_APP},
{"app2", CLIXON_DBG_APP2}, {"app2", CLIXON_DBG_APP2},
{"app3", CLIXON_DBG_APP3}, {"app3", CLIXON_DBG_APP3},

View file

@ -129,7 +129,7 @@
/* Enable for debugging, steals some cycles otherwise */ /* Enable for debugging, steals some cycles otherwise */
#if 0 #if 0
#define _PARSE_DEBUG(s) clixon_debug(1,(s)) #define _PARSE_DEBUG(s) clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL,(s))
#else #else
#define _PARSE_DEBUG(s) #define _PARSE_DEBUG(s)
#endif #endif

View file

@ -1451,7 +1451,7 @@ _json_parse(char *str,
int i; int i;
int failed = 0; /* yang assignment */ int failed = 0; /* yang assignment */
clixon_debug(CLIXON_DBG_DEFAULT, "%d %s", yb, str); clixon_debug(CLIXON_DBG_PARSE, "%s", str);
jy.jy_parse_string = str; jy.jy_parse_string = str;
jy.jy_linenum = 1; jy.jy_linenum = 1;
jy.jy_current = xt; jy.jy_current = xt;
@ -1537,7 +1537,7 @@ _json_parse(char *str,
goto done; goto done;
retval = 1; retval = 1;
done: done:
clixon_debug(CLIXON_DBG_DEFAULT, "retval:%d", retval); clixon_debug(CLIXON_DBG_PARSE, "retval:%d", retval);
if (cberr) if (cberr)
cbuf_free(cberr); cbuf_free(cberr);
json_parse_exit(&jy); json_parse_exit(&jy);

View file

@ -139,7 +139,7 @@ object.
/* Enable for debugging, steals some cycles otherwise */ /* Enable for debugging, steals some cycles otherwise */
#if 0 #if 0
#define _PARSE_DEBUG(s) clixon_debug(1,(s)) #define _PARSE_DEBUG(s) clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL,(s))
#else #else
#define _PARSE_DEBUG(s) #define _PARSE_DEBUG(s)
#endif #endif

View file

@ -132,7 +132,7 @@ api_path_parse(char *api_path,
int retval = -1; int retval = -1;
clixon_api_path_yacc ay = {0,}; clixon_api_path_yacc ay = {0,};
clixon_debug(CLIXON_DBG_DEFAULT, "api_path:%s", api_path); clixon_debug(CLIXON_DBG_PARSE, "%s", api_path);
ay.ay_parse_string = api_path; ay.ay_parse_string = api_path;
ay.ay_name = "api-path parser"; ay.ay_name = "api-path parser";
ay.ay_linenum = 1; ay.ay_linenum = 1;
@ -151,6 +151,7 @@ api_path_parse(char *api_path,
*cplist = ay.ay_top; *cplist = ay.ay_top;
retval = 0; retval = 0;
done: done:
clixon_debug(CLIXON_DBG_PARSE, "retval: %d", retval);
return retval; return retval;
} }
@ -177,7 +178,7 @@ instance_id_parse(char *path,
int retval = -1; int retval = -1;
clixon_instance_id_yacc iy = {0,}; clixon_instance_id_yacc iy = {0,};
clixon_debug(CLIXON_DBG_DEFAULT, "path:%s", path); clixon_debug(CLIXON_DBG_PARSE, "%s", path);
iy.iy_parse_string = path; iy.iy_parse_string = path;
iy.iy_name = "instance-id parser"; iy.iy_name = "instance-id parser";
iy.iy_linenum = 1; iy.iy_linenum = 1;
@ -196,6 +197,7 @@ instance_id_parse(char *path,
*cplist = iy.iy_top; *cplist = iy.iy_top;
retval = 0; retval = 0;
done: done:
clixon_debug(CLIXON_DBG_PARSE, "retval: %d", retval);
return retval; return retval;
} }

View file

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

View file

@ -86,7 +86,7 @@
/* Enable for debugging, steals some cycles otherwise */ /* Enable for debugging, steals some cycles otherwise */
#if 0 #if 0
#define _PARSE_DEBUG(s) clixon_debug(1,(s)) #define _PARSE_DEBUG(s) clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL,(s))
#else #else
#define _PARSE_DEBUG(s) #define _PARSE_DEBUG(s)
#endif #endif

View file

@ -1272,7 +1272,7 @@ xml_yang_validate_all(clixon_handle h,
} }
if (yang_config(yt) != 0){ if (yang_config(yt) != 0){
ret = yang_check_when_xpath(xt, xml_parent(xt), yt, &hit, &nr, &xpath); ret = yang_check_when_xpath(xt, xml_parent(xt), yt, &hit, &nr, &xpath);
clixon_debug(CLIXON_DBG_XPATH, "nr:%d xpath:%s return:%d", nr, xpath, ret); clixon_debug(CLIXON_DBG_XPATH|CLIXON_DBG_DETAIL, "nr:%d xpath:%s return:%d", nr, xpath, ret);
if (ret < 0) if (ret < 0)
goto done; goto done;

View file

@ -88,7 +88,7 @@
/* Enable for debugging, steals some cycles otherwise */ /* Enable for debugging, steals some cycles otherwise */
#if 0 #if 0
#define _PARSE_DEBUG(s) clixon_debug(1,(s)) #define _PARSE_DEBUG(s) clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL,(s))
#else #else
#define _PARSE_DEBUG(s) #define _PARSE_DEBUG(s)
#endif #endif
@ -450,7 +450,7 @@ element1 : ESLASH {_XY->xy_xelement = NULL;
| '>' { xml_parse_endslash_pre(_XY); } | '>' { xml_parse_endslash_pre(_XY); }
elist { xml_parse_endslash_mid(_XY); } elist { xml_parse_endslash_mid(_XY); }
endtag { xml_parse_endslash_post(_XY); endtag { xml_parse_endslash_post(_XY);
_PARSE_DEBUG("element1 -> > elist endtag");} _PARSE_DEBUG("element1 -> elist endtag");}
; ;
endtag : BSLASH NAME '>' endtag : BSLASH NAME '>'
@ -505,4 +505,3 @@ attvalue : '\"' STRING '\"' { $$=$2; /* $2 must be consumed */}
; ;
%% %%

View file

@ -558,7 +558,7 @@ xpath_parse(const char *xpath,
clixon_xpath_yacc xpy = {0,}; clixon_xpath_yacc xpy = {0,};
cbuf *cb = NULL; cbuf *cb = NULL;
clixon_debug(CLIXON_DBG_XPATH | CLIXON_DBG_DETAIL, "xpath %s", xpath); clixon_debug(CLIXON_DBG_PARSE, "%s", xpath);
if (xpath == NULL){ if (xpath == NULL){
clixon_err(OE_XML, EINVAL, "XPath is NULL"); clixon_err(OE_XML, EINVAL, "XPath is NULL");
goto done; goto done;
@ -583,7 +583,7 @@ xpath_parse(const char *xpath,
goto done; goto done;
} }
xpath_tree_print_cb(cb, xpy.xpy_top); xpath_tree_print_cb(cb, xpy.xpy_top);
clixon_debug(CLIXON_DBG_ALWAYS, "xpath parse tree:\n%s", cbuf_get(cb)); clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL, "xpath parse tree:\n%s", cbuf_get(cb));
} }
xpath_parse_exit(&xpy); xpath_parse_exit(&xpy);
xpath_scan_exit(&xpy); xpath_scan_exit(&xpy);
@ -593,6 +593,7 @@ xpath_parse(const char *xpath,
} }
retval = 0; retval = 0;
done: done:
clixon_debug(CLIXON_DBG_PARSE, "retval:%d", retval);
if (cb) if (cb)
cbuf_free(cb); cbuf_free(cb);
if (xpy.xpy_top) if (xpy.xpy_top)

View file

@ -138,9 +138,9 @@
* Disable it to stop any calls to clixon_debug. Having it on by default would mean very large debug outputs. * Disable it to stop any calls to clixon_debug. Having it on by default would mean very large debug outputs.
*/ */
#if 0 #if 0
#define _PARSE_DEBUG(s) clixon_debug(1,(s)) #define _PARSE_DEBUG(s) clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL,(s))
#define _PARSE_DEBUG1(s, s1) clixon_debug(1,(s), (s1)) #define _PARSE_DEBUG1(s, s1) clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL,(s), (s1))
#define _PARSE_DEBUG2(s, s1, s2) clixon_debug(1,(s), (s1), (s2)) #define _PARSE_DEBUG2(s, s1, s2) clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL,(s), (s1), (s2))
#else #else
#define _PARSE_DEBUG(s) #define _PARSE_DEBUG(s)
#define _PARSE_DEBUG1(s, s1) #define _PARSE_DEBUG1(s, s1)

View file

@ -204,8 +204,8 @@
* Disable it to stop any calls to clixon_debug. Having it on by default would mean very large debug outputs. * Disable it to stop any calls to clixon_debug. Having it on by default would mean very large debug outputs.
*/ */
#if 0 #if 0
#define _PARSE_DEBUG(s) clixon_debug(CLIXON_DBG_YANG, (s)) #define _PARSE_DEBUG(s) clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL, (s))
#define _PARSE_DEBUG1(s, s1) clixon_debug(CLIXON_DBG_YANG, (s), (s1)) #define _PARSE_DEBUG1(s, s1) clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL, (s), (s1))
#else #else
#define _PARSE_DEBUG(s) #define _PARSE_DEBUG(s)
#define _PARSE_DEBUG1(s, s1) #define _PARSE_DEBUG1(s, s1)

View file

@ -795,6 +795,7 @@ yang_parse_str(char *str,
clixon_yang_yacc yy = {0,}; clixon_yang_yacc yy = {0,};
yang_stmt *ymod = NULL; yang_stmt *ymod = NULL;
clixon_debug(CLIXON_DBG_PARSE, "%s", str);
if (yspec == NULL){ if (yspec == NULL){
clixon_err(OE_YANG, 0, "Yang parse need top level yang spec"); clixon_err(OE_YANG, 0, "Yang parse need top level yang spec");
goto done; goto done;
@ -832,6 +833,7 @@ yang_parse_str(char *str,
if (yang_filename_set(ymod, name) < 0) if (yang_filename_set(ymod, name) < 0)
goto done; goto done;
done: done:
clixon_debug(CLIXON_DBG_PARSE, "retval:%p", ymod);
ystack_pop(&yy); ystack_pop(&yy);
if (yy.yy_stack) if (yy.yy_stack)
free (yy.yy_stack); free (yy.yy_stack);

View file

@ -96,7 +96,7 @@
/* Enable for debugging, steals some cycles otherwise */ /* Enable for debugging, steals some cycles otherwise */
#if 0 #if 0
#define _PARSE_DEBUG(s) clixon_debug(CLIXON_DBG_YANG, (s)) #define _PARSE_DEBUG(s) clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL, (s))
#else #else
#define _PARSE_DEBUG(s) #define _PARSE_DEBUG(s)
#endif #endif

View file

@ -83,7 +83,7 @@ yang_subparse(char *str,
int retval = -1; int retval = -1;
clixon_yang_sub_parse_yacc ife = {0,}; clixon_yang_sub_parse_yacc ife = {0,};
clixon_debug(CLIXON_DBG_YANG | CLIXON_DBG_DETAIL, "%s", str); clixon_debug(CLIXON_DBG_PARSE, "%s", str);
ife.if_parse_string = str; ife.if_parse_string = str;
ife.if_linenum = linenum; ife.if_linenum = linenum;
if (enabled) if (enabled)
@ -102,6 +102,7 @@ yang_subparse(char *str,
*enabled = ife.if_enabled; *enabled = ife.if_enabled;
retval = 0; retval = 0;
done: done:
clixon_debug(CLIXON_DBG_PARSE, "retval:%d", retval);
clixon_yang_sub_parsel_exit(&ife); clixon_yang_sub_parsel_exit(&ife);
return retval; return retval;
} }
@ -125,7 +126,7 @@ yang_schema_nodeid_subparse(char *str,
int retval = -1; int retval = -1;
clixon_yang_schemanode_yacc ife = {0,}; clixon_yang_schemanode_yacc ife = {0,};
clixon_debug(CLIXON_DBG_YANG | CLIXON_DBG_DETAIL, "%s", str); clixon_debug(CLIXON_DBG_PARSE, "%s", str);
ife.if_parse_string = str; ife.if_parse_string = str;
ife.if_linenum = linenum; ife.if_linenum = linenum;
ife.if_mainfile = mainfile; ife.if_mainfile = mainfile;
@ -139,6 +140,7 @@ yang_schema_nodeid_subparse(char *str,
} }
retval = 0; retval = 0;
done: done:
clixon_debug(CLIXON_DBG_PARSE, "retval:%d", retval);
clixon_yang_schemanode_parsel_exit(&ife); clixon_yang_schemanode_parsel_exit(&ife);
return retval; return retval;
} }

View file

@ -106,7 +106,7 @@
/* Enable for debugging, steals some cycles otherwise */ /* Enable for debugging, steals some cycles otherwise */
#if 0 #if 0
#define _PARSE_DEBUG(s) clixon_debug(CLIXON_DBG_YANG, (s)) #define _PARSE_DEBUG(s) clixon_debug(CLIXON_DBG_PARSE|CLIXON_DBG_DETAIL, (s))
#else #else
#define _PARSE_DEBUG(s) #define _PARSE_DEBUG(s)
#endif #endif