LLDB mainline
CommandObjectTarget.cpp
Go to the documentation of this file.
1//===-- CommandObjectTarget.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/Address.h"
12#include "lldb/Core/Debugger.h"
13#include "lldb/Core/IOHandler.h"
14#include "lldb/Core/Module.h"
17#include "lldb/Core/Section.h"
43#include "lldb/Target/ABI.h"
44#include "lldb/Target/Process.h"
48#include "lldb/Target/Thread.h"
50#include "lldb/Utility/Args.h"
55#include "lldb/Utility/State.h"
56#include "lldb/Utility/Stream.h"
58#include "lldb/Utility/Timer.h"
61#include "lldb/lldb-forward.h"
63
64#include "clang/Driver/CreateInvocationFromArgs.h"
65#include "clang/Frontend/CompilerInstance.h"
66#include "clang/Frontend/CompilerInvocation.h"
67#include "clang/Frontend/FrontendActions.h"
68#include "clang/Serialization/ObjectFilePCHContainerReader.h"
69#include "llvm/ADT/ScopeExit.h"
70#include "llvm/ADT/StringRef.h"
71#include "llvm/Support/FileSystem.h"
72#include "llvm/Support/FormatAdapters.h"
73
74
75using namespace lldb;
76using namespace lldb_private;
77
78static void DumpTargetInfo(uint32_t target_idx, Target *target,
79 const char *prefix_cstr,
80 bool show_stopped_process_status, Stream &strm) {
81 const ArchSpec &target_arch = target->GetArchitecture();
82
83 Module *exe_module = target->GetExecutableModulePointer();
84 char exe_path[PATH_MAX];
85 bool exe_valid = false;
86 if (exe_module)
87 exe_valid = exe_module->GetFileSpec().GetPath(exe_path, sizeof(exe_path));
88
89 if (!exe_valid)
90 ::strcpy(exe_path, "<none>");
91
92 std::string formatted_label = "";
93 const std::string &label = target->GetLabel();
94 if (!label.empty()) {
95 formatted_label = " (" + label + ")";
96 }
97
98 strm.Printf("%starget #%u%s: %s", prefix_cstr ? prefix_cstr : "", target_idx,
99 formatted_label.data(), exe_path);
100
101 uint32_t properties = 0;
102 if (target_arch.IsValid()) {
103 strm.Printf(" ( arch=");
104 target_arch.DumpTriple(strm.AsRawOstream());
105 properties++;
106 }
107 PlatformSP platform_sp(target->GetPlatform());
108 if (platform_sp)
109 strm.Format("{0}platform={1}", properties++ > 0 ? ", " : " ( ",
110 platform_sp->GetName());
111
112 ProcessSP process_sp(target->GetProcessSP());
113 bool show_process_status = false;
114 if (process_sp) {
115 lldb::pid_t pid = process_sp->GetID();
116 StateType state = process_sp->GetState();
117 if (show_stopped_process_status)
118 show_process_status = StateIsStoppedState(state, true);
119 const char *state_cstr = StateAsCString(state);
120 if (pid != LLDB_INVALID_PROCESS_ID)
121 strm.Printf("%spid=%" PRIu64, properties++ > 0 ? ", " : " ( ", pid);
122 strm.Printf("%sstate=%s", properties++ > 0 ? ", " : " ( ", state_cstr);
123 }
124 if (properties > 0)
125 strm.PutCString(" )\n");
126 else
127 strm.EOL();
128 if (show_process_status) {
129 const bool only_threads_with_stop_reason = true;
130 const uint32_t start_frame = 0;
131 const uint32_t num_frames = 1;
132 const uint32_t num_frames_with_source = 1;
133 const bool stop_format = false;
134 process_sp->GetStatus(strm);
135 process_sp->GetThreadStatus(strm, only_threads_with_stop_reason,
136 start_frame, num_frames, num_frames_with_source,
137 stop_format);
138 }
139}
140
141static uint32_t DumpTargetList(TargetList &target_list,
142 bool show_stopped_process_status, Stream &strm) {
143 const uint32_t num_targets = target_list.GetNumTargets();
144 if (num_targets) {
145 TargetSP selected_target_sp(target_list.GetSelectedTarget());
146 strm.PutCString("Current targets:\n");
147 for (uint32_t i = 0; i < num_targets; ++i) {
148 TargetSP target_sp(target_list.GetTargetAtIndex(i));
149 if (target_sp) {
150 bool is_selected = target_sp.get() == selected_target_sp.get();
151 DumpTargetInfo(i, target_sp.get(), is_selected ? "* " : " ",
152 show_stopped_process_status, strm);
153 }
154 }
155 }
156 return num_targets;
157}
158
159#define LLDB_OPTIONS_target_dependents
160#include "CommandOptions.inc"
161
163public:
165
166 ~OptionGroupDependents() override = default;
167
168 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
169 return llvm::ArrayRef(g_target_dependents_options);
170 }
171
172 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_value,
173 ExecutionContext *execution_context) override {
175
176 // For compatibility no value means don't load dependents.
177 if (option_value.empty()) {
179 return error;
180 }
181
182 const char short_option =
183 g_target_dependents_options[option_idx].short_option;
184 if (short_option == 'd') {
185 LoadDependentFiles tmp_load_dependents;
187 option_value, g_target_dependents_options[option_idx].enum_values, 0,
188 error);
189 if (error.Success())
190 m_load_dependent_files = tmp_load_dependents;
191 } else {
193 "unrecognized short option '%c'", short_option);
194 }
195
196 return error;
197 }
198
199 Status SetOptionValue(uint32_t, const char *, ExecutionContext *) = delete;
200
204
206
207private:
211};
212
213#pragma mark CommandObjectTargetCreate
214
216public:
219 interpreter, "target create",
220 "Create a target using the argument as the main executable.",
221 nullptr),
222 m_platform_options(true), // Include the --platform option.
223 m_core_file(LLDB_OPT_SET_1, false, "core", 'c', 0, eArgTypeFilename,
224 "Fullpath to a core file to use for this target."),
225 m_label(LLDB_OPT_SET_1, false, "label", 'l', 0, eArgTypeName,
226 "Optional name for this target.", nullptr),
227 m_symbol_file(LLDB_OPT_SET_1, false, "symfile", 's', 0,
229 "Fullpath to a stand alone debug "
230 "symbols file for when debug symbols "
231 "are not in the executable."),
233 LLDB_OPT_SET_1, false, "remote-file", 'r', 0, eArgTypeFilename,
234 "Fullpath to the file on the remote host if debugging remotely.") {
235
237
245 m_option_group.Finalize();
246 }
247
248 ~CommandObjectTargetCreate() override = default;
249
250 Options *GetOptions() override { return &m_option_group; }
251
252protected:
253 void DoExecute(Args &command, CommandReturnObject &result) override {
254 const size_t argc = command.GetArgumentCount();
255 FileSpec core_file(m_core_file.GetOptionValue().GetCurrentValue());
256 FileSpec remote_file(m_remote_file.GetOptionValue().GetCurrentValue());
257
258 if (core_file) {
259 auto file = FileSystem::Instance().Open(
261
262 if (!file) {
263 result.AppendErrorWithFormatv("Cannot open '{0}': {1}.",
264 core_file.GetPath(),
265 llvm::toString(file.takeError()));
266 return;
267 }
268 }
269
270 if (argc == 1 || core_file || remote_file) {
271 FileSpec symfile(m_symbol_file.GetOptionValue().GetCurrentValue());
272 if (symfile) {
273 auto file = FileSystem::Instance().Open(
275
276 if (!file) {
277 result.AppendErrorWithFormatv("Cannot open '{0}': {1}.",
278 symfile.GetPath(),
279 llvm::toString(file.takeError()));
280 return;
281 }
282 }
283
284 const char *file_path = command.GetArgumentAtIndex(0);
285 LLDB_SCOPED_TIMERF("(lldb) target create '%s'", file_path);
286
287 bool must_set_platform_path = false;
288
289 Debugger &debugger = GetDebugger();
290
291 TargetSP target_sp;
292 llvm::StringRef arch_cstr = m_arch_option.GetArchitectureName();
294 debugger, file_path, arch_cstr,
295 m_add_dependents.m_load_dependent_files, &m_platform_options,
296 target_sp));
297
298 if (!target_sp) {
299 result.AppendError(error.AsCString());
300 return;
301 }
302
303 const llvm::StringRef label =
304 m_label.GetOptionValue().GetCurrentValueAsRef();
305 if (!label.empty()) {
306 if (auto E = target_sp->SetLabel(label))
307 result.SetError(std::move(E));
308 return;
309 }
310
311 llvm::scope_exit on_error(
312 [&target_list = debugger.GetTargetList(), &target_sp]() {
313 target_list.DeleteTarget(target_sp);
314 });
315
316 // Only get the platform after we create the target because we might
317 // have switched platforms depending on what the arguments were to
318 // CreateTarget() we can't rely on the selected platform.
319
320 PlatformSP platform_sp = target_sp->GetPlatform();
321
322 FileSpec file_spec;
323 if (file_path) {
324 file_spec.SetFile(file_path, FileSpec::Style::native);
325 FileSystem::Instance().Resolve(file_spec);
326
327 // Try to resolve the exe based on PATH and/or platform-specific
328 // suffixes, but only if using the host platform.
329 if (platform_sp && platform_sp->IsHost() &&
330 !FileSystem::Instance().Exists(file_spec))
332 }
333
334 if (remote_file) {
335 if (platform_sp) {
336 // I have a remote file.. two possible cases
337 if (file_spec && FileSystem::Instance().Exists(file_spec)) {
338 // if the remote file does not exist, push it there
339 if (!platform_sp->GetFileExists(remote_file)) {
340 Status err = platform_sp->PutFile(file_spec, remote_file);
341 if (err.Fail()) {
342 result.AppendError(err.AsCString());
343 return;
344 }
345 }
346 } else {
347 // there is no local file and we need one
348 // in order to make the remote ---> local transfer we need a
349 // platform
350 // TODO: if the user has passed in a --platform argument, use it
351 // to fetch the right platform
352 if (file_path) {
353 // copy the remote file to the local file
354 Status err = platform_sp->GetFile(remote_file, file_spec);
355 if (err.Fail()) {
356 result.AppendError(err.AsCString());
357 return;
358 }
359 } else {
360 // If the remote file exists, we can debug reading that out of
361 // memory. If the platform is already connected to an lldb-server
362 // then we can at least check the file exists remotely. Otherwise
363 // we'll just have to trust that it will be there when we do
364 // process connect.
365 // I don't do this for the host platform because it seems odd to
366 // support supplying a remote file but no local file for a local
367 // debug session.
368 if (platform_sp->IsHost()) {
369 result.AppendError("Supply a local file, not a remote file, "
370 "when debugging on the host.");
371 return;
372 }
373 if (platform_sp->IsConnected() && !platform_sp->GetFileExists(remote_file)) {
374 result.AppendError("remote --> local transfer without local "
375 "path is not implemented yet");
376 return;
377 }
378 // Since there's only a remote file, we need to set the executable
379 // file spec to the remote one.
380 ProcessLaunchInfo launch_info = target_sp->GetProcessLaunchInfo();
381 launch_info.SetExecutableFile(FileSpec(remote_file), true);
382 target_sp->SetProcessLaunchInfo(launch_info);
383 }
384 }
385 } else {
386 result.AppendError("no platform found for target");
387 return;
388 }
389 }
390
391 if (symfile || remote_file) {
392 ModuleSP module_sp(target_sp->GetExecutableModule());
393 if (module_sp) {
394 if (symfile)
395 module_sp->SetSymbolFileFileSpec(symfile);
396 if (remote_file) {
397 std::string remote_path = remote_file.GetPath();
398 target_sp->SetArg0(remote_path.c_str());
399 module_sp->SetPlatformFileSpec(remote_file);
400 }
401 }
402 }
403
404 if (must_set_platform_path) {
405 ModuleSpec main_module_spec(file_spec);
406 ModuleSP module_sp =
407 target_sp->GetOrCreateModule(main_module_spec, true /* notify */);
408 if (module_sp)
409 module_sp->SetPlatformFileSpec(remote_file);
410 }
411
412 if (core_file) {
413 FileSpec core_file_dir;
414 core_file_dir.SetDirectory(core_file.GetDirectory());
415 target_sp->AppendExecutableSearchPaths(core_file_dir);
416
417 ProcessSP process_sp(target_sp->CreateProcess(
418 GetDebugger().GetListener(), llvm::StringRef(), &core_file, false));
419
420 if (process_sp) {
421 // Seems weird that we Launch a core file, but that is what we
422 // do!
423 {
424 ElapsedTime load_core_time(
425 target_sp->GetStatistics().GetLoadCoreTime());
426 error = process_sp->LoadCore();
427 }
428
429 if (error.Fail()) {
430 result.AppendError(error.AsCString("unknown core file format"));
431 return;
432 } else {
434 "Core file '{0}' ({1}) was loaded.\n", core_file.GetPath(),
435 target_sp->GetArchitecture().GetArchitectureName());
437 on_error.release();
438 }
439 } else {
440 result.AppendErrorWithFormatv("Unknown core file format '{0}'\n",
441 core_file.GetPath());
442 }
443 } else {
445 "Current executable set to '{0}' ({1}).",
446 file_spec.GetPath().c_str(),
447 target_sp->GetArchitecture().GetArchitectureName());
449 on_error.release();
450 }
451 } else {
452 result.AppendErrorWithFormat("'%s' takes exactly one executable path "
453 "argument, or use the --core option.\n",
454 m_cmd_name.c_str());
455 }
456 }
457
458private:
467};
468
469#pragma mark CommandObjectTargetList
470
472public:
475 interpreter, "target list",
476 "List all current targets in the current debug session.", nullptr) {
477 }
478
479 ~CommandObjectTargetList() override = default;
480
481protected:
482 void DoExecute(Args &args, CommandReturnObject &result) override {
483 Stream &strm = result.GetOutputStream();
484
485 bool show_stopped_process_status = false;
486 if (DumpTargetList(GetDebugger().GetTargetList(),
487 show_stopped_process_status, strm) == 0) {
488 strm.PutCString("No targets.\n");
489 }
491 }
492};
493
494#pragma mark CommandObjectTargetSelect
495
497public:
500 interpreter, "target select",
501 "Select a target as the current target by target index.", nullptr) {
503 }
504
505 ~CommandObjectTargetSelect() override = default;
506
507protected:
508 void DoExecute(Args &args, CommandReturnObject &result) override {
509 if (args.GetArgumentCount() == 1) {
510 const char *target_identifier = args.GetArgumentAtIndex(0);
511 uint32_t target_idx = LLDB_INVALID_INDEX32;
512 TargetList &target_list = GetDebugger().GetTargetList();
513 const uint32_t num_targets = target_list.GetNumTargets();
514 if (llvm::to_integer(target_identifier, target_idx)) {
515 if (target_idx < num_targets) {
516 target_list.SetSelectedTarget(target_idx);
517 Stream &strm = result.GetOutputStream();
518 bool show_stopped_process_status = false;
519 DumpTargetList(target_list, show_stopped_process_status, strm);
521 } else {
522 if (num_targets > 0) {
524 "index %u is out of range, valid target indexes are 0 - %u\n",
525 target_idx, num_targets - 1);
526 } else {
528 "index %u is out of range since there are no active targets\n",
529 target_idx);
530 }
531 }
532 } else {
533 for (size_t i = 0; i < num_targets; i++) {
534 if (TargetSP target_sp = target_list.GetTargetAtIndex(i)) {
535 const std::string &label = target_sp->GetLabel();
536 if (!label.empty() && label == target_identifier) {
537 target_idx = i;
538 break;
539 }
540 }
541 }
542
543 if (target_idx != LLDB_INVALID_INDEX32) {
544 target_list.SetSelectedTarget(target_idx);
545 Stream &strm = result.GetOutputStream();
546 bool show_stopped_process_status = false;
547 DumpTargetList(target_list, show_stopped_process_status, strm);
549 } else {
550 result.AppendErrorWithFormat("invalid index string value '%s'\n",
551 target_identifier);
552 }
553 }
554 } else {
555 result.AppendError(
556 "'target select' takes a single argument: a target index\n");
557 }
558 }
559};
560
561#pragma mark CommandObjectTargetDelete
562
564public:
566 : CommandObjectParsed(interpreter, "target delete",
567 "Delete one or more targets by target index.",
568 nullptr),
569 m_all_option(LLDB_OPT_SET_1, false, "all", 'a', "Delete all targets.",
570 false, true),
572 LLDB_OPT_SET_1, false, "clean", 'c',
573 "Perform extra cleanup to minimize memory consumption after "
574 "deleting the target. "
575 "By default, LLDB will keep in memory any modules previously "
576 "loaded by the target as well "
577 "as all of its debug info. Specifying --clean will unload all of "
578 "these shared modules and "
579 "cause them to be reparsed again the next time the target is run",
580 false, true) {
583 m_option_group.Finalize();
585 }
586
587 ~CommandObjectTargetDelete() override = default;
588
589 Options *GetOptions() override { return &m_option_group; }
590
591protected:
592 void DoExecute(Args &args, CommandReturnObject &result) override {
593 const size_t argc = args.GetArgumentCount();
594 std::vector<TargetSP> delete_target_list;
595 TargetList &target_list = GetDebugger().GetTargetList();
596 TargetSP target_sp;
597
598 if (m_all_option.GetOptionValue()) {
599 for (size_t i = 0; i < target_list.GetNumTargets(); ++i)
600 delete_target_list.push_back(target_list.GetTargetAtIndex(i));
601 } else if (argc > 0) {
602 const uint32_t num_targets = target_list.GetNumTargets();
603 // Bail out if don't have any targets.
604 if (num_targets == 0) {
605 result.AppendError("no targets to delete");
606 return;
607 }
608
609 for (auto &entry : args.entries()) {
610 uint32_t target_idx;
611 if (entry.ref().getAsInteger(0, target_idx)) {
612 result.AppendErrorWithFormat("invalid target index '%s'\n",
613 entry.c_str());
614 return;
615 }
616 if (target_idx < num_targets) {
617 target_sp = target_list.GetTargetAtIndex(target_idx);
618 if (target_sp) {
619 delete_target_list.push_back(target_sp);
620 continue;
621 }
622 }
623 if (num_targets > 1)
624 result.AppendErrorWithFormat("target index %u is out of range, valid "
625 "target indexes are 0 - %u\n",
626 target_idx, num_targets - 1);
627 else
629 "target index %u is out of range, the only valid index is 0\n",
630 target_idx);
631
632 return;
633 }
634 } else {
635 target_sp = target_list.GetSelectedTarget();
636 if (!target_sp) {
637 result.AppendErrorWithFormat("no target is currently selected\n");
638 return;
639 }
640 delete_target_list.push_back(target_sp);
641 }
642
643 const size_t num_targets_to_delete = delete_target_list.size();
644 for (size_t idx = 0; idx < num_targets_to_delete; ++idx) {
645 target_sp = delete_target_list[idx];
646 target_list.DeleteTarget(target_sp);
647 target_sp->Destroy();
648 }
649 // If "--clean" was specified, prune any orphaned shared modules from the
650 // global shared module list
651 if (m_cleanup_option.GetOptionValue()) {
652 const bool mandatory = true;
654 }
655 result.GetOutputStream().Printf("%u targets deleted.\n",
656 (uint32_t)num_targets_to_delete);
658 }
659
663};
664
666public:
669 interpreter, "target show-launch-environment",
670 "Shows the environment being passed to the process when launched, "
671 "taking info account 3 settings: target.env-vars, "
672 "target.inherit-env and target.unset-env-vars.",
673 nullptr, eCommandRequiresTarget) {}
674
676
677protected:
678 void DoExecute(Args &args, CommandReturnObject &result) override {
679 Target *target = m_exe_ctx.GetTargetPtr();
680 Environment env = target->GetEnvironment();
681
682 std::vector<Environment::value_type *> env_vector;
683 env_vector.reserve(env.size());
684 for (auto &KV : env)
685 env_vector.push_back(&KV);
686 std::sort(env_vector.begin(), env_vector.end(),
687 [](Environment::value_type *a, Environment::value_type *b) {
688 return a->first() < b->first();
689 });
690
691 auto &strm = result.GetOutputStream();
692 for (auto &KV : env_vector)
693 strm.Format("{0}={1}\n", KV->first(), KV->second);
694
696 }
697};
698
699#pragma mark CommandObjectTargetVariable
700
702 static const uint32_t SHORT_OPTION_FILE = 0x66696c65; // 'file'
703 static const uint32_t SHORT_OPTION_SHLB = 0x73686c62; // 'shlb'
704
705public:
707 : CommandObjectParsed(interpreter, "target variable",
708 "Read global variables for the current target, "
709 "before or while running a process.",
710 nullptr, eCommandRequiresTarget),
711 m_option_variable(false), // Don't include frame options
715 "A basename or fullpath to a file that contains "
716 "global variables. This option can be "
717 "specified multiple times."),
719 LLDB_OPT_SET_1, false, "shlib", SHORT_OPTION_SHLB, 0,
721 "A basename or fullpath to a shared library to use in the search "
722 "for global "
723 "variables. This option can be specified multiple times.") {
725
736 m_option_group.Finalize();
737 }
738
739 ~CommandObjectTargetVariable() override = default;
740
741 void DumpValueObject(Stream &s, VariableSP &var_sp, ValueObjectSP &valobj_sp,
742 const char *root_name) {
743 DumpValueObjectOptions options(m_varobj_options.GetAsDumpOptions());
744
745 if (!valobj_sp->GetTargetSP()->GetDisplayRuntimeSupportValues() &&
746 valobj_sp->IsRuntimeSupportValue())
747 return;
748
749 switch (var_sp->GetScope()) {
751 if (m_option_variable.show_scope)
752 s.PutCString("GLOBAL: ");
753 break;
754
756 if (m_option_variable.show_scope)
757 s.PutCString("STATIC: ");
758 break;
759
761 if (m_option_variable.show_scope)
762 s.PutCString(" ARG: ");
763 break;
764
766 if (m_option_variable.show_scope)
767 s.PutCString(" LOCAL: ");
768 break;
769
771 if (m_option_variable.show_scope)
772 s.PutCString("THREAD: ");
773 break;
774
775 default:
776 break;
777 }
778
779 if (m_option_variable.show_decl) {
780 bool show_fullpaths = false;
781 bool show_module = true;
782 if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module))
783 s.PutCString(": ");
784 }
785
786 const Format format = m_option_format.GetFormat();
787 if (format != eFormatDefault)
788 options.SetFormat(format);
789
790 options.SetRootValueObjectName(root_name);
791
792 if (llvm::Error error = valobj_sp->Dump(s, options))
793 s << "error: " << toString(std::move(error));
794 }
795
796 static size_t GetVariableCallback(void *baton, const char *name,
797 VariableList &variable_list) {
798 size_t old_size = variable_list.GetSize();
799 Target *target = static_cast<Target *>(baton);
800 if (target)
802 variable_list);
803 return variable_list.GetSize() - old_size;
804 }
805
806 Options *GetOptions() override { return &m_option_group; }
807
808protected:
810 const SymbolContext &sc,
811 const VariableList &variable_list,
812 CommandReturnObject &result) {
813 Stream &s = result.GetOutputStream();
814 if (variable_list.Empty())
815 return;
816 if (sc.module_sp) {
817 if (sc.comp_unit) {
818 s.Format("Global variables for {0} in {1}:\n",
819 sc.comp_unit->GetPrimaryFile(), sc.module_sp->GetFileSpec());
820 } else {
821 s.Printf("Global variables for %s\n",
822 sc.module_sp->GetFileSpec().GetPath().c_str());
823 }
824 } else if (sc.comp_unit) {
825 s.Format("Global variables for {0}\n", sc.comp_unit->GetPrimaryFile());
826 }
827
828 for (VariableSP var_sp : variable_list) {
829 if (!var_sp)
830 continue;
832 exe_ctx.GetBestExecutionContextScope(), var_sp));
833
834 if (valobj_sp) {
835 result.GetValueObjectList().Append(valobj_sp);
836 DumpValueObject(s, var_sp, valobj_sp, var_sp->GetName().GetCString());
837 }
838 }
839 }
840
841 void DoExecute(Args &args, CommandReturnObject &result) override {
842 Target *target = m_exe_ctx.GetTargetPtr();
843 const size_t argc = args.GetArgumentCount();
844
845 if (argc > 0) {
846 for (const Args::ArgEntry &arg : args) {
847 VariableList variable_list;
848 ValueObjectList valobj_list;
849
850 size_t matches = 0;
851 bool use_var_name = false;
852 if (m_option_variable.use_regex) {
853 RegularExpression regex(arg.ref());
854 if (!regex.IsValid()) {
855 result.GetErrorStream().Printf(
856 "error: invalid regular expression: '%s'\n", arg.c_str());
857 return;
858 }
859 use_var_name = true;
861 variable_list);
862 matches = variable_list.GetSize();
863 } else {
865 arg.c_str(), m_exe_ctx.GetBestExecutionContextScope(),
866 GetVariableCallback, target, variable_list, valobj_list));
867 matches = variable_list.GetSize();
868 }
869
870 if (matches == 0) {
871 result.AppendErrorWithFormat("can't find global variable '%s'",
872 arg.c_str());
873 return;
874 } else {
875 for (uint32_t global_idx = 0; global_idx < matches; ++global_idx) {
876 VariableSP var_sp(variable_list.GetVariableAtIndex(global_idx));
877 if (var_sp) {
878 ValueObjectSP valobj_sp(
879 valobj_list.GetValueObjectAtIndex(global_idx));
880 if (!valobj_sp)
881 valobj_sp = ValueObjectVariable::Create(
882 m_exe_ctx.GetBestExecutionContextScope(), var_sp);
883
884 if (valobj_sp)
885 DumpValueObject(result.GetOutputStream(), var_sp, valobj_sp,
886 use_var_name ? var_sp->GetName().GetCString()
887 : arg.c_str());
888 }
889 }
890 }
891 }
892 } else {
893 const FileSpecList &compile_units =
894 m_option_compile_units.GetOptionValue().GetCurrentValue();
895 const FileSpecList &shlibs =
896 m_option_shared_libraries.GetOptionValue().GetCurrentValue();
897 SymbolContextList sc_list;
898 const size_t num_compile_units = compile_units.GetSize();
899 const size_t num_shlibs = shlibs.GetSize();
900 if (num_compile_units == 0 && num_shlibs == 0) {
901 bool success = false;
902 StackFrame *frame = m_exe_ctx.GetFramePtr();
903 CompileUnit *comp_unit = nullptr;
904 if (frame) {
905 SymbolContext sc = frame->GetSymbolContext(eSymbolContextCompUnit);
906 comp_unit = sc.comp_unit;
907 if (sc.comp_unit) {
908 const bool can_create = true;
909 VariableListSP comp_unit_varlist_sp(
910 sc.comp_unit->GetVariableList(can_create));
911 if (comp_unit_varlist_sp) {
912 size_t count = comp_unit_varlist_sp->GetSize();
913 if (count > 0) {
914 DumpGlobalVariableList(m_exe_ctx, sc, *comp_unit_varlist_sp,
915 result);
916 success = true;
917 }
918 }
919 }
920 }
921 if (!success) {
922 if (frame) {
923 if (comp_unit)
925 "no global variables in current compile unit: {0}\n",
926 comp_unit->GetPrimaryFile());
927 else
929 "no debug information for frame %u\n",
930 frame->GetFrameIndex());
931 } else
932 result.AppendError("'target variable' takes one or more global "
933 "variable names as arguments\n");
934 }
935 } else {
936 SymbolContextList sc_list;
937 // We have one or more compile unit or shlib
938 if (num_shlibs > 0) {
939 for (size_t shlib_idx = 0; shlib_idx < num_shlibs; ++shlib_idx) {
940 const FileSpec module_file(shlibs.GetFileSpecAtIndex(shlib_idx));
941 ModuleSpec module_spec(module_file);
942
943 ModuleSP module_sp(
944 target->GetImages().FindFirstModule(module_spec));
945 if (module_sp) {
946 if (num_compile_units > 0) {
947 for (size_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
948 module_sp->FindCompileUnits(
949 compile_units.GetFileSpecAtIndex(cu_idx), sc_list);
950 } else {
951 SymbolContext sc;
952 sc.module_sp = module_sp;
953 sc_list.Append(sc);
954 }
955 } else {
956 // Didn't find matching shlib/module in target...
958 "target doesn't contain the specified shared library: %s\n",
959 module_file.GetPath().c_str());
960 }
961 }
962 } else {
963 // No shared libraries, we just want to find globals for the compile
964 // units files that were specified
965 for (size_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
966 target->GetImages().FindCompileUnits(
967 compile_units.GetFileSpecAtIndex(cu_idx), sc_list);
968 }
969
970 for (const SymbolContext &sc : sc_list) {
971 if (sc.comp_unit) {
972 const bool can_create = true;
973 VariableListSP comp_unit_varlist_sp(
974 sc.comp_unit->GetVariableList(can_create));
975 if (comp_unit_varlist_sp)
976 DumpGlobalVariableList(m_exe_ctx, sc, *comp_unit_varlist_sp,
977 result);
978 } else if (sc.module_sp) {
979 // Get all global variables for this module
980 lldb_private::RegularExpression all_globals_regex(
981 llvm::StringRef(".")); // Any global with at least one character
982 VariableList variable_list;
983 sc.module_sp->FindGlobalVariables(all_globals_regex, UINT32_MAX,
984 variable_list);
985 DumpGlobalVariableList(m_exe_ctx, sc, variable_list, result);
986 }
987 }
988 }
989 }
990
991 m_interpreter.PrintWarningsIfNecessary(result.GetOutputStream(),
992 m_cmd_name);
993 }
994
1001};
1002
1003#pragma mark CommandObjectTargetModulesSearchPathsAdd
1004
1006public:
1008 : CommandObjectParsed(interpreter, "target modules search-paths add",
1009 "Add new image search paths substitution pairs to "
1010 "the current target.",
1011 nullptr, eCommandRequiresTarget) {
1013 CommandArgumentData old_prefix_arg;
1014 CommandArgumentData new_prefix_arg;
1015
1016 // Define the first variant of this arg pair.
1017 old_prefix_arg.arg_type = eArgTypeOldPathPrefix;
1018 old_prefix_arg.arg_repetition = eArgRepeatPairPlus;
1019
1020 // Define the first variant of this arg pair.
1021 new_prefix_arg.arg_type = eArgTypeNewPathPrefix;
1022 new_prefix_arg.arg_repetition = eArgRepeatPairPlus;
1023
1024 // There are two required arguments that must always occur together, i.e.
1025 // an argument "pair". Because they must always occur together, they are
1026 // treated as two variants of one argument rather than two independent
1027 // arguments. Push them both into the first argument position for
1028 // m_arguments...
1029
1030 arg.push_back(old_prefix_arg);
1031 arg.push_back(new_prefix_arg);
1032
1033 m_arguments.push_back(arg);
1034 }
1035
1037
1038protected:
1039 void DoExecute(Args &command, CommandReturnObject &result) override {
1040 Target &target = GetTarget();
1041 const size_t argc = command.GetArgumentCount();
1042 if (argc & 1) {
1043 result.AppendError("add requires an even number of arguments\n");
1044 } else {
1045 for (size_t i = 0; i < argc; i += 2) {
1046 const char *from = command.GetArgumentAtIndex(i);
1047 const char *to = command.GetArgumentAtIndex(i + 1);
1048
1049 if (from[0] && to[0]) {
1051 "target modules search path adding ImageSearchPath "
1052 "pair: '%s' -> '%s'",
1053 from, to);
1054 bool last_pair = ((argc - i) == 2);
1056 from, to, last_pair); // Notify if this is the last pair
1058 } else {
1059 if (from[0])
1060 result.AppendError("<path-prefix> can't be empty\n");
1061 else
1062 result.AppendError("<new-path-prefix> can't be empty\n");
1063 }
1064 }
1065 }
1066 }
1067};
1068
1069#pragma mark CommandObjectTargetModulesSearchPathsClear
1070
1072public:
1074 : CommandObjectParsed(interpreter, "target modules search-paths clear",
1075 "Clear all current image search path substitution "
1076 "pairs from the current target.",
1077 "target modules search-paths clear",
1078 eCommandRequiresTarget) {}
1079
1081
1082protected:
1083 void DoExecute(Args &command, CommandReturnObject &result) override {
1084 Target &target = GetTarget();
1085 bool notify = true;
1086 target.GetImageSearchPathList().Clear(notify);
1088 }
1089};
1090
1091#pragma mark CommandObjectTargetModulesSearchPathsInsert
1092
1094public:
1096 : CommandObjectParsed(interpreter, "target modules search-paths insert",
1097 "Insert a new image search path substitution pair "
1098 "into the current target at the specified index.",
1099 nullptr, eCommandRequiresTarget) {
1102 CommandArgumentData index_arg;
1103 CommandArgumentData old_prefix_arg;
1104 CommandArgumentData new_prefix_arg;
1105
1106 // Define the first and only variant of this arg.
1107 index_arg.arg_type = eArgTypeIndex;
1108 index_arg.arg_repetition = eArgRepeatPlain;
1109
1110 // Put the one and only variant into the first arg for m_arguments:
1111 arg1.push_back(index_arg);
1112
1113 // Define the first variant of this arg pair.
1114 old_prefix_arg.arg_type = eArgTypeOldPathPrefix;
1115 old_prefix_arg.arg_repetition = eArgRepeatPairPlus;
1116
1117 // Define the first variant of this arg pair.
1118 new_prefix_arg.arg_type = eArgTypeNewPathPrefix;
1119 new_prefix_arg.arg_repetition = eArgRepeatPairPlus;
1120
1121 // There are two required arguments that must always occur together, i.e.
1122 // an argument "pair". Because they must always occur together, they are
1123 // treated as two variants of one argument rather than two independent
1124 // arguments. Push them both into the same argument position for
1125 // m_arguments...
1126
1127 arg2.push_back(old_prefix_arg);
1128 arg2.push_back(new_prefix_arg);
1129
1130 // Add arguments to m_arguments.
1131 m_arguments.push_back(arg1);
1132 m_arguments.push_back(arg2);
1133 }
1134
1136
1137 void
1139 OptionElementVector &opt_element_vector) override {
1140 if (!m_exe_ctx.HasTargetScope() || request.GetCursorIndex() != 0)
1141 return;
1142
1143 Target *target = m_exe_ctx.GetTargetPtr();
1144 const PathMappingList &list = target->GetImageSearchPathList();
1145 const size_t num = list.GetSize();
1146 ConstString old_path, new_path;
1147 for (size_t i = 0; i < num; ++i) {
1148 if (!list.GetPathsAtIndex(i, old_path, new_path))
1149 break;
1150 StreamString strm;
1151 strm << old_path << " -> " << new_path;
1152 request.TryCompleteCurrentArg(std::to_string(i), strm.GetString());
1153 }
1154 }
1155
1156protected:
1157 void DoExecute(Args &command, CommandReturnObject &result) override {
1158 Target &target = GetTarget();
1159 size_t argc = command.GetArgumentCount();
1160 // check for at least 3 arguments and an odd number of parameters
1161 if (argc >= 3 && argc & 1) {
1162 uint32_t insert_idx;
1163
1164 if (!llvm::to_integer(command.GetArgumentAtIndex(0), insert_idx)) {
1165 result.AppendErrorWithFormat(
1166 "<index> parameter is not an integer: '%s'.\n",
1167 command.GetArgumentAtIndex(0));
1168 return;
1169 }
1170
1171 // shift off the index
1172 command.Shift();
1173 argc = command.GetArgumentCount();
1174
1175 for (uint32_t i = 0; i < argc; i += 2, ++insert_idx) {
1176 const char *from = command.GetArgumentAtIndex(i);
1177 const char *to = command.GetArgumentAtIndex(i + 1);
1178
1179 if (from[0] && to[0]) {
1180 bool last_pair = ((argc - i) == 2);
1181 target.GetImageSearchPathList().Insert(from, to, insert_idx,
1182 last_pair);
1184 } else {
1185 if (from[0])
1186 result.AppendError("<path-prefix> can't be empty\n");
1187 else
1188 result.AppendError("<new-path-prefix> can't be empty\n");
1189 return;
1190 }
1191 }
1192 } else {
1193 result.AppendError("insert requires at least three arguments\n");
1194 }
1195 }
1196};
1197
1198#pragma mark CommandObjectTargetModulesSearchPathsList
1199
1201public:
1203 : CommandObjectParsed(interpreter, "target modules search-paths list",
1204 "List all current image search path substitution "
1205 "pairs in the current target.",
1206 "target modules search-paths list",
1207 eCommandRequiresTarget) {}
1208
1210
1211protected:
1212 void DoExecute(Args &command, CommandReturnObject &result) override {
1213 Target &target = GetTarget();
1214 target.GetImageSearchPathList().Dump(&result.GetOutputStream());
1216 }
1217};
1218
1219#pragma mark CommandObjectTargetModulesSearchPathsQuery
1220
1222public:
1225 interpreter, "target modules search-paths query",
1226 "Transform a path using the first applicable image search path.",
1227 nullptr, eCommandRequiresTarget) {
1229 }
1230
1232
1233protected:
1234 void DoExecute(Args &command, CommandReturnObject &result) override {
1235 Target &target = GetTarget();
1236 if (command.GetArgumentCount() != 1) {
1237 result.AppendError("query requires one argument\n");
1238 return;
1239 }
1240
1241 ConstString orig(command.GetArgumentAtIndex(0));
1242 ConstString transformed;
1243 if (target.GetImageSearchPathList().RemapPath(orig, transformed))
1244 result.GetOutputStream().Printf("%s\n", transformed.GetCString());
1245 else
1246 result.GetOutputStream().Printf("%s\n", orig.GetCString());
1247
1249 }
1250};
1251
1252// Static Helper functions
1253static void DumpModuleArchitecture(Stream &strm, Module *module,
1254 bool full_triple, uint32_t width) {
1255 if (module) {
1256 StreamString arch_strm;
1257
1258 if (full_triple)
1259 module->GetArchitecture().DumpTriple(arch_strm.AsRawOstream());
1260 else
1261 arch_strm.PutCString(module->GetArchitecture().GetArchitectureName());
1262 std::string arch_str = std::string(arch_strm.GetString());
1263
1264 if (width)
1265 strm.Printf("%-*s", width, arch_str.c_str());
1266 else
1267 strm.PutCString(arch_str);
1268 }
1269}
1270
1271static void DumpModuleUUID(Stream &strm, Module *module) {
1272 if (module && module->GetUUID().IsValid())
1273 module->GetUUID().Dump(strm);
1274 else
1275 strm.PutCString(" ");
1276}
1277
1279 Stream &strm, Module *module,
1280 const FileSpec &file_spec,
1281 lldb::DescriptionLevel desc_level) {
1282 uint32_t num_matches = 0;
1283 if (module) {
1284 SymbolContextList sc_list;
1285 num_matches = module->ResolveSymbolContextsForFileSpec(
1286 file_spec, 0, false, eSymbolContextCompUnit, sc_list);
1287
1288 bool first_module = true;
1289 for (const SymbolContext &sc : sc_list) {
1290 if (!first_module)
1291 strm << "\n\n";
1292
1293 strm << "Line table for " << sc.comp_unit->GetPrimaryFile() << " in `"
1294 << module->GetFileSpec().GetFilename() << "\n";
1295 LineTable *line_table = sc.comp_unit->GetLineTable();
1296 if (line_table)
1297 line_table->GetDescription(
1298 &strm, interpreter.GetExecutionContext().GetTargetPtr(),
1299 desc_level);
1300 else
1301 strm << "No line table";
1302
1303 first_module = false;
1304 }
1305 }
1306 return num_matches;
1307}
1308
1309static void DumpFullpath(Stream &strm, const FileSpec *file_spec_ptr,
1310 uint32_t width) {
1311 if (file_spec_ptr) {
1312 if (width > 0) {
1313 std::string fullpath = file_spec_ptr->GetPath();
1314 strm.Printf("%-*s", width, fullpath.c_str());
1315 return;
1316 } else {
1317 file_spec_ptr->Dump(strm.AsRawOstream());
1318 return;
1319 }
1320 }
1321 // Keep the width spacing correct if things go wrong...
1322 if (width > 0)
1323 strm.Printf("%-*s", width, "");
1324}
1325
1326static void DumpDirectory(Stream &strm, const FileSpec *file_spec_ptr,
1327 uint32_t width) {
1328 if (file_spec_ptr) {
1329 if (width > 0)
1330 strm.Printf("%-*s", width, file_spec_ptr->GetDirectory().AsCString(""));
1331 else
1332 file_spec_ptr->GetDirectory().Dump(&strm);
1333 return;
1334 }
1335 // Keep the width spacing correct if things go wrong...
1336 if (width > 0)
1337 strm.Printf("%-*s", width, "");
1338}
1339
1340static void DumpBasename(Stream &strm, const FileSpec *file_spec_ptr,
1341 uint32_t width) {
1342 if (file_spec_ptr) {
1343 if (width > 0)
1344 strm.Printf("%-*s", width, file_spec_ptr->GetFilename().AsCString(""));
1345 else
1346 file_spec_ptr->GetFilename().Dump(&strm);
1347 return;
1348 }
1349 // Keep the width spacing correct if things go wrong...
1350 if (width > 0)
1351 strm.Printf("%-*s", width, "");
1352}
1353
1354static size_t DumpModuleObjfileHeaders(Stream &strm, ModuleList &module_list) {
1355 std::lock_guard<std::recursive_mutex> guard(module_list.GetMutex());
1356 const size_t num_modules = module_list.GetSize();
1357 if (num_modules == 0)
1358 return 0;
1359
1360 size_t num_dumped = 0;
1361 strm.Format("Dumping headers for {0} module(s).\n", num_modules);
1362 strm.IndentMore();
1363 for (ModuleSP module_sp : module_list.ModulesNoLocking()) {
1364 if (module_sp) {
1365 if (num_dumped++ > 0) {
1366 strm.EOL();
1367 strm.EOL();
1368 }
1369 ObjectFile *objfile = module_sp->GetObjectFile();
1370 if (objfile)
1371 objfile->Dump(&strm);
1372 else {
1373 strm.Format("No object file for module: {0:F}\n",
1374 module_sp->GetFileSpec());
1375 }
1376 }
1377 }
1378 strm.IndentLess();
1379 return num_dumped;
1380}
1381
1382static void DumpModuleSymtab(CommandInterpreter &interpreter, Stream &strm,
1383 Module *module, SortOrder sort_order,
1384 Mangled::NamePreference name_preference) {
1385 if (!module)
1386 return;
1387 if (Symtab *symtab = module->GetSymtab())
1388 symtab->Dump(&strm, interpreter.GetExecutionContext().GetTargetPtr(),
1389 sort_order, name_preference);
1390}
1391
1392static void DumpModuleSections(CommandInterpreter &interpreter, Stream &strm,
1393 Module *module) {
1394 if (module) {
1395 SectionList *section_list = module->GetSectionList();
1396 if (section_list) {
1397 strm.Printf("Sections for '%s' (%s):\n",
1398 module->GetSpecificationDescription().c_str(),
1400 section_list->Dump(strm.AsRawOstream(), strm.GetIndentLevel() + 2,
1401 interpreter.GetExecutionContext().GetTargetPtr(), true,
1402 UINT32_MAX);
1403 }
1404 }
1405}
1406
1407static bool DumpModuleSymbolFile(Stream &strm, Module *module) {
1408 if (module) {
1409 if (SymbolFile *symbol_file = module->GetSymbolFile(true)) {
1410 symbol_file->Dump(strm);
1411 return true;
1412 }
1413 }
1414 return false;
1415}
1416
1418 Module *module, bool errors_only,
1419 bool load_all_debug_info) {
1420 if (module) {
1421 if (SymbolFile *symbol_file = module->GetSymbolFile(/*can_create=*/true)) {
1423 if (symbol_file->GetSeparateDebugInfo(d, errors_only,
1424 load_all_debug_info)) {
1425 list.AddItem(
1426 std::make_shared<StructuredData::Dictionary>(std::move(d)));
1427 return true;
1428 }
1429 }
1430 }
1431 return false;
1432}
1433
1434static void DumpDwoFilesTable(Stream &strm,
1435 StructuredData::Array &dwo_listings) {
1436 strm.PutCString("Dwo ID Err Dwo Path");
1437 strm.EOL();
1438 strm.PutCString(
1439 "------------------ --- -----------------------------------------");
1440 strm.EOL();
1441 dwo_listings.ForEach([&strm](StructuredData::Object *dwo) {
1443 if (!dict)
1444 return false;
1445
1446 uint64_t dwo_id;
1447 if (dict->GetValueForKeyAsInteger("dwo_id", dwo_id))
1448 strm.Printf("0x%16.16" PRIx64 " ", dwo_id);
1449 else
1450 strm.Printf("0x???????????????? ");
1451
1452 llvm::StringRef error;
1453 if (dict->GetValueForKeyAsString("error", error))
1454 strm << "E " << error;
1455 else {
1456 llvm::StringRef resolved_dwo_path;
1457 if (dict->GetValueForKeyAsString("resolved_dwo_path",
1458 resolved_dwo_path)) {
1459 strm << " " << resolved_dwo_path;
1460 if (resolved_dwo_path.ends_with(".dwp")) {
1461 llvm::StringRef dwo_name;
1462 if (dict->GetValueForKeyAsString("dwo_name", dwo_name))
1463 strm << "(" << dwo_name << ")";
1464 }
1465 }
1466 }
1467 strm.EOL();
1468 return true;
1469 });
1470}
1471
1472static void DumpOsoFilesTable(Stream &strm,
1473 StructuredData::Array &oso_listings) {
1474 strm.PutCString("Mod Time Err Oso Path");
1475 strm.EOL();
1476 strm.PutCString("------------------ --- ---------------------");
1477 strm.EOL();
1478 oso_listings.ForEach([&strm](StructuredData::Object *oso) {
1480 if (!dict)
1481 return false;
1482
1483 uint32_t oso_mod_time;
1484 if (dict->GetValueForKeyAsInteger("oso_mod_time", oso_mod_time))
1485 strm.Printf("0x%16.16" PRIx32 " ", oso_mod_time);
1486
1487 llvm::StringRef error;
1488 if (dict->GetValueForKeyAsString("error", error))
1489 strm << "E " << error;
1490 else {
1491 llvm::StringRef oso_path;
1492 if (dict->GetValueForKeyAsString("oso_path", oso_path))
1493 strm << " " << oso_path;
1494 }
1495 strm.EOL();
1496 return true;
1497 });
1498}
1499
1500static void
1501DumpAddress(ExecutionContextScope *exe_scope, const Address &so_addr,
1502 bool verbose, bool all_ranges, Stream &strm,
1503 std::optional<Stream::HighlightSettings> settings = std::nullopt) {
1504 strm.IndentMore();
1505 strm.Indent(" Address: ");
1506 so_addr.Dump(&strm, exe_scope, Address::DumpStyleModuleWithFileAddress);
1507 strm.PutCString(" (");
1508 so_addr.Dump(&strm, exe_scope, Address::DumpStyleSectionNameOffset);
1509 strm.PutCString(")\n");
1510 strm.Indent(" Summary: ");
1511 const uint32_t save_indent = strm.GetIndentLevel();
1512 strm.SetIndentLevel(save_indent + 13);
1513 so_addr.Dump(&strm, exe_scope, Address::DumpStyleResolvedDescription,
1514 Address::DumpStyleInvalid, UINT32_MAX, false, settings);
1515 strm.SetIndentLevel(save_indent);
1516 // Print out detailed address information when verbose is enabled
1517 if (verbose) {
1518 strm.EOL();
1519 so_addr.Dump(&strm, exe_scope, Address::DumpStyleDetailedSymbolContext,
1520 Address::DumpStyleInvalid, UINT32_MAX, all_ranges, settings);
1521 }
1522 strm.IndentLess();
1523}
1524
1525static bool LookupAddressInModule(CommandInterpreter &interpreter, Stream &strm,
1526 Module *module, uint32_t resolve_mask,
1527 lldb::addr_t raw_addr, lldb::addr_t offset,
1528 bool verbose, bool all_ranges) {
1529 if (module) {
1530 lldb::addr_t addr = raw_addr - offset;
1531 Address so_addr;
1532 SymbolContext sc;
1533 Target *target = interpreter.GetExecutionContext().GetTargetPtr();
1534 if (target && target->HasLoadedSections()) {
1535 if (!target->ResolveLoadAddress(addr, so_addr))
1536 return false;
1537 else if (so_addr.GetModule().get() != module)
1538 return false;
1539 } else {
1540 if (!module->ResolveFileAddress(addr, so_addr))
1541 return false;
1542 }
1543
1544 ExecutionContextScope *exe_scope =
1546 DumpAddress(exe_scope, so_addr, verbose, all_ranges, strm);
1547 return true;
1548 }
1549
1550 return false;
1551}
1552
1553static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter,
1554 Stream &strm, Module *module,
1555 const char *name, bool name_is_regex,
1556 bool verbose, bool all_ranges) {
1557 if (!module)
1558 return 0;
1559
1560 Symtab *symtab = module->GetSymtab();
1561 if (!symtab)
1562 return 0;
1563
1564 SymbolContext sc;
1565 const bool use_color = interpreter.GetDebugger().GetUseColor();
1566 std::vector<uint32_t> match_indexes;
1567 ConstString symbol_name(name);
1568 uint32_t num_matches = 0;
1569 if (name_is_regex) {
1570 RegularExpression name_regexp(symbol_name.GetStringRef());
1571 num_matches = symtab->AppendSymbolIndexesMatchingRegExAndType(
1572 name_regexp, eSymbolTypeAny, match_indexes);
1573 } else {
1574 num_matches =
1575 symtab->AppendSymbolIndexesWithName(symbol_name, match_indexes);
1576 }
1577
1578 if (num_matches > 0) {
1579 strm.Indent();
1580 strm.Printf("%u symbols match %s'%s' in ", num_matches,
1581 name_is_regex ? "the regular expression " : "", name);
1582 DumpFullpath(strm, &module->GetFileSpec(), 0);
1583 strm.PutCString(":\n");
1584 strm.IndentMore();
1586 name, interpreter.GetDebugger().GetRegexMatchAnsiPrefix(),
1587 interpreter.GetDebugger().GetRegexMatchAnsiSuffix());
1588 for (uint32_t i = 0; i < num_matches; ++i) {
1589 const Symbol *symbol = symtab->SymbolAtIndex(match_indexes[i]);
1590 if (symbol) {
1591 if (symbol->ValueIsAddress()) {
1594 symbol->GetAddressRef(), verbose, all_ranges, strm,
1595 use_color && name_is_regex
1596 ? std::optional<Stream::HighlightSettings>{settings}
1597 : std::nullopt);
1598 strm.EOL();
1599 } else {
1600 strm.IndentMore();
1601 strm.Indent(" Name: ");
1603 symbol->GetDisplayName().GetStringRef(),
1604 use_color && name_is_regex
1605 ? std::optional<Stream::HighlightSettings>{settings}
1606 : std::nullopt);
1607 strm.EOL();
1608 strm.Indent(" Value: ");
1609 strm.Printf("0x%16.16" PRIx64 "\n", symbol->GetRawValue());
1610 if (symbol->GetByteSizeIsValid()) {
1611 strm.Indent(" Size: ");
1612 strm.Printf("0x%16.16" PRIx64 "\n", symbol->GetByteSize());
1613 }
1614 strm.IndentLess();
1615 }
1616 }
1617 }
1618 strm.IndentLess();
1619 }
1620 return num_matches;
1621}
1622
1624 ExecutionContextScope *exe_scope, Stream &strm,
1625 const SymbolContextList &sc_list, bool verbose, bool all_ranges,
1626 std::optional<Stream::HighlightSettings> settings = std::nullopt) {
1627 strm.IndentMore();
1628 bool first_module = true;
1629 for (const SymbolContext &sc : sc_list) {
1630 if (!first_module)
1631 strm.EOL();
1632
1633 Address addr;
1634 if (sc.line_entry.IsValid())
1635 addr = sc.line_entry.range.GetBaseAddress();
1636 else if (sc.block && sc.block->GetContainingInlinedBlock())
1637 sc.block->GetContainingInlinedBlock()->GetStartAddress(addr);
1638 else
1639 addr = sc.GetFunctionOrSymbolAddress();
1640
1641 DumpAddress(exe_scope, addr, verbose, all_ranges, strm, settings);
1642 first_module = false;
1643 }
1644 strm.IndentLess();
1645}
1646
1648 Stream &strm, Module *module,
1649 const char *name, bool name_is_regex,
1650 const ModuleFunctionSearchOptions &options,
1651 bool verbose, bool all_ranges) {
1652 if (module && name && name[0]) {
1653 SymbolContextList sc_list;
1654 size_t num_matches = 0;
1655 if (name_is_regex) {
1656 RegularExpression function_name_regex((llvm::StringRef(name)));
1657 module->FindFunctions(function_name_regex, options, sc_list);
1658 } else {
1659 ConstString function_name(name);
1660 module->FindFunctions(function_name, CompilerDeclContext(),
1661 eFunctionNameTypeAuto, options, sc_list);
1662 }
1663 num_matches = sc_list.GetSize();
1664 if (num_matches) {
1665 strm.Indent();
1666 strm.Printf("%" PRIu64 " match%s found in ", (uint64_t)num_matches,
1667 num_matches > 1 ? "es" : "");
1668 DumpFullpath(strm, &module->GetFileSpec(), 0);
1669 strm.PutCString(":\n");
1672 strm, sc_list, verbose, all_ranges);
1673 }
1674 return num_matches;
1675 }
1676 return 0;
1677}
1678
1679static size_t LookupTypeInModule(Target *target,
1680 CommandInterpreter &interpreter, Stream &strm,
1681 Module *module, const char *name_cstr,
1682 bool name_is_regex) {
1683 if (module && name_cstr && name_cstr[0]) {
1684 TypeQuery query(name_cstr);
1685 TypeResults results;
1686 module->FindTypes(query, results);
1687
1688 TypeList type_list;
1689 SymbolContext sc;
1690 if (module)
1691 sc.module_sp = module->shared_from_this();
1692 // Sort the type results and put the results that matched in \a module
1693 // first if \a module was specified.
1694 sc.SortTypeList(results.GetTypeMap(), type_list);
1695 if (type_list.Empty())
1696 return 0;
1697
1698 const uint64_t num_matches = type_list.GetSize();
1699
1700 strm.Indent();
1701 strm.Printf("%" PRIu64 " match%s found in ", num_matches,
1702 num_matches > 1 ? "es" : "");
1703 DumpFullpath(strm, &module->GetFileSpec(), 0);
1704 strm.PutCString(":\n");
1705 for (TypeSP type_sp : type_list.Types()) {
1706 if (!type_sp)
1707 continue;
1708 // Resolve the clang type so that any forward references to types
1709 // that haven't yet been parsed will get parsed.
1710 type_sp->GetFullCompilerType();
1711 type_sp->GetDescription(&strm, eDescriptionLevelFull, true, target);
1712 // Print all typedef chains
1713 TypeSP typedef_type_sp(type_sp);
1714 TypeSP typedefed_type_sp(typedef_type_sp->GetTypedefType());
1715 while (typedefed_type_sp) {
1716 strm.EOL();
1717 strm.Printf(" typedef '%s': ",
1718 typedef_type_sp->GetName().GetCString());
1719 typedefed_type_sp->GetFullCompilerType();
1720 typedefed_type_sp->GetDescription(&strm, eDescriptionLevelFull, true,
1721 target);
1722 typedef_type_sp = typedefed_type_sp;
1723 typedefed_type_sp = typedef_type_sp->GetTypedefType();
1724 }
1725 strm.EOL();
1726 }
1727 return type_list.GetSize();
1728 }
1729 return 0;
1730}
1731
1732static size_t LookupTypeHere(Target *target, CommandInterpreter &interpreter,
1733 Stream &strm, Module &module,
1734 const char *name_cstr, bool name_is_regex) {
1735 TypeQuery query(name_cstr);
1736 TypeResults results;
1737 module.FindTypes(query, results);
1738 TypeList type_list;
1739 SymbolContext sc;
1740 sc.module_sp = module.shared_from_this();
1741 sc.SortTypeList(results.GetTypeMap(), type_list);
1742 if (type_list.Empty())
1743 return 0;
1744
1745 strm.Indent();
1746 strm.PutCString("Best match found in ");
1747 DumpFullpath(strm, &module.GetFileSpec(), 0);
1748 strm.PutCString(":\n");
1749
1750 TypeSP type_sp(type_list.GetTypeAtIndex(0));
1751 if (type_sp) {
1752 // Resolve the clang type so that any forward references to types that
1753 // haven't yet been parsed will get parsed.
1754 type_sp->GetFullCompilerType();
1755 type_sp->GetDescription(&strm, eDescriptionLevelFull, true, target);
1756 // Print all typedef chains.
1757 TypeSP typedef_type_sp(type_sp);
1758 TypeSP typedefed_type_sp(typedef_type_sp->GetTypedefType());
1759 while (typedefed_type_sp) {
1760 strm.EOL();
1761 strm.Printf(" typedef '%s': ",
1762 typedef_type_sp->GetName().GetCString());
1763 typedefed_type_sp->GetFullCompilerType();
1764 typedefed_type_sp->GetDescription(&strm, eDescriptionLevelFull, true,
1765 target);
1766 typedef_type_sp = typedefed_type_sp;
1767 typedefed_type_sp = typedef_type_sp->GetTypedefType();
1768 }
1769 }
1770 strm.EOL();
1771 return type_list.GetSize();
1772}
1773
1775 Stream &strm, Module *module,
1776 const FileSpec &file_spec,
1777 uint32_t line, bool check_inlines,
1778 bool verbose, bool all_ranges) {
1779 if (module && file_spec) {
1780 SymbolContextList sc_list;
1781 const uint32_t num_matches = module->ResolveSymbolContextsForFileSpec(
1782 file_spec, line, check_inlines, eSymbolContextEverything, sc_list);
1783 if (num_matches > 0) {
1784 strm.Indent();
1785 strm.Printf("%u match%s found in ", num_matches,
1786 num_matches > 1 ? "es" : "");
1787 strm << file_spec;
1788 if (line > 0)
1789 strm.Printf(":%u", line);
1790 strm << " in ";
1791 DumpFullpath(strm, &module->GetFileSpec(), 0);
1792 strm.PutCString(":\n");
1795 strm, sc_list, verbose, all_ranges);
1796 return num_matches;
1797 }
1798 }
1799 return 0;
1800}
1801
1802static size_t FindModulesByName(Target *target, const char *module_name,
1803 ModuleList &module_list,
1804 bool check_global_list) {
1805 FileSpec module_file_spec(module_name);
1806 ModuleSpec module_spec(module_file_spec);
1807
1808 const size_t initial_size = module_list.GetSize();
1809
1810 if (check_global_list) {
1811 // Check the global list
1812 std::lock_guard<std::recursive_mutex> guard(
1814 const size_t num_modules = Module::GetNumberAllocatedModules();
1815 ModuleSP module_sp;
1816 for (size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
1817 Module *module = Module::GetAllocatedModuleAtIndex(image_idx);
1818
1819 if (module) {
1820 if (module->MatchesModuleSpec(module_spec)) {
1821 module_sp = module->shared_from_this();
1822 module_list.AppendIfNeeded(module_sp);
1823 }
1824 }
1825 }
1826 } else {
1827 if (target) {
1828 target->GetImages().FindModules(module_spec, module_list);
1829 const size_t num_matches = module_list.GetSize();
1830
1831 // Not found in our module list for our target, check the main shared
1832 // module list in case it is a extra file used somewhere else
1833 if (num_matches == 0) {
1834 module_spec.GetArchitecture() = target->GetArchitecture();
1835 ModuleList::FindSharedModules(module_spec, module_list);
1836 }
1837 } else {
1838 ModuleList::FindSharedModules(module_spec, module_list);
1839 }
1840 }
1841
1842 return module_list.GetSize() - initial_size;
1843}
1844
1845#pragma mark CommandObjectTargetModulesModuleAutoComplete
1846
1847// A base command object class that can auto complete with module file
1848// paths
1849
1851 : public CommandObjectParsed {
1852public:
1854 const char *name,
1855 const char *help,
1856 const char *syntax,
1857 uint32_t flags = 0)
1858 : CommandObjectParsed(interpreter, name, help, syntax, flags) {
1860 }
1861
1863
1864 void
1870};
1871
1872#pragma mark CommandObjectTargetModulesSourceFileAutoComplete
1873
1874// A base command object class that can auto complete with module source
1875// file paths
1876
1878 : public CommandObjectParsed {
1879public:
1881 CommandInterpreter &interpreter, const char *name, const char *help,
1882 const char *syntax, uint32_t flags)
1883 : CommandObjectParsed(interpreter, name, help, syntax, flags) {
1885 }
1886
1888
1889 void
1895};
1896
1897#pragma mark CommandObjectTargetModulesDumpObjfile
1898
1901public:
1904 interpreter, "target modules dump objfile",
1905 "Dump the object file headers from one or more target modules.",
1906 nullptr, eCommandRequiresTarget) {}
1907
1909
1910protected:
1911 void DoExecute(Args &command, CommandReturnObject &result) override {
1912 Target &target = GetTarget();
1913
1914 size_t num_dumped = 0;
1915 if (command.GetArgumentCount() == 0) {
1916 // Dump all headers for all modules images
1917 num_dumped = DumpModuleObjfileHeaders(result.GetOutputStream(),
1918 target.GetImages());
1919 if (num_dumped == 0) {
1920 result.AppendError("the target has no associated executable images");
1921 }
1922 } else {
1923 // Find the modules that match the basename or full path.
1924 ModuleList module_list;
1925 const char *arg_cstr;
1926 for (int arg_idx = 0;
1927 (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != nullptr;
1928 ++arg_idx) {
1929 size_t num_matched =
1930 FindModulesByName(&target, arg_cstr, module_list, true);
1931 if (num_matched == 0) {
1933 "unable to find an image that matches '{0}'", arg_cstr);
1934 }
1935 }
1936 // Dump all the modules we found.
1937 num_dumped =
1938 DumpModuleObjfileHeaders(result.GetOutputStream(), module_list);
1939 }
1940
1941 if (num_dumped > 0) {
1943 } else {
1944 result.AppendError("no matching executable images found");
1945 }
1946 }
1947};
1948
1949#define LLDB_OPTIONS_target_modules_dump_symtab
1950#include "CommandOptions.inc"
1951
1954public:
1957 interpreter, "target modules dump symtab",
1958 "Dump the symbol table from one or more target modules.", nullptr,
1959 eCommandRequiresTarget) {}
1960
1962
1963 Options *GetOptions() override { return &m_options; }
1964
1965 class CommandOptions : public Options {
1966 public:
1967 CommandOptions() = default;
1968
1969 ~CommandOptions() override = default;
1970
1971 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1972 ExecutionContext *execution_context) override {
1973 Status error;
1974 const int short_option = m_getopt_table[option_idx].val;
1975
1976 switch (short_option) {
1977 case 'm':
1978 m_prefer_mangled.SetCurrentValue(true);
1979 m_prefer_mangled.SetOptionWasSet();
1980 break;
1981
1982 case 's':
1984 option_arg, GetDefinitions()[option_idx].enum_values,
1986 break;
1987
1988 default:
1989 llvm_unreachable("Unimplemented option");
1990 }
1991 return error;
1992 }
1993
1994 void OptionParsingStarting(ExecutionContext *execution_context) override {
1996 m_prefer_mangled.Clear();
1997 }
1998
1999 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
2000 return llvm::ArrayRef(g_target_modules_dump_symtab_options);
2001 }
2002
2005 };
2006
2007protected:
2008 void DoExecute(Args &command, CommandReturnObject &result) override {
2009 Target &target = GetTarget();
2010 uint32_t num_dumped = 0;
2011 Mangled::NamePreference name_preference =
2012 (m_options.m_prefer_mangled ? Mangled::ePreferMangled
2014
2015 if (command.GetArgumentCount() == 0) {
2016 // Dump all sections for all modules images
2017 const ModuleList &module_list = target.GetImages();
2018 std::lock_guard<std::recursive_mutex> guard(module_list.GetMutex());
2019 const size_t num_modules = module_list.GetSize();
2020 if (num_modules > 0) {
2021 result.GetOutputStream().Format(
2022 "Dumping symbol table for {0} modules.\n", num_modules);
2023 for (ModuleSP module_sp : module_list.ModulesNoLocking()) {
2024 if (num_dumped > 0) {
2025 result.GetOutputStream().EOL();
2026 result.GetOutputStream().EOL();
2027 }
2029 "Interrupted in dump all symtabs with {0} "
2030 "of {1} dumped.", num_dumped, num_modules))
2031 break;
2032
2033 num_dumped++;
2035 module_sp.get(), m_options.m_sort_order,
2036 name_preference);
2037 }
2038 } else {
2039 result.AppendError("the target has no associated executable images");
2040 return;
2041 }
2042 } else {
2043 // Dump specified images (by basename or fullpath)
2044 const char *arg_cstr;
2045 for (int arg_idx = 0;
2046 (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != nullptr;
2047 ++arg_idx) {
2048 ModuleList module_list;
2049 const size_t num_matches =
2050 FindModulesByName(&target, arg_cstr, module_list, true);
2051 if (num_matches > 0) {
2052 for (ModuleSP module_sp : module_list.Modules()) {
2053 if (module_sp) {
2054 if (num_dumped > 0) {
2055 result.GetOutputStream().EOL();
2056 result.GetOutputStream().EOL();
2057 }
2059 "Interrupted in dump symtab list with {0} of {1} dumped.",
2060 num_dumped, num_matches))
2061 break;
2062
2063 num_dumped++;
2065 module_sp.get(), m_options.m_sort_order,
2066 name_preference);
2067 }
2068 }
2069 } else
2071 "unable to find an image that matches '{0}'", arg_cstr);
2072 }
2073 }
2074
2075 if (num_dumped > 0)
2077 else {
2078 result.AppendError("no matching executable images found");
2079 }
2080 }
2081
2083};
2084
2085#pragma mark CommandObjectTargetModulesDumpSections
2086
2087// Image section dumping command
2088
2091public:
2094 interpreter, "target modules dump sections",
2095 "Dump the sections from one or more target modules.",
2096 //"target modules dump sections [<file1> ...]")
2097 nullptr, eCommandRequiresTarget) {}
2098
2100
2101protected:
2102 void DoExecute(Args &command, CommandReturnObject &result) override {
2103 Target &target = GetTarget();
2104 uint32_t num_dumped = 0;
2105
2106 if (command.GetArgumentCount() == 0) {
2107 // Dump all sections for all modules images
2108 const size_t num_modules = target.GetImages().GetSize();
2109 if (num_modules == 0) {
2110 result.AppendError("the target has no associated executable images");
2111 return;
2112 }
2113
2114 result.GetOutputStream().Format("Dumping sections for {0} modules.\n",
2115 num_modules);
2116 for (size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
2118 "Interrupted in dump all sections with {0} of {1} dumped",
2119 image_idx, num_modules))
2120 break;
2121
2122 num_dumped++;
2125 target.GetImages().GetModulePointerAtIndex(image_idx));
2126 }
2127 } else {
2128 // Dump specified images (by basename or fullpath)
2129 const char *arg_cstr;
2130 for (int arg_idx = 0;
2131 (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != nullptr;
2132 ++arg_idx) {
2133 ModuleList module_list;
2134 const size_t num_matches =
2135 FindModulesByName(&target, arg_cstr, module_list, true);
2136 if (num_matches > 0) {
2137 for (size_t i = 0; i < num_matches; ++i) {
2139 "Interrupted in dump section list with {0} of {1} dumped.",
2140 i, num_matches))
2141 break;
2142
2143 Module *module = module_list.GetModulePointerAtIndex(i);
2144 if (module) {
2145 num_dumped++;
2147 module);
2148 }
2149 }
2150 } else {
2151 // Check the global list
2152 std::lock_guard<std::recursive_mutex> guard(
2154
2156 "unable to find an image that matches '{0}'", arg_cstr);
2157 }
2158 }
2159 }
2160
2161 if (num_dumped > 0)
2163 else {
2164 result.AppendError("no matching executable images found");
2165 }
2166 }
2167};
2168
2170public:
2173 interpreter, "target modules dump pcm-info",
2174 "Dump information about the given clang module (pcm).") {
2175 // Take a single file argument.
2177 }
2178
2180
2181protected:
2182 void DoExecute(Args &command, CommandReturnObject &result) override {
2183 if (command.GetArgumentCount() != 1) {
2184 result.AppendErrorWithFormat("'%s' takes exactly one pcm path argument.",
2185 m_cmd_name.c_str());
2186 return;
2187 }
2188
2189 const char *pcm_path = command.GetArgumentAtIndex(0);
2190 const FileSpec pcm_file{pcm_path};
2191
2192 if (pcm_file.GetFileNameExtension() != ".pcm") {
2193 result.AppendError("file must have a .pcm extension");
2194 return;
2195 }
2196
2197 if (!FileSystem::Instance().Exists(pcm_file)) {
2198 result.AppendError("pcm file does not exist");
2199 return;
2200 }
2201
2202 const char *clang_args[] = {"clang", pcm_path};
2203 clang::CompilerInstance compiler(clang::createInvocation(clang_args));
2204 compiler.setVirtualFileSystem(
2205 FileSystem::Instance().GetVirtualFileSystem());
2206 compiler.createDiagnostics();
2207
2208 // Pass empty deleter to not attempt to free memory that was allocated
2209 // outside of the current scope, possibly statically.
2210 std::shared_ptr<llvm::raw_ostream> Out(
2211 &result.GetOutputStream().AsRawOstream(), [](llvm::raw_ostream *) {});
2212 clang::DumpModuleInfoAction dump_module_info(Out);
2213 // DumpModuleInfoAction requires ObjectFilePCHContainerReader.
2214 compiler.getPCHContainerOperations()->registerReader(
2215 std::make_unique<clang::ObjectFilePCHContainerReader>());
2216
2217 if (compiler.ExecuteAction(dump_module_info))
2219 }
2220};
2221
2222#pragma mark CommandObjectTargetModulesDumpClangAST
2223
2224// Clang AST dumping command
2225
2228public:
2231 interpreter, "target modules dump ast",
2232 "Dump the clang ast for a given module's symbol file.",
2233 "target modules dump ast [--filter <name>] [<file1> ...]",
2234 eCommandRequiresTarget),
2235 m_filter(LLDB_OPT_SET_1, false, "filter", 'f', 0, eArgTypeName,
2236 "Dump only the decls whose names contain the specified filter "
2237 "string.",
2238 /*default_value=*/"") {
2240 m_option_group.Finalize();
2241 }
2242
2243 Options *GetOptions() override { return &m_option_group; }
2244
2246
2249
2250protected:
2251 void DoExecute(Args &command, CommandReturnObject &result) override {
2252 Target &target = GetTarget();
2253
2254 const ModuleList &module_list = target.GetImages();
2255 const size_t num_modules = module_list.GetSize();
2256 if (num_modules == 0) {
2257 result.AppendError("the target has no associated executable images");
2258 return;
2259 }
2260
2261 llvm::StringRef filter = m_filter.GetOptionValue().GetCurrentValueAsRef();
2262
2263 if (command.GetArgumentCount() == 0) {
2264 // Dump all ASTs for all modules images
2265 result.GetOutputStream().Format("Dumping clang ast for {0} modules.\n",
2266 num_modules);
2267 for (ModuleSP module_sp : module_list.ModulesNoLocking()) {
2268 if (INTERRUPT_REQUESTED(GetDebugger(), "Interrupted dumping clang ast"))
2269 break;
2270 if (SymbolFile *sf = module_sp->GetSymbolFile())
2271 sf->DumpClangAST(result.GetOutputStream(), filter,
2272 GetCommandInterpreter().GetDebugger().GetUseColor());
2273 }
2275 return;
2276 }
2277
2278 // Dump specified ASTs (by basename or fullpath)
2279 for (const Args::ArgEntry &arg : command.entries()) {
2280 ModuleList module_list;
2281 const size_t num_matches =
2282 FindModulesByName(&target, arg.c_str(), module_list, true);
2283 if (num_matches == 0) {
2284 // Check the global list
2285 std::lock_guard<std::recursive_mutex> guard(
2287
2289 "unable to find an image that matches '{0}'", arg.c_str());
2290 continue;
2291 }
2292
2293 for (size_t i = 0; i < num_matches; ++i) {
2295 "Interrupted in dump clang ast list with {0} of {1} dumped.",
2296 i, num_matches))
2297 break;
2298
2299 Module *m = module_list.GetModulePointerAtIndex(i);
2300 if (SymbolFile *sf = m->GetSymbolFile())
2301 sf->DumpClangAST(result.GetOutputStream(), filter,
2302 GetCommandInterpreter().GetDebugger().GetUseColor());
2303 }
2304 }
2306 }
2307};
2308
2309#pragma mark CommandObjectTargetModulesDumpSymfile
2310
2311// Image debug symbol dumping command
2312
2315public:
2318 interpreter, "target modules dump symfile",
2319 "Dump the debug symbol file for one or more target modules.",
2320 //"target modules dump symfile [<file1> ...]")
2321 nullptr, eCommandRequiresTarget) {}
2322
2324
2325protected:
2326 void DoExecute(Args &command, CommandReturnObject &result) override {
2327 Target &target = GetTarget();
2328 uint32_t num_dumped = 0;
2329
2330 if (command.GetArgumentCount() == 0) {
2331 // Dump all sections for all modules images
2332 const ModuleList &target_modules = target.GetImages();
2333 std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
2334 const size_t num_modules = target_modules.GetSize();
2335 if (num_modules == 0) {
2336 result.AppendError("the target has no associated executable images");
2337 return;
2338 }
2339 result.GetOutputStream().Format(
2340 "Dumping debug symbols for {0} modules.\n", num_modules);
2341 for (ModuleSP module_sp : target_modules.ModulesNoLocking()) {
2342 if (INTERRUPT_REQUESTED(GetDebugger(), "Interrupted in dumping all "
2343 "debug symbols with {0} of {1} modules dumped",
2344 num_dumped, num_modules))
2345 break;
2346
2347 if (DumpModuleSymbolFile(result.GetOutputStream(), module_sp.get()))
2348 num_dumped++;
2349 }
2350 } else {
2351 // Dump specified images (by basename or fullpath)
2352 const char *arg_cstr;
2353 for (int arg_idx = 0;
2354 (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != nullptr;
2355 ++arg_idx) {
2356 ModuleList module_list;
2357 const size_t num_matches =
2358 FindModulesByName(&target, arg_cstr, module_list, true);
2359 if (num_matches > 0) {
2360 for (size_t i = 0; i < num_matches; ++i) {
2361 if (INTERRUPT_REQUESTED(GetDebugger(), "Interrupted dumping {0} "
2362 "of {1} requested modules",
2363 i, num_matches))
2364 break;
2365 Module *module = module_list.GetModulePointerAtIndex(i);
2366 if (module) {
2367 if (DumpModuleSymbolFile(result.GetOutputStream(), module))
2368 num_dumped++;
2369 }
2370 }
2371 } else
2373 "unable to find an image that matches '{0}'", arg_cstr);
2374 }
2375 }
2376
2377 if (num_dumped > 0)
2379 else {
2380 result.AppendError("no matching executable images found");
2381 }
2382 }
2383};
2384
2385#pragma mark CommandObjectTargetModulesDumpLineTable
2386#define LLDB_OPTIONS_target_modules_dump
2387#include "CommandOptions.inc"
2388
2389// Image debug line table dumping command
2390
2393public:
2396 interpreter, "target modules dump line-table",
2397 "Dump the line table for one or more compilation units.", nullptr,
2398 eCommandRequiresTarget) {}
2399
2401
2402 Options *GetOptions() override { return &m_options; }
2403
2404protected:
2405 void DoExecute(Args &command, CommandReturnObject &result) override {
2406 Target *target = m_exe_ctx.GetTargetPtr();
2407 uint32_t total_num_dumped = 0;
2408
2409 if (command.GetArgumentCount() == 0) {
2410 result.AppendError("file option must be specified");
2411 return;
2412 } else {
2413 // Dump specified images (by basename or fullpath)
2414 const char *arg_cstr;
2415 for (int arg_idx = 0;
2416 (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != nullptr;
2417 ++arg_idx) {
2418 FileSpec file_spec(arg_cstr);
2419
2420 const ModuleList &target_modules = target->GetImages();
2421 std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
2422 size_t num_modules = target_modules.GetSize();
2423 if (num_modules > 0) {
2424 uint32_t num_dumped = 0;
2425 for (ModuleSP module_sp : target_modules.ModulesNoLocking()) {
2427 "Interrupted in dump all line tables with "
2428 "{0} of {1} dumped", num_dumped,
2429 num_modules))
2430 break;
2431
2433 m_interpreter, result.GetOutputStream(), module_sp.get(),
2434 file_spec,
2437 num_dumped++;
2438 }
2439 if (num_dumped == 0)
2440 result.AppendWarningWithFormatv("no source filenames matched '{0}'",
2441 arg_cstr);
2442 else
2443 total_num_dumped += num_dumped;
2444 }
2445 }
2446 }
2447
2448 if (total_num_dumped > 0)
2450 else {
2451 result.AppendError("no source filenames matched any command arguments");
2452 }
2453 }
2454
2455 class CommandOptions : public Options {
2456 public:
2458
2459 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
2460 ExecutionContext *execution_context) override {
2461 assert(option_idx == 0 && "We only have one option.");
2462 m_verbose = true;
2463
2464 return Status();
2465 }
2466
2467 void OptionParsingStarting(ExecutionContext *execution_context) override {
2468 m_verbose = false;
2469 }
2470
2471 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
2472 return llvm::ArrayRef(g_target_modules_dump_options);
2473 }
2474
2476 };
2477
2479};
2480
2481#pragma mark CommandObjectTargetModulesDumpSeparateDebugInfoFiles
2482#define LLDB_OPTIONS_target_modules_dump_separate_debug_info
2483#include "CommandOptions.inc"
2484
2485// Image debug separate debug info dumping command
2486
2489public:
2491 CommandInterpreter &interpreter)
2493 interpreter, "target modules dump separate-debug-info",
2494 "List the separate debug info symbol files for one or more target "
2495 "modules.",
2496 nullptr, eCommandRequiresTarget) {}
2497
2499
2500 Options *GetOptions() override { return &m_options; }
2501
2502 class CommandOptions : public Options {
2503 public:
2504 CommandOptions() = default;
2505
2506 ~CommandOptions() override = default;
2507
2508 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
2509 ExecutionContext *execution_context) override {
2510 Status error;
2511 const int short_option = m_getopt_table[option_idx].val;
2512
2513 switch (short_option) {
2514 case 'f':
2515 m_load_all_debug_info.SetCurrentValue(true);
2516 m_load_all_debug_info.SetOptionWasSet();
2517 break;
2518 case 'j':
2519 m_json.SetCurrentValue(true);
2520 m_json.SetOptionWasSet();
2521 break;
2522 case 'e':
2523 m_errors_only.SetCurrentValue(true);
2524 m_errors_only.SetOptionWasSet();
2525 break;
2526 default:
2527 llvm_unreachable("Unimplemented option");
2528 }
2529 return error;
2530 }
2531
2532 void OptionParsingStarting(ExecutionContext *execution_context) override {
2533 m_json.Clear();
2534 m_errors_only.Clear();
2535 m_load_all_debug_info.Clear();
2536 }
2537
2538 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
2539 return llvm::ArrayRef(g_target_modules_dump_separate_debug_info_options);
2540 }
2541
2545 };
2546
2547protected:
2548 void DoExecute(Args &command, CommandReturnObject &result) override {
2549 Target &target = GetTarget();
2550 uint32_t num_dumped = 0;
2551
2552 StructuredData::Array separate_debug_info_lists_by_module;
2553 if (command.GetArgumentCount() == 0) {
2554 // Dump all sections for all modules images
2555 const ModuleList &target_modules = target.GetImages();
2556 std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
2557 const size_t num_modules = target_modules.GetSize();
2558 if (num_modules == 0) {
2559 result.AppendError("the target has no associated executable images");
2560 return;
2561 }
2562 for (ModuleSP module_sp : target_modules.ModulesNoLocking()) {
2564 GetDebugger(),
2565 "Interrupted in dumping all "
2566 "separate debug info with {0} of {1} modules dumped",
2567 num_dumped, num_modules))
2568 break;
2569
2570 if (GetSeparateDebugInfoList(separate_debug_info_lists_by_module,
2571 module_sp.get(),
2572 bool(m_options.m_errors_only),
2573 bool(m_options.m_load_all_debug_info)))
2574 num_dumped++;
2575 }
2576 } else {
2577 // Dump specified images (by basename or fullpath)
2578 const char *arg_cstr;
2579 for (int arg_idx = 0;
2580 (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != nullptr;
2581 ++arg_idx) {
2582 ModuleList module_list;
2583 const size_t num_matches =
2584 FindModulesByName(&target, arg_cstr, module_list, true);
2585 if (num_matches > 0) {
2586 for (size_t i = 0; i < num_matches; ++i) {
2588 "Interrupted dumping {0} "
2589 "of {1} requested modules",
2590 i, num_matches))
2591 break;
2592 Module *module = module_list.GetModulePointerAtIndex(i);
2593 if (GetSeparateDebugInfoList(separate_debug_info_lists_by_module,
2594 module, bool(m_options.m_errors_only),
2595 bool(m_options.m_load_all_debug_info)))
2596 num_dumped++;
2597 }
2598 } else
2600 "unable to find an image that matches '{0}'", arg_cstr);
2601 }
2602 }
2603
2604 if (num_dumped > 0) {
2605 Stream &strm = result.GetOutputStream();
2606 // Display the debug info files in some format.
2607 if (m_options.m_json) {
2608 // JSON format
2609 separate_debug_info_lists_by_module.Dump(strm,
2610 /*pretty_print=*/true);
2611 } else {
2612 // Human-readable table format
2613 separate_debug_info_lists_by_module.ForEach(
2614 [&result, &strm](StructuredData::Object *obj) {
2615 if (!obj) {
2616 return false;
2617 }
2618
2619 // Each item in `separate_debug_info_lists_by_module` should be a
2620 // valid structured data dictionary.
2621 StructuredData::Dictionary *separate_debug_info_list =
2622 obj->GetAsDictionary();
2623 if (!separate_debug_info_list) {
2624 return false;
2625 }
2626
2627 llvm::StringRef type;
2628 llvm::StringRef symfile;
2629 StructuredData::Array *files;
2630 if (!(separate_debug_info_list->GetValueForKeyAsString("type",
2631 type) &&
2632 separate_debug_info_list->GetValueForKeyAsString("symfile",
2633 symfile) &&
2634 separate_debug_info_list->GetValueForKeyAsArray(
2635 "separate-debug-info-files", files))) {
2636 assert(false);
2637 }
2638
2639 strm << "Symbol file: " << symfile;
2640 strm.EOL();
2641 strm << "Type: \"" << type << "\"";
2642 strm.EOL();
2643 if (type == "dwo") {
2644 DumpDwoFilesTable(strm, *files);
2645 } else if (type == "oso") {
2646 DumpOsoFilesTable(strm, *files);
2647 } else {
2649 "found unsupported debug info type '{0}'", type);
2650 }
2651 return true;
2652 });
2653 }
2655 } else {
2656 result.AppendError("no matching executable images found");
2657 }
2658 }
2659
2661};
2662
2663#pragma mark CommandObjectTargetModulesDump
2664
2665// Dump multi-word command for target modules
2666
2668public:
2669 // Constructors and Destructors
2672 interpreter, "target modules dump",
2673 "Commands for dumping information about one or more target "
2674 "modules.",
2675 "target modules dump "
2676 "[objfile|symtab|sections|ast|symfile|line-table|pcm-info|separate-"
2677 "debug-info] "
2678 "[<file1> <file2> ...]") {
2679 LoadSubCommand("objfile",
2681 new CommandObjectTargetModulesDumpObjfile(interpreter)));
2683 "symtab",
2685 LoadSubCommand("sections",
2687 interpreter)));
2688 LoadSubCommand("symfile",
2690 new CommandObjectTargetModulesDumpSymfile(interpreter)));
2692 "ast", CommandObjectSP(
2693 new CommandObjectTargetModulesDumpClangAST(interpreter)));
2694 LoadSubCommand("line-table",
2696 interpreter)));
2698 "pcm-info",
2701 LoadSubCommand("separate-debug-info",
2704 interpreter)));
2705 }
2706
2708};
2709
2711public:
2713 : CommandObjectParsed(interpreter, "target modules add",
2714 "Add a new module to the current target's modules.",
2715 "target modules add [<module>]",
2716 eCommandRequiresTarget),
2717 m_symbol_file(LLDB_OPT_SET_1, false, "symfile", 's', 0,
2719 "Fullpath to a stand alone debug "
2720 "symbols file for when debug symbols "
2721 "are not in the executable.") {
2725 m_option_group.Finalize();
2727 }
2728
2730
2731 Options *GetOptions() override { return &m_option_group; }
2732
2733protected:
2737
2738 void DoExecute(Args &args, CommandReturnObject &result) override {
2739 Target &target = GetTarget();
2740 bool flush = false;
2741
2742 const size_t argc = args.GetArgumentCount();
2743 if (argc == 0) {
2744 if (m_uuid_option_group.GetOptionValue().OptionWasSet()) {
2745 // We are given a UUID only, go locate the file
2746 ModuleSpec module_spec;
2747 module_spec.GetUUID() =
2748 m_uuid_option_group.GetOptionValue().GetCurrentValue();
2749 if (m_symbol_file.GetOptionValue().OptionWasSet())
2750 module_spec.GetSymbolFileSpec() =
2751 m_symbol_file.GetOptionValue().GetCurrentValue();
2752 Status error;
2754 ModuleSP module_sp(
2755 target.GetOrCreateModule(module_spec, true /* notify */));
2756 if (module_sp) {
2758 return;
2759 } else {
2760 StreamString strm;
2761 module_spec.GetUUID().Dump(strm);
2762 if (module_spec.GetFileSpec()) {
2763 if (module_spec.GetSymbolFileSpec()) {
2764 result.AppendErrorWithFormat(
2765 "Unable to create the executable or symbol file with "
2766 "UUID %s with path %s and symbol file %s",
2767 strm.GetData(), module_spec.GetFileSpec().GetPath().c_str(),
2768 module_spec.GetSymbolFileSpec().GetPath().c_str());
2769 } else {
2770 result.AppendErrorWithFormat(
2771 "Unable to create the executable or symbol file with "
2772 "UUID %s with path %s",
2773 strm.GetData(),
2774 module_spec.GetFileSpec().GetPath().c_str());
2775 }
2776 } else {
2777 result.AppendErrorWithFormat("Unable to create the executable "
2778 "or symbol file with UUID %s",
2779 strm.GetData());
2780 }
2781 return;
2782 }
2783 } else {
2784 StreamString strm;
2785 module_spec.GetUUID().Dump(strm);
2786 result.AppendErrorWithFormat(
2787 "Unable to locate the executable or symbol file with UUID %s",
2788 strm.GetData());
2789 result.SetError(std::move(error));
2790 return;
2791 }
2792 } else {
2793 result.AppendError(
2794 "one or more executable image paths must be specified");
2795 return;
2796 }
2797 } else {
2798 for (auto &entry : args.entries()) {
2799 if (entry.ref().empty())
2800 continue;
2801
2802 FileSpec file_spec(entry.ref());
2803 if (FileSystem::Instance().Exists(file_spec)) {
2804 ModuleSpec module_spec(file_spec);
2805 if (m_uuid_option_group.GetOptionValue().OptionWasSet())
2806 module_spec.GetUUID() =
2807 m_uuid_option_group.GetOptionValue().GetCurrentValue();
2808 if (m_symbol_file.GetOptionValue().OptionWasSet())
2809 module_spec.GetSymbolFileSpec() =
2810 m_symbol_file.GetOptionValue().GetCurrentValue();
2811 if (!module_spec.GetArchitecture().IsValid())
2812 module_spec.GetArchitecture() = target.GetArchitecture();
2813 Status error;
2814 ModuleSP module_sp(
2815 target.GetOrCreateModule(module_spec, true /* notify */, &error));
2816 if (!module_sp) {
2817 const char *error_cstr = error.AsCString();
2818 if (error_cstr)
2819 result.AppendError(error_cstr);
2820 else
2821 result.AppendErrorWithFormat("unsupported module: %s",
2822 entry.c_str());
2823 return;
2824 } else {
2825 flush = true;
2826 }
2828 } else {
2829 std::string resolved_path = file_spec.GetPath();
2830 if (resolved_path != entry.ref()) {
2831 result.AppendErrorWithFormat(
2832 "invalid module path '%s' with resolved path '%s'\n",
2833 entry.ref().str().c_str(), resolved_path.c_str());
2834 break;
2835 }
2836 result.AppendErrorWithFormat("invalid module path '%s'\n",
2837 entry.c_str());
2838 break;
2839 }
2840 }
2841 }
2842
2843 if (flush) {
2844 ProcessSP process = target.GetProcessSP();
2845 if (process)
2846 process->Flush();
2847 }
2848 }
2849};
2850
2853public:
2856 interpreter, "target modules load",
2857 "Set the load addresses for one or more sections in a target "
2858 "module.",
2859 "target modules load [--file <module> --uuid <uuid>] <sect-name> "
2860 "<address> [<sect-name> <address> ....]",
2861 eCommandRequiresTarget),
2862 m_file_option(LLDB_OPT_SET_1, false, "file", 'f', 0, eArgTypeName,
2863 "Fullpath or basename for module to load.", ""),
2864 m_load_option(LLDB_OPT_SET_1, false, "load", 'l',
2865 "Write file contents to the memory.", false, true),
2866 m_pc_option(LLDB_OPT_SET_1, false, "set-pc-to-entry", 'p',
2867 "Set PC to the entry point."
2868 " Only applicable with '--load' option.",
2869 false, true),
2870 m_slide_option(LLDB_OPT_SET_1, false, "slide", 's', 0, eArgTypeOffset,
2871 "Set the load address for all sections to be the "
2872 "virtual address in the file plus the offset.",
2873 0) {
2880 m_option_group.Finalize();
2881 }
2882
2884
2885 Options *GetOptions() override { return &m_option_group; }
2886
2887protected:
2888 void DoExecute(Args &args, CommandReturnObject &result) override {
2889 Target &target = GetTarget();
2890 const bool load = m_load_option.GetOptionValue().GetCurrentValue();
2891 const bool set_pc = m_pc_option.GetOptionValue().GetCurrentValue();
2892
2893 const size_t argc = args.GetArgumentCount();
2894 ModuleSpec module_spec;
2895 bool search_using_module_spec = false;
2896
2897 // Allow "load" option to work without --file or --uuid option.
2898 if (load) {
2899 if (!m_file_option.GetOptionValue().OptionWasSet() &&
2900 !m_uuid_option_group.GetOptionValue().OptionWasSet()) {
2901 ModuleList &module_list = target.GetImages();
2902 if (module_list.GetSize() == 1) {
2903 search_using_module_spec = true;
2904 module_spec.GetFileSpec() =
2905 module_list.GetModuleAtIndex(0)->GetFileSpec();
2906 }
2907 }
2908 }
2909
2910 if (m_file_option.GetOptionValue().OptionWasSet()) {
2911 search_using_module_spec = true;
2912 const char *arg_cstr = m_file_option.GetOptionValue().GetCurrentValue();
2913 const bool use_global_module_list = true;
2914 ModuleList module_list;
2915 const size_t num_matches = FindModulesByName(
2916 &target, arg_cstr, module_list, use_global_module_list);
2917 if (num_matches == 1) {
2918 module_spec.GetFileSpec() =
2919 module_list.GetModuleAtIndex(0)->GetFileSpec();
2920 } else if (num_matches > 1) {
2921 search_using_module_spec = false;
2922 result.AppendErrorWithFormat(
2923 "more than 1 module matched by name '%s'\n", arg_cstr);
2924 } else {
2925 search_using_module_spec = false;
2926 result.AppendErrorWithFormat("no object file for module '%s'\n",
2927 arg_cstr);
2928 }
2929 }
2930
2931 if (m_uuid_option_group.GetOptionValue().OptionWasSet()) {
2932 search_using_module_spec = true;
2933 module_spec.GetUUID() =
2934 m_uuid_option_group.GetOptionValue().GetCurrentValue();
2935 }
2936
2937 if (search_using_module_spec) {
2938 ModuleList matching_modules;
2939 target.GetImages().FindModules(module_spec, matching_modules);
2940 const size_t num_matches = matching_modules.GetSize();
2941
2942 char path[PATH_MAX];
2943 if (num_matches == 1) {
2944 Module *module = matching_modules.GetModulePointerAtIndex(0);
2945 if (module) {
2946 ObjectFile *objfile = module->GetObjectFile();
2947 if (objfile) {
2948 SectionList *section_list = module->GetSectionList();
2949 if (section_list) {
2950 bool changed = false;
2951 if (argc == 0) {
2952 if (m_slide_option.GetOptionValue().OptionWasSet()) {
2953 const addr_t slide =
2954 m_slide_option.GetOptionValue().GetCurrentValue();
2955 const bool slide_is_offset = true;
2956 module->SetLoadAddress(target, slide, slide_is_offset,
2957 changed);
2958 } else {
2959 result.AppendError("one or more section name + load "
2960 "address pair must be specified");
2961 return;
2962 }
2963 } else {
2964 if (m_slide_option.GetOptionValue().OptionWasSet()) {
2965 result.AppendError("The \"--slide <offset>\" option can't "
2966 "be used in conjunction with setting "
2967 "section load addresses.\n");
2968 return;
2969 }
2970
2971 for (size_t i = 0; i < argc; i += 2) {
2972 const char *sect_name = args.GetArgumentAtIndex(i);
2973 const char *load_addr_cstr = args.GetArgumentAtIndex(i + 1);
2974 if (sect_name && load_addr_cstr) {
2975 ConstString const_sect_name(sect_name);
2976 addr_t load_addr;
2977 if (llvm::to_integer(load_addr_cstr, load_addr)) {
2978 SectionSP section_sp(
2979 section_list->FindSectionByName(const_sect_name));
2980 if (section_sp) {
2981 if (section_sp->IsThreadSpecific()) {
2982 result.AppendErrorWithFormat(
2983 "thread specific sections are not yet "
2984 "supported (section '%s')\n",
2985 sect_name);
2986 break;
2987 } else {
2988 if (target.SetSectionLoadAddress(section_sp,
2989 load_addr))
2990 changed = true;
2992 "section '{0}' loaded at {1:x}", sect_name,
2993 load_addr);
2994 }
2995 } else {
2996 result.AppendErrorWithFormat("no section found that "
2997 "matches the section "
2998 "name '%s'\n",
2999 sect_name);
3000 break;
3001 }
3002 } else {
3003 result.AppendErrorWithFormat(
3004 "invalid load address string '%s'\n", load_addr_cstr);
3005 break;
3006 }
3007 } else {
3008 if (sect_name)
3009 result.AppendError("section names must be followed by "
3010 "a load address.\n");
3011 else
3012 result.AppendError("one or more section name + load "
3013 "address pair must be specified.\n");
3014 break;
3015 }
3016 }
3017 }
3018
3019 if (changed) {
3020 target.ModulesDidLoad(matching_modules);
3021 Process *process = m_exe_ctx.GetProcessPtr();
3022 if (process)
3023 process->Flush();
3024 }
3025 if (load) {
3026 ProcessSP process = target.CalculateProcess();
3027 Address file_entry = objfile->GetEntryPointAddress();
3028 if (!process) {
3029 result.AppendError("No process");
3030 return;
3031 }
3032 if (set_pc && !file_entry.IsValid()) {
3033 result.AppendError("No entry address in object file");
3034 return;
3035 }
3036 std::vector<ObjectFile::LoadableData> loadables(
3037 objfile->GetLoadableData(target));
3038 if (loadables.size() == 0) {
3039 result.AppendError("No loadable sections");
3040 return;
3041 }
3042 Status error = process->WriteObjectFile(std::move(loadables));
3043 if (error.Fail()) {
3044 result.AppendError(error.AsCString());
3045 return;
3046 }
3047 if (set_pc) {
3048 ThreadList &thread_list = process->GetThreadList();
3049 RegisterContextSP reg_context(
3050 thread_list.GetSelectedThread()->GetRegisterContext());
3051 addr_t file_entry_addr = file_entry.GetLoadAddress(&target);
3052 if (!reg_context->SetPC(file_entry_addr)) {
3053 result.AppendErrorWithFormat("failed to set PC value to "
3054 "0x%" PRIx64 "\n",
3055 file_entry_addr);
3056 }
3057 }
3058 }
3059 } else {
3060 module->GetFileSpec().GetPath(path, sizeof(path));
3061 result.AppendErrorWithFormat("no sections in object file '%s'\n",
3062 path);
3063 }
3064 } else {
3065 module->GetFileSpec().GetPath(path, sizeof(path));
3066 result.AppendErrorWithFormat("no object file for module '%s'\n",
3067 path);
3068 }
3069 } else {
3070 FileSpec *module_spec_file = module_spec.GetFileSpecPtr();
3071 if (module_spec_file) {
3072 module_spec_file->GetPath(path, sizeof(path));
3073 result.AppendErrorWithFormat("invalid module '%s'.\n", path);
3074 } else
3075 result.AppendError("no module spec");
3076 }
3077 } else {
3078 std::string uuid_str;
3079
3080 if (module_spec.GetFileSpec())
3081 module_spec.GetFileSpec().GetPath(path, sizeof(path));
3082 else
3083 path[0] = '\0';
3084
3085 if (module_spec.GetUUIDPtr())
3086 uuid_str = module_spec.GetUUID().GetAsString();
3087 if (num_matches > 1) {
3088 result.AppendErrorWithFormat(
3089 "multiple modules match%s%s%s%s:\n", path[0] ? " file=" : "",
3090 path, !uuid_str.empty() ? " uuid=" : "", uuid_str.c_str());
3091 for (size_t i = 0; i < num_matches; ++i) {
3092 if (matching_modules.GetModulePointerAtIndex(i)
3093 ->GetFileSpec()
3094 .GetPath(path, sizeof(path)))
3095 result.AppendMessageWithFormatv("{0}", path);
3096 }
3097 } else {
3098 result.AppendErrorWithFormat(
3099 "no modules were found that match%s%s%s%s.\n",
3100 path[0] ? " file=" : "", path, !uuid_str.empty() ? " uuid=" : "",
3101 uuid_str.c_str());
3102 }
3103 }
3104 } else {
3105 result.AppendError("either the \"--file <module>\" or the \"--uuid "
3106 "<uuid>\" option must be specified.\n");
3107 }
3108 }
3109
3116};
3117
3118#pragma mark CommandObjectTargetModulesList
3119// List images with associated information
3120#define LLDB_OPTIONS_target_modules_list
3121#include "CommandOptions.inc"
3122
3124public:
3125 class CommandOptions : public Options {
3126 public:
3127 CommandOptions() = default;
3128
3129 ~CommandOptions() override = default;
3130
3131 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
3132 ExecutionContext *execution_context) override {
3133 Status error;
3134
3135 const int short_option = m_getopt_table[option_idx].val;
3136 if (short_option == 'g') {
3138 } else if (short_option == 'a') {
3140 execution_context, option_arg, LLDB_INVALID_ADDRESS, &error);
3141 } else {
3142 unsigned long width = 0;
3143 option_arg.getAsInteger(0, width);
3144 m_format_array.push_back(std::make_pair(short_option, width));
3145 }
3146 return error;
3147 }
3148
3149 void OptionParsingStarting(ExecutionContext *execution_context) override {
3150 m_format_array.clear();
3153 }
3154
3155 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
3156 return llvm::ArrayRef(g_target_modules_list_options);
3157 }
3158
3159 // Instance variables to hold the values for command options.
3160 typedef std::vector<std::pair<char, uint32_t>> FormatWidthCollection;
3164 };
3165
3168 interpreter, "target modules list",
3169 "List current executable and dependent shared library images.") {
3171 }
3172
3174
3175 Options *GetOptions() override { return &m_options; }
3176
3177protected:
3178 void DoExecute(Args &command, CommandReturnObject &result) override {
3179 Target &target = GetTarget();
3180 const bool use_global_module_list = m_options.m_use_global_module_list;
3181 // Define a local module list here to ensure it lives longer than any
3182 // "locker" object which might lock its contents below (through the
3183 // "module_list_ptr" variable).
3184 ModuleList module_list;
3185 // Dump all sections for all modules images
3186 Stream &strm = result.GetOutputStream();
3187
3188 if (m_options.m_module_addr != LLDB_INVALID_ADDRESS) {
3189 Address module_address;
3190 if (module_address.SetLoadAddress(m_options.m_module_addr, &target)) {
3191 ModuleSP module_sp(module_address.GetModule());
3192 if (module_sp) {
3193 PrintModule(target, module_sp.get(), 0, strm);
3195 } else {
3196 result.AppendErrorWithFormat(
3197 "Couldn't find module matching address: 0x%" PRIx64 ".",
3198 m_options.m_module_addr);
3199 }
3200 } else {
3201 result.AppendErrorWithFormat(
3202 "Couldn't find module containing address: 0x%" PRIx64 ".",
3203 m_options.m_module_addr);
3204 }
3205 return;
3206 }
3207
3208 size_t num_modules = 0;
3209
3210 // This locker will be locked on the mutex in module_list_ptr if it is
3211 // non-nullptr. Otherwise it will lock the
3212 // AllocationModuleCollectionMutex when accessing the global module list
3213 // directly.
3214 std::unique_lock<std::recursive_mutex> guard(
3216
3217 const ModuleList *module_list_ptr = nullptr;
3218 const size_t argc = command.GetArgumentCount();
3219 if (argc == 0) {
3220 if (use_global_module_list) {
3221 guard.lock();
3222 num_modules = Module::GetNumberAllocatedModules();
3223 } else {
3224 module_list_ptr = &target.GetImages();
3225 }
3226 } else {
3227 for (const Args::ArgEntry &arg : command) {
3228 // Dump specified images (by basename or fullpath)
3229 const size_t num_matches = FindModulesByName(
3230 &target, arg.c_str(), module_list, use_global_module_list);
3231 if (num_matches == 0) {
3232 if (argc == 1) {
3233 result.AppendErrorWithFormat("no modules found that match '%s'",
3234 arg.c_str());
3235 return;
3236 }
3237 }
3238 }
3239
3240 module_list_ptr = &module_list;
3241 }
3242
3243 std::unique_lock<std::recursive_mutex> lock;
3244 if (module_list_ptr != nullptr) {
3245 lock =
3246 std::unique_lock<std::recursive_mutex>(module_list_ptr->GetMutex());
3247
3248 num_modules = module_list_ptr->GetSize();
3249 }
3250
3251 if (num_modules > 0) {
3252 for (uint32_t image_idx = 0; image_idx < num_modules; ++image_idx) {
3253 ModuleSP module_sp;
3254 Module *module;
3255 if (module_list_ptr) {
3256 module_sp = module_list_ptr->GetModuleAtIndexUnlocked(image_idx);
3257 module = module_sp.get();
3258 } else {
3259 module = Module::GetAllocatedModuleAtIndex(image_idx);
3260 module_sp = module->shared_from_this();
3261 }
3262
3263 const size_t indent = strm.Printf("[%3u] ", image_idx);
3264 PrintModule(target, module, indent, strm);
3265 }
3267 } else {
3268 if (argc) {
3269 if (use_global_module_list)
3270 result.AppendError(
3271 "the global module list has no matching modules");
3272 else
3273 result.AppendError("the target has no matching modules");
3274 } else {
3275 if (use_global_module_list)
3276 result.AppendError("the global module list is empty");
3277 else
3278 result.AppendError(
3279 "the target has no associated executable images");
3280 }
3281 return;
3282 }
3283 }
3284
3285 void PrintModule(Target &target, Module *module, int indent, Stream &strm) {
3286 if (module == nullptr) {
3287 strm.PutCString("Null module");
3288 return;
3289 }
3290
3291 bool dump_object_name = false;
3292 if (m_options.m_format_array.empty()) {
3293 m_options.m_format_array.push_back(std::make_pair('u', 0));
3294 m_options.m_format_array.push_back(std::make_pair('h', 0));
3295 m_options.m_format_array.push_back(std::make_pair('f', 0));
3296 m_options.m_format_array.push_back(std::make_pair('S', 0));
3297 }
3298 const size_t num_entries = m_options.m_format_array.size();
3299 bool print_space = false;
3300 for (size_t i = 0; i < num_entries; ++i) {
3301 if (print_space)
3302 strm.PutChar(' ');
3303 print_space = true;
3304 const char format_char = m_options.m_format_array[i].first;
3305 uint32_t width = m_options.m_format_array[i].second;
3306 switch (format_char) {
3307 case 'A':
3308 DumpModuleArchitecture(strm, module, false, width);
3309 break;
3310
3311 case 't':
3312 DumpModuleArchitecture(strm, module, true, width);
3313 break;
3314
3315 case 'f':
3316 DumpFullpath(strm, &module->GetFileSpec(), width);
3317 dump_object_name = true;
3318 break;
3319
3320 case 'd':
3321 DumpDirectory(strm, &module->GetFileSpec(), width);
3322 break;
3323
3324 case 'b':
3325 DumpBasename(strm, &module->GetFileSpec(), width);
3326 dump_object_name = true;
3327 break;
3328
3329 case 'h':
3330 case 'o':
3331 // Image header address
3332 {
3333 uint32_t addr_nibble_width =
3334 target.GetArchitecture().GetAddressByteSize() * 2;
3335
3336 ObjectFile *objfile = module->GetObjectFile();
3337 if (objfile) {
3338 Address base_addr(objfile->GetBaseAddress());
3339 if (base_addr.IsValid()) {
3340 if (target.HasLoadedSections()) {
3341 lldb::addr_t load_addr = base_addr.GetLoadAddress(&target);
3342 if (load_addr == LLDB_INVALID_ADDRESS) {
3343 base_addr.Dump(&strm, &target,
3346 } else {
3347 if (format_char == 'o') {
3348 // Show the offset of slide for the image
3349 strm.Printf("0x%*.*" PRIx64, addr_nibble_width,
3350 addr_nibble_width,
3351 load_addr - base_addr.GetFileAddress());
3352 } else {
3353 // Show the load address of the image
3354 strm.Printf("0x%*.*" PRIx64, addr_nibble_width,
3355 addr_nibble_width, load_addr);
3356 }
3357 }
3358 break;
3359 }
3360 // The address was valid, but the image isn't loaded, output the
3361 // address in an appropriate format
3362 base_addr.Dump(&strm, &target, Address::DumpStyleFileAddress);
3363 break;
3364 }
3365 }
3366 strm.Printf("%*s", addr_nibble_width + 2, "");
3367 }
3368 break;
3369
3370 case 'r': {
3371 size_t ref_count = 0;
3372 char in_shared_cache = 'Y';
3373
3374 ModuleSP module_sp(module->shared_from_this());
3375 if (!ModuleList::ModuleIsInCache(module))
3376 in_shared_cache = 'N';
3377 if (module_sp) {
3378 // Take one away to make sure we don't count our local "module_sp"
3379 ref_count = module_sp.use_count() - 1;
3380 }
3381 if (width)
3382 strm.Printf("{%c %*" PRIu64 "}", in_shared_cache, width, (uint64_t)ref_count);
3383 else
3384 strm.Printf("{%c %" PRIu64 "}", in_shared_cache, (uint64_t)ref_count);
3385 } break;
3386
3387 case 's':
3388 case 'S': {
3389 if (const SymbolFile *symbol_file = module->GetSymbolFile()) {
3390 const FileSpec symfile_spec =
3391 symbol_file->GetObjectFile()->GetFileSpec();
3392 if (format_char == 'S') {
3393 // Dump symbol file only if different from module file
3394 if (!symfile_spec || symfile_spec == module->GetFileSpec()) {
3395 print_space = false;
3396 break;
3397 }
3398 // Add a newline and indent past the index
3399 strm.Printf("\n%*s", indent, "");
3400 }
3401 DumpFullpath(strm, &symfile_spec, width);
3402 dump_object_name = true;
3403 break;
3404 }
3405 strm.Printf("%.*s", width, "<NONE>");
3406 } break;
3407
3408 case 'm':
3409 strm.Format("{0:%c}", llvm::fmt_align(module->GetModificationTime(),
3410 llvm::AlignStyle::Left, width));
3411 break;
3412
3413 case 'p':
3414 strm.Printf("%p", static_cast<void *>(module));
3415 break;
3416
3417 case 'u':
3418 DumpModuleUUID(strm, module);
3419 break;
3420
3421 default:
3422 break;
3423 }
3424 }
3425 if (dump_object_name) {
3426 const char *object_name = module->GetObjectName().GetCString();
3427 if (object_name)
3428 strm.Printf("(%s)", object_name);
3429 }
3430 strm.EOL();
3431 }
3432
3434};
3435
3436#pragma mark CommandObjectTargetModulesShowUnwind
3437
3438// Lookup unwind information in images
3439#define LLDB_OPTIONS_target_modules_show_unwind
3440#include "CommandOptions.inc"
3441
3443public:
3444 enum {
3451 };
3452
3453 class CommandOptions : public Options {
3454 public:
3455 CommandOptions() = default;
3456
3457 ~CommandOptions() override = default;
3458
3459 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
3460 ExecutionContext *execution_context) override {
3461 Status error;
3462
3463 const int short_option = m_getopt_table[option_idx].val;
3464
3465 switch (short_option) {
3466 case 'a': {
3467 m_str = std::string(option_arg);
3469 m_addr = OptionArgParser::ToAddress(execution_context, option_arg,
3473 "invalid address string '%s'", option_arg.str().c_str());
3474 break;
3475 }
3476
3477 case 'n':
3478 m_str = std::string(option_arg);
3480 break;
3481
3482 case 'c':
3483 bool value, success;
3484 value = OptionArgParser::ToBoolean(option_arg, false, &success);
3485 if (success) {
3486 m_cached = value;
3487 } else {
3489 "invalid boolean value '%s' passed for -c option", option_arg);
3490 }
3491 break;
3492
3493 default:
3494 llvm_unreachable("Unimplemented option");
3495 }
3496
3497 return error;
3498 }
3499
3500 void OptionParsingStarting(ExecutionContext *execution_context) override {
3502 m_str.clear();
3504 m_cached = false;
3505 }
3506
3507 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
3508 return llvm::ArrayRef(g_target_modules_show_unwind_options);
3509 }
3510
3511 // Instance variables to hold the values for command options.
3512
3513 int m_type = eLookupTypeInvalid; // Should be a eLookupTypeXXX enum after
3514 // parsing options
3515 std::string m_str; // Holds name lookup
3516 lldb::addr_t m_addr = LLDB_INVALID_ADDRESS; // Holds the address to lookup
3517 bool m_cached = true;
3518 };
3519
3522 interpreter, "target modules show-unwind",
3523 "Show synthesized unwind instructions for a function.", nullptr,
3524 eCommandRequiresTarget | eCommandRequiresProcess |
3525 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
3526
3528
3529 Options *GetOptions() override { return &m_options; }
3530
3531protected:
3532 void DoExecute(Args &command, CommandReturnObject &result) override {
3533 Target *target = m_exe_ctx.GetTargetPtr();
3534 Process *process = m_exe_ctx.GetProcessPtr();
3535 ABI *abi = nullptr;
3536 if (process)
3537 abi = process->GetABI().get();
3538
3539 if (process == nullptr) {
3540 result.AppendError(
3541 "You must have a process running to use this command.");
3542 return;
3543 }
3544
3545 ThreadList threads(process->GetThreadList());
3546 if (threads.GetSize() == 0) {
3547 result.AppendError("the process must be paused to use this command");
3548 return;
3549 }
3550
3551 ThreadSP thread(threads.GetThreadAtIndex(0));
3552 if (!thread) {
3553 result.AppendError("the process must be paused to use this command");
3554 return;
3555 }
3556
3557 SymbolContextList sc_list;
3558
3559 if (m_options.m_type == eLookupTypeFunctionOrSymbol) {
3560 ConstString function_name(m_options.m_str.c_str());
3561 ModuleFunctionSearchOptions function_options;
3562 function_options.include_symbols = true;
3563 function_options.include_inlines = false;
3564 target->GetImages().FindFunctions(function_name, eFunctionNameTypeAuto,
3565 function_options, sc_list);
3566 } else if (m_options.m_type == eLookupTypeAddress && target) {
3567 Address addr;
3568 if (target->ResolveLoadAddress(m_options.m_addr, addr)) {
3569 SymbolContext sc;
3570 ModuleSP module_sp(addr.GetModule());
3571 module_sp->ResolveSymbolContextForAddress(addr,
3572 eSymbolContextEverything, sc);
3573 if (sc.function || sc.symbol) {
3574 sc_list.Append(sc);
3575 }
3576 }
3577 } else {
3578 result.AppendError(
3579 "address-expression or function name option must be specified.");
3580 return;
3581 }
3582
3583 if (sc_list.GetSize() == 0) {
3584 result.AppendErrorWithFormat("no unwind data found that matches '%s'.",
3585 m_options.m_str.c_str());
3586 return;
3587 }
3588
3589 for (const SymbolContext &sc : sc_list) {
3590 if (sc.symbol == nullptr && sc.function == nullptr)
3591 continue;
3592 if (!sc.module_sp || sc.module_sp->GetObjectFile() == nullptr)
3593 continue;
3594 Address addr = sc.GetFunctionOrSymbolAddress();
3595 if (!addr.IsValid())
3596 continue;
3597 ConstString funcname(sc.GetFunctionName());
3598 if (funcname.IsEmpty())
3599 continue;
3600 addr_t start_addr = addr.GetLoadAddress(target);
3601 if (abi)
3602 start_addr = abi->FixCodeAddress(start_addr);
3603
3604 UnwindTable &uw_table = sc.module_sp->GetUnwindTable();
3605 FuncUnwindersSP func_unwinders_sp =
3606 m_options.m_cached
3607 ? uw_table.GetFuncUnwindersContainingAddress(Address(start_addr),
3608 sc)
3610 Address(start_addr), sc);
3611 if (!func_unwinders_sp)
3612 continue;
3613
3614 result.GetOutputStream().Format(
3615 "UNWIND PLANS for {0}`{1} (start addr {2:x})\n",
3616 sc.module_sp->GetPlatformFileSpec().GetFilename(), funcname,
3617 start_addr);
3618
3619 Args args;
3621 size_t count = args.GetArgumentCount();
3622 for (size_t i = 0; i < count; i++) {
3623 const char *trap_func_name = args.GetArgumentAtIndex(i);
3624 if (strcmp(funcname.GetCString(), trap_func_name) == 0)
3625 result.GetOutputStream().Printf(
3626 "This function is "
3627 "treated as a trap handler function via user setting.\n");
3628 }
3629 PlatformSP platform_sp(target->GetPlatform());
3630 if (platform_sp) {
3631 const std::vector<ConstString> trap_handler_names(
3632 platform_sp->GetTrapHandlerSymbolNames());
3633 for (ConstString trap_name : trap_handler_names) {
3634 if (trap_name == funcname) {
3635 result.GetOutputStream().Printf(
3636 "This function's "
3637 "name is listed by the platform as a trap handler.\n");
3638 }
3639 }
3640 }
3641
3642 result.GetOutputStream().Printf("\n");
3643
3644 if (std::shared_ptr<const UnwindPlan> plan_sp =
3645 func_unwinders_sp->GetUnwindPlanAtNonCallSite(*target, *thread)) {
3646 result.GetOutputStream().Format(
3647 "Asynchronous (not restricted to call-sites) UnwindPlan is '{0}'\n",
3648 plan_sp->GetSourceName());
3649 }
3650 if (std::shared_ptr<const UnwindPlan> plan_sp =
3651 func_unwinders_sp->GetUnwindPlanAtCallSite(*target, *thread)) {
3652 result.GetOutputStream().Format(
3653 "Synchronous (restricted to call-sites) UnwindPlan is '{0}'\n",
3654 plan_sp->GetSourceName());
3655 }
3656 if (std::shared_ptr<const UnwindPlan> plan_sp =
3657 func_unwinders_sp->GetUnwindPlanFastUnwind(*target, *thread)) {
3658 result.GetOutputStream().Format("Fast UnwindPlan is '{0}'\n",
3659 plan_sp->GetSourceName());
3660 }
3661
3662 result.GetOutputStream().Printf("\n");
3663
3664 if (std::shared_ptr<const UnwindPlan> plan_sp =
3665 func_unwinders_sp->GetAssemblyUnwindPlan(*target, *thread)) {
3666 result.GetOutputStream().Printf(
3667 "Assembly language inspection UnwindPlan:\n");
3668 plan_sp->Dump(result.GetOutputStream(), thread.get(),
3670 result.GetOutputStream().Printf("\n");
3671 }
3672
3673 if (std::shared_ptr<const UnwindPlan> plan_sp =
3674 func_unwinders_sp->GetObjectFileUnwindPlan(*target)) {
3675 result.GetOutputStream().Printf("object file UnwindPlan:\n");
3676 plan_sp->Dump(result.GetOutputStream(), thread.get(),
3678 result.GetOutputStream().Printf("\n");
3679 }
3680
3681 if (std::shared_ptr<const UnwindPlan> plan_sp =
3682 func_unwinders_sp->GetObjectFileAugmentedUnwindPlan(*target,
3683 *thread)) {
3684 result.GetOutputStream().Printf("object file augmented UnwindPlan:\n");
3685 plan_sp->Dump(result.GetOutputStream(), thread.get(),
3687 result.GetOutputStream().Printf("\n");
3688 }
3689
3690 if (std::shared_ptr<const UnwindPlan> plan_sp =
3691 func_unwinders_sp->GetEHFrameUnwindPlan(*target)) {
3692 result.GetOutputStream().Printf("eh_frame UnwindPlan:\n");
3693 plan_sp->Dump(result.GetOutputStream(), thread.get(),
3695 result.GetOutputStream().Printf("\n");
3696 }
3697
3698 if (std::shared_ptr<const UnwindPlan> plan_sp =
3699 func_unwinders_sp->GetEHFrameAugmentedUnwindPlan(*target,
3700 *thread)) {
3701 result.GetOutputStream().Printf("eh_frame augmented UnwindPlan:\n");
3702 plan_sp->Dump(result.GetOutputStream(), thread.get(),
3704 result.GetOutputStream().Printf("\n");
3705 }
3706
3707 if (std::shared_ptr<const UnwindPlan> plan_sp =
3708 func_unwinders_sp->GetDebugFrameUnwindPlan(*target)) {
3709 result.GetOutputStream().Printf("debug_frame UnwindPlan:\n");
3710 plan_sp->Dump(result.GetOutputStream(), thread.get(),
3712 result.GetOutputStream().Printf("\n");
3713 }
3714
3715 if (std::shared_ptr<const UnwindPlan> plan_sp =
3716 func_unwinders_sp->GetDebugFrameAugmentedUnwindPlan(*target,
3717 *thread)) {
3718 result.GetOutputStream().Printf("debug_frame augmented UnwindPlan:\n");
3719 plan_sp->Dump(result.GetOutputStream(), thread.get(),
3721 result.GetOutputStream().Printf("\n");
3722 }
3723
3724 if (std::shared_ptr<const UnwindPlan> plan_sp =
3725 func_unwinders_sp->GetArmUnwindUnwindPlan(*target)) {
3726 result.GetOutputStream().Printf("ARM.exidx unwind UnwindPlan:\n");
3727 plan_sp->Dump(result.GetOutputStream(), thread.get(),
3729 result.GetOutputStream().Printf("\n");
3730 }
3731
3732 if (std::shared_ptr<const UnwindPlan> plan_sp =
3733 func_unwinders_sp->GetSymbolFileUnwindPlan(*thread)) {
3734 result.GetOutputStream().Printf("Symbol file UnwindPlan:\n");
3735 plan_sp->Dump(result.GetOutputStream(), thread.get(),
3737 result.GetOutputStream().Printf("\n");
3738 }
3739
3740 if (std::shared_ptr<const UnwindPlan> plan_sp =
3741 func_unwinders_sp->GetCompactUnwindUnwindPlan(*target)) {
3742 result.GetOutputStream().Printf("Compact unwind UnwindPlan:\n");
3743 plan_sp->Dump(result.GetOutputStream(), thread.get(),
3745 result.GetOutputStream().Printf("\n");
3746 }
3747
3748 if (std::shared_ptr<const UnwindPlan> plan_sp =
3749 func_unwinders_sp->GetUnwindPlanFastUnwind(*target, *thread)) {
3750 result.GetOutputStream().Printf("Fast UnwindPlan:\n");
3751 plan_sp->Dump(result.GetOutputStream(), thread.get(),
3753 result.GetOutputStream().Printf("\n");
3754 }
3755
3756 ABISP abi_sp = process->GetABI();
3757 if (abi_sp) {
3758 if (UnwindPlanSP plan_sp = abi_sp->CreateDefaultUnwindPlan()) {
3759 result.GetOutputStream().Printf("Arch default UnwindPlan:\n");
3760 plan_sp->Dump(result.GetOutputStream(), thread.get(),
3762 result.GetOutputStream().Printf("\n");
3763 }
3764
3765 if (UnwindPlanSP plan_sp = abi_sp->CreateFunctionEntryUnwindPlan()) {
3766 result.GetOutputStream().Printf(
3767 "Arch default at entry point UnwindPlan:\n");
3768 plan_sp->Dump(result.GetOutputStream(), thread.get(),
3770 result.GetOutputStream().Printf("\n");
3771 }
3772 }
3773
3774 result.GetOutputStream().Printf("\n");
3775 }
3776 }
3777
3779};
3780
3781// Lookup information in images
3782#define LLDB_OPTIONS_target_modules_lookup
3783#include "CommandOptions.inc"
3784
3786public:
3787 enum {
3791 eLookupTypeFileLine, // Line is optional
3796 };
3797
3798 class CommandOptions : public Options {
3799 public:
3801
3802 ~CommandOptions() override = default;
3803
3804 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
3805 ExecutionContext *execution_context) override {
3806 Status error;
3807
3808 const int short_option = m_getopt_table[option_idx].val;
3809
3810 switch (short_option) {
3811 case 'a': {
3813 m_addr = OptionArgParser::ToAddress(execution_context, option_arg,
3815 } break;
3816
3817 case 'o':
3818 if (option_arg.getAsInteger(0, m_offset))
3820 "invalid offset string '%s'", option_arg.str().c_str());
3821 break;
3822
3823 case 's':
3824 m_str = std::string(option_arg);
3826 break;
3827
3828 case 'f':
3829 m_file.SetFile(option_arg, FileSpec::Style::native);
3831 break;
3832
3833 case 'i':
3834 m_include_inlines = false;
3835 break;
3836
3837 case 'l':
3838 if (option_arg.getAsInteger(0, m_line_number))
3840 "invalid line number string '%s'", option_arg.str().c_str());
3841 else if (m_line_number == 0)
3842 error = Status::FromErrorString("zero is an invalid line number");
3844 break;
3845
3846 case 'F':
3847 m_str = std::string(option_arg);
3849 break;
3850
3851 case 'n':
3852 m_str = std::string(option_arg);
3854 break;
3855
3856 case 't':
3857 m_str = std::string(option_arg);
3859 break;
3860
3861 case 'v':
3862 m_verbose = true;
3863 break;
3864
3865 case 'A':
3866 m_print_all = true;
3867 break;
3868
3869 case 'r':
3870 m_use_regex = true;
3871 break;
3872
3873 case '\x01':
3874 m_all_ranges = true;
3875 break;
3876 default:
3877 llvm_unreachable("Unimplemented option");
3878 }
3879
3880 return error;
3881 }
3882
3883 void OptionParsingStarting(ExecutionContext *execution_context) override {
3885 m_str.clear();
3886 m_file.Clear();
3888 m_offset = 0;
3889 m_line_number = 0;
3890 m_use_regex = false;
3891 m_include_inlines = true;
3892 m_all_ranges = false;
3893 m_verbose = false;
3894 m_print_all = false;
3895 }
3896
3897 Status OptionParsingFinished(ExecutionContext *execution_context) override {
3898 Status status;
3899 if (m_all_ranges && !m_verbose) {
3900 status =
3901 Status::FromErrorString("--show-variable-ranges must be used in "
3902 "conjunction with --verbose.");
3903 }
3904 return status;
3905 }
3906
3907 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
3908 return llvm::ArrayRef(g_target_modules_lookup_options);
3909 }
3910
3911 int m_type; // Should be a eLookupTypeXXX enum after parsing options
3912 std::string m_str; // Holds name lookup
3913 FileSpec m_file; // Files for file lookups
3914 lldb::addr_t m_addr; // Holds the address to lookup
3916 m_offset; // Subtract this offset from m_addr before doing lookups.
3917 uint32_t m_line_number; // Line number for file+line lookups
3918 bool m_use_regex; // Name lookups in m_str are regular expressions.
3919 bool m_include_inlines; // Check for inline entries when looking up by
3920 // file/line.
3921 bool m_all_ranges; // Print all ranges or single range.
3922 bool m_verbose; // Enable verbose lookup info
3923 bool m_print_all; // Print all matches, even in cases where there's a best
3924 // match.
3925 };
3926
3928 : CommandObjectParsed(interpreter, "target modules lookup",
3929 "Look up information within executable and "
3930 "dependent shared library images.",
3931 nullptr, eCommandRequiresTarget) {
3933 }
3934
3936
3937 Options *GetOptions() override { return &m_options; }
3938
3940 bool &syntax_error) {
3941 switch (m_options.m_type) {
3942 case eLookupTypeAddress:
3946 case eLookupTypeSymbol:
3947 default:
3948 return false;
3949 case eLookupTypeType:
3950 break;
3951 }
3952
3953 StackFrameSP frame = m_exe_ctx.GetFrameSP();
3954
3955 if (!frame)
3956 return false;
3957
3958 const SymbolContext &sym_ctx(frame->GetSymbolContext(eSymbolContextModule));
3959
3960 if (!sym_ctx.module_sp)
3961 return false;
3962
3963 switch (m_options.m_type) {
3964 default:
3965 return false;
3966 case eLookupTypeType:
3967 if (!m_options.m_str.empty()) {
3969 result.GetOutputStream(), *sym_ctx.module_sp,
3970 m_options.m_str.c_str(), m_options.m_use_regex)) {
3972 return true;
3973 }
3974 }
3975 break;
3976 }
3977
3978 return false;
3979 }
3980
3981 bool LookupInModule(CommandInterpreter &interpreter, Module *module,
3982 CommandReturnObject &result, bool &syntax_error) {
3983 switch (m_options.m_type) {
3984 case eLookupTypeAddress:
3985 if (m_options.m_addr != LLDB_INVALID_ADDRESS) {
3987 m_interpreter, result.GetOutputStream(), module,
3988 eSymbolContextEverything |
3989 (m_options.m_verbose
3990 ? static_cast<int>(eSymbolContextVariable)
3991 : 0),
3992 m_options.m_addr, m_options.m_offset, m_options.m_verbose,
3993 m_options.m_all_ranges)) {
3995 return true;
3996 }
3997 }
3998 break;
3999
4000 case eLookupTypeSymbol:
4001 if (!m_options.m_str.empty()) {
4003 module, m_options.m_str.c_str(),
4004 m_options.m_use_regex, m_options.m_verbose,
4005 m_options.m_all_ranges)) {
4007 return true;
4008 }
4009 }
4010 break;
4011
4013 if (m_options.m_file) {
4015 m_interpreter, result.GetOutputStream(), module,
4016 m_options.m_file, m_options.m_line_number,
4017 m_options.m_include_inlines, m_options.m_verbose,
4018 m_options.m_all_ranges)) {
4020 return true;
4021 }
4022 }
4023 break;
4024
4027 if (!m_options.m_str.empty()) {
4028 ModuleFunctionSearchOptions function_options;
4029 function_options.include_symbols =
4031 function_options.include_inlines = m_options.m_include_inlines;
4032
4034 module, m_options.m_str.c_str(),
4035 m_options.m_use_regex, function_options,
4036 m_options.m_verbose,
4037 m_options.m_all_ranges)) {
4039 return true;
4040 }
4041 }
4042 break;
4043
4044 case eLookupTypeType:
4045 if (!m_options.m_str.empty()) {
4047 &GetTarget(), m_interpreter, result.GetOutputStream(), module,
4048 m_options.m_str.c_str(), m_options.m_use_regex)) {
4050 return true;
4051 }
4052 }
4053 break;
4054
4055 default:
4056 m_options.GenerateOptionUsage(
4057 result.GetErrorStream(), *this,
4058 GetCommandInterpreter().GetDebugger().GetTerminalWidth(),
4059 GetCommandInterpreter().GetDebugger().GetUseColor());
4060 syntax_error = true;
4061 break;
4062 }
4063
4065 return false;
4066 }
4067
4068protected:
4069 void DoExecute(Args &command, CommandReturnObject &result) override {
4070 Target &target = GetTarget();
4071 bool syntax_error = false;
4072 uint32_t i;
4073 uint32_t num_successful_lookups = 0;
4074 // Dump all sections for all modules images
4075
4076 if (command.GetArgumentCount() == 0) {
4077 // Where it is possible to look in the current symbol context first,
4078 // try that. If this search was successful and --all was not passed,
4079 // don't print anything else.
4080 if (LookupHere(m_interpreter, result, syntax_error)) {
4081 result.GetOutputStream().EOL();
4082 num_successful_lookups++;
4083 if (!m_options.m_print_all) {
4085 return;
4086 }
4087 }
4088
4089 // Dump all sections for all other modules
4090
4091 const ModuleList &target_modules = target.GetImages();
4092 std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
4093 if (target_modules.GetSize() == 0) {
4094 result.AppendError("the target has no associated executable images");
4095 return;
4096 }
4097
4098 for (ModuleSP module_sp : target_modules.ModulesNoLocking()) {
4099 if (LookupInModule(m_interpreter, module_sp.get(), result,
4100 syntax_error)) {
4101 result.GetOutputStream().EOL();
4102 num_successful_lookups++;
4103 }
4104 }
4105 } else {
4106 // Dump specified images (by basename or fullpath)
4107 const char *arg_cstr;
4108 for (i = 0; (arg_cstr = command.GetArgumentAtIndex(i)) != nullptr &&
4109 !syntax_error;
4110 ++i) {
4111 ModuleList module_list;
4112 const size_t num_matches =
4113 FindModulesByName(&target, arg_cstr, module_list, false);
4114 if (num_matches > 0) {
4115 for (size_t j = 0; j < num_matches; ++j) {
4116 Module *module = module_list.GetModulePointerAtIndex(j);
4117 if (module) {
4118 if (LookupInModule(m_interpreter, module, result, syntax_error)) {
4119 result.GetOutputStream().EOL();
4120 num_successful_lookups++;
4121 }
4122 }
4123 }
4124 } else
4126 "unable to find an image that matches '{0}'", arg_cstr);
4127 }
4128 }
4129
4130 if (num_successful_lookups > 0)
4132 else
4134 }
4135
4137};
4138
4139#pragma mark CommandObjectMultiwordImageSearchPaths
4140
4141// CommandObjectMultiwordImageSearchPaths
4142
4144 : public CommandObjectMultiword {
4145public:
4148 interpreter, "target modules search-paths",
4149 "Commands for managing module search paths for a target.",
4150 "target modules search-paths <subcommand> [<subcommand-options>]") {
4152 "add", CommandObjectSP(
4156 interpreter)));
4158 "insert",
4163 interpreter)));
4166 interpreter)));
4167 }
4168
4170};
4171
4172#pragma mark CommandObjectTargetModules
4173
4174// CommandObjectTargetModules
4175
4177public:
4178 // Constructors and Destructors
4180 : CommandObjectMultiword(interpreter, "target modules",
4181 "Commands for accessing information for one or "
4182 "more target modules.",
4183 "target modules <sub-command> ...") {
4185 "add", CommandObjectSP(new CommandObjectTargetModulesAdd(interpreter)));
4187 interpreter)));
4189 interpreter)));
4191 interpreter)));
4193 "lookup",
4196 "search-paths",
4200 "show-unwind",
4202 }
4203
4204 ~CommandObjectTargetModules() override = default;
4205
4206private:
4207 // For CommandObjectTargetModules only
4211};
4212
4214public:
4217 interpreter, "target symbols add",
4218 "Add a debug symbol file to one of the target's current modules by "
4219 "specifying a path to a debug symbols file or by using the options "
4220 "to specify a module.",
4221 "target symbols add <cmd-options> [<symfile>]",
4222 eCommandRequiresTarget),
4224 LLDB_OPT_SET_1, false, "shlib", 's', lldb::eModuleCompletion,
4226 "Locate the debug symbols for the shared library specified by "
4227 "name."),
4229 LLDB_OPT_SET_2, false, "frame", 'F',
4230 "Locate the debug symbols for the currently selected frame.", false,
4231 true),
4232 m_current_stack_option(LLDB_OPT_SET_2, false, "stack", 'S',
4233 "Locate the debug symbols for every frame in "
4234 "the current call stack.",
4235 false, true)
4236
4237 {
4245 m_option_group.Finalize();
4247 }
4248
4250
4251 Options *GetOptions() override { return &m_option_group; }
4252
4253protected:
4254 bool AddModuleSymbols(Target *target, ModuleSpec &module_spec, bool &flush,
4255 CommandReturnObject &result) {
4256 const FileSpec &symbol_fspec = module_spec.GetSymbolFileSpec();
4257 if (!symbol_fspec) {
4258 result.AppendError(
4259 "one or more executable image paths must be specified");
4260 return false;
4261 }
4262
4263 char symfile_path[PATH_MAX];
4264 symbol_fspec.GetPath(symfile_path, sizeof(symfile_path));
4265
4266 if (!module_spec.GetUUID().IsValid()) {
4267 if (!module_spec.GetFileSpec() && !module_spec.GetPlatformFileSpec())
4268 module_spec.GetFileSpec().SetFilename(symbol_fspec.GetFilename());
4269 }
4270
4271 // Now module_spec represents a symbol file for a module that might exist
4272 // in the current target. Let's find possible matches.
4273 ModuleList matching_modules;
4274
4275 // First extract all module specs from the symbol file
4276 lldb_private::ModuleSpecList symfile_module_specs =
4278 0);
4279 if (symfile_module_specs.GetSize() > 0) {
4280 // Now extract the module spec that matches the target architecture
4281 ModuleSpec target_arch_module_spec;
4282 ModuleSpec symfile_module_spec;
4283 target_arch_module_spec.GetArchitecture() = target->GetArchitecture();
4284 if (symfile_module_specs.FindMatchingModuleSpec(target_arch_module_spec,
4285 symfile_module_spec)) {
4286 if (symfile_module_spec.GetUUID().IsValid()) {
4287 // It has a UUID, look for this UUID in the target modules
4288 ModuleSpec symfile_uuid_module_spec;
4289 symfile_uuid_module_spec.GetUUID() = symfile_module_spec.GetUUID();
4290 target->GetImages().FindModules(symfile_uuid_module_spec,
4291 matching_modules);
4292 }
4293 }
4294
4295 if (matching_modules.IsEmpty()) {
4296 // No matches yet. Iterate through the module specs to find a UUID
4297 // value that we can match up to an image in our target.
4298 const size_t num_symfile_module_specs = symfile_module_specs.GetSize();
4299 for (size_t i = 0;
4300 i < num_symfile_module_specs && matching_modules.IsEmpty(); ++i) {
4301 if (symfile_module_specs.GetModuleSpecAtIndex(
4302 i, symfile_module_spec)) {
4303 if (symfile_module_spec.GetUUID().IsValid()) {
4304 // It has a UUID. Look for this UUID in the target modules.
4305 ModuleSpec symfile_uuid_module_spec;
4306 symfile_uuid_module_spec.GetUUID() =
4307 symfile_module_spec.GetUUID();
4308 target->GetImages().FindModules(symfile_uuid_module_spec,
4309 matching_modules);
4310 }
4311 }
4312 }
4313 }
4314 }
4315
4316 // Just try to match up the file by basename if we have no matches at
4317 // this point. For example, module foo might have symbols in foo.debug.
4318 if (matching_modules.IsEmpty())
4319 target->GetImages().FindModules(module_spec, matching_modules);
4320
4321 while (matching_modules.IsEmpty()) {
4322 ConstString filename_no_extension(
4324 // Empty string returned, let's bail
4325 if (!filename_no_extension)
4326 break;
4327
4328 // Check if there was no extension to strip and the basename is the same
4329 if (filename_no_extension == module_spec.GetFileSpec().GetFilename())
4330 break;
4331
4332 // Replace basename with one fewer extension
4333 module_spec.GetFileSpec().SetFilename(filename_no_extension);
4334 target->GetImages().FindModules(module_spec, matching_modules);
4335 }
4336
4337 if (matching_modules.GetSize() > 1) {
4338 result.AppendErrorWithFormat("multiple modules match symbol file '%s', "
4339 "use the --uuid option to resolve the "
4340 "ambiguity.\n",
4341 symfile_path);
4342 return false;
4343 }
4344
4345 if (matching_modules.GetSize() == 1) {
4346 ModuleSP module_sp(matching_modules.GetModuleAtIndex(0));
4347
4348 // The module has not yet created its symbol vendor, we can just give
4349 // the existing target module the symfile path to use for when it
4350 // decides to create it!
4351 module_sp->SetSymbolFileFileSpec(symbol_fspec);
4352
4353 SymbolFile *symbol_file =
4354 module_sp->GetSymbolFile(true, &result.GetErrorStream());
4355 if (symbol_file) {
4356 ObjectFile *object_file = symbol_file->GetObjectFile();
4357 if (object_file && object_file->GetFileSpec() == symbol_fspec) {
4358 // Provide feedback that the symfile has been successfully added.
4359 const FileSpec &module_fs = module_sp->GetFileSpec();
4361 "symbol file '{0}' has been added to '{1}'", symfile_path,
4362 module_fs.GetPath().c_str());
4363
4364 // Let clients know something changed in the module if it is
4365 // currently loaded
4366 ModuleList module_list;
4367 module_list.Append(module_sp);
4368 target->SymbolsDidLoad(module_list);
4369
4370 // Make sure we load any scripting resources that may be embedded
4371 // in the debug info files in case the platform supports that.
4372 std::list<Status> errors;
4373 module_list.LoadScriptingResourcesInTarget(target, errors);
4374 for (const auto &err : errors)
4375 result.AppendWarning(err.AsCString());
4376
4377 flush = true;
4379 return true;
4380 }
4381 }
4382 // Clear the symbol file spec if anything went wrong
4383 module_sp->SetSymbolFileFileSpec(FileSpec());
4384 }
4385
4386 StreamString ss_symfile_uuid;
4387 if (module_spec.GetUUID().IsValid()) {
4388 ss_symfile_uuid << " (";
4389 module_spec.GetUUID().Dump(ss_symfile_uuid);
4390 ss_symfile_uuid << ')';
4391 }
4392 result.AppendErrorWithFormat(
4393 "symbol file '%s'%s does not match any existing module%s\n",
4394 symfile_path, ss_symfile_uuid.GetData(),
4395 !llvm::sys::fs::is_regular_file(symbol_fspec.GetPath())
4396 ? "\n please specify the full path to the symbol file"
4397 : "");
4398 return false;
4399 }
4400
4402 CommandReturnObject &result, bool &flush) {
4403 Status error;
4405 if (module_spec.GetSymbolFileSpec())
4406 return AddModuleSymbols(m_exe_ctx.GetTargetPtr(), module_spec, flush,
4407 result);
4408 } else {
4409 result.SetError(std::move(error));
4410 }
4411 return false;
4412 }
4413
4414 bool AddSymbolsForUUID(CommandReturnObject &result, bool &flush) {
4415 assert(m_uuid_option_group.GetOptionValue().OptionWasSet());
4416
4417 ModuleSpec module_spec;
4418 module_spec.GetUUID() =
4419 m_uuid_option_group.GetOptionValue().GetCurrentValue();
4420
4421 if (!DownloadObjectAndSymbolFile(module_spec, result, flush)) {
4422 StreamString error_strm;
4423 error_strm.PutCString("unable to find debug symbols for UUID ");
4424 module_spec.GetUUID().Dump(error_strm);
4425 result.AppendError(error_strm.GetString());
4426 return false;
4427 }
4428
4429 return true;
4430 }
4431
4432 bool AddSymbolsForFile(CommandReturnObject &result, bool &flush) {
4433 assert(m_file_option.GetOptionValue().OptionWasSet());
4434
4435 ModuleSpec module_spec;
4436 module_spec.GetFileSpec() =
4437 m_file_option.GetOptionValue().GetCurrentValue();
4438
4439 Target *target = m_exe_ctx.GetTargetPtr();
4440 ModuleSP module_sp(target->GetImages().FindFirstModule(module_spec));
4441 if (module_sp) {
4442 module_spec.GetFileSpec() = module_sp->GetFileSpec();
4443 module_spec.GetPlatformFileSpec() = module_sp->GetPlatformFileSpec();
4444 module_spec.GetUUID() = module_sp->GetUUID();
4445 module_spec.GetArchitecture() = module_sp->GetArchitecture();
4446 } else {
4447 module_spec.GetArchitecture() = target->GetArchitecture();
4448 }
4449
4450 if (!DownloadObjectAndSymbolFile(module_spec, result, flush)) {
4451 StreamString error_strm;
4452 error_strm.PutCString(
4453 "unable to find debug symbols for the executable file ");
4454 error_strm << module_spec.GetFileSpec();
4455 result.AppendError(error_strm.GetString());
4456 return false;
4457 }
4458
4459 return true;
4460 }
4461
4462 bool AddSymbolsForFrame(CommandReturnObject &result, bool &flush) {
4463 assert(m_current_frame_option.GetOptionValue().OptionWasSet());
4464
4465 Process *process = m_exe_ctx.GetProcessPtr();
4466 if (!process) {
4467 result.AppendError(
4468 "a process must exist in order to use the --frame option");
4469 return false;
4470 }
4471
4472 const StateType process_state = process->GetState();
4473 if (!StateIsStoppedState(process_state, true)) {
4474 result.AppendErrorWithFormat("process is not stopped: %s",
4475 StateAsCString(process_state));
4476 return false;
4477 }
4478
4479 StackFrame *frame = m_exe_ctx.GetFramePtr();
4480 if (!frame) {
4481 result.AppendError("invalid current frame");
4482 return false;
4483 }
4484
4485 ModuleSP frame_module_sp(
4486 frame->GetSymbolContext(eSymbolContextModule).module_sp);
4487 if (!frame_module_sp) {
4488 result.AppendError("frame has no module");
4489 return false;
4490 }
4491
4492 ModuleSpec module_spec;
4493 module_spec.GetUUID() = frame_module_sp->GetUUID();
4494 module_spec.GetArchitecture() = frame_module_sp->GetArchitecture();
4495 module_spec.GetFileSpec() = frame_module_sp->GetPlatformFileSpec();
4496
4497 if (!DownloadObjectAndSymbolFile(module_spec, result, flush)) {
4498 result.AppendError("unable to find debug symbols for the current frame");
4499 return false;
4500 }
4501
4502 return true;
4503 }
4504
4505 bool AddSymbolsForStack(CommandReturnObject &result, bool &flush) {
4506 assert(m_current_stack_option.GetOptionValue().OptionWasSet());
4507
4508 Process *process = m_exe_ctx.GetProcessPtr();
4509 if (!process) {
4510 result.AppendError(
4511 "a process must exist in order to use the --stack option");
4512 return false;
4513 }
4514
4515 const StateType process_state = process->GetState();
4516 if (!StateIsStoppedState(process_state, true)) {
4517 result.AppendErrorWithFormat("process is not stopped: %s",
4518 StateAsCString(process_state));
4519 return false;
4520 }
4521
4522 Thread *thread = m_exe_ctx.GetThreadPtr();
4523 if (!thread) {
4524 result.AppendError("invalid current thread");
4525 return false;
4526 }
4527
4528 bool symbols_found = false;
4529 uint32_t frame_count = thread->GetStackFrameCount();
4530 for (uint32_t i = 0; i < frame_count; ++i) {
4531 lldb::StackFrameSP frame_sp = thread->GetStackFrameAtIndex(i);
4532
4533 ModuleSP frame_module_sp(
4534 frame_sp->GetSymbolContext(eSymbolContextModule).module_sp);
4535 if (!frame_module_sp)
4536 continue;
4537
4538 ModuleSpec module_spec;
4539 module_spec.GetUUID() = frame_module_sp->GetUUID();
4540 module_spec.GetFileSpec() = frame_module_sp->GetPlatformFileSpec();
4541 module_spec.GetArchitecture() = frame_module_sp->GetArchitecture();
4542
4543 bool current_frame_flush = false;
4544 if (DownloadObjectAndSymbolFile(module_spec, result, current_frame_flush))
4545 symbols_found = true;
4546 flush |= current_frame_flush;
4547 }
4548
4549 if (!symbols_found) {
4550 result.AppendError(
4551 "unable to find debug symbols in the current call stack");
4552 return false;
4553 }
4554
4555 return true;
4556 }
4557
4558 void DoExecute(Args &args, CommandReturnObject &result) override {
4559 Target *target = m_exe_ctx.GetTargetPtr();
4561 bool flush = false;
4562 ModuleSpec module_spec;
4563 const bool uuid_option_set =
4564 m_uuid_option_group.GetOptionValue().OptionWasSet();
4565 const bool file_option_set = m_file_option.GetOptionValue().OptionWasSet();
4566 const bool frame_option_set =
4567 m_current_frame_option.GetOptionValue().OptionWasSet();
4568 const bool stack_option_set =
4569 m_current_stack_option.GetOptionValue().OptionWasSet();
4570 const size_t argc = args.GetArgumentCount();
4571
4572 if (argc == 0) {
4573 if (uuid_option_set)
4574 AddSymbolsForUUID(result, flush);
4575 else if (file_option_set)
4576 AddSymbolsForFile(result, flush);
4577 else if (frame_option_set)
4578 AddSymbolsForFrame(result, flush);
4579 else if (stack_option_set)
4580 AddSymbolsForStack(result, flush);
4581 else
4582 result.AppendError("one or more symbol file paths must be specified, "
4583 "or options must be specified");
4584 } else {
4585 if (uuid_option_set) {
4586 result.AppendError("specify either one or more paths to symbol files "
4587 "or use the --uuid option without arguments");
4588 } else if (frame_option_set) {
4589 result.AppendError("specify either one or more paths to symbol files "
4590 "or use the --frame option without arguments");
4591 } else if (file_option_set && argc > 1) {
4592 result.AppendError("specify at most one symbol file path when "
4593 "--shlib option is set");
4594 } else {
4595 PlatformSP platform_sp(target->GetPlatform());
4596
4597 for (auto &entry : args.entries()) {
4598 if (!entry.ref().empty()) {
4599 auto &symbol_file_spec = module_spec.GetSymbolFileSpec();
4600 symbol_file_spec.SetFile(entry.ref(), FileSpec::Style::native);
4601 FileSystem::Instance().Resolve(symbol_file_spec);
4602 if (file_option_set) {
4603 module_spec.GetFileSpec() =
4604 m_file_option.GetOptionValue().GetCurrentValue();
4605 }
4606 if (platform_sp) {
4607 FileSpec symfile_spec;
4608 if (platform_sp
4609 ->ResolveSymbolFile(*target, module_spec, symfile_spec)
4610 .Success())
4611 module_spec.GetSymbolFileSpec() = symfile_spec;
4612 }
4613
4614 bool symfile_exists =
4616
4617 if (symfile_exists) {
4618 if (!AddModuleSymbols(target, module_spec, flush, result))
4619 break;
4620 } else {
4621 std::string resolved_symfile_path =
4622 module_spec.GetSymbolFileSpec().GetPath();
4623 if (resolved_symfile_path != entry.ref()) {
4624 result.AppendErrorWithFormat(
4625 "invalid module path '%s' with resolved path '%s'\n",
4626 entry.c_str(), resolved_symfile_path.c_str());
4627 break;
4628 }
4629 result.AppendErrorWithFormat("invalid module path '%s'\n",
4630 entry.c_str());
4631 break;
4632 }
4633 }
4634 }
4635 }
4636 }
4637
4638 if (flush) {
4639 Process *process = m_exe_ctx.GetProcessPtr();
4640 if (process)
4641 process->Flush();
4642 }
4643 }
4644
4650};
4651
4652#pragma mark CommandObjectTargetSymbols
4653
4654// CommandObjectTargetSymbols
4655
4657public:
4658 // Constructors and Destructors
4661 interpreter, "target symbols",
4662 "Commands for adding and managing debug symbol files.",
4663 "target symbols <sub-command> ...") {
4665 "add", CommandObjectSP(new CommandObjectTargetSymbolsAdd(interpreter)));
4666 }
4667
4668 ~CommandObjectTargetSymbols() override = default;
4669
4670private:
4671 // For CommandObjectTargetModules only
4675};
4676
4677#pragma mark CommandObjectTargetStopHookAdd
4678
4679// CommandObjectTargetStopHookAdd
4680#define LLDB_OPTIONS_target_stop_hook_add
4681#include "CommandOptions.inc"
4682
4685public:
4687 public:
4689
4690 ~CommandOptions() override = default;
4691
4692 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
4693 return llvm::ArrayRef(g_target_stop_hook_add_options);
4694 }
4695
4696 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
4697 ExecutionContext *execution_context) override {
4698 Status error;
4699 const int short_option =
4700 g_target_stop_hook_add_options[option_idx].short_option;
4701
4702 switch (short_option) {
4703 case 'c':
4704 m_class_name = std::string(option_arg);
4705 m_sym_ctx_specified = true;
4706 break;
4707
4708 case 'e':
4709 if (option_arg.getAsInteger(0, m_line_end)) {
4711 "invalid end line number: \"%s\"", option_arg.str().c_str());
4712 break;
4713 }
4714 m_sym_ctx_specified = true;
4715 break;
4716
4717 case 'G': {
4718 bool value, success;
4719 value = OptionArgParser::ToBoolean(option_arg, false, &success);
4720 if (success) {
4721 m_auto_continue = value;
4722 } else
4724 "invalid boolean value '%s' passed for -G option",
4725 option_arg.str().c_str());
4726 } break;
4727 case 'l':
4728 if (option_arg.getAsInteger(0, m_line_start)) {
4730 "invalid start line number: \"%s\"", option_arg.str().c_str());
4731 break;
4732 }
4733 m_sym_ctx_specified = true;
4734 break;
4735
4736 case 'i':
4737 m_no_inlines = true;
4738 break;
4739
4740 case 'n':
4741 m_function_name = std::string(option_arg);
4742 m_func_name_type_mask |= eFunctionNameTypeAuto;
4743 m_sym_ctx_specified = true;
4744 break;
4745
4746 case 'f':
4747 m_file_name = std::string(option_arg);
4748 m_sym_ctx_specified = true;
4749 break;
4750
4751 case 's':
4752 m_module_name = std::string(option_arg);
4753 m_sym_ctx_specified = true;
4754 break;
4755
4756 case 't':
4757 if (option_arg.getAsInteger(0, m_thread_id))
4759 "invalid thread id string '%s'", option_arg.str().c_str());
4760 m_thread_specified = true;
4761 break;
4762
4763 case 'T':
4764 m_thread_name = std::string(option_arg);
4765 m_thread_specified = true;
4766 break;
4767
4768 case 'q':
4769 m_queue_name = std::string(option_arg);
4770 m_thread_specified = true;
4771 break;
4772
4773 case 'x':
4774 if (option_arg.getAsInteger(0, m_thread_index))
4776 "invalid thread index string '%s'", option_arg.str().c_str());
4777 m_thread_specified = true;
4778 break;
4779
4780 case 'o':
4781 m_use_one_liner = true;
4782 m_one_liner.push_back(std::string(option_arg));
4783 break;
4784
4785 case 'I': {
4786 bool value, success;
4787 value = OptionArgParser::ToBoolean(option_arg, false, &success);
4788 if (success)
4789 m_at_initial_stop = value;
4790 else
4792 "invalid boolean value '%s' passed for -F option",
4793 option_arg.str().c_str());
4794 } break;
4795
4796 default:
4797 llvm_unreachable("Unimplemented option");
4798 }
4799 return error;
4800 }
4801
4802 void OptionParsingStarting(ExecutionContext *execution_context) override {
4803 m_class_name.clear();
4804 m_function_name.clear();
4805 m_line_start = 0;
4807 m_file_name.clear();
4808 m_module_name.clear();
4809 m_func_name_type_mask = eFunctionNameTypeAuto;
4812 m_thread_name.clear();
4813 m_queue_name.clear();
4814
4815 m_no_inlines = false;
4816 m_sym_ctx_specified = false;
4817 m_thread_specified = false;
4818
4819 m_use_one_liner = false;
4820 m_one_liner.clear();
4821 m_auto_continue = false;
4822 m_at_initial_stop = true;
4823 }
4824
4825 std::string m_class_name;
4826 std::string m_function_name;
4827 uint32_t m_line_start = 0;
4829 std::string m_file_name;
4830 std::string m_module_name;
4832 eFunctionNameTypeAuto; // A pick from lldb::FunctionNameType.
4835 std::string m_thread_name;
4836 std::string m_queue_name;
4838 bool m_no_inlines = false;
4840 // Instance variables to hold the values for one_liner options.
4841 bool m_use_one_liner = false;
4842 std::vector<std::string> m_one_liner;
4844
4845 bool m_auto_continue = false;
4846 };
4847
4849 : CommandObjectParsed(interpreter, "target stop-hook add",
4850 "Add a hook to be executed when the target stops."
4851 "The hook can either be a list of commands or an "
4852 "appropriately defined Python class. You can also "
4853 "add filters so the hook only runs a certain stop "
4854 "points.",
4855 "target stop-hook add"),
4858 m_python_class_options("scripted stop-hook", true, 'P') {
4860 R"(
4861Command Based stop-hooks:
4862-------------------------
4863 Stop hooks can run a list of lldb commands by providing one or more
4864 --one-liner options. The commands will get run in the order they are added.
4865 Or you can provide no commands, in which case you will enter a command editor
4866 where you can enter the commands to be run.
4867
4868Python Based Stop Hooks:
4869------------------------
4870 Stop hooks can be implemented with a suitably defined Python class, whose name
4871 is passed in the --python-class option.
4872
4873 When the stop hook is added, the class is initialized by calling:
4874
4875 def __init__(self, target, extra_args, internal_dict):
4876
4877 target: The target that the stop hook is being added to.
4878 extra_args: An SBStructuredData Dictionary filled with the -key -value
4879 option pairs passed to the command.
4880 dict: An implementation detail provided by lldb.
4881
4882 Then when the stop-hook triggers, lldb will run the 'handle_stop' method.
4883 The method has the signature:
4885 def handle_stop(self, exe_ctx, stream):
4886
4887 exe_ctx: An SBExecutionContext for the thread that has stopped.
4888 stream: An SBStream, anything written to this stream will be printed in the
4889 the stop message when the process stops.
4890
4891 Return Value: The method returns "should_stop". If should_stop is false
4892 from all the stop hook executions on threads that stopped
4893 with a reason, then the process will continue. Note that this
4894 will happen only after all the stop hooks are run.
4895
4896Filter Options:
4897---------------
4898 Stop hooks can be set to always run, or to only run when the stopped thread
4899 matches the filter options passed on the command line. The available filter
4900 options include a shared library or a thread or queue specification,
4901 a line range in a source file, a function name or a class name.
4902 )");
4905 LLDB_OPT_SET_FROM_TO(4, 6));
4906 m_all_options.Append(&m_options);
4907 m_all_options.Finalize();
4908 }
4909
4910 ~CommandObjectTargetStopHookAdd() override = default;
4911
4912 Options *GetOptions() override { return &m_all_options; }
4913
4914protected:
4915 void IOHandlerActivated(IOHandler &io_handler, bool interactive) override {
4916 if (interactive) {
4917 if (lldb::LockableStreamFileSP output_sp =
4918 io_handler.GetOutputStreamFileSP()) {
4919 LockedStreamFile locked_stream = output_sp->Lock();
4920 locked_stream.PutCString(
4921 "Enter your stop hook command(s). Type 'DONE' to end.\n");
4922 }
4923 }
4924 }
4925
4926 void IOHandlerInputComplete(IOHandler &io_handler,
4927 std::string &line) override {
4928 if (m_stop_hook_sp) {
4929 if (line.empty()) {
4930 if (lldb::LockableStreamFileSP error_sp =
4931 io_handler.GetErrorStreamFileSP()) {
4932 LockedStreamFile locked_stream = error_sp->Lock();
4933 locked_stream.Printf("error: stop hook #%" PRIu64
4934 " aborted, no commands.\n",
4935 m_stop_hook_sp->GetID());
4936 }
4938 } else {
4939 // The IOHandler editor is only for command lines stop hooks:
4940 Target::StopHookCommandLine *hook_ptr =
4941 static_cast<Target::StopHookCommandLine *>(m_stop_hook_sp.get());
4942
4943 hook_ptr->SetActionFromString(line);
4944 if (lldb::LockableStreamFileSP output_sp =
4945 io_handler.GetOutputStreamFileSP()) {
4946 LockedStreamFile locked_stream = output_sp->Lock();
4947 locked_stream.Printf("Stop hook #%" PRIu64 " added.\n",
4948 m_stop_hook_sp->GetID());
4949 }
4950 }
4951 m_stop_hook_sp.reset();
4952 }
4953 io_handler.SetIsDone(true);
4954 }
4955
4956 void DoExecute(Args &command, CommandReturnObject &result) override {
4957 m_stop_hook_sp.reset();
4958
4959 Target &target = GetTarget();
4960 Target::StopHookSP new_hook_sp =
4961 target.CreateStopHook(m_python_class_options.GetName().empty() ?
4962 Target::StopHook::StopHookKind::CommandBased
4963 : Target::StopHook::StopHookKind::ScriptBased);
4964
4965 // First step, make the specifier.
4966 std::unique_ptr<SymbolContextSpecifier> specifier_up;
4967 if (m_options.m_sym_ctx_specified) {
4968 specifier_up = std::make_unique<SymbolContextSpecifier>(
4969 GetDebugger().GetSelectedTarget());
4970
4971 if (!m_options.m_module_name.empty()) {
4972 specifier_up->AddSpecification(
4973 m_options.m_module_name.c_str(),
4975 }
4976
4977 if (!m_options.m_class_name.empty()) {
4978 specifier_up->AddSpecification(
4979 m_options.m_class_name.c_str(),
4981 }
4982
4983 if (!m_options.m_file_name.empty()) {
4984 specifier_up->AddSpecification(m_options.m_file_name.c_str(),
4986 }
4987
4988 if (m_options.m_line_start != 0) {
4989 specifier_up->AddLineSpecification(
4990 m_options.m_line_start,
4992 }
4993
4994 if (m_options.m_line_end != UINT_MAX) {
4995 specifier_up->AddLineSpecification(
4997 }
4998
4999 if (!m_options.m_function_name.empty()) {
5000 specifier_up->AddSpecification(
5001 m_options.m_function_name.c_str(),
5003 }
5004 }
5005
5006 if (specifier_up)
5007 new_hook_sp->SetSpecifier(specifier_up.release());
5008
5009 // Should we run at the initial stop:
5010 new_hook_sp->SetRunAtInitialStop(m_options.m_at_initial_stop);
5011
5012 // Next see if any of the thread options have been entered:
5013
5014 if (m_options.m_thread_specified) {
5015 ThreadSpec *thread_spec = new ThreadSpec();
5016
5017 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID) {
5018 thread_spec->SetTID(m_options.m_thread_id);
5019 }
5020
5021 if (m_options.m_thread_index != UINT32_MAX)
5022 thread_spec->SetIndex(m_options.m_thread_index);
5023
5024 if (!m_options.m_thread_name.empty())
5025 thread_spec->SetName(m_options.m_thread_name.c_str());
5027 if (!m_options.m_queue_name.empty())
5028 thread_spec->SetQueueName(m_options.m_queue_name.c_str());
5030 new_hook_sp->SetThreadSpecifier(thread_spec);
5031 }
5032
5033 new_hook_sp->SetAutoContinue(m_options.m_auto_continue);
5035 // This is a command line stop hook:
5036 Target::StopHookCommandLine *hook_ptr =
5037 static_cast<Target::StopHookCommandLine *>(new_hook_sp.get());
5039 result.AppendMessageWithFormatv("Stop hook #{0} added.",
5040 new_hook_sp->GetID());
5041 } else if (!m_python_class_options.GetName().empty()) {
5042 // This is a scripted stop hook:
5043 Target::StopHookScripted *hook_ptr =
5044 static_cast<Target::StopHookScripted *>(new_hook_sp.get());
5045 Status error = hook_ptr->SetScriptCallback(
5046 m_python_class_options.GetName(),
5047 m_python_class_options.GetStructuredData());
5048 if (error.Success())
5049 result.AppendMessageWithFormatv("Stop hook #{0} added.",
5050 new_hook_sp->GetID());
5051 else {
5052 // FIXME: Set the stop hook ID counter back.
5053 result.AppendErrorWithFormat("Couldn't add stop hook: %s",
5054 error.AsCString());
5055 target.UndoCreateStopHook(new_hook_sp->GetID());
5056 return;
5057 }
5058 } else {
5059 m_stop_hook_sp = new_hook_sp;
5060 m_interpreter.GetLLDBCommandsFromIOHandler("> ", // Prompt
5061 *this); // IOHandlerDelegate
5062 }
5064 }
5065
5066private:
5068 OptionGroupPythonClassWithDict m_python_class_options;
5069 OptionGroupOptions m_all_options;
5070
5072};
5073
5074#pragma mark CommandObjectTargetStopHookDelete
5075
5076// CommandObjectTargetStopHookDelete
5077
5079public:
5081 : CommandObjectParsed(interpreter, "target stop-hook delete",
5082 "Delete a stop-hook.",
5083 "target stop-hook delete [<idx>]") {
5085 R"(
5086Deletes the stop hook by index.
5087
5088At any given stop, all enabled stop hooks that pass the stop filter will
5089get a chance to run. That means if one stop-hook deletes another stop hook
5090while executing, the deleted stop hook will still fire for the stop at which
5091it was deleted.
5092 )");
5094 }
5095
5096 ~CommandObjectTargetStopHookDelete() override = default;
5097
5098 void
5100 OptionElementVector &opt_element_vector) override {
5101 if (request.GetCursorIndex())
5102 return;
5103 CommandObject::HandleArgumentCompletion(request, opt_element_vector);
5104 }
5105
5106protected:
5107 void DoExecute(Args &command, CommandReturnObject &result) override {
5108 Target &target = GetTarget();
5109 // FIXME: see if we can use the breakpoint id style parser?
5110 size_t num_args = command.GetArgumentCount();
5111 if (num_args == 0) {
5112 if (!m_interpreter.Confirm("Delete all stop hooks?", true)) {
5114 return;
5115 } else {
5116 target.RemoveAllStopHooks();
5117 }
5118 } else {
5119 for (size_t i = 0; i < num_args; i++) {
5120 lldb::user_id_t user_id;
5121 if (!llvm::to_integer(command.GetArgumentAtIndex(i), user_id)) {
5122 result.AppendErrorWithFormat("invalid stop hook id: \"%s\".\n",
5123 command.GetArgumentAtIndex(i));
5124 return;
5125 }
5126 if (!target.RemoveStopHookByID(user_id)) {
5127 result.AppendErrorWithFormat("unknown stop hook id: \"%s\".\n",
5128 command.GetArgumentAtIndex(i));
5129 return;
5130 }
5131 }
5132 }
5134 }
5135};
5136
5137#pragma mark CommandObjectTargetStopHookEnableDisable
5138
5139// CommandObjectTargetStopHookEnableDisable
5140
5142public:
5144 bool enable, const char *name,
5145 const char *help, const char *syntax)
5146 : CommandObjectParsed(interpreter, name, help, syntax), m_enable(enable) {
5148 }
5149
5151
5152 void
5154 OptionElementVector &opt_element_vector) override {
5155 if (request.GetCursorIndex())
5156 return;
5157 CommandObject::HandleArgumentCompletion(request, opt_element_vector);
5158 }
5159
5160protected:
5161 void DoExecute(Args &command, CommandReturnObject &result) override {
5162 Target &target = GetTarget();
5163 // FIXME: see if we can use the breakpoint id style parser?
5164 size_t num_args = command.GetArgumentCount();
5165 bool success;
5166
5167 if (num_args == 0) {
5169 } else {
5170 for (size_t i = 0; i < num_args; i++) {
5171 lldb::user_id_t user_id;
5172 if (!llvm::to_integer(command.GetArgumentAtIndex(i), user_id)) {
5173 result.AppendErrorWithFormat("invalid stop hook id: \"%s\".\n",
5174 command.GetArgumentAtIndex(i));
5175 return;
5176 }
5177 success = target.SetStopHookActiveStateByID(user_id, m_enable);
5178 if (!success) {
5179 result.AppendErrorWithFormat("unknown stop hook id: \"%s\".\n",
5180 command.GetArgumentAtIndex(i));
5181 return;
5182 }
5183 }
5184 }
5186 }
5187
5188private:
5190};
5191
5192#pragma mark CommandObjectTargetStopHookList
5193
5194// CommandObjectTargetStopHookList
5195#define LLDB_OPTIONS_target_stop_hook_list
5196#include "CommandOptions.inc"
5197
5199public:
5201 : CommandObjectParsed(interpreter, "target stop-hook list",
5202 "List all stop-hooks.") {}
5203
5205
5206 Options *GetOptions() override { return &m_options; }
5207
5208 class CommandOptions : public Options {
5209 public:
5210 CommandOptions() = default;
5211 ~CommandOptions() override = default;
5212
5213 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
5214 ExecutionContext *execution_context) override {
5215 Status error;
5216 const int short_option = m_getopt_table[option_idx].val;
5217
5218 switch (short_option) {
5219 case 'i':
5220 m_internal = true;
5221 break;
5222 default:
5223 llvm_unreachable("Unimplemented option");
5224 }
5225
5226 return error;
5227 }
5228
5229 void OptionParsingStarting(ExecutionContext *execution_context) override {
5230 m_internal = false;
5231 }
5232
5233 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
5234 return llvm::ArrayRef(g_target_stop_hook_list_options);
5235 }
5236
5237 // Instance variables to hold the values for command options.
5238 bool m_internal = false;
5239 };
5240
5241protected:
5242 void DoExecute(Args &command, CommandReturnObject &result) override {
5243 Target &target = GetTarget();
5244
5245 bool printed_hook = false;
5246 for (auto &hook : target.GetStopHooks(m_options.m_internal)) {
5247 if (printed_hook)
5248 result.GetOutputStream().PutCString("\n");
5249 hook->GetDescription(result.GetOutputStream(), eDescriptionLevelFull);
5250 printed_hook = true;
5251 }
5252
5253 if (!printed_hook)
5254 result.GetOutputStream().PutCString("No stop hooks.\n");
5255
5257 }
5258
5259private:
5261};
5262
5263#pragma mark CommandObjectMultiwordTargetStopHooks
5264
5265// CommandObjectMultiwordTargetStopHooks
5266
5268public:
5271 interpreter, "target stop-hook",
5272 "Commands for operating on debugger target stop-hooks.",
5273 "target stop-hook <subcommand> [<subcommand-options>]") {
5275 new CommandObjectTargetStopHookAdd(interpreter)));
5277 "delete",
5279 LoadSubCommand("disable",
5281 interpreter, false, "target stop-hook disable [<id>]",
5282 "Disable a stop-hook.", "target stop-hook disable")));
5283 LoadSubCommand("enable",
5285 interpreter, true, "target stop-hook enable [<id>]",
5286 "Enable a stop-hook.", "target stop-hook enable")));
5288 interpreter)));
5289 }
5290
5292};
5293
5294#pragma mark CommandObjectTargetDumpTypesystem
5295
5296/// Dumps the TypeSystem of the selected Target.
5298public:
5301 interpreter, "target dump typesystem",
5302 "Dump the state of the target's internal type system. Intended to "
5303 "be used for debugging LLDB itself.",
5304 nullptr, eCommandRequiresTarget) {}
5305
5307
5308protected:
5309 void DoExecute(Args &command, CommandReturnObject &result) override {
5310 // Go over every scratch TypeSystem and dump to the command output.
5311 for (lldb::TypeSystemSP ts : GetTarget().GetScratchTypeSystems())
5312 if (ts)
5313 ts->Dump(result.GetOutputStream().AsRawOstream(), "",
5314 GetCommandInterpreter().GetDebugger().GetUseColor());
5315
5317 }
5318};
5319
5320#pragma mark CommandObjectTargetDumpSectionLoadList
5321
5322/// Dumps the SectionLoadList of the selected Target.
5324public:
5327 interpreter, "target dump section-load-list",
5328 "Dump the state of the target's internal section load list. "
5329 "Intended to be used for debugging LLDB itself.",
5330 nullptr, eCommandRequiresTarget) {}
5331
5333
5334protected:
5335 void DoExecute(Args &command, CommandReturnObject &result) override {
5336 Target &target = GetTarget();
5337 target.DumpSectionLoadList(result.GetOutputStream());
5339 }
5340};
5341
5342#pragma mark CommandObjectTargetDump
5343
5344/// Multi-word command for 'target dump'.
5346public:
5347 // Constructors and Destructors
5350 interpreter, "target dump",
5351 "Commands for dumping information about the target.",
5352 "target dump [typesystem|section-load-list]") {
5354 "typesystem",
5356 LoadSubCommand("section-load-list",
5358 interpreter)));
5359 }
5360
5361 ~CommandObjectTargetDump() override = default;
5362};
5363
5364#pragma mark CommandObjectTargetFrameProvider
5365
5366#define LLDB_OPTIONS_target_frame_provider_register
5367#include "CommandOptions.inc"
5368
5370public:
5373 interpreter, "target frame-provider register",
5374 "Register frame provider for all threads in this target.", nullptr,
5375 eCommandRequiresTarget),
5376
5377 m_class_options("target frame-provider", true, 'C', 'k', 'v', 0) {
5380 m_all_options.Finalize();
5381 }
5382
5384
5385 Options *GetOptions() override { return &m_all_options; }
5386
5387 std::optional<std::string> GetRepeatCommand(Args &current_command_args,
5388 uint32_t index) override {
5389 return std::string("");
5390 }
5391
5392protected:
5393 void DoExecute(Args &command, CommandReturnObject &result) override {
5394 ScriptedMetadataSP metadata_sp = std::make_shared<ScriptedMetadata>(
5395 m_class_options.GetName(), m_class_options.GetStructuredData());
5396
5397 Target *target = m_exe_ctx.GetTargetPtr();
5398 if (!target)
5399 target = &GetDebugger().GetDummyTarget();
5400
5401 // Create the interface for calling static methods.
5403 GetDebugger()
5406
5407 // Create a descriptor from the metadata (applies to all threads by
5408 // default).
5409 ScriptedFrameProviderDescriptor descriptor(metadata_sp);
5410 descriptor.interface_sp = interface_sp;
5411
5412 auto id_or_err = target->AddScriptedFrameProviderDescriptor(descriptor);
5413 if (!id_or_err) {
5414 result.SetError(id_or_err.takeError());
5415 return;
5416 }
5417
5419 "successfully registered scripted frame provider '{0}' for target",
5420 m_class_options.GetName().c_str());
5421 }
5422
5425};
5426
5428public:
5431 interpreter, "target frame-provider clear",
5432 "Clear all registered frame providers from this target.", nullptr,
5433 eCommandRequiresTarget) {}
5434
5436
5437protected:
5438 void DoExecute(Args &command, CommandReturnObject &result) override {
5439 Target *target = m_exe_ctx.GetTargetPtr();
5440 if (!target) {
5441 result.AppendError("invalid target");
5442 return;
5443 }
5444
5446
5448 }
5449};
5450
5452public:
5455 interpreter, "target frame-provider list",
5456 "List all registered frame providers for the target.", nullptr,
5457 eCommandRequiresTarget) {}
5458
5460
5461protected:
5462 void DoExecute(Args &command, CommandReturnObject &result) override {
5463 Target *target = m_exe_ctx.GetTargetPtr();
5464 if (!target)
5465 target = &GetDebugger().GetDummyTarget();
5466
5467 const auto &descriptors = target->GetScriptedFrameProviderDescriptors();
5468 if (descriptors.empty()) {
5469 result.AppendMessage("no frame providers registered for this target.");
5471 return;
5472 }
5473
5474 Stream &strm = result.GetOutputStream();
5475 strm << llvm::formatv("{0} frame provider(s) registered:\n\n",
5476 descriptors.size());
5477
5478 for (const auto &entry : descriptors) {
5479 const ScriptedFrameProviderDescriptor &descriptor = entry.second;
5480 descriptor.Dump(&strm);
5481 strm.PutChar('\n');
5482 }
5483
5485 }
5486};
5487
5489public:
5492 interpreter, "target frame-provider remove",
5493 "Remove a registered frame provider from the target by id.",
5494 "target frame-provider remove <provider-id>",
5495 eCommandRequiresTarget) {
5497 }
5498
5500
5501protected:
5502 void DoExecute(Args &command, CommandReturnObject &result) override {
5503 Target *target = m_exe_ctx.GetTargetPtr();
5504 if (!target)
5505 target = &GetDebugger().GetDummyTarget();
5506
5507 std::vector<uint32_t> removed_provider_ids;
5508 for (size_t i = 0; i < command.GetArgumentCount(); i++) {
5509 uint32_t provider_id = 0;
5510 if (!llvm::to_integer(command[i].ref(), provider_id)) {
5511 result.AppendError("target frame-provider remove requires integer "
5512 "provider id argument");
5513 return;
5514 }
5515
5516 if (!target->RemoveScriptedFrameProviderDescriptor(provider_id)) {
5517 result.AppendErrorWithFormat(
5518 "no frame provider named '%u' found in target\n", provider_id);
5519 return;
5520 }
5521 removed_provider_ids.push_back(provider_id);
5522 }
5523
5524 if (size_t num_removed_providers = removed_provider_ids.size()) {
5526 "Successfully removed {0} frame-providers.", num_removed_providers);
5528 } else {
5529 result.AppendError("0 frame providers removed.\n");
5530 }
5531 }
5532};
5533
5535public:
5538 interpreter, "target frame-provider",
5539 "Commands for registering and viewing frame providers for the "
5540 "target.",
5541 "target frame-provider [<sub-command-options>] ") {
5542 LoadSubCommand("register",
5544 interpreter)));
5545 LoadSubCommand("clear",
5547 new CommandObjectTargetFrameProviderClear(interpreter)));
5549 "list",
5552 "remove", CommandObjectSP(
5553 new CommandObjectTargetFrameProviderRemove(interpreter)));
5554 }
5555
5557};
5558
5559#pragma mark CommandObjectMultiwordTarget
5560
5561// CommandObjectMultiwordTarget
5562
5564 CommandInterpreter &interpreter)
5565 : CommandObjectMultiword(interpreter, "target",
5566 "Commands for operating on debugger targets.",
5567 "target <subcommand> [<subcommand-options>]") {
5568 LoadSubCommand("create",
5569 CommandObjectSP(new CommandObjectTargetCreate(interpreter)));
5570 LoadSubCommand("delete",
5571 CommandObjectSP(new CommandObjectTargetDelete(interpreter)));
5572 LoadSubCommand("dump",
5573 CommandObjectSP(new CommandObjectTargetDump(interpreter)));
5575 "frame-provider",
5577 LoadSubCommand("list",
5578 CommandObjectSP(new CommandObjectTargetList(interpreter)));
5579 LoadSubCommand("select",
5580 CommandObjectSP(new CommandObjectTargetSelect(interpreter)));
5581 LoadSubCommand("show-launch-environment",
5583 interpreter)));
5585 "stop-hook",
5587 LoadSubCommand("modules",
5589 LoadSubCommand("symbols",
5591 LoadSubCommand("variable",
5593}
5594
static bool GetSeparateDebugInfoList(StructuredData::Array &list, Module *module, bool errors_only, bool load_all_debug_info)
static uint32_t DumpTargetList(TargetList &target_list, bool show_stopped_process_status, Stream &strm)
static void DumpModuleUUID(Stream &strm, Module *module)
static void DumpModuleSections(CommandInterpreter &interpreter, Stream &strm, Module *module)
static void DumpModuleArchitecture(Stream &strm, Module *module, bool full_triple, uint32_t width)
static bool LookupAddressInModule(CommandInterpreter &interpreter, Stream &strm, Module *module, uint32_t resolve_mask, lldb::addr_t raw_addr, lldb::addr_t offset, bool verbose, bool all_ranges)
static void DumpTargetInfo(uint32_t target_idx, Target *target, const char *prefix_cstr, bool show_stopped_process_status, Stream &strm)
static void DumpDirectory(Stream &strm, const FileSpec *file_spec_ptr, uint32_t width)
static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter, Stream &strm, Module *module, const char *name, bool name_is_regex, bool verbose, bool all_ranges)
static size_t LookupTypeInModule(Target *target, CommandInterpreter &interpreter, Stream &strm, Module *module, const char *name_cstr, bool name_is_regex)
static bool DumpModuleSymbolFile(Stream &strm, Module *module)
static void DumpFullpath(Stream &strm, const FileSpec *file_spec_ptr, uint32_t width)
static void DumpDwoFilesTable(Stream &strm, StructuredData::Array &dwo_listings)
static size_t LookupFunctionInModule(CommandInterpreter &interpreter, Stream &strm, Module *module, const char *name, bool name_is_regex, const ModuleFunctionSearchOptions &options, bool verbose, bool all_ranges)
static size_t LookupTypeHere(Target *target, CommandInterpreter &interpreter, Stream &strm, Module &module, const char *name_cstr, bool name_is_regex)
static uint32_t DumpCompileUnitLineTable(CommandInterpreter &interpreter, Stream &strm, Module *module, const FileSpec &file_spec, lldb::DescriptionLevel desc_level)
static void DumpBasename(Stream &strm, const FileSpec *file_spec_ptr, uint32_t width)
static size_t DumpModuleObjfileHeaders(Stream &strm, ModuleList &module_list)
static uint32_t LookupFileAndLineInModule(CommandInterpreter &interpreter, Stream &strm, Module *module, const FileSpec &file_spec, uint32_t line, bool check_inlines, bool verbose, bool all_ranges)
static void DumpSymbolContextList(ExecutionContextScope *exe_scope, Stream &strm, const SymbolContextList &sc_list, bool verbose, bool all_ranges, std::optional< Stream::HighlightSettings > settings=std::nullopt)
static void DumpOsoFilesTable(Stream &strm, StructuredData::Array &oso_listings)
static size_t FindModulesByName(Target *target, const char *module_name, ModuleList &module_list, bool check_global_list)
static void DumpModuleSymtab(CommandInterpreter &interpreter, Stream &strm, Module *module, SortOrder sort_order, Mangled::NamePreference name_preference)
static llvm::raw_ostream & error(Stream &strm)
#define INTERRUPT_REQUESTED(debugger,...)
This handy define will keep you from having to generate a report for the interruption by hand.
Definition Debugger.h:494
#define LLDB_LOGF(log,...)
Definition Log.h:378
#define LLDB_SCOPED_TIMERF(...)
Definition Timer.h:86
~CommandObjectMultiwordTargetStopHooks() override=default
CommandObjectMultiwordTargetStopHooks(CommandInterpreter &interpreter)
OptionGroupPlatform m_platform_options
~CommandObjectTargetCreate() override=default
OptionGroupArchitecture m_arch_option
CommandObjectTargetCreate(CommandInterpreter &interpreter)
OptionGroupDependents m_add_dependents
void DoExecute(Args &command, CommandReturnObject &result) override
void DoExecute(Args &args, CommandReturnObject &result) override
CommandObjectTargetDelete(CommandInterpreter &interpreter)
~CommandObjectTargetDelete() override=default
Dumps the SectionLoadList of the selected Target.
void DoExecute(Args &command, CommandReturnObject &result) override
~CommandObjectTargetDumpSectionLoadList() override=default
CommandObjectTargetDumpSectionLoadList(CommandInterpreter &interpreter)
Dumps the TypeSystem of the selected Target.
CommandObjectTargetDumpTypesystem(CommandInterpreter &interpreter)
~CommandObjectTargetDumpTypesystem() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
Multi-word command for 'target dump'.
CommandObjectTargetDump(CommandInterpreter &interpreter)
~CommandObjectTargetDump() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectTargetFrameProviderClear(CommandInterpreter &interpreter)
~CommandObjectTargetFrameProviderClear() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
~CommandObjectTargetFrameProviderList() override=default
CommandObjectTargetFrameProviderList(CommandInterpreter &interpreter)
OptionGroupPythonClassWithDict m_class_options
~CommandObjectTargetFrameProviderRegister() override=default
CommandObjectTargetFrameProviderRegister(CommandInterpreter &interpreter)
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
~CommandObjectTargetFrameProviderRemove() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectTargetFrameProviderRemove(CommandInterpreter &interpreter)
~CommandObjectTargetFrameProvider() override=default
CommandObjectTargetFrameProvider(CommandInterpreter &interpreter)
CommandObjectTargetList(CommandInterpreter &interpreter)
void DoExecute(Args &args, CommandReturnObject &result) override
~CommandObjectTargetList() override=default
CommandObjectTargetModulesAdd(CommandInterpreter &interpreter)
void DoExecute(Args &args, CommandReturnObject &result) override
~CommandObjectTargetModulesAdd() override=default
CommandObjectTargetModulesDumpClangAST(CommandInterpreter &interpreter)
void DoExecute(Args &command, CommandReturnObject &result) override
~CommandObjectTargetModulesDumpClangAST() override=default
~CommandObjectTargetModulesDumpClangPCMInfo() override=default
CommandObjectTargetModulesDumpClangPCMInfo(CommandInterpreter &interpreter)
void DoExecute(Args &command, CommandReturnObject &result) override
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
void OptionParsingStarting(ExecutionContext *execution_context) override
~CommandObjectTargetModulesDumpLineTable() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectTargetModulesDumpLineTable(CommandInterpreter &interpreter)
void DoExecute(Args &command, CommandReturnObject &result) override
~CommandObjectTargetModulesDumpObjfile() override=default
CommandObjectTargetModulesDumpObjfile(CommandInterpreter &interpreter)
CommandObjectTargetModulesDumpSections(CommandInterpreter &interpreter)
~CommandObjectTargetModulesDumpSections() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
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.
~CommandObjectTargetModulesDumpSeparateDebugInfoFiles() override=default
CommandObjectTargetModulesDumpSeparateDebugInfoFiles(CommandInterpreter &interpreter)
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectTargetModulesDumpSymfile(CommandInterpreter &interpreter)
~CommandObjectTargetModulesDumpSymfile() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
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
CommandObjectTargetModulesDumpSymtab(CommandInterpreter &interpreter)
~CommandObjectTargetModulesDumpSymtab() override=default
~CommandObjectTargetModulesDump() override=default
CommandObjectTargetModulesDump(CommandInterpreter &interpreter)
CommandObjectTargetModulesImageSearchPaths(CommandInterpreter &interpreter)
~CommandObjectTargetModulesImageSearchPaths() override=default
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
void OptionParsingStarting(ExecutionContext *execution_context) override
std::vector< std::pair< char, uint32_t > > FormatWidthCollection
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
CommandObjectTargetModulesList(CommandInterpreter &interpreter)
~CommandObjectTargetModulesList() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
void PrintModule(Target &target, Module *module, int indent, Stream &strm)
void DoExecute(Args &args, CommandReturnObject &result) override
~CommandObjectTargetModulesLoad() override=default
CommandObjectTargetModulesLoad(CommandInterpreter &interpreter)
void OptionParsingStarting(ExecutionContext *execution_context) override
Status OptionParsingFinished(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
bool LookupInModule(CommandInterpreter &interpreter, Module *module, CommandReturnObject &result, bool &syntax_error)
~CommandObjectTargetModulesLookup() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
bool LookupHere(CommandInterpreter &interpreter, CommandReturnObject &result, bool &syntax_error)
CommandObjectTargetModulesLookup(CommandInterpreter &interpreter)
CommandObjectTargetModulesModuleAutoComplete(CommandInterpreter &interpreter, const char *name, const char *help, const char *syntax, uint32_t flags=0)
~CommandObjectTargetModulesModuleAutoComplete() override=default
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The default version handles argument definitions that have only one argument type,...
~CommandObjectTargetModulesSearchPathsAdd() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectTargetModulesSearchPathsAdd(CommandInterpreter &interpreter)
void DoExecute(Args &command, CommandReturnObject &result) override
~CommandObjectTargetModulesSearchPathsClear() override=default
CommandObjectTargetModulesSearchPathsClear(CommandInterpreter &interpreter)
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The default version handles argument definitions that have only one argument type,...
~CommandObjectTargetModulesSearchPathsInsert() override=default
CommandObjectTargetModulesSearchPathsInsert(CommandInterpreter &interpreter)
void DoExecute(Args &command, CommandReturnObject &result) override
~CommandObjectTargetModulesSearchPathsList() override=default
CommandObjectTargetModulesSearchPathsList(CommandInterpreter &interpreter)
void DoExecute(Args &command, CommandReturnObject &result) override
~CommandObjectTargetModulesSearchPathsQuery() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectTargetModulesSearchPathsQuery(CommandInterpreter &interpreter)
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
void OptionParsingStarting(ExecutionContext *execution_context) override
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
CommandObjectTargetModulesShowUnwind(CommandInterpreter &interpreter)
void DoExecute(Args &command, CommandReturnObject &result) override
~CommandObjectTargetModulesShowUnwind() override=default
CommandObjectTargetModulesSourceFileAutoComplete(CommandInterpreter &interpreter, const char *name, const char *help, const char *syntax, uint32_t flags)
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The default version handles argument definitions that have only one argument type,...
~CommandObjectTargetModulesSourceFileAutoComplete() override=default
~CommandObjectTargetModules() override=default
const CommandObjectTargetModules & operator=(const CommandObjectTargetModules &)=delete
CommandObjectTargetModules(const CommandObjectTargetModules &)=delete
CommandObjectTargetModules(CommandInterpreter &interpreter)
~CommandObjectTargetSelect() override=default
void DoExecute(Args &args, CommandReturnObject &result) override
CommandObjectTargetSelect(CommandInterpreter &interpreter)
CommandObjectTargetShowLaunchEnvironment(CommandInterpreter &interpreter)
void DoExecute(Args &args, CommandReturnObject &result) override
~CommandObjectTargetShowLaunchEnvironment() override=default
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
void OptionParsingStarting(ExecutionContext *execution_context) override
void IOHandlerActivated(IOHandler &io_handler, bool interactive) override
CommandObjectTargetStopHookAdd(CommandInterpreter &interpreter)
void IOHandlerInputComplete(IOHandler &io_handler, std::string &line) override
Called when a line or lines have been retrieved.
~CommandObjectTargetStopHookAdd() override=default
OptionGroupPythonClassWithDict m_python_class_options
void DoExecute(Args &command, CommandReturnObject &result) override
void DoExecute(Args &command, CommandReturnObject &result) override
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The default version handles argument definitions that have only one argument type,...
CommandObjectTargetStopHookDelete(CommandInterpreter &interpreter)
~CommandObjectTargetStopHookDelete() override=default
~CommandObjectTargetStopHookEnableDisable() override=default
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The default version handles argument definitions that have only one argument type,...
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectTargetStopHookEnableDisable(CommandInterpreter &interpreter, bool enable, const char *name, const char *help, const char *syntax)
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
void OptionParsingStarting(ExecutionContext *execution_context) override
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
void DoExecute(Args &command, CommandReturnObject &result) override
~CommandObjectTargetStopHookList() override=default
CommandObjectTargetStopHookList(CommandInterpreter &interpreter)
bool AddSymbolsForUUID(CommandReturnObject &result, bool &flush)
bool DownloadObjectAndSymbolFile(ModuleSpec &module_spec, CommandReturnObject &result, bool &flush)
bool AddSymbolsForStack(CommandReturnObject &result, bool &flush)
CommandObjectTargetSymbolsAdd(CommandInterpreter &interpreter)
bool AddSymbolsForFrame(CommandReturnObject &result, bool &flush)
~CommandObjectTargetSymbolsAdd() override=default
void DoExecute(Args &args, CommandReturnObject &result) override
bool AddModuleSymbols(Target *target, ModuleSpec &module_spec, bool &flush, CommandReturnObject &result)
bool AddSymbolsForFile(CommandReturnObject &result, bool &flush)
const CommandObjectTargetSymbols & operator=(const CommandObjectTargetSymbols &)=delete
CommandObjectTargetSymbols(CommandInterpreter &interpreter)
~CommandObjectTargetSymbols() override=default
CommandObjectTargetSymbols(const CommandObjectTargetSymbols &)=delete
void DumpGlobalVariableList(const ExecutionContext &exe_ctx, const SymbolContext &sc, const VariableList &variable_list, CommandReturnObject &result)
void DumpValueObject(Stream &s, VariableSP &var_sp, ValueObjectSP &valobj_sp, const char *root_name)
static size_t GetVariableCallback(void *baton, const char *name, VariableList &variable_list)
static const uint32_t SHORT_OPTION_SHLB
CommandObjectTargetVariable(CommandInterpreter &interpreter)
OptionGroupFileList m_option_shared_libraries
void DoExecute(Args &args, CommandReturnObject &result) override
OptionGroupFileList m_option_compile_units
static const uint32_t SHORT_OPTION_FILE
OptionGroupValueObjectDisplay m_varobj_options
~CommandObjectTargetVariable() override=default
~OptionGroupDependents() override=default
OptionGroupDependents()=default
LoadDependentFiles m_load_dependent_files
OptionGroupDependents(const OptionGroupDependents &)=delete
const OptionGroupDependents & operator=(const OptionGroupDependents &)=delete
void OptionParsingStarting(ExecutionContext *execution_context) override
Status SetOptionValue(uint32_t, const char *, ExecutionContext *)=delete
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_value, ExecutionContext *execution_context) override
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
virtual lldb::addr_t FixCodeAddress(lldb::addr_t pc)
Some targets might use bits in a code address to indicate a mode switch.
Definition ABI.cpp:141
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
bool SetLoadAddress(lldb::addr_t load_addr, Target *target, bool allow_section_end=false)
Set the address to represent load_addr.
Definition Address.cpp:1034
@ DumpStyleFileAddress
Display as the file address (if any).
Definition Address.h:87
@ DumpStyleSectionNameOffset
Display as the section name + offset.
Definition Address.h:74
@ DumpStyleDetailedSymbolContext
Detailed symbol context information for an address for all symbol context members.
Definition Address.h:112
@ DumpStyleInvalid
Invalid dump style.
Definition Address.h:68
@ DumpStyleModuleWithFileAddress
Display as the file address with the module name prepended (if any).
Definition Address.h:93
@ DumpStyleResolvedDescription
Display the details about what an address resolves to.
Definition Address.h:104
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
bool IsValid() const
Check if the object state is valid.
Definition Address.h:355
An architecture specification class.
Definition ArchSpec.h:32
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition ArchSpec.cpp:681
bool IsValid() const
Tests if this ArchSpec is valid.
Definition ArchSpec.h:367
void DumpTriple(llvm::raw_ostream &s) const
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
Definition ArchSpec.cpp:548
A command line argument class.
Definition Args.h:33
void Shift()
Shifts the first argument C string value of the array off the argument array.
Definition Args.cpp:295
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
Definition Args.h:120
llvm::ArrayRef< ArgEntry > entries() const
Definition Args.h:132
const char * GetArgumentAtIndex(size_t idx) const
Gets the NULL terminated C string argument pointer for the argument at index idx.
Definition Args.cpp:273
static bool InvokeCommonCompletionCallbacks(CommandInterpreter &interpreter, uint32_t completion_mask, lldb_private::CompletionRequest &request, SearchFilter *searcher)
bool Confirm(llvm::StringRef message, bool default_answer)
ExecutionContext GetExecutionContext() const
CommandObjectMultiwordTarget(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)
std::vector< CommandArgumentData > CommandArgumentEntry
virtual void SetHelpLong(llvm::StringRef str)
void AddSimpleArgumentList(lldb::CommandArgumentType arg_type, ArgumentRepetitionType repetition_type=eArgRepeatPlain)
std::vector< CommandArgumentEntry > m_arguments
CommandInterpreter & GetCommandInterpreter()
CommandInterpreter & m_interpreter
virtual void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector)
The default version handles argument definitions that have only one argument type,...
void AppendMessage(llvm::StringRef in_string)
void AppendError(llvm::StringRef in_string)
const ValueObjectList & GetValueObjectList() const
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 AppendWarning(llvm::StringRef in_string)
void AppendErrorWithFormatv(const char *format, Args &&...args)
A class that describes a compilation unit.
Definition CompileUnit.h:43
lldb::VariableListSP GetVariableList(bool can_create)
Get the variable list for a compile unit.
const FileSpec & GetPrimaryFile() const
Return the primary source spec associated with this compile unit.
"lldb/Utility/ArgCompletionRequest.h"
void TryCompleteCurrentArg(llvm::StringRef completion, llvm::StringRef description="")
Adds a possible completion string if the completion would complete the current argument.
A uniqued constant string class.
Definition ConstString.h:40
void Dump(Stream *s, const char *value_if_empty=nullptr) const
Dump the object description to a stream.
bool IsEmpty() const
Test for empty string.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
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.
A class to manage flag bits.
Definition Debugger.h:100
TargetList & GetTargetList()
Get accessor for the target list.
Definition Debugger.h:224
bool GetUseColor() const
Definition Debugger.cpp:525
llvm::StringRef GetRegexMatchAnsiSuffix() const
Definition Debugger.cpp:630
Target & GetDummyTarget()
Definition Debugger.h:536
llvm::StringRef GetRegexMatchAnsiPrefix() const
Definition Debugger.cpp:624
ScriptInterpreter * GetScriptInterpreter(bool can_create=true, std::optional< lldb::ScriptLanguage > language={})
DumpValueObjectOptions & SetRootValueObjectName(const char *name=nullptr)
DumpValueObjectOptions & SetFormat(lldb::Format format=lldb::eFormatDefault)
A class that measures elapsed time in an exception safe way.
Definition Statistics.h:76
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
ExecutionContextScope * GetBestExecutionContextScope() const
Target * GetTargetPtr() const
Returns a pointer to the target object.
A file collection class.
const FileSpec & GetFileSpecAtIndex(size_t idx) const
Get file at index.
size_t GetSize() const
Get the number of files in the file list.
A file utility class.
Definition FileSpec.h:57
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
Definition FileSpec.cpp:174
void SetDirectory(ConstString directory)
Directory string set accessor.
Definition FileSpec.cpp:342
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
ConstString GetFileNameStrippingExtension() const
Return the filename without the extension part.
Definition FileSpec.cpp:414
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
void Dump(llvm::raw_ostream &s) const
Dump this object to a Stream.
Definition FileSpec.cpp:325
llvm::StringRef GetFileNameExtension() const
Extract the extension of the file.
Definition FileSpec.cpp:410
void SetFilename(ConstString filename)
Filename string set accessor.
Definition FileSpec.cpp:352
bool ResolveExecutableLocation(FileSpec &file_spec)
Call into the Host to see if it can help find the file.
bool Exists(const FileSpec &file_spec) const
Returns whether the given file exists.
int Open(const char *path, int flags, int mode=0600)
Wraps open in a platform-independent way.
static FileSystem & Instance()
void Resolve(llvm::SmallVectorImpl< char > &path, bool force_make_absolute=false)
Resolve path to make it canonical.
@ eOpenOptionReadOnly
Definition File.h:51
IOHandlerDelegateMultiline(llvm::StringRef end_line, Completion completion=Completion::None)
Definition IOHandler.h:289
A delegate class for use with IOHandler subclasses.
Definition IOHandler.h:184
lldb::LockableStreamFileSP GetErrorStreamFileSP()
Definition IOHandler.cpp:95
lldb::LockableStreamFileSP GetOutputStreamFileSP()
Definition IOHandler.cpp:93
void SetIsDone(bool b)
Definition IOHandler.h:81
A line table class.
Definition LineTable.h:25
void GetDescription(Stream *s, Target *target, lldb::DescriptionLevel level)
A collection class for Module objects.
Definition ModuleList.h:125
void FindFunctions(ConstString name, lldb::FunctionNameType name_type_mask, const ModuleFunctionSearchOptions &options, SymbolContextList &sc_list) const
ModuleIterableNoLocking ModulesNoLocking() const
Definition ModuleList.h:576
static bool ModuleIsInCache(const Module *module_ptr)
void FindGlobalVariables(ConstString name, size_t max_matches, VariableList &variable_list) const
Find global and static variables by name.
std::recursive_mutex & GetMutex() const
Definition ModuleList.h:252
lldb::ModuleSP FindFirstModule(const ModuleSpec &module_spec) const
Finds the first module whose file specification matches module_spec.
lldb::ModuleSP GetModuleAtIndexUnlocked(size_t idx) const
Get the module shared pointer for the module at index idx without acquiring the ModuleList mutex.
void FindCompileUnits(const FileSpec &path, SymbolContextList &sc_list) const
Find compile units by partial or full path.
bool AppendIfNeeded(const lldb::ModuleSP &new_module, bool notify=true)
Append a module to the module list, if it is not already there.
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 Append(const lldb::ModuleSP &module_sp, bool notify=true)
Append a module to the module list.
static size_t RemoveOrphanSharedModules(bool mandatory)
static void FindSharedModules(const ModuleSpec &module_spec, ModuleList &matching_module_list)
bool LoadScriptingResourcesInTarget(Target *target, std::list< Status > &errors, bool continue_on_error=true)
ModuleIterable Modules() const
Definition ModuleList.h:570
size_t GetSize() const
Gets the size of the module list.
bool GetModuleSpecAtIndex(size_t i, ModuleSpec &module_spec) const
Definition ModuleSpec.h:356
bool FindMatchingModuleSpec(const ModuleSpec &module_spec, ModuleSpec &match_module_spec) const
Definition ModuleSpec.h:366
FileSpec & GetPlatformFileSpec()
Definition ModuleSpec.h:69
FileSpec & GetFileSpec()
Definition ModuleSpec.h:57
ArchSpec & GetArchitecture()
Definition ModuleSpec.h:93
FileSpec * GetFileSpecPtr()
Definition ModuleSpec.h:51
FileSpec & GetSymbolFileSpec()
Definition ModuleSpec.h:81
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:90
const lldb_private::UUID & GetUUID()
Get a reference to the UUID value contained in this object.
Definition Module.cpp:344
virtual SymbolFile * GetSymbolFile(bool can_create=true, Stream *feedback_strm=nullptr)
Get the module's symbol file.
Definition Module.cpp:984
static Module * GetAllocatedModuleAtIndex(size_t idx)
Definition Module.cpp:123
static std::recursive_mutex & GetAllocationModuleCollectionMutex()
Definition Module.cpp:105
bool ResolveFileAddress(lldb::addr_t vm_addr, Address &so_addr)
Definition Module.cpp:431
Symtab * GetSymtab(bool can_create=true)
Get the module's symbol table.
Definition Module.cpp:1011
bool MatchesModuleSpec(const ModuleSpec &module_ref)
Definition Module.cpp:1442
static size_t GetNumberAllocatedModules()
Definition Module.cpp:117
const ArchSpec & GetArchitecture() const
Get const accessor for the module architecture.
Definition Module.cpp:1026
std::string GetSpecificationDescription() const
Get the module path and object name.
Definition Module.cpp:1028
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
Definition Module.h:446
const llvm::sys::TimePoint & GetModificationTime() const
Definition Module.h:482
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:46
virtual void Dump(Stream *s)=0
Dump a description of this object to a Stream.
virtual std::vector< LoadableData > GetLoadableData(Target &target)
Loads this objfile to memory.
virtual lldb_private::Address GetEntryPointAddress()
Returns the address of the Entry Point in this object file - if the object file doesn't have an entry...
Definition ObjectFile.h:452
virtual FileSpec & GetFileSpec()
Get accessor to the object file specification.
Definition ObjectFile.h:280
static ModuleSpecList GetModuleSpecifications(const FileSpec &file, lldb::offset_t file_offset, lldb::offset_t file_size, lldb::DataExtractorSP=lldb::DataExtractorSP())
virtual lldb_private::Address GetBaseAddress()
Returns base address of this object file.
Definition ObjectFile.h:462
static const uint32_t OPTION_GROUP_GDB_FMT
static const uint32_t OPTION_GROUP_FORMAT
A command line option parsing protocol class.
Definition Options.h:58
std::vector< Option > m_getopt_table
Definition Options.h:198
void Insert(llvm::StringRef path, llvm::StringRef replacement, uint32_t insert_idx, bool notify)
void Append(llvm::StringRef path, llvm::StringRef replacement, bool notify)
bool RemapPath(ConstString path, ConstString &new_path) const
bool GetPathsAtIndex(uint32_t idx, ConstString &path, ConstString &new_path) const
void Dump(Stream *s, int pair_index=-1)
static bool DownloadObjectAndSymbolFile(ModuleSpec &module_spec, Status &error, bool force_lookup=true, bool copy_executable=true)
void SetExecutableFile(const FileSpec &exe_file, bool add_exe_file_as_first_arg)
A plug-in interface definition class for debugging a process.
Definition Process.h:355
ThreadList & GetThreadList()
Definition Process.h:2312
void Flush()
Flush all data in the process.
Definition Process.cpp:6092
lldb::StateType GetState()
Get accessor for the current process state.
Definition Process.cpp:1259
const lldb::ABISP & GetABI()
Definition Process.cpp:1459
bool IsValid() const
Test if this object contains a valid regular expression.
virtual lldb::ScriptedFrameProviderInterfaceSP CreateScriptedFrameProviderInterface()
lldb::SectionSP FindSectionByName(ConstString section_dstr) const
Definition Section.cpp:556
void Dump(llvm::raw_ostream &s, unsigned indent, Target *target, bool show_header, uint32_t depth) const
Definition Section.cpp:642
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 uint32_t GetFrameIndex() const
Query this frame to find what frame it is in this Thread's StackFrameList.
An error handling class.
Definition Status.h:118
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition Status.cpp:106
static Status FromErrorString(const char *str)
Definition Status.h:141
bool Fail() const
Test for error condition.
Definition Status.cpp:293
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition Status.cpp:194
static Status static Status FromErrorStringWithFormatv(const char *format, Args &&...args)
Definition Status.h:151
const char * GetData() const
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
Definition Stream.h:28
void Format(const char *format, Args &&... args)
Forwards the arguments to llvm::formatv and writes to the stream.
Definition Stream.h:367
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition Stream.h:402
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
Definition Stream.cpp:155
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:132
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:63
size_t PutChar(char ch)
Definition Stream.cpp:129
void SetIndentLevel(unsigned level)
Set the current indentation level.
Definition Stream.cpp:194
void PutCStringColorHighlighted(llvm::StringRef text, std::optional< HighlightSettings > settings=std::nullopt)
Output a C string to the stream with color highlighting.
Definition Stream.cpp:73
size_t EOL()
Output and End of Line character to the stream.
Definition Stream.cpp:153
void IndentLess(unsigned amount=2)
Decrement the current indentation level.
Definition Stream.cpp:202
void IndentMore(unsigned amount=2)
Increment the current indentation level.
Definition Stream.cpp:199
unsigned GetIndentLevel() const
Get the current indentation level.
Definition Stream.cpp:191
void AddItem(const ObjectSP &item)
bool ForEach(std::function< bool(Object *object)> const &foreach_callback) const
bool GetValueForKeyAsInteger(llvm::StringRef key, IntType &result) const
bool GetValueForKeyAsString(llvm::StringRef key, llvm::StringRef &result) const
bool GetValueForKeyAsArray(llvm::StringRef key, Array *&result) const
void Dump(lldb_private::Stream &s, bool pretty_print=true) const
Defines a list of symbol context objects.
uint32_t GetSize() const
Get accessor for a symbol context list size.
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.
Function * function
The Function for a given query.
void SortTypeList(TypeMap &type_map, TypeList &type_list) const
Sorts the types in TypeMap according to SymbolContext to TypeList.
lldb::ModuleSP module_sp
The Module for a given query.
CompileUnit * comp_unit
The CompileUnit for a given query.
Symbol * symbol
The Symbol for a given query.
Provides public interface for all SymbolFiles.
Definition SymbolFile.h:51
virtual ObjectFile * GetObjectFile()=0
bool ValueIsAddress() const
Definition Symbol.cpp:165
bool GetByteSizeIsValid() const
Definition Symbol.h:209
Address & GetAddressRef()
Definition Symbol.h:73
lldb::addr_t GetByteSize() const
Definition Symbol.cpp:431
ConstString GetDisplayName() const
Definition Symbol.cpp:169
uint64_t GetRawValue() const
Get the raw value of the symbol from the symbol table.
Definition Symbol.h:110
Symbol * SymbolAtIndex(size_t idx)
Definition Symtab.cpp:225
uint32_t AppendSymbolIndexesWithName(ConstString symbol_name, std::vector< uint32_t > &matches)
Definition Symtab.cpp:679
uint32_t AppendSymbolIndexesMatchingRegExAndType(const RegularExpression &regex, lldb::SymbolType symbol_type, std::vector< uint32_t > &indexes, Mangled::NamePreference name_preference=Mangled::ePreferDemangled)
Definition Symtab.cpp:746
lldb::TargetSP GetTargetAtIndex(uint32_t index) const
Status CreateTarget(Debugger &debugger, llvm::StringRef user_exe_path, llvm::StringRef triple_str, LoadDependentFiles get_dependent_modules, const OptionGroupPlatform *platform_options, lldb::TargetSP &target_sp)
Create a new Target.
void SetSelectedTarget(uint32_t index)
bool DeleteTarget(lldb::TargetSP &target_sp)
Delete a Target object from the list.
lldb::TargetSP GetSelectedTarget()
size_t GetNumTargets() const
bool GetUserSpecifiedTrapHandlerNames(Args &args) const
Definition Target.cpp:5150
Environment GetEnvironment() const
Definition Target.cpp:4798
void SetActionFromString(const std::string &strings)
Definition Target.cpp:4109
void SetActionFromStrings(const std::vector< std::string > &strings)
Definition Target.cpp:4113
Status SetScriptCallback(std::string class_name, StructuredData::ObjectSP extra_args_sp)
Definition Target.cpp:4154
void ModulesDidLoad(ModuleList &module_list)
This call may preload module symbols, and may do so in parallel depending on the following target set...
Definition Target.cpp:1841
llvm::Expected< uint32_t > AddScriptedFrameProviderDescriptor(const ScriptedFrameProviderDescriptor &descriptor)
Add or update a scripted frame provider descriptor for this target.
Definition Target.cpp:3719
Module * GetExecutableModulePointer()
Definition Target.cpp:1541
PathMappingList & GetImageSearchPathList()
Definition Target.cpp:2588
std::shared_ptr< StopHook > StopHookSP
Definition Target.h:1658
void SymbolsDidLoad(ModuleList &module_list)
Definition Target.cpp:1868
const std::vector< StopHookSP > GetStopHooks(bool internal=false) const
Definition Target.cpp:3115
const llvm::MapVector< uint32_t, ScriptedFrameProviderDescriptor > & GetScriptedFrameProviderDescriptors() const
Get all scripted frame provider descriptors for this target.
Definition Target.cpp:3780
bool RemoveScriptedFrameProviderDescriptor(uint32_t id)
Remove a scripted frame provider descriptor by id.
Definition Target.cpp:3755
void DumpSectionLoadList(Stream &s)
Definition Target.cpp:5415
const lldb::ProcessSP & GetProcessSP() const
Definition Target.cpp:314
lldb::ModuleSP GetOrCreateModule(const ModuleSpec &module_spec, bool notify, Status *error_ptr=nullptr)
Find a binary on the system and return its Module, or return an existing Module that is already in th...
Definition Target.cpp:2338
void UndoCreateStopHook(lldb::user_id_t uid)
If you tried to create a stop hook, and that failed, call this to remove the stop hook,...
Definition Target.cpp:3067
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, uint32_t stop_id=SectionLoadHistory::eStopIDNow, bool allow_section_end=false)
Definition Target.cpp:3319
bool SetStopHookActiveStateByID(lldb::user_id_t uid, bool active_state)
Definition Target.cpp:3091
void SetAllStopHooksActiveState(bool active_state)
Definition Target.cpp:3102
StopHookSP CreateStopHook(StopHook::StopHookKind kind, bool internal=false)
Add an empty stop hook to the Target's stop hook list, and returns a shared pointer to the new hook.
Definition Target.cpp:3045
lldb::PlatformSP GetPlatform()
Definition Target.h:1694
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition Target.h:1157
const ArchSpec & GetArchitecture() const
Definition Target.h:1199
const std::string & GetLabel() const
Definition Target.h:673
void ClearScriptedFrameProviderDescriptors()
Clear all scripted frame provider descriptors for this target.
Definition Target.cpp:3768
lldb::ProcessSP CalculateProcess() override
Definition Target.cpp:2577
bool SetSectionLoadAddress(const lldb::SectionSP &section, lldb::addr_t load_addr, bool warn_multiple=false)
Definition Target.cpp:3330
bool RemoveStopHookByID(lldb::user_id_t uid)
Definition Target.cpp:3074
lldb::ThreadSP GetSelectedThread()
uint32_t GetSize(bool can_update=true)
lldb::ThreadSP GetThreadAtIndex(uint32_t idx, bool can_update=true)
void SetIndex(uint32_t index)
Definition ThreadSpec.h:47
void SetName(llvm::StringRef name)
Definition ThreadSpec.h:51
void SetTID(lldb::tid_t tid)
Definition ThreadSpec.h:49
void SetQueueName(llvm::StringRef queue_name)
Definition ThreadSpec.h:53
uint32_t GetSize() const
Definition TypeList.cpp:36
bool Empty() const
Definition TypeList.h:35
TypeIterable Types()
Definition TypeList.h:42
lldb::TypeSP GetTypeAtIndex(uint32_t idx)
Definition TypeList.cpp:42
A class that contains all state required for type lookups.
Definition Type.h:104
This class tracks the state and results of a TypeQuery.
Definition Type.h:344
TypeMap & GetTypeMap()
Definition Type.h:386
void Dump(Stream &s) const
Definition UUID.cpp:68
std::string GetAsString(llvm::StringRef separator="-") const
Definition UUID.cpp:54
bool IsValid() const
Definition UUID.h:69
lldb::FuncUnwindersSP GetFuncUnwindersContainingAddress(const Address &addr, const SymbolContext &sc)
lldb::FuncUnwindersSP GetUncachedFuncUnwindersContainingAddress(const Address &addr, const SymbolContext &sc)
A collection of ValueObject values that.
void Append(const lldb::ValueObjectSP &val_obj_sp)
lldb::ValueObjectSP GetValueObjectAtIndex(size_t idx)
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, const lldb::VariableSP &var_sp)
lldb::VariableSP GetVariableAtIndex(size_t idx) const
static Status GetValuesForVariableExpressionPath(llvm::StringRef variable_expr_path, ExecutionContextScope *scope, GetVariableCallback callback, void *baton, VariableList &variable_list, ValueObjectList &valobj_list)
Definition Variable.cpp:334
#define LLDB_OPT_SET_1
#define LLDB_OPT_SET_FROM_TO(A, B)
#define LLDB_OPT_SET_2
#define LLDB_INVALID_LINE_NUMBER
#define LLDB_INVALID_THREAD_ID
#define LLDB_INVALID_INDEX32
#define LLDB_OPT_SET_ALL
#define LLDB_INVALID_ADDRESS
#define UINT32_MAX
#define LLDB_INVALID_PROCESS_ID
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:327
std::vector< OptionArgElement > OptionElementVector
Definition Options.h:43
bool StateIsStoppedState(lldb::StateType state, bool must_exist)
Check if a state represents a state where the process or thread is stopped.
Definition State.cpp:89
void DumpAddress(llvm::raw_ostream &s, uint64_t addr, uint32_t addr_size, const char *prefix=nullptr, const char *suffix=nullptr)
Output an address value to this stream.
Definition Stream.cpp:106
const char * StateAsCString(lldb::StateType state)
Converts a StateType to a C string.
Definition State.cpp:14
std::string toString(FormatterBytecode::OpCodes op)
@ eSourceFileCompletion
std::shared_ptr< lldb_private::TypeSystem > TypeSystemSP
std::shared_ptr< lldb_private::ABI > ABISP
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
@ eDescriptionLevelBrief
@ eDescriptionLevelFull
std::shared_ptr< lldb_private::Thread > ThreadSP
std::shared_ptr< lldb_private::ScriptedMetadata > ScriptedMetadataSP
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Format
Display format definitions.
std::shared_ptr< lldb_private::Platform > PlatformSP
StateType
Process and Thread States.
std::shared_ptr< lldb_private::FuncUnwinders > FuncUnwindersSP
std::shared_ptr< lldb_private::Type > TypeSP
std::shared_ptr< lldb_private::Process > ProcessSP
@ eReturnStatusFailed
@ eReturnStatusSuccessFinishResult
@ eReturnStatusSuccessFinishNoResult
uint64_t pid_t
Definition lldb-types.h:83
@ eArgTypeOldPathPrefix
@ eArgTypeNewPathPrefix
@ eArgTypeUnsignedInteger
@ eArgTypeDirectoryName
std::shared_ptr< lldb_private::VariableList > VariableListSP
std::shared_ptr< lldb_private::UnwindPlan > UnwindPlanSP
std::shared_ptr< lldb_private::Variable > VariableSP
std::shared_ptr< lldb_private::ScriptedFrameProviderInterface > ScriptedFrameProviderInterfaceSP
uint64_t user_id_t
Definition lldb-types.h:82
std::shared_ptr< lldb_private::LockableStreamFile > LockableStreamFileSP
std::shared_ptr< lldb_private::Section > SectionSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP
uint64_t tid_t
Definition lldb-types.h:84
std::shared_ptr< lldb_private::Module > ModuleSP
@ eValueTypeVariableGlobal
globals variable
@ eValueTypeVariableLocal
function local variables
@ eValueTypeVariableArgument
function argument variables
@ eValueTypeVariableStatic
static variable
@ eValueTypeVariableThreadLocal
thread local storage variable
Used to build individual command argument lists.
Options used by Module::FindFunctions.
Definition Module.h:66
bool include_inlines
Include inlined functions.
Definition Module.h:70
bool include_symbols
Include the symbol table.
Definition Module.h:68
static int64_t ToOptionEnum(llvm::StringRef s, const OptionEnumValues &enum_values, int32_t fail_value, Status &error)
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.
static bool ToBoolean(llvm::StringRef s, bool fail_value, bool *success_ptr)
This struct contains the metadata needed to instantiate a frame provider and optional filters to cont...
void Dump(Stream *s) const
Dump a description of this descriptor to the given stream.
lldb::ScriptedFrameProviderInterfaceSP interface_sp
Interface for calling static methods on the provider class.
Struct to store information for color highlighting in the stream.
Definition Stream.h:37
#define PATH_MAX