1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-15 20:19:23 +00:00

core/emu: allow for custom GDB scripts with emulator

This commit is contained in:
grdddj 2023-03-30 17:21:25 +02:00
parent 7b77888a60
commit 0587f3ed09
3 changed files with 31 additions and 3 deletions

1
core/.gitignore vendored
View File

@ -10,3 +10,4 @@ htmlcov/
mypy_report
/CMakeLists.txt
/cmake-build-debug/
tools/gdb_scripts/*.log

View File

@ -67,7 +67,7 @@ def watch_emulator(emulator: CoreEmulator) -> int:
return 0
def run_debugger(emulator: CoreEmulator) -> None:
def run_debugger(emulator: CoreEmulator, gdb_script_file: str | Path | None) -> None:
os.chdir(emulator.workdir)
env = emulator.make_env()
if platform.system() == "Darwin":
@ -78,8 +78,15 @@ def run_debugger(emulator: CoreEmulator) -> None:
env,
)
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(
"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("-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", "--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("-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")
@ -135,6 +143,7 @@ def cli(
quiet: bool,
record_dir: Optional[str],
slip0014: bool,
script_gdb_file: str | Path | None,
temporary_profile: bool,
watch: bool,
extra_args: list[str],
@ -253,7 +262,7 @@ def cli(
os.environ["TREZOR_MEMPERF"] = "1"
if debugger:
run_debugger(emulator)
run_debugger(emulator, script_gdb_file)
raise RuntimeError("run_debugger should not return")
emulator.start()

View 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