diff --git a/lldb/test/API/tools/intel-features/intel-pt/test/TestIntelPTSimpleBinary.py b/lldb/test/API/tools/intel-features/intel-pt/test/TestIntelPTSimpleBinary.py --- a/lldb/test/API/tools/intel-features/intel-pt/test/TestIntelPTSimpleBinary.py +++ b/lldb/test/API/tools/intel-features/intel-pt/test/TestIntelPTSimpleBinary.py @@ -102,17 +102,8 @@ tid = process.GetProcessID() # We configure the tracing options - trace_opts = lldb.SBTraceOptions() + trace_opts = lldbIntelFeatures.PTDecoder.GetDefaultTraceOptions() trace_opts.setThreadID(tid) - trace_opts.setType(lldb.eTraceTypeProcessorTrace) - trace_opts.setMetaDataBufferSize(0) - trace_opts.setTraceBufferSize(4096) - - stream = lldb.SBStream() - stream.Print('{"trace-tech":"intel-pt"}') - custom_params = lldb.SBStructuredData() - self.assertSuccess(custom_params.SetFromJSON(stream)) - trace_opts.setTraceParams(custom_params) # We start tracing error = lldb.SBError() diff --git a/lldb/tools/intel-features/intel-pt/Decoder.h b/lldb/tools/intel-features/intel-pt/Decoder.h --- a/lldb/tools/intel-features/intel-pt/Decoder.h +++ b/lldb/tools/intel-features/intel-pt/Decoder.h @@ -171,6 +171,8 @@ void GetProcessorTraceInfo(lldb::SBProcess &sbprocess, lldb::tid_t tid, TraceOptions &traceinfo, lldb::SBError &sberror); + static lldb::SBTraceOptions GetDefaultTraceOptions(); + private: class ThreadTraceInfo; typedef std::vector Buffer; diff --git a/lldb/tools/intel-features/intel-pt/Decoder.cpp b/lldb/tools/intel-features/intel-pt/Decoder.cpp --- a/lldb/tools/intel-features/intel-pt/Decoder.cpp +++ b/lldb/tools/intel-features/intel-pt/Decoder.cpp @@ -958,3 +958,19 @@ return; } } + +lldb::SBTraceOptions Decoder::GetDefaultTraceOptions() { + lldb::SBTraceOptions trace_opts; + trace_opts.setThreadID(LLDB_INVALID_THREAD_ID); + trace_opts.setType(lldb::TraceType::eTraceTypeProcessorTrace); + trace_opts.setTraceBufferSize(4096); // 1 page + trace_opts.setMetaDataBufferSize(0); + + lldb::SBStream sb_stream; + sb_stream.Printf("{\"trace-tech\":\"intel-pt\"}"); + lldb::SBStructuredData custom_params; + custom_params.SetFromJSON(sb_stream); + trace_opts.setTraceParams(custom_params); + + return trace_opts; +} diff --git a/lldb/tools/intel-features/intel-pt/PTDecoder.h b/lldb/tools/intel-features/intel-pt/PTDecoder.h --- a/lldb/tools/intel-features/intel-pt/PTDecoder.h +++ b/lldb/tools/intel-features/intel-pt/PTDecoder.h @@ -262,6 +262,19 @@ void GetProcessorTraceInfo(lldb::SBProcess &sbprocess, lldb::tid_t tid, PTTraceOptions &options, lldb::SBError &sberror); + /// Get an instance of an \a lldb::SBTraceOptions object with a default + /// configuration for tracing with Intel(R) Processor Trace. This object + /// is ready to be passed as argument to \a PTDecoder::StartProcessorTrace. + /// + /// The default configuration sets 4096 bytes as trace buffer size per thread. + /// Besides, this configuration traces all the running threads of the target + /// process. + /// + /// \return + /// An \a lldb::SBTraceOptions object with a default tracing + /// configuration. + static lldb::SBTraceOptions GetDefaultTraceOptions(); + private: std::shared_ptr m_opaque_sp; }; diff --git a/lldb/tools/intel-features/intel-pt/PTDecoder.cpp b/lldb/tools/intel-features/intel-pt/PTDecoder.cpp --- a/lldb/tools/intel-features/intel-pt/PTDecoder.cpp +++ b/lldb/tools/intel-features/intel-pt/PTDecoder.cpp @@ -147,3 +147,7 @@ options.SetSP(trace_options_ptr); } + +lldb::SBTraceOptions PTDecoder::GetDefaultTraceOptions() { + return Decoder::GetDefaultTraceOptions(); +} diff --git a/lldb/tools/intel-features/intel-pt/cli-wrapper-pt.cpp b/lldb/tools/intel-features/intel-pt/cli-wrapper-pt.cpp --- a/lldb/tools/intel-features/intel-pt/cli-wrapper-pt.cpp +++ b/lldb/tools/intel-features/intel-pt/cli-wrapper-pt.cpp @@ -136,8 +136,9 @@ return false; // Default initialize API's arguments - lldb::SBTraceOptions lldb_SBTraceOptions; - uint32_t trace_buffer_size = m_default_trace_buff_size; + lldb::SBTraceOptions lldb_SBTraceOptions = + ptdecoder::PTDecoder::GetDefaultTraceOptions(); + uint32_t trace_buffer_size = lldb_SBTraceOptions.getTraceBufferSize(); lldb::tid_t thread_id; // Parse Command line options @@ -169,22 +170,11 @@ trace_buffer_size = m_max_trace_buff_size; // Set API's arguments with parsed values - lldb_SBTraceOptions.setType(lldb::TraceType::eTraceTypeProcessorTrace); lldb_SBTraceOptions.setTraceBufferSize(trace_buffer_size); - lldb_SBTraceOptions.setMetaDataBufferSize(0); lldb_SBTraceOptions.setThreadID(thread_id); - lldb::SBStream sb_stream; - sb_stream.Printf("{\"trace-tech\":\"intel-pt\"}"); - lldb::SBStructuredData custom_params; - lldb::SBError error = custom_params.SetFromJSON(sb_stream); - if (!error.Success()) { - result.Printf("error: %s\n", error.GetCString()); - result.SetStatus(lldb::eReturnStatusFailed); - return false; - } - lldb_SBTraceOptions.setTraceParams(custom_params); // Start trace + lldb::SBError error; pt_decoder_sp->StartProcessorTrace(process, lldb_SBTraceOptions, error); if (!error.Success()) { result.Printf("error: %s\n", error.GetCString()); @@ -198,7 +188,6 @@ private: std::shared_ptr pt_decoder_sp; const uint32_t m_max_trace_buff_size = 0x3fff; - const uint32_t m_default_trace_buff_size = 4096; }; class ProcessorTraceInfo : public lldb::SBCommandPluginInterface {