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.SetErrorStringWithFormat("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.SetErrorStringWithFormat("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.SetErrorStringWithFormat("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 {
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());
206 bool has_path = (file_spec.GetDirectory().AsCString() != 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.GetSectionLoadList().IsEmpty()) {
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.GetSectionLoadList().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.AppendWarningWithFormat("in symbol '%s': %s",
432 sc.GetFunctionName().AsCString(),
433 error_strm.GetData());
434 else
435 context_found_for_symbol = true;
436 }
437 }
438 if (!context_found_for_symbol)
439 result.AppendWarningWithFormat("Unable to find line information"
440 " for matching symbol '%s'.\n",
441 sc.GetFunctionName().AsCString());
442 }
443 if (sc_list_lines.GetSize() == 0) {
444 result.AppendErrorWithFormat("No line information could be found"
445 " for any symbols matching '%s'.\n",
446 name.AsCString());
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 '%s'.\n",
454 name.AsCString());
455 return false;
456 }
457 return true;
458 }
459
460 // Dump the line entries found for the address specified in the option.
462 Target &target = GetTarget();
463 SymbolContextList sc_list;
464
465 StreamString error_strm;
467 sc_list, error_strm)) {
468 result.AppendErrorWithFormat("%s.\n", error_strm.GetData());
469 return false;
470 }
471 ModuleList module_list;
472 FileSpec file_spec;
473 if (!DumpLinesInSymbolContexts(result.GetOutputStream(), sc_list,
474 module_list, file_spec)) {
475 result.AppendErrorWithFormat("No modules contain load address 0x%" PRIx64
476 ".\n",
478 return false;
479 }
480 return true;
481 }
482
483 // Dump the line entries found in the file specified in the option.
485 FileSpec file_spec(m_options.file_name);
486 const char *filename = m_options.file_name.c_str();
487 Target &target = GetTarget();
488 const ModuleList &module_list =
489 (m_module_list.GetSize() > 0) ? m_module_list : target.GetImages();
490
491 bool displayed_something = false;
492 const size_t num_modules = module_list.GetSize();
493 for (uint32_t i = 0; i < num_modules; ++i) {
494 // Dump lines for this module.
495 Module *module = module_list.GetModulePointerAtIndex(i);
496 assert(module);
497 if (DumpFileLinesInModule(result.GetOutputStream(), module, file_spec))
498 displayed_something = true;
499 }
500 if (!displayed_something) {
501 result.AppendErrorWithFormat("No source filenames matched '%s'.\n",
502 filename);
503 return false;
504 }
505 return true;
506 }
507
508 // Dump the line entries for the current frame.
510 StackFrame *cur_frame = m_exe_ctx.GetFramePtr();
511 if (cur_frame == nullptr) {
512 result.AppendError(
513 "No selected frame to use to find the default source.");
514 return false;
515 } else if (!cur_frame->HasDebugInformation()) {
516 result.AppendError("No debug info for the selected frame.");
517 return false;
518 } else {
519 const SymbolContext &sc =
520 cur_frame->GetSymbolContext(eSymbolContextLineEntry);
521 SymbolContextList sc_list;
522 sc_list.Append(sc);
523 ModuleList module_list;
524 FileSpec file_spec;
525 if (!DumpLinesInSymbolContexts(result.GetOutputStream(), sc_list,
526 module_list, file_spec)) {
527 result.AppendError(
528 "No source line info available for the selected frame.");
529 return false;
530 }
531 }
532 return true;
533 }
534
535 void DoExecute(Args &command, CommandReturnObject &result) override {
536 Target &target = GetTarget();
537
538 uint32_t addr_byte_size = target.GetArchitecture().GetAddressByteSize();
539 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
540 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
541
542 // Collect the list of modules to search.
544 if (!m_options.modules.empty()) {
545 for (size_t i = 0, e = m_options.modules.size(); i < e; ++i) {
546 FileSpec module_file_spec(m_options.modules[i]);
547 if (module_file_spec) {
548 ModuleSpec module_spec(module_file_spec);
549 target.GetImages().FindModules(module_spec, m_module_list);
551 result.AppendWarningWithFormat("No module found for '%s'.\n",
552 m_options.modules[i].c_str());
553 }
554 }
555 if (!m_module_list.GetSize()) {
556 result.AppendError("No modules match the input.");
557 return;
558 }
559 } else if (target.GetImages().GetSize() == 0) {
560 result.AppendError("The target has no associated executable images.");
561 return;
562 }
563
564 // Check the arguments to see what lines we should dump.
565 if (!m_options.symbol_name.empty()) {
566 // Print lines for symbol.
567 if (DumpLinesInFunctions(result))
569 else
571 } else if (m_options.address != LLDB_INVALID_ADDRESS) {
572 // Print lines for an address.
573 if (DumpLinesForAddress(result))
575 else
577 } else if (!m_options.file_name.empty()) {
578 // Dump lines for a file.
579 if (DumpLinesForFile(result))
581 else
583 } else {
584 // Dump the line for the current frame.
585 if (DumpLinesForFrame(result))
587 else
589 }
590 }
591
594};
595
596#pragma mark CommandObjectSourceList
597// CommandObjectSourceList
598#define LLDB_OPTIONS_source_list
599#include "CommandOptions.inc"
600
602 class CommandOptions : public Options {
603 public:
604 CommandOptions() = default;
605
606 ~CommandOptions() override = default;
607
608 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
609 ExecutionContext *execution_context) override {
611 const int short_option = GetDefinitions()[option_idx].short_option;
612 switch (short_option) {
613 case 'l':
614 if (option_arg.getAsInteger(0, start_line))
615 error.SetErrorStringWithFormat("invalid line number: '%s'",
616 option_arg.str().c_str());
617 break;
618
619 case 'c':
620 if (option_arg.getAsInteger(0, num_lines))
621 error.SetErrorStringWithFormat("invalid line count: '%s'",
622 option_arg.str().c_str());
623 break;
624
625 case 'f':
626 file_name = std::string(option_arg);
627 break;
628
629 case 'n':
630 symbol_name = std::string(option_arg);
631 break;
632
633 case 'a': {
634 address = OptionArgParser::ToAddress(execution_context, option_arg,
636 } break;
637 case 's':
638 modules.push_back(std::string(option_arg));
639 break;
640
641 case 'b':
642 show_bp_locs = true;
643 break;
644 case 'r':
645 reverse = true;
646 break;
647 case 'y':
648 {
650 Status fcl_err = value.SetValueFromString(option_arg);
651 if (!fcl_err.Success()) {
652 error.SetErrorStringWithFormat(
653 "Invalid value for file:line specifier: %s",
654 fcl_err.AsCString());
655 } else {
656 file_name = value.GetFileSpec().GetPath();
657 start_line = value.GetLineNumber();
658 // I don't see anything useful to do with a column number, but I don't
659 // want to complain since someone may well have cut and pasted a
660 // listing from somewhere that included a column.
661 }
662 } break;
663 default:
664 llvm_unreachable("Unimplemented option");
665 }
666
667 return error;
668 }
669
670 void OptionParsingStarting(ExecutionContext *execution_context) override {
672 file_name.clear();
673 symbol_name.clear();
675 start_line = 0;
676 num_lines = 0;
677 show_bp_locs = false;
678 reverse = false;
679 modules.clear();
680 }
681
682 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
683 return llvm::ArrayRef(g_source_list_options);
684 }
685
686 // Instance variables to hold the values for command options.
688 std::string file_name;
689 std::string symbol_name;
691 uint32_t start_line;
692 uint32_t num_lines;
693 std::vector<std::string> modules;
696 };
697
698public:
700 : CommandObjectParsed(interpreter, "source list",
701 "Display source code for the current target "
702 "process as specified by options.",
703 nullptr, eCommandRequiresTarget) {}
704
705 ~CommandObjectSourceList() override = default;
706
707 Options *GetOptions() override { return &m_options; }
708
709 std::optional<std::string> GetRepeatCommand(Args &current_command_args,
710 uint32_t index) override {
711 // This is kind of gross, but the command hasn't been parsed yet so we
712 // can't look at the option values for this invocation... I have to scan
713 // the arguments directly.
714 auto iter =
715 llvm::find_if(current_command_args, [](const Args::ArgEntry &e) {
716 return e.ref() == "-r" || e.ref() == "--reverse";
717 });
718 if (iter == current_command_args.end())
719 return m_cmd_name;
720
721 if (m_reverse_name.empty()) {
723 m_reverse_name.append(" -r");
724 }
725 return m_reverse_name;
726 }
727
728protected:
729 struct SourceInfo {
732
734 : function(name), line_entry(line_entry) {}
735
736 SourceInfo() = default;
737
738 bool IsValid() const { return (bool)function && line_entry.IsValid(); }
739
740 bool operator==(const SourceInfo &rhs) const {
741 return function == rhs.function &&
746 }
747
748 bool operator!=(const SourceInfo &rhs) const {
749 return function != rhs.function ||
754 }
755
756 bool operator<(const SourceInfo &rhs) const {
758 return true;
761 return true;
764 return true;
765 if (line_entry.line < rhs.line_entry.line)
766 return true;
767 return false;
768 }
769 };
770
771 size_t DisplayFunctionSource(const SymbolContext &sc, SourceInfo &source_info,
772 CommandReturnObject &result) {
773 if (!source_info.IsValid()) {
774 source_info.function = sc.GetFunctionName();
775 source_info.line_entry = sc.GetFunctionStartLineEntry();
776 }
777
778 if (sc.function) {
779 Target &target = GetTarget();
780
781 FileSpec start_file;
782 uint32_t start_line;
783 uint32_t end_line;
784 FileSpec end_file;
785
786 if (sc.block == nullptr) {
787 // Not an inlined function
788 sc.function->GetStartLineSourceInfo(start_file, start_line);
789 if (start_line == 0) {
790 result.AppendErrorWithFormat("Could not find line information for "
791 "start of function: \"%s\".\n",
792 source_info.function.GetCString());
793 return 0;
794 }
795 sc.function->GetEndLineSourceInfo(end_file, end_line);
796 } else {
797 // We have an inlined function
798 start_file = source_info.line_entry.GetFile();
799 start_line = source_info.line_entry.line;
800 end_line = start_line + m_options.num_lines;
801 }
802
803 // This is a little hacky, but the first line table entry for a function
804 // points to the "{" that starts the function block. It would be nice to
805 // actually get the function declaration in there too. So back up a bit,
806 // but not further than what you're going to display.
807 uint32_t extra_lines;
808 if (m_options.num_lines >= 10)
809 extra_lines = 5;
810 else
811 extra_lines = m_options.num_lines / 2;
812 uint32_t line_no;
813 if (start_line <= extra_lines)
814 line_no = 1;
815 else
816 line_no = start_line - extra_lines;
817
818 // For fun, if the function is shorter than the number of lines we're
819 // supposed to display, only display the function...
820 if (end_line != 0) {
821 if (m_options.num_lines > end_line - line_no)
822 m_options.num_lines = end_line - line_no + extra_lines;
823 }
824
826
828 const bool show_inlines = true;
829 m_breakpoint_locations.Reset(start_file, 0, show_inlines);
830 SearchFilterForUnconstrainedSearches target_search_filter(
832 target_search_filter.Search(m_breakpoint_locations);
833 }
834
835 result.AppendMessageWithFormat("File: %s\n",
836 start_file.GetPath().c_str());
837 // We don't care about the column here.
838 const uint32_t column = 0;
840 start_file, line_no, column, 0, m_options.num_lines, "",
842 } else {
844 "Could not find function info for: \"%s\".\n",
845 m_options.symbol_name.c_str());
846 }
847 return 0;
848 }
849
850 // From Jim: The FindMatchingFunctions / FindMatchingFunctionSymbols
851 // functions "take a possibly empty vector of strings which are names of
852 // modules, and run the two search functions on the subset of the full module
853 // list that matches the strings in the input vector". If we wanted to put
854 // these somewhere, there should probably be a module-filter-list that can be
855 // passed to the various ModuleList::Find* calls, which would either be a
856 // vector of string names or a ModuleSpecList.
858 SymbolContextList &sc_list) {
859 // Displaying the source for a symbol:
860 if (m_options.num_lines == 0)
861 m_options.num_lines = 10;
862
863 ModuleFunctionSearchOptions function_options;
864 function_options.include_symbols = true;
865 function_options.include_inlines = false;
866
867 const size_t num_modules = m_options.modules.size();
868 if (num_modules > 0) {
869 ModuleList matching_modules;
870 for (size_t i = 0; i < num_modules; ++i) {
871 FileSpec module_file_spec(m_options.modules[i]);
872 if (module_file_spec) {
873 ModuleSpec module_spec(module_file_spec);
874 matching_modules.Clear();
875 target.GetImages().FindModules(module_spec, matching_modules);
876
877 matching_modules.FindFunctions(name, eFunctionNameTypeAuto,
878 function_options, sc_list);
879 }
880 }
881 } else {
882 target.GetImages().FindFunctions(name, eFunctionNameTypeAuto,
883 function_options, sc_list);
884 }
885 }
886
888 SymbolContextList &sc_list) {
889 const size_t num_modules = m_options.modules.size();
890 if (num_modules > 0) {
891 ModuleList matching_modules;
892 for (size_t i = 0; i < num_modules; ++i) {
893 FileSpec module_file_spec(m_options.modules[i]);
894 if (module_file_spec) {
895 ModuleSpec module_spec(module_file_spec);
896 matching_modules.Clear();
897 target.GetImages().FindModules(module_spec, matching_modules);
898 matching_modules.FindFunctionSymbols(name, eFunctionNameTypeAuto,
899 sc_list);
900 }
901 }
902 } else {
903 target.GetImages().FindFunctionSymbols(name, eFunctionNameTypeAuto,
904 sc_list);
905 }
906 }
907
908 void DoExecute(Args &command, CommandReturnObject &result) override {
909 Target &target = GetTarget();
910
911 if (!m_options.symbol_name.empty()) {
912 SymbolContextList sc_list;
913 ConstString name(m_options.symbol_name.c_str());
914
915 // Displaying the source for a symbol. Search for function named name.
916 FindMatchingFunctions(target, name, sc_list);
917 if (sc_list.GetSize() == 0) {
918 // If we didn't find any functions with that name, try searching for
919 // symbols that line up exactly with function addresses.
920 SymbolContextList sc_list_symbols;
921 FindMatchingFunctionSymbols(target, name, sc_list_symbols);
922 for (const SymbolContext &sc : sc_list_symbols) {
923 if (sc.symbol && sc.symbol->ValueIsAddress()) {
924 const Address &base_address = sc.symbol->GetAddressRef();
925 Function *function = base_address.CalculateSymbolContextFunction();
926 if (function) {
927 sc_list.Append(SymbolContext(function));
928 break;
929 }
930 }
931 }
932 }
933
934 if (sc_list.GetSize() == 0) {
935 result.AppendErrorWithFormat("Could not find function named: \"%s\".\n",
936 m_options.symbol_name.c_str());
937 return;
938 }
939
940 std::set<SourceInfo> source_match_set;
941 bool displayed_something = false;
942 for (const SymbolContext &sc : sc_list) {
943 SourceInfo source_info(sc.GetFunctionName(),
944 sc.GetFunctionStartLineEntry());
945 if (source_info.IsValid() &&
946 source_match_set.find(source_info) == source_match_set.end()) {
947 source_match_set.insert(source_info);
948 if (DisplayFunctionSource(sc, source_info, result))
949 displayed_something = true;
950 }
951 }
952 if (displayed_something)
954 else
956 return;
957 } else if (m_options.address != LLDB_INVALID_ADDRESS) {
958 Address so_addr;
959 StreamString error_strm;
960 SymbolContextList sc_list;
961
962 if (target.GetSectionLoadList().IsEmpty()) {
963 // The target isn't loaded yet, we need to lookup the file address in
964 // all modules
965 const ModuleList &module_list = target.GetImages();
966 const size_t num_modules = module_list.GetSize();
967 for (size_t i = 0; i < num_modules; ++i) {
968 ModuleSP module_sp(module_list.GetModuleAtIndex(i));
969 if (module_sp &&
970 module_sp->ResolveFileAddress(m_options.address, so_addr)) {
971 SymbolContext sc;
972 sc.Clear(true);
973 if (module_sp->ResolveSymbolContextForAddress(
974 so_addr, eSymbolContextEverything, sc) &
975 eSymbolContextLineEntry)
976 sc_list.Append(sc);
977 }
978 }
979
980 if (sc_list.GetSize() == 0) {
982 "no modules have source information for file address 0x%" PRIx64
983 ".\n",
985 return;
986 }
987 } else {
988 // The target has some things loaded, resolve this address to a compile
989 // unit + file + line and display
991 so_addr)) {
992 ModuleSP module_sp(so_addr.GetModule());
993 if (module_sp) {
994 SymbolContext sc;
995 sc.Clear(true);
996 if (module_sp->ResolveSymbolContextForAddress(
997 so_addr, eSymbolContextEverything, sc) &
998 eSymbolContextLineEntry) {
999 sc_list.Append(sc);
1000 } else {
1001 so_addr.Dump(&error_strm, nullptr,
1003 result.AppendErrorWithFormat("address resolves to %s, but there "
1004 "is no line table information "
1005 "available for this address.\n",
1006 error_strm.GetData());
1007 return;
1008 }
1009 }
1010 }
1011
1012 if (sc_list.GetSize() == 0) {
1013 result.AppendErrorWithFormat(
1014 "no modules contain load address 0x%" PRIx64 ".\n",
1016 return;
1017 }
1018 }
1019 for (const SymbolContext &sc : sc_list) {
1020 if (sc.comp_unit) {
1021 if (m_options.show_bp_locs) {
1023 const bool show_inlines = true;
1024 m_breakpoint_locations.Reset(sc.comp_unit->GetPrimaryFile(), 0,
1025 show_inlines);
1026 SearchFilterForUnconstrainedSearches target_search_filter(
1027 target.shared_from_this());
1028 target_search_filter.Search(m_breakpoint_locations);
1029 }
1030
1031 bool show_fullpaths = true;
1032 bool show_module = true;
1033 bool show_inlined_frames = true;
1034 const bool show_function_arguments = true;
1035 const bool show_function_name = true;
1036 sc.DumpStopContext(&result.GetOutputStream(),
1038 sc.line_entry.range.GetBaseAddress(),
1039 show_fullpaths, show_module, show_inlined_frames,
1040 show_function_arguments, show_function_name);
1041 result.GetOutputStream().EOL();
1042
1043 if (m_options.num_lines == 0)
1044 m_options.num_lines = 10;
1045
1046 size_t lines_to_back_up =
1047 m_options.num_lines >= 10 ? 5 : m_options.num_lines / 2;
1048
1049 const uint32_t column =
1051 ? sc.line_entry.column
1052 : 0;
1054 sc.comp_unit->GetPrimaryFile(), sc.line_entry.line, column,
1055 lines_to_back_up, m_options.num_lines - lines_to_back_up, "->",
1058 }
1059 }
1060 } else if (m_options.file_name.empty()) {
1061 // Last valid source manager context, or the current frame if no valid
1062 // last context in source manager. One little trick here, if you type the
1063 // exact same list command twice in a row, it is more likely because you
1064 // typed it once, then typed it again
1065 if (m_options.start_line == 0) {
1070 }
1071 } else {
1072 if (m_options.num_lines == 0)
1073 m_options.num_lines = 10;
1074
1075 if (m_options.show_bp_locs) {
1076 SourceManager::FileSP last_file_sp(
1077 target.GetSourceManager().GetLastFile());
1078 if (last_file_sp) {
1079 const bool show_inlines = true;
1080 m_breakpoint_locations.Reset(last_file_sp->GetFileSpec(), 0,
1081 show_inlines);
1082 SearchFilterForUnconstrainedSearches target_search_filter(
1083 target.shared_from_this());
1084 target_search_filter.Search(m_breakpoint_locations);
1085 }
1086 } else
1088
1089 const uint32_t column = 0;
1090 if (target.GetSourceManager()
1092 m_options.start_line, // Line to display
1093 m_options.num_lines, // Lines after line to
1094 UINT32_MAX, // Don't mark "line"
1095 column,
1096 "", // Don't mark "line"
1099 }
1100 }
1101 } else {
1102 const char *filename = m_options.file_name.c_str();
1103
1104 bool check_inlines = false;
1105 SymbolContextList sc_list;
1106 size_t num_matches = 0;
1107
1108 if (!m_options.modules.empty()) {
1109 ModuleList matching_modules;
1110 for (size_t i = 0, e = m_options.modules.size(); i < e; ++i) {
1111 FileSpec module_file_spec(m_options.modules[i]);
1112 if (module_file_spec) {
1113 ModuleSpec module_spec(module_file_spec);
1114 matching_modules.Clear();
1115 target.GetImages().FindModules(module_spec, matching_modules);
1116 num_matches += matching_modules.ResolveSymbolContextForFilePath(
1117 filename, 0, check_inlines,
1118 SymbolContextItem(eSymbolContextModule |
1119 eSymbolContextCompUnit),
1120 sc_list);
1121 }
1122 }
1123 } else {
1124 num_matches = target.GetImages().ResolveSymbolContextForFilePath(
1125 filename, 0, check_inlines,
1126 eSymbolContextModule | eSymbolContextCompUnit, sc_list);
1127 }
1128
1129 if (num_matches == 0) {
1130 result.AppendErrorWithFormat("Could not find source file \"%s\".\n",
1131 m_options.file_name.c_str());
1132 return;
1133 }
1134
1135 if (num_matches > 1) {
1136 bool got_multiple = false;
1137 CompileUnit *test_cu = nullptr;
1138
1139 for (const SymbolContext &sc : sc_list) {
1140 if (sc.comp_unit) {
1141 if (test_cu) {
1142 if (test_cu != sc.comp_unit)
1143 got_multiple = true;
1144 break;
1145 } else
1146 test_cu = sc.comp_unit;
1147 }
1148 }
1149 if (got_multiple) {
1150 result.AppendErrorWithFormat(
1151 "Multiple source files found matching: \"%s.\"\n",
1152 m_options.file_name.c_str());
1153 return;
1154 }
1155 }
1156
1157 SymbolContext sc;
1158 if (sc_list.GetContextAtIndex(0, sc)) {
1159 if (sc.comp_unit) {
1160 if (m_options.show_bp_locs) {
1161 const bool show_inlines = true;
1163 show_inlines);
1164 SearchFilterForUnconstrainedSearches target_search_filter(
1165 target.shared_from_this());
1166 target_search_filter.Search(m_breakpoint_locations);
1167 } else
1169
1170 if (m_options.num_lines == 0)
1171 m_options.num_lines = 10;
1172 const uint32_t column = 0;
1174 sc.comp_unit->GetPrimaryFile(), m_options.start_line, column, 0,
1175 m_options.num_lines, "", &result.GetOutputStream(),
1177
1179 } else {
1180 result.AppendErrorWithFormat("No comp unit found for: \"%s.\"\n",
1181 m_options.file_name.c_str());
1182 }
1183 }
1184 }
1185 }
1186
1190 return nullptr;
1191 }
1192
1195 std::string m_reverse_name;
1196};
1197
1199public:
1201 : CommandObjectParsed(interpreter, "source cache dump",
1202 "Dump the state of the source code cache. Intended "
1203 "to be used for debugging LLDB itself.",
1204 nullptr) {}
1205
1206 ~CommandObjectSourceCacheDump() override = default;
1207
1208protected:
1209 void DoExecute(Args &command, CommandReturnObject &result) override {
1210 // Dump the debugger source cache.
1211 result.GetOutputStream() << "Debugger Source File Cache\n";
1213 cache.Dump(result.GetOutputStream());
1214
1215 // Dump the process source cache.
1216 if (ProcessSP process_sp = m_exe_ctx.GetProcessSP()) {
1217 result.GetOutputStream() << "\nProcess Source File Cache\n";
1218 SourceManager::SourceFileCache &cache = process_sp->GetSourceFileCache();
1219 cache.Dump(result.GetOutputStream());
1220 }
1221
1223 }
1224};
1225
1227public:
1229 : CommandObjectParsed(interpreter, "source cache clear",
1230 "Clear the source code cache.\n", nullptr) {}
1231
1233
1234protected:
1235 void DoExecute(Args &command, CommandReturnObject &result) override {
1236 // Clear the debugger cache.
1238 cache.Clear();
1239
1240 // Clear the process cache.
1241 if (ProcessSP process_sp = m_exe_ctx.GetProcessSP())
1242 process_sp->GetSourceFileCache().Clear();
1243
1245 }
1246};
1247
1249public:
1251 : CommandObjectMultiword(interpreter, "source cache",
1252 "Commands for managing the source code cache.",
1253 "source cache <sub-command>") {
1255 "dump", CommandObjectSP(new CommandObjectSourceCacheDump(interpreter)));
1257 interpreter)));
1258 }
1259
1260 ~CommandObjectSourceCache() override = default;
1261
1262private:
1266};
1267
1268#pragma mark CommandObjectMultiwordSource
1269// CommandObjectMultiwordSource
1270
1272 CommandInterpreter &interpreter)
1273 : CommandObjectMultiword(interpreter, "source",
1274 "Commands for examining "
1275 "source code described by "
1276 "debug information for the "
1277 "current target process.",
1278 "source <subcommand> [<subcommand-options>]") {
1279 LoadSubCommand("info",
1280 CommandObjectSP(new CommandObjectSourceInfo(interpreter)));
1281 LoadSubCommand("list",
1282 CommandObjectSP(new CommandObjectSourceList(interpreter)));
1283 LoadSubCommand("cache",
1284 CommandObjectSP(new CommandObjectSourceCache(interpreter)));
1285}
1286
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.
Definition: AddressRange.h:25
Address & GetBaseAddress()
Get accessor for the base address of the range.
Definition: AddressRange.h:211
lldb::addr_t GetByteSize() const
Get accessor for the byte size of this range.
Definition: AddressRange.h:223
A section + offset based address class.
Definition: Address.h:62
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition: Address.cpp:313
Function * CalculateSymbolContextFunction() const
Definition: Address.cpp:872
@ 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:408
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
Definition: Address.cpp:285
lldb::addr_t GetFileAddress() const
Get the file address.
Definition: Address.cpp:293
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition: ArchSpec.cpp:691
A command line argument class.
Definition: Args.h:33
const_iterator end() const
Definition: Args.h:133
CommandObjectMultiwordSource(CommandInterpreter &interpreter)
bool LoadSubCommand(llvm::StringRef cmd_name, const lldb::CommandObjectSP &command_obj) override
ExecutionContext m_exe_ctx
void void AppendError(llvm::StringRef in_string)
void AppendWarningWithFormat(const char *format,...) __attribute__((format(printf
void SetStatus(lldb::ReturnStatus status)
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
void AppendMessageWithFormat(const char *format,...) __attribute__((format(printf
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.
Definition: CompileUnit.h:232
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 * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:188
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:216
SourceManager::SourceFileCache & GetSourceFileCache()
Definition: Debugger.h:595
lldb::StopShowColumn GetStopShowColumn() const
Definition: Debugger.cpp:495
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
ExecutionContextScope * GetBestExecutionContextScope() const
const lldb::TargetSP & GetTargetSP() const
Get accessor to get the target shared pointer.
const lldb::ProcessSP & GetProcessSP() const
Get accessor to get the process shared pointer.
StackFrame * GetFramePtr() const
Returns a pointer to the frame object.
This class finds address for source file and line.
const SymbolContextList & GetFileLineMatches()
void Reset(const FileSpec &file_spec, uint32_t line, bool check_inlines)
A file utility class.
Definition: FileSpec.h:56
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:240
const ConstString & GetDirectory() const
Directory string const get accessor.
Definition: FileSpec.h:223
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition: FileSpec.cpp:367
void Clear()
Clears the object state.
Definition: FileSpec.cpp:259
A class that describes a function.
Definition: Function.h:399
void GetStartLineSourceInfo(FileSpec &source_file, uint32_t &line_no)
Find the file and line number of the source location of the start of the function.
Definition: Function.cpp:270
void GetEndLineSourceInfo(FileSpec &source_file, uint32_t &line_no)
Find the file and line number of the source location of the end of the function.
Definition: Function.cpp:298
A collection class for Module objects.
Definition: ModuleList.h:103
void FindFunctions(ConstString name, lldb::FunctionNameType name_type_mask, const ModuleFunctionSearchOptions &options, SymbolContextList &sc_list) const
size_t GetIndexForModule(const Module *module) const
Definition: ModuleList.cpp:725
void Clear()
Clear the object's state.
Definition: ModuleList.cpp:411
uint32_t ResolveSymbolContextForFilePath(const char *file_path, 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 char*,uint32_t,...
Definition: ModuleList.cpp:705
Module * GetModulePointerAtIndex(size_t idx) const
Get the module pointer for the module at index idx.
Definition: ModuleList.cpp:422
void FindModules(const ModuleSpec &module_spec, ModuleList &matching_module_list) const
Finds the first module whose file specification matches file_spec.
Definition: ModuleList.cpp:543
lldb::ModuleSP GetModuleAtIndex(size_t idx) const
Get the module shared pointer for the module at index idx.
Definition: ModuleList.cpp:429
void FindFunctionSymbols(ConstString name, lldb::FunctionNameType name_type_mask, SymbolContextList &sc_list)
Definition: ModuleList.cpp:469
size_t GetSize() const
Gets the size of the module list.
Definition: ModuleList.cpp:638
A class that describes an executable image and its associated object and symbol files.
Definition: Module.h:88
lldb::CompUnitSP GetCompileUnitAtIndex(size_t idx)
Definition: Module.cpp:431
size_t GetNumCompileUnits()
Get the number of compile units for this module.
Definition: Module.cpp:424
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
Definition: Module.h:452
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.
Definition: SearchFilter.h:289
virtual void Search(Searcher &searcher)
Call this method to do the search using the Searcher.
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, bool allow_section_end=false) const
The SourceFileCache class separates the source manager from the cache of source files.
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)
std::shared_ptr< File > FileSP
Definition: SourceManager.h:99
size_t DisplaySourceLinesWithLineNumbers(const FileSpec &file, 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)
size_t DisplayMoreWithLineNumbers(Stream *s, uint32_t count, bool reverse, const SymbolContextList *bp_locs=nullptr)
This base class provides an interface to stack frames.
Definition: StackFrame.h:43
const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame's current pc value.
Definition: StackFrame.cpp:300
bool HasDebugInformation()
Determine whether this StackFrame has debug information available or not.
An error handling class.
Definition: Status.h:44
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition: Status.cpp:129
bool Success() const
Test for success condition.
Definition: Status.cpp:278
const char * GetData() const
Definition: StreamString.h:45
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:134
void SetAddressByteSize(uint32_t addr_size)
Set the address size in bytes.
Definition: Stream.cpp:209
size_t EOL()
Output and End of Line character to the stream.
Definition: Stream.cpp:155
A list of support files for a CompileUnit.
Definition: FileSpecList.h:23
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.
Definition: SymbolContext.h:34
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.
SourceManager & GetSourceManager()
Definition: Target.cpp:2826
SectionLoadList & GetSectionLoadList()
Definition: Target.h:1143
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition: Target.h:986
const ArchSpec & GetArchitecture() const
Definition: Target.h:1028
#define LLDB_INVALID_INDEX32
Definition: lldb-defines.h:83
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:82
#define UINT32_MAX
Definition: lldb-defines.h:19
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
@ eDescriptionLevelBrief
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
Definition: lldb-forward.h:331
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:387
@ eStopShowColumnNone
@ eReturnStatusFailed
@ eReturnStatusSuccessFinishResult
@ eReturnStatusSuccessFinishNoResult
uint64_t addr_t
Definition: lldb-types.h:80
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:371
std::shared_ptr< lldb_private::CompileUnit > CompUnitSP
Definition: lldb-forward.h:333
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:48
A line table entry class.
Definition: LineEntry.h:21
lldb::SupportFileSP original_file_sp
The original source file, from debug info.
Definition: LineEntry.h:143
bool IsValid() const
Check if a line entry object is valid.
Definition: LineEntry.cpp:35
uint32_t line
The source line number, or LLDB_INVALID_LINE_NUMBER if there is no line number information.
Definition: LineEntry.h:147
bool GetDescription(Stream *s, lldb::DescriptionLevel level, CompileUnit *cu, Target *target, bool show_address_only) const
Definition: LineEntry.cpp:95
const FileSpec & GetFile() const
Helper to access the file.
Definition: LineEntry.h:134
Options used by Module::FindFunctions.
Definition: Module.h:65
bool include_inlines
Include inlined functions.
Definition: Module.h:69
bool include_symbols
Include the symbol table.
Definition: Module.h:67
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.