1*fe013be4SDimitry Andric //===-- CommandOptionsProcessAttach.cpp -----------------------------------===// 2*fe013be4SDimitry Andric // 3*fe013be4SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*fe013be4SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*fe013be4SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*fe013be4SDimitry Andric // 7*fe013be4SDimitry Andric //===----------------------------------------------------------------------===// 8*fe013be4SDimitry Andric 9*fe013be4SDimitry Andric #include "CommandOptionsProcessAttach.h" 10*fe013be4SDimitry Andric 11*fe013be4SDimitry Andric #include "lldb/Host/FileSystem.h" 12*fe013be4SDimitry Andric #include "lldb/Host/HostInfo.h" 13*fe013be4SDimitry Andric #include "lldb/Host/OptionParser.h" 14*fe013be4SDimitry Andric #include "lldb/Interpreter/CommandCompletions.h" 15*fe013be4SDimitry Andric #include "lldb/Interpreter/CommandObject.h" 16*fe013be4SDimitry Andric #include "lldb/Interpreter/CommandOptionArgumentTable.h" 17*fe013be4SDimitry Andric #include "lldb/Interpreter/OptionArgParser.h" 18*fe013be4SDimitry Andric #include "lldb/Target/ExecutionContext.h" 19*fe013be4SDimitry Andric #include "lldb/Target/Platform.h" 20*fe013be4SDimitry Andric #include "lldb/Target/Target.h" 21*fe013be4SDimitry Andric 22*fe013be4SDimitry Andric #include "llvm/ADT/ArrayRef.h" 23*fe013be4SDimitry Andric 24*fe013be4SDimitry Andric using namespace llvm; 25*fe013be4SDimitry Andric using namespace lldb; 26*fe013be4SDimitry Andric using namespace lldb_private; 27*fe013be4SDimitry Andric 28*fe013be4SDimitry Andric #define LLDB_OPTIONS_process_attach 29*fe013be4SDimitry Andric #include "CommandOptions.inc" 30*fe013be4SDimitry Andric SetOptionValue(uint32_t option_idx,llvm::StringRef option_arg,ExecutionContext * execution_context)31*fe013be4SDimitry AndricStatus CommandOptionsProcessAttach::SetOptionValue( 32*fe013be4SDimitry Andric uint32_t option_idx, llvm::StringRef option_arg, 33*fe013be4SDimitry Andric ExecutionContext *execution_context) { 34*fe013be4SDimitry Andric Status error; 35*fe013be4SDimitry Andric const int short_option = g_process_attach_options[option_idx].short_option; 36*fe013be4SDimitry Andric switch (short_option) { 37*fe013be4SDimitry Andric case 'c': 38*fe013be4SDimitry Andric attach_info.SetContinueOnceAttached(true); 39*fe013be4SDimitry Andric break; 40*fe013be4SDimitry Andric 41*fe013be4SDimitry Andric case 'p': { 42*fe013be4SDimitry Andric lldb::pid_t pid; 43*fe013be4SDimitry Andric if (option_arg.getAsInteger(0, pid)) { 44*fe013be4SDimitry Andric error.SetErrorStringWithFormat("invalid process ID '%s'", 45*fe013be4SDimitry Andric option_arg.str().c_str()); 46*fe013be4SDimitry Andric } else { 47*fe013be4SDimitry Andric attach_info.SetProcessID(pid); 48*fe013be4SDimitry Andric } 49*fe013be4SDimitry Andric } break; 50*fe013be4SDimitry Andric 51*fe013be4SDimitry Andric case 'P': 52*fe013be4SDimitry Andric attach_info.SetProcessPluginName(option_arg); 53*fe013be4SDimitry Andric break; 54*fe013be4SDimitry Andric 55*fe013be4SDimitry Andric case 'n': 56*fe013be4SDimitry Andric attach_info.GetExecutableFile().SetFile(option_arg, 57*fe013be4SDimitry Andric FileSpec::Style::native); 58*fe013be4SDimitry Andric break; 59*fe013be4SDimitry Andric 60*fe013be4SDimitry Andric case 'w': 61*fe013be4SDimitry Andric attach_info.SetWaitForLaunch(true); 62*fe013be4SDimitry Andric break; 63*fe013be4SDimitry Andric 64*fe013be4SDimitry Andric case 'i': 65*fe013be4SDimitry Andric attach_info.SetIgnoreExisting(false); 66*fe013be4SDimitry Andric break; 67*fe013be4SDimitry Andric 68*fe013be4SDimitry Andric default: 69*fe013be4SDimitry Andric llvm_unreachable("Unimplemented option"); 70*fe013be4SDimitry Andric } 71*fe013be4SDimitry Andric return error; 72*fe013be4SDimitry Andric } 73*fe013be4SDimitry Andric GetDefinitions()74*fe013be4SDimitry Andricllvm::ArrayRef<OptionDefinition> CommandOptionsProcessAttach::GetDefinitions() { 75*fe013be4SDimitry Andric return llvm::ArrayRef(g_process_attach_options); 76*fe013be4SDimitry Andric } 77