LLDB mainline
CommandObjectSource.cpp
Go to the documentation of this file.
1//===-- CommandObjectSource.cpp -------------------------------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
10
11#include "lldb/Core/Debugger.h"
13#include "lldb/Core/Module.h"
24#include "lldb/Symbol/Symbol.h"
25#include "lldb/Target/Process.h"
29#include <optional>
30
31using namespace lldb;
32using namespace lldb_private;
33
34#pragma mark CommandObjectSourceInfo
35// CommandObjectSourceInfo - debug line entries dumping command
36#define LLDB_OPTIONS_source_info
37#include "CommandOptions.inc"
38
40 class CommandOptions : public Options {
41 public:
42 CommandOptions() = default;
43
44 ~CommandOptions() override = default;
45
46 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
47 ExecutionContext *execution_context) override {
49 const int short_option = GetDefinitions()[option_idx].short_option;
50 switch (short_option) {
51 case 'l':
52 if (option_arg.getAsInteger(0, start_line))
53 error = Status::FromErrorStringWithFormat("invalid line number: '%s'",
54 option_arg.str().c_str());
55 break;
56
57 case 'e':
58 if (option_arg.getAsInteger(0, end_line))
59 error = Status::FromErrorStringWithFormat("invalid line number: '%s'",
60 option_arg.str().c_str());
61 break;
62
63 case 'c':
64 if (option_arg.getAsInteger(0, num_lines))
65 error = Status::FromErrorStringWithFormat("invalid line count: '%s'",
66 option_arg.str().c_str());
67 break;
68
69 case 'f':
70 file_name = std::string(option_arg);
71 break;
72
73 case 'n':
74 symbol_name = std::string(option_arg);
75 break;
76
77 case 'a': {
78 address = OptionArgParser::ToAddress(execution_context, option_arg,
80 } break;
81 case 's':
82 modules.push_back(std::string(option_arg));
83 break;
84 default:
85 llvm_unreachable("Unimplemented option");
86 }
87
88 return error;
89 }
90
91 void OptionParsingStarting(ExecutionContext *execution_context) override {
92 file_spec.Clear();
93 file_name.clear();
94 symbol_name.clear();
96 start_line = 0;
97 end_line = 0;
98 num_lines = 0;
99 modules.clear();
100 }
101
102 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
103 return llvm::ArrayRef(g_source_info_options);
104 }
105
106 // Instance variables to hold the values for command options.
108 std::string file_name;
109 std::string symbol_name;
111 uint32_t start_line;
112 uint32_t end_line;
113 uint32_t num_lines;
114 std::vector<std::string> modules;
115 };
116
117public:
120 interpreter, "source info",
121 "Display source line information for the current target "
122 "process. Defaults to instruction pointer in current stack "
123 "frame.",
124 nullptr, eCommandRequiresTarget) {}
125
126 ~CommandObjectSourceInfo() override = default;
127
128 Options *GetOptions() override { return &m_options; }
129
130protected:
131 // Dump the line entries in each symbol context. Return the number of entries
132 // found. If module_list is set, only dump lines contained in one of the
133 // modules. If file_spec is set, only dump lines in the file. If the
134 // start_line option was specified, don't print lines less than start_line.
135 // If the end_line option was specified, don't print lines greater than
136 // end_line. If the num_lines option was specified, dont print more than
137 // num_lines entries.
139 const SymbolContextList &sc_list,
140 const ModuleList &module_list,
141 const FileSpec &file_spec) {
142 uint32_t start_line = m_options.start_line;
143 uint32_t end_line = m_options.end_line;
144 uint32_t num_lines = m_options.num_lines;
145 Target &target = GetTarget();
146
147 uint32_t num_matches = 0;
148 // Dump all the line entries for the file in the list.
149 ConstString last_module_file_name;
150 for (const SymbolContext &sc : sc_list) {
151 if (sc.comp_unit) {
152 Module *module = sc.module_sp.get();
153 CompileUnit *cu = sc.comp_unit;
154 const LineEntry &line_entry = sc.line_entry;
155 assert(module && cu);
156
157 // Are we looking for specific modules, files or lines?
158 if (module_list.GetSize() &&
159 module_list.GetIndexForModule(module) == LLDB_INVALID_INDEX32)
160 continue;
161 if (!FileSpec::Match(file_spec, line_entry.GetFile()))
162 continue;
163 if (start_line > 0 && line_entry.line < start_line)
164 continue;
165 if (end_line > 0 && line_entry.line > end_line)
166 continue;
167 if (num_lines > 0 && num_matches > num_lines)
168 continue;
169
170 // Print a new header if the module changed.
171 ConstString module_file_name = module->GetFileSpec().GetFilename();
172 assert(module_file_name);
173 if (module_file_name != last_module_file_name) {
174 if (num_matches > 0)
175 strm << "\n\n";
176 strm << "Lines found in module `" << module_file_name << "\n";
177 }
178 // Dump the line entry.
179 line_entry.GetDescription(&strm, lldb::eDescriptionLevelBrief, cu,
180 &target, /*show_address_only=*/false);
181 strm << "\n";
182 last_module_file_name = module_file_name;
183 num_matches++;
184 }
185 }
186 return num_matches;
187 }
188
189 // Dump the requested line entries for the file in the compilation unit.
190 // Return the number of entries found. If module_list is set, only dump lines
191 // contained in one of the modules. If the start_line option was specified,
192 // don't print lines less than start_line. If the end_line option was
193 // specified, don't print lines greater than end_line. If the num_lines
194 // option was specified, dont print more than num_lines entries.
195 uint32_t DumpFileLinesInCompUnit(Stream &strm, Module *module,
196 CompileUnit *cu, const FileSpec &file_spec) {
197 uint32_t start_line = m_options.start_line;
198 uint32_t end_line = m_options.end_line;
199 uint32_t num_lines = m_options.num_lines;
200 Target &target = GetTarget();
201
202 uint32_t num_matches = 0;
203 assert(module);
204 if (cu) {
205 assert(file_spec.GetFilename().AsCString(nullptr));
206 bool has_path = (file_spec.GetDirectory().AsCString(nullptr) != nullptr);
207 const SupportFileList &cu_file_list = cu->GetSupportFiles();
208 size_t file_idx = cu_file_list.FindFileIndex(0, file_spec, has_path);
209 if (file_idx != UINT32_MAX) {
210 // Update the file to how it appears in the CU.
211 const FileSpec &cu_file_spec =
212 cu_file_list.GetFileSpecAtIndex(file_idx);
213
214 // Dump all matching lines at or above start_line for the file in the
215 // CU.
216 ConstString file_spec_name = file_spec.GetFilename();
217 ConstString module_file_name = module->GetFileSpec().GetFilename();
218 bool cu_header_printed = false;
219 uint32_t line = start_line;
220 while (true) {
221 LineEntry line_entry;
222
223 // Find the lowest index of a line entry with a line equal to or
224 // higher than 'line'.
225 uint32_t start_idx = 0;
226 start_idx = cu->FindLineEntry(start_idx, line, &cu_file_spec,
227 /*exact=*/false, &line_entry);
228 if (start_idx == UINT32_MAX)
229 // No more line entries for our file in this CU.
230 break;
231
232 if (end_line > 0 && line_entry.line > end_line)
233 break;
234
235 // Loop through to find any other entries for this line, dumping
236 // each.
237 line = line_entry.line;
238 do {
239 num_matches++;
240 if (num_lines > 0 && num_matches > num_lines)
241 break;
242 assert(cu_file_spec == line_entry.GetFile());
243 if (!cu_header_printed) {
244 if (num_matches > 0)
245 strm << "\n\n";
246 strm << "Lines found for file " << file_spec_name
247 << " in compilation unit "
248 << cu->GetPrimaryFile().GetFilename() << " in `"
249 << module_file_name << "\n";
250 cu_header_printed = true;
251 }
252 line_entry.GetDescription(&strm, lldb::eDescriptionLevelBrief, cu,
253 &target, /*show_address_only=*/false);
254 strm << "\n";
255
256 // Anymore after this one?
257 start_idx++;
258 start_idx = cu->FindLineEntry(start_idx, line, &cu_file_spec,
259 /*exact=*/true, &line_entry);
260 } while (start_idx != UINT32_MAX);
261
262 // Try the next higher line, starting over at start_idx 0.
263 line++;
264 }
265 }
266 }
267 return num_matches;
268 }
269
270 // Dump the requested line entries for the file in the module. Return the
271 // number of entries found. If module_list is set, only dump lines contained
272 // in one of the modules. If the start_line option was specified, don't print
273 // lines less than start_line. If the end_line option was specified, don't
274 // print lines greater than end_line. If the num_lines option was specified,
275 // dont print more than num_lines entries.
276 uint32_t DumpFileLinesInModule(Stream &strm, Module *module,
277 const FileSpec &file_spec) {
278 uint32_t num_matches = 0;
279 if (module) {
280 // Look through all the compilation units (CUs) in this module for ones
281 // that contain lines of code from this source file.
282 for (size_t i = 0; i < module->GetNumCompileUnits(); i++) {
283 // Look for a matching source file in this CU.
284 CompUnitSP cu_sp(module->GetCompileUnitAtIndex(i));
285 if (cu_sp) {
286 num_matches +=
287 DumpFileLinesInCompUnit(strm, module, cu_sp.get(), file_spec);
288 }
289 }
290 }
291 return num_matches;
292 }
293
294 // Given an address and a list of modules, append the symbol contexts of all
295 // line entries containing the address found in the modules and return the
296 // count of matches. If none is found, return an error in 'error_strm'.
297 size_t GetSymbolContextsForAddress(const ModuleList &module_list,
298 lldb::addr_t addr,
299 SymbolContextList &sc_list,
300 StreamString &error_strm) {
301 Address so_addr;
302 size_t num_matches = 0;
303 assert(module_list.GetSize() > 0);
304 Target &target = GetTarget();
305 if (!target.HasLoadedSections()) {
306 // The target isn't loaded yet, we need to lookup the file address in all
307 // modules. Note: the module list option does not apply to addresses.
308 const size_t num_modules = module_list.GetSize();
309 for (size_t i = 0; i < num_modules; ++i) {
310 ModuleSP module_sp(module_list.GetModuleAtIndex(i));
311 if (!module_sp)
312 continue;
313 if (module_sp->ResolveFileAddress(addr, so_addr)) {
314 SymbolContext sc;
315 sc.Clear(true);
316 if (module_sp->ResolveSymbolContextForAddress(
317 so_addr, eSymbolContextEverything, sc) &
318 eSymbolContextLineEntry) {
319 sc_list.AppendIfUnique(sc, /*merge_symbol_into_function=*/false);
320 ++num_matches;
321 }
322 }
323 }
324 if (num_matches == 0)
325 error_strm.Printf("Source information for file address 0x%" PRIx64
326 " not found in any modules.\n",
327 addr);
328 } else {
329 // The target has some things loaded, resolve this address to a compile
330 // unit + file + line and display
331 if (target.ResolveLoadAddress(addr, so_addr)) {
332 ModuleSP module_sp(so_addr.GetModule());
333 // Check to make sure this module is in our list.
334 if (module_sp && module_list.GetIndexForModule(module_sp.get()) !=
336 SymbolContext sc;
337 sc.Clear(true);
338 if (module_sp->ResolveSymbolContextForAddress(
339 so_addr, eSymbolContextEverything, sc) &
340 eSymbolContextLineEntry) {
341 sc_list.AppendIfUnique(sc, /*merge_symbol_into_function=*/false);
342 ++num_matches;
343 } else {
344 StreamString addr_strm;
345 so_addr.Dump(&addr_strm, nullptr,
347 error_strm.Printf(
348 "Address 0x%" PRIx64 " resolves to %s, but there is"
349 " no source information available for this address.\n",
350 addr, addr_strm.GetData());
351 }
352 } else {
353 StreamString addr_strm;
354 so_addr.Dump(&addr_strm, nullptr,
356 error_strm.Printf("Address 0x%" PRIx64
357 " resolves to %s, but it cannot"
358 " be found in any modules.\n",
359 addr, addr_strm.GetData());
360 }
361 } else
362 error_strm.Printf("Unable to resolve address 0x%" PRIx64 ".\n", addr);
363 }
364 return num_matches;
365 }
366
367 // Dump the line entries found in functions matching the name specified in
368 // the option.
370 SymbolContextList sc_list_funcs;
371 ConstString name(m_options.symbol_name.c_str());
372 SymbolContextList sc_list_lines;
373 Target &target = GetTarget();
374 uint32_t addr_byte_size = target.GetArchitecture().GetAddressByteSize();
375
376 ModuleFunctionSearchOptions function_options;
377 function_options.include_symbols = false;
378 function_options.include_inlines = true;
379
380 // Note: module_list can't be const& because FindFunctionSymbols isn't
381 // const.
382 ModuleList module_list =
383 (m_module_list.GetSize() > 0) ? m_module_list : target.GetImages();
384 module_list.FindFunctions(name, eFunctionNameTypeAuto, function_options,
385 sc_list_funcs);
386 size_t num_matches = sc_list_funcs.GetSize();
387
388 if (!num_matches) {
389 // If we didn't find any functions with that name, try searching for
390 // symbols that line up exactly with function addresses.
391 SymbolContextList sc_list_symbols;
392 module_list.FindFunctionSymbols(name, eFunctionNameTypeAuto,
393 sc_list_symbols);
394 for (const SymbolContext &sc : sc_list_symbols) {
395 if (sc.symbol && sc.symbol->ValueIsAddress()) {
396 const Address &base_address = sc.symbol->GetAddressRef();
397 Function *function = base_address.CalculateSymbolContextFunction();
398 if (function) {
399 sc_list_funcs.Append(SymbolContext(function));
400 num_matches++;
401 }
402 }
403 }
404 }
405 if (num_matches == 0) {
406 result.AppendErrorWithFormat("Could not find function named \'%s\'.\n",
407 m_options.symbol_name.c_str());
408 return false;
409 }
410 for (const SymbolContext &sc : sc_list_funcs) {
411 bool context_found_for_symbol = false;
412 // Loop through all the ranges in the function.
413 AddressRange range;
414 for (uint32_t r = 0;
415 sc.GetAddressRange(eSymbolContextEverything, r,
416 /*use_inline_block_range=*/true, range);
417 ++r) {
418 // Append the symbol contexts for each address in the range to
419 // sc_list_lines.
420 const Address &base_address = range.GetBaseAddress();
421 const addr_t size = range.GetByteSize();
422 lldb::addr_t start_addr = base_address.GetLoadAddress(&target);
423 if (start_addr == LLDB_INVALID_ADDRESS)
424 start_addr = base_address.GetFileAddress();
425 lldb::addr_t end_addr = start_addr + size;
426 for (lldb::addr_t addr = start_addr; addr < end_addr;
427 addr += addr_byte_size) {
428 StreamString error_strm;
429 if (!GetSymbolContextsForAddress(module_list, addr, sc_list_lines,
430 error_strm))
431 result.AppendWarningWithFormatv("in symbol '{0}': {1}",
432 sc.GetFunctionName(),
433 error_strm.GetData());
434 else
435 context_found_for_symbol = true;
436 }
437 }
438 if (!context_found_for_symbol)
439 result.AppendWarningWithFormatv("unable to find line information"
440 " for matching symbol '{0}'\n",
441 sc.GetFunctionName());
442 }
443 if (sc_list_lines.GetSize() == 0) {
444 result.AppendErrorWithFormatv("No line information could be found"
445 " for any symbols matching '{0}'.\n",
446 name);
447 return false;
448 }
449 FileSpec file_spec;
450 if (!DumpLinesInSymbolContexts(result.GetOutputStream(), sc_list_lines,
451 module_list, file_spec)) {
453 "Unable to dump line information for symbol '{0}'.\n", name);
454 return false;
455 }
456 return true;
457 }
458
459 // Dump the line entries found for the address specified in the option.
461 Target &target = GetTarget();
462 SymbolContextList sc_list;
463
464 StreamString error_strm;
465 if (!GetSymbolContextsForAddress(target.GetImages(), m_options.address,
466 sc_list, error_strm)) {
467 result.AppendErrorWithFormat("%s.\n", error_strm.GetData());
468 return false;
469 }
470 ModuleList module_list;
471 FileSpec file_spec;
472 if (!DumpLinesInSymbolContexts(result.GetOutputStream(), sc_list,
473 module_list, file_spec)) {
474 result.AppendErrorWithFormat("No modules contain load address 0x%" PRIx64
475 ".\n",
476 m_options.address);
477 return false;
478 }
479 return true;
480 }
481
482 // Dump the line entries found in the file specified in the option.
484 FileSpec file_spec(m_options.file_name);
485 const char *filename = m_options.file_name.c_str();
486 Target &target = GetTarget();
487 const ModuleList &module_list =
488 (m_module_list.GetSize() > 0) ? m_module_list : target.GetImages();
489
490 bool displayed_something = false;
491 const size_t num_modules = module_list.GetSize();
492 for (uint32_t i = 0; i < num_modules; ++i) {
493 // Dump lines for this module.
494 Module *module = module_list.GetModulePointerAtIndex(i);
495 assert(module);
496 if (DumpFileLinesInModule(result.GetOutputStream(), module, file_spec))
497 displayed_something = true;
498 }
499 if (!displayed_something) {
500 result.AppendErrorWithFormat("no source filenames matched '%s'",
501 filename);
502 return false;
503 }
504 return true;
505 }
506
507 // Dump the line entries for the current frame.
509 StackFrame *cur_frame = m_exe_ctx.GetFramePtr();
510 if (cur_frame == nullptr) {
511 result.AppendError(
512 "No selected frame to use to find the default source.");
513 return false;
514 } else if (!cur_frame->HasDebugInformation()) {
515 result.AppendError("no debug info for the selected frame");
516 return false;
517 } else {
518 const SymbolContext &sc =
519 cur_frame->GetSymbolContext(eSymbolContextLineEntry);
520 SymbolContextList sc_list;
521 sc_list.Append(sc);
522 ModuleList module_list;
523 FileSpec file_spec;
524 if (!DumpLinesInSymbolContexts(result.GetOutputStream(), sc_list,
525 module_list, file_spec)) {
526 result.AppendError(
527 "No source line info available for the selected frame.");
528 return false;
529 }
530 }
531 return true;
532 }
533
534 void DoExecute(Args &command, CommandReturnObject &result) override {
535 Target &target = GetTarget();
536
537 // Collect the list of modules to search.
538 m_module_list.Clear();
539 if (!m_options.modules.empty()) {
540 for (size_t i = 0, e = m_options.modules.size(); i < e; ++i) {
541 FileSpec module_file_spec(m_options.modules[i]);
542 if (module_file_spec) {
543 ModuleSpec module_spec(module_file_spec);
544 target.GetImages().FindModules(module_spec, m_module_list);
545 if (m_module_list.IsEmpty())
546 result.AppendWarningWithFormatv("no module found for '{0}'",
547 m_options.modules[i]);
548 }
549 }
550 if (!m_module_list.GetSize()) {
551 result.AppendError("no modules match the input");
552 return;
553 }
554 } else if (target.GetImages().GetSize() == 0) {
555 result.AppendError("the target has no associated executable images");
556 return;
557 }
558
559 // Check the arguments to see what lines we should dump.
560 if (!m_options.symbol_name.empty()) {
561 // Print lines for symbol.
562 if (DumpLinesInFunctions(result))
564 else
566 } else if (m_options.address != LLDB_INVALID_ADDRESS) {
567 // Print lines for an address.
568 if (DumpLinesForAddress(result))
570 else
572 } else if (!m_options.file_name.empty()) {
573 // Dump lines for a file.
574 if (DumpLinesForFile(result))
576 else
578 } else {
579 // Dump the line for the current frame.
580 if (DumpLinesForFrame(result))
582 else
584 }
585 }
586
589};
590
591#pragma mark CommandObjectSourceList
592// CommandObjectSourceList
593#define LLDB_OPTIONS_source_list
594#include "CommandOptions.inc"
595
597 class CommandOptions : public Options {
598 public:
599 CommandOptions() = default;
600
601 ~CommandOptions() override = default;
602
603 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
604 ExecutionContext *execution_context) override {
606 const int short_option = GetDefinitions()[option_idx].short_option;
607 switch (short_option) {
608 case 'l':
609 if (option_arg.getAsInteger(0, start_line))
610 error = Status::FromErrorStringWithFormat("invalid line number: '%s'",
611 option_arg.str().c_str());
612 break;
613
614 case 'c':
615 if (option_arg.getAsInteger(0, num_lines))
616 error = Status::FromErrorStringWithFormat("invalid line count: '%s'",
617 option_arg.str().c_str());
618 break;
619
620 case 'f':
621 file_name = std::string(option_arg);
622 break;
623
624 case 'n':
625 symbol_name = std::string(option_arg);
626 break;
627
628 case 'a': {
629 address = OptionArgParser::ToAddress(execution_context, option_arg,
631 } break;
632 case 's':
633 modules.push_back(std::string(option_arg));
634 break;
635
636 case 'b':
637 show_bp_locs = true;
638 break;
639 case 'r':
640 reverse = true;
641 break;
642 case 'y':
643 {
645 Status fcl_err = value.SetValueFromString(option_arg);
646 if (!fcl_err.Success()) {
648 "Invalid value for file:line specifier: %s", fcl_err.AsCString());
649 } else {
650 file_name = value.GetFileSpec().GetPath();
651 start_line = value.GetLineNumber();
652 // I don't see anything useful to do with a column number, but I don't
653 // want to complain since someone may well have cut and pasted a
654 // listing from somewhere that included a column.
655 }
656 } break;
657 default:
658 llvm_unreachable("Unimplemented option");
659 }
660
661 return error;
662 }
663
664 void OptionParsingStarting(ExecutionContext *execution_context) override {
665 file_spec.Clear();
666 file_name.clear();
667 symbol_name.clear();
669 start_line = 0;
670 num_lines = 0;
671 show_bp_locs = false;
672 reverse = false;
673 modules.clear();
674 }
675
676 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
677 return llvm::ArrayRef(g_source_list_options);
678 }
679
680 // Instance variables to hold the values for command options.
682 std::string file_name;
683 std::string symbol_name;
685 uint32_t start_line;
686 uint32_t num_lines;
687 std::vector<std::string> modules;
690 };
691
692public:
694 : CommandObjectParsed(interpreter, "source list",
695 "Display source code for the current target "
696 "process as specified by options.",
697 nullptr, eCommandRequiresTarget) {}
698
699 ~CommandObjectSourceList() override = default;
700
701 Options *GetOptions() override { return &m_options; }
702
703 std::optional<std::string> GetRepeatCommand(Args &current_command_args,
704 uint32_t index) override {
705 // This is kind of gross, but the command hasn't been parsed yet so we
706 // can't look at the option values for this invocation... I have to scan
707 // the arguments directly.
708 auto iter =
709 llvm::find_if(current_command_args, [](const Args::ArgEntry &e) {
710 return e.ref() == "-r" || e.ref() == "--reverse";
711 });
712 if (iter == current_command_args.end())
713 return m_cmd_name;
714
715 if (m_reverse_name.empty()) {
717 m_reverse_name.append(" -r");
718 }
719 return m_reverse_name;
720 }
721
722protected:
723 struct SourceInfo {
726
729
730 SourceInfo() = default;
731
732 bool IsValid() const { return (bool)function && line_entry.IsValid(); }
733
734 bool operator==(const SourceInfo &rhs) const {
735 return function == rhs.function &&
736 line_entry.original_file_sp->Equal(
739 line_entry.line == rhs.line_entry.line;
740 }
741
742 bool operator!=(const SourceInfo &rhs) const {
743 return function != rhs.function ||
744 !line_entry.original_file_sp->Equal(
747 line_entry.line != rhs.line_entry.line;
748 }
749
750 bool operator<(const SourceInfo &rhs) const {
751 if (function.GetCString() < rhs.function.GetCString())
752 return true;
753 if (line_entry.GetFile().GetDirectory().GetCString() <
755 return true;
756 if (line_entry.GetFile().GetFilename().GetCString() <
758 return true;
759 if (line_entry.line < rhs.line_entry.line)
760 return true;
761 return false;
762 }
763 };
764
765 size_t DisplayFunctionSource(const SymbolContext &sc, SourceInfo &source_info,
766 CommandReturnObject &result) {
767 if (!source_info.IsValid()) {
768 source_info.function = sc.GetFunctionName();
769 source_info.line_entry = sc.GetFunctionStartLineEntry();
770 }
771
772 if (sc.function) {
773 Target &target = GetTarget();
774
775 SupportFileNSP start_file = std::make_shared<SupportFile>();
776 uint32_t start_line;
777 uint32_t end_line;
778 FileSpec end_file;
779
780 if (sc.block == nullptr) {
781 // Not an inlined function
782 auto expected_info = sc.function->GetSourceInfo();
783 if (!expected_info) {
784 result.AppendError(llvm::toString(expected_info.takeError()));
785 return 0;
786 }
787 start_file = expected_info->first;
788 start_line = expected_info->second.GetRangeBase();
789 end_line = expected_info->second.GetRangeEnd();
790 } else {
791 // We have an inlined function
792 start_file = source_info.line_entry.file_sp;
793 start_line = source_info.line_entry.line;
794 end_line = start_line + m_options.num_lines;
795 }
796
797 // This is a little hacky, but the first line table entry for a function
798 // points to the "{" that starts the function block. It would be nice to
799 // actually get the function declaration in there too. So back up a bit,
800 // but not further than what you're going to display.
801 uint32_t extra_lines;
802 if (m_options.num_lines >= 10)
803 extra_lines = 5;
804 else
805 extra_lines = m_options.num_lines / 2;
806 uint32_t line_no;
807 if (start_line <= extra_lines)
808 line_no = 1;
809 else
810 line_no = start_line - extra_lines;
811
812 // For fun, if the function is shorter than the number of lines we're
813 // supposed to display, only display the function...
814 if (end_line != 0) {
815 if (m_options.num_lines > end_line - line_no)
816 m_options.num_lines = end_line - line_no + extra_lines;
817 }
818
820
821 if (m_options.show_bp_locs) {
822 const bool show_inlines = true;
823 m_breakpoint_locations.Reset(start_file->GetSpecOnly(), 0,
824 show_inlines);
825 SearchFilterForUnconstrainedSearches target_search_filter(
826 m_exe_ctx.GetTargetSP());
827 target_search_filter.Search(m_breakpoint_locations);
828 }
829
831 "File: {0}", start_file->GetSpecOnly().GetPath().c_str());
832 // We don't care about the column here.
833 const uint32_t column = 0;
835 start_file, line_no, column, 0, m_options.num_lines, "",
837 } else {
839 "Could not find function info for: \"%s\".\n",
840 m_options.symbol_name.c_str());
841 }
842 return 0;
843 }
844
845 // From Jim: The FindMatchingFunctions / FindMatchingFunctionSymbols
846 // functions "take a possibly empty vector of strings which are names of
847 // modules, and run the two search functions on the subset of the full module
848 // list that matches the strings in the input vector". If we wanted to put
849 // these somewhere, there should probably be a module-filter-list that can be
850 // passed to the various ModuleList::Find* calls, which would either be a
851 // vector of string names or a ModuleSpecList.
853 SymbolContextList &sc_list) {
854 // Displaying the source for a symbol:
855 if (m_options.num_lines == 0)
856 m_options.num_lines = 10;
857
858 ModuleFunctionSearchOptions function_options;
859 function_options.include_symbols = true;
860 function_options.include_inlines = false;
861
862 const size_t num_modules = m_options.modules.size();
863 if (num_modules > 0) {
864 ModuleList matching_modules;
865 for (size_t i = 0; i < num_modules; ++i) {
866 FileSpec module_file_spec(m_options.modules[i]);
867 if (module_file_spec) {
868 ModuleSpec module_spec(module_file_spec);
869 matching_modules.Clear();
870 target.GetImages().FindModules(module_spec, matching_modules);
871
872 matching_modules.FindFunctions(name, eFunctionNameTypeAuto,
873 function_options, sc_list);
874 }
875 }
876 } else {
877 target.GetImages().FindFunctions(name, eFunctionNameTypeAuto,
878 function_options, sc_list);
879 }
880 }
881
883 SymbolContextList &sc_list) {
884 const size_t num_modules = m_options.modules.size();
885 if (num_modules > 0) {
886 ModuleList matching_modules;
887 for (size_t i = 0; i < num_modules; ++i) {
888 FileSpec module_file_spec(m_options.modules[i]);
889 if (module_file_spec) {
890 ModuleSpec module_spec(module_file_spec);
891 matching_modules.Clear();
892 target.GetImages().FindModules(module_spec, matching_modules);
893 matching_modules.FindFunctionSymbols(name, eFunctionNameTypeAuto,
894 sc_list);
895 }
896 }
897 } else {
898 target.GetImages().FindFunctionSymbols(name, eFunctionNameTypeAuto,
899 sc_list);
900 }
901 }
902
903 void DoExecute(Args &command, CommandReturnObject &result) override {
904 Target &target = GetTarget();
905
906 if (!m_options.symbol_name.empty()) {
907 SymbolContextList sc_list;
908 ConstString name(m_options.symbol_name.c_str());
909
910 // Displaying the source for a symbol. Search for function named name.
911 FindMatchingFunctions(target, name, sc_list);
912 if (sc_list.GetSize() == 0) {
913 // If we didn't find any functions with that name, try searching for
914 // symbols that line up exactly with function addresses.
915 SymbolContextList sc_list_symbols;
916 FindMatchingFunctionSymbols(target, name, sc_list_symbols);
917 for (const SymbolContext &sc : sc_list_symbols) {
918 if (sc.symbol && sc.symbol->ValueIsAddress()) {
919 const Address &base_address = sc.symbol->GetAddressRef();
920 Function *function = base_address.CalculateSymbolContextFunction();
921 if (function) {
922 sc_list.Append(SymbolContext(function));
923 break;
924 }
925 }
926 }
927 }
928
929 if (sc_list.GetSize() == 0) {
930 result.AppendErrorWithFormat("Could not find function named: \"%s\".\n",
931 m_options.symbol_name.c_str());
932 return;
933 }
934
935 std::set<SourceInfo> source_match_set;
936 bool displayed_something = false;
937 for (const SymbolContext &sc : sc_list) {
938 SourceInfo source_info(sc.GetFunctionName(),
939 sc.GetFunctionStartLineEntry());
940 if (source_info.IsValid() &&
941 source_match_set.find(source_info) == source_match_set.end()) {
942 source_match_set.insert(source_info);
943 if (DisplayFunctionSource(sc, source_info, result))
944 displayed_something = true;
945 }
946 }
947 if (displayed_something)
949 else
951 return;
952 } else if (m_options.address != LLDB_INVALID_ADDRESS) {
953 Address so_addr;
954 StreamString error_strm;
955 SymbolContextList sc_list;
956
957 if (!target.HasLoadedSections()) {
958 // The target isn't loaded yet, we need to lookup the file address in
959 // all modules
960 const ModuleList &module_list = target.GetImages();
961 const size_t num_modules = module_list.GetSize();
962 for (size_t i = 0; i < num_modules; ++i) {
963 ModuleSP module_sp(module_list.GetModuleAtIndex(i));
964 if (module_sp &&
965 module_sp->ResolveFileAddress(m_options.address, so_addr)) {
966 SymbolContext sc;
967 sc.Clear(true);
968 if (module_sp->ResolveSymbolContextForAddress(
969 so_addr, eSymbolContextEverything, sc) &
970 eSymbolContextLineEntry)
971 sc_list.Append(sc);
972 }
973 }
974
975 if (sc_list.GetSize() == 0) {
977 "no modules have source information for file address 0x%" PRIx64
978 ".\n",
979 m_options.address);
980 return;
981 }
982 } else {
983 // The target has some things loaded, resolve this address to a compile
984 // unit + file + line and display
985 if (target.ResolveLoadAddress(m_options.address, so_addr)) {
986 ModuleSP module_sp(so_addr.GetModule());
987 if (module_sp) {
988 SymbolContext sc;
989 sc.Clear(true);
990 if (module_sp->ResolveSymbolContextForAddress(
991 so_addr, eSymbolContextEverything, sc) &
992 eSymbolContextLineEntry) {
993 sc_list.Append(sc);
994 } else {
995 so_addr.Dump(&error_strm, nullptr,
997 result.AppendErrorWithFormat("address resolves to %s, but there "
998 "is no line table information "
999 "available for this address.\n",
1000 error_strm.GetData());
1001 return;
1002 }
1003 }
1004 }
1005
1006 if (sc_list.GetSize() == 0) {
1007 result.AppendErrorWithFormat(
1008 "no modules contain load address 0x%" PRIx64 ".\n",
1009 m_options.address);
1010 return;
1011 }
1012 }
1013 for (const SymbolContext &sc : sc_list) {
1014 if (sc.comp_unit) {
1015 if (m_options.show_bp_locs) {
1016 m_breakpoint_locations.Clear();
1017 const bool show_inlines = true;
1018 m_breakpoint_locations.Reset(sc.comp_unit->GetPrimaryFile(), 0,
1019 show_inlines);
1020 SearchFilterForUnconstrainedSearches target_search_filter(
1021 target.shared_from_this());
1022 target_search_filter.Search(m_breakpoint_locations);
1023 }
1024
1025 bool show_fullpaths = true;
1026 bool show_module = true;
1027 bool show_inlined_frames = true;
1028 const bool show_function_arguments = true;
1029 const bool show_function_name = true;
1030 sc.DumpStopContext(&result.GetOutputStream(),
1031 m_exe_ctx.GetBestExecutionContextScope(),
1032 sc.line_entry.range.GetBaseAddress(),
1033 show_fullpaths, show_module, show_inlined_frames,
1034 show_function_arguments, show_function_name);
1035 result.GetOutputStream().EOL();
1036
1037 if (m_options.num_lines == 0)
1038 m_options.num_lines = 10;
1039
1040 size_t lines_to_back_up =
1041 m_options.num_lines >= 10 ? 5 : m_options.num_lines / 2;
1042
1043 const uint32_t column =
1045 ? sc.line_entry.column
1046 : 0;
1048 sc.comp_unit->GetPrimarySupportFile(),
1049 sc.line_entry.line, column, lines_to_back_up,
1050 m_options.num_lines - lines_to_back_up, "->",
1053 }
1054 }
1055 } else if (m_options.file_name.empty()) {
1056 // Last valid source manager context, or the current frame if no valid
1057 // last context in source manager. One little trick here, if you type the
1058 // exact same list command twice in a row, it is more likely because you
1059 // typed it once, then typed it again
1060 if (m_options.start_line == 0) {
1062 &result.GetOutputStream(), m_options.num_lines,
1063 m_options.reverse, GetBreakpointLocations())) {
1065 } else {
1066 if (target.GetSourceManager().AtLastLine(m_options.reverse)) {
1067 result.AppendNoteWithFormatv(
1068 "Reached {0} of the file, no more to page",
1069 m_options.reverse ? "beginning" : "end");
1070 } else {
1071 result.AppendNote("no source available");
1072 }
1073 }
1074
1075 } else {
1076 if (m_options.num_lines == 0)
1077 m_options.num_lines = 10;
1078
1079 if (m_options.show_bp_locs) {
1080 SourceManager::FileSP last_file_sp(
1081 target.GetSourceManager().GetLastFile());
1082 if (last_file_sp) {
1083 const bool show_inlines = true;
1085 last_file_sp->GetSupportFile()->GetSpecOnly(), 0, show_inlines);
1086 SearchFilterForUnconstrainedSearches target_search_filter(
1087 target.shared_from_this());
1088 target_search_filter.Search(m_breakpoint_locations);
1089 }
1090 } else
1091 m_breakpoint_locations.Clear();
1092
1093 const uint32_t column = 0;
1094 if (target.GetSourceManager()
1096 m_options.start_line, // Line to display
1097 m_options.num_lines, // Lines after line to
1098 UINT32_MAX, // Don't mark "line"
1099 column,
1100 "", // Don't mark "line"
1103 }
1104 }
1105 } else {
1106 // const char *filename = m_options.file_name.c_str();
1107 FileSpec file_spec(m_options.file_name);
1108 bool check_inlines = false;
1109 const InlineStrategy inline_strategy = target.GetInlineStrategy();
1110 if (inline_strategy == eInlineBreakpointsAlways ||
1111 (inline_strategy == eInlineBreakpointsHeaders &&
1112 !file_spec.IsSourceImplementationFile()))
1113 check_inlines = true;
1114
1115 SymbolContextList sc_list;
1116 size_t num_matches = 0;
1117
1118 if (!m_options.modules.empty()) {
1119 ModuleList matching_modules;
1120 for (size_t i = 0, e = m_options.modules.size(); i < e; ++i) {
1121 FileSpec module_file_spec(m_options.modules[i]);
1122 if (module_file_spec) {
1123 ModuleSpec module_spec(module_file_spec);
1124 matching_modules.Clear();
1125 target.GetImages().FindModules(module_spec, matching_modules);
1126 num_matches += matching_modules.ResolveSymbolContextsForFileSpec(
1127 file_spec, 1, check_inlines,
1128 SymbolContextItem(eSymbolContextModule |
1129 eSymbolContextCompUnit |
1130 eSymbolContextLineEntry),
1131 sc_list);
1132 }
1133 }
1134 } else {
1135 num_matches = target.GetImages().ResolveSymbolContextsForFileSpec(
1136 file_spec, 1, check_inlines,
1137 eSymbolContextModule | eSymbolContextCompUnit |
1138 eSymbolContextLineEntry,
1139 sc_list);
1140 }
1141
1142 if (num_matches == 0) {
1143 result.AppendErrorWithFormat("Could not find source file \"%s\".\n",
1144 m_options.file_name.c_str());
1145 return;
1146 }
1147
1148 if (num_matches > 1) {
1149 bool got_multiple = false;
1150 CompileUnit *test_cu = nullptr;
1151
1152 for (const SymbolContext &sc : sc_list) {
1153 if (sc.comp_unit) {
1154 if (test_cu) {
1155 if (test_cu != sc.comp_unit)
1156 got_multiple = true;
1157 break;
1158 } else
1159 test_cu = sc.comp_unit;
1160 }
1161 }
1162 if (got_multiple) {
1163 result.AppendErrorWithFormat(
1164 "Multiple source files found matching: \"%s.\"\n",
1165 m_options.file_name.c_str());
1166 return;
1167 }
1168 }
1169
1170 SymbolContext sc;
1171 if (sc_list.GetContextAtIndex(0, sc)) {
1172 if (sc.comp_unit) {
1173 if (m_options.show_bp_locs) {
1174 const bool show_inlines = true;
1176 show_inlines);
1177 SearchFilterForUnconstrainedSearches target_search_filter(
1178 target.shared_from_this());
1179 target_search_filter.Search(m_breakpoint_locations);
1180 } else
1181 m_breakpoint_locations.Clear();
1182
1183 if (m_options.num_lines == 0)
1184 m_options.num_lines = 10;
1185 const uint32_t column = 0;
1186
1187 // Headers aren't always in the DWARF but if they have
1188 // executable code (eg., inlined-functions) then the callsite's
1189 // file(s) will be found and assigned to
1190 // sc.comp_unit->GetPrimarySupportFile, which is NOT what we want to
1191 // print. Instead, we want to print the one from the line entry.
1192 SupportFileNSP found_file_sp = sc.line_entry.file_sp;
1193
1195 found_file_sp, m_options.start_line, column, 0,
1196 m_options.num_lines, "", &result.GetOutputStream(),
1198
1200 } else {
1201 result.AppendErrorWithFormat("No comp unit found for: \"%s.\"\n",
1202 m_options.file_name.c_str());
1203 }
1204 }
1205 }
1206 }
1207
1209 if (m_breakpoint_locations.GetFileLineMatches().GetSize() > 0)
1210 return &m_breakpoint_locations.GetFileLineMatches();
1211 return nullptr;
1212 }
1213
1216 std::string m_reverse_name;
1217};
1218
1220public:
1222 : CommandObjectParsed(interpreter, "source cache dump",
1223 "Dump the state of the source code cache. Intended "
1224 "to be used for debugging LLDB itself.",
1225 nullptr) {}
1226
1227 ~CommandObjectSourceCacheDump() override = default;
1228
1229protected:
1230 void DoExecute(Args &command, CommandReturnObject &result) override {
1231 // Dump the debugger source cache.
1232 result.GetOutputStream() << "Debugger Source File Cache\n";
1234 cache.Dump(result.GetOutputStream());
1235
1236 // Dump the process source cache.
1237 if (ProcessSP process_sp = m_exe_ctx.GetProcessSP()) {
1238 result.GetOutputStream() << "\nProcess Source File Cache\n";
1239 SourceManager::SourceFileCache &cache = process_sp->GetSourceFileCache();
1240 cache.Dump(result.GetOutputStream());
1241 }
1242
1244 }
1245};
1246
1248public:
1250 : CommandObjectParsed(interpreter, "source cache clear",
1251 "Clear the source code cache.\n", nullptr) {}
1252
1254
1255protected:
1256 void DoExecute(Args &command, CommandReturnObject &result) override {
1257 // Clear the debugger cache.
1259 cache.Clear();
1260
1261 // Clear the process cache.
1262 if (ProcessSP process_sp = m_exe_ctx.GetProcessSP())
1263 process_sp->GetSourceFileCache().Clear();
1264
1266 }
1267};
1268
1270public:
1272 : CommandObjectMultiword(interpreter, "source cache",
1273 "Commands for managing the source code cache.",
1274 "source cache <sub-command>") {
1276 "dump", CommandObjectSP(new CommandObjectSourceCacheDump(interpreter)));
1278 interpreter)));
1279 }
1280
1281 ~CommandObjectSourceCache() override = default;
1282
1283private:
1287};
1288
1289#pragma mark CommandObjectMultiwordSource
1290// CommandObjectMultiwordSource
1291
1293 CommandInterpreter &interpreter)
1294 : CommandObjectMultiword(interpreter, "source",
1295 "Commands for examining "
1296 "source code described by "
1297 "debug information for the "
1298 "current target process.",
1299 "source <subcommand> [<subcommand-options>]") {
1300 LoadSubCommand("info",
1301 CommandObjectSP(new CommandObjectSourceInfo(interpreter)));
1302 LoadSubCommand("list",
1303 CommandObjectSP(new CommandObjectSourceList(interpreter)));
1304 LoadSubCommand("cache",
1305 CommandObjectSP(new CommandObjectSourceCache(interpreter)));
1306}
1307
static llvm::raw_ostream & error(Stream &strm)
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectSourceCacheClear(CommandInterpreter &interpreter)
~CommandObjectSourceCacheClear() override=default
~CommandObjectSourceCacheDump() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectSourceCacheDump(CommandInterpreter &interpreter)
CommandObjectSourceCache(CommandInterpreter &interpreter)
~CommandObjectSourceCache() override=default
CommandObjectSourceCache(const CommandObjectSourceCache &)=delete
const CommandObjectSourceCache & operator=(const CommandObjectSourceCache &)=delete
void OptionParsingStarting(ExecutionContext *execution_context) override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
void DoExecute(Args &command, CommandReturnObject &result) override
bool DumpLinesForFile(CommandReturnObject &result)
size_t GetSymbolContextsForAddress(const ModuleList &module_list, lldb::addr_t addr, SymbolContextList &sc_list, StreamString &error_strm)
Options * GetOptions() override
uint32_t DumpLinesInSymbolContexts(Stream &strm, const SymbolContextList &sc_list, const ModuleList &module_list, const FileSpec &file_spec)
bool DumpLinesForFrame(CommandReturnObject &result)
uint32_t DumpFileLinesInCompUnit(Stream &strm, Module *module, CompileUnit *cu, const FileSpec &file_spec)
bool DumpLinesInFunctions(CommandReturnObject &result)
bool DumpLinesForAddress(CommandReturnObject &result)
~CommandObjectSourceInfo() override=default
CommandObjectSourceInfo(CommandInterpreter &interpreter)
uint32_t DumpFileLinesInModule(Stream &strm, Module *module, const FileSpec &file_spec)
void OptionParsingStarting(ExecutionContext *execution_context) override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
~CommandObjectSourceList() override=default
void FindMatchingFunctions(Target &target, ConstString name, SymbolContextList &sc_list)
FileLineResolver m_breakpoint_locations
CommandObjectSourceList(CommandInterpreter &interpreter)
void FindMatchingFunctionSymbols(Target &target, ConstString name, SymbolContextList &sc_list)
const SymbolContextList * GetBreakpointLocations()
size_t DisplayFunctionSource(const SymbolContext &sc, SourceInfo &source_info, CommandReturnObject &result)
std::optional< std::string > GetRepeatCommand(Args &current_command_args, uint32_t index) override
Get the command that appropriate for a "repeat" of the current command.
void DoExecute(Args &command, CommandReturnObject &result) override
Options * GetOptions() override
A section + offset based address range class.
Address & GetBaseAddress()
Get accessor for the base address of the range.
lldb::addr_t GetByteSize() const
Get accessor for the byte size of this range.
A section + offset based address class.
Definition Address.h:62
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition Address.cpp:301
Function * CalculateSymbolContextFunction() const
Definition Address.cpp:859
@ DumpStyleModuleWithFileAddress
Display as the file address with the module name prepended (if any).
Definition Address.h:93
bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style=DumpStyleInvalid, uint32_t addr_byte_size=UINT32_MAX, bool all_ranges=false, std::optional< Stream::HighlightSettings > settings=std::nullopt) const
Dump a description of this object to a Stream.
Definition Address.cpp:396
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
Definition Address.cpp:273
lldb::addr_t GetFileAddress() const
Get the file address.
Definition Address.cpp:281
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition ArchSpec.cpp:681
A command line argument class.
Definition Args.h:33
const_iterator end() const
Definition Args.h:137
CommandObjectMultiwordSource(CommandInterpreter &interpreter)
bool LoadSubCommand(llvm::StringRef cmd_name, const lldb::CommandObjectSP &command_obj) override
CommandObjectMultiword(CommandInterpreter &interpreter, const char *name, const char *help=nullptr, const char *syntax=nullptr, uint32_t flags=0)
CommandObjectParsed(CommandInterpreter &interpreter, const char *name, const char *help=nullptr, const char *syntax=nullptr, uint32_t flags=0)
void AppendError(llvm::StringRef in_string)
void AppendNote(llvm::StringRef in_string)
void AppendWarningWithFormatv(const char *format, Args &&...args)
void SetStatus(lldb::ReturnStatus status)
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
void void AppendMessageWithFormatv(const char *format, Args &&...args)
void AppendNoteWithFormatv(const char *format, Args &&...args)
void AppendErrorWithFormatv(const char *format, Args &&...args)
A class that describes a compilation unit.
Definition CompileUnit.h:43
const SupportFileList & GetSupportFiles()
Get the compile unit's support file list.
const FileSpec & GetPrimaryFile() const
Return the primary source spec associated with this compile unit.
uint32_t FindLineEntry(uint32_t start_idx, uint32_t line, const FileSpec *file_spec_ptr, bool exact, LineEntry *line_entry)
Find the line entry by line and optional inlined file spec.
A uniqued constant string class.
Definition ConstString.h:40
const char * GetCString() const
Get the string value as a C string.
const char * AsCString(const char *value_if_empty) const
Get the string value as a C string.
SourceManager::SourceFileCache & GetSourceFileCache()
Definition Debugger.h:643
lldb::StopShowColumn GetStopShowColumn() const
Definition Debugger.cpp:669
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
This class finds address for source file and line.
A file utility class.
Definition FileSpec.h:57
static bool Match(const FileSpec &pattern, const FileSpec &file)
Match FileSpec pattern against FileSpec file.
Definition FileSpec.cpp:301
const ConstString & GetFilename() const
Filename string const get accessor.
Definition FileSpec.h:250
const ConstString & GetDirectory() const
Directory string const get accessor.
Definition FileSpec.h:234
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition FileSpec.cpp:374
bool IsSourceImplementationFile() const
Returns true if the filespec represents an implementation source file (files with a "....
Definition FileSpec.cpp:501
A class that describes a function.
Definition Function.h:400
llvm::Expected< std::pair< SupportFileNSP, SourceRange > > GetSourceInfo()
Find the file and line number range of the function.
Definition Function.cpp:305
A collection class for Module objects.
Definition ModuleList.h:125
uint32_t ResolveSymbolContextsForFileSpec(const FileSpec &file_spec, uint32_t line, bool check_inlines, lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list) const
Resolve items in the symbol context for a given file and line. (const FileSpec&,...
void FindFunctions(ConstString name, lldb::FunctionNameType name_type_mask, const ModuleFunctionSearchOptions &options, SymbolContextList &sc_list) const
size_t GetIndexForModule(const Module *module) const
void Clear()
Clear the object's state.
Module * GetModulePointerAtIndex(size_t idx) const
Get the module pointer for the module at index idx.
void FindModules(const ModuleSpec &module_spec, ModuleList &matching_module_list) const
Finds modules whose file specification matches module_spec.
lldb::ModuleSP GetModuleAtIndex(size_t idx) const
Get the module shared pointer for the module at index idx.
void FindFunctionSymbols(ConstString name, lldb::FunctionNameType name_type_mask, SymbolContextList &sc_list)
size_t GetSize() const
Gets the size of the module list.
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:90
lldb::CompUnitSP GetCompileUnitAtIndex(size_t idx)
Definition Module.cpp:419
size_t GetNumCompileUnits()
Get the number of compile units for this module.
Definition Module.cpp:412
Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign) override
A command line option parsing protocol class.
Definition Options.h:58
"lldb/Core/SearchFilter.h" This is a SearchFilter that searches through all modules.
virtual void Search(Searcher &searcher)
Call this method to do the search using the Searcher.
The SourceFileCache class separates the source manager from the cache of source files.
std::shared_ptr< File > FileSP
size_t DisplayMoreWithLineNumbers(Stream *s, uint32_t count, bool reverse, const SymbolContextList *bp_locs=nullptr, lldb::LanguageType language_type=lldb::eLanguageTypeUnknown)
bool AtLastLine(bool reverse)
size_t DisplaySourceLinesWithLineNumbers(SupportFileNSP support_file_nsp, uint32_t line, uint32_t column, uint32_t context_before, uint32_t context_after, const char *current_line_cstr, Stream *s, const SymbolContextList *bp_locs=nullptr, lldb::LanguageType language_type=lldb::eLanguageTypeUnknown)
size_t DisplaySourceLinesWithLineNumbersUsingLastFile(uint32_t start_line, uint32_t count, uint32_t curr_line, uint32_t column, const char *current_line_cstr, Stream *s, const SymbolContextList *bp_locs=nullptr, lldb::LanguageType language_type=lldb::eLanguageTypeUnknown)
This base class provides an interface to stack frames.
Definition StackFrame.h:44
virtual const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame's current pc value.
virtual bool HasDebugInformation()
Determine whether this StackFrame has debug information available or not.
An error handling class.
Definition Status.h:118
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition Status.cpp:106
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition Status.cpp:194
bool Success() const
Test for success condition.
Definition Status.cpp:303
const char * GetData() const
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:132
size_t EOL()
Output and End of Line character to the stream.
Definition Stream.cpp:153
A list of support files for a CompileUnit.
const FileSpec & GetFileSpecAtIndex(size_t idx) const
size_t FindFileIndex(size_t idx, const FileSpec &file, bool full) const
Defines a list of symbol context objects.
bool GetContextAtIndex(size_t idx, SymbolContext &sc) const
Get accessor for a symbol context at index idx.
uint32_t GetSize() const
Get accessor for a symbol context list size.
bool AppendIfUnique(const SymbolContext &sc, bool merge_symbol_into_function)
void Append(const SymbolContext &sc)
Append a new symbol context to the list.
Defines a symbol context baton that can be handed other debug core functions.
LineEntry GetFunctionStartLineEntry() const
Get the line entry that corresponds to the function.
Function * function
The Function for a given query.
ConstString GetFunctionName(Mangled::NamePreference preference=Mangled::ePreferDemangled) const
Find a name of the innermost function for the symbol context.
Block * block
The Block for a given query.
CompileUnit * comp_unit
The CompileUnit for a given query.
void Clear(bool clear_target)
Clear the object's state.
LineEntry line_entry
The LineEntry for a given query.
InlineStrategy GetInlineStrategy() const
Definition Target.cpp:4733
SourceManager & GetSourceManager()
Definition Target.cpp:3039
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, uint32_t stop_id=SectionLoadHistory::eStopIDNow, bool allow_section_end=false)
Definition Target.cpp:3319
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition Target.h:1157
const ArchSpec & GetArchitecture() const
Definition Target.h:1199
#define LLDB_INVALID_INDEX32
#define LLDB_INVALID_ADDRESS
#define UINT32_MAX
A class that represents a running process on the host machine.
NonNullSharedPtr< lldb_private::SupportFile > SupportFileNSP
Definition SupportFile.h:80
@ eInlineBreakpointsAlways
Definition Target.h:54
@ eInlineBreakpointsHeaders
Definition Target.h:53
@ eDescriptionLevelBrief
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
std::shared_ptr< lldb_private::Process > ProcessSP
@ eStopShowColumnNone
@ eReturnStatusFailed
@ eReturnStatusSuccessFinishResult
@ eReturnStatusSuccessFinishNoResult
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Module > ModuleSP
std::shared_ptr< lldb_private::CompileUnit > CompUnitSP
bool operator==(const SourceInfo &rhs) const
SourceInfo(ConstString name, const LineEntry &line_entry)
bool operator!=(const SourceInfo &rhs) const
bool operator<(const SourceInfo &rhs) const
llvm::StringRef ref() const
Definition Args.h:50
A line table entry class.
Definition LineEntry.h:21
uint32_t line
The source line number, or LLDB_INVALID_LINE_NUMBER if there is no line number information.
Definition LineEntry.h:151
bool GetDescription(Stream *s, lldb::DescriptionLevel level, CompileUnit *cu, Target *target, bool show_address_only) const
Definition LineEntry.cpp:96
const FileSpec & GetFile() const
Helper to access the file.
Definition LineEntry.h:134
SupportFileNSP file_sp
The source file, possibly mapped by the target.source-map setting.
Definition LineEntry.h:144
SupportFileNSP original_file_sp
The original source file, from debug info.
Definition LineEntry.h:147
Options used by Module::FindFunctions.
Definition Module.h:66
bool include_inlines
Include inlined functions.
Definition Module.h:70
bool include_symbols
Include the symbol table.
Definition Module.h:68
static lldb::addr_t ToAddress(const ExecutionContext *exe_ctx, llvm::StringRef s, lldb::addr_t fail_value, Status *error_ptr)
Try to parse an address.