What's wrong with my freebasic - gdb environment ?

New to FreeBASIC? Post your questions here.
Post Reply
Simone47
Posts: 8
Joined: Oct 29, 2020 20:25

What's wrong with my freebasic - gdb environment ?

Post by Simone47 »

Hello.
I am just getting started with gdb, trying to debug an experimental freebasic program.
With very disappointing results.
My test program (prova.bas) is very simple: just a couple of integer variables (named c and ctr) and a short loop to increment their values.

This is my console command to compile the program: fbc -g prova.bas
And these are my console commands under gdb, with some of their answers:
file prova
break 7
Breakpoint 1 at 0x4024fa: file prova.bas, line 7.
run
Starting program: /home/simone/Provemie/prova
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Breakpoint 1, main (__FB_ARGC__$0=1, __FB_ARGV__$0=0x7fffffffdea8) at prova.bas:7
print ctr
No symbol "ctr" in current context. ← ?
print c
$1 = {i = {0, 1072693248}, d = 1} ← !??

I suppose there is something wrong with my installation.
Any suggestion?
Many thanks in advance
Simone

PS:
My environment:
an old 64 bit machine (Dell GX620; 4GB); Linux Mint 20 with Cinnamon 4.6.7; fbc 1.07.1; Geany 1.36; gdb 9.2.

My source statements:
1 rem prova.bas (prove gdb)
2 dim as integer ctr,c
3 ctr=0
4 for c=1 to 3
5 ctr=ctr+1
6 next c
7 print ctr
8 sleep
9 end
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: What's wrong with my freebasic - gdb environment ?

Post by caseih »

Variable names are mangled by the FB compiler, so "c" ends up being something like C$0. ctr becomes something like CTR$0.

I tend to use a graphical front-end to gdb, such as the venerable ddd program. Or if you want something more modern, try the kdbg program (a KDE plasma app).
Dinosaur
Posts: 1478
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Re: What's wrong with my freebasic - gdb environment ?

Post by Dinosaur »

Hi All

Or try Gede , I am very pleased with that.

Regards

Edit: And I use it with Linux Mint 19.3 on a similar Jurassic machine as my age.
Simone47
Posts: 8
Joined: Oct 29, 2020 20:25

Re: What's wrong with my freebasic - gdb environment ?

Post by Simone47 »

Hi. First of all, thank you both for the replies.
Now I’ll tell you why I’m beginning to believe that my machine is housing some goblins.
After reading Caseih indications, I immediately did some more tests with gdb.
First results made me happy; quite surprised but also happy: print commands actually gave the expected responses when associates with names CTR$0 and C$0 !!
So I thought I could dare more and try with a graphic interface.
I searched and installed ddd. The first launch failed because it told me it was waiting to start xterm. So I installed xterm too and reissued the command: ddd prova.
This time it worked and, at the first break, the display of the contents of my “ctr” variable worked too.
Very strangely, however, the display of the variable named “c” did not work: again, its content was shown as: {i = {0, 1072693248}, d = 1} !!?

At this point the strangest things began to add up.
1) I went back to run the initial test with gdb, giving exactly the same commands as before, until the first break and ….: print CTR$0 and print C$0 didn’t work any more (alway that message “No symbol <var> in current context”) !!
2) So I went back to run ddd and ….: impossible to work with, because of the small hourglass icon showing that the program was waiting for something … and xterm didn’t come up. I tried to run ddd again after running xterm first: no way !
I'm very confused.
Now I think I'll sleep on it for a while.
Then I'll be tempted by Dinosaur's suggestion regarding Gede as well.
But first I will try to read up well because I understand that I will have to try my hand at a real compilation under linux. And for me it will be the first time.
A warm greeting.
Simone
Post Reply