【问题标题】:running R CMD install with gdb to debug malloc error使用 gdb 运行 R CMD install 以调试 malloc 错误
【发布时间】:2012-02-12 18:44:08
【问题描述】:

我写了一些代码作为一个包。当我尝试发出R CMD install mypkg 时,它会给出诸如

之类的错误
* installing to library ‘/Users/USERNAME/R/x86_64-apple-darwin11.0.0-library/2.14’
* installing *source* package ‘mypkg’ ...
** libs
*** arch - x86_64
make: Nothing to be done for `all'.
installing to /Users/USERNAME/R/x86_64-apple-darwin11.0.0-library/2.14/mypkg/libs/x86_64
** R
** preparing package for lazy loading
** help
Warning: /Users/USERNAME/temp/mypkg/man/mypkg-package.Rd:31: All text must be in a section
Warning: /Users/USERNAME/temp/mypkg/man/mypkg-package.Rd:32: All text must be in a section
*** installing help indices
** building package indices ...
** testing if installed package can be loaded
R(57533) malloc: *** error for object 0x1110005e0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
sh: line 1: 57533 Abort trap: 6           '/opt/local/lib/R/bin/R' --no-save --slave < /var/folders/2f/kxqs800n6rq09nrm8_t637g40000gr/T//Rtmp6McNDz/filee0b91bc7fa41
ERROR: loading failed
* removing ‘/Users/USERNAME/R/x86_64-apple-darwin11.0.0-library/2.14/mypkg’

为了解决这个问题,我尝试使用 gdb 运行 R CMD,但无济于事

$ R -d gdb
GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Thu Nov  3 21:59:02 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries ...
(gdb) start CMD install mypkg
<-gdb intro ->
Breakpoint 1 at 0x100000ef4: file Rmain.c, line 30.
Starting program: /opt/local/lib/R/bin/exec/x86_64/R CMD install mypkg
Breakpoint 1, main (ac=4, av=0x7fff5fbff9a8) at Rmain.c:30
30      R_running_as_main_program = 1;
(gdb) c
Continuing.
ARGUMENT 'CMD' __ignored__

ARGUMENT 'install' __ignored__

ARGUMENT 'mypkg' __ignored__

Reading symbols for shared libraries . done

R version 2.14.1 (2011-12-22)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-apple-darwin11.0.0/x86_64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

Reading symbols for shared libraries . done
Reading symbols for shared libraries . done
> 

同样,R -d gdb CMD install mypkgR CMD install mypkg -d gdb 也不起作用。我的问题是:

  1. 如何在 gdb 下运行 R CMD install?
  2. 除了在 gdb 中,还有其他方法可以调试此错误吗?

【问题讨论】:

    标签: r gdb installation malloc package


    【解决方案1】:

    错误不会发生在INSTALL本身,它是在加载你的包时发生的,所以你可以简单地运行

    R CMD INSTALL --no-test-load mypkg
    R -d gdb
    > library(mypkg)
    

    至于调试,另一个解决内存问题的有用工具是valgrind

    但请注意,您的包裹很脏,因此您应该考虑清洁它并改用R CMD build mypkg &amp;&amp; R CMD INSTALL --no-test-load mypkg_x.y.tar.gz

    【讨论】:

      【解决方案2】:

      虽然问题不在于安装,而在于@Simon 指出的运行或负载测试包,但我想我可能会在 gdb 下分享安装方式,回答我的第一个问题,

      1. 如何在 gdb 下运行 R CMD 安装?

      首先简单地通过发出R CMD build mypkg 来构建包以形成mypkg_x.y.tar.gz,然后执行

      R -d gdb
      >install.packages('path\to\package\mypkg_x.y.tar.gz')
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-08-12
        • 1970-01-01
        • 2018-05-13
        • 1970-01-01
        • 2015-09-30
        • 2010-09-20
        • 2010-10-16
        相关资源
        最近更新 更多