Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- CommandObjectSource.cpp ---------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Daniel Malea | d891f9b | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 12 | #include "CommandObjectSource.h" |
| 13 | |
| 14 | // C Includes |
| 15 | // C++ Includes |
| 16 | // Other libraries and framework includes |
| 17 | // Project includes |
Jim Ingham | 84cdc15 | 2010-06-15 19:49:27 +0000 | [diff] [blame] | 18 | #include "lldb/Interpreter/Args.h" |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 19 | #include "lldb/Core/Debugger.h" |
Greg Clayton | 52c8b6e | 2011-04-19 04:19:37 +0000 | [diff] [blame] | 20 | #include "lldb/Core/FileLineResolver.h" |
Greg Clayton | 7812411 | 2012-12-07 00:19:47 +0000 | [diff] [blame] | 21 | #include "lldb/Core/Module.h" |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 22 | #include "lldb/Core/ModuleSpec.h" |
Greg Clayton | 52c8b6e | 2011-04-19 04:19:37 +0000 | [diff] [blame] | 23 | #include "lldb/Core/SourceManager.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 25 | #include "lldb/Interpreter/CommandReturnObject.h" |
Greg Clayton | 5f54ac3 | 2011-02-08 05:05:52 +0000 | [diff] [blame] | 26 | #include "lldb/Host/FileSpec.h" |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 27 | #include "lldb/Symbol/CompileUnit.h" |
| 28 | #include "lldb/Symbol/Function.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | #include "lldb/Target/Process.h" |
| 30 | #include "lldb/Target/TargetList.h" |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 31 | #include "lldb/Interpreter/CommandCompletions.h" |
| 32 | #include "lldb/Interpreter/Options.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 33 | |
| 34 | using namespace lldb; |
| 35 | using namespace lldb_private; |
| 36 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 37 | //------------------------------------------------------------------------- |
Greg Clayton | 52c8b6e | 2011-04-19 04:19:37 +0000 | [diff] [blame] | 38 | // CommandObjectSourceInfo |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | //------------------------------------------------------------------------- |
| 40 | |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 41 | class CommandObjectSourceInfo : public CommandObjectParsed |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 42 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 44 | class CommandOptions : public Options |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 45 | { |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 46 | public: |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 47 | CommandOptions (CommandInterpreter &interpreter) : |
| 48 | Options(interpreter) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 49 | { |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 50 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 51 | |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 52 | ~CommandOptions () |
| 53 | { |
| 54 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 55 | |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 56 | Error |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 57 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 58 | { |
| 59 | Error error; |
Greg Clayton | 6475c42 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 60 | const int short_option = g_option_table[option_idx].short_option; |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 61 | switch (short_option) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 62 | { |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 63 | case 'l': |
| 64 | start_line = Args::StringToUInt32 (option_arg, 0); |
| 65 | if (start_line == 0) |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 66 | error.SetErrorStringWithFormat("invalid line number: '%s'", option_arg); |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 67 | break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 68 | |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 69 | case 'f': |
| 70 | file_name = option_arg; |
| 71 | break; |
| 72 | |
| 73 | default: |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 74 | error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option); |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 75 | break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 78 | return error; |
| 79 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 80 | |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 81 | void |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 82 | OptionParsingStarting () |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 83 | { |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 84 | file_spec.Clear(); |
| 85 | file_name.clear(); |
| 86 | start_line = 0; |
| 87 | } |
| 88 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 89 | const OptionDefinition* |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 90 | GetDefinitions () |
| 91 | { |
| 92 | return g_option_table; |
| 93 | } |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 94 | static OptionDefinition g_option_table[]; |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 95 | |
| 96 | // Instance variables to hold the values for command options. |
| 97 | FileSpec file_spec; |
| 98 | std::string file_name; |
| 99 | uint32_t start_line; |
| 100 | |
| 101 | }; |
| 102 | |
| 103 | public: |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 104 | CommandObjectSourceInfo(CommandInterpreter &interpreter) : |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 105 | CommandObjectParsed (interpreter, |
| 106 | "source info", |
| 107 | "Display information about the source lines from the current executable's debug info.", |
| 108 | "source info [<cmd-options>]"), |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 109 | m_options (interpreter) |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 110 | { |
| 111 | } |
| 112 | |
| 113 | ~CommandObjectSourceInfo () |
| 114 | { |
| 115 | } |
| 116 | |
| 117 | |
| 118 | Options * |
| 119 | GetOptions () |
| 120 | { |
| 121 | return &m_options; |
| 122 | } |
| 123 | |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 124 | protected: |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 125 | bool |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 126 | DoExecute (Args& command, CommandReturnObject &result) |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 127 | { |
| 128 | result.AppendError ("Not yet implemented"); |
| 129 | result.SetStatus (eReturnStatusFailed); |
| 130 | return false; |
| 131 | } |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 132 | |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 133 | CommandOptions m_options; |
| 134 | }; |
| 135 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 136 | OptionDefinition |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 137 | CommandObjectSourceInfo::CommandOptions::g_option_table[] = |
| 138 | { |
Caroline Tice | 4d6675c | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 139 | { LLDB_OPT_SET_1, false, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum, "The line number at which to start the display source."}, |
| 140 | { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, "The file from which to display source."}, |
| 141 | { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | #pragma mark CommandObjectSourceList |
| 145 | //------------------------------------------------------------------------- |
| 146 | // CommandObjectSourceList |
| 147 | //------------------------------------------------------------------------- |
| 148 | |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 149 | class CommandObjectSourceList : public CommandObjectParsed |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 150 | { |
| 151 | |
| 152 | class CommandOptions : public Options |
| 153 | { |
| 154 | public: |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 155 | CommandOptions (CommandInterpreter &interpreter) : |
| 156 | Options(interpreter) |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 157 | { |
| 158 | } |
| 159 | |
| 160 | ~CommandOptions () |
| 161 | { |
| 162 | } |
| 163 | |
| 164 | Error |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 165 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 166 | { |
| 167 | Error error; |
Greg Clayton | 6475c42 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 168 | const int short_option = g_option_table[option_idx].short_option; |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 169 | switch (short_option) |
| 170 | { |
| 171 | case 'l': |
| 172 | start_line = Args::StringToUInt32 (option_arg, 0); |
| 173 | if (start_line == 0) |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 174 | error.SetErrorStringWithFormat("invalid line number: '%s'", option_arg); |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 175 | break; |
| 176 | |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 177 | case 'c': |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 178 | num_lines = Args::StringToUInt32 (option_arg, 0); |
| 179 | if (num_lines == 0) |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 180 | error.SetErrorStringWithFormat("invalid line count: '%s'", option_arg); |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 181 | break; |
| 182 | |
Greg Clayton | 52c8b6e | 2011-04-19 04:19:37 +0000 | [diff] [blame] | 183 | case 'f': |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 184 | file_name = option_arg; |
| 185 | break; |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 186 | |
| 187 | case 'n': |
| 188 | symbol_name = option_arg; |
| 189 | break; |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 190 | |
Greg Clayton | 7812411 | 2012-12-07 00:19:47 +0000 | [diff] [blame] | 191 | case 'a': |
| 192 | { |
| 193 | ExecutionContext exe_ctx (m_interpreter.GetExecutionContext()); |
| 194 | address = Args::StringToAddress(&exe_ctx, option_arg, LLDB_INVALID_ADDRESS, &error); |
| 195 | } |
| 196 | break; |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 197 | case 's': |
Greg Clayton | 52c8b6e | 2011-04-19 04:19:37 +0000 | [diff] [blame] | 198 | modules.push_back (std::string (option_arg)); |
| 199 | break; |
| 200 | |
| 201 | case 'b': |
| 202 | show_bp_locs = true; |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 203 | break; |
Jim Ingham | 12b5aa0 | 2013-01-09 03:27:33 +0000 | [diff] [blame] | 204 | case 'r': |
| 205 | reverse = true; |
| 206 | break; |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 207 | default: |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 208 | error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option); |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 209 | break; |
| 210 | } |
| 211 | |
| 212 | return error; |
| 213 | } |
| 214 | |
| 215 | void |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 216 | OptionParsingStarting () |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 217 | { |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 218 | file_spec.Clear(); |
| 219 | file_name.clear(); |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 220 | symbol_name.clear(); |
Greg Clayton | 7812411 | 2012-12-07 00:19:47 +0000 | [diff] [blame] | 221 | address = LLDB_INVALID_ADDRESS; |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 222 | start_line = 0; |
Greg Clayton | b1f44b3 | 2013-03-13 18:25:49 +0000 | [diff] [blame] | 223 | num_lines = 0; |
Greg Clayton | 52c8b6e | 2011-04-19 04:19:37 +0000 | [diff] [blame] | 224 | show_bp_locs = false; |
Jim Ingham | 12b5aa0 | 2013-01-09 03:27:33 +0000 | [diff] [blame] | 225 | reverse = false; |
Greg Clayton | 52c8b6e | 2011-04-19 04:19:37 +0000 | [diff] [blame] | 226 | modules.clear(); |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 227 | } |
| 228 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 229 | const OptionDefinition* |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 230 | GetDefinitions () |
| 231 | { |
| 232 | return g_option_table; |
| 233 | } |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 234 | static OptionDefinition g_option_table[]; |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 235 | |
| 236 | // Instance variables to hold the values for command options. |
| 237 | FileSpec file_spec; |
| 238 | std::string file_name; |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 239 | std::string symbol_name; |
Greg Clayton | 7812411 | 2012-12-07 00:19:47 +0000 | [diff] [blame] | 240 | lldb::addr_t address; |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 241 | uint32_t start_line; |
| 242 | uint32_t num_lines; |
Greg Clayton | 52c8b6e | 2011-04-19 04:19:37 +0000 | [diff] [blame] | 243 | STLStringArray modules; |
| 244 | bool show_bp_locs; |
Jim Ingham | 12b5aa0 | 2013-01-09 03:27:33 +0000 | [diff] [blame] | 245 | bool reverse; |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 246 | }; |
| 247 | |
| 248 | public: |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 249 | CommandObjectSourceList(CommandInterpreter &interpreter) : |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 250 | CommandObjectParsed (interpreter, |
| 251 | "source list", |
| 252 | "Display source code (as specified) based on the current executable's debug info.", |
Greg Clayton | ea0bb4d | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 253 | NULL, |
| 254 | eFlagRequiresTarget), |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 255 | m_options (interpreter) |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 256 | { |
| 257 | } |
| 258 | |
| 259 | ~CommandObjectSourceList () |
| 260 | { |
| 261 | } |
| 262 | |
| 263 | |
| 264 | Options * |
| 265 | GetOptions () |
| 266 | { |
| 267 | return &m_options; |
| 268 | } |
| 269 | |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 270 | virtual const char * |
| 271 | GetRepeatCommand (Args ¤t_command_args, uint32_t index) |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 272 | { |
Jim Ingham | 12b5aa0 | 2013-01-09 03:27:33 +0000 | [diff] [blame] | 273 | // This is kind of gross, but the command hasn't been parsed yet so we can't look at the option |
| 274 | // values for this invocation... I have to scan the arguments directly. |
| 275 | size_t num_args = current_command_args.GetArgumentCount(); |
| 276 | bool is_reverse = false; |
| 277 | for (size_t i = 0 ; i < num_args; i++) |
| 278 | { |
| 279 | const char *arg = current_command_args.GetArgumentAtIndex(i); |
| 280 | if (arg && (strcmp(arg, "-r") == 0 || strcmp(arg, "--reverse") == 0)) |
| 281 | { |
| 282 | is_reverse = true; |
| 283 | } |
| 284 | } |
| 285 | if (is_reverse) |
| 286 | { |
| 287 | if (m_reverse_name.empty()) |
| 288 | { |
| 289 | m_reverse_name = m_cmd_name; |
| 290 | m_reverse_name.append (" -r"); |
| 291 | } |
| 292 | return m_reverse_name.c_str(); |
| 293 | } |
| 294 | else |
| 295 | return m_cmd_name.c_str(); |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | protected: |
| 299 | bool |
| 300 | DoExecute (Args& command, CommandReturnObject &result) |
| 301 | { |
Greg Clayton | 36da2aa | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 302 | const size_t argc = command.GetArgumentCount(); |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 303 | |
| 304 | if (argc != 0) |
| 305 | { |
| 306 | result.AppendErrorWithFormat("'%s' takes no arguments, only flags.\n", GetCommandName()); |
| 307 | result.SetStatus (eReturnStatusFailed); |
Jim Ingham | 26e089b | 2011-11-29 21:21:26 +0000 | [diff] [blame] | 308 | return false; |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 309 | } |
| 310 | |
Greg Clayton | ea0bb4d | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 311 | Target *target = m_exe_ctx.GetTargetPtr(); |
Jim Ingham | fdf24ef | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 312 | |
Greg Clayton | 7812411 | 2012-12-07 00:19:47 +0000 | [diff] [blame] | 313 | SymbolContextList sc_list; |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 314 | if (!m_options.symbol_name.empty()) |
| 315 | { |
| 316 | // Displaying the source for a symbol: |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 317 | ConstString name(m_options.symbol_name.c_str()); |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 318 | bool include_symbols = false; |
Sean Callanan | 302d78c | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 319 | bool include_inlines = true; |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 320 | bool append = true; |
| 321 | size_t num_matches = 0; |
| 322 | |
Greg Clayton | b1f44b3 | 2013-03-13 18:25:49 +0000 | [diff] [blame] | 323 | if (m_options.num_lines == 0) |
| 324 | m_options.num_lines = 10; |
| 325 | |
Greg Clayton | 36da2aa | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 326 | const size_t num_modules = m_options.modules.size(); |
| 327 | if (num_modules > 0) |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 328 | { |
| 329 | ModuleList matching_modules; |
Greg Clayton | 36da2aa | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 330 | for (size_t i = 0; i < num_modules; ++i) |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 331 | { |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 332 | FileSpec module_file_spec(m_options.modules[i].c_str(), false); |
| 333 | if (module_file_spec) |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 334 | { |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 335 | ModuleSpec module_spec (module_file_spec); |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 336 | matching_modules.Clear(); |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 337 | target->GetImages().FindModules (module_spec, matching_modules); |
Sean Callanan | 302d78c | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 338 | num_matches += matching_modules.FindFunctions (name, eFunctionNameTypeAuto, include_symbols, include_inlines, append, sc_list); |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | } |
| 342 | else |
| 343 | { |
Sean Callanan | 302d78c | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 344 | num_matches = target->GetImages().FindFunctions (name, eFunctionNameTypeAuto, include_symbols, include_inlines, append, sc_list); |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | SymbolContext sc; |
| 348 | |
| 349 | if (num_matches == 0) |
| 350 | { |
| 351 | result.AppendErrorWithFormat("Could not find function named: \"%s\".\n", m_options.symbol_name.c_str()); |
| 352 | result.SetStatus (eReturnStatusFailed); |
| 353 | return false; |
| 354 | } |
| 355 | |
| 356 | sc_list.GetContextAtIndex (0, sc); |
| 357 | FileSpec start_file; |
| 358 | uint32_t start_line; |
| 359 | uint32_t end_line; |
| 360 | FileSpec end_file; |
| 361 | if (sc.function != NULL) |
| 362 | { |
| 363 | sc.function->GetStartLineSourceInfo (start_file, start_line); |
| 364 | if (start_line == 0) |
| 365 | { |
| 366 | result.AppendErrorWithFormat("Could not find line information for start of function: \"%s\".\n", m_options.symbol_name.c_str()); |
| 367 | result.SetStatus (eReturnStatusFailed); |
| 368 | return false; |
| 369 | } |
| 370 | sc.function->GetEndLineSourceInfo (end_file, end_line); |
| 371 | } |
| 372 | else |
| 373 | { |
| 374 | result.AppendErrorWithFormat("Could not find function info for: \"%s\".\n", m_options.symbol_name.c_str()); |
| 375 | result.SetStatus (eReturnStatusFailed); |
| 376 | return false; |
| 377 | } |
| 378 | |
| 379 | if (num_matches > 1) |
| 380 | { |
| 381 | // This could either be because there are multiple functions of this name, in which case |
| 382 | // we'll have to specify this further... Or it could be because there are multiple inlined instances |
| 383 | // of one function. So run through the matches and if they all have the same file & line then we can just |
| 384 | // list one. |
| 385 | |
| 386 | bool found_multiple = false; |
| 387 | |
| 388 | for (size_t i = 1; i < num_matches; i++) |
| 389 | { |
| 390 | SymbolContext scratch_sc; |
| 391 | sc_list.GetContextAtIndex (i, scratch_sc); |
| 392 | if (scratch_sc.function != NULL) |
| 393 | { |
| 394 | FileSpec scratch_file; |
| 395 | uint32_t scratch_line; |
| 396 | scratch_sc.function->GetStartLineSourceInfo (scratch_file, scratch_line); |
| 397 | if (scratch_file != start_file |
| 398 | || scratch_line != start_line) |
| 399 | { |
| 400 | found_multiple = true; |
| 401 | break; |
| 402 | } |
| 403 | } |
| 404 | } |
| 405 | if (found_multiple) |
| 406 | { |
| 407 | StreamString s; |
| 408 | for (size_t i = 0; i < num_matches; i++) |
| 409 | { |
| 410 | SymbolContext scratch_sc; |
| 411 | sc_list.GetContextAtIndex (i, scratch_sc); |
| 412 | if (scratch_sc.function != NULL) |
| 413 | { |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 414 | s.Printf("\n%lu: ", i); |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 415 | scratch_sc.function->Dump (&s, true); |
| 416 | } |
| 417 | } |
| 418 | result.AppendErrorWithFormat("Multiple functions found matching: %s: \n%s\n", |
| 419 | m_options.symbol_name.c_str(), |
| 420 | s.GetData()); |
| 421 | result.SetStatus (eReturnStatusFailed); |
| 422 | return false; |
| 423 | } |
| 424 | } |
| 425 | |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 426 | // This is a little hacky, but the first line table entry for a function points to the "{" that |
| 427 | // starts the function block. It would be nice to actually get the function |
| 428 | // declaration in there too. So back up a bit, but not further than what you're going to display. |
Greg Clayton | b1f44b3 | 2013-03-13 18:25:49 +0000 | [diff] [blame] | 429 | uint32_t extra_lines; |
| 430 | if (m_options.num_lines >= 10) |
| 431 | extra_lines = 5; |
| 432 | else |
| 433 | extra_lines = m_options.num_lines/2; |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 434 | uint32_t line_no; |
Greg Clayton | b1f44b3 | 2013-03-13 18:25:49 +0000 | [diff] [blame] | 435 | if (start_line <= extra_lines) |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 436 | line_no = 1; |
| 437 | else |
Greg Clayton | b1f44b3 | 2013-03-13 18:25:49 +0000 | [diff] [blame] | 438 | line_no = start_line - extra_lines; |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 439 | |
| 440 | // For fun, if the function is shorter than the number of lines we're supposed to display, |
| 441 | // only display the function... |
| 442 | if (end_line != 0) |
| 443 | { |
| 444 | if (m_options.num_lines > end_line - line_no) |
Greg Clayton | b1f44b3 | 2013-03-13 18:25:49 +0000 | [diff] [blame] | 445 | m_options.num_lines = end_line - line_no + extra_lines; |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 446 | } |
| 447 | |
Greg Clayton | 52c8b6e | 2011-04-19 04:19:37 +0000 | [diff] [blame] | 448 | char path_buf[PATH_MAX]; |
| 449 | start_file.GetPath(path_buf, sizeof(path_buf)); |
Greg Clayton | 1cee1e6 | 2011-04-20 18:52:45 +0000 | [diff] [blame] | 450 | |
Jim Ingham | fdf24ef | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 451 | if (m_options.show_bp_locs) |
Greg Clayton | 1cee1e6 | 2011-04-20 18:52:45 +0000 | [diff] [blame] | 452 | { |
| 453 | const bool show_inlines = true; |
| 454 | m_breakpoint_locations.Reset (start_file, 0, show_inlines); |
Greg Clayton | ea0bb4d | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 455 | SearchFilter target_search_filter (m_exe_ctx.GetTargetSP()); |
Greg Clayton | 1cee1e6 | 2011-04-20 18:52:45 +0000 | [diff] [blame] | 456 | target_search_filter.Search (m_breakpoint_locations); |
| 457 | } |
| 458 | else |
| 459 | m_breakpoint_locations.Clear(); |
| 460 | |
Greg Clayton | b1f44b3 | 2013-03-13 18:25:49 +0000 | [diff] [blame] | 461 | result.AppendMessageWithFormat("File: %s\n", path_buf); |
Jim Ingham | fdf24ef | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 462 | target->GetSourceManager().DisplaySourceLinesWithLineNumbers (start_file, |
| 463 | line_no, |
| 464 | 0, |
| 465 | m_options.num_lines, |
| 466 | "", |
| 467 | &result.GetOutputStream(), |
| 468 | GetBreakpointLocations ()); |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 469 | |
| 470 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 471 | return true; |
| 472 | |
| 473 | } |
Greg Clayton | 7812411 | 2012-12-07 00:19:47 +0000 | [diff] [blame] | 474 | else if (m_options.address != LLDB_INVALID_ADDRESS) |
| 475 | { |
| 476 | SymbolContext sc; |
| 477 | Address so_addr; |
| 478 | StreamString error_strm; |
| 479 | |
| 480 | if (target->GetSectionLoadList().IsEmpty()) |
| 481 | { |
| 482 | // The target isn't loaded yet, we need to lookup the file address |
| 483 | // in all modules |
| 484 | const ModuleList &module_list = target->GetImages(); |
Greg Clayton | 36da2aa | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 485 | const size_t num_modules = module_list.GetSize(); |
| 486 | for (size_t i=0; i<num_modules; ++i) |
Greg Clayton | 7812411 | 2012-12-07 00:19:47 +0000 | [diff] [blame] | 487 | { |
| 488 | ModuleSP module_sp (module_list.GetModuleAtIndex(i)); |
| 489 | if (module_sp && module_sp->ResolveFileAddress(m_options.address, so_addr)) |
| 490 | { |
Greg Clayton | a7e864c | 2013-02-23 04:12:47 +0000 | [diff] [blame] | 491 | sc.Clear(true); |
Greg Clayton | 7812411 | 2012-12-07 00:19:47 +0000 | [diff] [blame] | 492 | if (module_sp->ResolveSymbolContextForAddress (so_addr, eSymbolContextEverything, sc) & eSymbolContextLineEntry) |
| 493 | sc_list.Append(sc); |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | if (sc_list.GetSize() == 0) |
| 498 | { |
| 499 | result.AppendErrorWithFormat("no modules have source information for file address 0x%" PRIx64 ".\n", |
| 500 | m_options.address); |
| 501 | result.SetStatus (eReturnStatusFailed); |
| 502 | return false; |
| 503 | } |
| 504 | } |
| 505 | else |
| 506 | { |
| 507 | // The target has some things loaded, resolve this address to a |
| 508 | // compile unit + file + line and display |
| 509 | if (target->GetSectionLoadList().ResolveLoadAddress (m_options.address, so_addr)) |
| 510 | { |
| 511 | ModuleSP module_sp (so_addr.GetModule()); |
| 512 | if (module_sp) |
| 513 | { |
Greg Clayton | a7e864c | 2013-02-23 04:12:47 +0000 | [diff] [blame] | 514 | sc.Clear(true); |
Greg Clayton | 7812411 | 2012-12-07 00:19:47 +0000 | [diff] [blame] | 515 | if (module_sp->ResolveSymbolContextForAddress (so_addr, eSymbolContextEverything, sc) & eSymbolContextLineEntry) |
| 516 | { |
| 517 | sc_list.Append(sc); |
| 518 | } |
| 519 | else |
| 520 | { |
| 521 | so_addr.Dump(&error_strm, NULL, Address::DumpStyleModuleWithFileAddress); |
| 522 | result.AppendErrorWithFormat("address resolves to %s, but there is no line table information available for this address.\n", |
| 523 | error_strm.GetData()); |
| 524 | result.SetStatus (eReturnStatusFailed); |
| 525 | return false; |
| 526 | } |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | if (sc_list.GetSize() == 0) |
| 531 | { |
| 532 | result.AppendErrorWithFormat("no modules contain load address 0x%" PRIx64 ".\n", m_options.address); |
| 533 | result.SetStatus (eReturnStatusFailed); |
| 534 | return false; |
| 535 | } |
| 536 | } |
| 537 | uint32_t num_matches = sc_list.GetSize(); |
| 538 | for (uint32_t i=0; i<num_matches; ++i) |
| 539 | { |
| 540 | sc_list.GetContextAtIndex(i, sc); |
| 541 | if (sc.comp_unit) |
| 542 | { |
| 543 | if (m_options.show_bp_locs) |
| 544 | { |
| 545 | m_breakpoint_locations.Clear(); |
| 546 | const bool show_inlines = true; |
| 547 | m_breakpoint_locations.Reset (*sc.comp_unit, 0, show_inlines); |
| 548 | SearchFilter target_search_filter (target->shared_from_this()); |
| 549 | target_search_filter.Search (m_breakpoint_locations); |
| 550 | } |
| 551 | |
| 552 | bool show_fullpaths = true; |
| 553 | bool show_module = true; |
| 554 | bool show_inlined_frames = true; |
| 555 | sc.DumpStopContext(&result.GetOutputStream(), |
Greg Clayton | ea0bb4d | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 556 | m_exe_ctx.GetBestExecutionContextScope(), |
Greg Clayton | 7812411 | 2012-12-07 00:19:47 +0000 | [diff] [blame] | 557 | sc.line_entry.range.GetBaseAddress(), |
| 558 | show_fullpaths, |
| 559 | show_module, |
| 560 | show_inlined_frames); |
| 561 | result.GetOutputStream().EOL(); |
Greg Clayton | b1f44b3 | 2013-03-13 18:25:49 +0000 | [diff] [blame] | 562 | |
| 563 | if (m_options.num_lines == 0) |
| 564 | m_options.num_lines = 10; |
Greg Clayton | 7812411 | 2012-12-07 00:19:47 +0000 | [diff] [blame] | 565 | |
| 566 | size_t lines_to_back_up = m_options.num_lines >= 10 ? 5 : m_options.num_lines/2; |
| 567 | |
| 568 | target->GetSourceManager().DisplaySourceLinesWithLineNumbers (sc.comp_unit, |
| 569 | sc.line_entry.line, |
| 570 | lines_to_back_up, |
| 571 | m_options.num_lines - lines_to_back_up, |
| 572 | "->", |
| 573 | &result.GetOutputStream(), |
| 574 | GetBreakpointLocations ()); |
| 575 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 576 | } |
| 577 | } |
| 578 | } |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 579 | else if (m_options.file_name.empty()) |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 580 | { |
| 581 | // Last valid source manager context, or the current frame if no |
| 582 | // valid last context in source manager. |
| 583 | // One little trick here, if you type the exact same list command twice in a row, it is |
| 584 | // more likely because you typed it once, then typed it again |
| 585 | if (m_options.start_line == 0) |
| 586 | { |
Jim Ingham | c7f18c8 | 2011-09-29 20:22:33 +0000 | [diff] [blame] | 587 | if (target->GetSourceManager().DisplayMoreWithLineNumbers (&result.GetOutputStream(), |
Greg Clayton | b1f44b3 | 2013-03-13 18:25:49 +0000 | [diff] [blame] | 588 | m_options.num_lines, |
| 589 | m_options.reverse, |
| 590 | GetBreakpointLocations ())) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 591 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 592 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 593 | } |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 594 | } |
| 595 | else |
| 596 | { |
Greg Clayton | b1f44b3 | 2013-03-13 18:25:49 +0000 | [diff] [blame] | 597 | if (m_options.num_lines == 0) |
| 598 | m_options.num_lines = 10; |
| 599 | |
Jim Ingham | fdf24ef | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 600 | if (m_options.show_bp_locs) |
Greg Clayton | 1cee1e6 | 2011-04-20 18:52:45 +0000 | [diff] [blame] | 601 | { |
Jim Ingham | fdf24ef | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 602 | SourceManager::FileSP last_file_sp (target->GetSourceManager().GetLastFile ()); |
Greg Clayton | 1cee1e6 | 2011-04-20 18:52:45 +0000 | [diff] [blame] | 603 | if (last_file_sp) |
| 604 | { |
| 605 | const bool show_inlines = true; |
| 606 | m_breakpoint_locations.Reset (last_file_sp->GetFileSpec(), 0, show_inlines); |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 607 | SearchFilter target_search_filter (target->shared_from_this()); |
Greg Clayton | 1cee1e6 | 2011-04-20 18:52:45 +0000 | [diff] [blame] | 608 | target_search_filter.Search (m_breakpoint_locations); |
| 609 | } |
| 610 | } |
| 611 | else |
| 612 | m_breakpoint_locations.Clear(); |
| 613 | |
Jim Ingham | fdf24ef | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 614 | if (target->GetSourceManager().DisplaySourceLinesWithLineNumbersUsingLastFile( |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 615 | m_options.start_line, // Line to display |
Greg Clayton | b1f44b3 | 2013-03-13 18:25:49 +0000 | [diff] [blame] | 616 | m_options.num_lines, // Lines after line to |
| 617 | UINT32_MAX, // Don't mark "line" |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 618 | "", // Don't mark "line" |
Greg Clayton | 52c8b6e | 2011-04-19 04:19:37 +0000 | [diff] [blame] | 619 | &result.GetOutputStream(), |
| 620 | GetBreakpointLocations ())) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 621 | { |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 622 | result.SetStatus (eReturnStatusSuccessFinishResult); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 623 | } |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 624 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 625 | } |
| 626 | } |
| 627 | else |
| 628 | { |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 629 | const char *filename = m_options.file_name.c_str(); |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 630 | |
| 631 | bool check_inlines = false; |
| 632 | SymbolContextList sc_list; |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 633 | size_t num_matches = 0; |
| 634 | |
Greg Clayton | 52c8b6e | 2011-04-19 04:19:37 +0000 | [diff] [blame] | 635 | if (m_options.modules.size() > 0) |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 636 | { |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 637 | ModuleList matching_modules; |
Greg Clayton | 36da2aa | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 638 | for (size_t i = 0, e = m_options.modules.size(); i < e; ++i) |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 639 | { |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 640 | FileSpec module_file_spec(m_options.modules[i].c_str(), false); |
| 641 | if (module_file_spec) |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 642 | { |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 643 | ModuleSpec module_spec (module_file_spec); |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 644 | matching_modules.Clear(); |
Greg Clayton | 444fe99 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 645 | target->GetImages().FindModules (module_spec, matching_modules); |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 646 | num_matches += matching_modules.ResolveSymbolContextForFilePath (filename, |
Greg Clayton | 52c8b6e | 2011-04-19 04:19:37 +0000 | [diff] [blame] | 647 | 0, |
| 648 | check_inlines, |
| 649 | eSymbolContextModule | eSymbolContextCompUnit, |
| 650 | sc_list); |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 651 | } |
| 652 | } |
| 653 | } |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 654 | else |
| 655 | { |
| 656 | num_matches = target->GetImages().ResolveSymbolContextForFilePath (filename, |
| 657 | 0, |
| 658 | check_inlines, |
| 659 | eSymbolContextModule | eSymbolContextCompUnit, |
| 660 | sc_list); |
| 661 | } |
| 662 | |
| 663 | if (num_matches == 0) |
| 664 | { |
| 665 | result.AppendErrorWithFormat("Could not find source file \"%s\".\n", |
| 666 | m_options.file_name.c_str()); |
| 667 | result.SetStatus (eReturnStatusFailed); |
| 668 | return false; |
| 669 | } |
| 670 | |
| 671 | if (num_matches > 1) |
| 672 | { |
| 673 | SymbolContext sc; |
| 674 | bool got_multiple = false; |
| 675 | FileSpec *test_cu_spec = NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 676 | |
Chris Lattner | 0f6fa73 | 2010-09-08 22:55:31 +0000 | [diff] [blame] | 677 | for (unsigned i = 0; i < num_matches; i++) |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 678 | { |
| 679 | sc_list.GetContextAtIndex(i, sc); |
| 680 | if (sc.comp_unit) |
| 681 | { |
| 682 | if (test_cu_spec) |
| 683 | { |
| 684 | if (test_cu_spec != static_cast<FileSpec *> (sc.comp_unit)) |
| 685 | got_multiple = true; |
| 686 | break; |
| 687 | } |
| 688 | else |
| 689 | test_cu_spec = sc.comp_unit; |
| 690 | } |
| 691 | } |
| 692 | if (got_multiple) |
| 693 | { |
| 694 | result.AppendErrorWithFormat("Multiple source files found matching: \"%s.\"\n", |
| 695 | m_options.file_name.c_str()); |
| 696 | result.SetStatus (eReturnStatusFailed); |
| 697 | return false; |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | SymbolContext sc; |
| 702 | if (sc_list.GetContextAtIndex(0, sc)) |
| 703 | { |
| 704 | if (sc.comp_unit) |
| 705 | { |
Jim Ingham | fdf24ef | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 706 | if (m_options.show_bp_locs) |
Greg Clayton | 52c8b6e | 2011-04-19 04:19:37 +0000 | [diff] [blame] | 707 | { |
| 708 | const bool show_inlines = true; |
| 709 | m_breakpoint_locations.Reset (*sc.comp_unit, 0, show_inlines); |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 710 | SearchFilter target_search_filter (target->shared_from_this()); |
Greg Clayton | 52c8b6e | 2011-04-19 04:19:37 +0000 | [diff] [blame] | 711 | target_search_filter.Search (m_breakpoint_locations); |
| 712 | } |
| 713 | else |
| 714 | m_breakpoint_locations.Clear(); |
| 715 | |
Greg Clayton | b1f44b3 | 2013-03-13 18:25:49 +0000 | [diff] [blame] | 716 | if (m_options.num_lines == 0) |
| 717 | m_options.num_lines = 10; |
| 718 | |
Jim Ingham | fdf24ef | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 719 | target->GetSourceManager().DisplaySourceLinesWithLineNumbers (sc.comp_unit, |
| 720 | m_options.start_line, |
| 721 | 0, |
| 722 | m_options.num_lines, |
| 723 | "", |
| 724 | &result.GetOutputStream(), |
| 725 | GetBreakpointLocations ()); |
Greg Clayton | 52c8b6e | 2011-04-19 04:19:37 +0000 | [diff] [blame] | 726 | |
Jim Ingham | 338f753 | 2010-08-20 01:17:07 +0000 | [diff] [blame] | 727 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 728 | } |
| 729 | else |
| 730 | { |
| 731 | result.AppendErrorWithFormat("No comp unit found for: \"%s.\"\n", |
| 732 | m_options.file_name.c_str()); |
| 733 | result.SetStatus (eReturnStatusFailed); |
| 734 | return false; |
| 735 | } |
| 736 | } |
| 737 | } |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 738 | return result.Succeeded(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 739 | } |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 740 | |
Greg Clayton | 52c8b6e | 2011-04-19 04:19:37 +0000 | [diff] [blame] | 741 | const SymbolContextList * |
| 742 | GetBreakpointLocations () |
| 743 | { |
| 744 | if (m_breakpoint_locations.GetFileLineMatches().GetSize() > 0) |
| 745 | return &m_breakpoint_locations.GetFileLineMatches(); |
| 746 | return NULL; |
| 747 | } |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 748 | CommandOptions m_options; |
Greg Clayton | 52c8b6e | 2011-04-19 04:19:37 +0000 | [diff] [blame] | 749 | FileLineResolver m_breakpoint_locations; |
Jim Ingham | 12b5aa0 | 2013-01-09 03:27:33 +0000 | [diff] [blame] | 750 | std::string m_reverse_name; |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 751 | |
| 752 | }; |
| 753 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 754 | OptionDefinition |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 755 | CommandObjectSourceList::CommandOptions::g_option_table[] = |
| 756 | { |
Greg Clayton | 7812411 | 2012-12-07 00:19:47 +0000 | [diff] [blame] | 757 | { LLDB_OPT_SET_ALL, false, "count", 'c', required_argument, NULL, 0, eArgTypeCount, "The number of source lines to display."}, |
| 758 | { LLDB_OPT_SET_1 | |
| 759 | LLDB_OPT_SET_2 , false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName, "Look up the source file in the given shared library."}, |
Greg Clayton | 52c8b6e | 2011-04-19 04:19:37 +0000 | [diff] [blame] | 760 | { LLDB_OPT_SET_ALL, false, "show-breakpoints", 'b', no_argument, NULL, 0, eArgTypeNone, "Show the line table locations from the debug information that indicate valid places to set source level breakpoints."}, |
Greg Clayton | 7812411 | 2012-12-07 00:19:47 +0000 | [diff] [blame] | 761 | { LLDB_OPT_SET_1 , false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, "The file from which to display source."}, |
| 762 | { LLDB_OPT_SET_1 , false, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum, "The line number at which to start the display source."}, |
| 763 | { LLDB_OPT_SET_2 , false, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeSymbol, "The name of a function whose source to display."}, |
Enrico Granata | 4968ad8 | 2013-01-29 01:48:30 +0000 | [diff] [blame] | 764 | { LLDB_OPT_SET_3 , false, "address",'a', required_argument, NULL, 0, eArgTypeAddressOrExpression, "Lookup the address and display the source information for the corresponding file and line."}, |
Jim Ingham | 12b5aa0 | 2013-01-09 03:27:33 +0000 | [diff] [blame] | 765 | { LLDB_OPT_SET_4, false, "reverse", 'r', no_argument, NULL, 0, eArgTypeNone, "Reverse the listing to look backwards from the last displayed block of source."}, |
Caroline Tice | 4d6675c | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 766 | { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 767 | }; |
| 768 | |
| 769 | #pragma mark CommandObjectMultiwordSource |
| 770 | |
| 771 | //------------------------------------------------------------------------- |
| 772 | // CommandObjectMultiwordSource |
| 773 | //------------------------------------------------------------------------- |
| 774 | |
| 775 | CommandObjectMultiwordSource::CommandObjectMultiwordSource (CommandInterpreter &interpreter) : |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 776 | CommandObjectMultiword (interpreter, |
| 777 | "source", |
Caroline Tice | c1ad82e | 2010-09-07 22:38:08 +0000 | [diff] [blame] | 778 | "A set of commands for accessing source file information", |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 779 | "source <subcommand> [<subcommand-options>]") |
| 780 | { |
Greg Clayton | d8b8215 | 2013-04-18 19:58:52 +0000 | [diff] [blame^] | 781 | // "source info" isn't implemented yet... |
| 782 | //LoadSubCommand ("info", CommandObjectSP (new CommandObjectSourceInfo (interpreter))); |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 783 | LoadSubCommand ("list", CommandObjectSP (new CommandObjectSourceList (interpreter))); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 784 | } |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 785 | |
| 786 | CommandObjectMultiwordSource::~CommandObjectMultiwordSource () |
| 787 | { |
| 788 | } |
| 789 | |