plugins/ctf/common/metadata: logging: standardize in parser and lexer
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 13 Jun 2017 22:35:16 +0000 (18:35 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 14 Jun 2017 19:07:59 +0000 (15:07 -0400)
YYDEBUG is set if the VERBOSE mode is enabled for the common metadata
module. YYFPRINTF is defined to BT_LOGV so that everything uses the
standard logging macros.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
plugins/ctf/common/metadata/Makefile.am
plugins/ctf/common/metadata/decoder.c
plugins/ctf/common/metadata/lexer.l
plugins/ctf/common/metadata/logging.h
plugins/ctf/common/metadata/parser.y
plugins/ctf/lttng-live/metadata.c

index 1cd9e7536ab27ceb071badbf243a61e71de2dc28..0a490f3b652512a626fba7e8ff7306aff71131d5 100644 (file)
@@ -10,6 +10,7 @@ libctf_parser_la_SOURCES = lexer.l parser.y objstack.c
 # with bt_.
 libctf_parser_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir) \
                -include $(srcdir)/scanner-symbols.h
+libctf_parser_la_CFLAGS = $(AM_CFLAGS) -Wno-unused-function
 
 libctf_ast_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)
 libctf_ast_la_SOURCES = \
index c0cfa43850562073d160ceabfe00d626f6b6df7c..ddaeb02c41de577f26acda9380579c552f55c38d 100644 (file)
@@ -32,6 +32,9 @@
 
 #define TSDL_MAGIC     0x75d11d57
 
+BT_HIDDEN
+int yydebug;
+
 struct ctf_metadata_decoder {
        struct ctf_visitor_generate_ir *visitor;
        uint8_t uuid[16];
@@ -362,6 +365,10 @@ enum ctf_metadata_decoder_status ctf_metadata_decoder_decode(
                }
        }
 
+       if (BT_LOG_ON_VERBOSE) {
+               yydebug = 1;
+       }
+
        /* Allocate a scanner and append the metadata text content */
        scanner = ctf_scanner_alloc();
        if (!scanner) {
@@ -406,6 +413,8 @@ end:
                ctf_scanner_free(scanner);
        }
 
