首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何调试“程序接收信号SIGSEGV:分段故障”错误

如何调试“程序接收信号SIGSEGV:分段故障”错误
EN

Stack Overflow用户
提问于 2018-08-21 22:20:37
回答 1查看 2.9K关注 0票数 2

我正在运行一个Fortran exe,我得到了错误:

代码语言:javascript
复制
 set_nml_output Echo NML values to log file only
 Trying to open namelist log dart_log.nml
 PE 0: initialize_mpi_utilities:  Running with            8  MPI processes.

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:

然后我尝试使用gdb来查找一些内容,它报告说

代码语言:javascript
复制
[New LWP 9883]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Failed to read a valid object file image from memory.
Core was generated by `./filter'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00002af8e021390c in netcdf::nf90_open (
    path=<error reading variable: value requires 57959040 bytes, which is more than max-value-size>, mode=0, 
    ncid=<error reading variable: Cannot access memory at address 0x7ffe439346b0>, 
    chunksize=<error reading variable: Cannot access memory at address 0x0>, 
    cache_size=<error reading variable: Cannot access memory at address 0x7ffe43934530>, 
    cache_nelems=<error reading variable: Cannot access memory at address 0x7ffe43934528>, 
    cache_preemption=<error reading variable: Cannot access memory at address 0x7ffe439345a0>, 
---Type <return> to continue, or q <return> to quit---
    comm=<error reading variable: Cannot access memory at address 0x7ffe439345a8>, 
    info=<error reading variable: Cannot access memory at address 0x7ffe439345b0>, 
    _path=<error reading variable: Cannot access memory at address 0x7ffe439345b8>) at netcdf4_file.f90:39
39  netcdf4_file.f90: No such file or directory.
(gdb) bt
#0  0x00002af8e021390c in netcdf::nf90_open (
    path=<error reading variable: value requires 57959040 bytes, which is more than max-value-size>, mode=0, 
    ncid=<error reading variable: Cannot access memory at address 0x7ffe439346b0>, 
    chunksize=<error reading variable: Cannot access memory at address 0x0>, 
    cache_size=<error reading variable: Cannot access memory at address 0x7ffe43934530>, 
    cache_nelems=<error reading variable: Cannot access memory at address 0x7ffe43934528>, 
    cache_preemption=<error reading variable: Cannot access memory at address 0x7ffe439345a0>, 
    comm=<error reading variable: Cannot access memory at address 0x7ffe439345a8>, 
    info=<error reading variable: Cannot access memory at address 0x7ffe439345b0>, 
    _path=<error reading variable: Cannot access memory at address 0x7ffe439345b8>) at netcdf4_file.f90:39
Backtrace stopped: Cannot access memory at address 0x7ffe43934598

netcdf4_file.f90:39如下图所示:

代码语言:javascript
复制
if (present(cache_size) .or. present(cache_nelems) .or. &
       present(cache_preemption)) then
     ret = nf_get_chunk_cache(size_in, nelems_in, preemption_in)
     if (ret .ne. nf90_noerr) then
        nf90_open = ret
        return
     end if
     if (present(cache_size)) then
        size_out = cache_size     #### line 39
     else
        size_out = size_in
     end if
     if (present(cache_nelems)) then
        nelems_out = cache_nelems
     else
        nelems_out = nelems_in
     end if

netcdf的版本是否与问题相关,或者应该修改某些设置?

谁能给我一些建议,如何解决这个问题,因为我不是很熟悉这些。提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2018-08-22 19:15:11

分段错误真的很难调试,但下面是我要做的几件事:

使用调试符号和运行时检查进行编译。这些标志依赖于编译器,但以下是用于gfortran与英特尔Fortran的标志:

代码语言:javascript
复制
gfortran     ifort         effect
------------------------------------------------------
-g           -g            Stores the code inside the binary
-O0          -O0           Disables optimisation
-fbacktrace  -traceback    More informative stack trace
-Wall        -warn all     Enable all compile time warnings
-fcheck=all  -check all    Enable run time checks

幸运的是,当您的程序在以这种方式编译后崩溃时,将更容易推断出哪里出了问题。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51950805

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档