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