gdbsource error
There is a closed post on this subject and while I have tried various suggestions, none have worked for me on windows. Hans Skaug is here in San Diego teaching a TMB class so I decided to explore this further and came up with the following solution.
For Windows, gdbsource calls
if (.Platform$OS.type == "windows") {
return(.gdbsource.win(file, interactive))
In that function it calls system with cmd <- paste("gdb Rterm -x", gdbscript)
This then uses gdb.exe in Rtools/bin (first in path) which contains a gdb.exe and a gdb64.exe. Presumably the first is for R32 and the second for R64. I use R64 and this appears to be the source of the problem. I removed gdb.exe and renamed gdb64.exe to gdb.exe. That is all it took for it to work. I was unable to get the 32bit version to work however but no loss for me.
However, I also found that gdbsource did not work if you had used precompile(). Not sure why but you can always remove with clean=TRUE while debugging code.
A suggestion would be to include a switch in .gdbsource.win to use gdb.exe if run in R32 and gdb64.exe for R64 and then the user would not need to make any changes.
Let me take the good news first:
gdbsource now seems to work on Windows (R 3.5.0 and Rtools 3.5.0.1).
Even better is that flag="-O0 -g" is working, which gives much
better debugging than "-O1 -g".
For installation under Windows I followed:
https://github.com/kaskr/adcomp/wiki/Windows-installation
On the negative side I find that interactive=FALSE, as in:
gdbsource("file.R",interactive=FALSE)
is not working well (but it has worked for me in previous versions of R/Rtools) For instance, when the R script contains a syntax error I get the confusing message
Error in line:length(x) : argument of length 0
which also occurs if gdb itself is not working properly
For windows using facing problems, I recommend to try gdbsource both with
"interactive=TRUE" and "interactive=FALSE"
Details about version:
R.version
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 3
minor 5.0
Rtools version 3.5.0.1
@skaug
I seem to recall that -O0 -g only works for toy models such as
linreg.cpp whereas something more complex like sam.cpp fails. Has
that changed with R 3.5.0 and Rtools 3.5.0.1 ?
Thanks. I had only tried on a toy model. sam.cpp still does not work. In fact, it will
not even compile with -O0 -g.