TR-core/tools: add gdb scripts (outdated)

grdddj/debuglink_improvements
grdddj 2 years ago
parent 728c5e0c97
commit f52d33e3c0

@ -0,0 +1,185 @@
# File generated by debug_info.py
set pagination off
set print array on
set print pretty on
# pwd is core/src
set logging file ../tools/gdb_scripts/debug_info.log
set logging on
# `Flow` when being painted
break src/ui/model_tr/component/flow.rs:204
commands 1
printf "Flow: %d\n", sizeof(*self)
print self
print *self
# not stopping the debugger
continue
end
# `Page` when being painted
break src/ui/model_tr/component/flow_pages.rs:92
commands 2
printf "Page: %d\n", sizeof(*self)
print self
print *self
# not stopping the debugger
continue
end
# `PinEntry` when being painted
break src/ui/model_tr/component/pin.rs:194
commands 3
printf "PinEntry: %d\n", sizeof(*self)
print self
print *self
# not stopping the debugger
continue
end
# `Bip39Entry` when being painted
break src/ui/model_tr/component/bip39.rs:225
commands 4
printf "Bip39Entry: %d\n", sizeof(*self)
print self
print *self
# not stopping the debugger
continue
end
# `PassphraseEntry` when being painted
break src/ui/model_tr/component/passphrase.rs:287
commands 5
printf "PassphraseEntry: %d\n", sizeof(*self)
print self
print *self
# not stopping the debugger
continue
end
# `SimpleChoice` when being painted
break src/ui/model_tr/component/simple_choice.rs:100
commands 6
printf "SimpleChoice: %d\n", sizeof(*self)
print self
print *self
# not stopping the debugger
continue
end
# `ButtonPage` when being painted
break src/ui/model_tr/component/page.rs:213
commands 7
printf "ButtonPage: %d\n", sizeof(*self)
print self
print *self
# not stopping the debugger
continue
end
# `ChoicePage` when being painted
break src/ui/model_tr/component/choice.rs:283
commands 8
printf "ChoicePage: %d\n", sizeof(*self)
print self
print *self
# not stopping the debugger
continue
end
# `Paragraphs` when being painted
break src/ui/component/text/paragraphs.rs:142
commands 9
printf "Paragraphs: %d\n", sizeof(*self)
print self
print *self
# not stopping the debugger
continue
end
# `FormattedText` when being painted
break src/ui/component/text/formatted.rs:226
commands 10
printf "FormattedText: %d\n", sizeof(*self)
print self
print *self
# not stopping the debugger
continue
end
# `ButtonController` when being painted
break src/ui/model_tr/component/button_controller.rs:383
commands 11
printf "ButtonController: %d\n", sizeof(*self)
print self
print *self
# not stopping the debugger
continue
end
# `ButtonContainer` when being painted
break src/ui/model_tr/component/button_controller.rs:137
commands 12
printf "ButtonContainer: %d\n", sizeof(*self)
print self
print *self
# not stopping the debugger
continue
end
# `Button` when being painted
break src/ui/model_tr/component/button.rs:204
commands 13
printf "Button: %d\n", sizeof(*self)
print self
print *self
# not stopping the debugger
continue
end
# `HoldToConfirm` when being painted
break src/ui/model_tr/component/confirm.rs:109
commands 14
printf "HoldToConfirm: %d\n", sizeof(*self)
print self
print *self
# not stopping the debugger
continue
end
# `Loader` when being painted
break src/ui/model_tr/component/loader.rs:208
commands 15
printf "Loader: %d\n", sizeof(*self)
print self
print *self
# not stopping the debugger
continue
end
# `ButtonDetails` when being styled
break src/ui/model_tr/component/button.rs:509
commands 16
printf "ButtonDetails: %d\n", sizeof(*self)
print self
print *self
# not stopping the debugger
continue
end
run

@ -0,0 +1,25 @@
from __future__ import annotations
from pathlib import Path
from helpers import command_teardown, file_from_objects, indent_list
from objects import OBJECTS, Object
HERE = Path(__file__).parent
FILE = HERE / "debug_info.gdb.generated"
def get_command_content(obj: Object, cmd_index: int) -> str:
return indent_list(
[
f'printf "{obj.name}: %d\\n", sizeof(*self)',
"print self",
"print *self",
"",
*command_teardown(cmd_index, obj.show_only_once, obj.continue_after_cmd),
]
)
if __name__ == "__main__":
file_from_objects(FILE, OBJECTS, get_command_content, "debug_info")

