Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7ff1a79

Browse files
committedMay 26, 2017
Implementation of remote packets for Trace data.
Summary: The changes consist of new packets for trace manipulation and trace collection. The new packets are also documented. The packets are capable of providing custom trace specific parameters to start tracing and also retrieve such configuration from the server. Reviewers: clayborg, lldb-commits, tberghammer, labath, zturner Reviewed By: clayborg, labath Subscribers: krytarowski, lldb-commits Differential Revision: https://reviews.llvm.org/D32585 git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@303972 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 5a45a61 commit 7ff1a79

18 files changed

+1067
-44
lines changed
 

‎docs/lldb-gdb-remote.txt

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,163 @@ This packet must be sent _prior_ to sending a "A" packet.
208208
send packet: QListThreadsInStopReply
209209
read packet: OK
210210

211+
//----------------------------------------------------------------------
212+
// jTraceStart:
213+
//
214+
// BRIEF
215+
// Packet for starting trace of type lldb::TraceType. The following
216+
// parameters should be appended to the packet formatted as a JSON
217+
// dictionary, where the schematic for the JSON dictionary in terms of
218+
// the recognized Keys is given below in the table.
219+
// Different tracing types could require different custom parameters.
220+
// Such custom tracing parameters if needed should be collectively
221+
// specified in a JSON dictionary and the dictionary can be appended
222+
// to this packet (as Value corresponding to "params"). Since sending
223+
// JSON data over gdb-remote protocol has certain limitations, binary
224+
// escaping convention should be used.
225+
//
226+
// Following is the list of parameters -
227+
//
228+
// Key Value (Integer) (O)Optional/
229+
// (except params which should be a (M)Mandatory
230+
// JSON dictionary)
231+
// ========== ====================================================
232+
//
233+
// type The type of trace to start (see M
234+
// lldb-enumerations for TraceType)
235+
//
236+
// buffersize The size of the buffer to allocate M
237+
// for trace gathering.
238+
//
239+
// threadid The id of the thread to start tracing O
240+
// on.
241+
//
242+
// metabuffersize The size of buffer to hold meta data O
243+
// used for decoding the trace data.
244+
//
245+
// params Any parameters that are specific to O
246+
// certain trace technologies should be
247+
// collectively specified as a JSON
248+
// dictionary
249+
// ========== ====================================================
250+
//
251+
// Each tracing instance is identified by a trace id which is returned
252+
// as the reply to this packet. In case the tracing failed to begin an
253+
// error code is returned instead.
254+
//----------------------------------------------------------------------
255+
256+
send packet: jTraceStart:{"type":<type>,"buffersize":<buffersize>}]
257+
read packet: <trace id>/E<error code>
258+
259+
//----------------------------------------------------------------------
260+
// jTraceStop:
261+
//
262+
// BRIEF
263+
// Stop tracing instance with trace id <trace id>, of course trace
264+
// needs to be started before. The following parameters should be
265+
// formatted as a JSON dictionary to the packet. Since sending
266+
// JSON data over gdb-remote protocol has certain limitations, binary
267+
// escaping convention should be used.
268+
//
269+
// Following is the list of parameters -
270+
//
271+
// Key Value (Integer) (O)Optional/
272+
// (M)Mandatory
273+
// ========== ====================================================
274+
//
275+
// traceid The trace id of the tracing instance M
276+
//
277+
// threadid The id of the thread to stop tracing O
278+
// on. Since <trace id> could map to
279+
// multiple trace instances (in case it
280+
// maps to the complete process), the
281+
// threadid of a particular thread could
282+
// be appended as "threadid:<thread id>;"
283+
// to stop tracing on that thread.
284+
// ========== ====================================================
285+
//
286+
// An OK response is sent in case of success else an error code is
287+
// returned.
288+
//----------------------------------------------------------------------
289+
290+
send packet: jTraceStop:{"traceid":<trace id>}]
291+
read packet: <OK response>/E<error code>
292+
293+
//----------------------------------------------------------------------
294+
// jTraceBufferRead:
295+
//
296+
// BRIEF
297+
// Packet for reading the trace for tracing instance <trace id>, i.e the
298+
// id obtained from StartTrace API. The following parameters should be
299+
// formatted as a JSON dictionary to the packet. Since sending
300+
// JSON data over gdb-remote protocol has certain limitations, binary
301+
// escaping convention should be used.
302+
//
303+
// Following is the list of parameters -
304+
//
305+
// Key Value (Integer) (O)Optional/
306+
// (M)Mandatory
307+
// ========== ====================================================
308+
// traceid The trace id of the tracing instance M
309+
//
310+
// offset The offset to start reading the data M
311+
// from.
312+
//
313+
// buffersize The size of the data intended to read. M
314+
//
315+
// threadid The id of the thread to retrieve data O
316+
// from.
317+
// ========== ====================================================
318+
//
319+
// The trace data is sent as raw binary data if the read was successful
320+
// else an error code is sent.
321+
//----------------------------------------------------------------------
322+
323+
send packet: jTraceBufferRead:{"traceid":<trace id>,"offset":<byteoffset>,"buffersize":<byte_count>}]
324+
read packet: <binary trace data>/E<error code>
325+
326+
//----------------------------------------------------------------------
327+
// jTraceMetaRead:
328+
//
329+
// BRIEF
330+
// Similar Packet as above except it reads meta data.
331+
//----------------------------------------------------------------------
332+
333+
/----------------------------------------------------------------------
334+
// jTraceConfigRead:
335+
//
336+
// BRIEF
337+
// Request the trace configuration for the tracing instance with id
338+
// <trace id>.
339+
//
340+
// Following is the list of parameters -
341+
//
342+
// Key Value (Integer) (O)Optional/
343+
// (M)Mandatory
344+
// ========== ====================================================
345+
// traceid The trace id of the tracing instance M
346+
//
347+
// threadid The id of the thread to obtain trace O
348+
// configuration from. Since <trace id>
349+
// could map to multiple trace instances
350+
// (in case it maps to the complete
351+
// process), the threadid of a particular
352+
// thread could be appended as
353+
// "threadid:<thread id>;" to obtain the
354+
// trace configuration of that thread.
355+
// ========== ====================================================
356+
//
357+
// In the response packet the trace configuration is sent as text,
358+
// formatted as a JSON dictionary. Since sending JSON data over
359+
// gdb-remote protocol has certain limitations, binary escaping
360+
// convention is used.
361+
// In case the trace instance with the <trace id> was not found, an
362+
// error code is returned.
363+
//----------------------------------------------------------------------
364+
365+
send packet: jTraceConfigRead:{"traceid":<trace id>}
366+
read packet: {"conf1":<conf1>,"conf2":<conf2>,"params":{"paramName":paramValue}]}];/E<error code>
367+
211368
//----------------------------------------------------------------------
212369
// "qRegisterInfo<hex-reg-id>"
213370
//

