Is the compiler generating the wrong debug symbol?

General FreeBASIC programming questions.
Post Reply
VANYA
Posts: 1754
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Is the compiler generating the wrong debug symbol?

Post by VANYA »

Hi ALL!

Platform: Windows 32-bit

Example code freebasic:

Code: Select all

type A
    i as Long
End Type

redim shared A(5) as A

A(5).i = 10
Cannot get variable value when using GDB debugger: "A"

command GDB: print A

result:
Attempt to use a type name as an expression
caseih
Posts: 2044
Joined: Feb 26, 2007 5:32

Re: Is the compiler generating the wrong debug symbol?

Post by caseih »

Note that FBC mangles variable names to include type information. Which is a good thing in your example code, otherwise you'd have a name collision between Type A and the array variable A. GDB does not know about FB name mangling. If you want to print out the variable A, you'll need to tell gdb to print the full mangled name. If you tell gdb to dump the local variables, you should be able to see it in its mangled form. I believe the command is info locals.

You could also tell FB not to mangle the name of the variable, put the variable declaration inside an extern "C" block.
coderJeff
Site Admin
Posts: 4011
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Is the compiler generating the wrong debug symbol?

Post by coderJeff »

In this case here with -gen gas (32-bit), fbc emits debug information for both 'A' the type and 'A' the variable and both have the name 'A'. As far as I can tell there is no way to tell gdb to look at one or the other. I suspect gdb sees the 'A' type first and ignores the 'A' variable. It's been like this in fbc since forever. In other fbc backends, some name mangling goes on by default and avoids collisions. I guess most languages don't allow types and variables to have the same name.
fxm
Moderator
Posts: 11414
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Is the compiler generating the wrong debug symbol?

Post by fxm »

coderJeff wrote:I guess most languages don't allow types and variables to have the same name.
Especially since this is only allowed for very simplistic Types.
As soon as the Type has any member procedure or even just the least initializer for one of its member fields, it is forbidden.
So it's a very bad habit to use this compiler laxity.
SARG
Posts: 1565
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Is the compiler generating the wrong debug symbol?

Post by SARG »

@VANYA
Use fbdebugger. No problem with gas32 (On Windows). And I know that you know ;-)
VANYA
Posts: 1754
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: Is the compiler generating the wrong debug symbol?

Post by VANYA »

coderJeff wrote:In this case here with -gen gas (32-bit), fbc emits debug information for both 'A' the type and 'A' the variable and both have the name 'A'. As far as I can tell there is no way to tell gdb to look at one or the other. I suspect gdb sees the 'A' type first and ignores the 'A' variable. It's been like this in fbc since forever. In other fbc backends, some name mangling goes on by default and avoids collisions. I guess most languages don't allow types and variables to have the same name.
It's clear. I thought that perhaps you are not aware of this problem and perhaps there is a chance for a fix. But in your words: it has always been. And it seems that it remains only to come to terms with it.

Thanks everyone for the answers!
Post Reply