1 //===-- CommandObjectThreadTraceExportCTF.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 "CommandObjectThreadTraceExportCTF.h" 10 11 #include "lldb/Host/OptionParser.h" 12 13 using namespace lldb; 14 using namespace lldb_private; 15 using namespace lldb_private::ctf; 16 using namespace llvm; 17 18 // CommandObjectThreadTraceExportCTF 19 20 #define LLDB_OPTIONS_thread_trace_export_ctf 21 #include "TraceExporterCTFCommandOptions.inc" 22 23 Status CommandObjectThreadTraceExportCTF::CommandOptions::SetOptionValue( 24 uint32_t option_idx, llvm::StringRef option_arg, 25 ExecutionContext *execution_context) { 26 Status error; 27 const int short_option = m_getopt_table[option_idx].val; 28 29 switch (short_option) { 30 case 't': { 31 int64_t thread_index; 32 if (option_arg.empty() || option_arg.getAsInteger(0, thread_index) || 33 thread_index < 0) 34 error.SetErrorStringWithFormat("invalid integer value for option '%s'", 35 option_arg.str().c_str()); 36 else 37 m_thread_index = thread_index; 38 break; 39 } 40 default: 41 llvm_unreachable("Unimplemented option"); 42 } 43 return error; 44 } 45 46 void CommandObjectThreadTraceExportCTF::CommandOptions::OptionParsingStarting( 47 ExecutionContext *execution_context) { 48 m_thread_index = None; 49 } 50 51 llvm::ArrayRef<OptionDefinition> 52 CommandObjectThreadTraceExportCTF::CommandOptions::GetDefinitions() { 53 return llvm::makeArrayRef(g_thread_trace_export_ctf_options); 54 } 55 56 bool CommandObjectThreadTraceExportCTF::DoExecute(Args &command, 57 CommandReturnObject &result) { 58 Stream &s = result.GetOutputStream(); 59 // TODO: create an actual instance of the exporter and invoke it 60 if (m_options.m_thread_index) 61 s.Printf("got thread index %d\n", (int)m_options.m_thread_index.getValue()); 62 else 63 s.Printf("didn't get a thread index\n"); 64 65 return result.Succeeded(); 66 } 67