Bug 11349 - pchar/ansistring does not print correctly
Summary: pchar/ansistring does not print correctly
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: pascal (show other bugs)
Version: 7.0
: P2 normal
Target Milestone: 7.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-04 14:43 UTC by sethdgrover
Modified: 2010-05-10 02:32 UTC (History)
2 users (show)

See Also:
Host: x86_64-ubuntu-linux
Target: x86_64-ubuntu-linux
Build: x86_64-ubuntu-linux
Last reconfirmed:


Attachments
compiled program (89.54 KB, application/octet-stream)
2010-03-04 23:29 UTC, sethdgrover
Details
readelf -gw from compiled program (1.64 KB, text/plain)
2010-03-04 23:29 UTC, sethdgrover
Details
program compiled to assembly (2.18 KB, text/plain)
2010-03-04 23:32 UTC, sethdgrover
Details

Note You need to log in before you can comment on or make changes to this bug.
Description sethdgrover 2010-03-04 14:43:51 UTC
Given this example program:

--------------------------------------
program project1;

{$mode objfpc}{$H+}

 procedure doit (var s : ansistring);
 begin
   s := s + ' ' + s;
 end;

var
 s : ansistring;
begin
 s := 'test';
 doit(s);
end.
--------------------------------------

Compiled with Free Pascal 2.4.0 with the command line "fpc -Px86_64 -g -gl -gw
project1.lpr", when I set a breakpoint in "doit" and try to view the var
ansistring variable "s":

and set a breakpoint in "doit" in GDB, I see the following:

(gdb) whatis S
type = &ANSISTRING
(gdb) print S
$12 = (&ANSISTRING) @0x627130
(gdb) whatis S^
type = ANSISTRING
(gdb) print S^
$13 = 116 't'
(gdb) x/s S
0x74:    <Address 0x74 out of bounds>
(gdb) x/s S^
0x74:    <Address 0x74 out of bounds>

Debugging with GDB 6.8 with the exact same program and compiler options, I get
this instead:

(gdb) print S
$1 = (&ANSISTRING) @0x8069410: 0x8065074 'test'

It appears ansistring variables passed by reference are no longer working
correctly with "print" in GDB, and that this bug was introduced in GDB 7.0.

My system is Ubuntu 9.10 64-bit:

$ gdb --version
GNU gdb (GDB) 7.0-ubuntu

$ uname -a
Linux user-desktop 2.6.31-19-generic #56-Ubuntu SMP Thu Jan 28 02:39:34 UTC 2010
x86_64 GNU/Linux

$ fpc
Free Pascal Compiler version 2.4.0 [2010/02/09] for x86_64
Comment 1 sethdgrover 2010-03-04 23:29:21 UTC
Created attachment 4643 [details]
compiled program

Here's the same program using pchar instead of ansistring, along with the
compiled version of the program:

program project1;

procedure doit (var s : pchar);
begin
end;

var
 s : pchar;
begin
 s := 'test';
 doit(s);
end.
Comment 2 sethdgrover 2010-03-04 23:29:56 UTC
Created attachment 4644 [details]
readelf -gw from compiled program

readelf -gw of binary in attachment 4643 [details]
Comment 3 sethdgrover 2010-03-04 23:32:39 UTC
Created attachment 4645 [details]
program compiled to assembly

Assembly file generated by FPC from program in attachment 4643 [details] (compiled with
"fpc -a -al -an -Px86_64 -g -gl -gw project1.lpr").
Comment 4 sethdgrover 2010-04-01 20:03:36 UTC
gdb bugs sit for a month before anyone even looks at them?
Comment 5 Sourceware Commits 2010-05-03 13:38:49 UTC
Subject: Bug 11349

CVSROOT:	/cvs/src
Module name:	src
Changes by:	muller@sourceware.org	2010-05-03 13:38:27

Modified files:
	gdb            : ChangeLog p-valprint.c 

Log message:
	PR pascal/11349.
	* p-valprint.c (pascal_value_print): Always dereference a value with
	type code TYPE_CODE_REF.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.11713&r2=1.11714
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/p-valprint.c.diff?cvsroot=src&r1=1.69&r2=1.70

Comment 6 Sourceware Commits 2010-05-04 06:48:40 UTC
Subject: Bug 11349

CVSROOT:	/cvs/src
Module name:	src
Changes by:	muller@sourceware.org	2010-05-04 06:48:27

Modified files:
	gdb            : ChangeLog printcmd.c 
	gdb/testsuite  : ChangeLog 
	gdb/testsuite/gdb.cp: ref-types.exp 

Log message:
	PR exp/11349.
	* printcmd.c (x_command): Only dereference once implicitly for
	TYPE_CODE_REF.
	
	testsuite dir:
	PR exp/11349.
	* testsuite/gdb.cp/ref-types.exp: Add test to examine
	use a reference local variable.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.11717&r2=1.11718
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/printcmd.c.diff?cvsroot=src&r1=1.176&r2=1.177
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/ChangeLog.diff?cvsroot=src&r1=1.2260&r2=1.2261
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.cp/ref-types.exp.diff?cvsroot=src&r1=1.12&r2=1.13

Comment 7 Pierre Muller 2010-05-08 15:19:35 UTC
  The patches committed to trunk should solve the issue.
  Could you try it out and mark the issue as FIXED 
if all works correctly or report if you still get problems.
Comment 8 sethdgrover 2010-05-10 02:32:30 UTC
Thanks, that seems to have done the trick. With the test program from comment 1,
here's what I get with the patched version:

============================
(gdb) break DOIT
Breakpoint 1 at 0x80480a9: file project1.pas, line 5.
(gdb) r
Starting program: /home/tlacuache/tmp/project1 

Breakpoint 1, DOIT (S=@0x8068240) at project1.pas:5
5	end;
(gdb) print S
$1 = (&PCHAR) @0x8068240: 0x806404c 'test'
============================

compared to what I used to get (with gdb 7.1 in the Ubuntu repositories):
============================
(gdb) break DOIT
Breakpoint 1 at 0x80480a9: file project1.pas, line 5.
(gdb) r
Starting program: /home/tlacuache/tmp/project1 

Breakpoint 1, DOIT (S=@0x8068240) at project1.pas:5
5	end;
(gdb) print S
$1 = (&PCHAR) @0x8068240
============================

So the new behavior is correct.

Thanks again.