Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang++ doesnt add debuginfo about access level of typedefs in classes #57608

Closed
GwenTheKween opened this issue Sep 7, 2022 · 8 comments
Closed
Labels
debuginfo good first issue https://github.com/llvm/llvm-project/contribute

Comments

@GwenTheKween
Copy link

GwenTheKween commented Sep 7, 2022

when compiling a program such as

class c{
public:
    typedef double public_double;
    c(double dd) : d(dd) { }
private:
    public_double d;
};

int main(){
    c tmp(1);
    c::public_double dob = 0;
    return (int)dob;
}

clang can correctly identify the access level, but when analysing the class using readelf -w we find the following debug information for the typedef:

 <1><3e>: Abbrev Number: 5 (DW_TAG_typedef)
    <3f>   DW_AT_type        : <0x57>
    <43>   DW_AT_name        : (indexed string: 0x6): public_double
    <44>   DW_AT_decl_file   : 0
    <45>   DW_AT_decl_line   : 3

While g++ gives the following debuginfo:

 <2><53>: Abbrev Number: 8 (DW_TAG_typedef)
    <54>   DW_AT_name        : (indirect string, offset: 0x62): public_double
    <58>   DW_AT_decl_file   : 1
    <59>   DW_AT_decl_line   : 3
    <5a>   DW_AT_decl_column : 20
    <5b>   DW_AT_type        : <0x77>
    <5f>   DW_AT_accessibility: 1       (public)

The lack of DW_AT_accessibility means that GDB is unable to fully understand the class, and ptype can't inform the user about access levels of the typedef.

@llvmbot
Copy link

llvmbot commented Sep 7, 2022

@llvm/issue-subscribers-debuginfo

@dwblaikie
Copy link
Collaborator

Yep, sounds accurate.

https://godbolt.org/z/PPvo4EW3s
Shows:

!19 = !DIDerivedType(tag: DW_TAG_member, name: "y", scope: !17, file: !11, line: 4, baseType: !20, size: 32, flags: DIFlagProtected)
!20 = !DIDerivedType(tag: DW_TAG_typedef, name: "x", scope: !17, file: !11, line: 3, baseType: !14)

So probably a bug in clang to add the access level flag (& then /maybe/ a bug in LLVM to use that info ensure that flag is read/emitted into the DWARF - depending on how general the LLVM implementation already is)

@EugeneZelenko EugeneZelenko added good first issue https://github.com/llvm/llvm-project/contribute and removed beginner labels Sep 8, 2022
@llvmbot
Copy link

llvmbot commented Sep 8, 2022

@llvm/issue-subscribers-good-first-issue

@Abstract-Everything
Copy link
Contributor

I would like to tackle this issue.

@pogo59
Copy link
Collaborator

pogo59 commented Sep 20, 2022

I would like to tackle this issue.

When you post it for review in Phabricator, please add the debug-info tag.

@Abstract-Everything
Copy link
Contributor

I would like to tackle this issue.

When you post it for review in Phabricator, please add the debug-info tag.

Done. https://reviews.llvm.org/D134339

T-J-Teru pushed a commit to T-J-Teru/binutils-gdb that referenced this issue Oct 27, 2022
When running gdb.cp/derivation.exp using clang, we get an unexpected
failure when printing the type of a class with an internal typedef. This
happens because clang doesn't add accessibility information for typedefs
inside classes (see llvm/llvm-project#57608
for more info). To help with clang testing, an XFAIL was added to this
test.
T-J-Teru pushed a commit to T-J-Teru/binutils-gdb that referenced this issue Oct 27, 2022
When running gdb.cp/ptype-flags.exp using clang, we get an unexpected
failure when printing the type of a class with an internal typedef. This
happens because clang doesn't add accessibility information for typedefs
inside classes (see llvm/llvm-project#57608
for more info). To help with clang testing, an XFAIL was added to this
test.
saagarjha pushed a commit to ahjragaas/binutils-gdb that referenced this issue Oct 31, 2022
When running gdb.cp/ptype-flags.exp using Clang, we get an unexpected
failure when printing the type of a class with an internal typedef. This
happens because Clang doesn't add accessibility information for typedefs
inside classes (see llvm/llvm-project#57608
for more info). To help with Clang testing, an XFAIL was added to this
test.
saagarjha pushed a commit to ahjragaas/binutils-gdb that referenced this issue Nov 11, 2022
When attempting to run the gdb.cp/classes.exp test using Clang++, the
test fails to prepare with -Wnon-c-typedef-for-linkage like the
previously fixed gdb.cp/class2.exp. Upon fixing this, the test shows 5
unexpected failures. One such failures is:

ptype/r class class_with_public_typedef
type = class class_with_public_typedef {
  private:
    int a;
  public:
    class_with_public_typedef::INT b;

  private:
    typedef int INT;
}
(gdb) FAIL: gdb.cp/classes.exp: ptype class class_with_public_typedef // wrong access specifier for typedef: private

While g++ provided the following output:

ptype/r class class_with_public_typedef
type = class class_with_public_typedef {
  private:
    int a;
  public:
    class_with_public_typedef::INT b;

    typedef int INT;
}
(gdb) PASS: gdb.cp/classes.exp: ptype class class_with_public_typedef

This error happens because Clang does not add DW_AT_accessibility to
typedefs inside classes, and without this information GDB defaults to
assuming the typedef is private.  Since there is nothing that GDB can do
about this, these tests have been set as xfails, and Clang bug 57608 has
been filed.

Bug: llvm/llvm-project#57608
Approved-by: Tom Tromey <tom@tromey.com>
saagarjha pushed a commit to ahjragaas/binutils-gdb that referenced this issue Nov 11, 2022
When running gdb.cp/derivation.exp using Clang, we get an unexpected
failure when printing the type of a class with an internal typedef. This
happens because Clang doesn't add accessibility information for typedefs
inside classes (see llvm/llvm-project#57608
for more info). To help with Clang testing, an XFAIL was added to this
test.

Approved-by: Tom Tromey <tom@tromey.com>
@xgupta
Copy link
Contributor

xgupta commented Nov 22, 2022

We may close this issue if the patch is committed?

Patch seems to working fine - https://godbolt.org/z/G5nTax3ox.

<2><46>: Abbrev Number: 5 (DW_TAG_typedef)
<47> DW_AT_type : <0x66>
<4b> DW_AT_name : (indirect string, offset: 0x83): public_double
<4f> DW_AT_accessibility: 1 (public)
<50> DW_AT_decl_file : 1
<51> DW_AT_decl_line : 3

@dwblaikie
Copy link
Collaborator

Yeah, fixed by 0828805

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
debuginfo good first issue https://github.com/llvm/llvm-project/contribute
Projects
None yet
Development

No branches or pull requests

7 participants