[trace] [intel pt] Create a "process trace save" command
authorWalter Erquinigo <wallace@fb.com>
Fri, 27 Aug 2021 16:31:41 +0000 (09:31 -0700)
committerWalter Erquinigo <wallace@fb.com>
Fri, 27 Aug 2021 16:34:01 +0000 (09:34 -0700)
commit602497d672ca66f3f0e59adca35f00199f266810
tree3700e1f3448f70a0c3663d34d9ebb44b4565eff3
parent8e284be04f2cd43a821289133a759afa2844f935
[trace] [intel pt] Create a "process trace save" command

added new command "process trace save -d <directory>".
-it saves a JSON file as <directory>/trace.json, with the main properties of the trace session.
-it saves binary Intel-pt trace as <directory>/thread_id.trace; each file saves each thread.
-it saves modules to the directory <directory>/modules .
-it only works for live process and it only support Intel-pt right now.

Example:
```
b main
run
process trace start
n
process trace save -d /tmp/mytrace
```
A file named trace.json and xxx.trace should be generated in /tmp/mytrace. To load the trace that was just saved:
```
trace load /tmp/mytrace
thread trace dump instructions
```
You should see the instructions of the trace got printed.

To run a test:
```
cd ~/llvm-sand/build/Release/fbcode-x86_64/toolchain
ninja lldb-dotest
./bin/lldb-dotest -p TestTraceSave
```

Reviewed By: wallace

Differential Revision: https://reviews.llvm.org/D107669
21 files changed:
lldb/include/lldb/Target/Trace.h
lldb/source/Commands/CommandObjectProcess.cpp
lldb/source/Commands/Options.td
lldb/source/Plugins/Trace/common/CMakeLists.txt
lldb/source/Plugins/Trace/common/TraceJSONStructs.cpp [new file with mode: 0644]
lldb/source/Plugins/Trace/common/TraceJSONStructs.h [new file with mode: 0644]
lldb/source/Plugins/Trace/common/TraceSessionFileParser.cpp
lldb/source/Plugins/Trace/common/TraceSessionFileParser.h
lldb/source/Plugins/Trace/common/TraceSessionSaver.cpp [new file with mode: 0644]
lldb/source/Plugins/Trace/common/TraceSessionSaver.h [new file with mode: 0644]
lldb/source/Plugins/Trace/intel-pt/CMakeLists.txt
lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.h
lldb/source/Plugins/Trace/intel-pt/TraceIntelPTJSONStructs.cpp [new file with mode: 0644]
lldb/source/Plugins/Trace/intel-pt/TraceIntelPTJSONStructs.h [new file with mode: 0644]
lldb/source/Plugins/Trace/intel-pt/TraceIntelPTOptions.td
lldb/source/Plugins/Trace/intel-pt/TraceIntelPTSessionFileParser.cpp
lldb/source/Plugins/Trace/intel-pt/TraceIntelPTSessionFileParser.h
lldb/source/Plugins/Trace/intel-pt/TraceIntelPTSessionSaver.cpp [new file with mode: 0644]
lldb/source/Plugins/Trace/intel-pt/TraceIntelPTSessionSaver.h [new file with mode: 0644]
lldb/test/API/commands/trace/TestTraceSave.py [new file with mode: 0644]