Skip to content

Implement gdb/pretty_print.py#767

Merged
jeaye merged 13 commits into
jank-lang:mainfrom
djblue:gdb
May 18, 2026
Merged

Implement gdb/pretty_print.py#767
jeaye merged 13 commits into
jank-lang:mainfrom
djblue:gdb

Conversation

@djblue
Copy link
Copy Markdown
Contributor

@djblue djblue commented May 10, 2026

I wanted to improve the debugging experience for myself in vscode, so I put together this pretty printer for gdb. Here is what the UI looks like when combined with #761:

image

It also requires some setup of gdb to work well: https://gist.github.com/djblue/c0c992710897a78eed3688e984e76d7e is a vscode gdb setup.

@djblue djblue mentioned this pull request May 10, 2026
@djblue
Copy link
Copy Markdown
Contributor Author

djblue commented May 17, 2026

So when I tried testing the pretty printer against the most recent version of main, I ran into some segfaults. I think the commit a7cff49 was likely causing issues. I think this just reveals that the pretty printer was too coupled to the internals of jank's object system. I decided to add two additional c-api functions to help get the data I need from jank's objects for pretty printing:

  • char const *jank_to_string(jank_object_ref o);
    • I need this to turn immutable_strings into cstrings so I can use them from python
  • char const *jank_box_canonical_type(jank_object_ref o);
    • I need this to cast the data of opaque_box to leverage the automatic printing of native types

@djblue djblue requested a review from jeaye May 17, 2026 04:55
Comment thread gdb/pretty_print.py Outdated
def jank_opaque_box_type(val):
def jank_box_canonical_type(val):
address = jank_address(val)
canonical_type = gdb.parse_and_eval(f"((jank::runtime::obj::opaque_box*){address})->canonical_type.c_str()")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The problem is that these addresses are untagged. Pointers are represented in NaN space now, so untagged pointers need to be tagged first. Check out the big comment block in oref.hpp for more details.

Comment thread compiler+runtime/src/cpp/jank/c_api.cpp Outdated
Comment on lines +76 to +77
auto const str(try_object<obj::persistent_string>(reinterpret_cast<object *>(o)));
return str->data.c_str();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  1. I would expect this to do .to_string() on the object, so it works on any object
  2. I think what you want is to_code_string(), which is different from to_string since it puts quotes around strings and #' in front of vars and such

Comment thread compiler+runtime/src/cpp/jank/c_api.cpp Outdated
return op_box->data;
}

char const *jank_box_canonical_type(jank_object_ref o)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would prefer to not have this fn, if you can just use untagged to get your object_ref.

@jeaye jeaye merged commit ff6dfaf into jank-lang:main May 18, 2026
12 of 15 checks passed
@jeaye
Copy link
Copy Markdown
Member

jeaye commented May 18, 2026

Thank you, Chris!

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