gdb:print无法识别具有非标准名称或字符的变量?

新手

我正在使用LLVM编写一个小的BASIC编译器,一切正常。我正在尝试使调试工作正常,并且一切正常,但是对于变量名和GDB的print语句,我遇到了一个奇怪的问题。

不熟悉的人可以使用BASIC的一些背景知识:

在BASIC中,变量名在末尾使用符号来确定其类型。因此,变量x%将是整数,变量x $将是字符串,并且两者可以共存。

语句DEFINT AZ表示,从A到Z的任何字母开头的任何变量都将是INT类型,即使没有尾随的%。但是,在内部,我的编译器将存储以尾随%修饰的名称,以避免与带有尾随$的另一个变量重叠。

这是我的小测试程序:

defint a-z

x = 5
y = 100
z = x + y
if x = 5 then
  print "z=";z
else
  print "z!=";z
end if

因此,“ x”实际上存储在内部,并以x%的形式放入符号表。

OK,所以我将编译后的EXE加载到GDB中...

D:\dev\BasicParser>gdb t.exe
GNU gdb (GDB) 7.4
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-mingw32".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from D:\dev\BasicParser\t.exe...done.
(gdb) b _jbc_main
Breakpoint 1 at 0x401000: file t.bas, line 1.
(gdb) r
Starting program: D:\dev\BasicParser\t.exe
[New Thread 1532.0x25b8]

Breakpoint 1, _jbc_main () at t.bas:1
1       defint a-z
(gdb) n
4       x = 5
(gdb) info address x%
Symbol "x%" is static storage at address 0x4263c4.

此时,您可以看到GDB可以识别符号x%,因为它可以识别并显示其地址。但是以下“打印”失败:

(gdb) print x%
No symbol "x" in current context.

嗯...这很有趣...它删除了%符号。

但是我可以看一下存储x%的内存位置,这看起来是正确的:

(gdb) x 0x4263c4
0x4263c4 <x%>:  0x00000000

如果显示所有符号,将按预期方式获得:

(gdb) info variables
All defined variables:

File t.bas:
static i32 x%;
static i32 y%;
static i32 z%;

继续,以显示x%确实已被代码修改:

(gdb) n
5       y = 100
(gdb) print x%
No symbol "x" in current context.
(gdb) x 0x4263c4
0x4263c4 <x%>:  0x00000005
(gdb)

如您所见,GDB认为x%所在的内存肯定已更新。

由于某些原因,“ print”命令不喜欢%符号。

这是此模块上的“信息源”结果,您可以看到我没有将C指定为语言:

(gdb) info source
Current source file is t.bas
Compilation directory is D:\dev\BasicParser
Located in D:\dev\BasicParser\t.bas
Contains 18 lines.
Source language is minimal.
Compiled with DWARF 2 debugging format.
Does not include preprocessor macro info.

有任何解决方法的想法吗?我一直在搜索,找不到解决方案。

谢谢!

184

gdb只是将您的命令解释为模运算。这不是的错误gdb

请参阅,为您的文件info source显示minimal这来自gdb的文档:http : //sourceware.org/gdb/current/onlinedocs/gdb/Unsupported-Languages.html#Unsupported-Languages

除了其他完全支持的编程语言外,GDB还提供了一种伪语言,称为minimal它不代表真正的编程语言,但是提供了一组类似于C或汇编语言所提供的功能。

那么,您的调试会话中的此警告是什么意思?

(gdb) print x%
No symbol "x" in current context.

由于minimalC是一组接近C的功能,因此gdb必须按照C编程语言规则将其解释为试图除法其余部分(http://en.wikipedia.org/wiki/Modulo_operation)。x左arg%也是如此是操作,而右arg则丢失。

让我给你举个例子。这是一个显示minimal调试会话的测试C ++程序

D:\src-c++\tests\test.vars>cat minimal.cpp

int main()
{
  int k;
  k = 1;
  k = 2;
  return 0;
}

这是一个调试会话:

D:\src-c++\tests\test.vars>gdb -q minimal.exe
Reading symbols from D:\src-c++\tests\test.vars\minimal.exe...done.
(gdb) start
Temporary breakpoint 1 at 0x4016be: file minimal.cpp, line 5.
Starting program: D:\src-c++\tests\test.vars/minimal.exe
[New Thread 2872.0x8c0]

Temporary breakpoint 1, main () at minimal.cpp:5
5         k = 1;
(gdb) show language
The current source language is "auto; currently c++".
(gdb) set language minimal
Warning: the current language does not match this frame.
(gdb) show language
The current source language is "minimal".
Warning: the current language does not match this frame.
(gdb) n
6         k = 2;
(gdb) print k
$1 = 1
(gdb) print k%
A syntax error in expression, near `'.
(gdb) print kk%
No symbol "kk" in current context.

外观-在当前上下文中没有符号“ kk”,与您遇到的错误相同。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章