<div dir="ltr">Using 'valgrind', along with gctorture(TRUE) can help track down these bugs. E.g.<div><br></div><div><div>% R --debugger valgrind</div><div>==8445== Memcheck, a memory error detector</div><div>==8445== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.</div><div>==8445== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info</div><div>==8445== Command: /home/R/R-3.3.1/lib/R/bin/exec/R</div></div><div>... bunch of warnings from dl-load, etc., at startup ...</div><div><div>> library(Rcpp)</div><div>> cppFunction("IntegerVector runif_int2() { return wrap(floor(runif(1000000))); }")</div><div>> set.seed(1)</div><div>> gctorture(TRUE)</div><div>> z <- runif_int2()</div><div>> z <- runif_int2()</div><div>==8445== Invalid read of size 8</div><div>==8445==    at 0x4ED9465: Rf_coerceVector (coerce.c:495)</div><div>==8445==    by 0x100A3191: SEXPREC* Rcpp::internal::basic_cast<13>(SEXPREC*) (r_cast.h:58)</div><div>==8445==    by 0x100A1AD7: runif_int2() (r_cast.h:67)</div><div>==8445==    by 0x100A1F85: sourceCpp_1_runif_int2 (file20fd25662b99.cpp:16)</div><div>==8445==    by 0x4F0BD17: do_dotcall (dotcode.c:1251)</div><div>==8445==    by 0x4F4C2BA: Rf_eval (eval.c:713)</div><div>==8445==    by 0x4F4D646: Rf_applyClosure (eval.c:1134)</div><div>==8445==    by 0x4F4BE9E: Rf_eval (eval.c:732)</div><div>==8445==    by 0x4F4F68D: do_set (eval.c:2196)</div><div>==8445==    by 0x4F4C0C2: Rf_eval (eval.c:685)</div><div>==8445==    by 0x4F730E1: Rf_ReplIteration (main.c:258)</div><div>==8445==    by 0x4F73430: R_ReplConsole (main.c:308)</div><div>==8445==  Address 0x115ea048 is not stack'd, malloc'd or (recently) free'd</div><div>==8445==</div><div><br></div><div> *** caught segfault ***</div><div>address 0x115ea048, cause 'memory not mapped'</div><div><br></div><div>Traceback:</div><div> 1: .Primitive(".Call")(<pointer: 0x100a1f40>)</div><div> 2: runif_int2()</div><div><br></div><div>Possible actions:</div><div>1: abort (with core dump, if enabled)</div><div>2: normal R exit</div><div>3: exit R without saving workspace</div><div>4: exit R saving workspace</div></div><div><div>Selection: 3</div><div>==8445==</div><div>==8445== HEAP SUMMARY:</div><div>==8445==     in use at exit: 48,075,889 bytes in 14,975 blocks</div><div>==8445==   total heap usage: 64,852 allocs, 49,877 frees, 107,416,930 bytes allocated</div><div>==8445==</div><div>==8445== LEAK SUMMARY:</div><div>==8445==    definitely lost: 0 bytes in 0 blocks</div><div>==8445==    indirectly lost: 0 bytes in 0 blocks</div><div>==8445==      possibly lost: 0 bytes in 0 blocks</div><div>==8445==    still reachable: 48,075,889 bytes in 14,975 blocks</div><div>==8445==         suppressed: 0 bytes in 0 blocks</div><div>==8445== Rerun with --leak-check=full to see details of leaked memory</div></div><div><br></div><div><br></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature">Bill Dunlap<br>TIBCO Software<br>wdunlap <a href="http://tibco.com" target="_blank">tibco.com</a></div></div>
<br><div class="gmail_quote">On Thu, Aug 11, 2016 at 4:28 AM, Rajen Shah <span dir="ltr"><<a href="mailto:rds37@cam.ac.uk" target="_blank">rds37@cam.ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span style="font-size:12.8px">Hello,</span><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">I am having trouble debugging a package that appears to work fine on Mac operating systems but crashes on Unix and Windows.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">I have found the following example that crashes on my Windows setup (session info copied below)</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><div>IntegerVector runif_int2() {</div><div>  return wrap(floor(runif(1000000)));</div><div>}</div></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">When this is called about 5-10 times in succession R crashes (e.g. with set.seed(1), but this doesn't seem to matter).</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Any ideas about why this crashes would be much appreciated. To be clear, I am not looking for an alternative to the above code (which simply produces a vector of zeroes), but would like to know what aspects of this cause a crash so I know what code structures may be causing problems in the package I am creating. The code does not appear to crash on Mac and I have yet to try it on Unix.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Many thanks in advance,</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Rajen</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Session info:</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><div>R version 3.3.1 (2016-06-21)</div><div>Platform: x86_64-w64-mingw32/x64 (64-bit)</div><div>Running under: Windows >= 8 x64 (build 9200)</div><div><br></div><div>locale:</div><div>[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252</div><div>[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    </div><div><br></div><div>attached base packages:</div><div>[1] stats     graphics  grDevices utils     datasets  methods   base     </div><div><br></div><div>loaded via a namespace (and not attached):</div><div>[1] tools_3.3.1</div></div></div>
<br>______________________________<wbr>_________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-<wbr>project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" rel="noreferrer" target="_blank">https://lists.r-forge.r-<wbr>project.org/cgi-bin/mailman/<wbr>listinfo/rcpp-devel</a><br></blockquote></div><br></div>