[all-commits] [llvm/llvm-project] efbfde: [trace] Add an option to dump instructions in json...

walter erquinigo via All-commits all-commits at lists.llvm.org
Wed Jun 22 11:14:39 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: efbfde0dd0f92d89767df53cbfb883ecf93ffa83
      https://github.com/llvm/llvm-project/commit/efbfde0dd0f92d89767df53cbfb883ecf93ffa83
  Author: Walter Erquinigo <wallace at fb.com>
  Date:   2022-06-22 (Wed, 22 Jun 2022)

  Changed paths:
    M lldb/include/lldb/Target/TraceCursor.h
    M lldb/include/lldb/Target/TraceInstructionDumper.h
    M lldb/source/Commands/CommandObjectThread.cpp
    M lldb/source/Commands/Options.td
    M lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
    M lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.h
    M lldb/source/Target/TraceInstructionDumper.cpp
    M lldb/test/API/commands/trace/TestTraceDumpInstructions.py
    M lldb/test/API/commands/trace/TestTraceLoad.py
    M lldb/test/API/commands/trace/TestTraceTSC.py

  Log Message:
  -----------
  [trace] Add an option to dump instructions in json and to a file

In order to provide simple scripting support on top of instruction traces, a simple solution is to enhance the `dump instructions` command and allow printing in json and directly to a file. The format is verbose and not space efficient, but it's not supposed to be used for really large traces, in which case the TraceCursor API is the way to go.

- add a -j option for printing the dump in json
- add a -J option for pretty printing the json output
- add a -F option for specifying an output file
- add a -a option for dumping all the instructions available starting at the initial point configured with the other flags
- add tests for all cases
- refactored the instruction dumper and abstracted the actual "printing" logic. There are two writer implementations: CLI and JSON. This made the dumper itself much more readable and maintanable

sample output:

```
(lldb) thread trace dump instructions  -t -a --id 100 -J
[
  {
    "id": 100,
    "tsc": "43591204528448966"
    "loadAddress": "0x407a91",
    "module": "a.out",
    "symbol": "void std::deque<Foo, std::allocator<Foo>>::_M_push_back_aux<Foo>(Foo&&)",
    "mnemonic": "movq",
    "source": "/usr/include/c++/8/bits/deque.tcc",
    "line": 492,
    "column": 30
  },
  ...
```

Differential Revision: https://reviews.llvm.org/D128316




More information about the All-commits mailing list