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 auto on_error = llvm::make_scope_exit(
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 '%s' (%s).\n",
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]) {
1050 Log *log = GetLog(LLDBLog::Host);
1051 if (log) {
1052 LLDB_LOGF(log,
1053 "target modules search path adding ImageSearchPath "
1054 "pair: '%s' -> '%s'",
1055 from, to);
1056 }
1057 bool last_pair = ((argc - i) == 2);
1059 from, to, last_pair); // Notify if this is the last pair
1061 } else {
1062 if (from[0])
1063 result.AppendError("<path-prefix> can't be empty\n");
1064 else
1065 result.AppendError("<new-path-prefix> can't be empty\n");
1066 }
1067 }
1068 }
1069 }
1070};
1071
1072#pragma mark CommandObjectTargetModulesSearchPathsClear
1073
1075public:
1077 : CommandObjectParsed(interpreter, "target modules search-paths clear",
1078 "Clear all current image search path substitution "
1079 "pairs from the current target.",
1080 "target modules search-paths clear",
1081 eCommandRequiresTarget) {}
1082
1084
1085protected:
1086 void DoExecute(Args &command, CommandReturnObject &result) override {
1087 Target &target = GetTarget();
1088 bool notify = true;
1089 target.GetImageSearchPathList().Clear(notify);
1091 }
1092};
1093
1094#pragma mark CommandObjectTargetModulesSearchPathsInsert
1095
1097public:
1099 : CommandObjectParsed(interpreter, "target modules search-paths insert",
1100 "Insert a new image search path substitution pair "
1101 "into the current target at the specified index.",
1102 nullptr, eCommandRequiresTarget) {
1105 CommandArgumentData index_arg;
1106 CommandArgumentData old_prefix_arg;
1107 CommandArgumentData new_prefix_arg;
1108
1109 // Define the first and only variant of this arg.
1110 index_arg.arg_type = eArgTypeIndex;
1111 index_arg.arg_repetition = eArgRepeatPlain;
1112
1113 // Put the one and only variant into the first arg for m_arguments:
1114 arg1.push_back(index_arg);
1115
1116 // Define the first variant of this arg pair.
1117 old_prefix_arg.arg_type = eArgTypeOldPathPrefix;
1118 old_prefix_arg.arg_repetition = eArgRepeatPairPlus;
1119
1120 // Define the first variant of this arg pair.
1121 new_prefix_arg.arg_type = eArgTypeNewPathPrefix;
1122 new_prefix_arg.arg_repetition = eArgRepeatPairPlus;
1123
1124 // There are two required arguments that must always occur together, i.e.
1125 // an argument "pair". Because they must always occur together, they are
1126 // treated as two variants of one argument rather than two independent
1127 // arguments. Push them both into the same argument position for
1128 // m_arguments...
1129
1130 arg2.push_back(old_prefix_arg);
1131 arg2.push_back(new_prefix_arg);
1132
1133 // Add arguments to m_arguments.
1134 m_arguments.push_back(arg1);
1135 m_arguments.push_back(arg2);
1136 }
1137
1139
1140 void
1142 OptionElementVector &opt_element_vector) override {
1143 if (!m_exe_ctx.HasTargetScope() || request.GetCursorIndex() != 0)
1144 return;
1145
1146 Target *target = m_exe_ctx.GetTargetPtr();
1147 const PathMappingList &list = target->GetImageSearchPathList();
1148 const size_t num = list.GetSize();
1149 ConstString old_path, new_path;
1150 for (size_t i = 0; i < num; ++i) {
1151 if (!list.GetPathsAtIndex(i, old_path, new_path))
1152 break;
1153 StreamString strm;
1154 strm << old_path << " -> " << new_path;
1155 request.TryCompleteCurrentArg(std::to_string(i), strm.GetString());
1156 }
1157 }
1158
1159protected:
1160 void DoExecute(Args &command, CommandReturnObject &result) override {
1161 Target &target = GetTarget();
1162 size_t argc = command.GetArgumentCount();
1163 // check for at least 3 arguments and an odd number of parameters
1164 if (argc >= 3 && argc & 1) {
1165 uint32_t insert_idx;
1166
1167 if (!llvm::to_integer(command.GetArgumentAtIndex(0), insert_idx)) {
1168 result.AppendErrorWithFormat(
1169 "<index> parameter is not an integer: '%s'.\n",
1170 command.GetArgumentAtIndex(0));
1171 return;
1172 }
1173
1174 // shift off the index
1175 command.Shift();
1176 argc = command.GetArgumentCount();
1177
1178 for (uint32_t i = 0; i < argc; i += 2, ++insert_idx) {
1179 const char *from = command.GetArgumentAtIndex(i);
1180 const char *to = command.GetArgumentAtIndex(i + 1);
1181
1182 if (from[0] && to[0]) {
1183 bool last_pair = ((argc - i) == 2);
1184 target.GetImageSearchPathList().Insert(from, to, insert_idx,
1185 last_pair);
1187 } else {
1188 if (from[0])
1189 result.AppendError("<path-prefix> can't be empty\n");
1190 else
1191 result.AppendError("<new-path-prefix> can't be empty\n");
1192 return;
1193 }
1194 }
1195 } else {
1196 result.AppendError("insert requires at least three arguments\n");
1197 }
1198 }
1199};
1200
1201#pragma mark CommandObjectTargetModulesSearchPathsList
1202
1204public:
1206 : CommandObjectParsed(interpreter, "target modules search-paths list",
1207 "List all current image search path substitution "
1208 "pairs in the current target.",
1209 "target modules search-paths list",
1210 eCommandRequiresTarget) {}
1211
1213
1214protected:
1215 void DoExecute(Args &command, CommandReturnObject &result) override {
1216 Target &target = GetTarget();
1217 target.GetImageSearchPathList().Dump(&result.GetOutputStream());
1219 }
1220};
1221
1222#pragma mark CommandObjectTargetModulesSearchPathsQuery
1223
1225public:
1228 interpreter, "target modules search-paths query",
1229 "Transform a path using the first applicable image search path.",
1230 nullptr, eCommandRequiresTarget) {
1232 }
1233
1235
1236protected:
1237 void DoExecute(Args &command, CommandReturnObject &result) override {
1238 Target &target = GetTarget();
1239 if (command.GetArgumentCount() != 1) {
1240 result.AppendError("query requires one argument\n");
1241 return;
1242 }
1243
1244 ConstString orig(command.GetArgumentAtIndex(0));
1245 ConstString transformed;
1246 if (target.GetImageSearchPathList().RemapPath(orig, transformed))
1247 result.GetOutputStream().Printf("%s\n", transformed.GetCString());
1248 else
1249 result.GetOutputStream().Printf("%s\n", orig.GetCString());
1250
1252 }
1253};
1254
1255// Static Helper functions
1256static void DumpModuleArchitecture(Stream &strm, Module *module,
1257 bool full_triple, uint32_t width) {
1258 if (module) {
1259 StreamString arch_strm;
1260
1261 if (full_triple)
1262 module->GetArchitecture().DumpTriple(arch_strm.AsRawOstream());
1263 else
1264 arch_strm.PutCString(module->GetArchitecture().GetArchitectureName());
1265 std::string arch_str = std::string(arch_strm.GetString());
1266
1267 if (width)
1268 strm.Printf("%-*s", width, arch_str.c_str());
1269 else
1270 strm.PutCString(arch_str);
1271 }
1272}
1273
1274static void DumpModuleUUID(Stream &strm, Module *module) {
1275 if (module && module->GetUUID().IsValid())
1276 module->GetUUID().Dump(strm);
1277 else
1278 strm.PutCString(" ");
1279}
1280
1282 Stream &strm, Module *module,
1283 const FileSpec &file_spec,
1284 lldb::DescriptionLevel desc_level) {
1285 uint32_t num_matches = 0;
1286 if (module) {
1287 SymbolContextList sc_list;
1288 num_matches = module->ResolveSymbolContextsForFileSpec(
1289 file_spec, 0, false, eSymbolContextCompUnit, sc_list);
1290
1291 bool first_module = true;
1292 for (const SymbolContext &sc : sc_list) {
1293 if (!first_module)
1294 strm << "\n\n";
1295
1296 strm << "Line table for " << sc.comp_unit->GetPrimaryFile() << " in `"
1297 << module->GetFileSpec().GetFilename() << "\n";
1298 LineTable *line_table = sc.comp_unit->GetLineTable();
1299 if (line_table)
1300 line_table->GetDescription(
1301 &strm, interpreter.GetExecutionContext().GetTargetPtr(),
1302 desc_level);
1303 else
1304 strm << "No line table";
1305
1306 first_module = false;
1307 }
1308 }
1309 return num_matches;
1310}
1311
1312static void DumpFullpath(Stream &strm, const FileSpec *file_spec_ptr,
1313 uint32_t width) {
1314 if (file_spec_ptr) {
1315 if (width > 0) {
1316 std::string fullpath = file_spec_ptr->GetPath();
1317 strm.Printf("%-*s", width, fullpath.c_str());
1318 return;
1319 } else {
1320 file_spec_ptr->Dump(strm.AsRawOstream());
1321 return;
1322 }
1323 }
1324 // Keep the width spacing correct if things go wrong...
1325 if (width > 0)
1326 strm.Printf("%-*s", width, "");
1327}
1328
1329static void DumpDirectory(Stream &strm, const FileSpec *file_spec_ptr,
1330 uint32_t width) {
1331 if (file_spec_ptr) {
1332 if (width > 0)
1333 strm.Printf("%-*s", width, file_spec_ptr->GetDirectory().AsCString(""));
1334 else
1335 file_spec_ptr->GetDirectory().Dump(&strm);
1336 return;
1337 }
1338 // Keep the width spacing correct if things go wrong...
1339 if (width > 0)
1340 strm.Printf("%-*s", width, "");
1341}
1342
1343static void DumpBasename(Stream &strm, const FileSpec *file_spec_ptr,
1344 uint32_t width) {
1345 if (file_spec_ptr) {
1346 if (width > 0)
1347 strm.Printf("%-*s", width, file_spec_ptr->GetFilename().AsCString(""));
1348 else
1349 file_spec_ptr->GetFilename().Dump(&strm);
1350 return;
1351 }
1352 // Keep the width spacing correct if things go wrong...
1353 if (width > 0)
1354 strm.Printf("%-*s", width, "");
1355}
1356
1357static size_t DumpModuleObjfileHeaders(Stream &strm, ModuleList &module_list) {
1358 std::lock_guard<std::recursive_mutex> guard(module_list.GetMutex());
1359 const size_t num_modules = module_list.GetSize();
1360 if (num_modules == 0)
1361 return 0;
1362
1363 size_t num_dumped = 0;
1364 strm.Format("Dumping headers for {0} module(s).\n", num_modules);
1365 strm.IndentMore();
1366 for (ModuleSP module_sp : module_list.ModulesNoLocking()) {
1367 if (module_sp) {
1368 if (num_dumped++ > 0) {
1369 strm.EOL();
1370 strm.EOL();
1371 }
1372 ObjectFile *objfile = module_sp->GetObjectFile();
1373 if (objfile)
1374 objfile->Dump(&strm);
1375 else {
1376 strm.Format("No object file for module: {0:F}\n",
1377 module_sp->GetFileSpec());
1378 }
1379 }
1380 }
1381 strm.IndentLess();
1382 return num_dumped;
1383}
1384
1385static void DumpModuleSymtab(CommandInterpreter &interpreter, Stream &strm,
1386 Module *module, SortOrder sort_order,
1387 Mangled::NamePreference name_preference) {
1388 if (!module)
1389 return;
1390 if (Symtab *symtab = module->GetSymtab())
1391 symtab->Dump(&strm, interpreter.GetExecutionContext().GetTargetPtr(),
1392 sort_order, name_preference);
1393}
1394
1395static void DumpModuleSections(CommandInterpreter &interpreter, Stream &strm,
1396 Module *module) {
1397 if (module) {
1398 SectionList *section_list = module->GetSectionList();
1399 if (section_list) {
1400 strm.Printf("Sections for '%s' (%s):\n",
1401 module->GetSpecificationDescription().c_str(),
1403 section_list->Dump(strm.AsRawOstream(), strm.GetIndentLevel() + 2,
1404 interpreter.GetExecutionContext().GetTargetPtr(), true,
1405 UINT32_MAX);
1406 }
1407 }
1408}
1409
1410static bool DumpModuleSymbolFile(Stream &strm, Module *module) {
1411 if (module) {
1412 if (SymbolFile *symbol_file = module->GetSymbolFile(true)) {
1413 symbol_file->Dump(strm);
1414 return true;
1415 }
1416 }
1417 return false;
1418}
1419
1421 Module *module, bool errors_only,
1422 bool load_all_debug_info) {
1423 if (module) {
1424 if (SymbolFile *symbol_file = module->GetSymbolFile(/*can_create=*/true)) {
1426 if (symbol_file->GetSeparateDebugInfo(d, errors_only,
1427 load_all_debug_info)) {
1428 list.AddItem(
1429 std::make_shared<StructuredData::Dictionary>(std::move(d)));
1430 return true;
1431 }
1432 }
1433 }
1434 return false;
1435}
1436
1437static void DumpDwoFilesTable(Stream &strm,
1438 StructuredData::Array &dwo_listings) {
1439 strm.PutCString("Dwo ID Err Dwo Path");
1440 strm.EOL();
1441 strm.PutCString(
1442 "------------------ --- -----------------------------------------");
1443 strm.EOL();
1444 dwo_listings.ForEach([&strm](StructuredData::Object *dwo) {
1446 if (!dict)
1447 return false;
1448
1449 uint64_t dwo_id;
1450 if (dict->GetValueForKeyAsInteger("dwo_id", dwo_id))
1451 strm.Printf("0x%16.16" PRIx64 " ", dwo_id);
1452 else
1453 strm.Printf("0x???????????????? ");
1454
1455 llvm::StringRef error;
1456 if (dict->GetValueForKeyAsString("error", error))
1457 strm << "E " << error;
1458 else {
1459 llvm::StringRef resolved_dwo_path;
1460 if (dict->GetValueForKeyAsString("resolved_dwo_path",
1461 resolved_dwo_path)) {
1462 strm << " " << resolved_dwo_path;
1463 if (resolved_dwo_path.ends_with(".dwp")) {
1464 llvm::StringRef dwo_name;
1465 if (dict->GetValueForKeyAsString("dwo_name", dwo_name))
1466 strm << "(" << dwo_name << ")";
1467 }
1468 }
1469 }
1470 strm.EOL();
1471 return true;
1472 });
1473}
1474
1475static void DumpOsoFilesTable(Stream &strm,
1476 StructuredData::Array &oso_listings) {
1477 strm.PutCString("Mod Time Err Oso Path");
1478 strm.EOL();
1479 strm.PutCString("------------------ --- ---------------------");
1480 strm.EOL();
1481 oso_listings.ForEach([&strm](StructuredData::Object *oso) {
1483 if (!dict)
1484 return false;
1485
1486 uint32_t oso_mod_time;
1487 if (dict->GetValueForKeyAsInteger("oso_mod_time", oso_mod_time))
1488 strm.Printf("0x%16.16" PRIx32 " ", oso_mod_time);
1489
1490 llvm::StringRef error;
1491 if (dict->GetValueForKeyAsString("error", error))
1492 strm << "E " << error;
1493 else {
1494 llvm::StringRef oso_path;
1495 if (dict->GetValueForKeyAsString("oso_path", oso_path))
1496 strm << " " << oso_path;
1497 }
1498 strm.EOL();
1499 return true;
1500 });
1501}
1502
1503static void
1504DumpAddress(ExecutionContextScope *exe_scope, const Address &so_addr,
1505 bool verbose, bool all_ranges, Stream &strm,
1506 std::optional<Stream::HighlightSettings> settings = std::nullopt) {
1507 strm.IndentMore();
1508 strm.Indent(" Address: ");
1509 so_addr.Dump(&strm, exe_scope, Address::DumpStyleModuleWithFileAddress);
1510 strm.PutCString(" (");
1511 so_addr.Dump(&strm, exe_scope, Address::DumpStyleSectionNameOffset);
1512 strm.PutCString(")\n");
1513 strm.Indent(" Summary: ");
1514 const uint32_t save_indent = strm.GetIndentLevel();
1515 strm.SetIndentLevel(save_indent + 13);
1516 so_addr.Dump(&strm, exe_scope, Address::DumpStyleResolvedDescription,
1517 Address::DumpStyleInvalid, UINT32_MAX, false, settings);
1518 strm.SetIndentLevel(save_indent);
1519 // Print out detailed address information when verbose is enabled
1520 if (verbose) {
1521 strm.EOL();
1522 so_addr.Dump(&strm, exe_scope, Address::DumpStyleDetailedSymbolContext,
1523 Address::DumpStyleInvalid, UINT32_MAX, all_ranges, settings);
1524 }
1525 strm.IndentLess();
1526}
1527
1528static bool LookupAddressInModule(CommandInterpreter &interpreter, Stream &strm,
1529 Module *module, uint32_t resolve_mask,
1530 lldb::addr_t raw_addr, lldb::addr_t offset,
1531 bool verbose, bool all_ranges) {
1532 if (module) {
1533 lldb::addr_t addr = raw_addr - offset;
1534 Address so_addr;
1535 SymbolContext sc;
1536 Target *target = interpreter.GetExecutionContext().GetTargetPtr();
1537 if (target && target->HasLoadedSections()) {
1538 if (!target->ResolveLoadAddress(addr, so_addr))
1539 return false;
1540 else if (so_addr.GetModule().get() != module)
1541 return false;
1542 } else {
1543 if (!module->ResolveFileAddress(addr, so_addr))
1544 return false;
1545 }
1546
1547 ExecutionContextScope *exe_scope =
1549 DumpAddress(exe_scope, so_addr, verbose, all_ranges, strm);
1550 return true;
1551 }
1552
1553 return false;
1554}
1555
1556static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter,
1557 Stream &strm, Module *module,
1558 const char *name, bool name_is_regex,
1559 bool verbose, bool all_ranges) {
1560 if (!module)
1561 return 0;
1562
1563 Symtab *symtab = module->GetSymtab();
1564 if (!symtab)
1565 return 0;
1566
1567 SymbolContext sc;
1568 const bool use_color = interpreter.GetDebugger().GetUseColor();
1569 std::vector<uint32_t> match_indexes;
1570 ConstString symbol_name(name);
1571 uint32_t num_matches = 0;
1572 if (name_is_regex) {
1573 RegularExpression name_regexp(symbol_name.GetStringRef());
1574 num_matches = symtab->AppendSymbolIndexesMatchingRegExAndType(
1575 name_regexp, eSymbolTypeAny, match_indexes);
1576 } else {
1577 num_matches =
1578 symtab->AppendSymbolIndexesWithName(symbol_name, match_indexes);
1579 }
1580
1581 if (num_matches > 0) {
1582 strm.Indent();
1583 strm.Printf("%u symbols match %s'%s' in ", num_matches,
1584 name_is_regex ? "the regular expression " : "", name);
1585 DumpFullpath(strm, &module->GetFileSpec(), 0);
1586 strm.PutCString(":\n");
1587 strm.IndentMore();
1589 name, interpreter.GetDebugger().GetRegexMatchAnsiPrefix(),
1590 interpreter.GetDebugger().GetRegexMatchAnsiSuffix());
1591 for (uint32_t i = 0; i < num_matches; ++i) {
1592 Symbol *symbol = symtab->SymbolAtIndex(match_indexes[i]);
1593 if (symbol) {
1594 if (symbol->ValueIsAddress()) {
1597 symbol->GetAddressRef(), verbose, all_ranges, strm,
1598 use_color && name_is_regex
1599 ? std::optional<Stream::HighlightSettings>{settings}
1600 : std::nullopt);
1601 strm.EOL();
1602 } else {
1603 strm.IndentMore();
1604 strm.Indent(" Name: ");
1606 symbol->GetDisplayName().GetStringRef(),
1607 use_color && name_is_regex
1608 ? std::optional<Stream::HighlightSettings>{settings}
1609 : std::nullopt);
1610 strm.EOL();
1611 strm.Indent(" Value: ");
1612 strm.Printf("0x%16.16" PRIx64 "\n", symbol->GetRawValue());
1613 if (symbol->GetByteSizeIsValid()) {
1614 strm.Indent(" Size: ");
1615 strm.Printf("0x%16.16" PRIx64 "\n", symbol->GetByteSize());
1616 }
1617 strm.IndentLess();
1618 }
1619 }
1620 }
1621 strm.IndentLess();
1622 }
1623 return num_matches;
1624}
1625
1627 ExecutionContextScope *exe_scope, Stream &strm,
1628 const SymbolContextList &sc_list, bool verbose, bool all_ranges,
1629 std::optional<Stream::HighlightSettings> settings = std::nullopt) {
1630 strm.IndentMore();
1631 bool first_module = true;
1632 for (const SymbolContext &sc : sc_list) {
1633 if (!first_module)
1634 strm.EOL();
1635
1636 Address addr;
1637 if (sc.line_entry.IsValid())
1638 addr = sc.line_entry.range.GetBaseAddress();
1639 else if (sc.block && sc.block->GetContainingInlinedBlock())
1640 sc.block->GetContainingInlinedBlock()->GetStartAddress(addr);
1641 else
1642 addr = sc.GetFunctionOrSymbolAddress();
1643
1644 DumpAddress(exe_scope, addr, verbose, all_ranges, strm, settings);
1645 first_module = false;
1646 }
1647 strm.IndentLess();
1648}
1649
1651 Stream &strm, Module *module,
1652 const char *name, bool name_is_regex,
1653 const ModuleFunctionSearchOptions &options,
1654 bool verbose, bool all_ranges) {
1655 if (module && name && name[0]) {
1656 SymbolContextList sc_list;
1657 size_t num_matches = 0;
1658 if (name_is_regex) {
1659 RegularExpression function_name_regex((llvm::StringRef(name)));
1660 module->FindFunctions(function_name_regex, options, sc_list);
1661 } else {
1662 ConstString function_name(name);
1663 module->FindFunctions(function_name, CompilerDeclContext(),
1664 eFunctionNameTypeAuto, options, sc_list);
1665 }
1666 num_matches = sc_list.GetSize();
1667 if (num_matches) {
1668 strm.Indent();
1669 strm.Printf("%" PRIu64 " match%s found in ", (uint64_t)num_matches,
1670 num_matches > 1 ? "es" : "");
1671 DumpFullpath(strm, &module->GetFileSpec(), 0);
1672 strm.PutCString(":\n");
1675 strm, sc_list, verbose, all_ranges);
1676 }
1677 return num_matches;
1678 }
1679 return 0;
1680}
1681
1682static size_t LookupTypeInModule(Target *target,
1683 CommandInterpreter &interpreter, Stream &strm,
1684 Module *module, const char *name_cstr,
1685 bool name_is_regex) {
1686 if (module && name_cstr && name_cstr[0]) {
1687 TypeQuery query(name_cstr);
1688 TypeResults results;
1689 module->FindTypes(query, results);
1690
1691 TypeList type_list;
1692 SymbolContext sc;
1693 if (module)
1694 sc.module_sp = module->shared_from_this();
1695 // Sort the type results and put the results that matched in \a module
1696 // first if \a module was specified.
1697 sc.SortTypeList(results.GetTypeMap(), type_list);
1698 if (type_list.Empty())
1699 return 0;
1700
1701 const uint64_t num_matches = type_list.GetSize();
1702
1703 strm.Indent();
1704 strm.Printf("%" PRIu64 " match%s found in ", num_matches,
1705 num_matches > 1 ? "es" : "");
1706 DumpFullpath(strm, &module->GetFileSpec(), 0);
1707 strm.PutCString(":\n");
1708 for (TypeSP type_sp : type_list.Types()) {
1709 if (!type_sp)
1710 continue;
1711 // Resolve the clang type so that any forward references to types
1712 // that haven't yet been parsed will get parsed.
1713 type_sp->GetFullCompilerType();
1714 type_sp->GetDescription(&strm, eDescriptionLevelFull, true, target);
1715 // Print all typedef chains
1716 TypeSP typedef_type_sp(type_sp);
1717 TypeSP typedefed_type_sp(typedef_type_sp->GetTypedefType());
1718 while (typedefed_type_sp) {
1719 strm.EOL();
1720 strm.Printf(" typedef '%s': ",
1721 typedef_type_sp->GetName().GetCString());
1722 typedefed_type_sp->GetFullCompilerType();
1723 typedefed_type_sp->GetDescription(&strm, eDescriptionLevelFull, true,
1724 target);
1725 typedef_type_sp = typedefed_type_sp;
1726 typedefed_type_sp = typedef_type_sp->GetTypedefType();
1727 }
1728 strm.EOL();
1729 }
1730 return type_list.GetSize();
1731 }
1732 return 0;
1733}
1734
1735static size_t LookupTypeHere(Target *target, CommandInterpreter &interpreter,
1736 Stream &strm, Module &module,
1737 const char *name_cstr, bool name_is_regex) {
1738 TypeQuery query(name_cstr);
1739 TypeResults results;
1740 module.FindTypes(query, results);
1741 TypeList type_list;
1742 SymbolContext sc;
1743 sc.module_sp = module.shared_from_this();
1744 sc.SortTypeList(results.GetTypeMap(), type_list);
1745 if (type_list.Empty())
1746 return 0;
1747
1748 strm.Indent();
1749 strm.PutCString("Best match found in ");
1750 DumpFullpath(strm, &module.GetFileSpec(), 0);
1751 strm.PutCString(":\n");
1752
1753 TypeSP type_sp(type_list.GetTypeAtIndex(0));
1754 if (type_sp) {
1755 // Resolve the clang type so that any forward references to types that
1756 // haven't yet been parsed will get parsed.
1757 type_sp->GetFullCompilerType();
1758 type_sp->GetDescription(&strm, eDescriptionLevelFull, true, target);
1759 // Print all typedef chains.
1760 TypeSP typedef_type_sp(type_sp);
1761 TypeSP typedefed_type_sp(typedef_type_sp->GetTypedefType());
1762 while (typedefed_type_sp) {
1763 strm.EOL();
1764 strm.Printf(" typedef '%s': ",
1765 typedef_type_sp->GetName().GetCString());
1766 typedefed_type_sp->GetFullCompilerType();
1767 typedefed_type_sp->GetDescription(&strm, eDescriptionLevelFull, true,
1768 target);
1769 typedef_type_sp = typedefed_type_sp;
1770 typedefed_type_sp = typedef_type_sp->GetTypedefType();
1771 }
1772 }
1773 strm.EOL();
1774 return type_list.GetSize();
1775}
1776
1778 Stream &strm, Module *module,
1779 const FileSpec &file_spec,
1780 uint32_t line, bool check_inlines,
1781 bool verbose, bool all_ranges) {
1782 if (module && file_spec) {
1783 SymbolContextList sc_list;
1784 const uint32_t num_matches = module->ResolveSymbolContextsForFileSpec(
1785 file_spec, line, check_inlines, eSymbolContextEverything, sc_list);
1786 if (num_matches > 0) {
1787 strm.Indent();
1788 strm.Printf("%u match%s found in ", num_matches,
1789 num_matches > 1 ? "es" : "");
1790 strm << file_spec;
1791 if (line > 0)
1792 strm.Printf(":%u", line);
1793 strm << " in ";
1794 DumpFullpath(strm, &module->GetFileSpec(), 0);
1795 strm.PutCString(":\n");
1798 strm, sc_list, verbose, all_ranges);
1799 return num_matches;
1800 }
1801 }
1802 return 0;
1803}
1804
1805static size_t FindModulesByName(Target *target, const char *module_name,
1806 ModuleList &module_list,
1807 bool check_global_list) {
1808 FileSpec module_file_spec(module_name);
1809 ModuleSpec module_spec(module_file_spec);
1810
1811 const size_t initial_size = module_list.GetSize();
1812
1813 if (check_global_list) {
1814 // Check the global list
1815 std::lock_guard<std::recursive_mutex> guard(
1817 const size_t num_modules = Module::GetNumberAllocatedModules();
1818 ModuleSP module_sp;
1819 for (size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
1820 Module *module = Module::GetAllocatedModuleAtIndex(image_idx);
1821
1822 if (module) {
1823 if (module->MatchesModuleSpec(module_spec)) {
1824 module_sp = module->shared_from_this();
1825 module_list.AppendIfNeeded(module_sp);
1826 }
1827 }
1828 }
1829 } else {
1830 if (target) {
1831 target->GetImages().FindModules(module_spec, module_list);
1832 const size_t num_matches = module_list.GetSize();
1833
1834 // Not found in our module list for our target, check the main shared
1835 // module list in case it is a extra file used somewhere else
1836 if (num_matches == 0) {
1837 module_spec.GetArchitecture() = target->GetArchitecture();
1838 ModuleList::FindSharedModules(module_spec, module_list);
1839 }
1840 } else {
1841 ModuleList::FindSharedModules(module_spec, module_list);
1842 }
1843 }
1844
1845 return module_list.GetSize() - initial_size;
1846}
1847
1848#pragma mark CommandObjectTargetModulesModuleAutoComplete
1849
1850// A base command object class that can auto complete with module file
1851// paths
1852
1854 : public CommandObjectParsed {
1855public:
1857 const char *name,
1858 const char *help,
1859 const char *syntax,
1860 uint32_t flags = 0)
1861 : CommandObjectParsed(interpreter, name, help, syntax, flags) {
1863 }
1864
1866
1867 void
1873};
1874
1875#pragma mark CommandObjectTargetModulesSourceFileAutoComplete
1876
1877// A base command object class that can auto complete with module source
1878// file paths
1879
1881 : public CommandObjectParsed {
1882public:
1884 CommandInterpreter &interpreter, const char *name, const char *help,
1885 const char *syntax, uint32_t flags)
1886 : CommandObjectParsed(interpreter, name, help, syntax, flags) {
1888 }
1889
1891
1892 void
1898};
1899
1900#pragma mark CommandObjectTargetModulesDumpObjfile
1901
1904public:
1907 interpreter, "target modules dump objfile",
1908 "Dump the object file headers from one or more target modules.",
1909 nullptr, eCommandRequiresTarget) {}
1910
1912
1913protected:
1914 void DoExecute(Args &command, CommandReturnObject &result) override {
1915 Target &target = GetTarget();
1916
1917 uint32_t addr_byte_size = target.GetArchitecture().GetAddressByteSize();
1918 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
1919 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
1920
1921 size_t num_dumped = 0;
1922 if (command.GetArgumentCount() == 0) {
1923 // Dump all headers for all modules images
1924 num_dumped = DumpModuleObjfileHeaders(result.GetOutputStream(),
1925 target.GetImages());
1926 if (num_dumped == 0) {
1927 result.AppendError("the target has no associated executable images");
1928 }
1929 } else {
1930 // Find the modules that match the basename or full path.
1931 ModuleList module_list;
1932 const char *arg_cstr;
1933 for (int arg_idx = 0;
1934 (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != nullptr;
1935 ++arg_idx) {
1936 size_t num_matched =
1937 FindModulesByName(&target, arg_cstr, module_list, true);
1938 if (num_matched == 0) {
1940 "Unable to find an image that matches '%s'.\n", arg_cstr);
1941 }
1942 }
1943 // Dump all the modules we found.
1944 num_dumped =
1945 DumpModuleObjfileHeaders(result.GetOutputStream(), module_list);
1946 }
1947
1948 if (num_dumped > 0) {
1950 } else {
1951 result.AppendError("no matching executable images found");
1952 }
1953 }
1954};
1955
1956#define LLDB_OPTIONS_target_modules_dump_symtab
1957#include "CommandOptions.inc"
1958
1961public:
1964 interpreter, "target modules dump symtab",
1965 "Dump the symbol table from one or more target modules.", nullptr,
1966 eCommandRequiresTarget) {}
1967
1969
1970 Options *GetOptions() override { return &m_options; }
1971
1972 class CommandOptions : public Options {
1973 public:
1974 CommandOptions() = default;
1975
1976 ~CommandOptions() override = default;
1977
1978 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1979 ExecutionContext *execution_context) override {
1980 Status error;
1981 const int short_option = m_getopt_table[option_idx].val;
1982
1983 switch (short_option) {
1984 case 'm':
1985 m_prefer_mangled.SetCurrentValue(true);
1986 m_prefer_mangled.SetOptionWasSet();
1987 break;
1988
1989 case 's':
1991 option_arg, GetDefinitions()[option_idx].enum_values,
1993 break;
1994
1995 default:
1996 llvm_unreachable("Unimplemented option");
1997 }
1998 return error;
1999 }
2000
2001 void OptionParsingStarting(ExecutionContext *execution_context) override {
2003 m_prefer_mangled.Clear();
2004 }
2005
2006 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
2007 return llvm::ArrayRef(g_target_modules_dump_symtab_options);
2008 }
2009
2012 };
2013
2014protected:
2015 void DoExecute(Args &command, CommandReturnObject &result) override {
2016 Target &target = GetTarget();
2017 uint32_t num_dumped = 0;
2018 Mangled::NamePreference name_preference =
2019 (m_options.m_prefer_mangled ? Mangled::ePreferMangled
2021
2022 uint32_t addr_byte_size = target.GetArchitecture().GetAddressByteSize();
2023 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2024 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2025
2026 if (command.GetArgumentCount() == 0) {
2027 // Dump all sections for all modules images
2028 const ModuleList &module_list = target.GetImages();
2029 std::lock_guard<std::recursive_mutex> guard(module_list.GetMutex());
2030 const size_t num_modules = module_list.GetSize();
2031 if (num_modules > 0) {
2032 result.GetOutputStream().Format(
2033 "Dumping symbol table for {0} modules.\n", num_modules);
2034 for (ModuleSP module_sp : module_list.ModulesNoLocking()) {
2035 if (num_dumped > 0) {
2036 result.GetOutputStream().EOL();
2037 result.GetOutputStream().EOL();
2038 }
2040 "Interrupted in dump all symtabs with {0} "
2041 "of {1} dumped.", num_dumped, num_modules))
2042 break;
2043
2044 num_dumped++;
2046 module_sp.get(), m_options.m_sort_order,
2047 name_preference);
2048 }
2049 } else {
2050 result.AppendError("the target has no associated executable images");
2051 return;
2052 }
2053 } else {
2054 // Dump specified images (by basename or fullpath)
2055 const char *arg_cstr;
2056 for (int arg_idx = 0;
2057 (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != nullptr;
2058 ++arg_idx) {
2059 ModuleList module_list;
2060 const size_t num_matches =
2061 FindModulesByName(&target, arg_cstr, module_list, true);
2062 if (num_matches > 0) {
2063 for (ModuleSP module_sp : module_list.Modules()) {
2064 if (module_sp) {
2065 if (num_dumped > 0) {
2066 result.GetOutputStream().EOL();
2067 result.GetOutputStream().EOL();
2068 }
2070 "Interrupted in dump symtab list with {0} of {1} dumped.",
2071 num_dumped, num_matches))
2072 break;
2073
2074 num_dumped++;
2076 module_sp.get(), m_options.m_sort_order,
2077 name_preference);
2078 }
2079 }
2080 } else
2082 "Unable to find an image that matches '%s'.\n", arg_cstr);
2083 }
2084 }
2085
2086 if (num_dumped > 0)
2088 else {
2089 result.AppendError("no matching executable images found");
2090 }
2091 }
2092
2094};
2095
2096#pragma mark CommandObjectTargetModulesDumpSections
2097
2098// Image section dumping command
2099
2102public:
2105 interpreter, "target modules dump sections",
2106 "Dump the sections from one or more target modules.",
2107 //"target modules dump sections [<file1> ...]")
2108 nullptr, eCommandRequiresTarget) {}
2109
2111
2112protected:
2113 void DoExecute(Args &command, CommandReturnObject &result) override {
2114 Target &target = GetTarget();
2115 uint32_t num_dumped = 0;
2116
2117 uint32_t addr_byte_size = target.GetArchitecture().GetAddressByteSize();
2118 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2119 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2120
2121 if (command.GetArgumentCount() == 0) {
2122 // Dump all sections for all modules images
2123 const size_t num_modules = target.GetImages().GetSize();
2124 if (num_modules == 0) {
2125 result.AppendError("the target has no associated executable images");
2126 return;
2127 }
2128
2129 result.GetOutputStream().Format("Dumping sections for {0} modules.\n",
2130 num_modules);
2131 for (size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
2133 "Interrupted in dump all sections with {0} of {1} dumped",
2134 image_idx, num_modules))
2135 break;
2136
2137 num_dumped++;
2140 target.GetImages().GetModulePointerAtIndex(image_idx));
2141 }
2142 } else {
2143 // Dump specified images (by basename or fullpath)
2144 const char *arg_cstr;
2145 for (int arg_idx = 0;
2146 (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != nullptr;
2147 ++arg_idx) {
2148 ModuleList module_list;
2149 const size_t num_matches =
2150 FindModulesByName(&target, arg_cstr, module_list, true);
2151 if (num_matches > 0) {
2152 for (size_t i = 0; i < num_matches; ++i) {
2154 "Interrupted in dump section list with {0} of {1} dumped.",
2155 i, num_matches))
2156 break;
2157
2158 Module *module = module_list.GetModulePointerAtIndex(i);
2159 if (module) {
2160 num_dumped++;
2162 module);
2163 }
2164 }
2165 } else {
2166 // Check the global list
2167 std::lock_guard<std::recursive_mutex> guard(
2169
2171 "Unable to find an image that matches '%s'.\n", arg_cstr);
2172 }
2173 }
2174 }
2175
2176 if (num_dumped > 0)
2178 else {
2179 result.AppendError("no matching executable images found");
2180 }
2181 }
2182};
2183
2185public:
2188 interpreter, "target modules dump pcm-info",
2189 "Dump information about the given clang module (pcm).") {
2190 // Take a single file argument.
2192 }
2193
2195
2196protected:
2197 void DoExecute(Args &command, CommandReturnObject &result) override {
2198 if (command.GetArgumentCount() != 1) {
2199 result.AppendErrorWithFormat("'%s' takes exactly one pcm path argument.",
2200 m_cmd_name.c_str());
2201 return;
2202 }
2203
2204 const char *pcm_path = command.GetArgumentAtIndex(0);
2205 const FileSpec pcm_file{pcm_path};
2206
2207 if (pcm_file.GetFileNameExtension() != ".pcm") {
2208 result.AppendError("file must have a .pcm extension");
2209 return;
2210 }
2211
2212 if (!FileSystem::Instance().Exists(pcm_file)) {
2213 result.AppendError("pcm file does not exist");
2214 return;
2215 }
2216
2217 const char *clang_args[] = {"clang", pcm_path};
2218 clang::CompilerInstance compiler(clang::createInvocation(clang_args));
2219 compiler.setVirtualFileSystem(
2220 FileSystem::Instance().GetVirtualFileSystem());
2221 compiler.createDiagnostics();
2222
2223 // Pass empty deleter to not attempt to free memory that was allocated
2224 // outside of the current scope, possibly statically.
2225 std::shared_ptr<llvm::raw_ostream> Out(
2226 &result.GetOutputStream().AsRawOstream(), [](llvm::raw_ostream *) {});
2227 clang::DumpModuleInfoAction dump_module_info(Out);
2228 // DumpModuleInfoAction requires ObjectFilePCHContainerReader.
2229 compiler.getPCHContainerOperations()->registerReader(
2230 std::make_unique<clang::ObjectFilePCHContainerReader>());
2231
2232 if (compiler.ExecuteAction(dump_module_info))
2234 }
2235};
2236
2237#pragma mark CommandObjectTargetModulesDumpClangAST
2238
2239// Clang AST dumping command
2240
2243public:
2246 interpreter, "target modules dump ast",
2247 "Dump the clang ast for a given module's symbol file.",
2248 "target modules dump ast [--filter <name>] [<file1> ...]",
2249 eCommandRequiresTarget),
2250 m_filter(LLDB_OPT_SET_1, false, "filter", 'f', 0, eArgTypeName,
2251 "Dump only the decls whose names contain the specified filter "
2252 "string.",
2253 /*default_value=*/"") {
2255 m_option_group.Finalize();
2256 }
2257
2258 Options *GetOptions() override { return &m_option_group; }
2259
2261
2264
2265protected:
2266 void DoExecute(Args &command, CommandReturnObject &result) override {
2267 Target &target = GetTarget();
2268
2269 const ModuleList &module_list = target.GetImages();
2270 const size_t num_modules = module_list.GetSize();
2271 if (num_modules == 0) {
2272 result.AppendError("the target has no associated executable images");
2273 return;
2274 }
2275
2276 llvm::StringRef filter = m_filter.GetOptionValue().GetCurrentValueAsRef();
2277
2278 if (command.GetArgumentCount() == 0) {
2279 // Dump all ASTs for all modules images
2280 result.GetOutputStream().Format("Dumping clang ast for {0} modules.\n",
2281 num_modules);
2282 for (ModuleSP module_sp : module_list.ModulesNoLocking()) {
2283 if (INTERRUPT_REQUESTED(GetDebugger(), "Interrupted dumping clang ast"))
2284 break;
2285 if (SymbolFile *sf = module_sp->GetSymbolFile())
2286 sf->DumpClangAST(result.GetOutputStream(), filter,
2287 GetCommandInterpreter().GetDebugger().GetUseColor());
2288 }
2290 return;
2291 }
2292
2293 // Dump specified ASTs (by basename or fullpath)
2294 for (const Args::ArgEntry &arg : command.entries()) {
2295 ModuleList module_list;
2296 const size_t num_matches =
2297 FindModulesByName(&target, arg.c_str(), module_list, true);
2298 if (num_matches == 0) {
2299 // Check the global list
2300 std::lock_guard<std::recursive_mutex> guard(
2302
2304 "Unable to find an image that matches '%s'.\n", arg.c_str());
2305 continue;
2306 }
2307
2308 for (size_t i = 0; i < num_matches; ++i) {
2310 "Interrupted in dump clang ast list with {0} of {1} dumped.",
2311 i, num_matches))
2312 break;
2313
2314 Module *m = module_list.GetModulePointerAtIndex(i);
2315 if (SymbolFile *sf = m->GetSymbolFile())
2316 sf->DumpClangAST(result.GetOutputStream(), filter,
2317 GetCommandInterpreter().GetDebugger().GetUseColor());
2318 }
2319 }
2321 }
2322};
2323
2324#pragma mark CommandObjectTargetModulesDumpSymfile
2325
2326// Image debug symbol dumping command
2327
2330public:
2333 interpreter, "target modules dump symfile",
2334 "Dump the debug symbol file for one or more target modules.",
2335 //"target modules dump symfile [<file1> ...]")
2336 nullptr, eCommandRequiresTarget) {}
2337
2339
2340protected:
2341 void DoExecute(Args &command, CommandReturnObject &result) override {
2342 Target &target = GetTarget();
2343 uint32_t num_dumped = 0;
2344
2345 uint32_t addr_byte_size = target.GetArchitecture().GetAddressByteSize();
2346 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2347 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2348
2349 if (command.GetArgumentCount() == 0) {
2350 // Dump all sections for all modules images
2351 const ModuleList &target_modules = target.GetImages();
2352 std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
2353 const size_t num_modules = target_modules.GetSize();
2354 if (num_modules == 0) {
2355 result.AppendError("the target has no associated executable images");
2356 return;
2357 }
2358 result.GetOutputStream().Format(
2359 "Dumping debug symbols for {0} modules.\n", num_modules);
2360 for (ModuleSP module_sp : target_modules.ModulesNoLocking()) {
2361 if (INTERRUPT_REQUESTED(GetDebugger(), "Interrupted in dumping all "
2362 "debug symbols with {0} of {1} modules dumped",
2363 num_dumped, num_modules))
2364 break;
2365
2366 if (DumpModuleSymbolFile(result.GetOutputStream(), module_sp.get()))
2367 num_dumped++;
2368 }
2369 } else {
2370 // Dump specified images (by basename or fullpath)
2371 const char *arg_cstr;
2372 for (int arg_idx = 0;
2373 (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != nullptr;
2374 ++arg_idx) {
2375 ModuleList module_list;
2376 const size_t num_matches =
2377 FindModulesByName(&target, arg_cstr, module_list, true);
2378 if (num_matches > 0) {
2379 for (size_t i = 0; i < num_matches; ++i) {
2380 if (INTERRUPT_REQUESTED(GetDebugger(), "Interrupted dumping {0} "
2381 "of {1} requested modules",
2382 i, num_matches))
2383 break;
2384 Module *module = module_list.GetModulePointerAtIndex(i);
2385 if (module) {
2386 if (DumpModuleSymbolFile(result.GetOutputStream(), module))
2387 num_dumped++;
2388 }
2389 }
2390 } else
2392 "Unable to find an image that matches '%s'.\n", arg_cstr);
2393 }
2394 }
2395
2396 if (num_dumped > 0)
2398 else {
2399 result.AppendError("no matching executable images found");
2400 }
2401 }
2402};
2403
2404#pragma mark CommandObjectTargetModulesDumpLineTable
2405#define LLDB_OPTIONS_target_modules_dump
2406#include "CommandOptions.inc"
2407
2408// Image debug line table dumping command
2409
2412public:
2415 interpreter, "target modules dump line-table",
2416 "Dump the line table for one or more compilation units.", nullptr,
2417 eCommandRequiresTarget) {}
2418
2420
2421 Options *GetOptions() override { return &m_options; }
2422
2423protected:
2424 void DoExecute(Args &command, CommandReturnObject &result) override {
2425 Target *target = m_exe_ctx.GetTargetPtr();
2426 uint32_t total_num_dumped = 0;
2427
2428 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2429 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2430 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2431
2432 if (command.GetArgumentCount() == 0) {
2433 result.AppendError("file option must be specified");
2434 return;
2435 } else {
2436 // Dump specified images (by basename or fullpath)
2437 const char *arg_cstr;
2438 for (int arg_idx = 0;
2439 (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != nullptr;
2440 ++arg_idx) {
2441 FileSpec file_spec(arg_cstr);
2442
2443 const ModuleList &target_modules = target->GetImages();
2444 std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
2445 size_t num_modules = target_modules.GetSize();
2446 if (num_modules > 0) {
2447 uint32_t num_dumped = 0;
2448 for (ModuleSP module_sp : target_modules.ModulesNoLocking()) {
2450 "Interrupted in dump all line tables with "
2451 "{0} of {1} dumped", num_dumped,
2452 num_modules))
2453 break;
2454
2456 m_interpreter, result.GetOutputStream(), module_sp.get(),
2457 file_spec,
2460 num_dumped++;
2461 }
2462 if (num_dumped == 0)
2464 "No source filenames matched '%s'.\n", arg_cstr);
2465 else
2466 total_num_dumped += num_dumped;
2467 }
2468 }
2469 }
2470
2471 if (total_num_dumped > 0)
2473 else {
2474 result.AppendError("no source filenames matched any command arguments");
2475 }
2476 }
2477
2478 class CommandOptions : public Options {
2479 public:
2481
2482 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
2483 ExecutionContext *execution_context) override {
2484 assert(option_idx == 0 && "We only have one option.");
2485 m_verbose = true;
2486
2487 return Status();
2488 }
2489
2490 void OptionParsingStarting(ExecutionContext *execution_context) override {
2491 m_verbose = false;
2492 }
2493
2494 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
2495 return llvm::ArrayRef(g_target_modules_dump_options);
2496 }
2497
2499 };
2500
2502};
2503
2504#pragma mark CommandObjectTargetModulesDumpSeparateDebugInfoFiles
2505#define LLDB_OPTIONS_target_modules_dump_separate_debug_info
2506#include "CommandOptions.inc"
2507
2508// Image debug separate debug info dumping command
2509
2512public:
2514 CommandInterpreter &interpreter)
2516 interpreter, "target modules dump separate-debug-info",
2517 "List the separate debug info symbol files for one or more target "
2518 "modules.",
2519 nullptr, eCommandRequiresTarget) {}
2520
2522
2523 Options *GetOptions() override { return &m_options; }
2524
2525 class CommandOptions : public Options {
2526 public:
2527 CommandOptions() = default;
2528
2529 ~CommandOptions() override = default;
2530
2531 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
2532 ExecutionContext *execution_context) override {
2533 Status error;
2534 const int short_option = m_getopt_table[option_idx].val;
2535
2536 switch (short_option) {
2537 case 'f':
2538 m_load_all_debug_info.SetCurrentValue(true);
2539 m_load_all_debug_info.SetOptionWasSet();
2540 break;
2541 case 'j':
2542 m_json.SetCurrentValue(true);
2543 m_json.SetOptionWasSet();
2544 break;
2545 case 'e':
2546 m_errors_only.SetCurrentValue(true);
2547 m_errors_only.SetOptionWasSet();
2548 break;
2549 default:
2550 llvm_unreachable("Unimplemented option");
2551 }
2552 return error;
2553 }
2554
2555 void OptionParsingStarting(ExecutionContext *execution_context) override {
2556 m_json.Clear();
2557 m_errors_only.Clear();
2558 m_load_all_debug_info.Clear();
2559 }
2560
2561 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
2562 return llvm::ArrayRef(g_target_modules_dump_separate_debug_info_options);
2563 }
2564
2568 };
2569
2570protected:
2571 void DoExecute(Args &command, CommandReturnObject &result) override {
2572 Target &target = GetTarget();
2573 uint32_t num_dumped = 0;
2574
2575 uint32_t addr_byte_size = target.GetArchitecture().GetAddressByteSize();
2576 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2577 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2578
2579 StructuredData::Array separate_debug_info_lists_by_module;
2580 if (command.GetArgumentCount() == 0) {
2581 // Dump all sections for all modules images
2582 const ModuleList &target_modules = target.GetImages();
2583 std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
2584 const size_t num_modules = target_modules.GetSize();
2585 if (num_modules == 0) {
2586 result.AppendError("the target has no associated executable images");
2587 return;
2588 }
2589 for (ModuleSP module_sp : target_modules.ModulesNoLocking()) {
2591 GetDebugger(),
2592 "Interrupted in dumping all "
2593 "separate debug info with {0} of {1} modules dumped",
2594 num_dumped, num_modules))
2595 break;
2596
2597 if (GetSeparateDebugInfoList(separate_debug_info_lists_by_module,
2598 module_sp.get(),
2599 bool(m_options.m_errors_only),
2600 bool(m_options.m_load_all_debug_info)))
2601 num_dumped++;
2602 }
2603 } else {
2604 // Dump specified images (by basename or fullpath)
2605 const char *arg_cstr;
2606 for (int arg_idx = 0;
2607 (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != nullptr;
2608 ++arg_idx) {
2609 ModuleList module_list;
2610 const size_t num_matches =
2611 FindModulesByName(&target, arg_cstr, module_list, true);
2612 if (num_matches > 0) {
2613 for (size_t i = 0; i < num_matches; ++i) {
2615 "Interrupted dumping {0} "
2616 "of {1} requested modules",
2617 i, num_matches))
2618 break;
2619 Module *module = module_list.GetModulePointerAtIndex(i);
2620 if (GetSeparateDebugInfoList(separate_debug_info_lists_by_module,
2621 module, bool(m_options.m_errors_only),
2622 bool(m_options.m_load_all_debug_info)))
2623 num_dumped++;
2624 }
2625 } else
2627 "Unable to find an image that matches '%s'.\n", arg_cstr);
2628 }
2629 }
2630
2631 if (num_dumped > 0) {
2632 Stream &strm = result.GetOutputStream();
2633 // Display the debug info files in some format.
2634 if (m_options.m_json) {
2635 // JSON format
2636 separate_debug_info_lists_by_module.Dump(strm,
2637 /*pretty_print=*/true);
2638 } else {
2639 // Human-readable table format
2640 separate_debug_info_lists_by_module.ForEach(
2641 [&result, &strm](StructuredData::Object *obj) {
2642 if (!obj) {
2643 return false;
2644 }
2645
2646 // Each item in `separate_debug_info_lists_by_module` should be a
2647 // valid structured data dictionary.
2648 StructuredData::Dictionary *separate_debug_info_list =
2649 obj->GetAsDictionary();
2650 if (!separate_debug_info_list) {
2651 return false;
2652 }
2653
2654 llvm::StringRef type;
2655 llvm::StringRef symfile;
2656 StructuredData::Array *files;
2657 if (!(separate_debug_info_list->GetValueForKeyAsString("type",
2658 type) &&
2659 separate_debug_info_list->GetValueForKeyAsString("symfile",
2660 symfile) &&
2661 separate_debug_info_list->GetValueForKeyAsArray(
2662 "separate-debug-info-files", files))) {
2663 assert(false);
2664 }
2665
2666 strm << "Symbol file: " << symfile;
2667 strm.EOL();
2668 strm << "Type: \"" << type << "\"";
2669 strm.EOL();
2670 if (type == "dwo") {
2671 DumpDwoFilesTable(strm, *files);
2672 } else if (type == "oso") {
2673 DumpOsoFilesTable(strm, *files);
2674 } else {
2676 "Found unsupported debug info type '%s'.\n",
2677 type.str().c_str());
2678 }
2679 return true;
2680 });
2681 }
2683 } else {
2684 result.AppendError("no matching executable images found");
2685 }
2686 }
2687
2689};
2690
2691#pragma mark CommandObjectTargetModulesDump
2692
2693// Dump multi-word command for target modules
2694
2696public:
2697 // Constructors and Destructors
2700 interpreter, "target modules dump",
2701 "Commands for dumping information about one or more target "
2702 "modules.",
2703 "target modules dump "
2704 "[objfile|symtab|sections|ast|symfile|line-table|pcm-info|separate-"
2705 "debug-info] "
2706 "[<file1> <file2> ...]") {
2707 LoadSubCommand("objfile",
2709 new CommandObjectTargetModulesDumpObjfile(interpreter)));
2711 "symtab",
2713 LoadSubCommand("sections",
2715 interpreter)));
2716 LoadSubCommand("symfile",
2718 new CommandObjectTargetModulesDumpSymfile(interpreter)));
2720 "ast", CommandObjectSP(
2721 new CommandObjectTargetModulesDumpClangAST(interpreter)));
2722 LoadSubCommand("line-table",
2724 interpreter)));
2726 "pcm-info",
2729 LoadSubCommand("separate-debug-info",
2732 interpreter)));
2733 }
2734
2736};
2737
2739public:
2741 : CommandObjectParsed(interpreter, "target modules add",
2742 "Add a new module to the current target's modules.",
2743 "target modules add [<module>]",
2744 eCommandRequiresTarget),
2745 m_symbol_file(LLDB_OPT_SET_1, false, "symfile", 's', 0,
2747 "Fullpath to a stand alone debug "
2748 "symbols file for when debug symbols "
2749 "are not in the executable.") {
2753 m_option_group.Finalize();
2755 }
2756
2758
2759 Options *GetOptions() override { return &m_option_group; }
2760
2761protected:
2765
2766 void DoExecute(Args &args, CommandReturnObject &result) override {
2767 Target &target = GetTarget();
2768 bool flush = false;
2769
2770 const size_t argc = args.GetArgumentCount();
2771 if (argc == 0) {
2772 if (m_uuid_option_group.GetOptionValue().OptionWasSet()) {
2773 // We are given a UUID only, go locate the file
2774 ModuleSpec module_spec;
2775 module_spec.GetUUID() =
2776 m_uuid_option_group.GetOptionValue().GetCurrentValue();
2777 if (m_symbol_file.GetOptionValue().OptionWasSet())
2778 module_spec.GetSymbolFileSpec() =
2779 m_symbol_file.GetOptionValue().GetCurrentValue();
2780 Status error;
2782 ModuleSP module_sp(
2783 target.GetOrCreateModule(module_spec, true /* notify */));
2784 if (module_sp) {
2786 return;
2787 } else {
2788 StreamString strm;
2789 module_spec.GetUUID().Dump(strm);
2790 if (module_spec.GetFileSpec()) {
2791 if (module_spec.GetSymbolFileSpec()) {
2792 result.AppendErrorWithFormat(
2793 "Unable to create the executable or symbol file with "
2794 "UUID %s with path %s and symbol file %s",
2795 strm.GetData(), module_spec.GetFileSpec().GetPath().c_str(),
2796 module_spec.GetSymbolFileSpec().GetPath().c_str());
2797 } else {
2798 result.AppendErrorWithFormat(
2799 "Unable to create the executable or symbol file with "
2800 "UUID %s with path %s",
2801 strm.GetData(),
2802 module_spec.GetFileSpec().GetPath().c_str());
2803 }
2804 } else {
2805 result.AppendErrorWithFormat("Unable to create the executable "
2806 "or symbol file with UUID %s",
2807 strm.GetData());
2808 }
2809 return;
2810 }
2811 } else {
2812 StreamString strm;
2813 module_spec.GetUUID().Dump(strm);
2814 result.AppendErrorWithFormat(
2815 "Unable to locate the executable or symbol file with UUID %s",
2816 strm.GetData());
2817 result.SetError(std::move(error));
2818 return;
2819 }
2820 } else {
2821 result.AppendError(
2822 "one or more executable image paths must be specified");
2823 return;
2824 }
2825 } else {
2826 for (auto &entry : args.entries()) {
2827 if (entry.ref().empty())
2828 continue;
2829
2830 FileSpec file_spec(entry.ref());
2831 if (FileSystem::Instance().Exists(file_spec)) {
2832 ModuleSpec module_spec(file_spec);
2833 if (m_uuid_option_group.GetOptionValue().OptionWasSet())
2834 module_spec.GetUUID() =
2835 m_uuid_option_group.GetOptionValue().GetCurrentValue();
2836 if (m_symbol_file.GetOptionValue().OptionWasSet())
2837 module_spec.GetSymbolFileSpec() =
2838 m_symbol_file.GetOptionValue().GetCurrentValue();
2839 if (!module_spec.GetArchitecture().IsValid())
2840 module_spec.GetArchitecture() = target.GetArchitecture();
2841 Status error;
2842 ModuleSP module_sp(
2843 target.GetOrCreateModule(module_spec, true /* notify */, &error));
2844 if (!module_sp) {
2845 const char *error_cstr = error.AsCString();
2846 if (error_cstr)
2847 result.AppendError(error_cstr);
2848 else
2849 result.AppendErrorWithFormat("unsupported module: %s",
2850 entry.c_str());
2851 return;
2852 } else {
2853 flush = true;
2854 }
2856 } else {
2857 std::string resolved_path = file_spec.GetPath();
2858 if (resolved_path != entry.ref()) {
2859 result.AppendErrorWithFormat(
2860 "invalid module path '%s' with resolved path '%s'\n",
2861 entry.ref().str().c_str(), resolved_path.c_str());
2862 break;
2863 }
2864 result.AppendErrorWithFormat("invalid module path '%s'\n",
2865 entry.c_str());
2866 break;
2867 }
2868 }
2869 }
2870
2871 if (flush) {
2872 ProcessSP process = target.GetProcessSP();
2873 if (process)
2874 process->Flush();
2875 }
2876 }
2877};
2878
2881public:
2884 interpreter, "target modules load",
2885 "Set the load addresses for one or more sections in a target "
2886 "module.",
2887 "target modules load [--file <module> --uuid <uuid>] <sect-name> "
2888 "<address> [<sect-name> <address> ....]",
2889 eCommandRequiresTarget),
2890 m_file_option(LLDB_OPT_SET_1, false, "file", 'f', 0, eArgTypeName,
2891 "Fullpath or basename for module to load.", ""),
2892 m_load_option(LLDB_OPT_SET_1, false, "load", 'l',
2893 "Write file contents to the memory.", false, true),
2894 m_pc_option(LLDB_OPT_SET_1, false, "set-pc-to-entry", 'p',
2895 "Set PC to the entry point."
2896 " Only applicable with '--load' option.",
2897 false, true),
2898 m_slide_option(LLDB_OPT_SET_1, false, "slide", 's', 0, eArgTypeOffset,
2899 "Set the load address for all sections to be the "
2900 "virtual address in the file plus the offset.",
2901 0) {
2908 m_option_group.Finalize();
2909 }
2910
2912
2913 Options *GetOptions() override { return &m_option_group; }
2914
2915protected:
2916 void DoExecute(Args &args, CommandReturnObject &result) override {
2917 Target &target = GetTarget();
2918 const bool load = m_load_option.GetOptionValue().GetCurrentValue();
2919 const bool set_pc = m_pc_option.GetOptionValue().GetCurrentValue();
2920
2921 const size_t argc = args.GetArgumentCount();
2922 ModuleSpec module_spec;
2923 bool search_using_module_spec = false;
2924
2925 // Allow "load" option to work without --file or --uuid option.
2926 if (load) {
2927 if (!m_file_option.GetOptionValue().OptionWasSet() &&
2928 !m_uuid_option_group.GetOptionValue().OptionWasSet()) {
2929 ModuleList &module_list = target.GetImages();
2930 if (module_list.GetSize() == 1) {
2931 search_using_module_spec = true;
2932 module_spec.GetFileSpec() =
2933 module_list.GetModuleAtIndex(0)->GetFileSpec();
2934 }
2935 }
2936 }
2937
2938 if (m_file_option.GetOptionValue().OptionWasSet()) {
2939 search_using_module_spec = true;
2940 const char *arg_cstr = m_file_option.GetOptionValue().GetCurrentValue();
2941 const bool use_global_module_list = true;
2942 ModuleList module_list;
2943 const size_t num_matches = FindModulesByName(
2944 &target, arg_cstr, module_list, use_global_module_list);
2945 if (num_matches == 1) {
2946 module_spec.GetFileSpec() =
2947 module_list.GetModuleAtIndex(0)->GetFileSpec();
2948 } else if (num_matches > 1) {
2949 search_using_module_spec = false;
2950 result.AppendErrorWithFormat(
2951 "more than 1 module matched by name '%s'\n", arg_cstr);
2952 } else {
2953 search_using_module_spec = false;
2954 result.AppendErrorWithFormat("no object file for module '%s'\n",
2955 arg_cstr);
2956 }
2957 }
2958
2959 if (m_uuid_option_group.GetOptionValue().OptionWasSet()) {
2960 search_using_module_spec = true;
2961 module_spec.GetUUID() =
2962 m_uuid_option_group.GetOptionValue().GetCurrentValue();
2963 }
2964
2965 if (search_using_module_spec) {
2966 ModuleList matching_modules;
2967 target.GetImages().FindModules(module_spec, matching_modules);
2968 const size_t num_matches = matching_modules.GetSize();
2969
2970 char path[PATH_MAX];
2971 if (num_matches == 1) {
2972 Module *module = matching_modules.GetModulePointerAtIndex(0);
2973 if (module) {
2974 ObjectFile *objfile = module->GetObjectFile();
2975 if (objfile) {
2976 SectionList *section_list = module->GetSectionList();
2977 if (section_list) {
2978 bool changed = false;
2979 if (argc == 0) {
2980 if (m_slide_option.GetOptionValue().OptionWasSet()) {
2981 const addr_t slide =
2982 m_slide_option.GetOptionValue().GetCurrentValue();
2983 const bool slide_is_offset = true;
2984 module->SetLoadAddress(target, slide, slide_is_offset,
2985 changed);
2986 } else {
2987 result.AppendError("one or more section name + load "
2988 "address pair must be specified");
2989 return;
2990 }
2991 } else {
2992 if (m_slide_option.GetOptionValue().OptionWasSet()) {
2993 result.AppendError("The \"--slide <offset>\" option can't "
2994 "be used in conjunction with setting "
2995 "section load addresses.\n");
2996 return;
2997 }
2998
2999 for (size_t i = 0; i < argc; i += 2) {
3000 const char *sect_name = args.GetArgumentAtIndex(i);
3001 const char *load_addr_cstr = args.GetArgumentAtIndex(i + 1);
3002 if (sect_name && load_addr_cstr) {
3003 ConstString const_sect_name(sect_name);
3004 addr_t load_addr;
3005 if (llvm::to_integer(load_addr_cstr, load_addr)) {
3006 SectionSP section_sp(
3007 section_list->FindSectionByName(const_sect_name));
3008 if (section_sp) {
3009 if (section_sp->IsThreadSpecific()) {
3010 result.AppendErrorWithFormat(
3011 "thread specific sections are not yet "
3012 "supported (section '%s')\n",
3013 sect_name);
3014 break;
3015 } else {
3016 if (target.SetSectionLoadAddress(section_sp,
3017 load_addr))
3018 changed = true;
3020 "section '%s' loaded at 0x%" PRIx64 "\n",
3021 sect_name, load_addr);
3022 }
3023 } else {
3024 result.AppendErrorWithFormat("no section found that "
3025 "matches the section "
3026 "name '%s'\n",
3027 sect_name);
3028 break;
3029 }
3030 } else {
3031 result.AppendErrorWithFormat(
3032 "invalid load address string '%s'\n", load_addr_cstr);
3033 break;
3034 }
3035 } else {
3036 if (sect_name)
3037 result.AppendError("section names must be followed by "
3038 "a load address.\n");
3039 else
3040 result.AppendError("one or more section name + load "
3041 "address pair must be specified.\n");
3042 break;
3043 }
3044 }
3045 }
3046
3047 if (changed) {
3048 target.ModulesDidLoad(matching_modules);
3049 Process *process = m_exe_ctx.GetProcessPtr();
3050 if (process)
3051 process->Flush();
3052 }
3053 if (load) {
3054 ProcessSP process = target.CalculateProcess();
3055 Address file_entry = objfile->GetEntryPointAddress();
3056 if (!process) {
3057 result.AppendError("No process");
3058 return;
3059 }
3060 if (set_pc && !file_entry.IsValid()) {
3061 result.AppendError("No entry address in object file");
3062 return;
3063 }
3064 std::vector<ObjectFile::LoadableData> loadables(
3065 objfile->GetLoadableData(target));
3066 if (loadables.size() == 0) {
3067 result.AppendError("No loadable sections");
3068 return;
3069 }
3070 Status error = process->WriteObjectFile(std::move(loadables));
3071 if (error.Fail()) {
3072 result.AppendError(error.AsCString());
3073 return;
3074 }
3075 if (set_pc) {
3076 ThreadList &thread_list = process->GetThreadList();
3077 RegisterContextSP reg_context(
3078 thread_list.GetSelectedThread()->GetRegisterContext());
3079 addr_t file_entry_addr = file_entry.GetLoadAddress(&target);
3080 if (!reg_context->SetPC(file_entry_addr)) {
3081 result.AppendErrorWithFormat("failed to set PC value to "
3082 "0x%" PRIx64 "\n",
3083 file_entry_addr);
3084 }
3085 }
3086 }
3087 } else {
3088 module->GetFileSpec().GetPath(path, sizeof(path));
3089 result.AppendErrorWithFormat("no sections in object file '%s'\n",
3090 path);
3091 }
3092 } else {
3093 module->GetFileSpec().GetPath(path, sizeof(path));
3094 result.AppendErrorWithFormat("no object file for module '%s'\n",
3095 path);
3096 }
3097 } else {
3098 FileSpec *module_spec_file = module_spec.GetFileSpecPtr();
3099 if (module_spec_file) {
3100 module_spec_file->GetPath(path, sizeof(path));
3101 result.AppendErrorWithFormat("invalid module '%s'.\n", path);
3102 } else
3103 result.AppendError("no module spec");
3104 }
3105 } else {
3106 std::string uuid_str;
3107
3108 if (module_spec.GetFileSpec())
3109 module_spec.GetFileSpec().GetPath(path, sizeof(path));
3110 else
3111 path[0] = '\0';
3112
3113 if (module_spec.GetUUIDPtr())
3114 uuid_str = module_spec.GetUUID().GetAsString();
3115 if (num_matches > 1) {
3116 result.AppendErrorWithFormat(
3117 "multiple modules match%s%s%s%s:\n", path[0] ? " file=" : "",
3118 path, !uuid_str.empty() ? " uuid=" : "", uuid_str.c_str());
3119 for (size_t i = 0; i < num_matches; ++i) {
3120 if (matching_modules.GetModulePointerAtIndex(i)
3121 ->GetFileSpec()
3122 .GetPath(path, sizeof(path)))
3123 result.AppendMessageWithFormat("%s\n", path);
3124 }
3125 } else {
3126 result.AppendErrorWithFormat(
3127 "no modules were found that match%s%s%s%s.\n",
3128 path[0] ? " file=" : "", path, !uuid_str.empty() ? " uuid=" : "",
3129 uuid_str.c_str());
3130 }
3131 }
3132 } else {
3133 result.AppendError("either the \"--file <module>\" or the \"--uuid "
3134 "<uuid>\" option must be specified.\n");
3135 }
3136 }
3137
3144};
3145
3146#pragma mark CommandObjectTargetModulesList
3147// List images with associated information
3148#define LLDB_OPTIONS_target_modules_list
3149#include "CommandOptions.inc"
3150
3152public:
3153 class CommandOptions : public Options {
3154 public:
3155 CommandOptions() = default;
3156
3157 ~CommandOptions() override = default;
3158
3159 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
3160 ExecutionContext *execution_context) override {
3161 Status error;
3162
3163 const int short_option = m_getopt_table[option_idx].val;
3164 if (short_option == 'g') {
3166 } else if (short_option == 'a') {
3168 execution_context, option_arg, LLDB_INVALID_ADDRESS, &error);
3169 } else {
3170 unsigned long width = 0;
3171 option_arg.getAsInteger(0, width);
3172 m_format_array.push_back(std::make_pair(short_option, width));
3173 }
3174 return error;
3175 }
3176
3177 void OptionParsingStarting(ExecutionContext *execution_context) override {
3178 m_format_array.clear();
3181 }
3182
3183 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
3184 return llvm::ArrayRef(g_target_modules_list_options);
3185 }
3186
3187 // Instance variables to hold the values for command options.
3188 typedef std::vector<std::pair<char, uint32_t>> FormatWidthCollection;
3192 };
3193
3196 interpreter, "target modules list",
3197 "List current executable and dependent shared library images.") {
3199 }
3200
3202
3203 Options *GetOptions() override { return &m_options; }
3204
3205protected:
3206 void DoExecute(Args &command, CommandReturnObject &result) override {
3207 Target &target = GetTarget();
3208 const bool use_global_module_list = m_options.m_use_global_module_list;
3209 // Define a local module list here to ensure it lives longer than any
3210 // "locker" object which might lock its contents below (through the
3211 // "module_list_ptr" variable).
3212 ModuleList module_list;
3213 uint32_t addr_byte_size = target.GetArchitecture().GetAddressByteSize();
3214 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
3215 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
3216 // Dump all sections for all modules images
3217 Stream &strm = result.GetOutputStream();
3218
3219 if (m_options.m_module_addr != LLDB_INVALID_ADDRESS) {
3220 Address module_address;
3221 if (module_address.SetLoadAddress(m_options.m_module_addr, &target)) {
3222 ModuleSP module_sp(module_address.GetModule());
3223 if (module_sp) {
3224 PrintModule(target, module_sp.get(), 0, strm);
3226 } else {
3227 result.AppendErrorWithFormat(
3228 "Couldn't find module matching address: 0x%" PRIx64 ".",
3229 m_options.m_module_addr);
3230 }
3231 } else {
3232 result.AppendErrorWithFormat(
3233 "Couldn't find module containing address: 0x%" PRIx64 ".",
3234 m_options.m_module_addr);
3235 }
3236 return;
3237 }
3238
3239 size_t num_modules = 0;
3240
3241 // This locker will be locked on the mutex in module_list_ptr if it is
3242 // non-nullptr. Otherwise it will lock the
3243 // AllocationModuleCollectionMutex when accessing the global module list
3244 // directly.
3245 std::unique_lock<std::recursive_mutex> guard(
3247
3248 const ModuleList *module_list_ptr = nullptr;
3249 const size_t argc = command.GetArgumentCount();
3250 if (argc == 0) {
3251 if (use_global_module_list) {
3252 guard.lock();
3253 num_modules = Module::GetNumberAllocatedModules();
3254 } else {
3255 module_list_ptr = &target.GetImages();
3256 }
3257 } else {
3258 for (const Args::ArgEntry &arg : command) {
3259 // Dump specified images (by basename or fullpath)
3260 const size_t num_matches = FindModulesByName(
3261 &target, arg.c_str(), module_list, use_global_module_list);
3262 if (num_matches == 0) {
3263 if (argc == 1) {
3264 result.AppendErrorWithFormat("no modules found that match '%s'",
3265 arg.c_str());
3266 return;
3267 }
3268 }
3269 }
3270
3271 module_list_ptr = &module_list;
3272 }
3273
3274 std::unique_lock<std::recursive_mutex> lock;
3275 if (module_list_ptr != nullptr) {
3276 lock =
3277 std::unique_lock<std::recursive_mutex>(module_list_ptr->GetMutex());
3278
3279 num_modules = module_list_ptr->GetSize();
3280 }
3281
3282 if (num_modules > 0) {
3283 for (uint32_t image_idx = 0; image_idx < num_modules; ++image_idx) {
3284 ModuleSP module_sp;
3285 Module *module;
3286 if (module_list_ptr) {
3287 module_sp = module_list_ptr->GetModuleAtIndexUnlocked(image_idx);
3288 module = module_sp.get();
3289 } else {
3290 module = Module::GetAllocatedModuleAtIndex(image_idx);
3291 module_sp = module->shared_from_this();
3292 }
3293
3294 const size_t indent = strm.Printf("[%3u] ", image_idx);
3295 PrintModule(target, module, indent, strm);
3296 }
3298 } else {
3299 if (argc) {
3300 if (use_global_module_list)
3301 result.AppendError(
3302 "the global module list has no matching modules");
3303 else
3304 result.AppendError("the target has no matching modules");
3305 } else {
3306 if (use_global_module_list)
3307 result.AppendError("the global module list is empty");
3308 else
3309 result.AppendError(
3310 "the target has no associated executable images");
3311 }
3312 return;
3313 }
3314 }
3315
3316 void PrintModule(Target &target, Module *module, int indent, Stream &strm) {
3317 if (module == nullptr) {
3318 strm.PutCString("Null module");
3319 return;
3320 }
3321
3322 bool dump_object_name = false;
3323 if (m_options.m_format_array.empty()) {
3324 m_options.m_format_array.push_back(std::make_pair('u', 0));
3325 m_options.m_format_array.push_back(std::make_pair('h', 0));
3326 m_options.m_format_array.push_back(std::make_pair('f', 0));
3327 m_options.m_format_array.push_back(std::make_pair('S', 0));
3328 }
3329 const size_t num_entries = m_options.m_format_array.size();
3330 bool print_space = false;
3331 for (size_t i = 0; i < num_entries; ++i) {
3332 if (print_space)
3333 strm.PutChar(' ');
3334 print_space = true;
3335 const char format_char = m_options.m_format_array[i].first;
3336 uint32_t width = m_options.m_format_array[i].second;
3337 switch (format_char) {
3338 case 'A':
3339 DumpModuleArchitecture(strm, module, false, width);
3340 break;
3341
3342 case 't':
3343 DumpModuleArchitecture(strm, module, true, width);
3344 break;
3345
3346 case 'f':
3347 DumpFullpath(strm, &module->GetFileSpec(), width);
3348 dump_object_name = true;
3349 break;
3350
3351 case 'd':
3352 DumpDirectory(strm, &module->GetFileSpec(), width);
3353 break;
3354
3355 case 'b':
3356 DumpBasename(strm, &module->GetFileSpec(), width);
3357 dump_object_name = true;
3358 break;
3359
3360 case 'h':
3361 case 'o':
3362 // Image header address
3363 {
3364 uint32_t addr_nibble_width =
3365 target.GetArchitecture().GetAddressByteSize() * 2;
3366
3367 ObjectFile *objfile = module->GetObjectFile();
3368 if (objfile) {
3369 Address base_addr(objfile->GetBaseAddress());
3370 if (base_addr.IsValid()) {
3371 if (target.HasLoadedSections()) {
3372 lldb::addr_t load_addr = base_addr.GetLoadAddress(&target);
3373 if (load_addr == LLDB_INVALID_ADDRESS) {
3374 base_addr.Dump(&strm, &target,
3377 } else {
3378 if (format_char == 'o') {
3379 // Show the offset of slide for the image
3380 strm.Printf("0x%*.*" PRIx64, addr_nibble_width,
3381 addr_nibble_width,
3382 load_addr - base_addr.GetFileAddress());
3383 } else {
3384 // Show the load address of the image
3385 strm.Printf("0x%*.*" PRIx64, addr_nibble_width,
3386 addr_nibble_width, load_addr);
3387 }
3388 }
3389 break;
3390 }
3391 // The address was valid, but the image isn't loaded, output the
3392 // address in an appropriate format
3393 base_addr.Dump(&strm, &target, Address::DumpStyleFileAddress);
3394 break;
3395 }
3396 }
3397 strm.Printf("%*s", addr_nibble_width + 2, "");
3398 }
3399 break;
3400
3401 case 'r': {
3402 size_t ref_count = 0;
3403 char in_shared_cache = 'Y';
3404
3405 ModuleSP module_sp(module->shared_from_this());
3406 if (!ModuleList::ModuleIsInCache(module))
3407 in_shared_cache = 'N';
3408 if (module_sp) {
3409 // Take one away to make sure we don't count our local "module_sp"
3410 ref_count = module_sp.use_count() - 1;
3411 }
3412 if (width)
3413 strm.Printf("{%c %*" PRIu64 "}", in_shared_cache, width, (uint64_t)ref_count);
3414 else
3415 strm.Printf("{%c %" PRIu64 "}", in_shared_cache, (uint64_t)ref_count);
3416 } break;
3417
3418 case 's':
3419 case 'S': {
3420 if (const SymbolFile *symbol_file = module->GetSymbolFile()) {
3421 const FileSpec symfile_spec =
3422 symbol_file->GetObjectFile()->GetFileSpec();
3423 if (format_char == 'S') {
3424 // Dump symbol file only if different from module file
3425 if (!symfile_spec || symfile_spec == module->GetFileSpec()) {
3426 print_space = false;
3427 break;
3428 }
3429 // Add a newline and indent past the index
3430 strm.Printf("\n%*s", indent, "");
3431 }
3432 DumpFullpath(strm, &symfile_spec, width);
3433 dump_object_name = true;
3434 break;
3435 }
3436 strm.Printf("%.*s", width, "<NONE>");
3437 } break;
3438
3439 case 'm':
3440 strm.Format("{0:%c}", llvm::fmt_align(module->GetModificationTime(),
3441 llvm::AlignStyle::Left, width));
3442 break;
3443
3444 case 'p':
3445 strm.Printf("%p", static_cast<void *>(module));
3446 break;
3447
3448 case 'u':
3449 DumpModuleUUID(strm, module);
3450 break;
3451
3452 default:
3453 break;
3454 }
3455 }
3456 if (dump_object_name) {
3457 const char *object_name = module->GetObjectName().GetCString();
3458 if (object_name)
3459 strm.Printf("(%s)", object_name);
3460 }
3461 strm.EOL();
3462 }
3463
3465};
3466
3467#pragma mark CommandObjectTargetModulesShowUnwind
3468
3469// Lookup unwind information in images
3470#define LLDB_OPTIONS_target_modules_show_unwind
3471#include "CommandOptions.inc"
3472
3474public:
3475 enum {
3482 };
3483
3484 class CommandOptions : public Options {
3485 public:
3486 CommandOptions() = default;
3487
3488 ~CommandOptions() override = default;
3489
3490 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
3491 ExecutionContext *execution_context) override {
3492 Status error;
3493
3494 const int short_option = m_getopt_table[option_idx].val;
3495
3496 switch (short_option) {
3497 case 'a': {
3498 m_str = std::string(option_arg);
3500 m_addr = OptionArgParser::ToAddress(execution_context, option_arg,
3504 "invalid address string '%s'", option_arg.str().c_str());
3505 break;
3506 }
3507
3508 case 'n':
3509 m_str = std::string(option_arg);
3511 break;
3512
3513 case 'c':
3514 bool value, success;
3515 value = OptionArgParser::ToBoolean(option_arg, false, &success);
3516 if (success) {
3517 m_cached = value;
3518 } else {
3520 "invalid boolean value '%s' passed for -c option", option_arg);
3521 }
3522 break;
3523
3524 default:
3525 llvm_unreachable("Unimplemented option");
3526 }
3527
3528 return error;
3529 }
3530
3531 void OptionParsingStarting(ExecutionContext *execution_context) override {
3533 m_str.clear();
3535 m_cached = false;
3536 }
3537
3538 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
3539 return llvm::ArrayRef(g_target_modules_show_unwind_options);
3540 }
3541
3542 // Instance variables to hold the values for command options.
3543
3544 int m_type = eLookupTypeInvalid; // Should be a eLookupTypeXXX enum after
3545 // parsing options
3546 std::string m_str; // Holds name lookup
3547 lldb::addr_t m_addr = LLDB_INVALID_ADDRESS; // Holds the address to lookup
3548 bool m_cached = true;
3549 };
3550
3553 interpreter, "target modules show-unwind",
3554 "Show synthesized unwind instructions for a function.", nullptr,
3555 eCommandRequiresTarget | eCommandRequiresProcess |
3556 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
3557
3559
3560 Options *GetOptions() override { return &m_options; }
3561
3562protected:
3563 void DoExecute(Args &command, CommandReturnObject &result) override {
3564 Target *target = m_exe_ctx.GetTargetPtr();
3565 Process *process = m_exe_ctx.GetProcessPtr();
3566 ABI *abi = nullptr;
3567 if (process)
3568 abi = process->GetABI().get();
3569
3570 if (process == nullptr) {
3571 result.AppendError(
3572 "You must have a process running to use this command.");
3573 return;
3574 }
3575
3576 ThreadList threads(process->GetThreadList());
3577 if (threads.GetSize() == 0) {
3578 result.AppendError("the process must be paused to use this command");
3579 return;
3580 }
3581
3582 ThreadSP thread(threads.GetThreadAtIndex(0));
3583 if (!thread) {
3584 result.AppendError("the process must be paused to use this command");
3585 return;
3586 }
3587
3588 SymbolContextList sc_list;
3589
3590 if (m_options.m_type == eLookupTypeFunctionOrSymbol) {
3591 ConstString function_name(m_options.m_str.c_str());
3592 ModuleFunctionSearchOptions function_options;
3593 function_options.include_symbols = true;
3594 function_options.include_inlines = false;
3595 target->GetImages().FindFunctions(function_name, eFunctionNameTypeAuto,
3596 function_options, sc_list);
3597 } else if (m_options.m_type == eLookupTypeAddress && target) {
3598 Address addr;
3599 if (target->ResolveLoadAddress(m_options.m_addr, addr)) {
3600 SymbolContext sc;
3601 ModuleSP module_sp(addr.GetModule());
3602 module_sp->ResolveSymbolContextForAddress(addr,
3603 eSymbolContextEverything, sc);
3604 if (sc.function || sc.symbol) {
3605 sc_list.Append(sc);
3606 }
3607 }
3608 } else {
3609 result.AppendError(
3610 "address-expression or function name option must be specified.");
3611 return;
3612 }
3613
3614 if (sc_list.GetSize() == 0) {
3615 result.AppendErrorWithFormat("no unwind data found that matches '%s'.",
3616 m_options.m_str.c_str());
3617 return;
3618 }
3619
3620 for (const SymbolContext &sc : sc_list) {
3621 if (sc.symbol == nullptr && sc.function == nullptr)
3622 continue;
3623 if (!sc.module_sp || sc.module_sp->GetObjectFile() == nullptr)
3624 continue;
3625 Address addr = sc.GetFunctionOrSymbolAddress();
3626 if (!addr.IsValid())
3627 continue;
3628 ConstString funcname(sc.GetFunctionName());
3629 if (funcname.IsEmpty())
3630 continue;
3631 addr_t start_addr = addr.GetLoadAddress(target);
3632 if (abi)
3633 start_addr = abi->FixCodeAddress(start_addr);
3634
3635 UnwindTable &uw_table = sc.module_sp->GetUnwindTable();
3636 FuncUnwindersSP func_unwinders_sp =
3637 m_options.m_cached
3638 ? uw_table.GetFuncUnwindersContainingAddress(start_addr, sc)
3639 : uw_table.GetUncachedFuncUnwindersContainingAddress(start_addr,
3640 sc);
3641 if (!func_unwinders_sp)
3642 continue;
3643
3644 result.GetOutputStream().Printf(
3645 "UNWIND PLANS for %s`%s (start addr 0x%" PRIx64 ")\n",
3646 sc.module_sp->GetPlatformFileSpec().GetFilename().AsCString(),
3647 funcname.AsCString(), start_addr);
3648
3649 Args args;
3651 size_t count = args.GetArgumentCount();
3652 for (size_t i = 0; i < count; i++) {
3653 const char *trap_func_name = args.GetArgumentAtIndex(i);
3654 if (strcmp(funcname.GetCString(), trap_func_name) == 0)
3655 result.GetOutputStream().Printf(
3656 "This function is "
3657 "treated as a trap handler function via user setting.\n");
3658 }
3659 PlatformSP platform_sp(target->GetPlatform());
3660 if (platform_sp) {
3661 const std::vector<ConstString> trap_handler_names(
3662 platform_sp->GetTrapHandlerSymbolNames());
3663 for (ConstString trap_name : trap_handler_names) {
3664 if (trap_name == funcname) {
3665 result.GetOutputStream().Printf(
3666 "This function's "
3667 "name is listed by the platform as a trap handler.\n");
3668 }
3669 }
3670 }
3671
3672 result.GetOutputStream().Printf("\n");
3673
3674 if (std::shared_ptr<const UnwindPlan> plan_sp =
3675 func_unwinders_sp->GetUnwindPlanAtNonCallSite(*target, *thread)) {
3676 result.GetOutputStream().Printf(
3677 "Asynchronous (not restricted to call-sites) UnwindPlan is '%s'\n",
3678 plan_sp->GetSourceName().AsCString());
3679 }
3680 if (std::shared_ptr<const UnwindPlan> plan_sp =
3681 func_unwinders_sp->GetUnwindPlanAtCallSite(*target, *thread)) {
3682 result.GetOutputStream().Printf(
3683 "Synchronous (restricted to call-sites) UnwindPlan is '%s'\n",
3684 plan_sp->GetSourceName().AsCString());
3685 }
3686 if (std::shared_ptr<const UnwindPlan> plan_sp =
3687 func_unwinders_sp->GetUnwindPlanFastUnwind(*target, *thread)) {
3688 result.GetOutputStream().Printf("Fast UnwindPlan is '%s'\n",
3689 plan_sp->GetSourceName().AsCString());
3690 }
3691
3692 result.GetOutputStream().Printf("\n");
3693
3694 if (std::shared_ptr<const UnwindPlan> plan_sp =
3695 func_unwinders_sp->GetAssemblyUnwindPlan(*target, *thread)) {
3696 result.GetOutputStream().Printf(
3697 "Assembly language inspection UnwindPlan:\n");
3698 plan_sp->Dump(result.GetOutputStream(), thread.get(),
3700 result.GetOutputStream().Printf("\n");
3701 }
3702
3703 if (std::shared_ptr<const UnwindPlan> plan_sp =
3704 func_unwinders_sp->GetObjectFileUnwindPlan(*target)) {
3705 result.GetOutputStream().Printf("object file UnwindPlan:\n");
3706 plan_sp->Dump(result.GetOutputStream(), thread.get(),
3708 result.GetOutputStream().Printf("\n");
3709 }
3710
3711 if (std::shared_ptr<const UnwindPlan> plan_sp =
3712 func_unwinders_sp->GetObjectFileAugmentedUnwindPlan(*target,
3713 *thread)) {
3714 result.GetOutputStream().Printf("object file augmented UnwindPlan:\n");
3715 plan_sp->Dump(result.GetOutputStream(), thread.get(),
3717 result.GetOutputStream().Printf("\n");
3718 }
3719
3720 if (std::shared_ptr<const UnwindPlan> plan_sp =
3721 func_unwinders_sp->GetEHFrameUnwindPlan(*target)) {
3722 result.GetOutputStream().Printf("eh_frame UnwindPlan:\n");
3723 plan_sp->Dump(result.GetOutputStream(), thread.get(),
3725 result.GetOutputStream().Printf("\n");
3726 }
3727
3728 if (std::shared_ptr<const UnwindPlan> plan_sp =
3729 func_unwinders_sp->GetEHFrameAugmentedUnwindPlan(*target,
3730 *thread)) {
3731 result.GetOutputStream().Printf("eh_frame augmented UnwindPlan:\n");
3732 plan_sp->Dump(result.GetOutputStream(), thread.get(),
3734 result.GetOutputStream().Printf("\n");
3735 }
3736
3737 if (std::shared_ptr<const UnwindPlan> plan_sp =
3738 func_unwinders_sp->GetDebugFrameUnwindPlan(*target)) {
3739 result.GetOutputStream().Printf("debug_frame UnwindPlan:\n");
3740 plan_sp->Dump(result.GetOutputStream(), thread.get(),
3742 result.GetOutputStream().Printf("\n");
3743 }
3744
3745 if (std::shared_ptr<const UnwindPlan> plan_sp =
3746 func_unwinders_sp->GetDebugFrameAugmentedUnwindPlan(*target,
3747 *thread)) {
3748 result.GetOutputStream().Printf("debug_frame augmented UnwindPlan:\n");
3749 plan_sp->Dump(result.GetOutputStream(), thread.get(),
3751 result.GetOutputStream().Printf("\n");
3752 }
3753
3754 if (std::shared_ptr<const UnwindPlan> plan_sp =
3755 func_unwinders_sp->GetArmUnwindUnwindPlan(*target)) {
3756 result.GetOutputStream().Printf("ARM.exidx unwind UnwindPlan:\n");
3757 plan_sp->Dump(result.GetOutputStream(), thread.get(),
3759 result.GetOutputStream().Printf("\n");
3760 }
3761
3762 if (std::shared_ptr<const UnwindPlan> plan_sp =
3763 func_unwinders_sp->GetSymbolFileUnwindPlan(*thread)) {
3764 result.GetOutputStream().Printf("Symbol file UnwindPlan:\n");
3765 plan_sp->Dump(result.GetOutputStream(), thread.get(),
3767 result.GetOutputStream().Printf("\n");
3768 }
3769
3770 if (std::shared_ptr<const UnwindPlan> plan_sp =
3771 func_unwinders_sp->GetCompactUnwindUnwindPlan(*target)) {
3772 result.GetOutputStream().Printf("Compact unwind UnwindPlan:\n");
3773 plan_sp->Dump(result.GetOutputStream(), thread.get(),
3775 result.GetOutputStream().Printf("\n");
3776 }
3777
3778 if (std::shared_ptr<const UnwindPlan> plan_sp =
3779 func_unwinders_sp->GetUnwindPlanFastUnwind(*target, *thread)) {
3780 result.GetOutputStream().Printf("Fast UnwindPlan:\n");
3781 plan_sp->Dump(result.GetOutputStream(), thread.get(),
3783 result.GetOutputStream().Printf("\n");
3784 }
3785
3786 ABISP abi_sp = process->GetABI();
3787 if (abi_sp) {
3788 if (UnwindPlanSP plan_sp = abi_sp->CreateDefaultUnwindPlan()) {
3789 result.GetOutputStream().Printf("Arch default UnwindPlan:\n");
3790 plan_sp->Dump(result.GetOutputStream(), thread.get(),
3792 result.GetOutputStream().Printf("\n");
3793 }
3794
3795 if (UnwindPlanSP plan_sp = abi_sp->CreateFunctionEntryUnwindPlan()) {
3796 result.GetOutputStream().Printf(
3797 "Arch default at entry point UnwindPlan:\n");
3798 plan_sp->Dump(result.GetOutputStream(), thread.get(),
3800 result.GetOutputStream().Printf("\n");
3801 }
3802 }
3803
3804 result.GetOutputStream().Printf("\n");
3805 }
3806 }
3807
3809};
3810
3811// Lookup information in images
3812#define LLDB_OPTIONS_target_modules_lookup
3813#include "CommandOptions.inc"
3814
3816public:
3817 enum {
3821 eLookupTypeFileLine, // Line is optional
3826 };
3827
3828 class CommandOptions : public Options {
3829 public:
3831
3832 ~CommandOptions() override = default;
3833
3834 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
3835 ExecutionContext *execution_context) override {
3836 Status error;
3837
3838 const int short_option = m_getopt_table[option_idx].val;
3839
3840 switch (short_option) {
3841 case 'a': {
3843 m_addr = OptionArgParser::ToAddress(execution_context, option_arg,
3845 } break;
3846
3847 case 'o':
3848 if (option_arg.getAsInteger(0, m_offset))
3850 "invalid offset string '%s'", option_arg.str().c_str());
3851 break;
3852
3853 case 's':
3854 m_str = std::string(option_arg);
3856 break;
3857
3858 case 'f':
3859 m_file.SetFile(option_arg, FileSpec::Style::native);
3861 break;
3862
3863 case 'i':
3864 m_include_inlines = false;
3865 break;
3866
3867 case 'l':
3868 if (option_arg.getAsInteger(0, m_line_number))
3870 "invalid line number string '%s'", option_arg.str().c_str());
3871 else if (m_line_number == 0)
3872 error = Status::FromErrorString("zero is an invalid line number");
3874 break;
3875
3876 case 'F':
3877 m_str = std::string(option_arg);
3879 break;
3880
3881 case 'n':
3882 m_str = std::string(option_arg);
3884 break;
3885
3886 case 't':
3887 m_str = std::string(option_arg);
3889 break;
3890
3891 case 'v':
3892 m_verbose = true;
3893 break;
3894
3895 case 'A':
3896 m_print_all = true;
3897 break;
3898
3899 case 'r':
3900 m_use_regex = true;
3901 break;
3902
3903 case '\x01':
3904 m_all_ranges = true;
3905 break;
3906 default:
3907 llvm_unreachable("Unimplemented option");
3908 }
3909
3910 return error;
3911 }
3912
3913 void OptionParsingStarting(ExecutionContext *execution_context) override {
3915 m_str.clear();
3916 m_file.Clear();
3918 m_offset = 0;
3919 m_line_number = 0;
3920 m_use_regex = false;
3921 m_include_inlines = true;
3922 m_all_ranges = false;
3923 m_verbose = false;
3924 m_print_all = false;
3925 }
3926
3927 Status OptionParsingFinished(ExecutionContext *execution_context) override {
3928 Status status;
3929 if (m_all_ranges && !m_verbose) {
3930 status =
3931 Status::FromErrorString("--show-variable-ranges must be used in "
3932 "conjunction with --verbose.");
3933 }
3934 return status;
3935 }
3936
3937 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
3938 return llvm::ArrayRef(g_target_modules_lookup_options);
3939 }
3940
3941 int m_type; // Should be a eLookupTypeXXX enum after parsing options
3942 std::string m_str; // Holds name lookup
3943 FileSpec m_file; // Files for file lookups
3944 lldb::addr_t m_addr; // Holds the address to lookup
3946 m_offset; // Subtract this offset from m_addr before doing lookups.
3947 uint32_t m_line_number; // Line number for file+line lookups
3948 bool m_use_regex; // Name lookups in m_str are regular expressions.
3949 bool m_include_inlines; // Check for inline entries when looking up by
3950 // file/line.
3951 bool m_all_ranges; // Print all ranges or single range.
3952 bool m_verbose; // Enable verbose lookup info
3953 bool m_print_all; // Print all matches, even in cases where there's a best
3954 // match.
3955 };
3956
3958 : CommandObjectParsed(interpreter, "target modules lookup",
3959 "Look up information within executable and "
3960 "dependent shared library images.",
3961 nullptr, eCommandRequiresTarget) {
3963 }
3964
3966
3967 Options *GetOptions() override { return &m_options; }
3968
3970 bool &syntax_error) {
3971 switch (m_options.m_type) {
3972 case eLookupTypeAddress:
3976 case eLookupTypeSymbol:
3977 default:
3978 return false;
3979 case eLookupTypeType:
3980 break;
3981 }
3982
3983 StackFrameSP frame = m_exe_ctx.GetFrameSP();
3984
3985 if (!frame)
3986 return false;
3987
3988 const SymbolContext &sym_ctx(frame->GetSymbolContext(eSymbolContextModule));
3989
3990 if (!sym_ctx.module_sp)
3991 return false;
3992
3993 switch (m_options.m_type) {
3994 default:
3995 return false;
3996 case eLookupTypeType:
3997 if (!m_options.m_str.empty()) {
3999 result.GetOutputStream(), *sym_ctx.module_sp,
4000 m_options.m_str.c_str(), m_options.m_use_regex)) {
4002 return true;
4003 }
4004 }
4005 break;
4006 }
4007
4008 return false;
4009 }
4010
4011 bool LookupInModule(CommandInterpreter &interpreter, Module *module,
4012 CommandReturnObject &result, bool &syntax_error) {
4013 switch (m_options.m_type) {
4014 case eLookupTypeAddress:
4015 if (m_options.m_addr != LLDB_INVALID_ADDRESS) {
4017 m_interpreter, result.GetOutputStream(), module,
4018 eSymbolContextEverything |
4019 (m_options.m_verbose
4020 ? static_cast<int>(eSymbolContextVariable)
4021 : 0),
4022 m_options.m_addr, m_options.m_offset, m_options.m_verbose,
4023 m_options.m_all_ranges)) {
4025 return true;
4026 }
4027 }
4028 break;
4029
4030 case eLookupTypeSymbol:
4031 if (!m_options.m_str.empty()) {
4033 module, m_options.m_str.c_str(),
4034 m_options.m_use_regex, m_options.m_verbose,
4035 m_options.m_all_ranges)) {
4037 return true;
4038 }
4039 }
4040 break;
4041
4043 if (m_options.m_file) {
4045 m_interpreter, result.GetOutputStream(), module,
4046 m_options.m_file, m_options.m_line_number,
4047 m_options.m_include_inlines, m_options.m_verbose,
4048 m_options.m_all_ranges)) {
4050 return true;
4051 }
4052 }
4053 break;
4054
4057 if (!m_options.m_str.empty()) {
4058 ModuleFunctionSearchOptions function_options;
4059 function_options.include_symbols =
4061 function_options.include_inlines = m_options.m_include_inlines;
4062
4064 module, m_options.m_str.c_str(),
4065 m_options.m_use_regex, function_options,
4066 m_options.m_verbose,
4067 m_options.m_all_ranges)) {
4069 return true;
4070 }
4071 }
4072 break;
4073
4074 case eLookupTypeType:
4075 if (!m_options.m_str.empty()) {
4077 &GetTarget(), m_interpreter, result.GetOutputStream(), module,
4078 m_options.m_str.c_str(), m_options.m_use_regex)) {
4080 return true;
4081 }
4082 }
4083 break;
4084
4085 default:
4086 m_options.GenerateOptionUsage(
4087 result.GetErrorStream(), *this,
4088 GetCommandInterpreter().GetDebugger().GetTerminalWidth(),
4089 GetCommandInterpreter().GetDebugger().GetUseColor());
4090 syntax_error = true;
4091 break;
4092 }
4093
4095 return false;
4096 }
4097
4098protected:
4099 void DoExecute(Args &command, CommandReturnObject &result) override {
4100 Target &target = GetTarget();
4101 bool syntax_error = false;
4102 uint32_t i;
4103 uint32_t num_successful_lookups = 0;
4104 uint32_t addr_byte_size = target.GetArchitecture().GetAddressByteSize();
4105 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
4106 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
4107 // Dump all sections for all modules images
4108
4109 if (command.GetArgumentCount() == 0) {
4110 // Where it is possible to look in the current symbol context first,
4111 // try that. If this search was successful and --all was not passed,
4112 // don't print anything else.
4113 if (LookupHere(m_interpreter, result, syntax_error)) {
4114 result.GetOutputStream().EOL();
4115 num_successful_lookups++;
4116 if (!m_options.m_print_all) {
4118 return;
4119 }
4120 }
4121
4122 // Dump all sections for all other modules
4123
4124 const ModuleList &target_modules = target.GetImages();
4125 std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
4126 if (target_modules.GetSize() == 0) {
4127 result.AppendError("the target has no associated executable images");
4128 return;
4129 }
4130
4131 for (ModuleSP module_sp : target_modules.ModulesNoLocking()) {
4132 if (LookupInModule(m_interpreter, module_sp.get(), result,
4133 syntax_error)) {
4134 result.GetOutputStream().EOL();
4135 num_successful_lookups++;
4136 }
4137 }
4138 } else {
4139 // Dump specified images (by basename or fullpath)
4140 const char *arg_cstr;
4141 for (i = 0; (arg_cstr = command.GetArgumentAtIndex(i)) != nullptr &&
4142 !syntax_error;
4143 ++i) {
4144 ModuleList module_list;
4145 const size_t num_matches =
4146 FindModulesByName(&target, arg_cstr, module_list, false);
4147 if (num_matches > 0) {
4148 for (size_t j = 0; j < num_matches; ++j) {
4149 Module *module = module_list.GetModulePointerAtIndex(j);
4150 if (module) {
4151 if (LookupInModule(m_interpreter, module, result, syntax_error)) {
4152 result.GetOutputStream().EOL();
4153 num_successful_lookups++;
4154 }
4155 }
4156 }
4157 } else
4159 "Unable to find an image that matches '%s'.\n", arg_cstr);
4160 }
4161 }
4162
4163 if (num_successful_lookups > 0)
4165 else
4167 }
4168
4170};
4171
4172#pragma mark CommandObjectMultiwordImageSearchPaths
4173
4174// CommandObjectMultiwordImageSearchPaths
4175
4177 : public CommandObjectMultiword {
4178public:
4181 interpreter, "target modules search-paths",
4182 "Commands for managing module search paths for a target.",
4183 "target modules search-paths <subcommand> [<subcommand-options>]") {
4185 "add", CommandObjectSP(
4189 interpreter)));
4191 "insert",
4196 interpreter)));
4199 interpreter)));
4200 }
4201
4203};
4204
4205#pragma mark CommandObjectTargetModules
4206
4207// CommandObjectTargetModules
4208
4210public:
4211 // Constructors and Destructors
4213 : CommandObjectMultiword(interpreter, "target modules",
4214 "Commands for accessing information for one or "
4215 "more target modules.",
4216 "target modules <sub-command> ...") {
4218 "add", CommandObjectSP(new CommandObjectTargetModulesAdd(interpreter)));
4220 interpreter)));
4222 interpreter)));
4224 interpreter)));
4226 "lookup",
4229 "search-paths",
4233 "show-unwind",
4235 }
4236
4237 ~CommandObjectTargetModules() override = default;
4238
4239private:
4240 // For CommandObjectTargetModules only
4244};
4245
4247public:
4250 interpreter, "target symbols add",
4251 "Add a debug symbol file to one of the target's current modules by "
4252 "specifying a path to a debug symbols file or by using the options "
4253 "to specify a module.",
4254 "target symbols add <cmd-options> [<symfile>]",
4255 eCommandRequiresTarget),
4257 LLDB_OPT_SET_1, false, "shlib", 's', lldb::eModuleCompletion,
4259 "Locate the debug symbols for the shared library specified by "
4260 "name."),
4262 LLDB_OPT_SET_2, false, "frame", 'F',
4263 "Locate the debug symbols for the currently selected frame.", false,
4264 true),
4265 m_current_stack_option(LLDB_OPT_SET_2, false, "stack", 'S',
4266 "Locate the debug symbols for every frame in "
4267 "the current call stack.",
4268 false, true)
4269
4270 {
4278 m_option_group.Finalize();
4280 }
4281
4283
4284 Options *GetOptions() override { return &m_option_group; }
4285
4286protected:
4287 bool AddModuleSymbols(Target *target, ModuleSpec &module_spec, bool &flush,
4288 CommandReturnObject &result) {
4289 const FileSpec &symbol_fspec = module_spec.GetSymbolFileSpec();
4290 if (!symbol_fspec) {
4291 result.AppendError(
4292 "one or more executable image paths must be specified");
4293 return false;
4294 }
4295
4296 char symfile_path[PATH_MAX];
4297 symbol_fspec.GetPath(symfile_path, sizeof(symfile_path));
4298
4299 if (!module_spec.GetUUID().IsValid()) {
4300 if (!module_spec.GetFileSpec() && !module_spec.GetPlatformFileSpec())
4301 module_spec.GetFileSpec().SetFilename(symbol_fspec.GetFilename());
4302 }
4303
4304 // Now module_spec represents a symbol file for a module that might exist
4305 // in the current target. Let's find possible matches.
4306 ModuleList matching_modules;
4307
4308 // First extract all module specs from the symbol file
4309 lldb_private::ModuleSpecList symfile_module_specs;
4311 0, 0, symfile_module_specs)) {
4312 // Now extract the module spec that matches the target architecture
4313 ModuleSpec target_arch_module_spec;
4314 ModuleSpec symfile_module_spec;
4315 target_arch_module_spec.GetArchitecture() = target->GetArchitecture();
4316 if (symfile_module_specs.FindMatchingModuleSpec(target_arch_module_spec,
4317 symfile_module_spec)) {
4318 if (symfile_module_spec.GetUUID().IsValid()) {
4319 // It has a UUID, look for this UUID in the target modules
4320 ModuleSpec symfile_uuid_module_spec;
4321 symfile_uuid_module_spec.GetUUID() = symfile_module_spec.GetUUID();
4322 target->GetImages().FindModules(symfile_uuid_module_spec,
4323 matching_modules);
4324 }
4325 }
4326
4327 if (matching_modules.IsEmpty()) {
4328 // No matches yet. Iterate through the module specs to find a UUID
4329 // value that we can match up to an image in our target.
4330 const size_t num_symfile_module_specs = symfile_module_specs.GetSize();
4331 for (size_t i = 0;
4332 i < num_symfile_module_specs && matching_modules.IsEmpty(); ++i) {
4333 if (symfile_module_specs.GetModuleSpecAtIndex(
4334 i, symfile_module_spec)) {
4335 if (symfile_module_spec.GetUUID().IsValid()) {
4336 // It has a UUID. Look for this UUID in the target modules.
4337 ModuleSpec symfile_uuid_module_spec;
4338 symfile_uuid_module_spec.GetUUID() =
4339 symfile_module_spec.GetUUID();
4340 target->GetImages().FindModules(symfile_uuid_module_spec,
4341 matching_modules);
4342 }
4343 }
4344 }
4345 }
4346 }
4347
4348 // Just try to match up the file by basename if we have no matches at
4349 // this point. For example, module foo might have symbols in foo.debug.
4350 if (matching_modules.IsEmpty())
4351 target->GetImages().FindModules(module_spec, matching_modules);
4352
4353 while (matching_modules.IsEmpty()) {
4354 ConstString filename_no_extension(
4356 // Empty string returned, let's bail
4357 if (!filename_no_extension)
4358 break;
4359
4360 // Check if there was no extension to strip and the basename is the same
4361 if (filename_no_extension == module_spec.GetFileSpec().GetFilename())
4362 break;
4363
4364 // Replace basename with one fewer extension
4365 module_spec.GetFileSpec().SetFilename(filename_no_extension);
4366 target->GetImages().FindModules(module_spec, matching_modules);
4367 }
4368
4369 if (matching_modules.GetSize() > 1) {
4370 result.AppendErrorWithFormat("multiple modules match symbol file '%s', "
4371 "use the --uuid option to resolve the "
4372 "ambiguity.\n",
4373 symfile_path);
4374 return false;
4375 }
4376
4377 if (matching_modules.GetSize() == 1) {
4378 ModuleSP module_sp(matching_modules.GetModuleAtIndex(0));
4379
4380 // The module has not yet created its symbol vendor, we can just give
4381 // the existing target module the symfile path to use for when it
4382 // decides to create it!
4383 module_sp->SetSymbolFileFileSpec(symbol_fspec);
4384
4385 SymbolFile *symbol_file =
4386 module_sp->GetSymbolFile(true, &result.GetErrorStream());
4387 if (symbol_file) {
4388 ObjectFile *object_file = symbol_file->GetObjectFile();
4389 if (object_file && object_file->GetFileSpec() == symbol_fspec) {
4390 // Provide feedback that the symfile has been successfully added.
4391 const FileSpec &module_fs = module_sp->GetFileSpec();
4393 "symbol file '%s' has been added to '%s'\n", symfile_path,
4394 module_fs.GetPath().c_str());
4395
4396 // Let clients know something changed in the module if it is
4397 // currently loaded
4398 ModuleList module_list;
4399 module_list.Append(module_sp);
4400 target->SymbolsDidLoad(module_list);
4401
4402 // Make sure we load any scripting resources that may be embedded
4403 // in the debug info files in case the platform supports that.
4404 Status error;
4405 StreamString feedback_stream;
4406 module_sp->LoadScriptingResourceInTarget(target, error,
4407 feedback_stream);
4408 if (error.Fail() && error.AsCString())
4410 "unable to load scripting data for module %s - error "
4411 "reported was %s",
4412 module_sp->GetFileSpec()
4413 .GetFileNameStrippingExtension()
4414 .GetCString(),
4415 error.AsCString());
4416 else if (feedback_stream.GetSize())
4417 result.AppendWarning(feedback_stream.GetData());
4418
4419 flush = true;
4421 return true;
4422 }
4423 }
4424 // Clear the symbol file spec if anything went wrong
4425 module_sp->SetSymbolFileFileSpec(FileSpec());
4426 }
4427
4428 StreamString ss_symfile_uuid;
4429 if (module_spec.GetUUID().IsValid()) {
4430 ss_symfile_uuid << " (";
4431 module_spec.GetUUID().Dump(ss_symfile_uuid);
4432 ss_symfile_uuid << ')';
4433 }
4434 result.AppendErrorWithFormat(
4435 "symbol file '%s'%s does not match any existing module%s\n",
4436 symfile_path, ss_symfile_uuid.GetData(),
4437 !llvm::sys::fs::is_regular_file(symbol_fspec.GetPath())
4438 ? "\n please specify the full path to the symbol file"
4439 : "");
4440 return false;
4441 }
4442
4444 CommandReturnObject &result, bool &flush) {
4445 Status error;
4447 if (module_spec.GetSymbolFileSpec())
4448 return AddModuleSymbols(m_exe_ctx.GetTargetPtr(), module_spec, flush,
4449 result);
4450 } else {
4451 result.SetError(std::move(error));
4452 }
4453 return false;
4454 }
4455
4456 bool AddSymbolsForUUID(CommandReturnObject &result, bool &flush) {
4457 assert(m_uuid_option_group.GetOptionValue().OptionWasSet());
4458
4459 ModuleSpec module_spec;
4460 module_spec.GetUUID() =
4461 m_uuid_option_group.GetOptionValue().GetCurrentValue();
4462
4463 if (!DownloadObjectAndSymbolFile(module_spec, result, flush)) {
4464 StreamString error_strm;
4465 error_strm.PutCString("unable to find debug symbols for UUID ");
4466 module_spec.GetUUID().Dump(error_strm);
4467 result.AppendError(error_strm.GetString());
4468 return false;
4469 }
4470
4471 return true;
4472 }
4473
4474 bool AddSymbolsForFile(CommandReturnObject &result, bool &flush) {
4475 assert(m_file_option.GetOptionValue().OptionWasSet());
4476
4477 ModuleSpec module_spec;
4478 module_spec.GetFileSpec() =
4479 m_file_option.GetOptionValue().GetCurrentValue();
4480
4481 Target *target = m_exe_ctx.GetTargetPtr();
4482 ModuleSP module_sp(target->GetImages().FindFirstModule(module_spec));
4483 if (module_sp) {
4484 module_spec.GetFileSpec() = module_sp->GetFileSpec();
4485 module_spec.GetPlatformFileSpec() = module_sp->GetPlatformFileSpec();
4486 module_spec.GetUUID() = module_sp->GetUUID();
4487 module_spec.GetArchitecture() = module_sp->GetArchitecture();
4488 } else {
4489 module_spec.GetArchitecture() = target->GetArchitecture();
4490 }
4491
4492 if (!DownloadObjectAndSymbolFile(module_spec, result, flush)) {
4493 StreamString error_strm;
4494 error_strm.PutCString(
4495 "unable to find debug symbols for the executable file ");
4496 error_strm << module_spec.GetFileSpec();
4497 result.AppendError(error_strm.GetString());
4498 return false;
4499 }
4500
4501 return true;
4502 }
4503
4504 bool AddSymbolsForFrame(CommandReturnObject &result, bool &flush) {
4505 assert(m_current_frame_option.GetOptionValue().OptionWasSet());
4506
4507 Process *process = m_exe_ctx.GetProcessPtr();
4508 if (!process) {
4509 result.AppendError(
4510 "a process must exist in order to use the --frame option");
4511 return false;
4512 }
4513
4514 const StateType process_state = process->GetState();
4515 if (!StateIsStoppedState(process_state, true)) {
4516 result.AppendErrorWithFormat("process is not stopped: %s",
4517 StateAsCString(process_state));
4518 return false;
4519 }
4520
4521 StackFrame *frame = m_exe_ctx.GetFramePtr();
4522 if (!frame) {
4523 result.AppendError("invalid current frame");
4524 return false;
4525 }
4526
4527 ModuleSP frame_module_sp(
4528 frame->GetSymbolContext(eSymbolContextModule).module_sp);
4529 if (!frame_module_sp) {
4530 result.AppendError("frame has no module");
4531 return false;
4532 }
4533
4534 ModuleSpec module_spec;
4535 module_spec.GetUUID() = frame_module_sp->GetUUID();
4536 module_spec.GetArchitecture() = frame_module_sp->GetArchitecture();
4537 module_spec.GetFileSpec() = frame_module_sp->GetPlatformFileSpec();
4538
4539 if (!DownloadObjectAndSymbolFile(module_spec, result, flush)) {
4540 result.AppendError("unable to find debug symbols for the current frame");
4541 return false;
4542 }
4543
4544 return true;
4545 }
4546
4547 bool AddSymbolsForStack(CommandReturnObject &result, bool &flush) {
4548 assert(m_current_stack_option.GetOptionValue().OptionWasSet());
4549
4550 Process *process = m_exe_ctx.GetProcessPtr();
4551 if (!process) {
4552 result.AppendError(
4553 "a process must exist in order to use the --stack option");
4554 return false;
4555 }
4556
4557 const StateType process_state = process->GetState();
4558 if (!StateIsStoppedState(process_state, true)) {
4559 result.AppendErrorWithFormat("process is not stopped: %s",
4560 StateAsCString(process_state));
4561 return false;
4562 }
4563
4564 Thread *thread = m_exe_ctx.GetThreadPtr();
4565 if (!thread) {
4566 result.AppendError("invalid current thread");
4567 return false;
4568 }
4569
4570 bool symbols_found = false;
4571 uint32_t frame_count = thread->GetStackFrameCount();
4572 for (uint32_t i = 0; i < frame_count; ++i) {
4573 lldb::StackFrameSP frame_sp = thread->GetStackFrameAtIndex(i);
4574
4575 ModuleSP frame_module_sp(
4576 frame_sp->GetSymbolContext(eSymbolContextModule).module_sp);
4577 if (!frame_module_sp)
4578 continue;
4579
4580 ModuleSpec module_spec;
4581 module_spec.GetUUID() = frame_module_sp->GetUUID();
4582 module_spec.GetFileSpec() = frame_module_sp->GetPlatformFileSpec();
4583 module_spec.GetArchitecture() = frame_module_sp->GetArchitecture();
4584
4585 bool current_frame_flush = false;
4586 if (DownloadObjectAndSymbolFile(module_spec, result, current_frame_flush))
4587 symbols_found = true;
4588 flush |= current_frame_flush;
4589 }
4590
4591 if (!symbols_found) {
4592 result.AppendError(
4593 "unable to find debug symbols in the current call stack");
4594 return false;
4595 }
4596
4597 return true;
4598 }
4599
4600 void DoExecute(Args &args, CommandReturnObject &result) override {
4601 Target *target = m_exe_ctx.GetTargetPtr();
4603 bool flush = false;
4604 ModuleSpec module_spec;
4605 const bool uuid_option_set =
4606 m_uuid_option_group.GetOptionValue().OptionWasSet();
4607 const bool file_option_set = m_file_option.GetOptionValue().OptionWasSet();
4608 const bool frame_option_set =
4609 m_current_frame_option.GetOptionValue().OptionWasSet();
4610 const bool stack_option_set =
4611 m_current_stack_option.GetOptionValue().OptionWasSet();
4612 const size_t argc = args.GetArgumentCount();
4613
4614 if (argc == 0) {
4615 if (uuid_option_set)
4616 AddSymbolsForUUID(result, flush);
4617 else if (file_option_set)
4618 AddSymbolsForFile(result, flush);
4619 else if (frame_option_set)
4620 AddSymbolsForFrame(result, flush);
4621 else if (stack_option_set)
4622 AddSymbolsForStack(result, flush);
4623 else
4624 result.AppendError("one or more symbol file paths must be specified, "
4625 "or options must be specified");
4626 } else {
4627 if (uuid_option_set) {
4628 result.AppendError("specify either one or more paths to symbol files "
4629 "or use the --uuid option without arguments");
4630 } else if (frame_option_set) {
4631 result.AppendError("specify either one or more paths to symbol files "
4632 "or use the --frame option without arguments");
4633 } else if (file_option_set && argc > 1) {
4634 result.AppendError("specify at most one symbol file path when "
4635 "--shlib option is set");
4636 } else {
4637 PlatformSP platform_sp(target->GetPlatform());
4638
4639 for (auto &entry : args.entries()) {
4640 if (!entry.ref().empty()) {
4641 auto &symbol_file_spec = module_spec.GetSymbolFileSpec();
4642 symbol_file_spec.SetFile(entry.ref(), FileSpec::Style::native);
4643 FileSystem::Instance().Resolve(symbol_file_spec);
4644 if (file_option_set) {
4645 module_spec.GetFileSpec() =
4646 m_file_option.GetOptionValue().GetCurrentValue();
4647 }
4648 if (platform_sp) {
4649 FileSpec symfile_spec;
4650 if (platform_sp
4651 ->ResolveSymbolFile(*target, module_spec, symfile_spec)
4652 .Success())
4653 module_spec.GetSymbolFileSpec() = symfile_spec;
4654 }
4655
4656 bool symfile_exists =
4658
4659 if (symfile_exists) {
4660 if (!AddModuleSymbols(target, module_spec, flush, result))
4661 break;
4662 } else {
4663 std::string resolved_symfile_path =
4664 module_spec.GetSymbolFileSpec().GetPath();
4665 if (resolved_symfile_path != entry.ref()) {
4666 result.AppendErrorWithFormat(
4667 "invalid module path '%s' with resolved path '%s'\n",
4668 entry.c_str(), resolved_symfile_path.c_str());
4669 break;
4670 }
4671 result.AppendErrorWithFormat("invalid module path '%s'\n",
4672 entry.c_str());
4673 break;
4674 }
4675 }
4676 }
4677 }
4678 }
4679
4680 if (flush) {
4681 Process *process = m_exe_ctx.GetProcessPtr();
4682 if (process)
4683 process->Flush();
4684 }
4685 }
4686
4692};
4693
4694#pragma mark CommandObjectTargetSymbols
4695
4696// CommandObjectTargetSymbols
4697
4699public:
4700 // Constructors and Destructors
4703 interpreter, "target symbols",
4704 "Commands for adding and managing debug symbol files.",
4705 "target symbols <sub-command> ...") {
4707 "add", CommandObjectSP(new CommandObjectTargetSymbolsAdd(interpreter)));
4708 }
4709
4710 ~CommandObjectTargetSymbols() override = default;
4711
4712private:
4713 // For CommandObjectTargetModules only
4717};
4718
4719#pragma mark CommandObjectTargetStopHookAdd
4720
4721// CommandObjectTargetStopHookAdd
4722#define LLDB_OPTIONS_target_stop_hook_add
4723#include "CommandOptions.inc"
4724
4727public:
4729 public:
4731
4732 ~CommandOptions() override = default;
4733
4734 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
4735 return llvm::ArrayRef(g_target_stop_hook_add_options);
4736 }
4737
4738 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
4739 ExecutionContext *execution_context) override {
4740 Status error;
4741 const int short_option =
4742 g_target_stop_hook_add_options[option_idx].short_option;
4743
4744 switch (short_option) {
4745 case 'c':
4746 m_class_name = std::string(option_arg);
4747 m_sym_ctx_specified = true;
4748 break;
4749
4750 case 'e':
4751 if (option_arg.getAsInteger(0, m_line_end)) {
4753 "invalid end line number: \"%s\"", option_arg.str().c_str());
4754 break;
4755 }
4756 m_sym_ctx_specified = true;
4757 break;
4758
4759 case 'G': {
4760 bool value, success;
4761 value = OptionArgParser::ToBoolean(option_arg, false, &success);
4762 if (success) {
4763 m_auto_continue = value;
4764 } else
4766 "invalid boolean value '%s' passed for -G option",
4767 option_arg.str().c_str());
4768 } break;
4769 case 'l':
4770 if (option_arg.getAsInteger(0, m_line_start)) {
4772 "invalid start line number: \"%s\"", option_arg.str().c_str());
4773 break;
4774 }
4775 m_sym_ctx_specified = true;
4776 break;
4777
4778 case 'i':
4779 m_no_inlines = true;
4780 break;
4781
4782 case 'n':
4783 m_function_name = std::string(option_arg);
4784 m_func_name_type_mask |= eFunctionNameTypeAuto;
4785 m_sym_ctx_specified = true;
4786 break;
4787
4788 case 'f':
4789 m_file_name = std::string(option_arg);
4790 m_sym_ctx_specified = true;
4791 break;
4792
4793 case 's':
4794 m_module_name = std::string(option_arg);
4795 m_sym_ctx_specified = true;
4796 break;
4797
4798 case 't':
4799 if (option_arg.getAsInteger(0, m_thread_id))
4801 "invalid thread id string '%s'", option_arg.str().c_str());
4802 m_thread_specified = true;
4803 break;
4804
4805 case 'T':
4806 m_thread_name = std::string(option_arg);
4807 m_thread_specified = true;
4808 break;
4809
4810 case 'q':
4811 m_queue_name = std::string(option_arg);
4812 m_thread_specified = true;
4813 break;
4814
4815 case 'x':
4816 if (option_arg.getAsInteger(0, m_thread_index))
4818 "invalid thread index string '%s'", option_arg.str().c_str());
4819 m_thread_specified = true;
4820 break;
4821
4822 case 'o':
4823 m_use_one_liner = true;
4824 m_one_liner.push_back(std::string(option_arg));
4825 break;
4826
4827 case 'I': {
4828 bool value, success;
4829 value = OptionArgParser::ToBoolean(option_arg, false, &success);
4830 if (success)
4831 m_at_initial_stop = value;
4832 else
4834 "invalid boolean value '%s' passed for -F option",
4835 option_arg.str().c_str());
4836 } break;
4837
4838 default:
4839 llvm_unreachable("Unimplemented option");
4840 }
4841 return error;
4842 }
4843
4844 void OptionParsingStarting(ExecutionContext *execution_context) override {
4845 m_class_name.clear();
4846 m_function_name.clear();
4847 m_line_start = 0;
4849 m_file_name.clear();
4850 m_module_name.clear();
4851 m_func_name_type_mask = eFunctionNameTypeAuto;
4854 m_thread_name.clear();
4855 m_queue_name.clear();
4856
4857 m_no_inlines = false;
4858 m_sym_ctx_specified = false;
4859 m_thread_specified = false;
4860
4861 m_use_one_liner = false;
4862 m_one_liner.clear();
4863 m_auto_continue = false;
4864 m_at_initial_stop = true;
4865 }
4866
4867 std::string m_class_name;
4868 std::string m_function_name;
4869 uint32_t m_line_start = 0;
4871 std::string m_file_name;
4872 std::string m_module_name;
4874 eFunctionNameTypeAuto; // A pick from lldb::FunctionNameType.
4877 std::string m_thread_name;
4878 std::string m_queue_name;
4880 bool m_no_inlines = false;
4882 // Instance variables to hold the values for one_liner options.
4883 bool m_use_one_liner = false;
4884 std::vector<std::string> m_one_liner;
4886
4887 bool m_auto_continue = false;
4888 };
4889
4891 : CommandObjectParsed(interpreter, "target stop-hook add",
4892 "Add a hook to be executed when the target stops."
4893 "The hook can either be a list of commands or an "
4894 "appropriately defined Python class. You can also "
4895 "add filters so the hook only runs a certain stop "
4896 "points.",
4897 "target stop-hook add"),
4900 m_python_class_options("scripted stop-hook", true, 'P') {
4902 R"(
4903Command Based stop-hooks:
4904-------------------------
4905 Stop hooks can run a list of lldb commands by providing one or more
4906 --one-liner options. The commands will get run in the order they are added.
4907 Or you can provide no commands, in which case you will enter a command editor
4908 where you can enter the commands to be run.
4909
4910Python Based Stop Hooks:
4911------------------------
4912 Stop hooks can be implemented with a suitably defined Python class, whose name
4913 is passed in the --python-class option.
4914
4915 When the stop hook is added, the class is initialized by calling:
4916
4917 def __init__(self, target, extra_args, internal_dict):
4918
4919 target: The target that the stop hook is being added to.
4920 extra_args: An SBStructuredData Dictionary filled with the -key -value
4921 option pairs passed to the command.
4922 dict: An implementation detail provided by lldb.
4923
4924 Then when the stop-hook triggers, lldb will run the 'handle_stop' method.
4925 The method has the signature:
4927 def handle_stop(self, exe_ctx, stream):
4928
4929 exe_ctx: An SBExecutionContext for the thread that has stopped.
4930 stream: An SBStream, anything written to this stream will be printed in the
4931 the stop message when the process stops.
4932
4933 Return Value: The method returns "should_stop". If should_stop is false
4934 from all the stop hook executions on threads that stopped
4935 with a reason, then the process will continue. Note that this
4936 will happen only after all the stop hooks are run.
4937
4938Filter Options:
4939---------------
4940 Stop hooks can be set to always run, or to only run when the stopped thread
4941 matches the filter options passed on the command line. The available filter
4942 options include a shared library or a thread or queue specification,
4943 a line range in a source file, a function name or a class name.
4944 )");
4947 LLDB_OPT_SET_FROM_TO(4, 6));
4948 m_all_options.Append(&m_options);
4949 m_all_options.Finalize();
4950 }
4951
4952 ~CommandObjectTargetStopHookAdd() override = default;
4953
4954 Options *GetOptions() override { return &m_all_options; }
4955
4956protected:
4957 void IOHandlerActivated(IOHandler &io_handler, bool interactive) override {
4958 if (interactive) {
4959 if (lldb::LockableStreamFileSP output_sp =
4960 io_handler.GetOutputStreamFileSP()) {
4961 LockedStreamFile locked_stream = output_sp->Lock();
4962 locked_stream.PutCString(
4963 "Enter your stop hook command(s). Type 'DONE' to end.\n");
4964 }
4965 }
4966 }
4967
4968 void IOHandlerInputComplete(IOHandler &io_handler,
4969 std::string &line) override {
4970 if (m_stop_hook_sp) {
4971 if (line.empty()) {
4972 if (lldb::LockableStreamFileSP error_sp =
4973 io_handler.GetErrorStreamFileSP()) {
4974 LockedStreamFile locked_stream = error_sp->Lock();
4975 locked_stream.Printf("error: stop hook #%" PRIu64
4976 " aborted, no commands.\n",
4977 m_stop_hook_sp->GetID());
4978 }
4980 } else {
4981 // The IOHandler editor is only for command lines stop hooks:
4982 Target::StopHookCommandLine *hook_ptr =
4983 static_cast<Target::StopHookCommandLine *>(m_stop_hook_sp.get());
4984
4985 hook_ptr->SetActionFromString(line);
4986 if (lldb::LockableStreamFileSP output_sp =
4987 io_handler.GetOutputStreamFileSP()) {
4988 LockedStreamFile locked_stream = output_sp->Lock();
4989 locked_stream.Printf("Stop hook #%" PRIu64 " added.\n",
4990 m_stop_hook_sp->GetID());
4991 }
4992 }
4993 m_stop_hook_sp.reset();
4994 }
4995 io_handler.SetIsDone(true);
4996 }
4997
4998 void DoExecute(Args &command, CommandReturnObject &result) override {
4999 m_stop_hook_sp.reset();
5000
5001 Target &target = GetTarget();
5002 Target::StopHookSP new_hook_sp =
5003 target.CreateStopHook(m_python_class_options.GetName().empty() ?
5004 Target::StopHook::StopHookKind::CommandBased
5005 : Target::StopHook::StopHookKind::ScriptBased);
5006
5007 // First step, make the specifier.
5008 std::unique_ptr<SymbolContextSpecifier> specifier_up;
5009 if (m_options.m_sym_ctx_specified) {
5010 specifier_up = std::make_unique<SymbolContextSpecifier>(
5011 GetDebugger().GetSelectedTarget());
5012
5013 if (!m_options.m_module_name.empty()) {
5014 specifier_up->AddSpecification(
5015 m_options.m_module_name.c_str(),
5017 }
5018
5019 if (!m_options.m_class_name.empty()) {
5020 specifier_up->AddSpecification(
5021 m_options.m_class_name.c_str(),
5023 }
5024
5025 if (!m_options.m_file_name.empty()) {
5026 specifier_up->AddSpecification(m_options.m_file_name.c_str(),
5028 }
5029
5030 if (m_options.m_line_start != 0) {
5031 specifier_up->AddLineSpecification(
5032 m_options.m_line_start,
5034 }
5035
5036 if (m_options.m_line_end != UINT_MAX) {
5037 specifier_up->AddLineSpecification(
5039 }
5040
5041 if (!m_options.m_function_name.empty()) {
5042 specifier_up->AddSpecification(
5043 m_options.m_function_name.c_str(),
5045 }
5046 }
5047
5048 if (specifier_up)
5049 new_hook_sp->SetSpecifier(specifier_up.release());
5050
5051 // Should we run at the initial stop:
5052 new_hook_sp->SetRunAtInitialStop(m_options.m_at_initial_stop);
5053
5054 // Next see if any of the thread options have been entered:
5055
5056 if (m_options.m_thread_specified) {
5057 ThreadSpec *thread_spec = new ThreadSpec();
5058
5059 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID) {
5060 thread_spec->SetTID(m_options.m_thread_id);
5061 }
5062
5063 if (m_options.m_thread_index != UINT32_MAX)
5064 thread_spec->SetIndex(m_options.m_thread_index);
5065
5066 if (!m_options.m_thread_name.empty())
5067 thread_spec->SetName(m_options.m_thread_name.c_str());
5069 if (!m_options.m_queue_name.empty())
5070 thread_spec->SetQueueName(m_options.m_queue_name.c_str());
5072 new_hook_sp->SetThreadSpecifier(thread_spec);
5073 }
5074
5075 new_hook_sp->SetAutoContinue(m_options.m_auto_continue);
5077 // This is a command line stop hook:
5078 Target::StopHookCommandLine *hook_ptr =
5079 static_cast<Target::StopHookCommandLine *>(new_hook_sp.get());
5081 result.AppendMessageWithFormat("Stop hook #%" PRIu64 " added.\n",
5082 new_hook_sp->GetID());
5083 } else if (!m_python_class_options.GetName().empty()) {
5084 // This is a scripted stop hook:
5085 Target::StopHookScripted *hook_ptr =
5086 static_cast<Target::StopHookScripted *>(new_hook_sp.get());
5087 Status error = hook_ptr->SetScriptCallback(
5088 m_python_class_options.GetName(),
5089 m_python_class_options.GetStructuredData());
5090 if (error.Success())
5091 result.AppendMessageWithFormat("Stop hook #%" PRIu64 " added.\n",
5092 new_hook_sp->GetID());
5093 else {
5094 // FIXME: Set the stop hook ID counter back.
5095 result.AppendErrorWithFormat("Couldn't add stop hook: %s",
5096 error.AsCString());
5097 target.UndoCreateStopHook(new_hook_sp->GetID());
5098 return;
5099 }
5100 } else {
5101 m_stop_hook_sp = new_hook_sp;
5102 m_interpreter.GetLLDBCommandsFromIOHandler("> ", // Prompt
5103 *this); // IOHandlerDelegate
5104 }
5106 }
5107
5108private:
5110 OptionGroupPythonClassWithDict m_python_class_options;
5111 OptionGroupOptions m_all_options;
5112
5114};
5115
5116#pragma mark CommandObjectTargetStopHookDelete
5117
5118// CommandObjectTargetStopHookDelete
5119
5121public:
5123 : CommandObjectParsed(interpreter, "target stop-hook delete",
5124 "Delete a stop-hook.",
5125 "target stop-hook delete [<idx>]") {
5127 R"(
5128Deletes the stop hook by index.
5129
5130At any given stop, all enabled stop hooks that pass the stop filter will
5131get a chance to run. That means if one stop-hook deletes another stop hook
5132while executing, the deleted stop hook will still fire for the stop at which
5133it was deleted.
5134 )");
5136 }
5137
5138 ~CommandObjectTargetStopHookDelete() override = default;
5139
5140 void
5142 OptionElementVector &opt_element_vector) override {
5143 if (request.GetCursorIndex())
5144 return;
5145 CommandObject::HandleArgumentCompletion(request, opt_element_vector);
5146 }
5147
5148protected:
5149 void DoExecute(Args &command, CommandReturnObject &result) override {
5150 Target &target = GetTarget();
5151 // FIXME: see if we can use the breakpoint id style parser?
5152 size_t num_args = command.GetArgumentCount();
5153 if (num_args == 0) {
5154 if (!m_interpreter.Confirm("Delete all stop hooks?", true)) {
5156 return;
5157 } else {
5158 target.RemoveAllStopHooks();
5159 }
5160 } else {
5161 for (size_t i = 0; i < num_args; i++) {
5162 lldb::user_id_t user_id;
5163 if (!llvm::to_integer(command.GetArgumentAtIndex(i), user_id)) {
5164 result.AppendErrorWithFormat("invalid stop hook id: \"%s\".\n",
5165 command.GetArgumentAtIndex(i));
5166 return;
5167 }
5168 if (!target.RemoveStopHookByID(user_id)) {
5169 result.AppendErrorWithFormat("unknown stop hook id: \"%s\".\n",
5170 command.GetArgumentAtIndex(i));
5171 return;
5172 }
5173 }
5174 }
5176 }
5177};
5178
5179#pragma mark CommandObjectTargetStopHookEnableDisable
5180
5181// CommandObjectTargetStopHookEnableDisable
5182
5184public:
5186 bool enable, const char *name,
5187 const char *help, const char *syntax)
5188 : CommandObjectParsed(interpreter, name, help, syntax), m_enable(enable) {
5190 }
5191
5193
5194 void
5196 OptionElementVector &opt_element_vector) override {
5197 if (request.GetCursorIndex())
5198 return;
5199 CommandObject::HandleArgumentCompletion(request, opt_element_vector);
5200 }
5201
5202protected:
5203 void DoExecute(Args &command, CommandReturnObject &result) override {
5204 Target &target = GetTarget();
5205 // FIXME: see if we can use the breakpoint id style parser?
5206 size_t num_args = command.GetArgumentCount();
5207 bool success;
5208
5209 if (num_args == 0) {
5211 } else {
5212 for (size_t i = 0; i < num_args; i++) {
5213 lldb::user_id_t user_id;
5214 if (!llvm::to_integer(command.GetArgumentAtIndex(i), user_id)) {
5215 result.AppendErrorWithFormat("invalid stop hook id: \"%s\".\n",
5216 command.GetArgumentAtIndex(i));
5217 return;
5218 }
5219 success = target.SetStopHookActiveStateByID(user_id, m_enable);
5220 if (!success) {
5221 result.AppendErrorWithFormat("unknown stop hook id: \"%s\".\n",
5222 command.GetArgumentAtIndex(i));
5223 return;
5224 }
5225 }
5226 }
5228 }
5229
5230private:
5232};
5233
5234#pragma mark CommandObjectTargetStopHookList
5235
5236// CommandObjectTargetStopHookList
5237#define LLDB_OPTIONS_target_stop_hook_list
5238#include "CommandOptions.inc"
5239
5241public:
5243 : CommandObjectParsed(interpreter, "target stop-hook list",
5244 "List all stop-hooks.") {}
5245
5247
5248 Options *GetOptions() override { return &m_options; }
5249
5250 class CommandOptions : public Options {
5251 public:
5252 CommandOptions() = default;
5253 ~CommandOptions() override = default;
5254
5255 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
5256 ExecutionContext *execution_context) override {
5257 Status error;
5258 const int short_option = m_getopt_table[option_idx].val;
5259
5260 switch (short_option) {
5261 case 'i':
5262 m_internal = true;
5263 break;
5264 default:
5265 llvm_unreachable("Unimplemented option");
5266 }
5267
5268 return error;
5269 }
5270
5271 void OptionParsingStarting(ExecutionContext *execution_context) override {
5272 m_internal = false;
5273 }
5274
5275 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
5276 return llvm::ArrayRef(g_target_stop_hook_list_options);
5277 }
5278
5279 // Instance variables to hold the values for command options.
5280 bool m_internal = false;
5281 };
5282
5283protected:
5284 void DoExecute(Args &command, CommandReturnObject &result) override {
5285 Target &target = GetTarget();
5286
5287 bool printed_hook = false;
5288 for (auto &hook : target.GetStopHooks(m_options.m_internal)) {
5289 if (printed_hook)
5290 result.GetOutputStream().PutCString("\n");
5291 hook->GetDescription(result.GetOutputStream(), eDescriptionLevelFull);
5292 printed_hook = true;
5293 }
5294
5295 if (!printed_hook)
5296 result.GetOutputStream().PutCString("No stop hooks.\n");
5297
5299 }
5300
5301private:
5303};
5304
5305#pragma mark CommandObjectMultiwordTargetStopHooks
5306
5307// CommandObjectMultiwordTargetStopHooks
5308
5310public:
5313 interpreter, "target stop-hook",
5314 "Commands for operating on debugger target stop-hooks.",
5315 "target stop-hook <subcommand> [<subcommand-options>]") {
5317 new CommandObjectTargetStopHookAdd(interpreter)));
5319 "delete",
5321 LoadSubCommand("disable",
5323 interpreter, false, "target stop-hook disable [<id>]",
5324 "Disable a stop-hook.", "target stop-hook disable")));
5325 LoadSubCommand("enable",
5327 interpreter, true, "target stop-hook enable [<id>]",
5328 "Enable a stop-hook.", "target stop-hook enable")));
5330 interpreter)));
5331 }
5332
5334};
5335
5336#pragma mark CommandObjectTargetDumpTypesystem
5337
5338/// Dumps the TypeSystem of the selected Target.
5340public:
5343 interpreter, "target dump typesystem",
5344 "Dump the state of the target's internal type system. Intended to "
5345 "be used for debugging LLDB itself.",
5346 nullptr, eCommandRequiresTarget) {}
5347
5349
5350protected:
5351 void DoExecute(Args &command, CommandReturnObject &result) override {
5352 // Go over every scratch TypeSystem and dump to the command output.
5353 for (lldb::TypeSystemSP ts : GetTarget().GetScratchTypeSystems())
5354 if (ts)
5355 ts->Dump(result.GetOutputStream().AsRawOstream(), "",
5356 GetCommandInterpreter().GetDebugger().GetUseColor());
5357
5359 }
5360};
5361
5362#pragma mark CommandObjectTargetDumpSectionLoadList
5363
5364/// Dumps the SectionLoadList of the selected Target.
5366public:
5369 interpreter, "target dump section-load-list",
5370 "Dump the state of the target's internal section load list. "
5371 "Intended to be used for debugging LLDB itself.",
5372 nullptr, eCommandRequiresTarget) {}
5373
5375
5376protected:
5377 void DoExecute(Args &command, CommandReturnObject &result) override {
5378 Target &target = GetTarget();
5379 target.DumpSectionLoadList(result.GetOutputStream());
5381 }
5382};
5383
5384#pragma mark CommandObjectTargetDump
5385
5386/// Multi-word command for 'target dump'.
5388public:
5389 // Constructors and Destructors
5392 interpreter, "target dump",
5393 "Commands for dumping information about the target.",
5394 "target dump [typesystem|section-load-list]") {
5396 "typesystem",
5398 LoadSubCommand("section-load-list",
5400 interpreter)));
5401 }
5402
5403 ~CommandObjectTargetDump() override = default;
5404};
5405
5406#pragma mark CommandObjectTargetFrameProvider
5407
5408#define LLDB_OPTIONS_target_frame_provider_register
5409#include "CommandOptions.inc"
5410
5412public:
5415 interpreter, "target frame-provider register",
5416 "Register frame provider for all threads in this target.", nullptr,
5417 eCommandRequiresTarget),
5418
5419 m_class_options("target frame-provider", true, 'C', 'k', 'v', 0) {
5422 m_all_options.Finalize();
5423 }
5424
5426
5427 Options *GetOptions() override { return &m_all_options; }
5428
5429 std::optional<std::string> GetRepeatCommand(Args &current_command_args,
5430 uint32_t index) override {
5431 return std::string("");
5432 }
5433
5434protected:
5435 void DoExecute(Args &command, CommandReturnObject &result) override {
5436 ScriptedMetadataSP metadata_sp = std::make_shared<ScriptedMetadata>(
5437 m_class_options.GetName(), m_class_options.GetStructuredData());
5438
5439 Target *target = m_exe_ctx.GetTargetPtr();
5440 if (!target)
5441 target = &GetDebugger().GetDummyTarget();
5442
5443 // Create the interface for calling static methods.
5445 GetDebugger()
5448
5449 // Create a descriptor from the metadata (applies to all threads by
5450 // default).
5451 ScriptedFrameProviderDescriptor descriptor(metadata_sp);
5452 descriptor.interface_sp = interface_sp;
5453
5454 auto id_or_err = target->AddScriptedFrameProviderDescriptor(descriptor);
5455 if (!id_or_err) {
5456 result.SetError(id_or_err.takeError());
5457 return;
5458 }
5459
5461 "successfully registered scripted frame provider '%s' for target\n",
5462 m_class_options.GetName().c_str());
5463 }
5464
5467};
5468
5470public:
5473 interpreter, "target frame-provider clear",
5474 "Clear all registered frame providers from this target.", nullptr,
5475 eCommandRequiresTarget) {}
5476
5478
5479protected:
5480 void DoExecute(Args &command, CommandReturnObject &result) override {
5481 Target *target = m_exe_ctx.GetTargetPtr();
5482 if (!target) {
5483 result.AppendError("invalid target");
5484 return;
5485 }
5486
5488
5490 }
5491};
5492
5494public:
5497 interpreter, "target frame-provider list",
5498 "List all registered frame providers for the target.", nullptr,
5499 eCommandRequiresTarget) {}
5500
5502
5503protected:
5504 void DoExecute(Args &command, CommandReturnObject &result) override {
5505 Target *target = m_exe_ctx.GetTargetPtr();
5506 if (!target)
5507 target = &GetDebugger().GetDummyTarget();
5508
5509 const auto &descriptors = target->GetScriptedFrameProviderDescriptors();
5510 if (descriptors.empty()) {
5511 result.AppendMessage("no frame providers registered for this target.");
5513 return;
5514 }
5515
5516 result.AppendMessageWithFormat("%u frame provider(s) registered:\n\n",
5517 descriptors.size());
5518
5519 for (const auto &entry : descriptors) {
5520 const ScriptedFrameProviderDescriptor &descriptor = entry.second;
5521 descriptor.Dump(&result.GetOutputStream());
5522 result.GetOutputStream().PutChar('\n');
5523 }
5524
5526 }
5527};
5528
5530public:
5533 interpreter, "target frame-provider remove",
5534 "Remove a registered frame provider from the target by id.",
5535 "target frame-provider remove <provider-id>",
5536 eCommandRequiresTarget) {
5538 }
5539
5541
5542protected:
5543 void DoExecute(Args &command, CommandReturnObject &result) override {
5544 Target *target = m_exe_ctx.GetTargetPtr();
5545 if (!target)
5546 target = &GetDebugger().GetDummyTarget();
5547
5548 std::vector<uint32_t> removed_provider_ids;
5549 for (size_t i = 0; i < command.GetArgumentCount(); i++) {
5550 uint32_t provider_id = 0;
5551 if (!llvm::to_integer(command[i].ref(), provider_id)) {
5552 result.AppendError("target frame-provider remove requires integer "
5553 "provider id argument");
5554 return;
5555 }
5556
5557 if (!target->RemoveScriptedFrameProviderDescriptor(provider_id)) {
5558 result.AppendErrorWithFormat(
5559 "no frame provider named '%u' found in target\n", provider_id);
5560 return;
5561 }
5562 removed_provider_ids.push_back(provider_id);
5563 }
5564
5565 if (size_t num_removed_providers = removed_provider_ids.size()) {
5567 "Successfully removed %zu frame-providers.\n", num_removed_providers);
5569 } else {
5570 result.AppendError("0 frame providers removed.\n");
5571 }
5572 }
5573};
5574
5576public:
5579 interpreter, "target frame-provider",
5580 "Commands for registering and viewing frame providers for the "
5581 "target.",
5582 "target frame-provider [<sub-command-options>] ") {
5583 LoadSubCommand("register",
5585 interpreter)));
5586 LoadSubCommand("clear",
5588 new CommandObjectTargetFrameProviderClear(interpreter)));
5590 "list",
5593 "remove", CommandObjectSP(
5594 new CommandObjectTargetFrameProviderRemove(interpreter)));
5595 }
5596
5598};
5599
5600#pragma mark CommandObjectMultiwordTarget
5601
5602// CommandObjectMultiwordTarget
5603
5605 CommandInterpreter &interpreter)
5606 : CommandObjectMultiword(interpreter, "target",
5607 "Commands for operating on debugger targets.",
5608 "target <subcommand> [<subcommand-options>]") {
5609 LoadSubCommand("create",
5610 CommandObjectSP(new CommandObjectTargetCreate(interpreter)));
5611 LoadSubCommand("delete",
5612 CommandObjectSP(new CommandObjectTargetDelete(interpreter)));
5613 LoadSubCommand("dump",
5614 CommandObjectSP(new CommandObjectTargetDump(interpreter)));
5616 "frame-provider",
5618 LoadSubCommand("list",
5619 CommandObjectSP(new CommandObjectTargetList(interpreter)));
5620 LoadSubCommand("select",
5621 CommandObjectSP(new CommandObjectTargetSelect(interpreter)));
5622 LoadSubCommand("show-launch-environment",
5624 interpreter)));
5626 "stop-hook",
5628 LoadSubCommand("modules",
5630 LoadSubCommand("symbols",
5632 LoadSubCommand("variable",
5634}
5635
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:469
#define LLDB_LOGF(log,...)
Definition Log.h:376
#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:150
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:1035
@ 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:31
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition ArchSpec.cpp:685
bool IsValid() const
Tests if this ArchSpec is valid.
Definition ArchSpec.h:366
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 void AppendError(llvm::StringRef in_string)
const ValueObjectList & GetValueObjectList() const
void AppendWarningWithFormat(const char *format,...) __attribute__((format(printf
void SetStatus(lldb::ReturnStatus status)
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
void AppendMessageWithFormat(const char *format,...) __attribute__((format(printf
void void AppendMessageWithFormatv(const char *format, Args &&...args)
void 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
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
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.
A class to manage flag bits.
Definition Debugger.h:80
TargetList & GetTargetList()
Get accessor for the target list.
Definition Debugger.h:204
bool GetUseColor() const
Definition Debugger.cpp:456
llvm::StringRef GetRegexMatchAnsiSuffix() const
Definition Debugger.cpp:561
Target & GetDummyTarget()
Definition Debugger.h:511
llvm::StringRef GetRegexMatchAnsiPrefix() const
Definition Debugger.cpp:555
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:251
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
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
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()
@ 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:104
void FindFunctions(ConstString name, lldb::FunctionNameType name_type_mask, const ModuleFunctionSearchOptions &options, SymbolContextList &sc_list) const
ModuleIterableNoLocking ModulesNoLocking() const
Definition ModuleList.h:552
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:231
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)
ModuleIterable Modules() const
Definition ModuleList.h:546
size_t GetSize() const
Gets the size of the module list.
bool GetModuleSpecAtIndex(size_t i, ModuleSpec &module_spec) const
Definition ModuleSpec.h:341
bool FindMatchingModuleSpec(const ModuleSpec &module_spec, ModuleSpec &match_module_spec) const
Definition ModuleSpec.h:351
FileSpec & GetPlatformFileSpec()
Definition ModuleSpec.h:67
FileSpec & GetFileSpec()
Definition ModuleSpec.h:55
ArchSpec & GetArchitecture()
Definition ModuleSpec.h:91
FileSpec * GetFileSpecPtr()
Definition ModuleSpec.h:49
FileSpec & GetSymbolFileSpec()
Definition ModuleSpec.h:79
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:347
virtual SymbolFile * GetSymbolFile(bool can_create=true, Stream *feedback_strm=nullptr)
Get the module's symbol file.
Definition Module.cpp:991
static Module * GetAllocatedModuleAtIndex(size_t idx)
Definition Module.cpp:121
static std::recursive_mutex & GetAllocationModuleCollectionMutex()
Definition Module.cpp:103
bool ResolveFileAddress(lldb::addr_t vm_addr, Address &so_addr)
Definition Module.cpp:444
Symtab * GetSymtab(bool can_create=true)
Get the module's symbol table.
Definition Module.cpp:1018
bool MatchesModuleSpec(const ModuleSpec &module_ref)
Definition Module.cpp:1517
static size_t GetNumberAllocatedModules()
Definition Module.cpp:115
const ArchSpec & GetArchitecture() const
Get const accessor for the module architecture.
Definition Module.cpp:1033
std::string GetSpecificationDescription() const
Get the module path and object name.
Definition Module.cpp:1035
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:477
virtual FileSpec & GetFileSpec()
Get accessor to the object file specification.
Definition ObjectFile.h:282
virtual lldb_private::Address GetBaseAddress()
Returns base address of this object file.
Definition ObjectFile.h:487
static size_t GetModuleSpecifications(const FileSpec &file, lldb::offset_t file_offset, lldb::offset_t file_size, ModuleSpecList &specs, lldb::DataBufferSP data_sp=lldb::DataBufferSP())
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:354
ThreadList & GetThreadList()
Definition Process.h:2272
void Flush()
Flush all data in the process.
Definition Process.cpp:5934
lldb::StateType GetState()
Get accessor for the current process state.
Definition Process.cpp:1283
const lldb::ABISP & GetABI()
Definition Process.cpp:1479
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:564
void Dump(llvm::raw_ostream &s, unsigned indent, Target *target, bool show_header, uint32_t depth) const
Definition Section.cpp:650
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:294
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition Status.cpp:195
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)
Definition Stream.h:364
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition Stream.h:406
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
Definition Stream.cpp:157
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:65
void SetAddressByteSize(uint32_t addr_size)
Set the address size in bytes.
Definition Stream.cpp:217
size_t PutChar(char ch)
Definition Stream.cpp:131
void SetIndentLevel(unsigned level)
Set the current indentation level.
Definition Stream.cpp:190
void PutCStringColorHighlighted(llvm::StringRef text, std::optional< HighlightSettings > settings=std::nullopt)
Output a C string to the stream with color highlighting.
Definition Stream.cpp:75
size_t EOL()
Output and End of Line character to the stream.
Definition Stream.cpp:155
void IndentLess(unsigned amount=2)
Decrement the current indentation level.
Definition Stream.cpp:198
void IndentMore(unsigned amount=2)
Increment the current indentation level.
Definition Stream.cpp:195
unsigned GetIndentLevel() const
Get the current indentation level.
Definition Stream.cpp:187
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:228
uint32_t AppendSymbolIndexesWithName(ConstString symbol_name, std::vector< uint32_t > &matches)
Definition Symtab.cpp:681
uint32_t AppendSymbolIndexesMatchingRegExAndType(const RegularExpression &regex, lldb::SymbolType symbol_type, std::vector< uint32_t > &indexes, Mangled::NamePreference name_preference=Mangled::ePreferDemangled)
Definition Symtab.cpp:750
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:5103
Environment GetEnvironment() const
Definition Target.cpp:4757
void SetActionFromString(const std::string &strings)
Definition Target.cpp:4074
void SetActionFromStrings(const std::vector< std::string > &strings)
Definition Target.cpp:4078
Status SetScriptCallback(std::string class_name, StructuredData::ObjectSP extra_args_sp)
Definition Target.cpp:4119
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:1858
llvm::Expected< uint32_t > AddScriptedFrameProviderDescriptor(const ScriptedFrameProviderDescriptor &descriptor)
Add or update a scripted frame provider descriptor for this target.
Definition Target.cpp:3723
Module * GetExecutableModulePointer()
Definition Target.cpp:1540
PathMappingList & GetImageSearchPathList()
Definition Target.cpp:2601
std::shared_ptr< StopHook > StopHookSP
Definition Target.h:1612
void SymbolsDidLoad(ModuleList &module_list)
Definition Target.cpp:1881
const std::vector< StopHookSP > GetStopHooks(bool internal=false) const
Definition Target.cpp:3119
bool RemoveScriptedFrameProviderDescriptor(uint32_t id)
Remove a scripted frame provider descriptor by id.
Definition Target.cpp:3747
void DumpSectionLoadList(Stream &s)
Definition Target.cpp:5341
const lldb::ProcessSP & GetProcessSP() const
Definition Target.cpp:312
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:2351
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:3071
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, uint32_t stop_id=SectionLoadHistory::eStopIDNow, bool allow_section_end=false)
Definition Target.cpp:3323
const llvm::DenseMap< uint32_t, ScriptedFrameProviderDescriptor > & GetScriptedFrameProviderDescriptors() const
Get all scripted frame provider descriptors for this target.
Definition Target.cpp:3772
bool SetStopHookActiveStateByID(lldb::user_id_t uid, bool active_state)
Definition Target.cpp:3095
void SetAllStopHooksActiveState(bool active_state)
Definition Target.cpp:3106
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:3049
lldb::PlatformSP GetPlatform()
Definition Target.h:1648
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition Target.h:1111
const ArchSpec & GetArchitecture() const
Definition Target.h:1153
const std::string & GetLabel() const
Definition Target.h:632
void ClearScriptedFrameProviderDescriptors()
Clear all scripted frame provider descriptors for this target.
Definition Target.cpp:3760
lldb::ProcessSP CalculateProcess() override
Definition Target.cpp:2590
bool SetSectionLoadAddress(const lldb::SectionSP &section, lldb::addr_t load_addr, bool warn_multiple=false)
Definition Target.cpp:3334
bool RemoveStopHookByID(lldb::user_id_t uid)
Definition Target.cpp:3078
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:60
bool Empty() const
Definition TypeList.h:37
TypeIterable Types()
Definition TypeList.h:44
lldb::TypeSP GetTypeAtIndex(uint32_t idx)
Definition TypeList.cpp:66
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:326
#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:332
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:108
const char * StateAsCString(lldb::StateType state)
Converts a StateType to a C string.
Definition State.cpp:14
const char * toString(AppleArm64ExceptionClass EC)
@ 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