www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4149] New: refs displayed as pointers in gdb

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4149

           Summary: refs displayed as pointers in gdb
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: braddr puremagic.com
            Blocks: 4044



---
(gdb) list inline.d:1
1  module test.d;
2
3  void foo(ref int x)
4  {
5      ++x;
6  }
7
8  void bar()
9  {
10     int x = 0;
11
12     foo(x);
13 }
14
15 void main()
16 {
17     bar();
18 }

(gdb) break 5
Breakpoint 1 at 0x804910d: file inline.d, line 5.
(gdb) run
Breakpoint 1, test.d.foo (x=0xbffff62c) at inline.d:5
5      ++x;
(gdb) print x
$1 = (int *) 0xbffff62c

Assuming I'm understanding the dwarf records correctly, foo's argument:
 <2><a2>: Abbrev Number: 5 (DW_TAG_formal_parameter)
    <a3>   DW_AT_name        : x
    <a5>   DW_AT_type        : <0x69>
    <a9>   DW_AT_location    : 2 byte block: 91 7c    (DW_OP_fbreg: -4)

And type 0x69:
 <1><69>: Abbrev Number: 4 (DW_TAG_pointer_type)
    <6a>   DW_AT_byte_size   : 4
    <6b>   DW_AT_type        : <0x62>


Dwarf formally supports a reference type according to the spec.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 02 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4149


Robert Clipsham <robert octarineparrot.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |robert octarineparrot.com



21:44:31 BST ---
This is done because C does not have reference types, and no debugger currently
supports the debug output produced by dmd when using -g. When using -g dmd
should, as you say, use the DWARF reference type, which it does not currently
do. When using -gc, it should be a pointer as it is now. I'll try and put a
patch together later today. As a side note, classes should be reference types
too, rather than acting as pointers as they do currently.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 02 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4149




---
Depends on if gc implies c, c++, or 'as much as is supported in the built-in
debug format without extension'. 

I'd argue for the last definition.  Given that dwarf supports it without
extension, I'd argue that it should use it.  I'd argue that -g should be
built-in + d extensions.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 02 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4149




21:50:30 BST ---
-gc means act as C. I think I'm going to talk to Walter about this actually, as
the debugging situation for D could be far better.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 02 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4149




---
I've been looking at how to patch up that part of the code, and it looks like
the ref-ness has been lost at this layer:

(gdb) print *t
$2 = {id = 4660, Tty = 29, Tflags = 0, Tmangle = 7 '\a', Tcount = 1, Tnext =
0x81ffd20, {Tdim = 0, Tel = 0x0, Tparamtypes = 0x0, Ttag = 0x0, Tident = 0x0,
Tkey = 0x0}, Texcspec = 0x0}
(gdb) print t->Tnext
$3 = (TYPE *) 0x81ffd20
(gdb) print t->Tnext[0]
$4 = {id = 4660, Tty = 10, Tflags = 0, Tmangle = 0 '\000', Tcount = 3, Tnext =
0x0, {Tdim = 0, Tel = 0x0, Tparamtypes = 0x0, Ttag = 0x0, Tident = 0x0, Tkey =
0x0}, Texcspec = 0x0}

Tty 29 == 0x1d == TYnptr

If it was still a TYnref, it'd be easy.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 02 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4149




22:17:49 BST ---
It is easy, I wrote the patch that adds support for ref types to the debug info
;) The refness isn't lost, it just uses the same case statement, and thus gets
replaced. I'm about to write a patch for it now :)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 02 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4149


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com



16:14:03 PDT ---
I agree with Brad's comment 2.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 02 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4149




---
Created an attachment (id=625)
Fix some plumbing and change the dwarf code to emit ref types.

The ref'ness was lost before it got into the dwarf stage, but also easy to fix,
assuming that Walter is right about the backend being ready to handle TYref's
now.

I've attached the diff I've whipped up.  It does work to emit the right debug
info, but I haven't tested it on much more than the simplest code
(specifically, the code at the top of this bug report).

