Mercurial > hg > CbC > CbC_llvm
comparison lldb/source/Commands/CommandObjectSource.cpp @ 236:c4bab56944e8 llvm-original
LLVM 16
author | kono |
---|---|
date | Wed, 09 Nov 2022 17:45:10 +0900 |
parents | 5f17cb93ff66 |
children | 1f2b6ac9f198 |
comparison
equal
deleted
inserted
replaced
232:70dce7da266c | 236:c4bab56944e8 |
---|---|
12 #include "lldb/Core/FileLineResolver.h" | 12 #include "lldb/Core/FileLineResolver.h" |
13 #include "lldb/Core/Module.h" | 13 #include "lldb/Core/Module.h" |
14 #include "lldb/Core/ModuleSpec.h" | 14 #include "lldb/Core/ModuleSpec.h" |
15 #include "lldb/Core/SourceManager.h" | 15 #include "lldb/Core/SourceManager.h" |
16 #include "lldb/Host/OptionParser.h" | 16 #include "lldb/Host/OptionParser.h" |
17 #include "lldb/Interpreter/CommandOptionArgumentTable.h" | |
17 #include "lldb/Interpreter/CommandReturnObject.h" | 18 #include "lldb/Interpreter/CommandReturnObject.h" |
18 #include "lldb/Interpreter/OptionArgParser.h" | 19 #include "lldb/Interpreter/OptionArgParser.h" |
19 #include "lldb/Interpreter/OptionValueFileColonLine.h" | 20 #include "lldb/Interpreter/OptionValueFileColonLine.h" |
20 #include "lldb/Interpreter/Options.h" | 21 #include "lldb/Interpreter/Options.h" |
21 #include "lldb/Symbol/CompileUnit.h" | 22 #include "lldb/Symbol/CompileUnit.h" |
34 #include "CommandOptions.inc" | 35 #include "CommandOptions.inc" |
35 | 36 |
36 class CommandObjectSourceInfo : public CommandObjectParsed { | 37 class CommandObjectSourceInfo : public CommandObjectParsed { |
37 class CommandOptions : public Options { | 38 class CommandOptions : public Options { |
38 public: | 39 public: |
39 CommandOptions() : Options() {} | 40 CommandOptions() = default; |
40 | 41 |
41 ~CommandOptions() override = default; | 42 ~CommandOptions() override = default; |
42 | 43 |
43 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, | 44 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, |
44 ExecutionContext *execution_context) override { | 45 ExecutionContext *execution_context) override { |
116 : CommandObjectParsed( | 117 : CommandObjectParsed( |
117 interpreter, "source info", | 118 interpreter, "source info", |
118 "Display source line information for the current target " | 119 "Display source line information for the current target " |
119 "process. Defaults to instruction pointer in current stack " | 120 "process. Defaults to instruction pointer in current stack " |
120 "frame.", | 121 "frame.", |
121 nullptr, eCommandRequiresTarget), | 122 nullptr, eCommandRequiresTarget) {} |
122 m_options() {} | |
123 | 123 |
124 ~CommandObjectSourceInfo() override = default; | 124 ~CommandObjectSourceInfo() override = default; |
125 | 125 |
126 Options *GetOptions() override { return &m_options; } | 126 Options *GetOptions() override { return &m_options; } |
127 | 127 |
372 ConstString name(m_options.symbol_name.c_str()); | 372 ConstString name(m_options.symbol_name.c_str()); |
373 SymbolContextList sc_list_lines; | 373 SymbolContextList sc_list_lines; |
374 Target *target = m_exe_ctx.GetTargetPtr(); | 374 Target *target = m_exe_ctx.GetTargetPtr(); |
375 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize(); | 375 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize(); |
376 | 376 |
377 ModuleFunctionSearchOptions function_options; | |
378 function_options.include_symbols = false; | |
379 function_options.include_inlines = true; | |
380 | |
377 // Note: module_list can't be const& because FindFunctionSymbols isn't | 381 // Note: module_list can't be const& because FindFunctionSymbols isn't |
378 // const. | 382 // const. |
379 ModuleList module_list = | 383 ModuleList module_list = |
380 (m_module_list.GetSize() > 0) ? m_module_list : target->GetImages(); | 384 (m_module_list.GetSize() > 0) ? m_module_list : target->GetImages(); |
381 module_list.FindFunctions(name, eFunctionNameTypeAuto, | 385 module_list.FindFunctions(name, eFunctionNameTypeAuto, function_options, |
382 /*include_symbols=*/false, | 386 sc_list_funcs); |
383 /*include_inlines=*/true, sc_list_funcs); | |
384 size_t num_matches = sc_list_funcs.GetSize(); | 387 size_t num_matches = sc_list_funcs.GetSize(); |
385 | 388 |
386 if (!num_matches) { | 389 if (!num_matches) { |
387 // If we didn't find any functions with that name, try searching for | 390 // If we didn't find any functions with that name, try searching for |
388 // symbols that line up exactly with function addresses. | 391 // symbols that line up exactly with function addresses. |
534 } | 537 } |
535 return true; | 538 return true; |
536 } | 539 } |
537 | 540 |
538 bool DoExecute(Args &command, CommandReturnObject &result) override { | 541 bool DoExecute(Args &command, CommandReturnObject &result) override { |
539 const size_t argc = command.GetArgumentCount(); | |
540 | |
541 if (argc != 0) { | |
542 result.AppendErrorWithFormat("'%s' takes no arguments, only flags.\n", | |
543 GetCommandName().str().c_str()); | |
544 return false; | |
545 } | |
546 | |
547 Target *target = m_exe_ctx.GetTargetPtr(); | 542 Target *target = m_exe_ctx.GetTargetPtr(); |
548 if (target == nullptr) { | 543 if (target == nullptr) { |
549 target = GetDebugger().GetSelectedTarget().get(); | 544 target = GetDebugger().GetSelectedTarget().get(); |
550 if (target == nullptr) { | 545 if (target == nullptr) { |
551 result.AppendError("invalid target, create a debug target using the " | 546 result.AppendError("invalid target, create a debug target using the " |
619 #include "CommandOptions.inc" | 614 #include "CommandOptions.inc" |
620 | 615 |
621 class CommandObjectSourceList : public CommandObjectParsed { | 616 class CommandObjectSourceList : public CommandObjectParsed { |
622 class CommandOptions : public Options { | 617 class CommandOptions : public Options { |
623 public: | 618 public: |
624 CommandOptions() : Options() {} | 619 CommandOptions() = default; |
625 | 620 |
626 ~CommandOptions() override = default; | 621 ~CommandOptions() override = default; |
627 | 622 |
628 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, | 623 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, |
629 ExecutionContext *execution_context) override { | 624 ExecutionContext *execution_context) override { |
718 public: | 713 public: |
719 CommandObjectSourceList(CommandInterpreter &interpreter) | 714 CommandObjectSourceList(CommandInterpreter &interpreter) |
720 : CommandObjectParsed(interpreter, "source list", | 715 : CommandObjectParsed(interpreter, "source list", |
721 "Display source code for the current target " | 716 "Display source code for the current target " |
722 "process as specified by options.", | 717 "process as specified by options.", |
723 nullptr, eCommandRequiresTarget), | 718 nullptr, eCommandRequiresTarget) {} |
724 m_options() {} | |
725 | 719 |
726 ~CommandObjectSourceList() override = default; | 720 ~CommandObjectSourceList() override = default; |
727 | 721 |
728 Options *GetOptions() override { return &m_options; } | 722 Options *GetOptions() override { return &m_options; } |
729 | 723 |
730 const char *GetRepeatCommand(Args ¤t_command_args, | 724 llvm::Optional<std::string> GetRepeatCommand(Args ¤t_command_args, |
731 uint32_t index) override { | 725 uint32_t index) override { |
732 // This is kind of gross, but the command hasn't been parsed yet so we | 726 // This is kind of gross, but the command hasn't been parsed yet so we |
733 // can't look at the option values for this invocation... I have to scan | 727 // can't look at the option values for this invocation... I have to scan |
734 // the arguments directly. | 728 // the arguments directly. |
735 auto iter = | 729 auto iter = |
736 llvm::find_if(current_command_args, [](const Args::ArgEntry &e) { | 730 llvm::find_if(current_command_args, [](const Args::ArgEntry &e) { |
737 return e.ref() == "-r" || e.ref() == "--reverse"; | 731 return e.ref() == "-r" || e.ref() == "--reverse"; |
738 }); | 732 }); |
739 if (iter == current_command_args.end()) | 733 if (iter == current_command_args.end()) |
740 return m_cmd_name.c_str(); | 734 return m_cmd_name; |
741 | 735 |
742 if (m_reverse_name.empty()) { | 736 if (m_reverse_name.empty()) { |
743 m_reverse_name = m_cmd_name; | 737 m_reverse_name = m_cmd_name; |
744 m_reverse_name.append(" -r"); | 738 m_reverse_name.append(" -r"); |
745 } | 739 } |
746 return m_reverse_name.c_str(); | 740 return m_reverse_name; |
747 } | 741 } |
748 | 742 |
749 protected: | 743 protected: |
750 struct SourceInfo { | 744 struct SourceInfo { |
751 ConstString function; | 745 ConstString function; |
752 LineEntry line_entry; | 746 LineEntry line_entry; |
753 | 747 |
754 SourceInfo(ConstString name, const LineEntry &line_entry) | 748 SourceInfo(ConstString name, const LineEntry &line_entry) |
755 : function(name), line_entry(line_entry) {} | 749 : function(name), line_entry(line_entry) {} |
756 | 750 |
757 SourceInfo() : function(), line_entry() {} | 751 SourceInfo() = default; |
758 | 752 |
759 bool IsValid() const { return (bool)function && line_entry.IsValid(); } | 753 bool IsValid() const { return (bool)function && line_entry.IsValid(); } |
760 | 754 |
761 bool operator==(const SourceInfo &rhs) const { | 755 bool operator==(const SourceInfo &rhs) const { |
762 return function == rhs.function && | 756 return function == rhs.function && |
872 // passed to the various ModuleList::Find* calls, which would either be a | 866 // passed to the various ModuleList::Find* calls, which would either be a |
873 // vector of string names or a ModuleSpecList. | 867 // vector of string names or a ModuleSpecList. |
874 void FindMatchingFunctions(Target *target, ConstString name, | 868 void FindMatchingFunctions(Target *target, ConstString name, |
875 SymbolContextList &sc_list) { | 869 SymbolContextList &sc_list) { |
876 // Displaying the source for a symbol: | 870 // Displaying the source for a symbol: |
877 bool include_inlines = true; | |
878 bool include_symbols = false; | |
879 | |
880 if (m_options.num_lines == 0) | 871 if (m_options.num_lines == 0) |
881 m_options.num_lines = 10; | 872 m_options.num_lines = 10; |
873 | |
874 ModuleFunctionSearchOptions function_options; | |
875 function_options.include_symbols = true; | |
876 function_options.include_inlines = false; | |
882 | 877 |
883 const size_t num_modules = m_options.modules.size(); | 878 const size_t num_modules = m_options.modules.size(); |
884 if (num_modules > 0) { | 879 if (num_modules > 0) { |
885 ModuleList matching_modules; | 880 ModuleList matching_modules; |
886 for (size_t i = 0; i < num_modules; ++i) { | 881 for (size_t i = 0; i < num_modules; ++i) { |
887 FileSpec module_file_spec(m_options.modules[i]); | 882 FileSpec module_file_spec(m_options.modules[i]); |
888 if (module_file_spec) { | 883 if (module_file_spec) { |
889 ModuleSpec module_spec(module_file_spec); | 884 ModuleSpec module_spec(module_file_spec); |
890 matching_modules.Clear(); | 885 matching_modules.Clear(); |
891 target->GetImages().FindModules(module_spec, matching_modules); | 886 target->GetImages().FindModules(module_spec, matching_modules); |
887 | |
892 matching_modules.FindFunctions(name, eFunctionNameTypeAuto, | 888 matching_modules.FindFunctions(name, eFunctionNameTypeAuto, |
893 include_symbols, include_inlines, | 889 function_options, sc_list); |
894 sc_list); | |
895 } | 890 } |
896 } | 891 } |
897 } else { | 892 } else { |
898 target->GetImages().FindFunctions(name, eFunctionNameTypeAuto, | 893 target->GetImages().FindFunctions(name, eFunctionNameTypeAuto, |
899 include_symbols, include_inlines, | 894 function_options, sc_list); |
900 sc_list); | |
901 } | 895 } |
902 } | 896 } |
903 | 897 |
904 void FindMatchingFunctionSymbols(Target *target, ConstString name, | 898 void FindMatchingFunctionSymbols(Target *target, ConstString name, |
905 SymbolContextList &sc_list) { | 899 SymbolContextList &sc_list) { |
921 sc_list); | 915 sc_list); |
922 } | 916 } |
923 } | 917 } |
924 | 918 |
925 bool DoExecute(Args &command, CommandReturnObject &result) override { | 919 bool DoExecute(Args &command, CommandReturnObject &result) override { |
926 const size_t argc = command.GetArgumentCount(); | |
927 | |
928 if (argc != 0) { | |
929 result.AppendErrorWithFormat("'%s' takes no arguments, only flags.\n", | |
930 GetCommandName().str().c_str()); | |
931 return false; | |
932 } | |
933 | |
934 Target *target = m_exe_ctx.GetTargetPtr(); | 920 Target *target = m_exe_ctx.GetTargetPtr(); |
935 | 921 |
936 if (!m_options.symbol_name.empty()) { | 922 if (!m_options.symbol_name.empty()) { |
937 SymbolContextList sc_list; | 923 SymbolContextList sc_list; |
938 ConstString name(m_options.symbol_name.c_str()); | 924 ConstString name(m_options.symbol_name.c_str()); |