@ -0,0 +1,82 @@
from __future__ import annotations
from pathlib import Path
from typing import Callable
from objects import Object
def beginning(script: str) -> str:
return f"""\
# File generated by {script}.py
set pagination off
set print array on
set print pretty on
# pwd is core/src
set logging file ../tools/gdb_scripts/{script}.log
set logging on
"""
def run() -> str:
return "run"
def indent_list(lines: list[str], num: int = 2) -> str:
return "\n".join(indent(line, num) for line in lines)
def indent(text: str, num: int = 2) -> str:
return num * " " + text if text else ""
def command_teardown(
b_num: int, show_only_once: bool, continue_after_cmd: bool
) -> list[str]:
delete_breakpoint = [
"# deleting itself not to show multiple times",
f"delete {b_num}",
]
cont = [
"# not stopping the debugger",
"continue",
]
buf = []
if show_only_once:
buf += delete_breakpoint
if continue_after_cmd:
buf += cont
return buf
def breakpoint_and_command(obj: Object, cmd_num: int, command_content: str) -> str:
return "\n".join(
[
f"# {obj.comment}",
f"break {obj.breakpoint}",
f"commands {cmd_num}",
command_content,
"end\n",
]
)
def file_from_objects(
file: Path,
objects: list[Object],
get_command_content: Callable[[Object, int], str],
script: str,
) -> None:
with open(file, "w") as f:
f.write(beginning(script))
f.write("\n")
for index, obj in enumerate(objects, start=1):
cmd_content = get_command_content(obj, index)
f.write(breakpoint_and_command(obj, index, cmd_content))
f.write("\n")
f.write(run())
f.write("\n")

@ -0,0 +1,225 @@
from __future__ import annotations
from dataclasses import dataclass
@dataclass
class Object:
name: str
comment: str
breakpoint: str
attributes: list[str]
show_only_once: bool = False
continue_after_cmd: bool = True
# TODO: look into C and micropython as well
# TODO: could define some tests for this - create a test-case and assert sizes
# TODO: could become a stack-size-tool as a counterpart to bin-size-tool
# TODO: look into tools/analyze-memory-dump.py script
# TODO: add possibility to determine the breakpoint dynamically from python,
# , so that we do not need to change the breakpoint line-number manually
# (like setting a function name and a path-to-file, determining linenumber automatically)
# TODO: might analyze it in place() not paint() so it does not spam so much when HoldToConfirm repaints
OBJECTS: list[Object] = [
Object(
name="Flow",
comment="`Flow` when being painted",
breakpoint="src/ui/model_tr/component/flow.rs:204",
attributes=[
"pages",
"page_counter",
"pad",
"common_title",
"current_page",
"buttons",
],
),
Object(
name="Page",
comment="`Page` when being painted",
breakpoint="src/ui/model_tr/component/flow_pages.rs:92",
attributes=[
"ops",
"layout",
"btn_layout",
"btn_actions",
"current_page",
"page_count",
"char_offset",
],
),
Object(
name="PinEntry",
comment="`PinEntry` when being painted",
breakpoint="src/ui/model_tr/component/pin.rs:194",
attributes=[
"show_real_pin",
"textbox",
"choice_page",
],
),
Object(
name="Bip39Entry",
comment="`Bip39Entry` when being painted",
breakpoint="src/ui/model_tr/component/bip39.rs:225",
attributes=[
"choice_page",
"letter_choices",
"textbox",
"pad",
"offer_words",
"bip39_words_list",
"words",
"word_count",
],
),
Object(
name="PassphraseEntry",
comment="`PassphraseEntry` when being painted",
breakpoint="src/ui/model_tr/component/passphrase.rs:287",
attributes=[
"choice_page",
"show_plain_passphrase",
"textbox",
"current_category",
"menu_position",
],
),
Object(
name="SimpleChoice",
comment="`SimpleChoice` when being painted",
breakpoint="src/ui/model_tr/component/simple_choice.rs:100",
attributes=[
"choices",
"choice_page",
],
),
Object(
name="ButtonPage",
comment="`ButtonPage` when being painted",
breakpoint="src/ui/model_tr/component/page.rs:213",
attributes=[
"content",
"scrollbar",
"pad",
"cancel_btn_details",
"confirm_btn_details",
"back_btn_details",
"next_btn_details",
"buttons",
],
),
Object(
name="ChoicePage",
comment="`ChoicePage` when being painted",
breakpoint="src/ui/model_tr/component/choice.rs:283",
attributes=[
"choices",
"pad",
"buttons",
"page_counter",
"is_carousel",
],
),
Object(
name="Paragraphs",
comment="`Paragraphs` when being painted",
breakpoint="src/ui/component/text/paragraphs.rs:142",
attributes=[
"area",
"list",
"placement",
"offset",
"visible",
],
),
Object(
name="FormattedText",
comment="`FormattedText` when being painted",
breakpoint="src/ui/component/text/formatted.rs:226",
attributes=[
"layout",
"fonts",
"format",
"args",
"icon_args",
"char_offset",
],
),
Object(
name="ButtonController",
comment="`ButtonController` when being painted",
breakpoint="src/ui/model_tr/component/button_controller.rs:383",
attributes=[
"pad",
"left_btn",
"middle_btn",
"right_btn",
"state",
"button_area",
],
),
Object(
name="ButtonContainer",
comment="`ButtonContainer` when being painted",
breakpoint="src/ui/model_tr/component/button_controller.rs:137",
attributes=[
"pos",
"button_type",
],
),
Object(
name="Button",
comment="`Button` when being painted",
breakpoint="src/ui/model_tr/component/button.rs:204",
attributes=[
"bounds",
"pos",
"content",
"styles",
"state",
],
),
Object(
name="HoldToConfirm",
comment="`HoldToConfirm` when being painted",
breakpoint="src/ui/model_tr/component/confirm.rs:109",
attributes=[
"area",
"pos",
"loader",
"text_width",
],
),
Object(
name="Loader",
comment="`Loader` when being painted",
breakpoint="src/ui/model_tr/component/loader.rs:208",
attributes=[
"area",
"state",
"growing_duration",
"shrinking_duration",
"text_overlay",
"styles",
],
),
Object(
name="ButtonDetails",
comment="`ButtonDetails` when being styled",
breakpoint="src/ui/model_tr/component/button.rs:509",
attributes=[
"text",
"icon",
"duration",
"is_cancel",
"with_outline",
"with_arms",
"force_width",
"offset",
],
),
]

