1*e8d8bef9SDimitry Andric //===-- CommandObjectTraceStartIntelPT.cpp --------------------------------===// 2*e8d8bef9SDimitry Andric // 3*e8d8bef9SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*e8d8bef9SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*e8d8bef9SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*e8d8bef9SDimitry Andric // 7*e8d8bef9SDimitry Andric //===----------------------------------------------------------------------===// 8*e8d8bef9SDimitry Andric 9*e8d8bef9SDimitry Andric #include "CommandObjectTraceStartIntelPT.h" 10*e8d8bef9SDimitry Andric 11*e8d8bef9SDimitry Andric #include "lldb/Host/OptionParser.h" 12*e8d8bef9SDimitry Andric #include "lldb/Target/Trace.h" 13*e8d8bef9SDimitry Andric 14*e8d8bef9SDimitry Andric using namespace lldb; 15*e8d8bef9SDimitry Andric using namespace lldb_private; 16*e8d8bef9SDimitry Andric using namespace lldb_private::trace_intel_pt; 17*e8d8bef9SDimitry Andric using namespace llvm; 18*e8d8bef9SDimitry Andric 19*e8d8bef9SDimitry Andric #define LLDB_OPTIONS_thread_trace_start_intel_pt 20*e8d8bef9SDimitry Andric #include "TraceIntelPTCommandOptions.inc" 21*e8d8bef9SDimitry Andric 22*e8d8bef9SDimitry Andric Status CommandObjectTraceStartIntelPT::CommandOptions::SetOptionValue( 23*e8d8bef9SDimitry Andric uint32_t option_idx, llvm::StringRef option_arg, 24*e8d8bef9SDimitry Andric ExecutionContext *execution_context) { 25*e8d8bef9SDimitry Andric Status error; 26*e8d8bef9SDimitry Andric const int short_option = m_getopt_table[option_idx].val; 27*e8d8bef9SDimitry Andric 28*e8d8bef9SDimitry Andric switch (short_option) { 29*e8d8bef9SDimitry Andric case 's': { 30*e8d8bef9SDimitry Andric int32_t size_in_kb; 31*e8d8bef9SDimitry Andric if (option_arg.empty() || option_arg.getAsInteger(0, size_in_kb) || 32*e8d8bef9SDimitry Andric size_in_kb < 0) 33*e8d8bef9SDimitry Andric error.SetErrorStringWithFormat("invalid integer value for option '%s'", 34*e8d8bef9SDimitry Andric option_arg.str().c_str()); 35*e8d8bef9SDimitry Andric else 36*e8d8bef9SDimitry Andric m_size_in_kb = size_in_kb; 37*e8d8bef9SDimitry Andric break; 38*e8d8bef9SDimitry Andric } 39*e8d8bef9SDimitry Andric case 'c': { 40*e8d8bef9SDimitry Andric int32_t custom_config; 41*e8d8bef9SDimitry Andric if (option_arg.empty() || option_arg.getAsInteger(0, custom_config) || 42*e8d8bef9SDimitry Andric custom_config < 0) 43*e8d8bef9SDimitry Andric error.SetErrorStringWithFormat("invalid integer value for option '%s'", 44*e8d8bef9SDimitry Andric option_arg.str().c_str()); 45*e8d8bef9SDimitry Andric else 46*e8d8bef9SDimitry Andric m_custom_config = custom_config; 47*e8d8bef9SDimitry Andric break; 48*e8d8bef9SDimitry Andric } 49*e8d8bef9SDimitry Andric default: 50*e8d8bef9SDimitry Andric llvm_unreachable("Unimplemented option"); 51*e8d8bef9SDimitry Andric } 52*e8d8bef9SDimitry Andric return error; 53*e8d8bef9SDimitry Andric } 54*e8d8bef9SDimitry Andric 55*e8d8bef9SDimitry Andric void CommandObjectTraceStartIntelPT::CommandOptions::OptionParsingStarting( 56*e8d8bef9SDimitry Andric ExecutionContext *execution_context) { 57*e8d8bef9SDimitry Andric m_size_in_kb = 4; 58*e8d8bef9SDimitry Andric m_custom_config = 0; 59*e8d8bef9SDimitry Andric } 60*e8d8bef9SDimitry Andric 61*e8d8bef9SDimitry Andric llvm::ArrayRef<OptionDefinition> 62*e8d8bef9SDimitry Andric CommandObjectTraceStartIntelPT::CommandOptions::GetDefinitions() { 63*e8d8bef9SDimitry Andric return llvm::makeArrayRef(g_thread_trace_start_intel_pt_options); 64*e8d8bef9SDimitry Andric } 65*e8d8bef9SDimitry Andric 66*e8d8bef9SDimitry Andric bool CommandObjectTraceStartIntelPT::HandleOneThread( 67*e8d8bef9SDimitry Andric lldb::tid_t tid, CommandReturnObject &result) { 68*e8d8bef9SDimitry Andric result.AppendMessageWithFormat( 69*e8d8bef9SDimitry Andric "would trace tid %" PRIu64 " with size_in_kb %zu and custom_config %d\n", 70*e8d8bef9SDimitry Andric tid, m_options.m_size_in_kb, m_options.m_custom_config); 71*e8d8bef9SDimitry Andric result.SetStatus(eReturnStatusSuccessFinishResult); 72*e8d8bef9SDimitry Andric return result.Succeeded(); 73*e8d8bef9SDimitry Andric } 74