Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust debugger - add pretty representation for ManagedBuffer and other string-like types #1932

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/lldb-formatter-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ jobs:
- name: Setup vscode-lldb
run: |
unzip codelldb-linux-x64.vsix -d vscode-lldb
mkdir -p $HOME/.vscode/extensions/vadimcn.vscode-lldb-1.11.0/
mv vscode-lldb/extension/* $HOME/.vscode/extensions/vadimcn.vscode-lldb-1.11.0/
mkdir -p $HOME/.vscode/extensions/vadimcn.vscode-lldb-1.11.1/
mv vscode-lldb/extension/* $HOME/.vscode/extensions/vadimcn.vscode-lldb-1.11.1/

- name: Run the rust tests
run: |
Expand Down
10 changes: 7 additions & 3 deletions tools/rust-debugger/format-tests/src/format_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ fn main() {
push!(to_check, bigfloat, "-1234.5678");

let managed_buffer: ManagedBuffer<DebugApi> = ManagedBuffer::new_from_bytes(b"hello world");
push!(to_check, managed_buffer, "(11) 0x68656c6c6f20776f726c64");
push!(
to_check,
managed_buffer,
"\"hello world\" - (11) 0x68656c6c6f20776f726c64"
);

let token_identifier: TokenIdentifier<DebugApi> = TokenIdentifier::from("MYTOK-123456");
push!(to_check, token_identifier, "\"MYTOK-123456\"");
Expand All @@ -71,7 +75,7 @@ fn main() {

let managed_byte_array: ManagedByteArray<DebugApi, 4> =
ManagedByteArray::new_from_bytes(b"test");
push!(to_check, managed_byte_array, "(4) 0x74657374");
push!(to_check, managed_byte_array, "\"test\" - (4) 0x74657374");

let managed_option_some_token_identifier: ManagedOption<DebugApi, TokenIdentifier<DebugApi>> =
ManagedOption::some(token_identifier.clone());
Expand Down Expand Up @@ -166,7 +170,7 @@ fn main() {
push!(
to_check,
managed_vec_of_managed_buffers,
"(3) { [0] = (2) 0x6162, [1] = (4) 0x61626364, [2] = (12) 0x6162636465666768696a6b6c }"
"(3) { [0] = \"ab\" - (2) 0x6162, [1] = \"abcd\" - (4) 0x61626364, [2] = \"abcdefghijkl\" - (12) 0x6162636465666768696a6b6c }"
);

// 6. MultiversX codec - Multi-types
Expand Down
4 changes: 2 additions & 2 deletions tools/rust-debugger/format-tests/tests/run_format_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ fn run_format_tests() {
let home_dir = home::home_dir().unwrap();

let mut vscode_lldb_plugin_lookup = home_dir.clone();
vscode_lldb_plugin_lookup.push(".vscode/extensions/vadimcn.vscode-lldb-1.11.0*");
vscode_lldb_plugin_lookup.push(".vscode/extensions/vadimcn.vscode-lldb-1.11.1*");

let vscode_lldb_plugin = glob::glob(vscode_lldb_plugin_lookup.as_os_str().to_str().unwrap())
.expect("Failed to read glob pattern")
.next()
.expect("No installed vscode-lldb found")
.expect("No installed vscode-lldb found. Check for matching version in .vscode/extensions")
.expect("Glob failed");
check_path(&vscode_lldb_plugin);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from functools import partial
import string
from typing import Callable, Collection, Iterable, List, Tuple, Type
from lldb import SBValue, SBDebugger
import lldb
Expand Down Expand Up @@ -186,9 +187,18 @@ def ascii_to_string(buffer_iterator: Iterable[int]) -> str:


def buffer_as_string(buffer: lldb.value) -> str:
buffer_string = ascii_to_string(buffer)
buffer_ints = buffer_to_bytes(buffer)
buffer_string = ascii_to_string(buffer_ints)
return f'"{buffer_string}"'

def mixed_representation(buffer: lldb.value) -> str:
buffer_hex = format_buffer_hex(buffer)
buffer_string = buffer_as_string(buffer)
if all(c in string.printable for c in buffer_string):
return buffer_string + " - " + buffer_hex

return buffer_hex


def parse_handles_from_buffer_hex(buffer_hex: str) -> List[int]:
"""
Expand Down Expand Up @@ -315,7 +325,7 @@ def value_summary(self, value: lldb.value, context: lldb.value, type_info: lldb.

class ManagedBuffer(PlainManagedVecItem, ManagedType):
def value_summary(self, buffer: lldb.value, context: lldb.value, type_info: lldb.SBType) -> str:
return format_buffer_hex(buffer)
return mixed_representation(buffer)


class BigUint(PlainManagedVecItem, ManagedType):
Expand All @@ -342,15 +352,15 @@ def lookup(self, managed_address: lldb.value) -> lldb.value:
return managed_address.bytes.buffer

def value_summary(self, buffer: lldb.value, context: lldb.value, type_info: lldb.SBType) -> str:
return format_buffer_hex(buffer)
return mixed_representation(buffer)


class ManagedByteArray(PlainManagedVecItem, ManagedType):
def lookup(self, managed_byte_array: lldb.value) -> lldb.value:
return managed_byte_array.buffer

def value_summary(self, buffer: lldb.value, context: lldb.value, type_info: lldb.SBType) -> str:
return format_buffer_hex(buffer)
return mixed_representation(buffer)


class ManagedOption(PlainManagedVecItem, ManagedType):
Expand Down
Loading