From 99986be0b9c540317da421312a0faaf26b34617a Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Thu, 8 Feb 2018 14:04:45 -0200 Subject: [PATCH] Incluindo mecanismo para geração de arquivo de trace com as chamadas da API. --- configure.ac | 9 +++++++++ pw3270-sharp.cbp | 1 + src/include/config.h.in | 7 +++++++ src/native/Makefile.in | 2 +- src/native/get.cc | 2 ++ src/native/init.cc | 26 ++++++++++++++++++++++++++ src/native/private.h | 9 +++++++++ src/native/screen.cc | 2 ++ src/native/set.cc | 1 + 9 files changed, 58 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 3cd859c..0ca716a 100644 --- a/configure.ac +++ b/configure.ac @@ -335,6 +335,15 @@ if test "$app_cv_pic" == "yes"; then fi dnl --------------------------------------------------------------------------- +dnl Enable/Disable trace file +dnl --------------------------------------------------------------------------- +AC_ARG_ENABLE([trace],[AS_HELP_STRING([--enable-trace], [Enable creation of trace file])],[app_cv_trace="$enableval"],[app_cv_trace="no"]) + +if test "$app_cv_trace" == "yes"; then + AC_DEFINE(ENABLE_TRACE_TO_FILE) +fi + +dnl --------------------------------------------------------------------------- dnl Output config dnl --------------------------------------------------------------------------- diff --git a/pw3270-sharp.cbp b/pw3270-sharp.cbp index 24c7894..e27a8ec 100644 --- a/pw3270-sharp.cbp +++ b/pw3270-sharp.cbp @@ -43,6 +43,7 @@ + diff --git a/src/include/config.h.in b/src/include/config.h.in index da383ba..a7cbdba 100644 --- a/src/include/config.h.in +++ b/src/include/config.h.in @@ -43,5 +43,12 @@ */ #undef HAVE_GNUC_VISIBILITY + /** + * @brief Ativa trace em um arquivo texto. + * + */ + #undef ENABLE_TRACE_TO_FILE + + #endif // CONFIG_H_INCLUDED diff --git a/src/native/Makefile.in b/src/native/Makefile.in index ed9f169..98f7b0c 100644 --- a/src/native/Makefile.in +++ b/src/native/Makefile.in @@ -67,7 +67,7 @@ CC=@CC@ LD=@CXX@ LIBS=-lpw3270cpp @LIBS@ @LIBICONV@ -CFLAGS=@CFLAGS@ +CFLAGS=-I../include @CFLAGS@ LDFLAGS=@LDFLAGS@ #---[ Rules ]---------------------------------------------------------------------------- diff --git a/src/native/get.cc b/src/native/get.cc index c95c337..d9967c2 100644 --- a/src/native/get.cc +++ b/src/native/get.cc @@ -63,6 +63,8 @@ int tn3270_get_cstate(h3270::session *ses) { + trace_to_file("%s: %d",__FUNCTION__,(int) ses->get_cstate()); + try { return (int) ses->get_cstate(); } catch(std::exception &e) { diff --git a/src/native/init.cc b/src/native/init.cc index 4db5deb..5a8d01a 100644 --- a/src/native/init.cc +++ b/src/native/init.cc @@ -42,6 +42,9 @@ * */ h3270::session * tn3270_create_session(const char *name) { + + trace_to_file("%s(%s)",__FUNCTION__,name ? name : ""); + try { return h3270::session::create(name); } catch(std::exception &e) { @@ -55,6 +58,9 @@ * */ int tn3270_destroy_session(h3270::session *ses) { + + trace_to_file("%s",__FUNCTION__); + try { delete ses; } catch(std::exception &e) { @@ -64,3 +70,23 @@ return 0; } +#ifdef ENABLE_TRACE_TO_FILE + void write_trace(const char *fmt, ...) { + + FILE *trace = fopen(PACKAGE_NAME ".trace","a"); + if(trace) { + va_list arg_ptr; + va_start(arg_ptr, fmt); + vfprintf(trace, fmt, arg_ptr); + fprintf(trace,"\n"); + va_end(arg_ptr); + fclose(trace); + } +#ifdef DEBUG + else { + perror(PACKAGE_NAME ".trace"); + } +#endif // DEBUG + + } +#endif // ENABLE_TRACE_TO_FILE diff --git a/src/native/private.h b/src/native/private.h index 1ec70fc..26ede0e 100644 --- a/src/native/private.h +++ b/src/native/private.h @@ -35,6 +35,8 @@ #define PRIVATE_H_INCLUDED + #include + #if defined(_WIN32) #include @@ -63,6 +65,13 @@ #define debug( fmt, ... ) /* */ #endif // DEBUG + #ifdef ENABLE_TRACE_TO_FILE + DLL_PRIVATE void write_trace(const char *fmt, ...); + #define trace_to_file( ... ) write_trace(__VA_ARGS__) + #else + #define trace( ... ) /* */ + #endif // ENABLE_TRACE_TO_FILE + #include #include #include diff --git a/src/native/screen.cc b/src/native/screen.cc index c778c75..710c8f5 100644 --- a/src/native/screen.cc +++ b/src/native/screen.cc @@ -70,6 +70,7 @@ int tn3270_get_string_at(h3270::session *ses, int row, int col, char* str, int s try { memset(str,0,sz+1); strncpy(str,ses->get_string_at(row,col,sz).c_str(),sz); + trace_to_file("%s(%d,%d,%d):\n%s\n",__FUNCTION__,row,col,sz,str); } catch(std::exception &e) { tn3270_lasterror = e.what(); return -1; @@ -79,6 +80,7 @@ int tn3270_get_string_at(h3270::session *ses, int row, int col, char* str, int s int tn3270_set_string_at(h3270::session *ses, int row, int col, const char* str) { try { + trace_to_file("%s(%d,%d):\n%s\n",__FUNCTION__,row,col,str); debug("%s(%d,%d,\"%s\")",__FUNCTION__,row,col,str); ses->set_string_at(row,col,str); } catch(std::exception &e) { diff --git a/src/native/set.cc b/src/native/set.cc index 7249194..3db2c77 100644 --- a/src/native/set.cc +++ b/src/native/set.cc @@ -63,6 +63,7 @@ int tn3270_set_cursor_addr(h3270::session *ses, int addr) { int tn3270_set_charset(h3270::session *ses, const char* str) { try { + trace_to_file("%s: \"%s\" -> \"%s\"",__FUNCTION__,ses->get_display_charset().c_str(),str); ses->set_display_charset(NULL, str); } catch(std::exception &e) { tn3270_lasterror = e.what(); -- libgit2 0.21.2