使用gdb调试Fortran:显示所有变量的名称,但不显示其内容 [英] Debugging Fortran with gdb: Display names of all variables, but not their contents

查看:435
本文介绍了使用gdb调试Fortran:显示所有变量的名称,但不显示其内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用gdb调试一个Fortran程序,当我在一个断点时,尝试用 p / d cs(ii,inti + 1)打印二维数组的元素, 我收到消息在当前上下文中没有符号cs。但是, cs 在当前范围内显然可用 - 我刚刚步过了使用它 - 虽然没有声明,但在模块级别(在同一个模块中)。



我试图找出什么变量可以查看是否可以弄清楚为什么 gdb 不会让我查看这个内容。 info locals 没有做太多的事情,因为我不是在一个局部变量之后,而信息变量永远完成,因为我有几个矩阵与10 000行,它不仅打印名称,而且打印每个变量的内容。



有没有仅打印当前范围中可用的所有变量的名称(可能维度)?当我问 - 有没有什么明显的,我错过了这里,解释了为什么我不能查看 cs(ii,inti + 1)的内容? / p>

解决方案

对于原始当前上下文中没有符号cs的问题,我会快速峰值在反汇编以查看函数是否内联。



只需打印全局变量的名称和类型即可通过Python脚本实现。



将其另存为list-globals.py

  import gdb 
block = gdb .block_for_pc(long(gdb.parse_and_eval('$ pc')))。全局块
块中的符号:
gdb.write('%s:%s\\\
'%(symbol.print_name ,symbol.type))

然后运行:



开始
(gdb)源代码列表 - globals.py

您的gdb需要使用Python脚本编译才能启用。


I'm debugging a Fortran program with gdb, and when, at a breakpoint, I try to print an element of a 2-dimensional array with p/d cs(ii,inti+1) I get the message No symbol cs in current context. However, cs is clearly available in the current scope - the line I just stepped over used it - although not declared thare, but on module level (in the same module).

I tried to find out what variables are available, to see if I could figure out why gdb wouldn't let me view the contents of this one. info locals didn't do me much good, since I'm not after a local variable, and info variables takes forever to complete, because I have a couple of matrices with 10 000 rows and it prints not only the names, but also the contents, of each variable.

Is there a way to print only the names (and possibly dimensions) of all variables available in the current scope? And while I'm asking - is there something obvious I've missed here that explains why I can't view the contents of cs(ii,inti+1)?

解决方案

For the original "No symbol cs in current context" problem, I'd take a quick peak at the disassembly to see if the function is being inlined.

Just printing the names and types of global variables can be achieved with Python scripting.

Save this to list-globals.py

import gdb
block = gdb.block_for_pc(long(gdb.parse_and_eval('$pc'))).global_block
for symbol in block:
    gdb.write('%s: %s\n' % (symbol.print_name, symbol.type))

Then run:

$ gdb /bin/true
(gdb) start
(gdb) source list-globals.py

Your gdb needs to be compiled with Python scripting enabled though.

这篇关于使用gdb调试Fortran:显示所有变量的名称,但不显示其内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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