Sign in Join

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

Mailing lists / fpc-devel / 2011-09

issue examining pointer/array/record elements with GDB

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Seth Grover

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

Reply by email

Martin
to Seth Grover
Seth Grover wrote 18 lines
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.

I do not know whaere the erro comes from.

just tried with gdb 7.3.2 on w32 fpc trunk
- same error
- but
Record1(myrec2^.RECS^[0]).a
does work

So if all you need is a way to get the data....

Reply by email

Seth Grover
to Seth Grover: Good morning/afternoon/evening everyone (depending on where you are)! I've often run into…

Martin said:

Show quoted text 9 lines
I do not know whaere the erro comes from. just tried with gdb 7.3.2 on w32 fpc trunk - same error - but Record1(myrec2^.RECS^[0]).a does work So if all you need is a way to get the data....

Thanks. You're correct, and that's exactly what I've been doing as a workaround. It's less convenient than having it "just work," because often at the point where I am in the code when I run across this (which is usually more complicated than the simple example I provided) it requires me opening up other units and searching for the record definitions so I can remember what types the members are.

-SG

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

Reply by email