+       yydebug = 0;
+
        if (fp && close_fp) {
                if (fclose(fp)) {
                        BT_LOGE("Cannot close metadata file stream");
index d805a43409c57d57df562222343c644b7a445131..694ddc3aed28258b26ae0f36a27577841470a43b 100644 (file)
  * SOFTWARE.
  */
 
+#define BT_LOG_TAG "PLUGIN-CTF-METADATA-LEXER"
+#include "logging.h"
+
 #include <stdio.h>
 #include <ctype.h>
-#include <babeltrace/babeltrace-internal.h>
 #include "scanner.h"
 #include "parser.h"
 #include "ast.h"
 
+#define YY_FATAL_ERROR(_msg)   BT_LOGF_STR(_msg)
+
 #define PARSE_INTEGER_LITERAL(base)                                    \
        do {                                                            \
                errno = 0;                                              \
                yylval->ull = strtoull(yytext, NULL, base);             \
                if (errno) {                                            \
-                       printfl_perror(yylineno, "Integer literal");    \
-                       return CTF_ERROR;                                       \
+                       _BT_LOGE_LINENO(yylineno,                       \
+                               "Cannot parser constant integer: "      \
+                               "base=%d, text=\"%s\"", base, yytext);  \
+                       return CTF_ERROR;                               \
                }                                                       \
        } while (0)
 
@@ -72,7 +78,7 @@ IDENTIFIER                    {ID_NONDIGIT}({ID_NONDIGIT}|{DIGIT})*
                                /*
                                 * Using start conditions to deal with comments
                                 * and strings.
-                                */ 
+                                */
 
 "/*"                           BEGIN(comment_ml);
 <comment_ml>[^*\n]*            /* eat anything that's not a '*' */
@@ -136,7 +142,7 @@ _Imaginary                  setstring(yyextra, yylval, yytext); return CTF_IMAGINARY;
 0{OCTALDIGIT}*{INTEGER_SUFFIX}?        PARSE_INTEGER_LITERAL(8); return CTF_INTEGER_LITERAL;
 0[xX]{HEXDIGIT}+{INTEGER_SUFFIX}?      PARSE_INTEGER_LITERAL(16); return CTF_INTEGER_LITERAL;
 
-{IDENTIFIER}                   printf_debug("<IDENTIFIER %s>\n", yytext); setstring(yyextra, yylval, yytext); if (is_type(yyextra, yytext)) return ID_TYPE; else return IDENTIFIER;
+{IDENTIFIER}                   BT_LOGV("Got identifier: id=\"%s\"", yytext); setstring(yyextra, yylval, yytext); if (is_type(yyextra, yytext)) return ID_TYPE; else return IDENTIFIER;
 [ \t\r\n]                      ; /* ignore */
-.                              printfl_error(yylineno, "invalid character '0x%02X'", yytext[0]);  return CTF_ERROR;
+.                              _BT_LOGE_LINENO(yylineno, "Invalid character: char=\"%c\", val=0x%02x", isprint(yytext[0]) ? yytext[0] : '\0', yytext[0]); return CTF_ERROR;
 %%
index 5ecbdb13e13f6d8762a8e1294ec7f7bf586d217b..78a41a66a7a3cb02d188127b7d30d97d08c5f482 100644 (file)
 
 BT_LOG_LEVEL_EXTERN_SYMBOL(metadata_log_level);
 
+#define _BT_LOGW_LINENO(_lineno, _msg, args...) \
+       BT_LOGW("At line %u in metadata stream: " _msg, _lineno, ## args)
+
+#define _BT_LOGE_LINENO(_lineno, _msg, args...) \
+       BT_LOGE("At line %u in metadata stream: " _msg, _lineno, ## args)
+
 #endif /* CTF_METADATA_LOGGING_H */
index 02203aeb422aa9a9e236a4a0d679b79e1d287896..83080063fd4f66c7a4bca2627fc1b0ec4928952b 100644 (file)
@@ -25,6 +25,9 @@
  * SOFTWARE.
  */
 
+#define BT_LOG_TAG "PLUGIN-CTF-METADATA-PARSER"
+#include "logging.h"
+
 #include <stdio.h>
 #include <ctype.h>
 #include <unistd.h>
 #include <errno.h>
 #include <inttypes.h>
 #include <babeltrace/list-internal.h>
-#include <babeltrace/babeltrace-internal.h>
 #include "scanner.h"
 #include "parser.h"
 #include "ast.h"
 #include "objstack.h"
 
-BT_HIDDEN
-int yydebug;
+#if BT_LOG_ENABLED_VERBOSE
+# define YYDEBUG 1
+# define YYFPRINTF(_stream, _fmt, args...) BT_LOGV(_fmt, ## args)
+#else
+# define YYDEBUG 0
+#endif
 
 /* Join two lists, put "add" at the end of "head".  */
 static inline void
@@ -284,8 +290,9 @@ int import_string(struct ctf_scanner *scanner, YYSTYPE *lvalp,
        lvalp->s = objstack_alloc(scanner->objstack, len);
        if (src[0] == 'L') {
                // TODO: import wide string
-               printfl_error(yyget_lineno(scanner),
-                       "Wide string not supported yet.");
+               _BT_LOGE_LINENO(yyget_lineno(scanner),
+                       "wide characters are not supported as of this version: "
+                       "scanner-addr=%p", scanner);
                return -1;
        } else {
                return import_basic_string(scanner, lvalp, len, src, delim);
@@ -309,7 +316,7 @@ static void push_scope(struct ctf_scanner *scanner)
 {
        struct ctf_scanner_scope *ns;
 
-       printf_debug("push scope\n");
+       BT_LOGV("Pushing scope: scanner-addr=%p", scanner);
        ns = malloc(sizeof(struct ctf_scanner_scope));
        init_scope(ns, scanner->cs);
        scanner->cs = ns;
@@ -319,7 +326,7 @@ static void pop_scope(struct ctf_scanner *scanner)
 {
        struct ctf_scanner_scope *os;
 
-       printf_debug("pop scope\n");
+       BT_LOGV("Popping scope: scanner-addr=%p", scanner);
        os = scanner->cs;
        scanner->cs = os->parent;
        finalize_scope(os);
@@ -331,7 +338,8 @@ static int lookup_type(struct ctf_scanner_scope *s, const char *id)
        int ret;
 
        ret = GPOINTER_TO_INT(g_hash_table_lookup(s->types, id));
-       printf_debug("lookup %p %s %d\n", s, id, ret);
+       BT_LOGV("Looked up type: scanner-addr=%p, id=\"%s\", ret=%d",
+               s, id, ret);
        return ret;
 }
 
@@ -347,13 +355,15 @@ int is_type(struct ctf_scanner *scanner, const char *id)
                        break;
                }
        }
-       printf_debug("is type %s %d\n", id, ret);
+       BT_LOGV("Found if ID is type: scanner-addr=%p, id=\"%s\", ret=%d",
+               scanner, id, ret);
        return ret;
 }
 
 static void add_type(struct ctf_scanner *scanner, char *id)
 {
-       printf_debug("add type %s\n", id);
+       BT_LOGV("Adding type: scanner-addr=%p, id=\"%s\"",
+               scanner, id);
        if (lookup_type(scanner->cs, id))
                return;
        g_hash_table_insert(scanner->cs->types, id, id);
@@ -366,7 +376,9 @@ static struct ctf_node *make_node(struct ctf_scanner *scanner,
 
        node = objstack_alloc(scanner->objstack, sizeof(*node));
        if (!node) {
-               printfl_fatal(yyget_lineno(scanner->scanner), "out of memory");
+               _BT_LOGE_LINENO(yyget_lineno(scanner->scanner),
+                       "failed to allocate one stack entry: "
+                       "scanner-addr=%p", scanner);
                return &error_node;
        }
        node->type = type;
@@ -377,9 +389,9 @@ static struct ctf_node *make_node(struct ctf_scanner *scanner,
        switch (type) {
        case NODE_ROOT:
                node->type = NODE_ERROR;
-               printfn_fatal(node, "trying to create root node");
+               BT_LOGE("Trying to create root node: scanner-addr=%p",
+                       scanner);
                break;
-
        case NODE_EVENT:
                BT_INIT_LIST_HEAD(&node->u.event.declaration_list);
                break;
@@ -398,14 +410,12 @@ static struct ctf_node *make_node(struct ctf_scanner *scanner,
        case NODE_CALLSITE:
                BT_INIT_LIST_HEAD(&node->u.callsite.declaration_list);
                break;
-
        case NODE_CTF_EXPRESSION:
                BT_INIT_LIST_HEAD(&node->u.ctf_expression.left);
                BT_INIT_LIST_HEAD(&node->u.ctf_expression.right);
                break;
        case NODE_UNARY_EXPRESSION:
                break;
-
        case NODE_TYPEDEF:
                BT_INIT_LIST_HEAD(&node->u._typedef.type_declarators);
                break;
@@ -417,7 +427,6 @@ static struct ctf_node *make_node(struct ctf_scanner *scanner,
                break;
        case NODE_TYPEALIAS:
                break;
-
        case NODE_TYPE_SPECIFIER:
                break;
        case NODE_TYPE_SPECIFIER_LIST:
@@ -428,7 +437,6 @@ static struct ctf_node *make_node(struct ctf_scanner *scanner,
        case NODE_TYPE_DECLARATOR:
                BT_INIT_LIST_HEAD(&node->u.type_declarator.pointers);
                break;
-
        case NODE_FLOATING_POINT:
                BT_INIT_LIST_HEAD(&node->u.floating_point.expressions);
                break;
@@ -454,11 +462,11 @@ static struct ctf_node *make_node(struct ctf_scanner *scanner,
                BT_INIT_LIST_HEAD(&node->u._struct.declaration_list);
                BT_INIT_LIST_HEAD(&node->u._struct.min_align);
                break;
-
        case NODE_UNKNOWN:
        default:
                node->type = NODE_ERROR;
-               printfn_fatal(node, "unknown node type '%d'", (int) type);
+               BT_LOGE("Unknown node type: scanner-addr=%p, node-type=%d",
+                       scanner, type);
                break;
        }
 
@@ -517,7 +525,7 @@ static int reparent_ctf_expression(struct ctf_node *node,
 
        case NODE_UNKNOWN:
        default:
-               printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
+               BT_LOGE("Unknown node type: node-type=%d", parent->type);
                return -EINVAL;
        }
        return 0;
@@ -574,7 +582,7 @@ static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
 
        case NODE_UNKNOWN:
        default:
-               printfn_fatal(node, "unknown node type %d", parent->type);
+               BT_LOGE("Unknown node type: node-type=%d", parent->type);
                return -EINVAL;
        }
        return 0;
@@ -631,7 +639,7 @@ static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
 
        case NODE_UNKNOWN:
        default:
-               printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
+               BT_LOGE("Unknown node type: node-type=%d", parent->type);
                return -EINVAL;
        }
        return 0;
@@ -672,7 +680,7 @@ static int reparent_type_specifier(struct ctf_node *node,
 
        case NODE_UNKNOWN:
        default:
-               printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
+               BT_LOGE("Unknown node type: node-type=%d", parent->type);
                return -EINVAL;
        }
        return 0;
@@ -738,7 +746,7 @@ static int reparent_type_specifier_list(struct ctf_node *node,
 
        case NODE_UNKNOWN:
        default:
-               printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
+               BT_LOGE("Unknown node type: node-type=%d", parent->type);
                return -EINVAL;
        }
        return 0;
@@ -789,7 +797,7 @@ static int reparent_type_declarator(struct ctf_node *node,
 
        case NODE_UNKNOWN:
        default:
-               printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
+               BT_LOGE("Unknown node type: node-type=%d", parent->type);
                return -EINVAL;
        }
        return 0;
@@ -812,7 +820,7 @@ static int set_parent_node(struct ctf_node *node,
 
        switch (node->type) {
        case NODE_ROOT:
-               printfn_fatal(node, "trying to reparent root node");
+               BT_LOGE_STR("Trying to reparent root node.");
                return -EINVAL;
 
        case NODE_EVENT:
@@ -927,7 +935,7 @@ static int set_parent_node(struct ctf_node *node,
 
        case NODE_UNKNOWN:
        default:
-               printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
+               BT_LOGE("Unknown node type: node-type=%d", parent->type);
                return -EINVAL;
        }
        return 0;
@@ -936,9 +944,8 @@ static int set_parent_node(struct ctf_node *node,
 BT_HIDDEN
 void yyerror(struct ctf_scanner *scanner, yyscan_t yyscanner, const char *str)
 {
-       printfl_error(yyget_lineno(scanner->scanner),
-               "token \"%s\": %s\n",
-               yyget_text(scanner->scanner), str);
+       _BT_LOGE_LINENO(yyget_lineno(scanner->scanner),
+               "%s: token=\"%s\"", str, yyget_text(scanner->scanner));
 }
 
 BT_HIDDEN
@@ -976,10 +983,6 @@ int ctf_scanner_append_ast(struct ctf_scanner *scanner, FILE *input)
 {
        /* Start processing new stream */
        yyrestart(input, scanner->scanner);
-       if (yydebug)
-               fprintf(stdout, "Scanner input is a%s.\n",
-                       isatty(fileno(input)) ? "n interactive tty" :
-                                               " noninteractive file");
        return yyparse(scanner, scanner->scanner);
 }
 
@@ -988,15 +991,13 @@ struct ctf_scanner *ctf_scanner_alloc(void)
        struct ctf_scanner *scanner;
        int ret;
 
-       yydebug = babeltrace_debug;
-
        scanner = malloc(sizeof(*scanner));
        if (!scanner)
                return NULL;
        memset(scanner, 0, sizeof(*scanner));
        ret = yylex_init_extra(scanner, &scanner->scanner);
        if (ret) {
-               printf_fatal("yylex_init error");
+               BT_LOGE("yylex_init_extra() failed: ret=%d", ret);
                goto cleanup_scanner;
        }
        scanner->objstack = objstack_create();
@@ -1015,7 +1016,8 @@ cleanup_objstack:
 cleanup_lexer:
        ret = yylex_destroy(scanner->scanner);
        if (!ret)
-               printf_fatal("yylex_destroy error");
+               BT_LOGE("yylex_destroy() failed: scanner-addr=%p, ret=%d",
+                       scanner, ret);
 cleanup_scanner:
        free(scanner);
        return NULL;
@@ -1031,7 +1033,8 @@ void ctf_scanner_free(struct ctf_scanner *scanner)
        objstack_destroy(scanner->objstack);
        ret = yylex_destroy(scanner->scanner);
        if (ret)
-               printf_error("yylex_destroy error");
+               BT_LOGE("yylex_destroy() failed: scanner-addr=%p, ret=%d",
+                       scanner, ret);
        free(scanner);
 }
 
index ffc775d05ddfe3babf4d4b1ab8058ef66bd23f32..1adc81c1553bd893319738aae900c54e1b5c4534 100644 (file)
@@ -185,10 +185,6 @@ enum bt_ctf_lttng_live_iterator_status lttng_live_metadata_update(
                goto end;
        }
 
-       if (babeltrace_debug) {
-               // yydebug = 1;
-       }
-
        fp = bt_fmemopen(metadata_buf, len_read, "rb");
        if (!fp) {
                BT_LOGE("Cannot memory-open metadata buffer: %s",
This page took 0.031658 seconds and 4 git commands to generate.