Skip to content

Commit

Permalink
[DebugInfo] Generate debug info for system typedefs even with -fno-sy…
Browse files Browse the repository at this point in the history
…stem-debug

Signed-off-by: Lu, John <[email protected]>
  • Loading branch information
LU-JOHN committed Jan 18, 2024
1 parent 8959c3c commit 98eeff7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
12 changes: 12 additions & 0 deletions clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6027,6 +6027,18 @@ bool clang::CodeGen::noSystemDebugInfo(const Decl *D,
const CodeGenModule &CGM) {
// Declaration is in system file
if (CGM.getContext().getSourceManager().isInSystemHeader(D->getLocation())) {
// Make an exception for typedefs in system header files. Generate debug
// information for these decls because these are rare (thus they will not
// greatly increase debug size) and a user could rely on these typedefs
// during debugging. For example uid_t in in "sys/types.h" can be used in
// the gdb command:
//
// print ruid == (uid_t)-1
//
// This occurs in GDB test gdb.reverse/getresuid-reverse.c
if (isa<TypedefDecl>(D))
return false;

// -fno-system-debug was used. Do not generate debug info.
if (CGM.getCodeGenOpts().NoSystemDebug)
return true;
Expand Down
25 changes: 25 additions & 0 deletions clang/test/CodeGen/debug-info-system-typedef.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Ensure that debug info for typedefs in system headers is still generated
// even if -fno-system-debug is used. This is justified because debug size
// savings is small, but debugging is commonly done with types that are
// typedef-ed in system headers. Thus, the increased debuggability
// is worth the small extra cost.

// RUN: %clang -fno-system-debug -emit-llvm -S -g %s -o %t.ll

// RUN: FileCheck %s < %t.ll

// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "gid_t",
// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "__gid_t",
// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "uid_t",
// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "__uid_t",

#include <unistd.h>

uid_t xuid;
gid_t xgid;

int
main (void)
{
return 0;
}

0 comments on commit 98eeff7

Please sign in to comment.