diff options
| author | Pavel Labath <pavel@labath.sk> | 2019-11-19 09:54:24 +0100 |
|---|---|---|
| committer | Pavel Labath <pavel@labath.sk> | 2019-11-19 10:34:30 +0100 |
| commit | c0fc29c4684a997d282bfed71eb4d903ad16ee25 (patch) | |
| tree | aaeed42b3d1ecbac3fd0a5e74edad4adccae5bb3 | |
| parent | 7db1230a9f5e0185a88019c9aa5b55bd85498285 (diff) | |
| download | bcm5719-llvm-c0fc29c4684a997d282bfed71eb4d903ad16ee25.tar.gz bcm5719-llvm-c0fc29c4684a997d282bfed71eb4d903ad16ee25.zip | |
Add operator<< for object::SectionedAddress
The main motivation for this is better failure messages in unit tests.
Split off from D70394.
| -rw-r--r-- | llvm/include/llvm/Object/ObjectFile.h | 2 | ||||
| -rw-r--r-- | llvm/lib/Object/ObjectFile.cpp | 7 | ||||
| -rw-r--r-- | llvm/unittests/Object/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | llvm/unittests/Object/ObjectFileTest.cpp | 20 |
4 files changed, 30 insertions, 0 deletions
diff --git a/llvm/include/llvm/Object/ObjectFile.h b/llvm/include/llvm/Object/ObjectFile.h index adc9dbc189a..2f149345760 100644 --- a/llvm/include/llvm/Object/ObjectFile.h +++ b/llvm/include/llvm/Object/ObjectFile.h @@ -155,6 +155,8 @@ inline bool operator==(const SectionedAddress &LHS, std::tie(RHS.SectionIndex, RHS.Address); } +raw_ostream &operator<<(raw_ostream &OS, const SectionedAddress &Addr); + /// This is a value type class that represents a single symbol in the list of /// symbols in the object file. class SymbolRef : public BasicSymbolRef { diff --git a/llvm/lib/Object/ObjectFile.cpp b/llvm/lib/Object/ObjectFile.cpp index e0e63a5a7d7..098b3d8f8dd 100644 --- a/llvm/lib/Object/ObjectFile.cpp +++ b/llvm/lib/Object/ObjectFile.cpp @@ -32,6 +32,13 @@ using namespace llvm; using namespace object; +raw_ostream &object::operator<<(raw_ostream &OS, const SectionedAddress &Addr) { + OS << "SectionedAddress{" << format_hex(Addr.Address, 10); + if (Addr.SectionIndex != SectionedAddress::UndefSection) + OS << ", " << Addr.SectionIndex; + return OS << "}"; +} + void ObjectFile::anchor() {} ObjectFile::ObjectFile(unsigned int Type, MemoryBufferRef Source) diff --git a/llvm/unittests/Object/CMakeLists.txt b/llvm/unittests/Object/CMakeLists.txt index e0be1ba2b2f..809515a2e78 100644 --- a/llvm/unittests/Object/CMakeLists.txt +++ b/llvm/unittests/Object/CMakeLists.txt @@ -5,6 +5,7 @@ set(LLVM_LINK_COMPONENTS add_llvm_unittest(ObjectTests MinidumpTest.cpp + ObjectFileTest.cpp SymbolSizeTest.cpp SymbolicFileTest.cpp ) diff --git a/llvm/unittests/Object/ObjectFileTest.cpp b/llvm/unittests/Object/ObjectFileTest.cpp new file mode 100644 index 00000000000..7309c2c2528 --- /dev/null +++ b/llvm/unittests/Object/ObjectFileTest.cpp @@ -0,0 +1,20 @@ +//===- ObjectFileTest.cpp - Tests for ObjectFile.cpp ----------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "llvm/Object/ObjectFile.h" +#include "llvm/Support/ScopedPrinter.h" +#include "gtest/gtest.h" + +using namespace llvm; +using namespace llvm::object; + +TEST(SectionedAddress, StreamingOperator) { + EXPECT_EQ("SectionedAddress{0x00000047}", to_string(SectionedAddress{0x47})); + EXPECT_EQ("SectionedAddress{0x00000047, 42}", + to_string(SectionedAddress{0x47, 42})); +} |

