View Issue Details

IDProjectCategoryView StatusLast Update
0014542LazarusDebuggerpublic2010-12-17 16:56
ReporterDaniel GasparyAssigned ToMartin Friebe 
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Product Version0.9.29 (SVN)Product Build 
Target Version0.9.30Fixed in Version0.9.29 (SVN) 
Summary0014542: Values of Variables passed by reference are not being showed
DescriptionWhen a variable is passed by reference only its address is being displayed at debug tooltip or using the "Evaluate/modify" Menu item.

Example attached.
TagsNo tags attached.
Fixed in Revision28725
LazTarget1.0
WidgetsetGTK 2
Attached Files
  • unit1.pas (694 bytes)
    unit Unit1; 
    
    {$mode objfpc}{$H+}
    
    interface
    
    uses
      Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
      StdCtrls;
    
    type
    
      { TForm1 }
    
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { private declarations }
      public
        { public declarations }
      end; 
    
    var
      Form1: TForm1; 
    
    implementation
    
    { TForm1 }
    
    procedure test(var a: string);
    var
       b: string;
    begin
         //When I try to see the value of "A" variable only its address is being displayed
         b:=a+'5678';
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
       a: string='1234';
    begin
         test(a);
    end;
    
    initialization
      {$I unit1.lrs}
    
    end.
    
    
    unit1.pas (694 bytes)
  • unit2.pas (1,227 bytes)
    unit Unit2; 
    
    {$mode objfpc}{$H+}
    
    interface
    
    uses
      Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
    
    type
    
      { TForm2 }
    
      TForm2 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
    
        procedure byReferenceMethod(var bref: string);
      private
        { private declarations }
      public
        { public declarations }
      end; 
    
    var
      Form2: TForm2; 
    
    implementation
    
    {$R *.lfm}
    
    
    procedure byReferenceProcedure(var bref: string);
    var
       t: string;
    begin
         t:=bref + '123';
    end;
    
    { TForm2 }
    
    procedure TForm2.Button1Click(Sender: TObject);
    type
        arec = record
          c1, c2: integer;
        end;
    
    var
      s: String;
      i: Integer;
      r: real;
      a: array[1..3] of integer;
      reg: arec;
    begin
         i:=1;
         r:=1.2;
         s:='abc';
         a[1]:=1;
         a[2]:=2;
         a[3]:=3;
    
         reg.c1:=1;
         reg.c2:=2;
    end;
    
    procedure TForm2.Button2Click(Sender: TObject);
    var
       s: string;
    begin
         s:='123';
         s:=s+'c';
    
         byReferenceMethod(s);
         byReferenceProcedure(s);
    end;
    
    procedure TForm2.byReferenceMethod(var bref: string);
    var
       anotherString: string;
    begin
         anotherString:=bref + 'sdas';
    end;
    
    end.
    
    
    unit2.pas (1,227 bytes)

Activities

2009-09-08 22:41

 

unit1.pas (694 bytes)
unit Unit1; 

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  StdCtrls;

type

  { TForm1 }

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

var
  Form1: TForm1; 

implementation

{ TForm1 }

procedure test(var a: string);
var
   b: string;
begin
     //When I try to see the value of "A" variable only its address is being displayed
     b:=a+'5678';
end;

procedure TForm1.Button1Click(Sender: TObject);
var
   a: string='1234';
begin
     test(a);
end;

initialization
  {$I unit1.lrs}

end.

unit1.pas (694 bytes)

Flávio Etrusco (notifications not working)

2010-02-09 07:55

developer   ~0034311

Last edited: 2010-02-09 13:56

Marc, how do you intend to tackle this?
Get help from CodeTools, try to get the compiler to put additional debuginfo, or do some trickery if the gdb type name suggests a class/object/record and the address seems to point to a class instance?

Martin Friebe

2010-12-16 04:10

manager   ~0044260

Please test and close if ok.

Please note, there is a remaining issue, under dwarf (only dwarf) dereferencing a pointer variable, that is a var param, will not work.
This works fine with Stabs, so if that is important please use stabs.
To fix that under dwarf, would seriously slow down the debugging, and is considered not worth it, therefore this particular remaining issue will be considered a "wont fix".

