gdb: print doesn't recognize variables with non-standard names or characters?

Novicaine

I'm writing a little BASIC compiler using LLVM, everything works fine. I'm trying to get debugging to work, and it's going fine, but I have a weird issue with variable names and GDB's print statement.

A little background on BASIC for those not familiar:

In BASIC, variable names use a symbol on the end to determine their type. So a variable x% would be integer, and variable x$ would be a string, and both can co-exist.

The statement DEFINT A-Z means that any variable starting with any letter from A to Z will be type INT, even without the trailing %. But, internally, my compiler will store the name mangled with the trailing % to avoid overlap with another variable with a trailing $.

Here is my little test program:

defint a-z

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

So 'x' is actually stored internally and put into the symbol table as x%.

OK, so I load my compiled EXE into 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.

At this point, you can see that GDB recognizes the symbol x% because it recognizes and display it's address. But the following "print" fails:

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

Hmmm... that's interesting ... it dropped the % symbol.

But I can look at the memory location where x% is stored and this looks correct:

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

If I show all symbols I get this as expected:

(gdb) info variables
All defined variables:

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

Continuing on, to show that x% does get modified by the code:

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

And as you can see, the memory that GDB thinks x% is at is definitely updated.

For some reason, the "print" command doesn't like the % symbol.

Here is the "info source" results on this module, you can see I didn't specify C as the language:

(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.

Any ideas for workarounds? I've been searching and searching and can't find a solution.

Thanks!

user184968

gdb simply interprets your command as modulo operation. It is not an error in gdb.

See, info source shows minimal for your file. This is from gdb's doc: http://sourceware.org/gdb/current/onlinedocs/gdb/Unsupported-Languages.html#Unsupported-Languages

In addition to the other fully-supported programming languages, GDB also provides a pseudo-language, called minimal. It does not represent a real programming language, but provides a set of capabilities close to what the C or assembly languages provide.

So, what does this warning in your debugging session mean?

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

Since minimal is a set of capabilities close C then gdb must iterpret this as trying to get remainder of division (http://en.wikipedia.org/wiki/Modulo_operation) - according to C programming language rules. So x is left arg, % is operation and the right arg is missing.

Let me show you example. This is a test C++ program that shows the minimal debugging session:

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

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

And this is a debugging session:

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.

Look -- No symbol "kk" in current context, the same error that you have.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

gdb: print doesn't recognize variables with non-standard names or characters?

From Dev

Xamarin randomly doesn't recognize names

From Dev

Seaborn doesn't recognize column names

From Dev

Android doesn't recognize french characters

From Dev

JavaScript doesn't recognize Turkish characters

From Dev

print doesn't recognize barewords as parameter?

From Dev

print doesn't recognize barewords as parameter?

From Dev

GDB doesn't print the output in signed decimal

From Dev

GDB doesn't print the output in signed decimal

From Dev

Why methods in onCreate() doesn't recognize variables?

From Dev

VBA SQL doesn't recognize assigned variables

From Dev

Is using non standard English characters in c# names a bad practice?

From Dev

It doesn't print the names on screen with fetch call

From Dev

plot_ly doesn't recognize column names

From Dev

Powershell(cmd too) doesn't recognize special characters "ą, ę" etc

From Dev

Continuous Deployment with Codeship doesn't recognize environment variables

From Dev

Swift - Xcode doesn't recognize existing member variables

From Dev

Cloudformation Doesn't Recognize Shell Variables in UserData Scripts

From Dev

g++ doesn't recognize standard 14 (-std=c++14)

From Dev

Why does reading a file that doesn't exist print garbage characters?

From Dev

Contact form doesn't accept non-Latin characters

From Dev

Route with non-English characters doesn't work with Laravel Collective

From Dev

Route with non-English characters doesn't work with Laravel Collective

From Dev

find command doesn't print non pruned items

From Dev

Functions don't recognize variables

From Dev

Print the values of variables of a structure array in GDB

From Dev

Print the values of variables of a structure array in GDB

From Dev

countrycode() doesn't recognize Kosovo?

From Dev

Compiler doesn't recognize flags

Related Related

  1. 1

    gdb: print doesn't recognize variables with non-standard names or characters?

  2. 2

    Xamarin randomly doesn't recognize names

  3. 3

    Seaborn doesn't recognize column names

  4. 4

    Android doesn't recognize french characters

  5. 5

    JavaScript doesn't recognize Turkish characters

  6. 6

    print doesn't recognize barewords as parameter?

  7. 7

    print doesn't recognize barewords as parameter?

  8. 8

    GDB doesn't print the output in signed decimal

  9. 9

    GDB doesn't print the output in signed decimal

  10. 10

    Why methods in onCreate() doesn't recognize variables?

  11. 11

    VBA SQL doesn't recognize assigned variables

  12. 12

    Is using non standard English characters in c# names a bad practice?

  13. 13

    It doesn't print the names on screen with fetch call

  14. 14

    plot_ly doesn't recognize column names

  15. 15

    Powershell(cmd too) doesn't recognize special characters "ą, ę" etc

  16. 16

    Continuous Deployment with Codeship doesn't recognize environment variables

  17. 17

    Swift - Xcode doesn't recognize existing member variables

  18. 18

    Cloudformation Doesn't Recognize Shell Variables in UserData Scripts

  19. 19

    g++ doesn't recognize standard 14 (-std=c++14)

  20. 20

    Why does reading a file that doesn't exist print garbage characters?

  21. 21

    Contact form doesn't accept non-Latin characters

  22. 22

    Route with non-English characters doesn't work with Laravel Collective

  23. 23

    Route with non-English characters doesn't work with Laravel Collective

  24. 24

    find command doesn't print non pruned items

  25. 25

    Functions don't recognize variables

  26. 26

    Print the values of variables of a structure array in GDB

  27. 27

    Print the values of variables of a structure array in GDB

  28. 28

    countrycode() doesn't recognize Kosovo?

  29. 29

    Compiler doesn't recognize flags

HotTag

Archive