Skip to content

Commit

Permalink
Merge pull request #1840 from multiversx/lldb-formatter-fix
Browse files Browse the repository at this point in the history
lldb formatter fix
  • Loading branch information
alyn509 authored Nov 4, 2024
2 parents 2b9d402 + 524d73d commit 4a109b4
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 30 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/lldb-formatter-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ jobs:
uses: robinraju/[email protected]
with:
repository: vadimcn/vscode-lldb
tag: v1.10.0
fileName: codelldb-x86_64-linux.vsix
tag: v1.11.0
fileName: codelldb-linux-x64.vsix

- name: Setup vscode-lldb
run: |
unzip codelldb-x86_64-linux.vsix -d vscode-lldb
mkdir -p $HOME/.vscode/extensions/vadimcn.vscode-lldb-x.x.x/
mv vscode-lldb/extension/* $HOME/.vscode/extensions/vadimcn.vscode-lldb-x.x.x/
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/
- name: Run the rust tests
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def end_of_main_breakpoint_handler(frame: SBFrame, bp_loc: SBBreakpointLocation,
incorrect = 0
duplicate = 0
checked = set()
for item in lldb.value(to_check):
to_check_value = lldb.value(to_check)
for item in to_check_value:
variable_name_string, value_to_check_string = item
variable_name = get_string(variable_name_string)
value_to_check = get_string(value_to_check_string)
Expand Down
4 changes: 4 additions & 0 deletions tools/rust-debugger/format-tests/src/init_internal_dict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import sys

def __lldb_init_module(debugger, internal_dict):
internal_dict['adapter_settings'] = {'sourceLanguages': ['rust'], 'evaluateForHovers': True, 'commandCompletions': True, 'displayFormat': 'auto', 'showDisassembly': 'auto', 'dereferencePointers': True, 'evaluationTimeout': 5.0, 'suppressMissingSourceFiles': True, 'consoleMode': 'commands', 'scriptConfig': {}, 'reproducer': False}
23 changes: 18 additions & 5 deletions tools/rust-debugger/format-tests/tests/run_format_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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-*");
vscode_lldb_plugin_lookup.push(".vscode/extensions/vadimcn.vscode-lldb-1.11.0*");

let vscode_lldb_plugin = glob::glob(vscode_lldb_plugin_lookup.as_os_str().to_str().unwrap())
.expect("Failed to read glob pattern")
Expand All @@ -27,9 +27,18 @@ fn run_format_tests() {
.unwrap();
check_path(&format_tests_path);

let mut rust_formatters = vscode_lldb_plugin.clone();
rust_formatters.push("formatters");
check_path(&rust_formatters);
let init_internal_dict = Path::new("./src/init_internal_dict.py")
.canonicalize()
.unwrap();
check_path(&init_internal_dict);

let mut codelldb = vscode_lldb_plugin.clone();
codelldb.push("adapter/scripts/codelldb");
check_path(&codelldb);

let mut lang_support = vscode_lldb_plugin.clone();
lang_support.push("lang_support");
check_path(&lang_support);

let pretty_printers = Path::new("../pretty-printers/multiversx_sc_lldb_pretty_printers.py")
.canonicalize()
Expand All @@ -44,7 +53,11 @@ fn run_format_tests() {
let debugger_output = Command::new(lldb)
.arg(format_tests_path)
.arg("-o")
.arg(command_script_import(&rust_formatters))
.arg(command_script_import(&init_internal_dict))
.arg("-o")
.arg(command_script_import(&codelldb))
.arg("-o")
.arg(command_script_import(&lang_support))
.arg("-o")
.arg(command_script_import(&pretty_printers))
.arg("-o")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import struct

DEBUG_API_TYPE = "multiversx_sc_scenario::api::impl_vh::vm_hooks_api::VMHooksApi<multiversx_sc_scenario::api::impl_vh::debug_api::DebugApiBackend>"
ANY_NUMBER = "[0-9]+"
ANY_TYPE = ".*"
SOME_OR_NONE = "(Some|None)"

Expand All @@ -18,25 +17,24 @@
# 2. SC wasm - Managed basic types
MOD_PATH = "multiversx_sc::types::managed::basic"

BIG_INT_TYPE = f"{MOD_PATH}::big_int::BigInt<{DEBUG_API_TYPE}>"
BIG_FLOAT_TYPE = f"{MOD_PATH}::big_float::BigFloat<{DEBUG_API_TYPE}>"
MANAGED_BUFFER_TYPE = f"{MOD_PATH}::managed_buffer::ManagedBuffer<{DEBUG_API_TYPE}>"
BIG_INT_TYPE = f"{MOD_PATH}::big_int::BigInt<{DEBUG_API_TYPE} ?>"
BIG_FLOAT_TYPE = f"{MOD_PATH}::big_float::BigFloat<{DEBUG_API_TYPE} ?>"
MANAGED_BUFFER_TYPE = f"{MOD_PATH}::managed_buffer::ManagedBuffer<{DEBUG_API_TYPE} ?>"

# 3. SC wasm - Managed wrapped types
MOD_PATH = "multiversx_sc::types::managed::wrapped"

BIG_UINT_TYPE = f"{MOD_PATH}::big_uint::BigUint<{DEBUG_API_TYPE}>"
TOKEN_IDENTIFIER_TYPE = f"{MOD_PATH}::token_identifier::TokenIdentifier<{DEBUG_API_TYPE}>"
MANAGED_ADDRESS_TYPE = f"{MOD_PATH}::managed_address::ManagedAddress<{DEBUG_API_TYPE}>"
MANAGED_BYTE_ARRAY_TYPE = f"{MOD_PATH}::managed_byte_array::ManagedByteArray<{DEBUG_API_TYPE}, {ANY_NUMBER}>"
BIG_UINT_TYPE = f"{MOD_PATH}::big_uint::BigUint<{DEBUG_API_TYPE} ?>"
TOKEN_IDENTIFIER_TYPE = f"{MOD_PATH}::token_identifier::TokenIdentifier<{DEBUG_API_TYPE} ?>"
MANAGED_ADDRESS_TYPE = f"{MOD_PATH}::managed_address::ManagedAddress<{DEBUG_API_TYPE} ?>"
MANAGED_BYTE_ARRAY_TYPE = f"{MOD_PATH}::managed_byte_array::ManagedByteArray<{DEBUG_API_TYPE} ?>"

# ManagedOption
MANAGED_OPTION_INNER_TYPE_INDEX = 1
MANAGED_OPTION_NONE_HANDLE = 2147483646 # i32::MAX - 1
MANAGED_OPTION_TYPE = f"{MOD_PATH}::managed_option::ManagedOption<{DEBUG_API_TYPE}, {ANY_TYPE}>"

ESDT_TOKEN_PAYMENT_TYPE = f"{MOD_PATH}::esdt_token_payment::EsdtTokenPayment<{DEBUG_API_TYPE}>"
EGLD_OR_ESDT_TOKEN_IDENTIFIER_TYPE = f"{MOD_PATH}::egld_or_esdt_token_identifier::EgldOrEsdtTokenIdentifier<{DEBUG_API_TYPE}>"
ESDT_TOKEN_PAYMENT_TYPE = f"{MOD_PATH}::esdt_token_payment::EsdtTokenPayment<{DEBUG_API_TYPE} ?>"
EGLD_OR_ESDT_TOKEN_IDENTIFIER_TYPE = f"{MOD_PATH}::egld_or_esdt_token_identifier::EgldOrEsdtTokenIdentifier<{DEBUG_API_TYPE} ?>"

# ManagedVec
MANAGED_VEC_INNER_TYPE_INDEX = 1
Expand All @@ -53,7 +51,7 @@
# 6. MultiversX codec - Multi-types
MOD_PATH = "multiversx_sc_codec::multi_types"

OPTIONAL_VALUE_TYPE = f"{MOD_PATH}::multi_value_optional::OptionalValue<{ANY_TYPE}>::{SOME_OR_NONE}"
OPTIONAL_VALUE_TYPE = f"{MOD_PATH}::multi_value_optional::OptionalValue<{ANY_TYPE}>"


class InvalidHandle(Exception):
Expand Down Expand Up @@ -241,7 +239,7 @@ def lookup(self, full_value: lldb.value) -> lldb.value:
return full_value

def extract_value_from_raw_handle(self, context: lldb.value, raw_handle: int, map_picker: Callable) -> lldb.value:
managed_types = context.managed_types
managed_types = context[0].managed_types.data.value
chosen_map = map_picker(managed_types)
value = map_lookup(chosen_map, raw_handle)
return value
Expand Down Expand Up @@ -288,7 +286,7 @@ def summarize_item(self, handle_bytes: List[int], context: lldb.value, type_info
class NumBigInt(Handler):
def summary(self, num_big_int: lldb.value) -> str:
value_int = num_bigint_data_to_int(num_big_int.data.data)
if num_big_int.sign.sbvalue.GetValue() == 'num_bigint::bigint::Sign::Minus':
if num_big_int.sign.sbvalue.GetValue() == 'Minus':
return str(-value_int)
return str(value_int)

Expand Down Expand Up @@ -461,13 +459,14 @@ def summary(self, boxed_bytes: lldb.value) -> str:

class OptionalValue(Handler):
def summary(self, optional_value: lldb.value) -> str:
if optional_value.sbvalue.GetType().GetName().endswith('::Some'):
summary = optional_value.sbvalue.GetChildAtIndex(0).GetSummary()
base_type = optional_value.sbvalue.GetType().GetName()
if optional_value.value.sbvalue.GetType().GetName().startswith(f'{base_type}::Some'):
summary = optional_value.value.sbvalue.GetChildAtIndex(0).GetSummary()
return f"OptionalValue::Some({summary})"
return "OptionalValue::None"


ELROND_WASM_TYPE_HANDLERS = [
MULTIVERSX_WASM_TYPE_HANDLERS = [
# 1. num_bigint library
(NUM_BIG_INT_TYPE, NumBigInt),
(NUM_BIG_UINT_TYPE, NumBigUint),
Expand Down Expand Up @@ -505,7 +504,7 @@ def get_inner_type_handler(type_info: lldb.SBType, inner_type_index: int) -> Tup


def get_handler(type_name: str) -> Handler:
for rust_type, handler_class in ELROND_WASM_TYPE_HANDLERS:
for rust_type, handler_class in MULTIVERSX_WASM_TYPE_HANDLERS:
if re.fullmatch(rust_type, type_name) is not None:
return handler_class()
raise UnknownType(type_name)
Expand All @@ -520,7 +519,7 @@ def summarize_handler(handler_type: Type[Handler], valobj: SBValue, dictionary)
def __lldb_init_module(debugger: SBDebugger, dict):
python_module_name = Path(__file__).with_suffix('').name

for rust_type, handler_class in ELROND_WASM_TYPE_HANDLERS:
for rust_type, handler_class in MULTIVERSX_WASM_TYPE_HANDLERS:
# Add summary binding
summary_function_name = f"handle{handler_class.__name__}"
globals()[summary_function_name] = partial(summarize_handler, handler_class)
Expand Down

0 comments on commit 4a109b4

Please sign in to comment.