mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-18 12:28:09 +00:00
feat(core): add support for gdb scripts to emulator
This commit is contained in:
parent
6fd4173d2e
commit
be75e359a2
1
core/.gitignore
vendored
1
core/.gitignore
vendored
@ -10,3 +10,4 @@ htmlcov/
|
|||||||
mypy_report
|
mypy_report
|
||||||
/CMakeLists.txt
|
/CMakeLists.txt
|
||||||
/cmake-build-debug/
|
/cmake-build-debug/
|
||||||
|
tools/gdb_scripts/*.log
|
||||||
|
15
core/emu.py
15
core/emu.py
@ -67,7 +67,7 @@ def watch_emulator(emulator: CoreEmulator) -> int:
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def run_debugger(emulator: CoreEmulator) -> None:
|
def run_debugger(emulator: CoreEmulator, gdb_script_file: str | Path | None) -> None:
|
||||||
os.chdir(emulator.workdir)
|
os.chdir(emulator.workdir)
|
||||||
env = emulator.make_env()
|
env = emulator.make_env()
|
||||||
if platform.system() == "Darwin":
|
if platform.system() == "Darwin":
|
||||||
@ -78,8 +78,15 @@ def run_debugger(emulator: CoreEmulator) -> None:
|
|||||||
env,
|
env,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
# Optionally run a gdb script from a file
|
||||||
|
if gdb_script_file is None:
|
||||||
|
gdb = ["gdb"]
|
||||||
|
else:
|
||||||
|
gdb = ["gdb", "-x", str(HERE / gdb_script_file)]
|
||||||
os.execvpe(
|
os.execvpe(
|
||||||
"gdb", ["gdb", "--args", str(emulator.executable)] + emulator.make_args(), env
|
"gdb",
|
||||||
|
gdb + ["--args", str(emulator.executable)] + emulator.make_args(),
|
||||||
|
env,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -110,6 +117,7 @@ def _from_env(name: str) -> bool:
|
|||||||
@click.option("-q", "--quiet", is_flag=True, help="Silence emulator output")
|
@click.option("-q", "--quiet", is_flag=True, help="Silence emulator output")
|
||||||
@click.option("-r", "--record-dir", help="Directory where to record screen changes")
|
@click.option("-r", "--record-dir", help="Directory where to record screen changes")
|
||||||
@click.option("-s", "--slip0014", is_flag=True, help="Initialize device with SLIP-14 seed (all all all...)")
|
@click.option("-s", "--slip0014", is_flag=True, help="Initialize device with SLIP-14 seed (all all all...)")
|
||||||
|
@click.option("-S", "--script-gdb-file", type=click.Path(exists=True, dir_okay=False), help="Run gdb with an init file")
|
||||||
@click.option("-t", "--temporary-profile", is_flag=True, help="Create an empty temporary profile")
|
@click.option("-t", "--temporary-profile", is_flag=True, help="Create an empty temporary profile")
|
||||||
@click.option("-w", "--watch", is_flag=True, help="Restart emulator if sources change")
|
@click.option("-w", "--watch", is_flag=True, help="Restart emulator if sources change")
|
||||||
@click.option("-X", "--extra-arg", "extra_args", multiple=True, help="Extra argument to pass to micropython")
|
@click.option("-X", "--extra-arg", "extra_args", multiple=True, help="Extra argument to pass to micropython")
|
||||||
@ -135,6 +143,7 @@ def cli(
|
|||||||
quiet: bool,
|
quiet: bool,
|
||||||
record_dir: Optional[str],
|
record_dir: Optional[str],
|
||||||
slip0014: bool,
|
slip0014: bool,
|
||||||
|
script_gdb_file: str | Path | None,
|
||||||
temporary_profile: bool,
|
temporary_profile: bool,
|
||||||
watch: bool,
|
watch: bool,
|
||||||
extra_args: list[str],
|
extra_args: list[str],
|
||||||
@ -253,7 +262,7 @@ def cli(
|
|||||||
os.environ["TREZOR_MEMPERF"] = "1"
|
os.environ["TREZOR_MEMPERF"] = "1"
|
||||||
|
|
||||||
if debugger:
|
if debugger:
|
||||||
run_debugger(emulator)
|
run_debugger(emulator, script_gdb_file)
|
||||||
raise RuntimeError("run_debugger should not return")
|
raise RuntimeError("run_debugger should not return")
|
||||||
|
|
||||||
emulator.start()
|
emulator.start()
|
||||||
|
18
core/tools/gdb_scripts/layout_size.gdb
Normal file
18
core/tools/gdb_scripts/layout_size.gdb
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
set pagination off
|
||||||
|
set print array on
|
||||||
|
set print pretty on
|
||||||
|
# pwd is core/src
|
||||||
|
set logging file ../tools/gdb_scripts/layout_size.log
|
||||||
|
set logging on
|
||||||
|
|
||||||
|
break src/ui/layout/obj.rs:122
|
||||||
|
commands 1
|
||||||
|
print "Size of current root layout"
|
||||||
|
print sizeof(root)
|
||||||
|
print root
|
||||||
|
|
||||||
|
# not stopping the debugger
|
||||||
|
continue
|
||||||
|
end
|
||||||
|
|
||||||
|
run
|
Loading…
Reference in New Issue
Block a user