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 assert(target && "target guaranteed by eCommandRequiresTarget");
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 assert(target && "target guaranteed by eCommandRequiresTarget");
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 assert(target && "target guaranteed by eCommandRequiresTarget");
306 if (!target->HasLoadedSections()) {
307 // The target isn't loaded yet, we need to lookup the file address in all
308 // modules. Note: the module list option does not apply to addresses.
309 const size_t num_modules = module_list.GetSize();
310 for (size_t i = 0; i < num_modules; ++i) {
311 ModuleSP module_sp(module_list.GetModuleAtIndex(i));
312 if (!module_sp)
313 continue;
314 if (module_sp->ResolveFileAddress(addr, so_addr)) {
315 SymbolContext sc;
316 sc.Clear(true);
317 if (module_sp->ResolveSymbolContextForAddress(
318 so_addr, eSymbolContextEverything, sc) &
319 eSymbolContextLineEntry) {
320 sc_list.AppendIfUnique(sc, /*merge_symbol_into_function=*/false);
321 ++num_matches;
322 }
323 }
324 }
325 if (num_matches == 0)
326 error_strm.Printf("Source information for file address 0x%" PRIx64
327 " not found in any modules.\n",
328 addr);
329 } else {
330 // The target has some things loaded, resolve this address to a compile
331 // unit + file + line and display
332 if (target->ResolveLoadAddress(addr, so_addr)) {
333 ModuleSP module_sp(so_addr.GetModule());
334 // Check to make sure this module is in our list.
335 if (module_sp && module_list.GetIndexForModule(module_sp.get()) !=
337 SymbolContext sc;
338 sc.Clear(true);
339 if (module_sp->ResolveSymbolContextForAddress(
340 so_addr, eSymbolContextEverything, sc) &
341 eSymbolContextLineEntry) {
342 sc_list.AppendIfUnique(sc, /*merge_symbol_into_function=*/false);
343 ++num_matches;
344 } else {
345 StreamString addr_strm;
346 so_addr.Dump(&addr_strm, nullptr,
348 error_strm.Printf(
349 "Address 0x%" PRIx64 " resolves to %s, but there is"
350 " no source information available for this address.\n",
351 addr, addr_strm.GetData());
352 }
353 } else {
354 StreamString addr_strm;
355 so_addr.Dump(&addr_strm, nullptr,
357 error_strm.Printf("Address 0x%" PRIx64
358 " resolves to %s, but it cannot"
359 " be found in any modules.\n",
360 addr, addr_strm.GetData());
361 }
362 } else
363 error_strm.Printf("Unable to resolve address 0x%" PRIx64 ".\n", addr);
364 }
365 return num_matches;
366 }
367
368 // Dump the line entries found in functions matching the name specified in
369 // the option.
371 SymbolContextList sc_list_funcs;
372 ConstString name(m_options.symbol_name);
373 SymbolContextList sc_list_lines;
374 Target *target = GetTarget();
375 assert(target && "target guaranteed by eCommandRequiresTarget");
376 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
377
378 ModuleFunctionSearchOptions function_options;
379 function_options.include_symbols = false;
380 function_options.include_inlines = true;
381
382 // Note: module_list can't be const& because FindFunctionSymbols isn't
383 // const.
384 ModuleList module_list =
385 (m_module_list.GetSize() > 0) ? m_module_list : target->GetImages();
386 module_list.FindFunctions(name, eFunctionNameTypeAuto, function_options,
387 sc_list_funcs);
388 size_t num_matches = sc_list_funcs.GetSize();
389
390 if (!num_matches) {
391 // If we didn't find any functions with that name, try searching for
392 // symbols that line up exactly with function addresses.
393 SymbolContextList sc_list_symbols;
394 module_list.FindFunctionSymbols(name, eFunctionNameTypeAuto,
395 sc_list_symbols);
396 for (const SymbolContext &sc : sc_list_symbols) {
397 if (sc.symbol && sc.symbol->ValueIsAddress()) {
398 const Address &base_address = sc.symbol->GetAddressRef();
399 Function *function = base_address.CalculateSymbolContextFunction();
400 if (function) {
401 sc_list_funcs.Append(SymbolContext(function));
402 num_matches++;
403 }
404 }
405 }
406 }
407 if (num_matches == 0) {
408 result.AppendErrorWithFormat("Could not find function named \'%s\'",
409 m_options.symbol_name.c_str());
410 return false;
411 }
412 for (const SymbolContext &sc : sc_list_funcs) {
413 bool context_found_for_symbol = false;
414 // Loop through all the ranges in the function.
415 AddressRange range;
416 for (uint32_t r = 0;
417 sc.GetAddressRange(eSymbolContextEverything, r,
418 /*use_inline_block_range=*/true, range);
419 ++r) {
420 // Append the symbol contexts for each address in the range to
421 // sc_list_lines.
422 const Address &base_address = range.GetBaseAddress();
423 const addr_t size = range.GetByteSize();
424 lldb::addr_t start_addr = base_address.GetLoadAddress(target);
425 if (start_addr == LLDB_INVALID_ADDRESS)
426 start_addr = base_address.GetFileAddress();
427 lldb::addr_t end_addr = start_addr + size;
428 for (lldb::addr_t addr = start_addr; addr < end_addr;
429 addr += addr_byte_size) {
430 StreamString error_strm;
431 if (!GetSymbolContextsForAddress(module_list, addr, sc_list_lines,
432 error_strm))
433 result.AppendWarningWithFormatv("in symbol '{0}': {1}",
434 sc.GetFunctionName(),
435 error_strm.GetData());
436 else
437 context_found_for_symbol = true;
438 }
439 }
440 if (!context_found_for_symbol)
441 result.AppendWarningWithFormatv("unable to find line information"
442 " for matching symbol '{0}'\n",
443 sc.GetFunctionName());
444 }
445 if (sc_list_lines.GetSize() == 0) {
446 result.AppendErrorWithFormatv("No line information could be found"
447 " for any symbols matching '{0}'.\n",
448 name);
449 return false;
450 }
451 FileSpec file_spec;
452 if (!DumpLinesInSymbolContexts(result.GetOutputStream(), sc_list_lines,
453 module_list, file_spec)) {
455 "Unable to dump line information for symbol '{0}'.\n", name);
456 return false;
457 }
458 return true;
459 }
460
461 // Dump the line entries found for the address specified in the option.
463 Target *target = GetTarget();
464 assert(target && "target guaranteed by eCommandRequiresTarget");
465 SymbolContextList sc_list;
466
467 StreamString error_strm;
468 if (!GetSymbolContextsForAddress(target->GetImages(), m_options.address,
469 sc_list, error_strm)) {
470 result.AppendErrorWithFormat("%s", error_strm.GetData());
471 return false;
472 }
473 ModuleList module_list;
474 FileSpec file_spec;
475 if (!DumpLinesInSymbolContexts(result.GetOutputStream(), sc_list,
476 module_list, file_spec)) {
477 result.AppendErrorWithFormat("No modules contain load address 0x%" PRIx64,
478 m_options.address);
479 return false;
480 }
481 return true;
482 }
483
484 // Dump the line entries found in the file specified in the option.
486 FileSpec file_spec(m_options.file_name);
487 const char *filename = m_options.file_name.c_str();
488 Target *target = GetTarget();
489 assert(target && "target guaranteed by eCommandRequiresTarget");
490 const ModuleList &module_list =
491 (m_module_list.GetSize() > 0) ? m_module_list : target->GetImages();
492
493 bool displayed_something = false;
494 const size_t num_modules = module_list.GetSize();
495 for (uint32_t i = 0; i < num_modules; ++i) {
496 // Dump lines for this module.
497 Module *module = module_list.GetModulePointerAtIndex(i);
498 assert(module);
499 if (DumpFileLinesInModule(result.GetOutputStream(), module, file_spec))
500 displayed_something = true;
501 }
502 if (!displayed_something) {
503 result.AppendErrorWithFormat("no source filenames matched '%s'",
504 filename);
505 return false;
506 }
507 return true;
508 }
509
510 // Dump the line entries for the current frame.
512 StackFrame *cur_frame = m_exe_ctx.GetFramePtr();
513 if (cur_frame == nullptr) {
514 result.AppendError(
515 "No selected frame to use to find the default source.");
516 return false;
517 } else if (!cur_frame->HasDebugInformation()) {
518 result.AppendError("no debug info for the selected frame");
519 return false;
520 } else {
521 const SymbolContext &sc =
522 cur_frame->GetSymbolContext(eSymbolContextLineEntry);
523 SymbolContextList sc_list;
524 sc_list.Append(sc);
525 ModuleList module_list;
526 FileSpec file_spec;
527 if (!DumpLinesInSymbolContexts(result.GetOutputStream(), sc_list,
528 module_list, file_spec)) {
529 result.AppendError(
530 "No source line info available for the selected frame.");
531 return false;
532 }
533 }
534 return true;
535 }
536
537 void DoExecute(Args &command, CommandReturnObject &result) override {
538 Target *target = GetTarget();
539 assert(target && "target guaranteed by eCommandRequiresTarget");
540 // Collect the list of modules to search.
541 m_module_list.Clear();
542 if (!m_options.modules.empty()) {
543 for (size_t i = 0, e = m_options.modules.size(); i < e; ++i) {
544 FileSpec module_file_spec(m_options.modules[i]);
545 if (module_file_spec) {
546 ModuleSpec module_spec(module_file_spec);
547 target->GetImages().FindModules(module_spec, m_module_list);
548 if (m_module_list.IsEmpty())
549 result.AppendWarningWithFormatv("no module found for '{0}'",
550 m_options.modules[i]);
551 }
552 }
553 if (!m_module_list.GetSize()) {
554 result.AppendError("no modules match the input");
555 return;
556 }
557 } else if (target->GetImages().GetSize() == 0) {
558 result.AppendError("the target has no associated executable images");
559 return;
560 }
561
562 // Check the arguments to see what lines we should dump.
563 if (!m_options.symbol_name.empty()) {
564 // Print lines for symbol.
565 if (DumpLinesInFunctions(result))
567 else
569 } else if (m_options.address != LLDB_INVALID_ADDRESS) {
570 // Print lines for an address.
571 if (DumpLinesForAddress(result))
573 else
575 } else if (!m_options.file_name.empty()) {
576 // Dump lines for a file.
577 if (DumpLinesForFile(result))
579 else
581 } else {
582 // Dump the line for the current frame.
583 if (DumpLinesForFrame(result))
585 else
587 }
588 }
589
592};
593
594#pragma mark CommandObjectSourceList
595// CommandObjectSourceList
596#define LLDB_OPTIONS_source_list
597#include "CommandOptions.inc"
598
600 class CommandOptions : public Options {
601 public:
602 CommandOptions() = default;
603
604 ~CommandOptions() override = default;
605
606 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
607 ExecutionContext *execution_context) override {
609 const int short_option = GetDefinitions()[option_idx].short_option;
610 switch (short_option) {
611 case 'l':
612 if (option_arg.getAsInteger(0, start_line))
613 error = Status::FromErrorStringWithFormat("invalid line number: '%s'",
614 option_arg.str().c_str());
615 break;
616
617 case 'c':
618 if (option_arg.getAsInteger(0, num_lines))
619 error = Status::FromErrorStringWithFormat("invalid line count: '%s'",
620 option_arg.str().c_str());
621 break;
622
623 case 'f':
624 file_name = std::string(option_arg);
625 break;
626
627 case 'n':
628 symbol_name = std::string(option_arg);
629 break;
630
631 case 'a': {
632 address = OptionArgParser::ToAddress(execution_context, option_arg,
634 } break;
635 case 's':
636 modules.push_back(std::string(option_arg));
637 break;
638
639 case 'b':
640 show_bp_locs = true;
641 break;
642 case 'r':
643 reverse = true;
644 break;
645 case 'y':
646 {
648 Status fcl_err = value.SetValueFromString(option_arg);
649 if (!fcl_err.Success()) {
651 "Invalid value for file:line specifier: %s", fcl_err.AsCString());
652 } else {
653 file_name = value.GetFileSpec().GetPath();
654 start_line = value.GetLineNumber();
655 // I don't see anything useful to do with a column number, but I don't
656 // want to complain since someone may well have cut and pasted a
657 // listing from somewhere that included a column.
658 }
659 } break;
660 default:
661 llvm_unreachable("Unimplemented option");
662 }
663
664 return error;
665 }
666
667 void OptionParsingStarting(ExecutionContext *execution_context) override {
668 file_spec.Clear();
669 file_name.clear();
670 symbol_name.clear();
672 start_line = 0;
673 num_lines = 0;
674 show_bp_locs = false;
675 reverse = false;
676 modules.clear();
677 }
678
679 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
680 return llvm::ArrayRef(g_source_list_options);
681 }
682
683 // Instance variables to hold the values for command options.
685 std::string file_name;
686 std::string symbol_name;
688 uint32_t start_line;
689 uint32_t num_lines;
690 std::vector<std::string> modules;
693 };
694
695public:
697 : CommandObjectParsed(interpreter, "source list",
698 "Display source code for the current target "
699 "process as specified by options.",
700 nullptr, eCommandRequiresTarget) {}
701
702 ~CommandObjectSourceList() override = default;
703
704 Options *GetOptions() override { return &m_options; }
705
706 std::optional<std::string> GetRepeatCommand(Args &current_command_args,
707 uint32_t index) override {
708 // This is kind of gross, but the command hasn't been parsed yet so we
709 // can't look at the option values for this invocation... I have to scan
710 // the arguments directly.
711 auto iter =
712 llvm::find_if(current_command_args, [](const Args::ArgEntry &e) {
713 return e.ref() == "-r" || e.ref() == "--reverse";
714 });
715 if (iter == current_command_args.end())
716 return m_cmd_name;
717
718 if (m_reverse_name.empty()) {
720 m_reverse_name.append(" -r");
721 }
722 return m_reverse_name;
723 }
724
725protected:
726 struct SourceInfo {
729
732
733 SourceInfo() = default;
734
735 bool IsValid() const { return (bool)function && line_entry.IsValid(); }
736
737 bool operator==(const SourceInfo &rhs) const {
738 return function == rhs.function &&
739 line_entry.original_file_sp->Equal(
742 line_entry.line == rhs.line_entry.line;
743 }
744
745 bool operator!=(const SourceInfo &rhs) const {
746 return function != rhs.function ||
747 !line_entry.original_file_sp->Equal(
750 line_entry.line != rhs.line_entry.line;
751 }
752
753 bool operator<(const SourceInfo &rhs) const {
754 if (function.GetCString() < rhs.function.GetCString())
755 return true;
756 if (line_entry.GetFile().GetDirectory().GetCString() <
758 return true;
759 if (line_entry.GetFile().GetFilename().GetCString() <
761 return true;
762 if (line_entry.line < rhs.line_entry.line)
763 return true;
764 return false;
765 }
766 };
767
768 size_t DisplayFunctionSource(const SymbolContext &sc, SourceInfo &source_info,
769 CommandReturnObject &result) {
770 if (!source_info.IsValid()) {
771 source_info.function = sc.GetFunctionName();
772 source_info.line_entry = sc.GetFunctionStartLineEntry();
773 }
774
775 if (sc.function) {
776 Target *target = GetTarget();
777 assert(target && "target guaranteed by eCommandRequiresTarget");
778 SupportFileNSP start_file = std::make_shared<SupportFile>();
779 uint32_t start_line;
780 uint32_t end_line;
781 FileSpec end_file;
782
783 if (sc.block == nullptr) {
784 // Not an inlined function
785 auto expected_info = sc.function->GetSourceInfo();
786 if (!expected_info) {
787 result.AppendError(llvm::toString(expected_info.takeError()));
788 return 0;
789 }
790 start_file = expected_info->first;
791 start_line = expected_info->second.GetRangeBase();
792 end_line = expected_info->second.GetRangeEnd();
793 } else {
794 // We have an inlined function
795 start_file = source_info.line_entry.file_sp;
796 start_line = source_info.line_entry.line;
797 end_line = start_line + m_options.num_lines;
798 }
799
800 // This is a little hacky, but the first line table entry for a function
801 // points to the "{" that starts the function block. It would be nice to
802 // actually get the function declaration in there too. So back up a bit,
803 // but not further than what you're going to display.
804 uint32_t extra_lines;
805 if (m_options.num_lines >= 10)
806 extra_lines = 5;
807 else
808 extra_lines = m_options.num_lines / 2;
809 uint32_t line_no;
810 if (start_line <= extra_lines)
811 line_no = 1;
812 else
813 line_no = start_line - extra_lines;
814
815 // For fun, if the function is shorter than the number of lines we're
816 // supposed to display, only display the function...
817 if (end_line != 0) {
818 if (m_options.num_lines > end_line - line_no)
819 m_options.num_lines = end_line - line_no + extra_lines;
820 }
821
823
824 if (m_options.show_bp_locs) {
825 const bool show_inlines = true;
826 m_breakpoint_locations.Reset(start_file->GetSpecOnly(), 0,
827 show_inlines);
828 SearchFilterForUnconstrainedSearches target_search_filter(
829 m_exe_ctx.GetTargetSP());
830 target_search_filter.Search(m_breakpoint_locations);
831 }
832
834 "File: {0}", start_file->GetSpecOnly().GetPath().c_str());
835 // We don't care about the column here.
836 const uint32_t column = 0;
838 start_file, line_no, column, 0, m_options.num_lines, "",
840 } else {
841 result.AppendErrorWithFormat("Could not find function info for: \"%s\"",
842 m_options.symbol_name.c_str());
843 }
844 return 0;
845 }
846
847 // From Jim: The FindMatchingFunctions / FindMatchingFunctionSymbols
848 // functions "take a possibly empty vector of strings which are names of
849 // modules, and run the two search functions on the subset of the full module
850 // list that matches the strings in the input vector". If we wanted to put
851 // these somewhere, there should probably be a module-filter-list that can be
852 // passed to the various ModuleList::Find* calls, which would either be a
853 // vector of string names or a ModuleSpecList.
855 SymbolContextList &sc_list) {
856 // Displaying the source for a symbol:
857 if (m_options.num_lines == 0)
858 m_options.num_lines = 10;
859
860 ModuleFunctionSearchOptions function_options;
861 function_options.include_symbols = true;
862 function_options.include_inlines = false;
863
864 const size_t num_modules = m_options.modules.size();
865 if (num_modules > 0) {
866 ModuleList matching_modules;
867 for (size_t i = 0; i < num_modules; ++i) {
868 FileSpec module_file_spec(m_options.modules[i]);
869 if (module_file_spec) {
870 ModuleSpec module_spec(module_file_spec);
871 matching_modules.Clear();
872 target.GetImages().FindModules(module_spec, matching_modules);
873
874 matching_modules.FindFunctions(name, eFunctionNameTypeAuto,
875 function_options, sc_list);
876 }
877 }
878 } else {
879 target.GetImages().FindFunctions(name, eFunctionNameTypeAuto,
880 function_options, sc_list);
881 }
882 }
883
885 SymbolContextList &sc_list) {
886 const size_t num_modules = m_options.modules.size();
887 if (num_modules > 0) {
888 ModuleList matching_modules;
889 for (size_t i = 0; i < num_modules; ++i) {
890 FileSpec module_file_spec(m_options.modules[i]);
891 if (module_file_spec) {
892 ModuleSpec module_spec(module_file_spec);
893 matching_modules.Clear();
894 target.GetImages().FindModules(module_spec, matching_modules);
895 matching_modules.FindFunctionSymbols(name, eFunctionNameTypeAuto,
896 sc_list);
897 }
898 }
899 } else {
900 target.GetImages().FindFunctionSymbols(name, eFunctionNameTypeAuto,
901 sc_list);
902 }
903 }
904
905 void DoExecute(Args &command, CommandReturnObject &result) override {
906 Target *target = GetTarget();
907 assert(target && "target guaranteed by eCommandRequiresTarget");
908 if (!m_options.symbol_name.empty()) {
909 SymbolContextList sc_list;
910 ConstString name(m_options.symbol_name);
911
912 // Displaying the source for a symbol. Search for function named name.
913 FindMatchingFunctions(*target, name, sc_list);
914 if (sc_list.GetSize() == 0) {
915 // If we didn't find any functions with that name, try searching for
916 // symbols that line up exactly with function addresses.
917 SymbolContextList sc_list_symbols;
918 FindMatchingFunctionSymbols(*target, name, sc_list_symbols);
919 for (const SymbolContext &sc : sc_list_symbols) {
920 if (sc.symbol && sc.symbol->ValueIsAddress()) {
921 const Address &base_address = sc.symbol->GetAddressRef();
922 Function *function = base_address.CalculateSymbolContextFunction();
923 if (function) {
924 sc_list.Append(SymbolContext(function));
925 break;
926 }
927 }
928 }
929 }
930
931 if (sc_list.GetSize() == 0) {
932 result.AppendErrorWithFormat("Could not find function named: \"%s\"",
933 m_options.symbol_name.c_str());
934 return;
935 }
936
937 std::set<SourceInfo> source_match_set;
938 bool displayed_something = false;
939 for (const SymbolContext &sc : sc_list) {
940 SourceInfo source_info(sc.GetFunctionName(),
941 sc.GetFunctionStartLineEntry());
942 if (source_info.IsValid() &&
943 source_match_set.find(source_info) == source_match_set.end()) {
944 source_match_set.insert(source_info);
945 if (DisplayFunctionSource(sc, source_info, result))
946 displayed_something = true;
947 }
948 }
949 if (displayed_something)
951 else
953 return;
954 } else if (m_options.address != LLDB_INVALID_ADDRESS) {
955 Address so_addr;
956 StreamString error_strm;
957 SymbolContextList sc_list;
958
959 if (!target->HasLoadedSections()) {
960 // The target isn't loaded yet, we need to lookup the file address in
961 // all modules
962 const ModuleList &module_list = target->GetImages();
963 const size_t num_modules = module_list.GetSize();
964 for (size_t i = 0; i < num_modules; ++i) {
965 ModuleSP module_sp(module_list.GetModuleAtIndex(i));
966 if (module_sp &&
967 module_sp->ResolveFileAddress(m_options.address, so_addr)) {
968 SymbolContext sc;
969 sc.Clear(true);
970 if (module_sp->ResolveSymbolContextForAddress(
971 so_addr, eSymbolContextEverything, sc) &
972 eSymbolContextLineEntry)
973 sc_list.Append(sc);
974 }
975 }
976
977 if (sc_list.GetSize() == 0) {
979 "no modules have source information for file address 0x%" PRIx64,
980 m_options.address);
981 return;
982 }
983 } else {
984 // The target has some things loaded, resolve this address to a compile
985 // unit + file + line and display
986 if (target->ResolveLoadAddress(m_options.address, so_addr)) {
987 ModuleSP module_sp(so_addr.GetModule());
988 if (module_sp) {
989 SymbolContext sc;
990 sc.Clear(true);
991 if (module_sp->ResolveSymbolContextForAddress(
992 so_addr, eSymbolContextEverything, sc) &
993 eSymbolContextLineEntry) {
994 sc_list.Append(sc);
995 } else {
996 so_addr.Dump(&error_strm, nullptr,
998 result.AppendErrorWithFormat("address resolves to %s, but there "
999 "is no line table information "
1000 "available for this address",
1001 error_strm.GetData());
1002 return;
1003 }
1004 }
1005 }
1006
1007 if (sc_list.GetSize() == 0) {
1008 result.AppendErrorWithFormat(
1009 "no modules contain load address 0x%" PRIx64, 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(), sc.line_entry.line, column,
1049 lines_to_back_up, m_options.num_lines - lines_to_back_up, "->",
1052 }
1053 }
1054 } else if (m_options.file_name.empty()) {
1055 // Last valid source manager context, or the current frame if no valid
1056 // last context in source manager. One little trick here, if you type the
1057 // exact same list command twice in a row, it is more likely because you
1058 // typed it once, then typed it again
1059 if (m_options.start_line == 0) {
1061 &result.GetOutputStream(), m_options.num_lines,
1062 m_options.reverse, GetBreakpointLocations())) {
1064 } else {
1065 if (target->GetSourceManager().AtLastLine(m_options.reverse)) {
1066 result.AppendNoteWithFormatv(
1067 "Reached {0} of the file, no more to page",
1068 m_options.reverse ? "beginning" : "end");
1069 } else {
1070 result.AppendNote("no source available");
1071 }
1072 }
1073
1074 } else {
1075 if (m_options.num_lines == 0)
1076 m_options.num_lines = 10;
1077
1078 if (m_options.show_bp_locs) {
1079 SourceManager::FileSP last_file_sp(
1080 target->GetSourceManager().GetLastFile());
1081 if (last_file_sp) {
1082 const bool show_inlines = true;
1084 last_file_sp->GetSupportFile()->GetSpecOnly(), 0, show_inlines);
1085 SearchFilterForUnconstrainedSearches target_search_filter(
1086 target->shared_from_this());
1087 target_search_filter.Search(m_breakpoint_locations);
1088 }
1089 } else
1090 m_breakpoint_locations.Clear();
1091
1092 const uint32_t column = 0;
1093 if (target->GetSourceManager()
1095 m_options.start_line, // Line to display
1096 m_options.num_lines, // Lines after line to
1097 UINT32_MAX, // Don't mark "line"
1098 column,
1099 "", // Don't mark "line"
1102 }
1103 }
1104 } else {
1105 // const char *filename = m_options.file_name.c_str();
1106 FileSpec file_spec(m_options.file_name);
1107 bool check_inlines = false;
1108 const InlineStrategy inline_strategy = target->GetInlineStrategy();
1109 if (inline_strategy == eInlineBreakpointsAlways ||
1110 (inline_strategy == eInlineBreakpointsHeaders &&
1111 !file_spec.IsSourceImplementationFile()))
1112 check_inlines = true;
1113
1114 SymbolContextList sc_list;
1115 size_t num_matches = 0;
1116
1117 if (!m_options.modules.empty()) {
1118 ModuleList matching_modules;
1119 for (size_t i = 0, e = m_options.modules.size(); i < e; ++i) {
1120 FileSpec module_file_spec(m_options.modules[i]);
1121 if (module_file_spec) {
1122 ModuleSpec module_spec(module_file_spec);
1123 matching_modules.Clear();
1124 target->GetImages().FindModules(module_spec, matching_modules);
1125 num_matches += matching_modules.ResolveSymbolContextsForFileSpec(
1126 file_spec, 1, check_inlines,
1127 SymbolContextItem(eSymbolContextModule |
1128 eSymbolContextCompUnit |
1129 eSymbolContextLineEntry),
1130 sc_list);
1131 }
1132 }
1133 } else {
1134 num_matches = target->GetImages().ResolveSymbolContextsForFileSpec(
1135 file_spec, 1, check_inlines,
1136 eSymbolContextModule | eSymbolContextCompUnit |
1137 eSymbolContextLineEntry,
1138 sc_list);
1139 }
1140
1141 if (num_matches == 0) {
1142 result.AppendErrorWithFormat("Could not find source file \"%s\"",
1143 m_options.file_name.c_str());
1144 return;
1145 }
1146
1147 if (num_matches > 1) {
1148 bool got_multiple = false;
1149 CompileUnit *test_cu = nullptr;
1150
1151 for (const SymbolContext &sc : sc_list) {
1152 if (sc.comp_unit) {
1153 if (test_cu) {
1154 if (test_cu != sc.comp_unit)
1155 got_multiple = true;
1156 break;
1157 } else
1158 test_cu = sc.comp_unit;
1159 }
1160 }
1161 if (got_multiple) {
1162 result.AppendErrorWithFormat(
1163 "Multiple source files found matching: \"%s.\"",
1164 m_options.file_name.c_str());
1165 return;
1166 }
1167 }
1168
1169 SymbolContext sc;
1170 if (sc_list.GetContextAtIndex(0, sc)) {
1171 if (sc.comp_unit) {
1172 if (m_options.show_bp_locs) {
1173 const bool show_inlines = true;
1175 show_inlines);
1176 SearchFilterForUnconstrainedSearches target_search_filter(
1177 target->shared_from_this());
1178 target_search_filter.Search(m_breakpoint_locations);
1179 } else
1180 m_breakpoint_locations.Clear();
1181
1182 if (m_options.num_lines == 0)
1183 m_options.num_lines = 10;
1184 const uint32_t column = 0;
1185
1186 // Headers aren't always in the DWARF but if they have
1187 // executable code (eg., inlined-functions) then the callsite's
1188 // file(s) will be found and assigned to
1189 // sc.comp_unit->GetPrimarySupportFile, which is NOT what we want to
1190 // print. Instead, we want to print the one from the line entry.
1191 SupportFileNSP found_file_sp = sc.line_entry.file_sp;
1192
1194 found_file_sp, m_options.start_line, column, 0,
1195 m_options.num_lines, "", &result.GetOutputStream(),
1197
1199 } else {
1200 result.AppendErrorWithFormat("No comp unit found for: \"%s.\"",
1201 m_options.file_name.c_str());
1202 }
1203 }
1204 }
1205 if (result.GetStatus() != eReturnStatusFailed)
1207 }
1208
1210 if (m_breakpoint_locations.GetFileLineMatches().GetSize() > 0)
1211 return &m_breakpoint_locations.GetFileLineMatches();
1212 return nullptr;
1213 }
1214
1217 std::string m_reverse_name;
1218};
1219
1221public:
1223 : CommandObjectParsed(interpreter, "source cache dump",
1224 "Dump the state of the source code cache. Intended "
1225 "to be used for debugging LLDB itself.",
1226 nullptr) {}
1227
1228 ~CommandObjectSourceCacheDump() override = default;
1229
1230protected:
1231 void DoExecute(Args &command, CommandReturnObject &result) override {
1232 // Dump the debugger source cache.
1233 result.GetOutputStream() << "Debugger Source File Cache\n";
1235 cache.Dump(result.GetOutputStream());
1236
1237 // Dump the process source cache.
1238 if (ProcessSP process_sp = m_exe_ctx.GetProcessSP()) {
1239 result.GetOutputStream() << "\nProcess Source File Cache\n";
1240 SourceManager::SourceFileCache &cache = process_sp->GetSourceFileCache();
1241 cache.Dump(result.GetOutputStream());
1242 }
1243
1245 }
1246};
1247
1249public:
1251 : CommandObjectParsed(interpreter, "source cache clear",
1252 "Clear the source code cache.\n", nullptr) {}
1253
1255
1256protected:
1257 void DoExecute(Args &command, CommandReturnObject &result) override {
1258 // Clear the debugger cache.
1260 cache.Clear();
1261
1262 // Clear the process cache.
1263 if (ProcessSP process_sp = m_exe_ctx.GetProcessSP())
1264 process_sp->GetSourceFileCache().Clear();
1265
1267 }
1268};
1269
1271public:
1273 : CommandObjectMultiword(interpreter, "source cache",
1274 "Commands for managing the source code cache.",
1275 "source cache <sub-command>") {
1277 "dump", CommandObjectSP(new CommandObjectSourceCacheDump(interpreter)));
1279 interpreter)));
1280 }
1281
1282 ~CommandObjectSourceCache() override = default;
1283
1284private:
1288};
1289
1290#pragma mark CommandObjectMultiwordSource
1291// CommandObjectMultiwordSource
1292
1294 CommandInterpreter &interpreter)
1295 : CommandObjectMultiword(interpreter, "source",
1296 "Commands for examining "
1297 "source code described by "
1298 "debug information for the "
1299 "current target process.",
1300 "source <subcommand> [<subcommand-options>]") {
1301 LoadSubCommand("info",
1302 CommandObjectSP(new CommandObjectSourceInfo(interpreter)));
1303 LoadSubCommand("list",
1304 CommandObjectSP(new CommandObjectSourceList(interpreter)));
1305 LoadSubCommand("cache",
1306 CommandObjectSP(new CommandObjectSourceCache(interpreter)));
1307}
1308
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:690
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)
Target * GetTarget()
Get the target this command should operate on.
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:639
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:392
llvm::Expected< std::pair< SupportFileNSP, SourceRange > > GetSourceInfo()
Find the file and line number range of the function.
Definition Function.cpp:309
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:91
lldb::CompUnitSP GetCompileUnitAtIndex(size_t idx)
Definition Module.cpp:413
size_t GetNumCompileUnits()
Get the number of compile units for this module.
Definition Module.cpp:407
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:134
size_t EOL()
Output and End of Line character to the stream.
Definition Stream.cpp:155
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:5289
SourceManager & GetSourceManager()
Definition Target.cpp:3110
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, uint32_t stop_id=SectionLoadHistory::eStopIDNow, bool allow_section_end=false)
Definition Target.cpp:3448
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition Target.h:1241
const ArchSpec & GetArchitecture() const
Definition Target.h:1283
#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:56
@ eInlineBreakpointsHeaders
Definition Target.h:55
@ 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:67
bool include_inlines
Include inlined functions.
Definition Module.h:71
bool include_symbols
Include the symbol table.
Definition Module.h:69
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.