您为GFORTRAN调试器/编译器设置什么标志来捕获错误的代码? [英] What flags do you set for your GFORTRAN debugger/compiler to catch faulty code?

查看:232
本文介绍了您为GFORTRAN调试器/编译器设置什么标志来捕获错误的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为在任何教科书中都不会发现,因为回答这个需要经验。
我目前正在测试/验证我的代码/狩猎bug,使其进入生产状态,任何错误都会导致许多人遭受痛苦。黑暗的一面。




  • 当您为Fortran编译程序进行调试时,您设置了什么样的标志?


  • 您为生产系统设置了什么样的标志?


  • 你部署?




生产版本使用 ifort 作为编译器我用 gfortran 进行测试。我做错了吗?

解决方案

最低限度






-Og / - O0



-O0 基本上告诉编译器没有优化。优化器可以删除一些局部变量,合并一些代码块等,并且作为结果可以使调试变得不可预测。 -O0 选项的代码是非常慢的代码执行,但是从4.8版本的GCC编译器(包括Fortran一)开始接受新引入的优化级别 -Og


-Og



优化调试经验。 -Og允许不干扰调试的优化。它应该是标准编辑 - 调试循环的优化级别,提供合理的优化级别,同时保持快速编译和良好的调试体验。


所以,如果可能,使用 -Og ,否则使用 -O0






-g



此选项实际上可以通过请求编译器生成调试调试信息旨在由交互式调试器(GDB)使用。






附加



有很多他们。在我看来最有用的是:



-Wall 来启用有关用户认为可疑的建筑的所有警告,并且这些警告很容易避免(或修改以防止警告),甚至与宏一起使用。



-Wextra 以启用一些不被-Wall启用的额外的警告标志。



-pedantic 来生成关于gfortran支持但不属于官方Fortran 95标准的语言功能的警告。可能会更加迂腐,并使用 -std = f95 标志为警告成为错误。



-fimplicit-none 指定没有隐式打字是允许的,除非被明确的IMPLICIT语句覆盖,这相当于在每个过程的开始添加隐式none。



-fcheck = all 启用运行时测试,例如数组边界检查。



-fbacktrace 指定,当遇到运行时错误或致命的信号我(分段错误,非法指令,总线错误或浮点异常),Fortran运行时库应该输出错误的回溯。


I think I won't find that in any textbook, because answering this takes experience. I am currently in the stage of testing/validating my code / hunting bugs to get it into production state and any errors would lead to many people suffering e.g. the dark side.

  • What kind of flags do you set when you compile your program for Fortran for debugging purposes?

  • What kind of flags do you set for the production system?

  • What do you do before you deploy?

The production version uses ifort as a compiler, yet I do my testing with gfortran. Am I doing it wrong?

解决方案

Bare minimum


-Og/-O0

-O0 basically tells the compiler to make no optimisations. Optimiser can remove some local variables, merge some code blocks, etc. and as an outcome it can make debugging unpredictable. The price for -O0 option is very slow code execution, but starting from version 4.8 GCC compilers (including the Fortran one) accept a newly introduced optimisation level -Og:

-Og

Optimize debugging experience. -Og enables optimizations that do not interfere with debugging. It should be the optimization level of choice for the standard edit-compile-debug cycle, offering a reasonable level of optimization while maintaining fast compilation and a good debugging experience.

So, if possible use -Og, otherwise use -O0.


-g

This option actually makes debugging possible by requesting the compiler to produce debugging information intended to be used by interactive debugger (GDB).


Addititonal

There are a plenty of them. The most useful in my opinion are:

-Wall to "enable all the warnings about constructions that some users consider questionable, and that are easy to avoid (or modify to prevent the warning), even in conjunction with macros."

-Wextra to "enable some extra warning flags that are not enabled by -Wall."

-pedantic to generate warnings about language features that are supported by gfortran but are not part of the official Fortran 95 standard. It possible to be even more "pedantic" and use -std=f95 flag for warnings to become errors.

-fimplicit-none to "specify that no implicit typing is allowed, unless overridden by explicit IMPLICIT statements. This is the equivalent of adding implicit none to the start of every procedure."

-fcheck=all to "enable run-time tests", such as, for instance, array bounds checks.

-fbacktrace to "specify that, when a runtime error is encountered or a deadly signal is emitted (segmentation fault, illegal instruction, bus error or floating-point exception), the Fortran runtime library should output a backtrace of the error."

这篇关于您为GFORTRAN调试器/编译器设置什么标志来捕获错误的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