Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 1 | //===-- llvm-symbolizer.cpp - Simple addr2line-like symbolizer ------------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This utility works much like "addr2line". It is able of transforming |
| 10 | // tuples (module name, module offset) to code locations (function name, |
| 11 | // file, line number, column number). It is targeted for compiler-rt tools |
| 12 | // (especially AddressSanitizer and ThreadSanitizer) that can use it |
| 13 | // to symbolize stack traces in their error reports. |
| 14 | // |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | |
Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/StringRef.h" |
Alexey Samsonov | d6aa820 | 2015-11-03 22:20:52 +0000 | [diff] [blame] | 18 | #include "llvm/DebugInfo/Symbolize/DIPrinter.h" |
Alexey Samsonov | 57f8837 | 2015-10-26 17:56:12 +0000 | [diff] [blame] | 19 | #include "llvm/DebugInfo/Symbolize/Symbolize.h" |
Zachary Turner | 20dbd0d | 2015-04-27 17:19:51 +0000 | [diff] [blame] | 20 | #include "llvm/Support/COM.h" |
Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 21 | #include "llvm/Support/CommandLine.h" |
| 22 | #include "llvm/Support/Debug.h" |
Alexander Potapenko | 7aaf514 | 2014-10-17 00:50:19 +0000 | [diff] [blame] | 23 | #include "llvm/Support/FileSystem.h" |
Rui Ueyama | 197194b | 2018-04-13 18:26:06 +0000 | [diff] [blame] | 24 | #include "llvm/Support/InitLLVM.h" |
Benjamin Kramer | 16132e6 | 2015-03-23 18:07:13 +0000 | [diff] [blame] | 25 | #include "llvm/Support/Path.h" |
Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 26 | #include "llvm/Support/raw_ostream.h" |
Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 27 | #include <cstdio> |
| 28 | #include <cstring> |
Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 29 | #include <string> |
| 30 | |
| 31 | using namespace llvm; |
Alexey Samsonov | ea83baf | 2013-01-22 14:21:19 +0000 | [diff] [blame] | 32 | using namespace symbolize; |
Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 33 | |
| 34 | static cl::opt<bool> |
Alexey Samsonov | ea83baf | 2013-01-22 14:21:19 +0000 | [diff] [blame] | 35 | ClUseSymbolTable("use-symbol-table", cl::init(true), |
Alexey Samsonov | d5d7bb5 | 2013-02-15 08:54:47 +0000 | [diff] [blame] | 36 | cl::desc("Prefer names in symbol table to names " |
| 37 | "in debug info")); |
Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 38 | |
Alexey Samsonov | cd01472 | 2014-05-17 00:07:48 +0000 | [diff] [blame] | 39 | static cl::opt<FunctionNameKind> ClPrintFunctions( |
| 40 | "functions", cl::init(FunctionNameKind::LinkageName), |
James Henderson | 9652652 | 2019-02-04 16:17:57 +0000 | [diff] [blame] | 41 | cl::desc("Print function name for a given address"), cl::ValueOptional, |
Alexey Samsonov | cd01472 | 2014-05-17 00:07:48 +0000 | [diff] [blame] | 42 | cl::values(clEnumValN(FunctionNameKind::None, "none", "omit function name"), |
| 43 | clEnumValN(FunctionNameKind::ShortName, "short", |
| 44 | "print short function name"), |
| 45 | clEnumValN(FunctionNameKind::LinkageName, "linkage", |
James Henderson | 25ce596 | 2019-01-23 17:27:48 +0000 | [diff] [blame] | 46 | "print function linkage name (default)"), |
| 47 | // Sentinel value for unspecified value. |
| 48 | clEnumValN(FunctionNameKind::LinkageName, "", ""))); |
| 49 | static cl::alias ClPrintFunctionsShort("f", cl::desc("Alias for -functions"), |
| 50 | cl::NotHidden, cl::Grouping, |
| 51 | cl::aliasopt(ClPrintFunctions)); |
Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 52 | |
| 53 | static cl::opt<bool> |
Zachary Turner | c007aa4 | 2015-05-06 22:26:30 +0000 | [diff] [blame] | 54 | ClUseRelativeAddress("relative-address", cl::init(false), |
| 55 | cl::desc("Interpret addresses as relative addresses"), |
| 56 | cl::ReallyHidden); |
| 57 | |
| 58 | static cl::opt<bool> |
| 59 | ClPrintInlining("inlining", cl::init(true), |
| 60 | cl::desc("Print all inlined frames for a given address")); |
Douglas Yung | 7876c0e | 2019-01-24 00:34:09 +0000 | [diff] [blame] | 61 | static cl::alias |
| 62 | ClPrintInliningAliasI("i", cl::desc("Alias for -inlining"), |
| 63 | cl::NotHidden, cl::aliasopt(ClPrintInlining), |
| 64 | cl::Grouping); |
| 65 | static cl::alias |
| 66 | ClPrintInliningAliasInlines("inlines", cl::desc("Alias for -inlining"), |
| 67 | cl::NotHidden, cl::aliasopt(ClPrintInlining)); |
Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 68 | |
James Henderson | 33c16a3 | 2019-01-22 10:24:32 +0000 | [diff] [blame] | 69 | // -basenames, -s |
| 70 | static cl::opt<bool> ClBasenames("basenames", cl::init(false), |
| 71 | cl::desc("Strip directory names from paths")); |
| 72 | static cl::alias ClBasenamesShort("s", cl::desc("Alias for -basenames"), |
| 73 | cl::NotHidden, cl::aliasopt(ClBasenames)); |
| 74 | |
Dmitry Venikov | 119cf66 | 2019-01-21 10:00:57 +0000 | [diff] [blame] | 75 | // -demangle, -C, -no-demangle |
Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 76 | static cl::opt<bool> |
Alexey Samsonov | d5d7bb5 | 2013-02-15 08:54:47 +0000 | [diff] [blame] | 77 | ClDemangle("demangle", cl::init(true), cl::desc("Demangle function names")); |
Dmitry Venikov | d3f21d3 | 2019-01-16 07:05:58 +0000 | [diff] [blame] | 78 | static cl::alias |
| 79 | ClDemangleShort("C", cl::desc("Alias for -demangle"), |
Dmitry Venikov | cce6687 | 2019-01-23 09:49:37 +0000 | [diff] [blame] | 80 | cl::NotHidden, cl::aliasopt(ClDemangle), cl::Grouping); |
Dmitry Venikov | 119cf66 | 2019-01-21 10:00:57 +0000 | [diff] [blame] | 81 | static cl::opt<bool> |
| 82 | ClNoDemangle("no-demangle", cl::init(false), |
| 83 | cl::desc("Don't demangle function names")); |
Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 84 | |
Alexey Samsonov | 2ca6536 | 2013-06-28 08:15:40 +0000 | [diff] [blame] | 85 | static cl::opt<std::string> ClDefaultArch("default-arch", cl::init(""), |
| 86 | cl::desc("Default architecture " |
| 87 | "(for multi-arch objects)")); |
| 88 | |
Dmitry Venikov | 37c1e2e | 2019-01-11 11:51:52 +0000 | [diff] [blame] | 89 | // -obj, -exe, -e |
Alexey Samsonov | 60e59e2 | 2013-12-24 19:33:22 +0000 | [diff] [blame] | 90 | static cl::opt<std::string> |
| 91 | ClBinaryName("obj", cl::init(""), |
| 92 | cl::desc("Path to object file to be symbolized (if not provided, " |
| 93 | "object file should be specified for each input line)")); |
Dmitry Venikov | 37c1e2e | 2019-01-11 11:51:52 +0000 | [diff] [blame] | 94 | static cl::alias |
| 95 | ClBinaryNameAliasExe("exe", cl::desc("Alias for -obj"), |
| 96 | cl::NotHidden, cl::aliasopt(ClBinaryName)); |
Igor Kudrin | 734a2bc | 2019-04-04 08:45:06 +0000 | [diff] [blame^] | 97 | static cl::alias ClBinaryNameAliasE("e", cl::desc("Alias for -obj"), |
| 98 | cl::NotHidden, cl::Grouping, cl::Prefix, |
| 99 | cl::aliasopt(ClBinaryName)); |
Alexey Samsonov | 60e59e2 | 2013-12-24 19:33:22 +0000 | [diff] [blame] | 100 | |
David Blaikie | e5adb68 | 2017-07-30 01:34:08 +0000 | [diff] [blame] | 101 | static cl::opt<std::string> |
| 102 | ClDwpName("dwp", cl::init(""), |
| 103 | cl::desc("Path to DWP file to be use for any split CUs")); |
| 104 | |
Alexander Potapenko | 7aaf514 | 2014-10-17 00:50:19 +0000 | [diff] [blame] | 105 | static cl::list<std::string> |
| 106 | ClDsymHint("dsym-hint", cl::ZeroOrMore, |
| 107 | cl::desc("Path to .dSYM bundles to search for debug info for the " |
| 108 | "object files")); |
Dmitry Venikov | 5c1768f | 2019-01-14 10:10:51 +0000 | [diff] [blame] | 109 | |
| 110 | // -print-address, -addresses, -a |
Hemant Kulkarni | 80f82fb | 2015-10-12 19:26:44 +0000 | [diff] [blame] | 111 | static cl::opt<bool> |
Dmitry Venikov | 5c1768f | 2019-01-14 10:10:51 +0000 | [diff] [blame] | 112 | ClPrintAddress("print-address", cl::init(false), |
| 113 | cl::desc("Show address before line information")); |
| 114 | static cl::alias |
| 115 | ClPrintAddressAliasAddresses("addresses", cl::desc("Alias for -print-address"), |
| 116 | cl::NotHidden, cl::aliasopt(ClPrintAddress)); |
| 117 | static cl::alias |
| 118 | ClPrintAddressAliasA("a", cl::desc("Alias for -print-address"), |
Dmitry Venikov | cce6687 | 2019-01-23 09:49:37 +0000 | [diff] [blame] | 119 | cl::NotHidden, cl::aliasopt(ClPrintAddress), cl::Grouping); |
Alexander Potapenko | 7aaf514 | 2014-10-17 00:50:19 +0000 | [diff] [blame] | 120 | |
Dmitry Venikov | 60d71e4 | 2019-01-10 15:33:35 +0000 | [diff] [blame] | 121 | // -pretty-print, -p |
Hemant Kulkarni | bdce12a | 2015-11-11 20:41:43 +0000 | [diff] [blame] | 122 | static cl::opt<bool> |
| 123 | ClPrettyPrint("pretty-print", cl::init(false), |
| 124 | cl::desc("Make the output more human friendly")); |
Dmitry Venikov | 60d71e4 | 2019-01-10 15:33:35 +0000 | [diff] [blame] | 125 | static cl::alias ClPrettyPrintShort("p", cl::desc("Alias for -pretty-print"), |
| 126 | cl::NotHidden, |
Dmitry Venikov | cce6687 | 2019-01-23 09:49:37 +0000 | [diff] [blame] | 127 | cl::aliasopt(ClPrettyPrint), cl::Grouping); |
Hemant Kulkarni | bdce12a | 2015-11-11 20:41:43 +0000 | [diff] [blame] | 128 | |
Mike Aizatsky | 17dbc28 | 2016-01-09 00:14:35 +0000 | [diff] [blame] | 129 | static cl::opt<int> ClPrintSourceContextLines( |
| 130 | "print-source-context-lines", cl::init(0), |
| 131 | cl::desc("Print N number of source file context")); |
| 132 | |
David Blaikie | 0012dd5 | 2017-01-31 22:19:38 +0000 | [diff] [blame] | 133 | static cl::opt<bool> ClVerbose("verbose", cl::init(false), |
| 134 | cl::desc("Print verbose line info")); |
| 135 | |
James Henderson | 759d5e6 | 2019-01-25 11:49:21 +0000 | [diff] [blame] | 136 | // -adjust-vma |
| 137 | static cl::opt<unsigned long long> |
| 138 | ClAdjustVMA("adjust-vma", cl::init(0), cl::value_desc("offset"), |
| 139 | cl::desc("Add specified offset to object file addresses")); |
| 140 | |
James Henderson | 3a6a5a3 | 2019-01-10 14:10:02 +0000 | [diff] [blame] | 141 | static cl::list<std::string> ClInputAddresses(cl::Positional, |
| 142 | cl::desc("<input addresses>..."), |
| 143 | cl::ZeroOrMore); |
| 144 | |
Jordan Rupprecht | 5b7ad42 | 2019-02-11 18:05:48 +0000 | [diff] [blame] | 145 | static cl::opt<std::string> |
| 146 | ClFallbackDebugPath("fallback-debug-path", cl::init(""), |
| 147 | cl::desc("Fallback path for debug binaries.")); |
| 148 | |
Igor Kudrin | 0fed7b0 | 2019-04-04 08:39:40 +0000 | [diff] [blame] | 149 | static cl::opt<DIPrinter::OutputStyle> |
| 150 | ClOutputStyle("output-style", cl::init(DIPrinter::OutputStyle::LLVM), |
| 151 | cl::desc("Specify print style"), cl::Hidden, |
| 152 | cl::values(clEnumValN(DIPrinter::OutputStyle::LLVM, "LLVM", |
| 153 | "LLVM default style"), |
| 154 | clEnumValN(DIPrinter::OutputStyle::GNU, "GNU", |
| 155 | "GNU addr2line style"))); |
| 156 | |
Reid Kleckner | f27f3f8 | 2016-06-03 20:25:09 +0000 | [diff] [blame] | 157 | template<typename T> |
| 158 | static bool error(Expected<T> &ResOrErr) { |
| 159 | if (ResOrErr) |
Alexey Samsonov | 884adda | 2015-11-04 00:30:24 +0000 | [diff] [blame] | 160 | return false; |
Reid Kleckner | f27f3f8 | 2016-06-03 20:25:09 +0000 | [diff] [blame] | 161 | logAllUnhandledErrors(ResOrErr.takeError(), errs(), |
| 162 | "LLVMSymbolizer: error reading file: "); |
Alexey Samsonov | 884adda | 2015-11-04 00:30:24 +0000 | [diff] [blame] | 163 | return true; |
| 164 | } |
| 165 | |
Mike Aizatsky | 54a7c69 | 2016-01-07 23:57:41 +0000 | [diff] [blame] | 166 | static bool parseCommand(StringRef InputString, bool &IsData, |
| 167 | std::string &ModuleName, uint64_t &ModuleOffset) { |
Mike Aizatsky | 54a7c69 | 2016-01-07 23:57:41 +0000 | [diff] [blame] | 168 | const char kDelimiters[] = " \n\r"; |
Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 169 | ModuleName = ""; |
Fangrui Song | 3b7499d | 2018-05-25 00:11:15 +0000 | [diff] [blame] | 170 | if (InputString.consume_front("CODE ")) { |
Dmitry Vyukov | d08bd13 | 2013-01-11 07:16:20 +0000 | [diff] [blame] | 171 | IsData = false; |
Fangrui Song | 3b7499d | 2018-05-25 00:11:15 +0000 | [diff] [blame] | 172 | } else if (InputString.consume_front("DATA ")) { |
| 173 | IsData = true; |
Dmitry Vyukov | d08bd13 | 2013-01-11 07:16:20 +0000 | [diff] [blame] | 174 | } else { |
| 175 | // If no cmd, assume it's CODE. |
| 176 | IsData = false; |
| 177 | } |
Fangrui Song | 3b7499d | 2018-05-25 00:11:15 +0000 | [diff] [blame] | 178 | const char *pos = InputString.data(); |
Alexey Samsonov | 60e59e2 | 2013-12-24 19:33:22 +0000 | [diff] [blame] | 179 | // Skip delimiters and parse input filename (if needed). |
Fangrui Song | ffebfe1 | 2018-05-26 02:29:14 +0000 | [diff] [blame] | 180 | if (ClBinaryName.empty()) { |
Alexey Samsonov | 60e59e2 | 2013-12-24 19:33:22 +0000 | [diff] [blame] | 181 | pos += strspn(pos, kDelimiters); |
| 182 | if (*pos == '"' || *pos == '\'') { |
| 183 | char quote = *pos; |
| 184 | pos++; |
Mike Aizatsky | 54a7c69 | 2016-01-07 23:57:41 +0000 | [diff] [blame] | 185 | const char *end = strchr(pos, quote); |
Craig Topper | e6cb63e | 2014-04-25 04:24:47 +0000 | [diff] [blame] | 186 | if (!end) |
Alexey Samsonov | 60e59e2 | 2013-12-24 19:33:22 +0000 | [diff] [blame] | 187 | return false; |
| 188 | ModuleName = std::string(pos, end - pos); |
| 189 | pos = end + 1; |
| 190 | } else { |
| 191 | int name_length = strcspn(pos, kDelimiters); |
| 192 | ModuleName = std::string(pos, name_length); |
| 193 | pos += name_length; |
| 194 | } |
Alexey Samsonov | d206932 | 2013-04-05 09:22:24 +0000 | [diff] [blame] | 195 | } else { |
Alexey Samsonov | 60e59e2 | 2013-12-24 19:33:22 +0000 | [diff] [blame] | 196 | ModuleName = ClBinaryName; |
Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 197 | } |
Alexey Samsonov | d206932 | 2013-04-05 09:22:24 +0000 | [diff] [blame] | 198 | // Skip delimiters and parse module offset. |
| 199 | pos += strspn(pos, kDelimiters); |
| 200 | int offset_length = strcspn(pos, kDelimiters); |
Rafael Espindola | 2c5bcc5 | 2015-10-24 23:23:25 +0000 | [diff] [blame] | 201 | return !StringRef(pos, offset_length).getAsInteger(0, ModuleOffset); |
Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 202 | } |
| 203 | |
James Henderson | 3a6a5a3 | 2019-01-10 14:10:02 +0000 | [diff] [blame] | 204 | static void symbolizeInput(StringRef InputString, LLVMSymbolizer &Symbolizer, |
| 205 | DIPrinter &Printer) { |
| 206 | bool IsData = false; |
| 207 | std::string ModuleName; |
Alexey Lapshin | 77fc1f6 | 2019-02-27 13:17:36 +0000 | [diff] [blame] | 208 | uint64_t Offset = 0; |
| 209 | if (!parseCommand(StringRef(InputString), IsData, ModuleName, Offset)) { |
James Henderson | 3a6a5a3 | 2019-01-10 14:10:02 +0000 | [diff] [blame] | 210 | outs() << InputString; |
| 211 | return; |
| 212 | } |
| 213 | |
| 214 | if (ClPrintAddress) { |
| 215 | outs() << "0x"; |
Alexey Lapshin | 77fc1f6 | 2019-02-27 13:17:36 +0000 | [diff] [blame] | 216 | outs().write_hex(Offset); |
James Henderson | 3a6a5a3 | 2019-01-10 14:10:02 +0000 | [diff] [blame] | 217 | StringRef Delimiter = ClPrettyPrint ? ": " : "\n"; |
| 218 | outs() << Delimiter; |
| 219 | } |
Alexey Lapshin | 77fc1f6 | 2019-02-27 13:17:36 +0000 | [diff] [blame] | 220 | Offset -= ClAdjustVMA; |
James Henderson | 3a6a5a3 | 2019-01-10 14:10:02 +0000 | [diff] [blame] | 221 | if (IsData) { |
Alexey Lapshin | b2c4b8b | 2019-03-23 08:08:40 +0000 | [diff] [blame] | 222 | auto ResOrErr = Symbolizer.symbolizeData( |
| 223 | ModuleName, {Offset, object::SectionedAddress::UndefSection}); |
James Henderson | 3a6a5a3 | 2019-01-10 14:10:02 +0000 | [diff] [blame] | 224 | Printer << (error(ResOrErr) ? DIGlobal() : ResOrErr.get()); |
| 225 | } else if (ClPrintInlining) { |
Alexey Lapshin | b2c4b8b | 2019-03-23 08:08:40 +0000 | [diff] [blame] | 226 | auto ResOrErr = Symbolizer.symbolizeInlinedCode( |
| 227 | ModuleName, {Offset, object::SectionedAddress::UndefSection}, |
| 228 | ClDwpName); |
James Henderson | 3a6a5a3 | 2019-01-10 14:10:02 +0000 | [diff] [blame] | 229 | Printer << (error(ResOrErr) ? DIInliningInfo() : ResOrErr.get()); |
| 230 | } else { |
Alexey Lapshin | b2c4b8b | 2019-03-23 08:08:40 +0000 | [diff] [blame] | 231 | auto ResOrErr = Symbolizer.symbolizeCode( |
| 232 | ModuleName, {Offset, object::SectionedAddress::UndefSection}, |
| 233 | ClDwpName); |
James Henderson | 3a6a5a3 | 2019-01-10 14:10:02 +0000 | [diff] [blame] | 234 | Printer << (error(ResOrErr) ? DILineInfo() : ResOrErr.get()); |
| 235 | } |
| 236 | outs() << "\n"; |
| 237 | outs().flush(); |
| 238 | } |
| 239 | |
Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 240 | int main(int argc, char **argv) { |
Rui Ueyama | 197194b | 2018-04-13 18:26:06 +0000 | [diff] [blame] | 241 | InitLLVM X(argc, argv); |
Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 242 | |
Zachary Turner | 20dbd0d | 2015-04-27 17:19:51 +0000 | [diff] [blame] | 243 | llvm::sys::InitializeCOMRAII COM(llvm::sys::COMThreadingMode::MultiThreaded); |
Alexey Samsonov | 60e59e2 | 2013-12-24 19:33:22 +0000 | [diff] [blame] | 244 | cl::ParseCommandLineOptions(argc, argv, "llvm-symbolizer\n"); |
Dmitry Venikov | 119cf66 | 2019-01-21 10:00:57 +0000 | [diff] [blame] | 245 | |
| 246 | // If both --demangle and --no-demangle are specified then pick the last one. |
| 247 | if (ClNoDemangle.getPosition() > ClDemangle.getPosition()) |
| 248 | ClDemangle = !ClNoDemangle; |
| 249 | |
Alexey Samsonov | 46c1ce6 | 2015-10-30 00:40:20 +0000 | [diff] [blame] | 250 | LLVMSymbolizer::Options Opts(ClPrintFunctions, ClUseSymbolTable, ClDemangle, |
Jordan Rupprecht | 5b7ad42 | 2019-02-11 18:05:48 +0000 | [diff] [blame] | 251 | ClUseRelativeAddress, ClDefaultArch, |
| 252 | ClFallbackDebugPath); |
Hemant Kulkarni | bdce12a | 2015-11-11 20:41:43 +0000 | [diff] [blame] | 253 | |
Alexander Potapenko | 7aaf514 | 2014-10-17 00:50:19 +0000 | [diff] [blame] | 254 | for (const auto &hint : ClDsymHint) { |
| 255 | if (sys::path::extension(hint) == ".dSYM") { |
| 256 | Opts.DsymHints.push_back(hint); |
| 257 | } else { |
| 258 | errs() << "Warning: invalid dSYM hint: \"" << hint << |
| 259 | "\" (must have the '.dSYM' extension).\n"; |
| 260 | } |
| 261 | } |
Alexey Samsonov | ea83baf | 2013-01-22 14:21:19 +0000 | [diff] [blame] | 262 | LLVMSymbolizer Symbolizer(Opts); |
Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 263 | |
Hemant Kulkarni | bdce12a | 2015-11-11 20:41:43 +0000 | [diff] [blame] | 264 | DIPrinter Printer(outs(), ClPrintFunctions != FunctionNameKind::None, |
James Henderson | 33c16a3 | 2019-01-22 10:24:32 +0000 | [diff] [blame] | 265 | ClPrettyPrint, ClPrintSourceContextLines, ClVerbose, |
Igor Kudrin | 0fed7b0 | 2019-04-04 08:39:40 +0000 | [diff] [blame] | 266 | ClBasenames, ClOutputStyle); |
Alexey Samsonov | d6aa820 | 2015-11-03 22:20:52 +0000 | [diff] [blame] | 267 | |
James Henderson | 3a6a5a3 | 2019-01-10 14:10:02 +0000 | [diff] [blame] | 268 | if (ClInputAddresses.empty()) { |
| 269 | const int kMaxInputStringLength = 1024; |
| 270 | char InputString[kMaxInputStringLength]; |
Mike Aizatsky | 54a7c69 | 2016-01-07 23:57:41 +0000 | [diff] [blame] | 271 | |
James Henderson | 3a6a5a3 | 2019-01-10 14:10:02 +0000 | [diff] [blame] | 272 | while (fgets(InputString, sizeof(InputString), stdin)) |
| 273 | symbolizeInput(InputString, Symbolizer, Printer); |
| 274 | } else { |
| 275 | for (StringRef Address : ClInputAddresses) |
| 276 | symbolizeInput(Address, Symbolizer, Printer); |
Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 277 | } |
Zachary Turner | 20dbd0d | 2015-04-27 17:19:51 +0000 | [diff] [blame] | 278 | |
Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 279 | return 0; |
| 280 | } |