A snippit from a gdb session:

Breakpoint 1, test.foo (x= 0xbffff62c) at inline.d:5
5      ++x;
(gdb) print x
$1 = (int &)  0xbffff62c: 0
(gdb) next
0x08049112 in test.foo (x= 0xbffff62c)
(gdb) print x
$2 = (int &)  0xbffff62c: 1

So, gdb is using C++ style demangling, but that can be addressed by someone
working on gdb.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 09 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4149


Brad Roberts <braddr puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------

          mime type|                            |

              patch|                            |


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 09 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4149




---
Looks like one more minor change is needed to build phobos with these changes:

backed/cgcod.c:
   -1508,6 +1508,7    regm_t regmask(tym_t tym, tym_t tyf)
         case TYnptr:
         case TYsptr:
         case TYcptr:
+        case TYref:
             return mAX;
         case TYfloat:
         case TYifloat:

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 09 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4149


Robert Clipsham <robert octarineparrot.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch



15:29:05 BST ---
If this patch is accepted, we should probably change the DW_AT_language to be
C++ instead of C with -gc, and update the help message to say so.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 09 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4149




20:52:37 PST ---
Can this be turned into a pull request?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 18 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4149




PST ---
Last time I played with this diff on current code, it caused failures.  I
haven't looked at in any detail in ages and I'm fairly sure it's rather
incomplete now that I know more about the backend.

The bug is still real though.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 18 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4149


Leandro Lucarella <leandro.lucarella sociomantic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |leandro.lucarella sociomant
                   |                            |ic.com



2012-01-26 07:04:10 PST ---

 I agree with Brad's comment 2.
What's the relation between this and pull request 526[1] (commit e81dbc2 in dmd-1.x) that has been merged recently. At least according to the pull request, the improved usage of DWARF is only activated when -g is specified. Should that be changed for -gc? What about bug 3389? I think Robert's suggestion about having a -gd for D extensions and -g for standard debugging stuff would be better. Right now the situation with -g/-gc is far from ideal. [1] https://github.com/D-Programming-Language/dmd/pull/526 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 26 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4149


dawg dawgfoto.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dawg dawgfoto.de
         AssignedTo|nobody puremagic.com        |dawg dawgfoto.de





-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 31 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4149




2012-02-01 02:22:04 PST ---


I'm talking about the comment 2 by Brad:
 Depends on if gc implies c, c++, or 'as much as is supported in the built-in
 debug format without extension'. 
 
 I'd argue for the last definition.  Given that dwarf supports it without
 extension, I'd argue that it should use it.  I'd argue that -g should be
 built-in + d extensions.
Walter expressed he agree with this comment in comment 3. AFAIK this pull request works for -g instead of -gc, even when it uses standard DWARF features, which goes against that comment. In the bug 3389 that you just closed, Robert Clipsham makes what for me is a good point:
 -g not working is how it's meant to be, at least until gdb adds support for the
 D extensions to DWARF. I've hopefully fixed the remaining bugs with -gc (on
 linux at least). My solution to this would be to add in a -gd, and make -g an
 alias to -gc until better support for debug info is added to debuggers. This
 way users get working debug output with -g, and don't blame it on a buggy dmd
 :)
At least this will be more familiar with people used to GCC command line arguments (which is probably 100% of the *nix world), where -g is the default for debug and you have, for example -ggdb for GDB extensions. AFAIK there is no clear direction about this. But maybe is a topic for another bug report, I think I'll reopen bug 3389 because the root issue in that bug is what's being discussed here. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 01 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4149




PST ---
Please stop cluttering this bug report with discussion about the meaning of -g,
that's a solved problem.  This report is about preserving 'ref'ness through the
backend and dwarf debug data.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 01 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4149




https://github.com/D-Programming-Language/dmd/pull/687

Based on patch but had to add another change to e2ir.c.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 02 2012