Recent

Author Topic: gdb and object pascal objects functions properties problem  (Read 7772 times)

andreasa

  • Newbie
  • Posts: 3
gdb and object pascal objects functions properties problem
« on: August 19, 2007, 04:20:47 pm »
I have the following pascal object:
There is one function 'GETTST2' which returns a number.
Every call to GETTST2 increments the number.

Code: [Select]

  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { private declarations }
    i:integer;
  public
    { public declarations }
    function gettst2:integer;
  end;

var
  Form1: TForm1;

implementation

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
var s:string;
    j:integer;
begin
   j:=2;
   s:='Andi'+inttostr(j);
   
   showmessage(s);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  i:=1;
end;

function TForm1.gettst2: integer;
begin
   inc(i);
   result:=i;
end;    


After compilation I start gdb:

Code: [Select]

andi@athlon-mp ~/lazarus2/dbgtest $ gdb project1
GNU gdb 6.6
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...
Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) break TFORM1__BUTTON1CLICK
Breakpoint 1 at 0x807993b: file unit1.pas, line 36.
(gdb) run
Starting program: /home/andi/lazarus2/dbgtest/project1
Failed to read a valid object file image from memory.
[Thread debugging using libthread_db enabled]
[New Thread -1212778832 (LWP 25239)]
[Switching to Thread -1212778832 (LWP 25239)]

Breakpoint 1, TFORM1__BUTTON1CLICK (SENDER=0xb7b2d5f8, this=0xb7b2c1a8) at unit1.pas:36
36      begin
Current language:  auto; currently pascal
(gdb) call TFORM1__GETTST2(this)
$1 = 2
(gdb) call TFORM1__GETTST2(0)
$2 = 3
(gdb) next
37         j:=2;
(gdb)
38         s:='Andi'+inttostr(j);
(gdb)
40         showmessage(s);
(gdb) call TFORM1__GETTST2(this)
$3 = -1208243567
(gdb)


Ok, first question:
As you can see above looking at the first two call statements, it follows that the parameter to the function call is ignored. Why?
Shouldn't it be 'this'
Second, stepping three lines further, the call doesn't work anymore. See result $3. So why is the 'this' pointer not passed to the function?
It looks like if the parameter is ignored at all. Why?

Does anyone know the problem?
Please help me.

Thanks, Andreas

Bart

  • Hero Member
  • *****
  • Posts: 5713
    • Bart en Mariska's Webstek
RE: gdb and object pascal objects functions properties probl
« Reply #1 on: August 20, 2007, 11:20:25 am »
I maybe missing something here, but in your pascal code I never see you calling GetTest2 anywhere., but it shows up in gdb anyway???

Bart

andreasa

  • Newbie
  • Posts: 3
gdb and object pascal objects functions properties problem
« Reply #2 on: August 20, 2007, 01:43:30 pm »
Thats true, there is no call to GETTST2. The Code in Button1Click is just dummy code without a contribution to the problem.
We have now new information about the problem:
The 'this' pointer is passed via the eax register in the above case. Immediate after stopping at the breakpoint at TFORM1_BUTTON1CLICK the eax register has the value of the this pointer and the subsequent call to GETTST2 succeeds.
After stepping two commands the eax pointer is changed and a call to GETTST2 fails with a segmentation fault.
It seems that the gdb doesn't know to pass the paramter through eax...
Do you know why?

andreasa

  • Newbie
  • Posts: 3
gdb and object pascal objects functions properties problem
« Reply #3 on: August 20, 2007, 05:54:29 pm »
Ok the problem is, that gdb always passes paramters through the stack.
This will be a problem for the development of lazarus because this means that one can't use 'allow function calls' in the watches dialog or watch properties.
It would be necessary to compile fpc/lazarus and the project with calling convention 'stdcall' unless gdb/fpc is modified to write and read additional information about the calling convention and register usage.
Tell me if I'm wrong.

 

TinyPortal © 2005-2018