Example (example with pointer to object, but similar for pointer to other types)

type
  PMyObject = ^TMyObject
procedure Foo(var AnObjPtr: PMyObject);

the watch for "AnObjPtr" is shown correct under dwarf and stabs, but it is a pointer, and shown as pointer.

if you enter "AnObjPtr^" as watch (note the deref "^"), then under stabs you will see the object. with dwarf this fails.

You can use "PMyObject(AnObjPtr)^" and this will work

Daniel Gaspary

2010-12-17 06:03

reporter   ~0044287

Now it 's not working at all

The value I got when try Evaluate 'a':

{
  i = {
    0,
    1045149306},
  d = 1.2904777690891933e-08}


Lazarus: 9.29 - Rev. 28738.
FPC: 2.4.2-0 [2010/11/20] for x86_64

Martin Friebe

2010-12-17 07:42

manager   ~0044288

Last edited: 2010-12-17 07:44

Unfortunately I can not reproduce (it works correct on my 32 bit system)
w32 various fpc and gdb versions
Fedora 13 (32bit) fpc trunk / gdb 7.1.-18

I will need some feedback from you please:
- version of gdb
  Can it be upgraded?
- which OS
- compiled without any optimization? -O-
- I believe 64 bit only supports dwarf, otherwise try stabs and dwarf
- "when try Evaluate 'a'" => in the WATCHES window?
  the evaluate dialog should also work, and tooltip/hint should work
  the "locals" window is not fixed.
- please open the "Debug Output" window.
  You can empty it (select all/del) before you add the watch.
  Then post the output for evaluating the watch.
  Should be something like
    whatis a
    ...
    ptype ....
    ....
    -data-evaluate-expression ...a...
    ...
    <gdb>
  potentiality some more

Daniel Gaspary

2010-12-17 13:18

reporter   ~0044295

>version of gdb
GNU gdb (GDB) 7.2-ubuntu

>Can it be upgraded?
I could, but I'm using Ubuntu 10.10, so, the bug can hit a lot of people.

>which OS
Ubuntu 10.10 x86-64 bits

>compiled without any optimization? -O-
Just the default configuration.

>I believe 64 bit only supports dwarf

The value of the other types I tested (Integer, Real, a record) are been displayed as expected.

>otherwise try stabs and dwarf
How can I configure that ? Lazarus Debug options shows only GDB as available. I have installed ubuntu "dwarves" package.

>"when try Evaluate 'a'" => in the WATCHES window?
> the evaluate dialog should also work, and tooltip/hint should work

I was talking about the "Evaluate/Modify" Menu option, but WATCHES windows and tooltip show the same.

>please open the "Debug Output" window.
>You can empty it (select all/del) before you add the watch.
>Then post the output for evaluating the watch

<whatis a>
&"whatis a\n"
~"type = number\n"
^done
(gdb)
<ptype number>
&"ptype number\n"
~"type = case <?> of \n"
~" i : array [0..1] of int;\n"
~" d : double;\n"
~"end\n"
^done
(gdb)
<-data-evaluate-expression a>
^done,value="{i = {0, 1045149306}, d = 1.2904777690891933e-08}"
(gdb)

Daniel Gaspary

2010-12-17 13:40

reporter   ~0044296

With the second Test I have attached everything works fine.

When I use the exact same procedures of the first example, the problem occurs again.

I Believe we can close the issue. Or we try other tests?

2010-12-17 13:40

 

unit2.pas (1,227 bytes)
unit Unit2; 

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;

type

  { TForm2 }

  TForm2 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);

    procedure byReferenceMethod(var bref: string);
  private
    { private declarations }
  public
    { public declarations }
  end; 

var
  Form2: TForm2; 

implementation

{$R *.lfm}


procedure byReferenceProcedure(var bref: string);
var
   t: string;
begin
     t:=bref + '123';
end;

{ TForm2 }

procedure TForm2.Button1Click(Sender: TObject);
type
    arec = record
      c1, c2: integer;
    end;

