summaryrefslogtreecommitdiff
path: root/tools/llvm-objdump
diff options
context:
space:
mode:
authorAlp Toker <alp@nuanti.com>2014-06-26 00:00:48 +0000
committerAlp Toker <alp@nuanti.com>2014-06-26 00:00:48 +0000
commit255907042245b77779e3e38c5ce66901866cabe5 (patch)
tree92db65aa99c37ab5f68cd6adaae1d8cf6d629b8f /tools/llvm-objdump
parentce6e7c7a59e8595ea3f30d87cbad4af278cb5ef3 (diff)
downloadllvm-255907042245b77779e3e38c5ce66901866cabe5.tar.gz
llvm-255907042245b77779e3e38c5ce66901866cabe5.tar.bz2
llvm-255907042245b77779e3e38c5ce66901866cabe5.tar.xz
Introduce a string_ostream string builder facilty
string_ostream is a safe and efficient string builder that combines opaque stack storage with a built-in ostream interface. small_string_ostream<bytes> additionally permits an explicit stack storage size other than the default 128 bytes to be provided. Beyond that, storage is transferred to the heap. This convenient class can be used in most places an std::string+raw_string_ostream pair or SmallString<>+raw_svector_ostream pair would previously have been used, in order to guarantee consistent access without byte truncation. The patch also converts much of LLVM to use the new facility. These changes include several probable bug fixes for truncated output, a programming error that's no longer possible with the new interface. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211749 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-objdump')
-rw-r--r--tools/llvm-objdump/llvm-objdump.cpp12
1 files changed, 4 insertions, 8 deletions
diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp
index d98691b4b0..d9886c10ae 100644
--- a/tools/llvm-objdump/llvm-objdump.cpp
+++ b/tools/llvm-objdump/llvm-objdump.cpp
@@ -222,8 +222,7 @@ static void emitDOTFile(const char *FileName, const MCFunction &f,
Out << "<o>";
// Escape special chars and print the instruction in mnemonic form.
- std::string Str;
- raw_string_ostream OS(Str);
+ string_ostream OS;
IP->printInst(&(*i)->getInsts()->at(ii).Inst, OS, "");
Out << DOT::EscapeString(OS.str());
}
@@ -473,9 +472,7 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
if (Symbols.empty())
Symbols.push_back(std::make_pair(0, name));
-
- SmallString<40> Comments;
- raw_svector_ostream CommentStream(Comments);
+ small_string_ostream<40> Comments;
StringRef Bytes;
if (error(Section.getContents(Bytes)))
@@ -513,15 +510,14 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
MCInst Inst;
if (DisAsm->getInstruction(Inst, Size, memoryObject,
- SectionAddr + Index,
- DebugOut, CommentStream)) {
+ SectionAddr + Index, DebugOut, Comments)) {
outs() << format("%8" PRIx64 ":", SectionAddr + Index);
if (!NoShowRawInsn) {
outs() << "\t";
DumpBytes(StringRef(Bytes.data() + Index, Size));
}
IP->printInst(&Inst, outs(), "");
- outs() << CommentStream.str();
+ outs() << Comments.str();
Comments.clear();
outs() << "\n";
} else {