Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2002-04

Strange indexing problem - gdb or fpc?

4 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

JOHN COPPENS

Hi...

I'm debugging (trying to) a program, was nearing the problem, and found this strange behaviour:

820 rconst[r+1] := x;
(gdb) print RCONST[0] // Still 0 $5 = 0
(gdb) print R
$6 = 0 // Was initialized like this (gdb) print X
$7 = 0.29999999999999999 // New value (gdb) next // Execute the rconst[r+1] := x 821 realindex := 1;
(gdb) print RCONST[0]
$8 = 0.29999999999999999 // Should've been in [1]!!! (gdb) print R
$9 = 0 // R is 0, so r+1 = 1 (gdb) print X
$10 = 0.29999999999999999

  realarray = array[1..rmax] of real;
  rconst: realarray;

BTW, RCONST[1] is 0 after the operation. Any ideas?

Is this because C arrays are 0 based? I checked the Docs, they don't mention this problem...

John

Reply by email

Pierre Muller
to JOHN COPPENS
JOHN COPPENS wrote 28 lines
Hi... I'm debugging (trying to) a program, was nearing the problem, and found this strange behaviour: 820 rconst[r+1] := x; (gdb) print RCONST[0] // Still 0 $5 = 0 (gdb) print R $6 = 0 // Was initialized like this (gdb) print X $7 = 0.29999999999999999 // New value (gdb) next // Execute the rconst[r+1] := x 821 realindex := 1; (gdb) print RCONST[0] $8 = 0.29999999999999999 // Should've been in [1]!!! (gdb) print R $9 = 0 // R is 0, so r+1 = 1 (gdb) print X $10 = 0.29999999999999999 realarray = array[1..rmax] of real; rconst: realarray; BTW, RCONST[1] is 0 after the operation. Any ideas? Is this because C arrays are 0 based? I checked the Docs, they don't mention this problem...

You need to givemore info, so that we can help you out.

1) Could you please send a short complete source
for your problem so that we can compile it also?
2) On which OS are you working?
3) Which version of GDB do you use?
4) What current language do you use?

I can maybe help (as I wrote the pascal language support for GDB) after you give us these informations.

Reply by email

JOHN COPPENS

Hi Pierre.

Here's the routine that gave the problems with gdb:

    procedure enterreal(x: real);
    var
      rr: integer;
    begin
      if r = (rmax - 1) then
        fatal(10)
      else begin
        rr := r + 1;
        rconst[rr] := x;
        realindex := 1;
        while rconst[realindex]  x do
          inc(realindex);
        if realindex > r then
          r := realindex;
      end;
    end;  { enterreal }

(This is part of the didactic Pascal-FC compiler to show concurrent processes and inter-process communication - author Alan Burns. I am extending this compiler to include a few more modern primitives; This routine stores real constants in a table, avoiding duplicates)

I am on Linux 2.4.17, using fpc 1.0.4, gdb 5.0.

When debugging, I get the strange results as described in the previous message.

John

Reply by email

Pierre Muller
to JOHN COPPENS
JOHN COPPENS wrote 20 lines
Hi Pierre. Here's the routine that gave the problems with gdb: procedure enterreal(x: real); var rr: integer; begin if r = (rmax - 1) then fatal(10) else begin rr := r + 1; rconst[rr] := x; realindex := 1; while rconst[realindex] x do inc(realindex); if realindex > r then r := realindex; end; end; { enterreal }

gdb 5.0 does not contain pascal language support,
thus your display is based on C language that does not know about arrays that are not zero based... If rconst is a one-based array, this probably explains your problem.

Show quoted text 9 lines
(This is part of the didactic Pascal-FC compiler to show concurrent processes and inter-process communication - author Alan Burns. I am extending this compiler to include a few more modern primitives; This routine stores real constants in a table, avoiding duplicates) I am on Linux 2.4.17, using fpc 1.0.4, gdb 5.0. When debugging, I get the strange results as described in the previous message.

Try to get the gdb 5.1 or 5.1.1 version that has integrated pascal language support or use the source patch to gdb for 5.0 to add this pascal language support (this will also allow you to inspect pascal sets or strings).

Accessible via the cvsweb interface
http://www.freepascal.org/develop.html#cvs
in
projects/gdbpas/v5.0/patch file.

Reply by email