Hi!
Debug cpp files generated from epp ones are a nightmare.
The debugger goes/shows cpp line numbers where you want to see epp lines.
Gpre has some support for #line directive but was not working properly.
Attached I put a patch to fix it. It's rudimentary, it overloads std C
functions (*put*, *print*) to not change gpre too much.
It does changes only the internal language used in our build.
Here is a gdb session where I put a breakpoint in METD_get_relation
http://pastebin.com/raw/B4qbQVrE
Lines from 1388-1416 are the epp lines. You see the epp filename where
gdb breaks.
Lines from 3357-3364 are the cpp lines. You see the cpp filename with bt.
I want this. See generated code in the generated file and source code in
the source file.
I have no idea if this works great in Visual Studio, I believe it's even
great than in gdb. When I used Visual Studio, sometimes I edited cpp
files while debugging and lost changes.
What do you think and can you test it in Windows?
Adriano
diff --git a/src/gpre/gpre.cpp b/src/gpre/gpre.cpp
index b029dd7..3218599 100644
--- a/src/gpre/gpre.cpp
+++ b/src/gpre/gpre.cpp
@@ -674,13 +674,9 @@ int main(int argc, char* argv[])
gpreGlob.sw_auto = false;
break;
- case IN_SW_GPRE_N:
- sw_lines = false;
- break;
-
case IN_SW_GPRE_O:
sw_standard_out = true;
- gpreGlob.out_file = stdout;
+ gpreGlob.out_file.open(stdout);
break;
case IN_SW_GPRE_R:
@@ -829,7 +825,7 @@ int main(int argc, char* argv[])
fprintf(stderr, "gpre: output file %s would duplicate input\n", out_file_name);
CPR_exit(FINI_ERROR);
}
- if ((gpreGlob.out_file = fopen(out_file_name, FOPEN_WRITE_TYPE)) == NULL)
+ if (!gpreGlob.out_file.open(out_file_name, FOPEN_WRITE_TYPE))
{
fprintf(stderr, "gpre: can't open output file %s\n", out_file_name);
CPR_exit(FINI_ERROR);
@@ -857,7 +853,7 @@ int main(int argc, char* argv[])
if (!sw_standard_out)
{
- fclose(gpreGlob.out_file);
+ gpreGlob.out_file.close();
if (gpreGlob.errors_global)
unlink(out_file_name);
}
@@ -2619,6 +2615,16 @@ static void pass2( SLONG start_position)
fputc('\n', gpreGlob.out_file);
}
+ if (!continue_flag &&
+ sw_lines &&
+ gpreGlob.sw_language == lang_internal &&
+ gpreGlob.out_file.filename &&
+ !(action->act_type == ACT_routine && !action->act_object))
+ {
+ fprintf(gpreGlob.out_file, "\n#line %"SLONGFORMAT" \"%s\"",
+ gpreGlob.out_file.line + 2, gpreGlob.out_file.filename);
+ }
+
suppress_output = false;
(*gen_routine) (action, start);
if (action->act_type == ACT_routine && !action->act_object &&
diff --git a/src/gpre/gpre.h b/src/gpre/gpre.h
index c4b256f..c752293 100644
--- a/src/gpre/gpre.h
+++ b/src/gpre/gpre.h
@@ -1516,6 +1516,112 @@ const size_t UPD_LEN = sizeof(upd);
// GPRE wide globals
+struct GpreOutFile
+{
+ GpreOutFile()
+ : file(NULL),
+ filename(NULL),
+ line(1),
+ shouldClose(false)
+ {
+ }
+
+ ~GpreOutFile()
+ {
+ close();
+ }
+
+ bool open(const char* name, const char* mode)
+ {
+ if (file)
+ close();
+
+ file = fopen(name, mode);
+ filename = strdup(name);
+ line = 1;
+ shouldClose = true;
+
+ return file != NULL;
+ }
+
+ void open(FILE* f)
+ {
+ if (file)
+ close();
+
+ file = f;
+ line = 1;
+ shouldClose = false;
+ }
+
+ void close()
+ {
+ if (file)
+ {
+ if (shouldClose)
+ fclose(file);
+ file = NULL;
+ }
+
+ if (filename)
+ {
+ free(filename);
+ filename = NULL;
+ }
+ }
+
+ FILE* file;
+ char* filename;
+ unsigned line;
+ bool shouldClose;
+
+private:
+ // copying is prohibited
+ GpreOutFile(const GpreOutFile&);
+ GpreOutFile& operator =(const GpreOutFile&);
+};
+
+inline int fputc(int c, GpreOutFile& outFile)
+{
+ if (c == '\n')
+ ++outFile.line;
+
+ return fputc(c, outFile.file);
+}
+
+inline int fputs(const char* s, GpreOutFile& outFile)
+{
+ for (const char* p = s; *p; ++p)
+ {
+ if (*p == '\n')
+ ++outFile.line;
+ }
+
+ return fputs(s, outFile.file);
+}
+
+inline int putc(int c, GpreOutFile& outFile)
+{
+ return fputc(c, outFile);
+}
+
+inline int vfprintf(GpreOutFile& outFile, const char* format, va_list ap)
+{
+ Firebird::string s;
+ s.vprintf(format, ap);
+ return fputs(s.c_str(), outFile);
+}
+
+inline int fprintf(GpreOutFile& outFile, const char* format, ...)
+{
+ va_list params;
+ va_start(params, format);
+ int ret = vfprintf(outFile, format, params);
+ va_end(params);
+
+ return ret;
+}
+
struct GpreGlobals
{
bool sw_auto;
@@ -1546,7 +1652,7 @@ struct GpreGlobals
const TEXT* default_lc_ctype;
gpre_req* requests;
gpre_lls* events;
- FILE *out_file;
+ GpreOutFile out_file;
lang_t sw_language;
int errors_global;
act* global_functions;
diff --git a/src/gpre/int_cxx.cpp b/src/gpre/int_cxx.cpp
index 53396a3..62dbe13 100644
--- a/src/gpre/int_cxx.cpp
+++ b/src/gpre/int_cxx.cpp
@@ -628,7 +628,7 @@ static void gen_variable( const act* action, int column)
{
char s[MAX_REF_SIZE];
- align(column);
+ /// ASF: Do not align to not insert blank lines in the user source code - align(column);
fprintf(gpreGlob.out_file, "%s", gen_name(s, action->act_object));
}
------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
Firebird-Devel mailing list, web interface at
https://lists.sourceforge.net/lists/listinfo/firebird-devel