A followup to my previous message about using Visual Studio to
directly debug fossil.exe (built with DEBUG=1) as:
devenv /debugexe fossil.exe
In case anyone has stumbled upon this before.
In order to have the actually compiled Fossil source-files (e.g.
main_.c translated without @ mark-up) load in the debugger, you need
to patch 'src/translate.c', so it does not insert a #line directive in
Debug mode :
patchBase::http://fossil-scm.org/index.html/info/version-1.35
---
Index: src/translate.c
==
--- src/translate.c
+++ src/translate.c
@@ -186,21 +186,28 @@
FILE *in = fopen(argv[1], "r");
if( in==0 ){
fprintf(stderr,"can not open %s\n", argv[1]);
exit(1);
}
+/* Make compiler refer to original source-file in error messages
+** This may be confusing during debug as the translated code may
+** not correspond to the un-translated source.
+** Disable this for MSVC compiler.
+*/
+#if !(defined(_MSC_VER) && defined(_DEBUG))
printf("#line 1 \"");
for(arg=argv[1]; *arg; arg++){
if( *arg!='\\' ){
printf("%c", *arg);
}else{
printf("");
}
}
printf("\"\n");
+#endif
trans(in, stdout);
fclose(in);
}else{
trans(stdin, stdout);
}
return 0;
}
---
If you wonder what this all is about -- read on for the details on how
the Fossil sources are pre-processed prior to compilation (the offical
doc http://fossil-scm.org/index.html/doc/trunk/www/makefile.wiki).
IN BRIEF: VisualStudio debugger attempts to load into editor source
files referenced in the compiled object files.
The actually compiled source-files are generated after several
pre-processing steps in the build sub-directory and named with an
underscore (e.g. msvcbld/main_c). However a special #line directive is
inserted (by translate.exe) at the beginning of each pre-processed
files to reference the original source file (e.g. src/main.c) instead
of the one resulting from pre-processing (e.g. msvcbld/main_.c):
#line 1 "..\\src\\main.c"
This is by intent, such that any error-messages would refer to the
original source files and not the pre-processed ones.
In general this may not be a big deal for step-tracing the execution
in the debugger, but it does conseal code introduced by the
pre-processors.
Thus for debugging purposes the #line directive could be omitted, at
least for MS VisualStudio compiler, so that one could follow the
actually compiled source-code.
On Sat, Oct 29, 2016 at 8:08 PM, Artur Shepilko wrote:
> BTW, in general you may use VisualStudio debugger directly without a
> solution, by manually starting the 'devenv' as:
>
> devenv /debugexe fossil.exe
>
> This launches VisualStudio in Debug mode and allows you to 'Step Into' a new
> instance of the exe (fossil.exe). By default it breaks in main().
>
> To actually see the source-code in the debugger editor window, fossil.exe
> has to be built in DEBUG mode.
>
> cd win
> buildmsvc DEBUG=1
> cd ..\msvcbld
> devenv /debugexe fossil.exe
>
> Otherwise you have to really be fluent in assembler :)
>
> Once in VS debugger, you can use all of the usual features: call-stack,
> break-points, watches, etc.
>
> Of course a solution would give you also source-referencing freedom, but if
> you know the source well and not averse to step-debbuging, this gives you
> ability to debug projects in the absence of an all-embracing solition, say
> CMake based projects etc, or indeed compex projects like fossil that
> involves a lot of code-generation.
>
> Hope this helps.
>
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users