| 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)); |
| 97 | static cl::alias |
| 98 | ClBinaryNameAliasE("e", cl::desc("Alias for -obj"), |
| 99 | cl::NotHidden, cl::aliasopt(ClBinaryName)); |
| 100 | |
| Alexey Samsonov | 60e59e2 | 2013-12-24 19:33:22 +0000 | [diff] [blame] | 101 | |
| David Blaikie | e5adb68 | 2017-07-30 01:34:08 +0000 | [diff] [blame] | 102 | static cl::opt<std::string> |
| 103 | ClDwpName("dwp", cl::init(""), |
| 104 | cl::desc("Path to DWP file to be use for any split CUs")); |
| 105 | |
| Alexander Potapenko | 7aaf514 | 2014-10-17 00:50:19 +0000 | [diff] [blame] | 106 | static cl::list<std::string> |
| 107 | ClDsymHint("dsym-hint", cl::ZeroOrMore, |
| 108 | cl::desc("Path to .dSYM bundles to search for debug info for the " |
| 109 | "object files")); |
| Dmitry Venikov | 5c1768f | 2019-01-14 10:10:51 +0000 | [diff] [blame] | 110 | |
| 111 | // -print-address, -addresses, -a |
| Hemant Kulkarni | 80f82fb | 2015-10-12 19:26:44 +0000 | [diff] [blame] | 112 | static cl::opt<bool> |
| Dmitry Venikov | 5c1768f | 2019-01-14 10:10:51 +0000 | [diff] [blame] | 113 | ClPrintAddress("print-address", cl::init(false), |
| 114 | cl::desc("Show address before line information")); |
| 115 | static cl::alias |
| 116 | ClPrintAddressAliasAddresses("addresses", cl::desc("Alias for -print-address"), |
| 117 | cl::NotHidden, cl::aliasopt(ClPrintAddress)); |
| 118 | static cl::alias |
| 119 | ClPrintAddressAliasA("a", cl::desc("Alias for -print-address"), |
| Dmitry Venikov | cce6687 | 2019-01-23 09:49:37 +0000 | [diff] [blame] | 120 | cl::NotHidden, cl::aliasopt(ClPrintAddress), cl::Grouping); |
| Alexander Potapenko | 7aaf514 | 2014-10-17 00:50:19 +0000 | [diff] [blame] | 121 | |
| Dmitry Venikov | 60d71e4 | 2019-01-10 15:33:35 +0000 | [diff] [blame] | 122 | // -pretty-print, -p |
| Hemant Kulkarni | bdce12a | 2015-11-11 20:41:43 +0000 | [diff] [blame] | 123 | static cl::opt<bool> |
| 124 | ClPrettyPrint("pretty-print", cl::init(false), |
| 125 | cl::desc("Make the output more human friendly")); |
| Dmitry Venikov | 60d71e4 | 2019-01-10 15:33:35 +0000 | [diff] [blame] | 126 | static cl::alias ClPrettyPrintShort("p", cl::desc("Alias for -pretty-print"), |
| 127 | cl::NotHidden, |
| Dmitry Venikov | cce6687 | 2019-01-23 09:49:37 +0000 | [diff] [blame] | 128 | cl::aliasopt(ClPrettyPrint), cl::Grouping); |
| Hemant Kulkarni | bdce12a | 2015-11-11 20:41:43 +0000 | [diff] [blame] | 129 | |
| Mike Aizatsky | 17dbc28 | 2016-01-09 00:14:35 +0000 | [diff] [blame] | 130 | static cl::opt<int> ClPrintSourceContextLines( |
| 131 | "print-source-context-lines", cl::init(0), |
| 132 | cl::desc("Print N number of source file context")); |
| 133 | |
| David Blaikie | 0012dd5 | 2017-01-31 22:19:38 +0000 | [diff] [blame] | 134 | static cl::opt<bool> ClVerbose("verbose", cl::init(false), |
| 135 | cl::desc("Print verbose line info")); |
| 136 | |
| James Henderson | 759d5e6 | 2019-01-25 11:49:21 +0000 | [diff] [blame] | 137 | // -adjust-vma |
| 138 | static cl::opt<unsigned long long> |
| 139 | ClAdjustVMA("adjust-vma", cl::init(0), cl::value_desc("offset"), |
| 140 | cl::desc("Add specified offset to object file addresses")); |
| 141 | |
| James Henderson | 3a6a5a3 | 2019-01-10 14:10:02 +0000 | [diff] [blame] | 142 | static cl::list<std::string> ClInputAddresses(cl::Positional, |
| 143 | cl::desc("<input addresses>..."), |
| 144 | cl::ZeroOrMore); |
| 145 | |
| Jordan Rupprecht | 5b7ad42 | 2019-02-11 18:05:48 +0000 | [diff] [blame] | 146 | static cl::opt<std::string> |
| 147 | ClFallbackDebugPath("fallback-debug-path", cl::init(""), |
| 148 | cl::desc("Fallback path for debug binaries.")); |
| 149 | |
| Igor Kudrin | 0fed7b0 | 2019-04-04 08:39:40 +0000 | [diff] [blame^] | 150 | static cl::opt<DIPrinter::OutputStyle> |
| 151 | ClOutputStyle("output-style", cl::init(DIPrinter::OutputStyle::LLVM), |
| 152 | cl::desc("Specify print style"), cl::Hidden, |
| 153 | cl::values(clEnumValN(DIPrinter::OutputStyle::LLVM, "LLVM", |
| 154 | "LLVM default style"), |
| 155 | clEnumValN(DIPrinter::OutputStyle::GNU, "GNU", |
| 156 | "GNU addr2line style"))); |
| 157 | |
| Reid Kleckner | f27f3f8 | 2016-06-03 20:25:09 +0000 | [diff] [blame] | 158 | template<typename T> |
| 159 | static bool error(Expected<T> &ResOrErr) { |
| 160 | if (ResOrErr) |
| Alexey Samsonov | 884adda | 2015-11-04 00:30:24 +0000 | [diff] [blame] | 161 | return false; |
| Reid Kleckner | f27f3f8 | 2016-06-03 20:25:09 +0000 | [diff] [blame] | 162 | logAllUnhandledErrors(ResOrErr.takeError(), errs(), |
| 163 | "LLVMSymbolizer: error reading file: "); |
| Alexey Samsonov | 884adda | 2015-11-04 00:30:24 +0000 | [diff] [blame] | 164 | return true; |
| 165 | } |
| 166 | |
| Mike Aizatsky | 54a7c69 | 2016-01-07 23:57:41 +0000 | [diff] [blame] | 167 | static bool parseCommand(StringRef InputString, bool &IsData, |
| 168 | std::string &ModuleName, uint64_t &ModuleOffset) { |
| Mike Aizatsky | 54a7c69 | 2016-01-07 23:57:41 +0000 | [diff] [blame] | 169 | const char kDelimiters[] = " \n\r"; |
| Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 170 | ModuleName = ""; |
| Fangrui Song | 3b7499d | 2018-05-25 00:11:15 +0000 | [diff] [blame] | 171 | if (InputString.consume_front("CODE ")) { |
| Dmitry Vyukov | d08bd13 | 2013-01-11 07:16:20 +0000 | [diff] [blame] | 172 | IsData = false; |
| Fangrui Song | 3b7499d | 2018-05-25 00:11:15 +0000 | [diff] [blame] | 173 | } else if (InputString.consume_front("DATA ")) { |
| 174 | IsData = true; |
| Dmitry Vyukov | d08bd13 | 2013-01-11 07:16:20 +0000 | [diff] [blame] | 175 | } else { |
| 176 | // If no cmd, assume it's CODE. |
| 177 | IsData = false; |
| 178 | } |
| Fangrui Song | 3b7499d | 2018-05-25 00:11:15 +0000 | [diff] [blame] | 179 | const char *pos = InputString.data(); |
| Alexey Samsonov | 60e59e2 | 2013-12-24 19:33:22 +0000 | [diff] [blame] | 180 | // Skip delimiters and parse input filename (if needed). |
| Fangrui Song | ffebfe1 | 2018-05-26 02:29:14 +0000 | [diff] [blame] | 181 | if (ClBinaryName.empty()) { |
| Alexey Samsonov | 60e59e2 | 2013-12-24 19:33:22 +0000 | [diff] [blame] | 182 | pos += strspn(pos, kDelimiters); |
| 183 | if (*pos == '"' || *pos == '\'') { |
| 184 | char quote = *pos; |
| 185 | pos++; |
| Mike Aizatsky | 54a7c69 | 2016-01-07 23:57:41 +0000 | [diff] [blame] | 186 | const char *end = strchr(pos, quote); |
| Craig Topper | e6cb63e | 2014-04-25 04:24:47 +0000 | [diff] [blame] | 187 | if (!end) |
| Alexey Samsonov | 60e59e2 | 2013-12-24 19:33:22 +0000 | [diff] [blame] | 188 | return false; |
| 189 | ModuleName = std::string(pos, end - pos); |
| 190 | pos = end + 1; |
| 191 | } else { |
| 192 | int name_length = strcspn(pos, kDelimiters); |
| 193 | ModuleName = std::string(pos, name_length); |
| 194 | pos += name_length; |
| 195 | } |
| Alexey Samsonov | d206932 | 2013-04-05 09:22:24 +0000 | [diff] [blame] | 196 | } else { |
| Alexey Samsonov | 60e59e2 | 2013-12-24 19:33:22 +0000 | [diff] [blame] | 197 | ModuleName = ClBinaryName; |
| Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 198 | } |
| Alexey Samsonov | d206932 | 2013-04-05 09:22:24 +0000 | [diff] [blame] | 199 | // Skip delimiters and parse module offset. |
| 200 | pos += strspn(pos, kDelimiters); |
| 201 | int offset_length = strcspn(pos, kDelimiters); |
| Rafael Espindola | 2c5bcc5 | 2015-10-24 23:23:25 +0000 | [diff] [blame] | 202 | return !StringRef(pos, offset_length).getAsInteger(0, ModuleOffset); |
| Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| James Henderson | 3a6a5a3 | 2019-01-10 14:10:02 +0000 | [diff] [blame] | 205 | static void symbolizeInput(StringRef InputString, LLVMSymbolizer &Symbolizer, |
| 206 | DIPrinter &Printer) { |
| 207 | bool IsData = false; |
| 208 | std::string ModuleName; |
| Alexey Lapshin | 77fc1f6 | 2019-02-27 13:17:36 +0000 | [diff] [blame] | 209 | uint64_t Offset = 0; |
| 210 | if (!parseCommand(StringRef(InputString), IsData, ModuleName, Offset)) { |
| James Henderson | 3a6a5a3 | 2019-01-10 14:10:02 +0000 | [diff] [blame] | 211 | outs() << InputString; |
| 212 | return; |
| 213 | } |
| 214 | |
| 215 | if (ClPrintAddress) { |
| 216 | outs() << "0x"; |
| Alexey Lapshin | 77fc1f6 | 2019-02-27 13:17:36 +0000 | [diff] [blame] | 217 | outs().write_hex(Offset); |
| James Henderson | 3a6a5a3 | 2019-01-10 14:10:02 +0000 | [diff] [blame] | 218 | StringRef Delimiter = ClPrettyPrint ? ": " : "\n"; |
| 219 | outs() << Delimiter; |
| 220 | } |
| Alexey Lapshin | 77fc1f6 | 2019-02-27 13:17:36 +0000 | [diff] [blame] | 221 | Offset -= ClAdjustVMA; |
| James Henderson | 3a6a5a3 | 2019-01-10 14:10:02 +0000 | [diff] [blame] | 222 | if (IsData) { |
| Alexey Lapshin | b2c4b8b | 2019-03-23 08:08:40 +0000 | [diff] [blame] | 223 | auto ResOrErr = Symbolizer.symbolizeData( |
| 224 | ModuleName, {Offset, object::SectionedAddress::UndefSection}); |
| James Henderson | 3a6a5a3 | 2019-01-10 14:10:02 +0000 | [diff] [blame] | 225 | Printer << (error(ResOrErr) ? DIGlobal() : ResOrErr.get()); |
| 226 | } else if (ClPrintInlining) { |
| Alexey Lapshin | b2c4b8b | 2019-03-23 08:08:40 +0000 | [diff] [blame] | 227 | auto ResOrErr = Symbolizer.symbolizeInlinedCode( |
| 228 | ModuleName, {Offset, object::SectionedAddress::UndefSection}, |
| 229 | ClDwpName); |
| James Henderson | 3a6a5a3 | 2019-01-10 14:10:02 +0000 | [diff] [blame] | 230 | Printer << (error(ResOrErr) ? DIInliningInfo() : ResOrErr.get()); |
| 231 | } else { |
| Alexey Lapshin | b2c4b8b | 2019-03-23 08:08:40 +0000 | [diff] [blame] | 232 | auto ResOrErr = Symbolizer.symbolizeCode( |
| 233 | ModuleName, {Offset, object::SectionedAddress::UndefSection}, |
| 234 | ClDwpName); |
| James Henderson | 3a6a5a3 | 2019-01-10 14:10:02 +0000 | [diff] [blame] | 235 | Printer << (error(ResOrErr) ? DILineInfo() : ResOrErr.get()); |
| 236 | } |
| 237 | outs() << "\n"; |
| 238 | outs().flush(); |
| 239 | } |
| 240 | |
| Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 241 | int main(int argc, char **argv) { |
| Rui Ueyama | 197194b | 2018-04-13 18:26:06 +0000 | [diff] [blame] | 242 | InitLLVM X(argc, argv); |
| Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 243 | |
| Zachary Turner | 20dbd0d | 2015-04-27 17:19:51 +0000 | [diff] [blame] | 244 | llvm::sys::InitializeCOMRAII COM(llvm::sys::COMThreadingMode::MultiThreaded); |
| Alexey Samsonov | 60e59e2 | 2013-12-24 19:33:22 +0000 | [diff] [blame] | 245 | cl::ParseCommandLineOptions(argc, argv, "llvm-symbolizer\n"); |
| Dmitry Venikov | 119cf66 | 2019-01-21 10:00:57 +0000 | [diff] [blame] | 246 | |
| 247 | // If both --demangle and --no-demangle are specified then pick the last one. |
| 248 | if (ClNoDemangle.getPosition() > ClDemangle.getPosition()) |
| 249 | ClDemangle = !ClNoDemangle; |
| 250 | |
| Alexey Samsonov | 46c1ce6 | 2015-10-30 00:40:20 +0000 | [diff] [blame] | 251 | LLVMSymbolizer::Options Opts(ClPrintFunctions, ClUseSymbolTable, ClDemangle, |
| Jordan Rupprecht | 5b7ad42 | 2019-02-11 18:05:48 +0000 | [diff] [blame] | 252 | ClUseRelativeAddress, ClDefaultArch, |
| 253 | ClFallbackDebugPath); |
| Hemant Kulkarni | bdce12a | 2015-11-11 20:41:43 +0000 | [diff] [blame] | 254 | |
| Alexander Potapenko | 7aaf514 | 2014-10-17 00:50:19 +0000 | [diff] [blame] | 255 | for (const auto &hint : ClDsymHint) { |
| 256 | if (sys::path::extension(hint) == ".dSYM") { |
| 257 | Opts.DsymHints.push_back(hint); |
| 258 | } else { |
| 259 | errs() << "Warning: invalid dSYM hint: \"" << hint << |
| 260 | "\" (must have the '.dSYM' extension).\n"; |
| 261 | } |
| 262 | } |
| Alexey Samsonov | ea83baf | 2013-01-22 14:21:19 +0000 | [diff] [blame] | 263 | LLVMSymbolizer Symbolizer(Opts); |
| Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 264 | |
| Hemant Kulkarni | bdce12a | 2015-11-11 20:41:43 +0000 | [diff] [blame] | 265 | DIPrinter Printer(outs(), ClPrintFunctions != FunctionNameKind::None, |
| James Henderson | 33c16a3 | 2019-01-22 10:24:32 +0000 | [diff] [blame] | 266 | ClPrettyPrint, ClPrintSourceContextLines, ClVerbose, |
| Igor Kudrin | 0fed7b0 | 2019-04-04 08:39:40 +0000 | [diff] [blame^] | 267 | ClBasenames, ClOutputStyle); |
| Alexey Samsonov | d6aa820 | 2015-11-03 22:20:52 +0000 | [diff] [blame] | 268 | |
| James Henderson | 3a6a5a3 | 2019-01-10 14:10:02 +0000 | [diff] [blame] | 269 | if (ClInputAddresses.empty()) { |
| 270 | const int kMaxInputStringLength = 1024; |
| 271 | char InputString[kMaxInputStringLength]; |
| Mike Aizatsky | 54a7c69 | 2016-01-07 23:57:41 +0000 | [diff] [blame] | 272 | |
| James Henderson | 3a6a5a3 | 2019-01-10 14:10:02 +0000 | [diff] [blame] | 273 | while (fgets(InputString, sizeof(InputString), stdin)) |
| 274 | symbolizeInput(InputString, Symbolizer, Printer); |
| 275 | } else { |
| 276 | for (StringRef Address : ClInputAddresses) |
| 277 | symbolizeInput(Address, Symbolizer, Printer); |
| Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 278 | } |
| Zachary Turner | 20dbd0d | 2015-04-27 17:19:51 +0000 | [diff] [blame] | 279 | |
| Alexander Potapenko | 8c07f55 | 2012-11-12 11:33:29 +0000 | [diff] [blame] | 280 | return 0; |
| 281 | } |