aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap
diff options
context:
space:
mode:
authorPascal Quantin <pascal@wireshark.org>2019-07-12 14:54:40 +0200
committerPascal Quantin <pascal@wireshark.org>2019-07-12 14:39:11 +0000
commit86cb2c78582bb78400af3651579df0b5d5bfc913 (patch)
tree1733e7f66bcf1de76ab9ce3cd63d799098e9653a /wiretap
parent5e59d50b46a24acff4c631373d62349abd85d70b (diff)
wiretap: do not pollute debug builds with candump debug messages
Change-Id: I2f7c4c3d23d5be27c1fac704272b9e581a4de0f7 Reviewed-on: https://code.wireshark.org/review/33912 Petri-Dish: Pascal Quantin <pascal@wireshark.org> Tested-by: Petri Dish Buildbot Reviewed-by: Pascal Quantin <pascal@wireshark.org>
Diffstat (limited to 'wiretap')
-rw-r--r--wiretap/candump.c16
-rw-r--r--wiretap/candump_parser.lemon20
-rw-r--r--wiretap/candump_priv.h2
3 files changed, 33 insertions, 5 deletions
diff --git a/wiretap/candump.c b/wiretap/candump.c
index 331eaee079..0fe484d322 100644
--- a/wiretap/candump.c
+++ b/wiretap/candump.c
@@ -111,7 +111,9 @@ candump_dump(GSList *packets, int *err, char **err_info)
static const gchar *opt_comment = "File converted to Exported PDU format during opening";
static const gchar *if_name = "Fake IF";
+#ifdef CANDUMP_DEBUG
ws_debug_printf("%s: Creating a temporary file\n", G_STRFUNC);
+#endif
import_file_fd = create_tempfile(&filename, "Wireshark_PDU_candump_", NULL);
/* Now open a file and dump to it */
@@ -169,14 +171,18 @@ candump_dump(GSList *packets, int *err, char **err_info)
.idb_inf = idb_inf,
};
+#ifdef CANDUMP_DEBUG
ws_debug_printf("%s: Opening the temporary file for writing\n", G_STRFUNC);
+#endif
wdh = wtap_dump_fdopen(import_file_fd, WTAP_FILE_TYPE_SUBTYPE_PCAPNG,
WTAP_UNCOMPRESSED, &params, err);
if (!wdh)
goto error_open;
+#ifdef CANDUMP_DEBUG
ws_debug_printf("%s: Writing packet data into the file\n", G_STRFUNC);
+#endif
/* OK we've opened a new pcapng file and written the headers, time to do the packets */
for (packet = packets; packet; packet = g_slist_next(packet))
{
@@ -184,7 +190,9 @@ candump_dump(GSList *packets, int *err, char **err_info)
goto error_write;
}
+#ifdef CANDUMP_DEBUG
ws_debug_printf("%s: Closing the file\n", G_STRFUNC);
+#endif
/* Close the written file */
if (!wtap_dump_close(wdh, err))
goto error_write;
@@ -211,7 +219,9 @@ candump_parse(candump_priv_t **priv, wtap *wth, int *err, char **err_info)
gchar *filename;
wtap *fh;
+#ifdef CANDUMP_DEBUG
ws_debug_printf("%s: Trying candump file decoder\n", G_STRFUNC);
+#endif
packets = run_candump_parser(wth->fh, err, err_info);
if (!packets)
@@ -223,7 +233,9 @@ candump_parse(candump_priv_t **priv, wtap *wth, int *err, char **err_info)
return WTAP_OPEN_ERROR;
}
+#ifdef CANDUMP_DEBUG
ws_debug_printf("%s: Creating a PCAPNG file with data we've just read\n", G_STRFUNC);
+#endif
/* Dump packets into a temporary file */
filename = candump_dump(packets, err, err_info);
g_slist_free_full(packets, g_free);
@@ -231,7 +243,9 @@ candump_parse(candump_priv_t **priv, wtap *wth, int *err, char **err_info)
if (!filename)
return WTAP_OPEN_ERROR;
+#ifdef CANDUMP_DEBUG
ws_debug_printf("%s: Opening the newly created file\n", G_STRFUNC);
+#endif
/* Now open the file for reading */
fh = wtap_open_offline(filename, WTAP_TYPE_AUTO,
err, err_info,
@@ -248,7 +262,9 @@ candump_parse(candump_priv_t **priv, wtap *wth, int *err, char **err_info)
(*priv)->tmp_file = fh;
(*priv)->tmp_filename = filename;
+#ifdef CANDUMP_DEBUG
ws_debug_printf("%s: Ok\n", G_STRFUNC);
+#endif
return WTAP_OPEN_MINE;
}
diff --git a/wiretap/candump_parser.lemon b/wiretap/candump_parser.lemon
index 2af58a6ea5..705f6dc041 100644
--- a/wiretap/candump_parser.lemon
+++ b/wiretap/candump_parser.lemon
@@ -20,7 +20,7 @@ extern void *CandumpParserAlloc(void *(*mallocProc)(size_t));
extern void CandumpParser(void *yyp, int yymajor, token_t yyminor, candump_state_t *state);
extern void CandumpParserFree(void *p, void (*freeProc)(void*));
-#ifndef NDEBUG
+#ifdef CANDUMP_DEBUG
extern void CandumpParserTrace(FILE *TraceFILE, char *zTracePrompt);
#endif
@@ -55,7 +55,7 @@ DIAG_OFF(unreachable-code)
(void)yypParser;
(void)yyminor;
-#ifndef NDEBUG
+#ifdef CANDUMP_DEBUG
const int n = sizeof(yyTokenName) / sizeof(yyTokenName[0]);
ws_debug_printf("%s: got token: %s\n", G_STRFUNC, yyTokenName[yymajor]);
for (int i = 0; i < n; ++i) {
@@ -68,14 +68,18 @@ DIAG_OFF(unreachable-code)
g_free(state->parse_error);
state->parse_error = g_strdup_printf("Syntax Error");
+#ifdef CANDUMP_DEBUG
ws_debug_printf("%s: Syntax Error\n", G_STRFUNC);
+#endif
}
%parse_failure
{
g_free(state->parse_error);
state->parse_error = g_strdup("Parse Error");
+#ifdef CANDUMP_DEBUG
ws_debug_printf("%s: Parse Error\n", G_STRFUNC);
+#endif
}
%type msg { msg_t }
@@ -113,13 +117,17 @@ lines ::= lines ENDL line .
line ::= maybe_spaces msg(M) .
{
+#ifdef CANDUMP_DEBUG
ws_debug_printf("%s: read message\n", G_STRFUNC);
+#endif
state->packets = g_slist_append(state->packets, g_memdup(&(M), sizeof(M)));
}
line ::= maybe_spaces .
{
+#ifdef CANDUMP_DEBUG
ws_debug_printf("%s: read empty line\n", G_STRFUNC);
+#endif
}
maybe_spaces ::= maybe_spaces SPACE .
@@ -292,17 +300,17 @@ run_candump_parser(FILE_T fh, int *err, gchar **err_info)
parser = CandumpParserAlloc(g_malloc);
-#ifndef NDEBUG
+#ifdef CANDUMP_DEBUG
CandumpParserTrace(stdout, "parser >> ");
-#endif
ws_debug_printf("%s: Starting parsing\n", G_STRFUNC);
+#endif
do
{
lex_code = candump_lex(scanner);
-#ifndef NDEBUG
+#ifdef CANDUMP_DEBUG
if (lex_code && lex_code != TOKEN_ENDL)
ws_debug_printf("%s: Feeding %s '%s'\n",
G_STRFUNC, yyTokenName[lex_code],
@@ -319,7 +327,9 @@ run_candump_parser(FILE_T fh, int *err, gchar **err_info)
}
while (lex_code);
+#ifdef CANDUMP_DEBUG
ws_debug_printf("%s: Done (%d)\n", G_STRFUNC, lex_code);
+#endif
CandumpParserFree(parser, g_free);
candump_lex_destroy(scanner);
diff --git a/wiretap/candump_priv.h b/wiretap/candump_priv.h
index 9749daec3e..9b10ec8220 100644
--- a/wiretap/candump_priv.h
+++ b/wiretap/candump_priv.h
@@ -16,6 +16,8 @@
#include <wiretap/wtap.h>
#include <epan/dissectors/packet-socketcan.h>
+//#define CANDUMP_DEBUG
+
#define CAN_MAX_DLEN 8
#define CANFD_MAX_DLEN 64