[Lldb-commits] [PATCH] D40745: Add a clang-ast subcommand to lldb-test

Zachary Turner via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Dec 1 16:16:01 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL319599: Add a symbols subcommand to lldb-test. (authored by zturner).

Changed prior to commit:
  https://reviews.llvm.org/D40745?vs=125197&id=125239#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40745

Files:
  lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/trunk/tools/lldb-test/lldb-test.cpp


Index: lldb/trunk/tools/lldb-test/lldb-test.cpp
===================================================================
--- lldb/trunk/tools/lldb-test/lldb-test.cpp
+++ lldb/trunk/tools/lldb-test/lldb-test.cpp
@@ -10,11 +10,15 @@
 #include "FormatUtil.h"
 #include "SystemInitializerTest.h"
 
+#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
 #include "lldb/Core/Debugger.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/Section.h"
 #include "lldb/Initialization/SystemLifetimeManager.h"
+#include "lldb/Symbol/ClangASTContext.h"
+#include "lldb/Symbol/ClangASTImporter.h"
 #include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/StreamString.h"
 
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/CommandLine.h"
@@ -30,26 +34,47 @@
 namespace opts {
 cl::SubCommand ModuleSubcommand("module-sections",
                                 "Display LLDB Module Information");
+cl::SubCommand SymbolsSubcommand("symbols", "Dump symbols for an object file");
 
 namespace module {
 cl::opt<bool> SectionContents("contents",
                               cl::desc("Dump each section's contents"),
                               cl::sub(ModuleSubcommand));
 cl::list<std::string> InputFilenames(cl::Positional, cl::desc("<input files>"),
                                      cl::OneOrMore, cl::sub(ModuleSubcommand));
 } // namespace module
+
+namespace symbols {
+cl::list<std::string> InputFilenames(cl::Positional, cl::desc("<input files>"),
+                                     cl::OneOrMore, cl::sub(SymbolsSubcommand));
+}
 } // namespace opts
 
 static llvm::ManagedStatic<SystemLifetimeManager> DebuggerLifetime;
 
+static void dumpSymbols(Debugger &Dbg) {
+  for (const auto &File : opts::symbols::InputFilenames) {
+    ModuleSpec Spec{FileSpec(File, false)};
+    Spec.GetSymbolFileSpec().SetFile(File, false);
+
+    auto ModulePtr = std::make_shared<lldb_private::Module>(Spec);
+
+    StreamString Stream;
+    ModulePtr->ParseAllDebugSymbols();
+    ModulePtr->Dump(&Stream);
+    llvm::outs() << Stream.GetData() << "\n";
+    llvm::outs().flush();
+  }
+}
+
 static void dumpModules(Debugger &Dbg) {
   LinePrinter Printer(4, llvm::outs());
 
   for (const auto &File : opts::module::InputFilenames) {
     ModuleSpec Spec{FileSpec(File, false)};
     Spec.GetSymbolFileSpec().SetFile(File, false);
 
-    auto ModulePtr = std::make_shared<Module>(Spec);
+    auto ModulePtr = std::make_shared<lldb_private::Module>(Spec);
     SectionList *Sections = ModulePtr->GetSectionList();
     if (!Sections) {
       llvm::errs() << "Could not load sections for module " << File << "\n";
@@ -92,6 +117,8 @@
 
   if (opts::ModuleSubcommand)
     dumpModules(*Dbg);
+  else if (opts::SymbolsSubcommand)
+    dumpSymbols(*Dbg);
 
   DebuggerLifetime->Terminate();
   return 0;
Index: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===================================================================
--- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -2764,6 +2764,14 @@
       case R_386_32:
       case R_386_PC32:
       default:
+        // FIXME: This asserts with this input:
+        //
+        // foo.cpp
+        // int main(int argc, char **argv) { return 0; }
+        //
+        // clang++.exe --target=i686-unknown-linux-gnu -g -c foo.cpp -o foo.o
+        //
+        // and running this on the foo.o module.
         assert(false && "unexpected relocation type");
       }
     } else {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40745.125239.patch
Type: text/x-patch
Size: 3518 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20171202/1c1492a1/attachment-0001.bin>


More information about the lldb-commits mailing list