* 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)
/*
* Using start conditions to deal with comments
* and strings.
- */
+ */
"/*" BEGIN(comment_ml);
<comment_ml>[^*\n]* /* eat anything that's not a '*' */
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;
%%
* 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
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);
{
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;
{
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);
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;
}
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);
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;
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;
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;
break;
case NODE_TYPEALIAS:
break;
-
case NODE_TYPE_SPECIFIER:
break;
case NODE_TYPE_SPECIFIER_LIST:
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;
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;
}
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;
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;
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;
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;
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;
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;
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:
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;
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
{
/* 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);
}
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();
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;
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);
}