Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is basically a proof-of-concept and starting point for having a testing-centric tool in LLDB. I'm sure this leaves a lot of room to be desired, but this at least allows us to have something to build on. Right now there is only one command, the `module-sections` command, and I created this command not because it was particularly special, but because it addressed an immediate use case and was extremely simple. Run the tool as `lldb-test module-sections <path-to-object>`. Feel free to add testing related stuff to your heart's content after this goes in. Implementing the commands themselves takes some work, but once they're there they can be reused without writing any code and result in very easy to use and maintain tests. Differential Revision: https://reviews.llvm.org/D40636 llvm-svn: 319504
- Loading branch information
Zachary Turner
committed
Dec 1, 2017
1 parent
1cf7f9c
commit 888a428
Showing
7 changed files
with
650 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
get_property(LLDB_ALL_PLUGINS GLOBAL PROPERTY LLDB_PLUGINS) | ||
|
||
add_lldb_tool(lldb-test | ||
FormatUtil.cpp | ||
lldb-test.cpp | ||
SystemInitializerTest.cpp | ||
|
||
LINK_LIBS | ||
lldbBase | ||
lldbBreakpoint | ||
lldbCore | ||
lldbDataFormatters | ||
lldbExpression | ||
lldbHost | ||
lldbInitialization | ||
lldbInterpreter | ||
lldbSymbol | ||
lldbTarget | ||
lldbUtility | ||
${LLDB_ALL_PLUGINS} | ||
${host_lib} | ||
|
||
LINK_COMPONENTS | ||
Support | ||
) | ||
|
||
include_directories(${LLDB_SOURCE_DIR}/source) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
//===- FormatUtil.cpp ----------------------------------------- *- C++ --*-===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "FormatUtil.h" | ||
#include "llvm/Support/Format.h" | ||
#include "llvm/Support/FormatVariadic.h" | ||
|
||
using namespace lldb_private; | ||
using namespace llvm; | ||
|
||
LinePrinter::LinePrinter(int Indent, llvm::raw_ostream &Stream) | ||
: OS(Stream), IndentSpaces(Indent), CurrentIndent(0) {} | ||
|
||
void LinePrinter::Indent(uint32_t Amount) { | ||
if (Amount == 0) | ||
Amount = IndentSpaces; | ||
CurrentIndent += Amount; | ||
} | ||
|
||
void LinePrinter::Unindent(uint32_t Amount) { | ||
if (Amount == 0) | ||
Amount = IndentSpaces; | ||
CurrentIndent = std::max<int>(0, CurrentIndent - Amount); | ||
} | ||
|
||
void LinePrinter::NewLine() { | ||
OS << "\n"; | ||
OS.indent(CurrentIndent); | ||
} | ||
|
||
void LinePrinter::print(const Twine &T) { OS << T; } | ||
|
||
void LinePrinter::printLine(const Twine &T) { | ||
NewLine(); | ||
OS << T; | ||
} | ||
|
||
void LinePrinter::formatBinary(StringRef Label, ArrayRef<uint8_t> Data, | ||
uint32_t StartOffset) { | ||
NewLine(); | ||
OS << Label << " ("; | ||
if (!Data.empty()) { | ||
OS << "\n"; | ||
OS << format_bytes_with_ascii(Data, StartOffset, 32, 4, | ||
CurrentIndent + IndentSpaces, true); | ||
NewLine(); | ||
} | ||
OS << ")"; | ||
} | ||
|
||
void LinePrinter::formatBinary(StringRef Label, ArrayRef<uint8_t> Data, | ||
uint64_t Base, uint32_t StartOffset) { | ||
NewLine(); | ||
OS << Label << " ("; | ||
if (!Data.empty()) { | ||
OS << "\n"; | ||
Base += StartOffset; | ||
OS << format_bytes_with_ascii(Data, Base, 32, 4, | ||
CurrentIndent + IndentSpaces, true); | ||
NewLine(); | ||
} | ||
OS << ")"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
//===- FormatUtil.h ------------------------------------------- *- C++ --*-===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_TOOLS_LLDBTEST_FORMATUTIL_H | ||
#define LLVM_TOOLS_LLDBTEST_FORMATUTIL_H | ||
|
||
#include "llvm/ADT/ArrayRef.h" | ||
#include "llvm/ADT/StringRef.h" | ||
#include "llvm/ADT/Twine.h" | ||
#include "llvm/Support/FormatVariadic.h" | ||
#include "llvm/Support/raw_ostream.h" | ||
|
||
#include <list> | ||
|
||
namespace lldb_private { | ||
|
||
class LinePrinter { | ||
llvm::raw_ostream &OS; | ||
int IndentSpaces; | ||
int CurrentIndent; | ||
|
||
public: | ||
LinePrinter(int Indent, llvm::raw_ostream &Stream); | ||
|
||
void Indent(uint32_t Amount = 0); | ||
void Unindent(uint32_t Amount = 0); | ||
void NewLine(); | ||
|
||
void printLine(const llvm::Twine &T); | ||
void print(const llvm::Twine &T); | ||
template <typename... Ts> void formatLine(const char *Fmt, Ts &&... Items) { | ||
printLine(llvm::formatv(Fmt, std::forward<Ts>(Items)...)); | ||
} | ||
template <typename... Ts> void format(const char *Fmt, Ts &&... Items) { | ||
print(llvm::formatv(Fmt, std::forward<Ts>(Items)...)); | ||
} | ||
|
||
void formatBinary(llvm::StringRef Label, llvm::ArrayRef<uint8_t> Data, | ||
uint32_t StartOffset); | ||
void formatBinary(llvm::StringRef Label, llvm::ArrayRef<uint8_t> Data, | ||
uint64_t BaseAddr, uint32_t StartOffset); | ||
|
||
llvm::raw_ostream &getStream() { return OS; } | ||
int getIndentLevel() const { return CurrentIndent; } | ||
}; | ||
|
||
struct AutoIndent { | ||
explicit AutoIndent(LinePrinter &L, uint32_t Amount = 0) | ||
: L(&L), Amount(Amount) { | ||
L.Indent(Amount); | ||
} | ||
~AutoIndent() { | ||
if (L) | ||
L->Unindent(Amount); | ||
} | ||
|
||
LinePrinter *L = nullptr; | ||
uint32_t Amount = 0; | ||
}; | ||
|
||
template <class T> | ||
inline llvm::raw_ostream &operator<<(LinePrinter &Printer, const T &Item) { | ||
Printer.getStream() << Item; | ||
return Printer.getStream(); | ||
} | ||
|
||
} // namespace lldb_private | ||
|
||
#endif |
Oops, something went wrong.