[fpc-devel] issue examining pointer/array/record elements with GDB

Seth Grover sethdgrover at gmail.com
Thu Sep 8 18:03:40 CEST 2011


Good morning/afternoon/evening everyone (depending on where you are)!

I've often run into something annoying debugging FPC programs with
GDB, so I boiled it down a little bit into something that can be
reproduced.

Given this simple program:

=============================================
program project1;

{$mode objfpc}{$H+}

type

  Record1 = record
    a : integer;
    b : integer;
  end;

  Record1Array = array of Record1;

  Record2 = record
    c : integer;
    recs : Record1Array;
  end;
  PRecord2 = ^Record2;

var
  myRec2 : PRecord2;
  i : integer;

begin
  new(myRec2);
  myRec2^.c := 16;
  SetLength(myRec2^.recs, myRec2^.c);
  for i := 0 to myRec2^.c-1 do begin
    myRec2^.recs[i].a := i;
    myRec2^.recs[i].b := myRec2^.c - i - 1;
    writeln(myRec2^.recs[i].a, ',', myRec2^.recs[i].b);
  end;
  dispose(myRec2);
end.
=============================================

If I compile this program with FPC 2.4.4 with debugging (-g), line
numbers in backtraces (-gl), and dwarf debug information (-gw), then
fire up GDB (I'm in Linux, by the way), put a breakpoint at the
writeln, then run, observe what happens:

(gdb) print MYREC2^
$3 = {C = 16, RECS = 0x7ffff7fee050}

(gdb) print MYREC2^.RECS
$4 = (^RECORD1ARRAY) 0x7ffff7fee050

(gdb) print MYREC2^.RECS^[I]
$5 = {A = 0, B = 15}

(gdb) print MYREC2^.RECS^[I].A
Type RECORD1ARRAY is not a structure or union type.

GDB seems to be able to keep track of things find up to the point
where I try to access an element of the records which comprise the
array. I can print MYREC2^.RECS^[I] just fine, but not print
MYREC2^.RECS^[I].A.

Is this a bug in the GDB info generated by the compiler, or a bug in GDB itself?

Thanks,

-SG

--
This email is fiction. Any resemblance to actual events
or persons living or dead is purely coincidental.

Seth Grover



More information about the fpc-devel mailing list