var
  s: String;
  i: Integer;
  r: real;
  a: array[1..3] of integer;
  reg: arec;
begin
     i:=1;
     r:=1.2;
     s:='abc';
     a[1]:=1;
     a[2]:=2;
     a[3]:=3;

     reg.c1:=1;
     reg.c2:=2;
end;

procedure TForm2.Button2Click(Sender: TObject);
var
   s: string;
begin
     s:='123';
     s:=s+'c';

     byReferenceMethod(s);
     byReferenceProcedure(s);
end;

procedure TForm2.byReferenceMethod(var bref: string);
var
   anotherString: string;
begin
     anotherString:=bref + 'sdas';
end;

end.

unit2.pas (1,227 bytes)

Martin Friebe

2010-12-17 15:29

manager   ~0044298

Thanks.
- GDB 7.2=> no need to upgrade.
- Stabs a Dwarf => Sorry, I didn't explain. they are debug-info-formats. In Project/Options/Linking: Stabs = -gs / Dwarf = -gw

Well, yes from the data and the 2nd test:
This seems a problem in GDB, which can't be fixed in the IDE. For some reason it seems to find another "a"
So, yes, I will close the issue.

But what you may try:
- Use an upper-case "A" (in the watch expression)
- use "ansistring(A)" (maybe all upper)
- compile using the external linker (in case it's a linker issue). Project-Options/Other "Custom Options": -Xe
- Ask on the fpc mail list, that it isn't an issue in fpc

Daniel Gaspary

2010-12-17 16:56

reporter   ~0044299

>But what you may try:
>- Use an upper-case "A" (in the watch expression)
>- use "ansistring(A)" (maybe all upper)

In both cases, using UpperCase A, the result is correct.

Something is case sensitive where it shouldn't. Well, closing. Thank you!

Issue History

Date Modified Username Field Change
2009-09-08 22:41 Daniel Gaspary New Issue
2009-09-08 22:41 Daniel Gaspary Status new => assigned
2009-09-08 22:41 Daniel Gaspary Assigned To => Marc Weustink
2009-09-08 22:41 Daniel Gaspary File Added: unit1.pas
2009-09-08 22:41 Daniel Gaspary Widgetset => GTK 2
2010-02-09 07:55 Flávio Etrusco (notifications not working) Note Added: 0034311
2010-02-09 13:56 Flávio Etrusco (notifications not working) Note Edited: 0034311
2010-12-16 04:10 Martin Friebe Fixed in Revision => 28725
2010-12-16 04:10 Martin Friebe LazTarget => 1.0
2010-12-16 04:10 Martin Friebe Status assigned => resolved
2010-12-16 04:10 Martin Friebe Fixed in Version => 0.9.29 (SVN)
2010-12-16 04:10 Martin Friebe Resolution open => fixed
2010-12-16 04:10 Martin Friebe Note Added: 0044260
2010-12-16 04:10 Martin Friebe Target Version => 0.9.30
2010-12-17 06:03 Daniel Gaspary Status resolved => assigned
2010-12-17 06:03 Daniel Gaspary Resolution fixed => reopened
2010-12-17 06:03 Daniel Gaspary Note Added: 0044287
2010-12-17 07:42 Martin Friebe Note Added: 0044288
2010-12-17 07:42 Martin Friebe Assigned To Marc Weustink => Martin Friebe
2010-12-17 07:42 Martin Friebe Status assigned => feedback
2010-12-17 07:44 Martin Friebe Note Edited: 0044288
2010-12-17 13:18 Daniel Gaspary Note Added: 0044295
2010-12-17 13:40 Daniel Gaspary Note Added: 0044296
2010-12-17 13:40 Daniel Gaspary File Added: unit2.pas
2010-12-17 15:29 Martin Friebe Status feedback => resolved
2010-12-17 15:29 Martin Friebe Resolution reopened => fixed
2010-12-17 15:29 Martin Friebe Note Added: 0044298
2010-12-17 16:56 Daniel Gaspary Status resolved => closed
2010-12-17 16:56 Daniel Gaspary Note Added: 0044299