Skip to content

Introduce rr dump --json, dump trace in JSONL, one object per line - #4092

Open
timo wants to merge 1 commit into
rr-debugger:masterfrom
timo:rr_dump_json_format
Open

Introduce rr dump --json, dump trace in JSONL, one object per line#4092
timo wants to merge 1 commit into
rr-debugger:masterfrom
timo:rr_dump_json_format

Conversation

@timo

@timo timo commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Combines with some of the other flags:

  • --syscallbuf adds a syscalls key
  • --mmaps adds a maps key
  • --task_events adds a task_events key`
  • --recorded-metadata adds a metadata key

Furthermore, also passing --raw will add extra output to some of the above:

  • syscallbuf_flush_raw key with the header of a syscallbuf flush
  • raw key with the syscall data for each syscall
  • raw key with mmap record data to mmaps entries

On top of all that, a --no-regs flag is introduced that skips outputting
register values in the regular, the raw, or the json output.

This also moves write_hex_string from being a static function inside
GdbServerConnection to live in src/util.cc instead.

Here's some example output:

https://gist.github.com/timo/d6dd3b2762d78a9ee468b3cb554fa6b9

Open questions:

  • Currently, some functions are duplicated as a _json variant, some functions check flags.json_dump in-line. Is there a preference?
  • The current dump function ignores when frame.event().record_extra_regs() is true; do we care about that?
  • The initial thing that caused me (well, really dzaima) to look into the code in the first place was that the header of --raw still has three entries in it that correspond to field that are not being output any more. Is that for a separate pull request, or fine to include here?
  • The help for the command says that --raw outputs in a different format, and --json makes the same claim, so it's not obvious that they can be combined. The current behaviour of --raw and --json together may want to get a different flag and then --raw could conflict with --json
    • there could instead be a --format=raw/--format=json option instead? though a short flag for json would be nice

@timo
timo force-pushed the rr_dump_json_format branch from 2543682 to 9b1ee6c Compare August 14, 2026 15:30
@timo
timo marked this pull request as ready for review August 14, 2026 15:31
@timo
timo force-pushed the rr_dump_json_format branch 3 times, most recently from cf05bfc to ad998be Compare August 14, 2026 16:07
Combines with some of the other flags:
* `--syscallbuf` adds a `syscalls` key
* `--mmaps` adds a `maps` key
* `--task_events` adds a `task_events` key
* `--recorded-metadata` adds a `metadata` key

Furthermore, also passing `--raw` will add extra output to some of the above:
* `syscallbuf_flush_raw` key with the header of a syscallbuf flush
* `raw` key with the syscall data for each syscall
* `raw` key with mmap record data to mmaps entries

On top of all that, a `--no-regs` flag is introduced that skips outputting
register values in the regular, the raw, or the json output.

This also moves write_hex_string from being a static function inside
GdbServerConnection to live in src/util.cc instead.
@timo
timo force-pushed the rr_dump_json_format branch from ad998be to b458af5 Compare August 14, 2026 17:07

@rocallahan rocallahan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is basically fine as-is, just some minor comments. Sorry for the delay, I've been traveling.

Comment thread src/DumpCommand.cc
namespace rr {

struct JsonArrayAtKeyWriter {
public:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need public:, it's the default for struct

Comment thread src/DumpCommand.cc

namespace rr {

struct JsonArrayAtKeyWriter {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document what this struct is for and what its parts mean

Comment thread src/DumpCommand.cc
fprintf(out, " ");
for (unsigned long i = 0; i < record->size; ++i) {
fprintf(out, "%2.2x", *(record_ptr + (uintptr_t)i));
auto record_out = std::vector<char>();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this std::string.

Comment thread src/DumpCommand.cc
bool key_written = false;
bool write_comma = false;

void ensure_key(FILE *out, const char *key) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is weird. Why would the caller not know if a key has been emitted yet?

@rocallahan

Copy link
Copy Markdown
Collaborator

Sorry for the delay, I was traveling.

  • Currently, some functions are duplicated as a _json variant, some functions check flags.json_dump in-line. Is there a preference?

No, I think having a mix like you have is OK.

  • The current dump function ignores when frame.event().record_extra_regs() is true; do we care about that?

No, at least, definitely not in this PR.

  • The initial thing that caused me (well, really dzaima) to look into the code in the first place was that the header of --raw still has three entries in it that correspond to field that are not being output any more. Is that for a separate pull request, or fine to include here?

Separate PR please.

  • The help for the command says that --raw outputs in a different format, and --json makes the same claim, so it's not obvious that they can be combined. The current behaviour of --raw and --json together may want to get a different flag and then --raw could conflict with --json

Yeah I think it doesn't really make sense to combine them and we shouldn't support that.

  • there could instead be a --format=raw/--format=json option instead? though a short flag for json would be nice

I'm OK with having one flag per format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants