Add rbpf-cli tool (#17378)

* Add rbpf-cli tool

* Replace explicit file type specification by required positional arg

- the type of file is determined automatically.  If ELF magic found,
  the program file is considered to be an executable ELF file, and
  an assembly input file otherwise.

* Add a note about tool's limitations and input format description
This commit is contained in:
Dmitri Makarov 2021-05-28 13:28:30 +02:00 committed by GitHub
parent 2316ddb90a
commit b8897df515
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 920 additions and 32 deletions

169
Cargo.lock generated
View File

@ -596,12 +596,44 @@ dependencies = [
"ansi_term",
"atty",
"bitflags",
"strsim",
"textwrap",
"strsim 0.8.0",
"textwrap 0.11.0",
"unicode-width",
"vec_map",
]
[[package]]
name = "clap"
version = "3.0.0-beta.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bd1061998a501ee7d4b6d449020df3266ca3124b941ec56cf2005c3779ca142"
dependencies = [
"atty",
"bitflags",
"clap_derive",
"indexmap",
"lazy_static",
"os_str_bytes",
"strsim 0.10.0",
"termcolor",
"textwrap 0.12.1",
"unicode-width",
"vec_map",
]
[[package]]
name = "clap_derive"
version = "3.0.0-beta.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "370f715b81112975b1b69db93e0b56ea4cd4e5002ac43b2da8474106a54096a1"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2 1.0.24",
"quote 1.0.6",
"syn 1.0.60",
]
[[package]]
name = "cloudabi"
version = "0.0.3"
@ -1634,6 +1666,15 @@ dependencies = [
"ahash 0.4.6",
]
[[package]]
name = "heck"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac"
dependencies = [
"unicode-segmentation",
]
[[package]]
name = "hermit-abi"
version = "0.1.13"
@ -2643,6 +2684,12 @@ dependencies = [
"vcpkg",
]
[[package]]
name = "os_str_bytes"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "afb2e1c3ee07430c2cf76151675e583e0f19985fa6efae47d6848a3e2c824f85"
[[package]]
name = "ouroboros"
version = "0.5.1"
@ -2960,6 +3007,30 @@ dependencies = [
"toml",
]
[[package]]
name = "proc-macro-error"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2 1.0.24",
"quote 1.0.6",
"syn 1.0.60",
"version_check 0.9.2",
]
[[package]]
name = "proc-macro-error-attr"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2 1.0.24",
"quote 1.0.6",
"version_check 0.9.2",
]
[[package]]
name = "proc-macro-hack"
version = "0.5.19"
@ -3294,6 +3365,19 @@ dependencies = [
"num_cpus",
]
[[package]]
name = "rbpf-cli"
version = "1.8.0"
dependencies = [
"clap 3.0.0-beta.2",
"serde",
"serde_json",
"solana-bpf-loader-program",
"solana-logger 1.8.0",
"solana-sdk",
"solana_rbpf",
]
[[package]]
name = "rdrand"
version = "0.4.0"
@ -3886,7 +3970,7 @@ dependencies = [
name = "solana-accounts-bench"
version = "1.8.0"
dependencies = [
"clap",
"clap 2.33.3",
"crossbeam-channel 0.4.4",
"log 0.4.11",
"rand 0.7.3",
@ -3902,7 +3986,7 @@ dependencies = [
name = "solana-accounts-cluster-bench"
version = "1.8.0"
dependencies = [
"clap",
"clap 2.33.3",
"log 0.4.11",
"rand 0.7.3",
"rayon",
@ -3927,7 +4011,7 @@ dependencies = [
name = "solana-banking-bench"
version = "1.8.0"
dependencies = [
"clap",
"clap 2.33.3",
"crossbeam-channel 0.4.4",
"log 0.4.11",
"rand 0.7.3",
@ -3997,7 +4081,7 @@ dependencies = [
name = "solana-bench-exchange"
version = "1.8.0"
dependencies = [
"clap",
"clap 2.33.3",
"itertools",
"log 0.4.11",
"num-derive",
@ -4026,7 +4110,7 @@ dependencies = [
name = "solana-bench-streamer"
version = "1.8.0"
dependencies = [
"clap",
"clap 2.33.3",
"solana-clap-utils",
"solana-logger 1.8.0",
"solana-net-utils",
@ -4039,7 +4123,7 @@ name = "solana-bench-tps"
version = "1.8.0"
dependencies = [
"bincode",
"clap",
"clap 2.33.3",
"log 0.4.11",
"rayon",
"serde_json",
@ -4103,7 +4187,7 @@ version = "1.8.0"
dependencies = [
"bzip2",
"cargo_metadata",
"clap",
"clap 2.33.3",
"regex",
"solana-download-utils",
"solana-sdk",
@ -4115,7 +4199,7 @@ name = "solana-cargo-test-bpf"
version = "1.8.0"
dependencies = [
"cargo_metadata",
"clap",
"clap 2.33.3",
]
[[package]]
@ -4123,7 +4207,7 @@ name = "solana-clap-utils"
version = "1.8.0"
dependencies = [
"chrono",
"clap",
"clap 2.33.3",
"rpassword",
"solana-remote-wallet",
"solana-sdk",
@ -4142,7 +4226,7 @@ dependencies = [
"bincode",
"bs58",
"chrono",
"clap",
"clap 2.33.3",
"console 0.14.1",
"criterion-stats",
"ctrlc",
@ -4224,7 +4308,7 @@ dependencies = [
"base64 0.13.0",
"bincode",
"bs58",
"clap",
"clap 2.33.3",
"indicatif",
"jsonrpc-core",
"jsonrpc-http-server",
@ -4376,7 +4460,7 @@ name = "solana-dos"
version = "1.8.0"
dependencies = [
"bincode",
"clap",
"clap 2.33.3",
"log 0.4.11",
"rand 0.7.3",
"rayon",
@ -4437,7 +4521,7 @@ version = "1.8.0"
dependencies = [
"bincode",
"byteorder",
"clap",
"clap 2.33.3",
"log 0.4.11",
"serde",
"serde_derive",
@ -4519,7 +4603,7 @@ version = "1.8.0"
dependencies = [
"base64 0.12.3",
"chrono",
"clap",
"clap 2.33.3",
"serde",
"serde_json",
"serde_yaml",
@ -4552,7 +4636,7 @@ version = "1.8.0"
dependencies = [
"bincode",
"bv",
"clap",
"clap 2.33.3",
"flate2",
"indexmap",
"itertools",
@ -4596,7 +4680,7 @@ dependencies = [
"bincode",
"bzip2",
"chrono",
"clap",
"clap 2.33.3",
"console 0.14.1",
"ctrlc",
"dirs-next",
@ -4626,7 +4710,7 @@ name = "solana-keygen"
version = "1.8.0"
dependencies = [
"bs58",
"clap",
"clap 2.33.3",
"dirs-next",
"num_cpus",
"solana-clap-utils",
@ -4701,7 +4785,7 @@ dependencies = [
"assert_cmd",
"bs58",
"bytecount",
"clap",
"clap 2.33.3",
"csv",
"futures 0.3.8",
"futures-util",
@ -4764,7 +4848,7 @@ name = "solana-log-analyzer"
version = "1.8.0"
dependencies = [
"byte-unit",
"clap",
"clap 2.33.3",
"serde",
"serde_json",
"solana-clap-utils",
@ -4805,7 +4889,7 @@ dependencies = [
name = "solana-merkle-root-bench"
version = "1.8.0"
dependencies = [
"clap",
"clap 2.33.3",
"log 0.4.11",
"solana-logger 1.8.0",
"solana-measure",
@ -4842,7 +4926,7 @@ dependencies = [
name = "solana-net-shaper"
version = "1.8.0"
dependencies = [
"clap",
"clap 2.33.3",
"rand 0.7.3",
"serde",
"serde_json",
@ -4855,7 +4939,7 @@ name = "solana-net-utils"
version = "1.8.0"
dependencies = [
"bincode",
"clap",
"clap 2.33.3",
"log 0.4.11",
"nix 0.19.0",
"rand 0.7.3",
@ -4924,7 +5008,7 @@ dependencies = [
name = "solana-poh-bench"
version = "1.8.0"
dependencies = [
"clap",
"clap 2.33.3",
"log 0.4.11",
"rand 0.7.3",
"rayon",
@ -5235,7 +5319,7 @@ dependencies = [
name = "solana-stake-accounts"
version = "1.8.0"
dependencies = [
"clap",
"clap 2.33.3",
"solana-clap-utils",
"solana-cli-config",
"solana-client",
@ -5249,7 +5333,7 @@ dependencies = [
name = "solana-stake-monitor"
version = "1.8.0"
dependencies = [
"clap",
"clap 2.33.3",
"console 0.14.1",
"log 0.4.11",
"serde",
@ -5335,7 +5419,7 @@ dependencies = [
name = "solana-store-tool"
version = "1.8.0"
dependencies = [
"clap",
"clap 2.33.3",
"log 0.4.11",
"solana-logger 1.8.0",
"solana-measure",
@ -5363,7 +5447,7 @@ dependencies = [
name = "solana-sys-tuner"
version = "1.8.0"
dependencies = [
"clap",
"clap 2.33.3",
"libc",
"log 0.4.11",
"nix 0.19.0",
@ -5381,7 +5465,7 @@ version = "1.8.0"
dependencies = [
"bincode",
"chrono",
"clap",
"clap 2.33.3",
"console 0.14.1",
"csv",
"ctrlc",
@ -5447,7 +5531,7 @@ dependencies = [
"base64 0.12.3",
"bincode",
"chrono",
"clap",
"clap 2.33.3",
"console 0.14.1",
"core_affinity",
"fd-lock",
@ -5521,7 +5605,7 @@ dependencies = [
name = "solana-watchtower"
version = "1.8.0"
dependencies = [
"clap",
"clap 2.33.3",
"humantime",
"log 0.4.11",
"solana-clap-utils",
@ -5669,6 +5753,12 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "subtle"
version = "1.0.0"
@ -5844,6 +5934,15 @@ dependencies = [
"unicode-width",
]
[[package]]
name = "textwrap"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "203008d98caf094106cfaba70acfed15e18ed3ddb7d94e49baec153a2b462789"
dependencies = [
"unicode-width",
]
[[package]]
name = "thiserror"
version = "1.0.23"
@ -6515,6 +6614,12 @@ dependencies = [
"tinyvec",
]
[[package]]
name = "unicode-segmentation"
version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796"
[[package]]
name = "unicode-width"
version = "0.1.7"

View File

@ -51,6 +51,7 @@ members = [
"programs/ownable",
"programs/stake",
"programs/vote",
"rbpf-cli",
"remote-wallet",
"runtime",
"runtime/store-tool",

510
rbpf-cli/Cargo.lock generated Normal file
View File

@ -0,0 +1,510 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "ascii"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eab1c04a571841102f5345a8fc0f6bb3d31c315dec879b5c6e42e40ce7ffa34e"
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
]
[[package]]
name = "autocfg"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
name = "bitflags"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "byteorder"
version = "1.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "clap"
version = "3.0.0-beta.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bd1061998a501ee7d4b6d449020df3266ca3124b941ec56cf2005c3779ca142"
dependencies = [
"atty",
"bitflags",
"clap_derive",
"indexmap",
"lazy_static",
"os_str_bytes",
"strsim",
"termcolor",
"textwrap",
"unicode-width",
"vec_map",
]
[[package]]
name = "clap_derive"
version = "3.0.0-beta.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "370f715b81112975b1b69db93e0b56ea4cd4e5002ac43b2da8474106a54096a1"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "combine"
version = "3.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da3da6baa321ec19e1cc41d31bf599f00c783d0517095cdaf0332e3fe8d20680"
dependencies = [
"ascii",
"byteorder",
"either",
"memchr",
"unreachable",
]
[[package]]
name = "either"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]]
name = "getrandom"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6"
dependencies = [
"cfg-if",
"libc",
"wasi 0.9.0+wasi-snapshot-preview1",
]
[[package]]
name = "goblin"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c69552f48b18aa6102ce0c82dd9bc9d3f8af5fc0a5797069b1b466b90570e39c"
dependencies = [
"log",
"plain",
"scroll",
]
[[package]]
name = "hash32"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4041af86e63ac4298ce40e5cca669066e75b6f1aa3390fe2561ffa5e1d9f4cc"
dependencies = [
"byteorder",
]
[[package]]
name = "hashbrown"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
[[package]]
name = "heck"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
dependencies = [
"unicode-segmentation",
]
[[package]]
name = "hermit-abi"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8"
dependencies = [
"libc",
]
[[package]]
name = "indexmap"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55e2e4c765aa53a0424761bf9f41aa7a6ac1efa87238f59560640e27fca028f2"
dependencies = [
"autocfg",
"hashbrown",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.80"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614"
[[package]]
name = "log"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
dependencies = [
"cfg-if",
]
[[package]]
name = "memchr"
version = "2.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
[[package]]
name = "os_str_bytes"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "afb2e1c3ee07430c2cf76151675e583e0f19985fa6efae47d6848a3e2c824f85"
[[package]]
name = "plain"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6"
[[package]]
name = "ppv-lite86"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
[[package]]
name = "proc-macro-error"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"syn",
"version_check",
]
[[package]]
name = "proc-macro-error-attr"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2",
"quote",
"version_check",
]
[[package]]
name = "proc-macro2"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
dependencies = [
"getrandom",
"libc",
"rand_chacha",
"rand_core",
"rand_hc",
"rand_pcg",
]
[[package]]
name = "rand_chacha"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
dependencies = [
"getrandom",
]
[[package]]
name = "rand_hc"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
dependencies = [
"rand_core",
]
[[package]]
name = "rand_pcg"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429"
dependencies = [
"rand_core",
]
[[package]]
name = "rbpf_cli"
version = "0.2.8"
dependencies = [
"clap",
"solana_rbpf",
"test_utils",
]
[[package]]
name = "rustc-demangle"
version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232"
[[package]]
name = "scroll"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fda28d4b4830b807a8b43f7b0e6b5df875311b3e7621d84577188c175b6ec1ec"
dependencies = [
"scroll_derive",
]
[[package]]
name = "scroll_derive"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b12bd20b94c7cdfda8c7ba9b92ad0d9a56e3fa018c25fca83b51aa664c9b4c0d"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "solana_rbpf"
version = "0.2.8"
dependencies = [
"byteorder",
"combine",
"goblin",
"hash32",
"libc",
"log",
"rand",
"rustc-demangle",
"scroll",
"thiserror",
"time",
]
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
version = "1.0.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc371affeffc477f42a221a1e4297aedcea33d47d19b61455588bd9d8f6b19ac"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "termcolor"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f"
dependencies = [
"winapi-util",
]
[[package]]
name = "test_utils"
version = "0.2.8"
dependencies = [
"libc",
"solana_rbpf",
]
[[package]]
name = "textwrap"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "203008d98caf094106cfaba70acfed15e18ed3ddb7d94e49baec153a2b462789"
dependencies = [
"unicode-width",
]
[[package]]
name = "thiserror"
version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e9ae34b84616eedaaf1e9dd6026dbe00dcafa92aa0c8077cb69df1fcfe5e53e"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ba20f23e85b10754cd195504aebf6a27e2e6cbe28c17778a0c930724628dd56"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "time"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
dependencies = [
"libc",
"wasi 0.10.0+wasi-snapshot-preview1",
"winapi",
]
[[package]]
name = "unicode-segmentation"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0"
[[package]]
name = "unicode-width"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
[[package]]
name = "unicode-xid"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]]
name = "unreachable"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
dependencies = [
"void",
]
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]]
name = "version_check"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
[[package]]
name = "void"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
[[package]]
name = "wasi"
version = "0.9.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]]
name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

18
rbpf-cli/Cargo.toml Normal file
View File

@ -0,0 +1,18 @@
[package]
name = "rbpf-cli"
version = "1.8.0"
description = "CLI to test and analyze eBPF programs"
authors = ["Solana Maintainers <maintainers@solana.foundation>"]
repository = "https://github.com/solana-labs/rbpf"
homepage = "https://solana.com/"
keywords = ["BPF", "eBPF", "interpreter", "JIT"]
edition = "2018"
[dependencies]
clap = "3.0.0-beta.2"
serde = "1.0.122"
serde_json = "1.0.56"
solana-bpf-loader-program = { path = "../programs/bpf_loader", version = "=1.8.0" }
solana-logger = { path = "../logger", version = "=1.8.0" }
solana-sdk = { path = "../sdk", version = "=1.8.0" }
solana_rbpf = "=0.2.11"

253
rbpf-cli/src/main.rs Normal file
View File

@ -0,0 +1,253 @@
use clap::{crate_version, App, Arg};
use serde::{Deserialize, Serialize};
use serde_json::Result;
use solana_bpf_loader_program::{
create_vm, serialization::serialize_parameters, syscalls::register_syscalls, BpfError,
ThisInstructionMeter,
};
use solana_rbpf::{
assembler::assemble,
static_analysis::Analysis,
verifier::check,
vm::{Config, DynamicAnalysis, Executable},
};
use solana_sdk::{
account::AccountSharedData,
bpf_loader,
keyed_account::KeyedAccount,
process_instruction::{InvokeContext, MockInvokeContext},
pubkey::Pubkey,
};
use std::{cell::RefCell, fs::File, io::Read, io::Seek, io::SeekFrom, path::Path};
#[derive(Serialize, Deserialize, Debug)]
struct Account {
lamports: u64,
data: Vec<u8>,
owner: Pubkey,
}
#[derive(Serialize, Deserialize)]
struct Input {
accounts: Vec<Account>,
insndata: Vec<u8>,
}
fn load_accounts(path: &Path) -> Result<Input> {
let file = File::open(path).unwrap();
let input: Input = serde_json::from_reader(file)?;
println!("Program input:");
println!("accounts {:?}", &input.accounts);
println!("insndata {:?}", &input.insndata);
println!("----------------------------------------");
Ok(input)
}
fn main() {
solana_logger::setup();
let matches = App::new("Solana BPF CLI")
.version(crate_version!())
.author("Solana Maintainers <maintainers@solana.foundation>")
.about(
r##"CLI to test and analyze eBPF programs.
The tool executes eBPF programs in a mocked environment.
Some features, such as sysvars syscall and CPI, are not
available for the programs executed by the CLI tool.
The input data for a program execution have to be in JSON format
and the following fields are required
{
"accounts": [
{
"lamports": 1000,
"data": [0, 0, 0, 3],
"owner": [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
]
}
],
"insndata": []
}
"##,
)
.arg(
Arg::new("PROGRAM")
.about(
"Program file to use. This is either an ELF shared-object file to be executed, \
or an assembly file to be assembled and executed.",
)
.required(true)
.index(1)
)
.arg(
Arg::new("input")
.about(
"Input for the program to run on, where FILE is a name of a JSON file \
with input data, or BYTES is the number of 0-valued bytes to allocate for program parameters",
)
.short('i')
.long("input")
.value_name("FILE / BYTES")
.takes_value(true)
.default_value("0"),
)
.arg(
Arg::new("memory")
.about("Heap memory for the program to run on")
.short('m')
.long("memory")
.value_name("BYTES")
.takes_value(true)
.default_value("0"),
)
.arg(
Arg::new("use")
.about(
"Method of execution to use, where 'cfg' generates Control Flow Graph \
of the program, 'disassembler' dumps disassembled code of the program, 'interpreter' runs \
the program in the virtual machine's interpreter, and 'jit' precompiles the program to \
native machine code before execting it in the virtual machine.",
)
.short('u')
.long("use")
.takes_value(true)
.value_name("VALUE")
.possible_values(&["cfg", "disassembler", "interpreter", "jit"])
.default_value("interpreter"),
)
.arg(
Arg::new("instruction limit")
.about("Limit the number of instructions to execute")
.short('l')
.long("limit")
.takes_value(true)
.value_name("COUNT")
.default_value(&std::i64::MAX.to_string()),
)
.arg(
Arg::new("trace")
.about("Output trace to 'trace.out' file using tracing instrumentation")
.short('t')
.long("trace"),
)
.arg(
Arg::new("profile")
.about("Output profile to 'profile.dot' file using tracing instrumentation")
.short('p')
.long("profile"),
)
.arg(
Arg::new("verify")
.about("Run the verifier before execution or disassembly")
.short('v')
.long("verify"),
)
.get_matches();
let config = Config {
enable_instruction_tracing: matches.is_present("trace") || matches.is_present("profile"),
..Config::default()
};
let mut accounts = Vec::new();
let mut account_refcells = Vec::new();
let default_account = RefCell::new(AccountSharedData::default());
let key = solana_sdk::pubkey::new_rand();
let mut mem = match matches.value_of("input").unwrap().parse::<usize>() {
Ok(allocate) => {
accounts.push(KeyedAccount::new(&key, false, &default_account));
vec![0u8; allocate]
}
Err(_) => {
let input = load_accounts(&Path::new(matches.value_of("input").unwrap())).unwrap();
for acc in input.accounts {
let asd = AccountSharedData::new_ref(acc.lamports, acc.data.len(), &acc.owner);
asd.borrow_mut().set_data(acc.data);
account_refcells.push(asd);
}
for acc in &account_refcells {
accounts.push(KeyedAccount::new(&key, false, acc));
}
let lid = bpf_loader::id();
let pid = Pubkey::new(&[0u8; 32]);
let mut bytes = serialize_parameters(&lid, &pid, &accounts, &input.insndata).unwrap();
Vec::from(bytes.as_slice_mut())
}
};
let mut invoke_context = MockInvokeContext::new(accounts);
let logger = invoke_context.logger.clone();
let compute_meter = invoke_context.get_compute_meter();
let mut instruction_meter = ThisInstructionMeter { compute_meter };
let program = matches.value_of("PROGRAM").unwrap();
let mut file = File::open(&Path::new(program)).unwrap();
let mut magic = [0u8; 4];
file.read_exact(&mut magic).unwrap();
file.seek(SeekFrom::Start(0)).unwrap();
let mut contents = Vec::new();
file.read_to_end(&mut contents).unwrap();
let mut executable = if magic == [0x7f, 0x45, 0x4c, 0x46] {
<dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(&contents, None, config)
.map_err(|err| format!("Executable constructor failed: {:?}", err))
} else {
assemble::<BpfError, ThisInstructionMeter>(
std::str::from_utf8(contents.as_slice()).unwrap(),
None,
config,
)
}
.unwrap();
if matches.is_present("verify") {
let (_, elf_bytes) = executable.get_text_bytes().unwrap();
check(elf_bytes).unwrap();
}
executable.set_syscall_registry(register_syscalls(&mut invoke_context).unwrap());
executable.jit_compile().unwrap();
let analysis = Analysis::from_executable(executable.as_ref());
match matches.value_of("use") {
Some("cfg") => {
let mut file = File::create("cfg.dot").unwrap();
analysis.visualize_graphically(&mut file, None).unwrap();
return;
}
Some("disassembler") => {
let stdout = std::io::stdout();
analysis.disassemble(&mut stdout.lock()).unwrap();
return;
}
_ => {}
}
let id = bpf_loader::id();
let mut vm = create_vm(&id, executable.as_ref(), &mut mem, &mut invoke_context).unwrap();
let result = if matches.value_of("use").unwrap() == "interpreter" {
vm.execute_program_interpreted(&mut instruction_meter)
} else {
vm.execute_program_jit(&mut instruction_meter)
};
if logger.log.borrow().len() > 0 {
println!("Program output:");
for s in logger.log.borrow_mut().iter() {
println!("{}", s);
}
println!("----------------------------------------");
}
println!("Result: {:?}", result);
println!("Instruction Count: {}", vm.get_total_instruction_count());
if matches.is_present("trace") {
println!("Trace is saved in trace.out");
let mut file = File::create("trace.out").unwrap();
let analysis = Analysis::from_executable(executable.as_ref());
vm.get_tracer().write(&mut file, &analysis).unwrap();
}
if matches.is_present("profile") {
println!("Profile is saved in profile.dot");
let tracer = &vm.get_tracer();
let dynamic_analysis = DynamicAnalysis::new(&tracer, &analysis);
let mut file = File::create("profile.dot").unwrap();
analysis
.visualize_graphically(&mut file, Some(&dynamic_analysis))
.unwrap();
}
}

View File

@ -95,6 +95,7 @@ else
solana-net-shaper
solana-sys-tuner
solana-validator
rbpf-cli
)
# Speed up net.sh deploys by excluding unused binaries