2013-04-04 02:31:38 +08:00
|
|
|
//===-- llvm-readobj.h ----------------------------------------------------===//
|
2013-02-20 10:37:12 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2013-02-20 10:37:12 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_TOOLS_LLVM_READOBJ_LLVM_READOBJ_H
|
|
|
|
#define LLVM_TOOLS_LLVM_READOBJ_LLVM_READOBJ_H
|
2013-02-20 10:37:12 +08:00
|
|
|
|
2013-04-04 02:31:38 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2015-12-05 05:29:53 +08:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2016-02-18 00:21:49 +08:00
|
|
|
#include "llvm/Support/ErrorOr.h"
|
2016-04-21 05:24:34 +08:00
|
|
|
#include "llvm/Support/Error.h"
|
2013-04-04 02:31:38 +08:00
|
|
|
#include <string>
|
2013-02-20 10:37:12 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
2013-04-04 02:31:38 +08:00
|
|
|
namespace object {
|
|
|
|
class RelocationRef;
|
|
|
|
}
|
2013-02-20 10:37:12 +08:00
|
|
|
|
2013-04-04 02:31:38 +08:00
|
|
|
// Various helper functions.
|
Recommit r369190 "[llvm-readobj/llvm-readelf] - Improve/cleanup the error reporting API."
Fix: Add a `consumeError` call removed by mistake to 'printStackSize',
this should fix the "Expected<T> must be checked before access or destruction." reported by following bot:
http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/9743/steps/stage%201%20check/logs/stdio
Original commit message:
Currently we have the following functions for error reporting:
LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg);
void reportError(Error Err, StringRef Input);
void reportWarning(Twine Msg);
void reportWarning(StringRef Input, Error Err);
void warn(llvm::Error Err);
void error(std::error_code EC);
Problems are: naming is inconsistent, arguments order is inconsistent,
some of the functions looks excessive.
After applying this patch we have:
void reportError(Error Err, StringRef Input);
void reportError(std::error_code EC, StringRef Input);
void reportWarning(Error Err, StringRef Input);
I'd be happy to remove reportError(std::error_code EC, StringRef Input) too, but it
is used by COFF heavily.
Test cases were updated, they show an improvement introduced.
Differential revision: https://reviews.llvm.org/D66286
llvm-svn: 369194
2019-08-18 00:07:18 +08:00
|
|
|
LLVM_ATTRIBUTE_NORETURN void reportError(Error Err, StringRef Input);
|
|
|
|
void reportWarning(Error Err, StringRef Input);
|
2017-05-04 01:11:11 +08:00
|
|
|
|
2019-08-08 15:17:35 +08:00
|
|
|
template <class T> T unwrapOrError(StringRef Input, Expected<T> EO) {
|
|
|
|
if (EO)
|
|
|
|
return *EO;
|
2019-08-13 20:07:41 +08:00
|
|
|
reportError(EO.takeError(), Input);
|
2019-08-08 15:17:35 +08:00
|
|
|
}
|
2013-04-04 02:31:38 +08:00
|
|
|
} // namespace llvm
|
|
|
|
|
|
|
|
namespace opts {
|
|
|
|
extern llvm::cl::opt<bool> SectionRelocations;
|
|
|
|
extern llvm::cl::opt<bool> SectionSymbols;
|
|
|
|
extern llvm::cl::opt<bool> SectionData;
|
2013-04-12 12:01:52 +08:00
|
|
|
extern llvm::cl::opt<bool> ExpandRelocs;
|
2018-06-29 05:07:34 +08:00
|
|
|
extern llvm::cl::opt<bool> RawRelr;
|
2015-02-19 03:32:05 +08:00
|
|
|
extern llvm::cl::opt<bool> CodeViewSubsectionBytes;
|
2019-01-17 23:34:12 +08:00
|
|
|
extern llvm::cl::opt<bool> Demangle;
|
2016-03-02 05:45:22 +08:00
|
|
|
enum OutputStyleTy { LLVM, GNU };
|
|
|
|
extern llvm::cl::opt<OutputStyleTy> Output;
|
2013-04-04 02:31:38 +08:00
|
|
|
} // namespace opts
|
|
|
|
|
|
|
|
#define LLVM_READOBJ_ENUM_ENT(ns, enum) \
|
|
|
|
{ #enum, ns::enum }
|
2013-02-20 10:37:12 +08:00
|
|
|
|
2016-01-14 03:32:35 +08:00
|
|
|
#define LLVM_READOBJ_ENUM_CLASS_ENT(enum_class, enum) \
|
|
|
|
{ #enum, std::underlying_type<enum_class>::type(enum_class::enum) }
|
|
|
|
|
2013-02-20 10:37:12 +08:00
|
|
|
#endif
|