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