‎include/lldb/API/SBTrace.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class LLDB_API SBTrace {
4040
///
4141
/// @param[in] thread_id
4242
/// Tracing could be started for the complete process or a
43-
/// single thread, in the first case the uid obtained would
43+
/// single thread, in the first case the traceid obtained would
4444
/// map to all the threads existing within the process and the
4545
/// ones spawning later. The thread_id parameter can be used in
4646
/// such a scenario to select the trace data for a specific
@@ -68,16 +68,17 @@ class LLDB_API SBTrace {
6868
/// An error explaining what went wrong.
6969
///
7070
/// @param[in] thread_id
71-
/// The user id could map to a tracing instance for a thread
71+
/// The trace id could map to a tracing instance for a thread
7272
/// or could also map to a group of threads being traced with
7373
/// the same trace options. A thread_id is normally optional
7474
/// except in the case of tracing a complete process and tracing
7575
/// needs to switched off on a particular thread.
7676
/// A situation could occur where initially a thread (lets say
77-
/// thread A) is being individually traced with a particular uid
78-
/// and then tracing is started on the complete process, in this
79-
/// case thread A will continue without any change. All newly
80-
/// spawned threads would be traced with the uid of the process.
77+
/// thread A) is being individually traced with a particular
78+
/// trace id and then tracing is started on the complete
79+
/// process, in this case thread A will continue without any
80+
/// change. All newly spawned threads would be traced with the
81+
/// trace id of the process.
8182
/// Now if the StopTrace API is called for the whole process,
8283
/// thread A will not be stopped and must be stopped separately.
8384
//------------------------------------------------------------------

‎include/lldb/Core/TraceOptions.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
namespace lldb_private {
1919
class TraceOptions {
2020
public:
21-
TraceOptions()
22-
: m_trace_params(new StructuredData::Dictionary()) {}
21+
TraceOptions() : m_trace_params(new StructuredData::Dictionary()) {}
2322

2423
const StructuredData::DictionarySP &getTraceParams() const {
2524
return m_trace_params;
@@ -43,7 +42,7 @@ class TraceOptions {
4342

4443
void setThreadID(lldb::tid_t thread_id) { m_thread_id = thread_id; }
4544

46-
lldb::tid_t getThreadID() { return m_thread_id; }
45+
lldb::tid_t getThreadID() const { return m_thread_id; }
4746

4847
private:
4948
lldb::TraceType m_type;

‎include/lldb/Host/common/NativeProcessProtocol.h

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#ifndef liblldb_NativeProcessProtocol_h_
1111
#define liblldb_NativeProcessProtocol_h_
1212

13+
#include "lldb/Core/TraceOptions.h"
1314
#include "lldb/Host/MainLoop.h"
1415
#include "lldb/Utility/Status.h"
1516
#include "lldb/lldb-private-forward.h"
@@ -308,6 +309,108 @@ class NativeProcessProtocol
308309
static Status Attach(lldb::pid_t pid, NativeDelegate &native_delegate,
309310
MainLoop &mainloop, NativeProcessProtocolSP &process_sp);
310311

312+
//------------------------------------------------------------------
313+
/// StartTracing API for starting a tracing instance with the
314+
/// TraceOptions on a specific thread or process.
315+
///
316+
/// @param[in] config
317+
/// The configuration to use when starting tracing.
318+
///
319+
/// @param[out] error
320+
/// Status indicates what went wrong.
321+
///
322+
/// @return
323+
/// The API returns a user_id which can be used to get trace
324+
/// data, trace configuration or stopping the trace instance.
325+
/// The user_id is a key to identify and operate with a tracing
326+
/// instance. It may refer to the complete process or a single
327+
/// thread.
328+
//------------------------------------------------------------------
329+
virtual lldb::user_id_t StartTrace(const TraceOptions &config,
330+
Status &error) {
331+
error.SetErrorString("Not implemented");
332+
return LLDB_INVALID_UID;
333+
}
334+
335+
//------------------------------------------------------------------
336+
/// StopTracing API as the name suggests stops a tracing instance.
337+
///
338+
/// @param[in] uid
339+
/// The user id of the trace intended to be stopped. Now a
340+
/// user_id may map to multiple threads in which case this API
341+
/// could be used to stop the tracing for a specific thread by
342+
/// supplying its thread id.
343+
///
344+
/// @param[in] thread
345+
/// Thread is needed when the complete process is being traced
346+
/// and the user wishes to stop tracing on a particular thread.
347+
///
348+
/// @return
349+
/// Status indicating what went wrong.
350+
//------------------------------------------------------------------
351+
virtual Status StopTrace(lldb::user_id_t uid,
352+
lldb::tid_t thread = LLDB_INVALID_THREAD_ID) {
353+
return Status("Not implemented");
354+
}
355+
356+
//------------------------------------------------------------------
357+
/// This API provides the trace data collected in the form of raw
358+
/// data.
359+
///
360+
/// @param[in] uid thread
361+
/// The uid and thread provide the context for the trace
362+
/// instance.
363+
///
364+
/// @param[in] buffer
365+
/// The buffer provides the destination buffer where the trace
366+
/// data would be read to. The buffer should be truncated to the
367+
/// filled length by this function.
368+
///
369+
/// @param[in] offset
370+
/// There is possibility to read partially the trace data from
371+
/// a specified offset where in such cases the buffer provided
372+
/// may be smaller than the internal trace collection container.
373+
///
374+
/// @return
375+
/// The size of the data actually read.
376+
//------------------------------------------------------------------
377+
virtual Status GetData(lldb::user_id_t uid, lldb::tid_t thread,
378+
llvm::MutableArrayRef<uint8_t> &buffer,
379+
size_t offset = 0) {
380+
return Status("Not implemented");
381+
}
382+
383+
//------------------------------------------------------------------
384+
/// Similar API as above except it aims to provide any extra data
385+
/// useful for decoding the actual trace data.
386+
//------------------------------------------------------------------
387+
virtual Status GetMetaData(lldb::user_id_t uid, lldb::tid_t thread,
388+
llvm::MutableArrayRef<uint8_t> &buffer,
389+
size_t offset = 0) {
390+
return Status("Not implemented");
391+
}
392+
393+
//------------------------------------------------------------------
394+
/// API to query the TraceOptions for a given user id
395+
///
396+
/// @param[in] uid
397+
/// The user id of the tracing instance.
398+
///
399+
/// @param[in] config
400+
/// The thread id of the tracing instance, in case configuration
401+
/// for a specific thread is needed should be specified in the
402+
/// config.
403+
///
404+
/// @param[out] error
405+
/// Status indicates what went wrong.
406+
///
407+
/// @param[out] config
408+
/// The actual configuration being used for tracing.
409+
//------------------------------------------------------------------
410+
virtual Status GetTraceConfig(lldb::user_id_t uid, TraceOptions &config) {
411+
return Status("Not implemented");
412+
}
413+
311414
protected:
312415
lldb::pid_t m_pid;
313416

@@ -381,6 +484,6 @@ class NativeProcessProtocol
381484
private:
382485
void SynchronouslyNotifyProcessStateChanged(lldb::StateType state);
383486
};
384-
}
487+
} // namespace lldb_private
385488

386489
#endif // #ifndef liblldb_NativeProcessProtocol_h_

0 commit comments

Comments
 (0)
This repository has been archived.