@ -0,0 +1,255 @@
# File generated by size_info.py
set pagination off
set print array on
set print pretty on
# pwd is core/src
set logging file ../tools/gdb_scripts/size_info.log
set logging on
# `Flow` when being painted
break src/ui/model_tr/component/flow.rs:204
commands 1
printf "`Flow` when being painted\n"
printf "Flow: %d\n", sizeof(*self)
printf "Flow.pages: %d\n", sizeof(self.pages)
printf "Flow.page_counter: %d\n", sizeof(self.page_counter)
printf "Flow.pad: %d\n", sizeof(self.pad)
printf "Flow.common_title: %d\n", sizeof(self.common_title)
printf "Flow.current_page: %d\n", sizeof(self.current_page)
printf "Flow.buttons: %d\n", sizeof(self.buttons)
# not stopping the debugger
continue
end
# `Page` when being painted
break src/ui/model_tr/component/flow_pages.rs:92
commands 2
printf "`Page` when being painted\n"
printf "Page: %d\n", sizeof(*self)
printf "Page.ops: %d\n", sizeof(self.ops)
printf "Page.layout: %d\n", sizeof(self.layout)
printf "Page.btn_layout: %d\n", sizeof(self.btn_layout)
printf "Page.btn_actions: %d\n", sizeof(self.btn_actions)
printf "Page.current_page: %d\n", sizeof(self.current_page)
printf "Page.page_count: %d\n", sizeof(self.page_count)
printf "Page.char_offset: %d\n", sizeof(self.char_offset)
# not stopping the debugger
continue
end
# `PinEntry` when being painted
break src/ui/model_tr/component/pin.rs:194
commands 3
printf "`PinEntry` when being painted\n"
printf "PinEntry: %d\n", sizeof(*self)
printf "PinEntry.show_real_pin: %d\n", sizeof(self.show_real_pin)
printf "PinEntry.textbox: %d\n", sizeof(self.textbox)
printf "PinEntry.choice_page: %d\n", sizeof(self.choice_page)
# not stopping the debugger
continue
end
# `Bip39Entry` when being painted
break src/ui/model_tr/component/bip39.rs:225
commands 4
printf "`Bip39Entry` when being painted\n"
printf "Bip39Entry: %d\n", sizeof(*self)
printf "Bip39Entry.choice_page: %d\n", sizeof(self.choice_page)
printf "Bip39Entry.letter_choices: %d\n", sizeof(self.letter_choices)
printf "Bip39Entry.textbox: %d\n", sizeof(self.textbox)
printf "Bip39Entry.pad: %d\n", sizeof(self.pad)
printf "Bip39Entry.offer_words: %d\n", sizeof(self.offer_words)
printf "Bip39Entry.bip39_words_list: %d\n", sizeof(self.bip39_words_list)
printf "Bip39Entry.words: %d\n", sizeof(self.words)
printf "Bip39Entry.word_count: %d\n", sizeof(self.word_count)
# not stopping the debugger
continue
end
# `PassphraseEntry` when being painted
break src/ui/model_tr/component/passphrase.rs:287
commands 5
printf "`PassphraseEntry` when being painted\n"
printf "PassphraseEntry: %d\n", sizeof(*self)
printf "PassphraseEntry.choice_page: %d\n", sizeof(self.choice_page)
printf "PassphraseEntry.show_plain_passphrase: %d\n", sizeof(self.show_plain_passphrase)
printf "PassphraseEntry.textbox: %d\n", sizeof(self.textbox)
printf "PassphraseEntry.current_category: %d\n", sizeof(self.current_category)
printf "PassphraseEntry.menu_position: %d\n", sizeof(self.menu_position)
# not stopping the debugger
continue
end
# `SimpleChoice` when being painted
break src/ui/model_tr/component/simple_choice.rs:100
commands 6
printf "`SimpleChoice` when being painted\n"
printf "SimpleChoice: %d\n", sizeof(*self)
printf "SimpleChoice.choices: %d\n", sizeof(self.choices)
printf "SimpleChoice.choice_page: %d\n", sizeof(self.choice_page)
# not stopping the debugger
continue
end
# `ButtonPage` when being painted
break src/ui/model_tr/component/page.rs:213
commands 7
printf "`ButtonPage` when being painted\n"
printf "ButtonPage: %d\n", sizeof(*self)
printf "ButtonPage.content: %d\n", sizeof(self.content)
printf "ButtonPage.scrollbar: %d\n", sizeof(self.scrollbar)
printf "ButtonPage.pad: %d\n", sizeof(self.pad)
printf "ButtonPage.cancel_btn_details: %d\n", sizeof(self.cancel_btn_details)
printf "ButtonPage.confirm_btn_details: %d\n", sizeof(self.confirm_btn_details)
printf "ButtonPage.back_btn_details: %d\n", sizeof(self.back_btn_details)
printf "ButtonPage.next_btn_details: %d\n", sizeof(self.next_btn_details)
printf "ButtonPage.buttons: %d\n", sizeof(self.buttons)
# not stopping the debugger
continue
end
# `ChoicePage` when being painted
break src/ui/model_tr/component/choice.rs:283
commands 8
printf "`ChoicePage` when being painted\n"
printf "ChoicePage: %d\n", sizeof(*self)
printf "ChoicePage.choices: %d\n", sizeof(self.choices)
printf "ChoicePage.pad: %d\n", sizeof(self.pad)
printf "ChoicePage.buttons: %d\n", sizeof(self.buttons)
printf "ChoicePage.page_counter: %d\n", sizeof(self.page_counter)
printf "ChoicePage.is_carousel: %d\n", sizeof(self.is_carousel)
# not stopping the debugger
continue
end
# `Paragraphs` when being painted
break src/ui/component/text/paragraphs.rs:142
commands 9
printf "`Paragraphs` when being painted\n"
printf "Paragraphs: %d\n", sizeof(*self)
printf "Paragraphs.area: %d\n", sizeof(self.area)
printf "Paragraphs.list: %d\n", sizeof(self.list)
printf "Paragraphs.placement: %d\n", sizeof(self.placement)
printf "Paragraphs.offset: %d\n", sizeof(self.offset)
printf "Paragraphs.visible: %d\n", sizeof(self.visible)
# not stopping the debugger
continue
end
# `FormattedText` when being painted
break src/ui/component/text/formatted.rs:226
commands 10
printf "`FormattedText` when being painted\n"
printf "FormattedText: %d\n", sizeof(*self)
printf "FormattedText.layout: %d\n", sizeof(self.layout)
printf "FormattedText.fonts: %d\n", sizeof(self.fonts)
printf "FormattedText.format: %d\n", sizeof(self.format)
printf "FormattedText.args: %d\n", sizeof(self.args)
printf "FormattedText.icon_args: %d\n", sizeof(self.icon_args)
printf "FormattedText.char_offset: %d\n", sizeof(self.char_offset)
# not stopping the debugger
continue
end
# `ButtonController` when being painted
break src/ui/model_tr/component/button_controller.rs:383
commands 11
printf "`ButtonController` when being painted\n"
printf "ButtonController: %d\n", sizeof(*self)
printf "ButtonController.pad: %d\n", sizeof(self.pad)
printf "ButtonController.left_btn: %d\n", sizeof(self.left_btn)
printf "ButtonController.middle_btn: %d\n", sizeof(self.middle_btn)
printf "ButtonController.right_btn: %d\n", sizeof(self.right_btn)
printf "ButtonController.state: %d\n", sizeof(self.state)
printf "ButtonController.button_area: %d\n", sizeof(self.button_area)
# not stopping the debugger
continue
end
# `ButtonContainer` when being painted
break src/ui/model_tr/component/button_controller.rs:137
commands 12
printf "`ButtonContainer` when being painted\n"
printf "ButtonContainer: %d\n", sizeof(*self)
printf "ButtonContainer.pos: %d\n", sizeof(self.pos)
printf "ButtonContainer.button_type: %d\n", sizeof(self.button_type)
# not stopping the debugger
continue
end
# `Button` when being painted
break src/ui/model_tr/component/button.rs:204
commands 13
printf "`Button` when being painted\n"
printf "Button: %d\n", sizeof(*self)
printf "Button.bounds: %d\n", sizeof(self.bounds)
printf "Button.pos: %d\n", sizeof(self.pos)
printf "Button.content: %d\n", sizeof(self.content)
printf "Button.styles: %d\n", sizeof(self.styles)
printf "Button.state: %d\n", sizeof(self.state)
# not stopping the debugger
continue
end
# `HoldToConfirm` when being painted
break src/ui/model_tr/component/confirm.rs:109
commands 14
printf "`HoldToConfirm` when being painted\n"
printf "HoldToConfirm: %d\n", sizeof(*self)
printf "HoldToConfirm.area: %d\n", sizeof(self.area)
printf "HoldToConfirm.pos: %d\n", sizeof(self.pos)
printf "HoldToConfirm.loader: %d\n", sizeof(self.loader)
printf "HoldToConfirm.text_width: %d\n", sizeof(self.text_width)
# not stopping the debugger
continue
end
# `Loader` when being painted
break src/ui/model_tr/component/loader.rs:208
commands 15
printf "`Loader` when being painted\n"
printf "Loader: %d\n", sizeof(*self)
printf "Loader.area: %d\n", sizeof(self.area)
printf "Loader.state: %d\n", sizeof(self.state)
printf "Loader.growing_duration: %d\n", sizeof(self.growing_duration)
printf "Loader.shrinking_duration: %d\n", sizeof(self.shrinking_duration)
printf "Loader.text_overlay: %d\n", sizeof(self.text_overlay)
printf "Loader.styles: %d\n", sizeof(self.styles)
# not stopping the debugger
continue
end
# `ButtonDetails` when being styled
break src/ui/model_tr/component/button.rs:509
commands 16
printf "`ButtonDetails` when being styled\n"
printf "ButtonDetails: %d\n", sizeof(*self)
printf "ButtonDetails.text: %d\n", sizeof(self.text)
printf "ButtonDetails.icon: %d\n", sizeof(self.icon)
printf "ButtonDetails.duration: %d\n", sizeof(self.duration)
printf "ButtonDetails.is_cancel: %d\n", sizeof(self.is_cancel)
printf "ButtonDetails.with_outline: %d\n", sizeof(self.with_outline)
printf "ButtonDetails.with_arms: %d\n", sizeof(self.with_arms)
printf "ButtonDetails.force_width: %d\n", sizeof(self.force_width)
printf "ButtonDetails.offset: %d\n", sizeof(self.offset)
# not stopping the debugger
continue
end
run

@ -0,0 +1,32 @@
from __future__ import annotations
from pathlib import Path
from helpers import command_teardown, file_from_objects, indent_list
from objects import OBJECTS, Object
HERE = Path(__file__).parent
FILE = HERE / "size_info.gdb.generated"
def attribute_sizes(obj: Object) -> list[str]:
def attr_size(attr: str) -> str:
return f'printf "{obj.name}.{attr}: %d\\n", sizeof(self.{attr})'
return [attr_size(attr) for attr in obj.attributes]
def get_command_content(obj: Object, cmd_index: int) -> str:
return indent_list(
[
f'printf "{obj.comment}\\n"',
f'printf "{obj.name}: %d\\n", sizeof(*self)',
*attribute_sizes(obj),
"",
*command_teardown(cmd_index, obj.show_only_once, obj.continue_after_cmd),
]
)
if __name__ == "__main__":
file_from_objects(FILE, OBJECTS, get_command_content, "size_info")
Loading…
Cancel
Save