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

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

问题描述

我想我不会在任何教科书中找到它,因为回答这个需要经验.我目前正处于测试/验证我的代码/寻找错误以使其进入生产状态的阶段,任何错误都会导致许多人遭受痛苦,例如阴暗面.

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.

  • 当您为 Fortran 编译程序以进行调试时,您设置了哪些标志?

  • 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?

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

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

推荐答案

最低限度

<小时>

-Og/-O0

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

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

优化调试体验.-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.

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

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

该选项实际上通过请求编译器生成供交互式调试器 (GDB) 使用的调试信息来实现调试.

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

有很多.我认为最有用的是:

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

-Wall 以启用一些用户认为有问题的关于结构的所有警告,并且即使与宏结合使用也很容易避免(或修改以防止警告)."

-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 以启用 -Wall 未启用的一些额外警告标志."

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

-pedantic 生成有关 gfortran 支持但不属于官方 Fortran 95 标准的语言功能的警告.可能更迂腐"并使用 -std=f95 标志将警告变为错误.

-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 以指定不允许隐式类型,除非被显式 IMPLICIT 语句覆盖.这相当于在每个过程的开头添加隐式 none."

-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 以启用运行时测试",例如数组边界检查.

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

-fbacktrace 以指定也就是说,当遇到运行时错误或发出致命信号(分段错误、非法指令、总线错误或浮点异常)时,Fortran 运行时库应输出错误的回溯."

-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天全站免登陆