From 43fef84ceb3905a22e7ba280491907bee02cc630 Mon Sep 17 00:00:00 2001 From: Alexander Koz Date: Mon, 10 Jun 2024 19:55:39 +0400 Subject: [PATCH] symbolizer: rid of sqlx, use rusqlite --- Cargo.lock | 479 ++++++++++---------- support/addr2line/.cargo/config.toml | 2 - support/addr2line/Cargo.toml | 15 +- support/addr2line/src/addr2line-crashlog.rs | 2 +- support/addr2line/src/addr2line-trace.rs | 2 +- support/addr2line/src/addr2line.rs | 2 +- support/addr2line/src/build.rs | 22 - support/addr2line/src/db.rs | 110 ++--- 8 files changed, 320 insertions(+), 314 deletions(-) delete mode 100644 support/addr2line/.cargo/config.toml delete mode 100644 support/addr2line/src/build.rs diff --git a/Cargo.lock b/Cargo.lock index 41e5bec1..ac06f807 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -35,7 +35,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", - "getrandom", "once_cell", "version_check", "zerocopy", @@ -354,15 +353,6 @@ dependencies = [ "syn 2.0.66", ] -[[package]] -name = "atoi" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" -dependencies = [ - "num-traits", -] - [[package]] name = "atomic-waker" version = "1.1.2" @@ -875,9 +865,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.6" +version = "4.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9689a29b593160de5bc4aacab7b5d54fb52231de70122626c178e6a368994c7" +checksum = "5db83dced34638ad474f39f250d7fea9598bdd239eaced1bdf45d597da0f433f" dependencies = [ "clap_builder", "clap_derive", @@ -885,9 +875,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.6" +version = "4.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e5387378c84f6faa26890ebf9f0a92989f8873d4d380467bcd0d8d8620424df" +checksum = "f7e204572485eb3fbf28f871612191521df159bc3e15a9f5064c66dba3a8c05f" dependencies = [ "anstream", "anstyle", @@ -1165,15 +1155,6 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "crossbeam-queue" -version = "0.3.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df0346b5d5e76ac2fe4e327c5fd1118d6be7c51dfb18f9b7922923f287471e35" -dependencies = [ - "crossbeam-utils", -] - [[package]] name = "crossbeam-utils" version = "0.8.20" @@ -1343,12 +1324,6 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" -[[package]] -name = "dotenvy" -version = "0.15.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" - [[package]] name = "dunce" version = "1.0.4" @@ -1383,9 +1358,6 @@ name = "either" version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" -dependencies = [ - "serde", -] [[package]] name = "eject" @@ -1619,17 +1591,6 @@ dependencies = [ "miniz_oxide", ] -[[package]] -name = "flume" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181" -dependencies = [ - "futures-core", - "futures-sink", - "spin", -] - [[package]] name = "fnv" version = "1.0.7" @@ -1703,17 +1664,6 @@ dependencies = [ "futures-util", ] -[[package]] -name = "futures-intrusive" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f" -dependencies = [ - "futures-core", - "lock_api", - "parking_lot 0.12.3", -] - [[package]] name = "futures-io" version = "0.3.30" @@ -2702,9 +2652,6 @@ name = "heck" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] [[package]] name = "heck" @@ -2812,9 +2759,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.8.0" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" +checksum = "8720bf4c5bfb5b6c350840c4cd14b787bf00ed51c148c857fbf7a6ddb7062764" [[package]] name = "httpdate" @@ -2864,14 +2811,134 @@ dependencies = [ "tokio-io-timeout", ] +[[package]] +name = "icu_collections" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locid" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locid_transform" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locid_transform_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" + +[[package]] +name = "icu_normalizer" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "utf16_iter", + "utf8_iter", + "write16", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" + +[[package]] +name = "icu_properties" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f8ac670d7422d7f76b32e17a5db556510825b29ec9154f235977c9caba61036" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locid_transform", + "icu_properties_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" + +[[package]] +name = "icu_provider" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_provider_macros" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + [[package]] name = "idna" -version = "0.5.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +checksum = "4716a3a0933a1d01c2f72450e89596eb51dd34ef3c211ccd875acdf1f8fe47ed" dependencies = [ - "unicode-bidi", - "unicode-normalization", + "icu_normalizer", + "icu_properties", + "smallvec", + "utf8_iter", ] [[package]] @@ -3281,6 +3348,12 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" +[[package]] +name = "litemap" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "643cb0b8d4fcc284004d5fd0d67ccf61dfffadb7f75e1e71bc420f4688a3a704" + [[package]] name = "lock_api" version = "0.4.12" @@ -3866,12 +3939,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "paste" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" - [[package]] name = "pathdiff" version = "0.2.1" @@ -4272,7 +4339,7 @@ dependencies = [ [[package]] name = "playdate-symbolize" -version = "0.1.1" +version = "0.1.2" dependencies = [ "anyhow", "async-stream", @@ -4283,7 +4350,7 @@ dependencies = [ "log", "playdate-build-utils", "regex", - "sqlx", + "rusqlite", "symbolic", "tokio", "tokio-stream", @@ -5095,15 +5162,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" -dependencies = [ - "lock_api", -] - [[package]] name = "spki" version = "0.7.3" @@ -5114,126 +5172,6 @@ dependencies = [ "der", ] -[[package]] -name = "sqlformat" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce81b7bd7c4493975347ef60d8c7e8b742d4694f4c49f93e0a12ea263938176c" -dependencies = [ - "itertools 0.12.1", - "nom", - "unicode_categories", -] - -[[package]] -name = "sqlx" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9a2ccff1a000a5a59cd33da541d9f2fdcd9e6e8229cc200565942bff36d0aaa" -dependencies = [ - "sqlx-core", - "sqlx-macros", - "sqlx-sqlite", -] - -[[package]] -name = "sqlx-core" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24ba59a9342a3d9bab6c56c118be528b27c9b60e490080e9711a04dccac83ef6" -dependencies = [ - "ahash", - "atoi", - "byteorder", - "bytes", - "crc", - "crossbeam-queue", - "either", - "event-listener 2.5.3", - "futures-channel", - "futures-core", - "futures-intrusive", - "futures-io", - "futures-util", - "hashlink", - "hex", - "indexmap 2.2.6", - "log", - "memchr", - "once_cell", - "paste", - "percent-encoding", - "serde", - "sha2", - "smallvec", - "sqlformat", - "thiserror", - "tokio", - "tokio-stream", - "tracing", - "url", -] - -[[package]] -name = "sqlx-macros" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea40e2345eb2faa9e1e5e326db8c34711317d2b5e08d0d5741619048a803127" -dependencies = [ - "proc-macro2", - "quote", - "sqlx-core", - "sqlx-macros-core", - "syn 1.0.109", -] - -[[package]] -name = "sqlx-macros-core" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5833ef53aaa16d860e92123292f1f6a3d53c34ba8b1969f152ef1a7bb803f3c8" -dependencies = [ - "dotenvy", - "either", - "heck 0.4.1", - "hex", - "once_cell", - "proc-macro2", - "quote", - "serde", - "serde_json", - "sha2", - "sqlx-core", - "sqlx-sqlite", - "syn 1.0.109", - "tempfile", - "tokio", - "url", -] - -[[package]] -name = "sqlx-sqlite" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b244ef0a8414da0bed4bb1910426e890b19e5e9bccc27ada6b797d05c55ae0aa" -dependencies = [ - "atoi", - "flume", - "futures-channel", - "futures-core", - "futures-executor", - "futures-intrusive", - "futures-util", - "libsqlite3-sys", - "log", - "percent-encoding", - "serde", - "sqlx-core", - "tracing", - "url", - "urlencoding", -] - [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -5433,6 +5371,17 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +[[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + [[package]] name = "tar" version = "0.4.41" @@ -5556,6 +5505,16 @@ dependencies = [ "time-core", ] +[[package]] +name = "tinystr" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" +dependencies = [ + "displaydoc", + "zerovec", +] + [[package]] name = "tinyvec" version = "1.6.0" @@ -5761,7 +5720,6 @@ version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ - "log", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -5877,12 +5835,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "unicode-bidi" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" - [[package]] name = "unicode-bom" version = "2.0.3" @@ -5910,12 +5862,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-segmentation" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" - [[package]] name = "unicode-width" version = "0.1.13" @@ -5928,29 +5874,17 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" -[[package]] -name = "unicode_categories" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" - [[package]] name = "url" -version = "2.5.0" +version = "2.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +checksum = "f7c25da092f0a868cdf09e8674cd3b7ef3a7d92a24253e663a2fb85e2496de56" dependencies = [ "form_urlencoded", "idna", "percent-encoding", ] -[[package]] -name = "urlencoding" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" - [[package]] name = "usb-ids" version = "1.2024.3" @@ -5970,6 +5904,18 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" +[[package]] +name = "utf16_iter" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + [[package]] name = "utf8parse" version = "0.2.2" @@ -6476,6 +6422,18 @@ version = "0.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904" +[[package]] +name = "write16" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" + +[[package]] +name = "writeable" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" + [[package]] name = "xml5ever" version = "0.17.0" @@ -6487,6 +6445,30 @@ dependencies = [ "markup5ever", ] +[[package]] +name = "yoke" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c5b1314b079b0930c31e3af543d8ee1757b1951ae1e1565ec704403a7240ca5" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28cc31741b18cb6f1d5ff12f5b7523e3d6eb0852bbbad19d73905511d9849b95" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", + "synstructure", +] + [[package]] name = "zerocopy" version = "0.7.34" @@ -6507,12 +6489,55 @@ dependencies = [ "syn 2.0.66", ] +[[package]] +name = "zerofrom" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ec111ce797d0e0784a1116d0ddcdbea84322cd79e5d5ad173daeba4f93ab55" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ea7b4a3637ea8669cedf0f1fd5c286a17f3de97b8dd5a70a6c167a1730e63a5" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", + "synstructure", +] + [[package]] name = "zeroize" version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" +[[package]] +name = "zerovec" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb2cc8827d6c0994478a15c53f374f46fbd41bea663d809b14744bc42e6b109c" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97cf56601ee5052b4417d90c8755c6683473c926039908196cf35d99f893ebe7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + [[package]] name = "zip" version = "1.1.4" diff --git a/support/addr2line/.cargo/config.toml b/support/addr2line/.cargo/config.toml deleted file mode 100644 index e8ece6e9..00000000 --- a/support/addr2line/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[env] -DATABASE_URL = "sqlite://symbols.db" diff --git a/support/addr2line/Cargo.toml b/support/addr2line/Cargo.toml index 68d77a3e..8500370d 100644 --- a/support/addr2line/Cargo.toml +++ b/support/addr2line/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "playdate-symbolize" -version = "0.1.1" +version = "0.1.2" readme = "README.md" description = "Tools for symbolise addresses from bin (pdex.elf) and Playdate's trace or crashlog." keywords = ["playdate", "bin", "elf", "addr2line", "utility"] @@ -10,7 +10,6 @@ license.workspace = true authors.workspace = true homepage.workspace = true repository.workspace = true -build = "src/build.rs" [[bin]] @@ -48,12 +47,9 @@ features = ["std", "env", "derive", "help", "usage", "color"] workspace = true optional = true -[dependencies.sqlx] -version = "0.7" -# TODO: support runtime-async-std -features = ["runtime-tokio", "sqlite", "macros"] -default-features = false - +[dependencies.rusqlite] +version = "0.30" +features = ["bundled"] [dependencies.utils] features = ["log"] @@ -62,4 +58,5 @@ workspace = true [features] -default = ["clap", "env_logger", "const-str"] +default = ["clap", "env_logger", "const-str", "sqlite-bundled"] +sqlite-bundled = ["rusqlite/bundled"] diff --git a/support/addr2line/src/addr2line-crashlog.rs b/support/addr2line/src/addr2line-crashlog.rs index 98583e88..d734b9fb 100644 --- a/support/addr2line/src/addr2line-crashlog.rs +++ b/support/addr2line/src/addr2line-crashlog.rs @@ -63,7 +63,7 @@ async fn main() -> anyhow::Result<()> { } debug!("Resolved addresses: {}", resolved_addrs.len()); - os_db.close().await; + os_db.close().await?; let docs: Vec<_> = docs.into_iter() .map(|doc| { diff --git a/support/addr2line/src/addr2line-trace.rs b/support/addr2line/src/addr2line-trace.rs index 95993f65..3a6cf2a5 100644 --- a/support/addr2line/src/addr2line-trace.rs +++ b/support/addr2line/src/addr2line-trace.rs @@ -146,7 +146,7 @@ async fn process_trace(reader: R, } } - os_db.close().await; + os_db.close().await?; info!("Resolved addresses: {resolved}"); info!("Unknown addresses: {missed}"); diff --git a/support/addr2line/src/addr2line.rs b/support/addr2line/src/addr2line.rs index 9b982634..aeaee07d 100644 --- a/support/addr2line/src/addr2line.rs +++ b/support/addr2line/src/addr2line.rs @@ -51,7 +51,7 @@ async fn main() -> anyhow::Result<()> { } } - os_db.close().await; + os_db.close().await?; Ok(()) } diff --git a/support/addr2line/src/build.rs b/support/addr2line/src/build.rs deleted file mode 100644 index ec427c6f..00000000 --- a/support/addr2line/src/build.rs +++ /dev/null @@ -1,22 +0,0 @@ -fn main() { - #[cfg(query_validation)] - { - use std::path::PathBuf; - let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("symbols.db"); - let root = root.canonicalize() - .map_err(|err| println!("cargo::warning={err:#}")) - .unwrap_or(root); - - let src = root.join("src"); - std::env::set_var("PD_SYM_QUERY_ROOT", src.as_os_str()); - - if std::env::var_os("DATABASE_URL").is_none() { - let url = format!("sqlite://{}", root.display()); - std::env::set_var("DATABASE_URL", &url); - println!("env var DATABASE_URL has been set to '{url}'."); - if !root.exists() { - println!("cargo::warning=env var DATABASE_URL isn't set and db doesn't exist."); - } - } - } -} diff --git a/support/addr2line/src/db.rs b/support/addr2line/src/db.rs index aa07354c..9299600e 100644 --- a/support/addr2line/src/db.rs +++ b/support/addr2line/src/db.rs @@ -4,7 +4,7 @@ use std::path::{Path, PathBuf}; use std::io::{Error as IoError, ErrorKind as IoErrorKind}; use anyhow::Result; -use sqlx::{Executor, Pool, Sqlite, SqlitePool}; +use rusqlite::Connection; use symbolic::common::{Language, Name, NameMangling}; use utils::toolchain::sdk::Sdk; @@ -16,7 +16,7 @@ const QUERY_LN: &str = include_str!("query-ln.sql"); pub struct Resolver { - pool: Pool, + conn: Connection, } impl Resolver { @@ -38,14 +38,16 @@ impl Resolver { } pub async fn with_exact(db_path: &Path) -> Result { - let db_url = format!("sqlite://{}", db_path.display()); - let pool = SqlitePool::connect(&db_url).await?; - trace!("query fn prepared: {}", pool.prepare(QUERY_FN).await.is_ok()); - trace!("query ln prepared: {}", pool.prepare(QUERY_LN).await.is_ok()); - Ok(Self { pool }) + let conn = Connection::open(db_path)?; + Ok(Self { conn }) } - pub async fn close(&self) { self.pool.close().await } + pub async fn close(self) -> rusqlite::Result<()> { + self.conn.close().map_err(|(conn, err)| { + conn.close().ok(); + err + }) + } pub async fn resolve(&self, addr: u32) -> anyhow::Result { @@ -86,28 +88,33 @@ impl Resolver { } pub async fn resolve_fn(&self, addr: u32) -> anyhow::Result { - #[cfg(query_validation)] // build with RUSTFLAGS='--cfg query_validation' - let recs = sqlx::query_file!("src/query-fn.sql", addr).fetch_all(&self.pool); - #[cfg(not(query_validation))] - let recs = { - #[derive(sqlx::FromRow)] - struct Record { - name: Option, - low: Option, - size: Option, - fn_hw_id: Option, - ln_low: Option, - ln_hw_id: Option, - lineno: Option, - path: Option, - } - sqlx::query_as::<_, Record>(QUERY_FN).bind(addr) - .fetch_all(&self.pool) - }; + struct Record { + name: Option, + low: Option, + size: Option, + fn_hw_id: Option, + ln_low: Option, + ln_hw_id: Option, + lineno: Option, + path: Option, + } + + let mut stmt = self.conn.prepare(QUERY_FN)?; + let records = stmt.query_map([addr], |row| { + Ok(Record { name: row.get(0)?, + low: row.get(1)?, + size: row.get(2)?, + fn_hw_id: row.get(3)?, + ln_low: row.get(4)?, + ln_hw_id: row.get(4)?, + lineno: row.get(6)?, + path: row.get(7)? }) + })?; let mut results = HashMap::new(); - for func in recs.await? { + for record in records { + let func = record?; let fn_name = func.name.as_deref().map(Cow::from).unwrap_or(UNKNOWN.into()); let fn_id = format_args!("{fn_name}{}", func.fn_hw_id.unwrap_or_default()).to_string(); let name = Name::new(fn_name.to_string(), NameMangling::Unmangled, Language::C); @@ -140,31 +147,32 @@ impl Resolver { pub async fn resolve_ln(&self, addr: u32) -> anyhow::Result { - #[cfg(query_validation)] // build with RUSTFLAGS='--cfg query_validation' - let recs = sqlx::query_file!("src/query-ln.sql", addr).fetch_all(&self.pool); - #[cfg(not(query_validation))] - let recs = { - #[derive(sqlx::FromRow)] - struct Record { - low: Option, - hw_id: Option, - lineno: Option, - path: Option, - } - sqlx::query_as::<_, Record>(QUERY_LN).bind(addr) - .fetch_all(&self.pool) - }; + struct Record { + low: Option, + hw_id: Option, + lineno: Option, + path: Option, + } - let mut lines: Vec<_> = recs.await? - .into_iter() - .map(|ln| { - report::Span { hw_id: ln.hw_id, - address: ln.low.map(|p| p as _).unwrap_or_default(), - size: None, - line: ln.lineno.map(|p| p as _), - file: ln.path.unwrap_or(UNKNOWN.into()).into() } - }) - .collect(); + let mut stmt = self.conn.prepare(QUERY_LN)?; + let records = stmt.query_map([addr], |row| { + Ok(Record { low: row.get(0)?, + hw_id: row.get(1)?, + lineno: row.get(2)?, + path: row.get(3)? }) + })?; + + let mut lines = records.into_iter() + .try_fold(Vec::new(), |mut acc, res| -> rusqlite::Result<_> { + let ln = res?; + let span = report::Span { hw_id: ln.hw_id, + address: ln.low.map(|p| p as _).unwrap_or_default(), + size: None, + line: ln.lineno.map(|p| p as _), + file: ln.path.unwrap_or(UNKNOWN.into()).into() }; + acc.push(span); + Ok(acc) + })?; let result = if lines.is_empty() { report::Report { addr: (addr as u64).into(),