[llvm-commits] [PATCH] - RFC - Selecting a Dwarf Info version from the command line.
Pranav Bhandarkar
pranavb at codeaurora.org
Sun Nov 25 11:43:06 PST 2012
Hi,
In October, there had been a discussion
(http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-October/054543.html)
about DWARF information related backwards compatibility. Rick Foos (he
was speaking on my behalf too), in the email above, had proposed a
mechanism for backwards compatibility. Unfortunately, I could not tend
to it at that time, but now I have been able to. I am attaching two
patches here, one for LLVM and the other for clang.
1) The LLVM patch introduces a command line variable DwarfDebugLevel
that is set to 4 by default. Additionaly, as a first step, this is used
in CompileUnit:addFlag to gate the use of DW_FORM_flag_present which is
a DWARF 4 addition that is compatible with DWARF 3.
2) The second patch is a patch to clang to process the -gdwarf-2/3/4
flags, which involves setting DwarfDebugLevel using the
-dwarf-debug-level option for "clang -cc1".
This is an initial proposal. Please comment on what changes are needed.
I am posting the clang patch here too because I wanted to post both the
patches in one place. If cfe-commits is a better place to post (or if
the two patches should be posted on both the lists) please let me know,
and I'll do that.
Thanks,
Pranav
--
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation.
-------------- next part --------------
>From 99f5745833c2d66cece22a44d0bae2cc44aaf552 Mon Sep 17 00:00:00 2001
From: Pranav Bhandarkar <pranavb at codeaurora.org>
Date: Tue, 23 Oct 2012 01:12:44 -0500
Subject: [PATCH] Add a DWARF debug level mechanism for debug information
version.
* lib/Driver/Tools.cpp(Clang:ConstructJob): Process the options above and
pass on the appropriate value to cc1.
---
lib/Driver/Tools.cpp | 15 +++++++++++++++
1 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 51228d7..246bfb7 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -2410,6 +2410,21 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
Args.AddLastArg(CmdArgs, options::OPT_fwritable_strings);
Args.AddLastArg(CmdArgs, options::OPT_funroll_loops);
+ // -gdwarf-<version>
+ if (Arg *A = Args.getLastArg(options::OPT_gdwarf_2, options::OPT_gdwarf_3,
+ options::OPT_gdwarf_4)) {
+ CmdArgs.push_back("-g");
+ CmdArgs.push_back("-mllvm");
+ std::string DwarfDebugLevel="-dwarf-debug-level=";
+ if (A->getOption().matches(options::OPT_gdwarf_2))
+ DwarfDebugLevel += "2";
+ else if (A->getOption().matches(options::OPT_gdwarf_3))
+ DwarfDebugLevel += "3";
+ else
+ DwarfDebugLevel += "4";
+ CmdArgs.push_back(Args.MakeArgString(DwarfDebugLevel));
+ }
+
Args.AddLastArg(CmdArgs, options::OPT_pthread);
// -stack-protector=0 is default.
--
1.7.6.4
-------------- next part --------------
>From 2b6949063eb8b90a3790b440f087db3e43d7aae6 Mon Sep 17 00:00:00 2001
From: Pranav Bhandarkar <pranavb at codeaurora.org>
Date: Tue, 23 Oct 2012 01:15:45 -0500
Subject: [PATCH] Add a new mechanism to handle Dwarf debug information
version.
* lib/CodeGen/AsmPrinter/DwarfDebug.h(DwarfDebug:DebugLevelOptions):
New enum for debug info version.
(DwarfDebug:DebugLevel): The chosen Dwarf debug info version.
* lib/CodeGen/AsmPrinter/DwarfDebug.cpp(DwarfDebug): Initialize
DebugLevel.
* lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp(addFlag): Use
DwarfDebug::DebugLevel to decide on the use of DW_FORM_flag_present.
---
lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp | 2 +-
lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 15 +++++++++++++++
lib/CodeGen/AsmPrinter/DwarfDebug.h | 11 ++++++++++-
3 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
index 2b07dda..287f6b0 100644
--- a/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ b/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -53,7 +53,7 @@ DIEEntry *CompileUnit::createDIEEntry(DIE *Entry) {
/// addFlag - Add a flag that is true.
void CompileUnit::addFlag(DIE *Die, unsigned Attribute) {
- if (!DD->useDarwinGDBCompat())
+ if (!DD->useDarwinGDBCompat() && DD->getDebugLevel() >= DwarfDebug::DWARF_4)
Die->addValue(Attribute, dwarf::DW_FORM_flag_present,
DIEIntegerOne);
else
diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index df162e0..c12cd95 100644
--- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -54,6 +54,11 @@ static cl::opt<bool> UnknownLocations("use-unknown-locations", cl::Hidden,
cl::desc("Make an absence of debug location information explicit."),
cl::init(false));
+static cl::opt<int>
+DwarfDebugLevel("dwarf-debug-level",
+ cl::init(4), cl::Hidden,
+ cl::desc("Dwarf Debug Level (Dwarf 2, 3 or 4)"));
+
namespace {
enum DefaultOnOff {
Default, Enable, Disable
@@ -150,6 +155,16 @@ DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
PrevLabel(NULL) {
NextStringPoolNumber = 0;
+ switch (DwarfDebugLevel) {
+ case 2:
+ DebugLevel = DwarfDebug::DWARF_2;
+ break;
+ case 3:
+ DebugLevel = DwarfDebug::DWARF_3;
+ break;
+ default:
+ DebugLevel = DwarfDebug::DWARF_4;
+ }
DwarfInfoSectionSym = DwarfAbbrevSectionSym = 0;
DwarfStrSectionSym = TextSectionSym = 0;
DwarfDebugRangeSectionSym = DwarfDebugLocSectionSym = 0;
diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.h b/lib/CodeGen/AsmPrinter/DwarfDebug.h
index 20e232d..d93609a 100644
--- a/lib/CodeGen/AsmPrinter/DwarfDebug.h
+++ b/lib/CodeGen/AsmPrinter/DwarfDebug.h
@@ -191,6 +191,14 @@ public:
};
class DwarfDebug {
+public:
+ enum DebugLevelOptions {
+ DWARF_2 = 2,
+ DWARF_3,
+ DWARF_4,
+ BAD_DEBUG_LEVEL
+ };
+private:
/// Asm - Target of Dwarf emission.
AsmPrinter *Asm;
@@ -319,7 +327,7 @@ class DwarfDebug {
// A holder for the DarwinGDBCompat flag so that the compile unit can use it.
bool isDarwinGDBCompat;
bool hasDwarfAccelTables;
-private:
+ enum DebugLevelOptions DebugLevel;
/// assignAbbrevNumber - Define a unique number for the abbreviation.
///
@@ -537,6 +545,7 @@ public:
/// output to the limitations of darwin gdb.
bool useDarwinGDBCompat() { return isDarwinGDBCompat; }
bool useDwarfAccelTables() { return hasDwarfAccelTables; }
+ DebugLevelOptions getDebugLevel() { return DebugLevel; }
};
} // End of namespace llvm
--
1.7.6.4
More information about the llvm-commits
mailing list