Closed19

ARM macでrust-gdbを動かす(詰んだので停止中)

ultimatileultimatile
  • terminal.appx86_64用とaarch64用に複製した方が楽な気がするが,Ventura以降は不可能な模様.
  • rust-gdbを動かすためにgdbが必要.brew install gdbで入れる.
  • rust-gdbを動かすためにpythonも必要.現在aarch64用pythonを使ってしまっているので後で修正する
ultimatileultimatile

rustup-initで書き換えられるfile(default path?)

$HOME/.profile
$HOME/.bash_profile
$HOME/.zshenv
ultimatileultimatile

rust-gdbを実行すると以下のerrorで動かない.適当にググるとptrace関係っぽいことが書いてある.調査中.上記python設定の問題があるので要検証

(gdb) r
Starting program: /Users/ultimatile/programming/Rust/zero_rust/dbg_target/target/debug/dbg_target 
Note: this version of macOS has System Integrity Protection.
Because `startup-with-shell' is enabled, gdb has worked around this by
caching a copy of your shell.  The shell used by "run" is now:
    /Users/ultimatile/Library/Caches/gdb/bin/zsh
Unable to find Mach task port for process-id 87475: (os/kern) failure (0x5).
ultimatileultimatile

Rust環境のinstall先を変更

export "CARGO_HOME=$HOME/x86_64/.cargo" 
export "RUSTUP_HOME=$HOME/x86_64/.rustup"

x86_64は別の名前にしても良い.

ultimatileultimatile

ryeのinstall

curl -sSf https://rye-up.com/get | bash

brew install ryeも使えるが,環境変数の設定や他の設定ができないっぽいので非推奨.(.ryeも作成されない?)

ultimatileultimatile

brewでgdb入れたときの出力よく見たら

gdb requires special privileges to access Mach ports.
You will need to codesign the binary. For instructions, see:

  https://sourceware.org/gdb/wiki/PermissionsDarwin

とちゃんと書いてある...

ultimatileultimatile

gdbのcode署名

wget https://raw.githubusercontent.com/conda-forge/gdb-feedstock/main/recipe/macos-codesign/macos-setup-codesign.sh
bash macos-setup-codesign.sh
ultimatileultimatile
security find-certificate -c gdb_codesign |grep System.keychain
security find-certificate -p -c gdb_codesign | openssl x509 -checkend 0
% security find-certificate -c gdb_codesign |grep System.keychain
keychain: "/Library/Keychains/System.keychain"
% security find-certificate -p -c gdb_codesign | openssl x509 -in /dev/stdin -checkend 0
Certificate will not expire
% security dump-trust-settings -d
Number of trusted certs = 1
Cert 0: gdb_codesign
   Number of trust settings : 1
   Trust Setting 0:
      Policy OID            : Code Signing

[1]

wget https://gist.githubusercontent.com/ultimatile/c2452c20c31e377b9df3ffed5ea3680a/raw/d43b7e6734232583e58a033e8139798748617c67/gdb-entitlement.xml
codesign --entitlements gdb-entitlement.xml -fs gdb_codesign $(which gdb)
% codesign -vv $(which gdb)
/usr/local/bin/gdb: valid on disk
/usr/local/bin/gdb: satisfies its Designated Requirement
% codesign -d --entitlements - $(which gdb)|grep -a com.apple.security.cs.debugger 
Executable=/usr/local/Cellar/gdb/14.2/bin/gdb
	[Key] com.apple.security.cs.debugger
脚注
  1. openssl x509 -in /dev/stdin -checkend 0openssl x509 -checkend 0だとWarning: Reading certificate from stdin since no -in or -new option is givenというwarningが出る.結果は変わらないので気にしなくても良い.
    https://github.com/openssl/openssl/issues/22893 ↩︎

ultimatileultimatile

(gdb)rすると

During startup program terminated with signal SIGTRAP, Trace/breakpoint trap.

と出て動かない

chmod 755 $(which gdb)
chgrp admin $(which gdb)

をすると上述のerrorは出ないが止まったままshellが帰ってこない

ultimatileultimatile

新しいshellを立ち上げるとまた出るので毎回やるか.zshrc入れる必要がある?

ultimatileultimatile

code署名を完了しても色々

warning: can't find symbol '_ZN108_$LT$nix..sys..socket..addr..sys_control..SysControlAddr$u20$as$u20$nix..sys..socket..addr..SockaddrLike$GT$8from_raw17h0b262d3dbad4b6cdE' in minsymtab

みたいなwarningが出て動かない
https://github.com/rust-lang/rust/issues/40787
libか何かのpathが解決できていないっぽい?

ultimatileultimatile
rust-gdb ./target/debug/deps/[program_name]-[randome_string]

でいけるみたいなやつが書いてあり,確かにWarningは消えるがhang upしてCtrl-CもCtrl-Dも受け付けなくなりkillするしかなくなる.
issueの最初に書いてある例でも動かないので別の問題?

このスクラップは1ヶ月前にクローズされました