{"action":"created","comment":{"url":"https://api.github.com/repos/gimli-rs/gimli/pulls/comments/206689635","pull_request_review_id":142151562,"id":206689635,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwNjY4OTYzNQ==","diff_hunk":"@@ -269,6 +269,37 @@ impl<'a, R: Reader + 'a> EhHdrTable<'a, R> {\n             &mut reader,\n         )\n     }\n+\n+    /// Returns a parsed FDE for the given address, or NoUnwindInfoForAddress\n+    /// if there are none.\n+    pub fn lookup_and_parse(&self, address: u64, bases: &BaseAddresses, frame: EhFrame<R>) -> Result<FrameDescriptionEntry<EhFrame<R>, R, R::Offset>> {\n+        let fdeptr = self.lookup(address, bases)?;\n+        let fdeptr = match fdeptr {\n+            Pointer::Direct(x) => x,\n+            _ => unreachable!(),\n+        };\n+\n+        let eh_frame_ptr = match self.hdr.eh_frame_ptr() {\n+            Pointer::Direct(x) => x,\n+            _ => unreachable!(),\n+        };\n+\n+        // Calculate the offset in the EhFrame section\n+        let offset = R::Offset::from_u64(fdeptr - eh_frame_ptr)?;\n+        let mut input = &mut frame.section().clone();\n+        input.skip(offset)?;\n+\n+        let entry = parse_cfi_entry(bases, frame.clone(), &mut input)?;\n+        let target_fde = match entry {\n+            Some(CieOrFde::Fde(fde)) => Some(fde.parse(|offset| frame.cie_from_offset(bases, offset))?),\n+            Some(CieOrFde::Cie(_)) => unimplemented!(),\n+            None => None\n+        };\n+        match target_fde {\n+            Some(ref fde) if fde.contains(address) => Ok((*fde).clone()),","path":"src/cfi.rs","position":31,"original_position":31,"commit_id":"a33221b7fc732e05739c6691c31a896f800622bf","original_commit_id":"a33221b7fc732e05739c6691c31a896f800622bf","user":{"login":"main--","id":754850,"node_id":"MDQ6VXNlcjc1NDg1MA==","avatar_url":"https://avatars3.githubusercontent.com/u/754850?v=4","gravatar_id":"","url":"https://api.github.com/users/main--","html_url":"https://github.com/main--","followers_url":"https://api.github.com/users/main--/followers","following_url":"https://api.github.com/users/main--/following{/other_user}","gists_url":"https://api.github.com/users/main--/gists{/gist_id}","starred_url":"https://api.github.com/users/main--/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/main--/subscriptions","organizations_url":"https://api.github.com/users/main--/orgs","repos_url":"https://api.github.com/users/main--/repos","events_url":"https://api.github.com/users/main--/events{/privacy}","received_events_url":"https://api.github.com/users/main--/received_events","type":"User","site_admin":false},"body":"The `ref` here is required because of the pattern guard, right? You can get around the awkwardness of cloning for no reason by moving this into the match above (since the other arms of that match are dead anyways).","created_at":"2018-07-31T21:28:10Z","updated_at":"2018-07-31T21:32:30Z","html_url":"https://github.com/gimli-rs/gimli/pull/316#discussion_r206689635","pull_request_url":"https://api.github.com/repos/gimli-rs/gimli/pulls/316","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/gimli-rs/gimli/pulls/comments/206689635"},"html":{"href":"https://github.com/gimli-rs/gimli/pull/316#discussion_r206689635"},"pull_request":{"href":"https://api.github.com/repos/gimli-rs/gimli/pulls/316"}}},"pull_request":{"url":"https://api.github.com/repos/gimli-rs/gimli/pulls/316","id":205223529,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA1MjIzNTI5","html_url":"https://github.com/gimli-rs/gimli/pull/316","diff_url":"https://github.com/gimli-rs/gimli/pull/316.diff","patch_url":"https://github.com/gimli-rs/gimli/pull/316.patch","issue_url":"https://api.github.com/repos/gimli-rs/gimli/issues/316","number":316,"state":"open","locked":false,"title":"[WIP] Add EhFrameHdr::lookup_and_parse function","user":{"login":"roblabla","id":1069318,"node_id":"MDQ6VXNlcjEwNjkzMTg=","avatar_url":"https://avatars3.githubusercontent.com/u/1069318?v=4","gravatar_id":"","url":"https://api.github.com/users/roblabla","html_url":"https://github.com/roblabla","followers_url":"https://api.github.com/users/roblabla/followers","following_url":"https://api.github.com/users/roblabla/following{/other_user}","gists_url":"https://api.github.com/users/roblabla/gists{/gist_id}","starred_url":"https://api.github.com/users/roblabla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roblabla/subscriptions","organizations_url":"https://api.github.com/users/roblabla/orgs","repos_url":"https://api.github.com/users/roblabla/repos","events_url":"https://api.github.com/users/roblabla/events{/privacy}","received_events_url":"https://api.github.com/users/roblabla/received_events","type":"User","site_admin":false},"body":"Currently, `EhFrameHdr::lookup` returns a Pointer, which is an absolute pointer which may (or may not) point to the correct FDE. This API is used by unwind-rs to speed up stack unwinding. Unfortunately, unwind-rs requires patches to gimli (see gimli-rs/unwind-rs#6) in order to make full use of this API. This is because there is no method to parse the returned Pointer into a FrameDescriptionEntry. Unwind makes parse_cfi_entry, and uses it as such:\r\n\r\n```rust\r\nlet fdeptr = eh_frame_hdr.table().unwrap().lookup(address, bases).unwrap();\r\nlet fdeptr = match fdeptr {\r\n    Pointer::Direct(x) => x,\r\n    _ => unreachable!(),\r\n};\r\n\r\nlet entry = gimli::parse_cfi_entry(bases, *sel, &mut EndianBuf::new(unsafe { std::slice::from_raw_parts(fdeptr as *const u8, 0x1000000) }, NativeEndian)).unwrap().unwrap();\r\nlet target_fde = match entry {\r\n    CieOrFde::Fde(fde) => Some(fde.parse(|offset| sel.cie_from_offset(bases, offset))?),\r\n    CieOrFde::Cie(_) => unimplemented!(), // return error here probably\r\n};\r\nif let Some(fde) = target_fde {\r\n    if !fde.contains(address) {\r\n        return Err(gimli::Error::NoUnwindInfoForAddress);\r\n    }\r\n}\r\n```\r\n\r\nAs can be seen here, there is a big fat unsafe in the middle, which sucks. I believe there is a better solution. \r\n\r\nThe complicated part is that the fdeptr is absolute, and has no length associated to it. It is, however, guaranteed to always point to an eh_frame section. Furthermore, the eh_frame_hdr has a pointer to the start of this section. As such, I propose this solution, which allows us to get rid of the unsafety.\r\n\r\nI additionally took the liberty of adding the guarantee that the returned FramePointer *will* be valid (there is no need to check contains()).\r\n\r\nI am in the process of testing this, and the implementation and doc might need a bit of refinement.\r\n\r\nCC @main-- ","created_at":"2018-07-31T19:52:20Z","updated_at":"2018-07-31T21:32:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a50795aed705a8dfcfbfca12d7c253151322cff8","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/gimli-rs/gimli/pulls/316/commits","review_comments_url":"https://api.github.com/repos/gimli-rs/gimli/pulls/316/comments","review_comment_url":"https://api.github.com/repos/gimli-rs/gimli/pulls/comments{/number}","comments_url":"https://api.github.com/repos/gimli-rs/gimli/issues/316/comments","statuses_url":"https://api.github.com/repos/gimli-rs/gimli/statuses/a33221b7fc732e05739c6691c31a896f800622bf","head":{"label":"roblabla:lookup_and_parse","ref":"lookup_and_parse","sha":"a33221b7fc732e05739c6691c31a896f800622bf","user":{"login":"roblabla","id":1069318,"node_id":"MDQ6VXNlcjEwNjkzMTg=","avatar_url":"https://avatars3.githubusercontent.com/u/1069318?v=4","gravatar_id":"","url":"https://api.github.com/users/roblabla","html_url":"https://github.com/roblabla","followers_url":"https://api.github.com/users/roblabla/followers","following_url":"https://api.github.com/users/roblabla/following{/other_user}","gists_url":"https://api.github.com/users/roblabla/gists{/gist_id}","starred_url":"https://api.github.com/users/roblabla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roblabla/subscriptions","organizations_url":"https://api.github.com/users/roblabla/orgs","repos_url":"https://api.github.com/users/roblabla/repos","events_url":"https://api.github.com/users/roblabla/events{/privacy}","received_events_url":"https://api.github.com/users/roblabla/received_events","type":"User","site_admin":false},"repo":{"id":142432710,"node_id":"MDEwOlJlcG9zaXRvcnkxNDI0MzI3MTA=","name":"gimli","full_name":"roblabla/gimli","owner":{"login":"roblabla","id":1069318,"node_id":"MDQ6VXNlcjEwNjkzMTg=","avatar_url":"https://avatars3.githubusercontent.com/u/1069318?v=4","gravatar_id":"","url":"https://api.github.com/users/roblabla","html_url":"https://github.com/roblabla","followers_url":"https://api.github.com/users/roblabla/followers","following_url":"https://api.github.com/users/roblabla/following{/other_user}","gists_url":"https://api.github.com/users/roblabla/gists{/gist_id}","starred_url":"https://api.github.com/users/roblabla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roblabla/subscriptions","organizations_url":"https://api.github.com/users/roblabla/orgs","repos_url":"https://api.github.com/users/roblabla/repos","events_url":"https://api.github.com/users/roblabla/events{/privacy}","received_events_url":"https://api.github.com/users/roblabla/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/roblabla/gimli","description":"A lazy, zero-copy parser for the DWARF debugging format.","fork":true,"url":"https://api.github.com/repos/roblabla/gimli","forks_url":"https://api.github.com/repos/roblabla/gimli/forks","keys_url":"https://api.github.com/repos/roblabla/gimli/keys{/key_id}","collaborators_url":"https://api.github.com/repos/roblabla/gimli/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/roblabla/gimli/teams","hooks_url":"https://api.github.com/repos/roblabla/gimli/hooks","issue_events_url":"https://api.github.com/repos/roblabla/gimli/issues/events{/number}","events_url":"https://api.github.com/repos/roblabla/gimli/events","assignees_url":"https://api.github.com/repos/roblabla/gimli/assignees{/user}","branches_url":"https://api.github.com/repos/roblabla/gimli/branches{/branch}","tags_url":"https://api.github.com/repos/roblabla/gimli/tags","blobs_url":"https://api.github.com/repos/roblabla/gimli/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/roblabla/gimli/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/roblabla/gimli/git/refs{/sha}","trees_url":"https://api.github.com/repos/roblabla/gimli/git/trees{/sha}","statuses_url":"https://api.github.com/repos/roblabla/gimli/statuses/{sha}","languages_url":"https://api.github.com/repos/roblabla/gimli/languages","stargazers_url":"https://api.github.com/repos/roblabla/gimli/stargazers","contributors_url":"https://api.github.com/repos/roblabla/gimli/contributors","subscribers_url":"https://api.github.com/repos/roblabla/gimli/subscribers","subscription_url":"https://api.github.com/repos/roblabla/gimli/subscription","commits_url":"https://api.github.com/repos/roblabla/gimli/commits{/sha}","git_commits_url":"https://api.github.com/repos/roblabla/gimli/git/commits{/sha}","comments_url":"https://api.github.com/repos/roblabla/gimli/comments{/number}","issue_comment_url":"https://api.github.com/repos/roblabla/gimli/issues/comments{/number}","contents_url":"https://api.github.com/repos/roblabla/gimli/contents/{+path}","compare_url":"https://api.github.com/repos/roblabla/gimli/compare/{base}...{head}","merges_url":"https://api.github.com/repos/roblabla/gimli/merges","archive_url":"https://api.github.com/repos/roblabla/gimli/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/roblabla/gimli/downloads","issues_url":"https://api.github.com/repos/roblabla/gimli/issues{/number}","pulls_url":"https://api.github.com/repos/roblabla/gimli/pulls{/number}","milestones_url":"https://api.github.com/repos/roblabla/gimli/milestones{/number}","notifications_url":"https://api.github.com/repos/roblabla/gimli/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/roblabla/gimli/labels{/name}","releases_url":"https://api.github.com/repos/roblabla/gimli/releases{/id}","deployments_url":"https://api.github.com/repos/roblabla/gimli/deployments","created_at":"2018-07-26T11:37:54Z","updated_at":"2018-07-26T11:40:01Z","pushed_at":"2018-07-31T19:47:48Z","git_url":"git://github.com/roblabla/gimli.git","ssh_url":"git@github.com:roblabla/gimli.git","clone_url":"https://github.com/roblabla/gimli.git","svn_url":"https://github.com/roblabla/gimli","homepage":"https://docs.rs/gimli/","size":4688,"stargazers_count":0,"watchers_count":0,"language":"Rust","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"gimli-rs:master","ref":"master","sha":"ed9659833ebe1bca37cc14bece171a3f27380aab","user":{"login":"gimli-rs","id":21131604,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIxMTMxNjA0","avatar_url":"https://avatars0.githubusercontent.com/u/21131604?v=4","gravatar_id":"","url":"https://api.github.com/users/gimli-rs","html_url":"https://github.com/gimli-rs","followers_url":"https://api.github.com/users/gimli-rs/followers","following_url":"https://api.github.com/users/gimli-rs/following{/other_user}","gists_url":"https://api.github.com/users/gimli-rs/gists{/gist_id}","starred_url":"https://api.github.com/users/gimli-rs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gimli-rs/subscriptions","organizations_url":"https://api.github.com/users/gimli-rs/orgs","repos_url":"https://api.github.com/users/gimli-rs/repos","events_url":"https://api.github.com/users/gimli-rs/events{/privacy}","received_events_url":"https://api.github.com/users/gimli-rs/received_events","type":"Organization","site_admin":false},"repo":{"id":61165669,"node_id":"MDEwOlJlcG9zaXRvcnk2MTE2NTY2OQ==","name":"gimli","full_name":"gimli-rs/gimli","owner":{"login":"gimli-rs","id":21131604,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIxMTMxNjA0","avatar_url":"https://avatars0.githubusercontent.com/u/21131604?v=4","gravatar_id":"","url":"https://api.github.com/users/gimli-rs","html_url":"https://github.com/gimli-rs","followers_url":"https://api.github.com/users/gimli-rs/followers","following_url":"https://api.github.com/users/gimli-rs/following{/other_user}","gists_url":"https://api.github.com/users/gimli-rs/gists{/gist_id}","starred_url":"https://api.github.com/users/gimli-rs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gimli-rs/subscriptions","organizations_url":"https://api.github.com/users/gimli-rs/orgs","repos_url":"https://api.github.com/users/gimli-rs/repos","events_url":"https://api.github.com/users/gimli-rs/events{/privacy}","received_events_url":"https://api.github.com/users/gimli-rs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/gimli-rs/gimli","description":"A lazy, zero-copy parser for the DWARF debugging format.","fork":false,"url":"https://api.github.com/repos/gimli-rs/gimli","forks_url":"https://api.github.com/repos/gimli-rs/gimli/forks","keys_url":"https://api.github.com/repos/gimli-rs/gimli/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gimli-rs/gimli/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gimli-rs/gimli/teams","hooks_url":"https://api.github.com/repos/gimli-rs/gimli/hooks","issue_events_url":"https://api.github.com/repos/gimli-rs/gimli/issues/events{/number}","events_url":"https://api.github.com/repos/gimli-rs/gimli/events","assignees_url":"https://api.github.com/repos/gimli-rs/gimli/assignees{/user}","branches_url":"https://api.github.com/repos/gimli-rs/gimli/branches{/branch}","tags_url":"https://api.github.com/repos/gimli-rs/gimli/tags","blobs_url":"https://api.github.com/repos/gimli-rs/gimli/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gimli-rs/gimli/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gimli-rs/gimli/git/refs{/sha}","trees_url":"https://api.github.com/repos/gimli-rs/gimli/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gimli-rs/gimli/statuses/{sha}","languages_url":"https://api.github.com/repos/gimli-rs/gimli/languages","stargazers_url":"https://api.github.com/repos/gimli-rs/gimli/stargazers","contributors_url":"https://api.github.com/repos/gimli-rs/gimli/contributors","subscribers_url":"https://api.github.com/repos/gimli-rs/gimli/subscribers","subscription_url":"https://api.github.com/repos/gimli-rs/gimli/subscription","commits_url":"https://api.github.com/repos/gimli-rs/gimli/commits{/sha}","git_commits_url":"https://api.github.com/repos/gimli-rs/gimli/git/commits{/sha}","comments_url":"https://api.github.com/repos/gimli-rs/gimli/comments{/number}","issue_comment_url":"https://api.github.com/repos/gimli-rs/gimli/issues/comments{/number}","contents_url":"https://api.github.com/repos/gimli-rs/gimli/contents/{+path}","compare_url":"https://api.github.com/repos/gimli-rs/gimli/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gimli-rs/gimli/merges","archive_url":"https://api.github.com/repos/gimli-rs/gimli/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gimli-rs/gimli/downloads","issues_url":"https://api.github.com/repos/gimli-rs/gimli/issues{/number}","pulls_url":"https://api.github.com/repos/gimli-rs/gimli/pulls{/number}","milestones_url":"https://api.github.com/repos/gimli-rs/gimli/milestones{/number}","notifications_url":"https://api.github.com/repos/gimli-rs/gimli/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gimli-rs/gimli/labels{/name}","releases_url":"https://api.github.com/repos/gimli-rs/gimli/releases{/id}","deployments_url":"https://api.github.com/repos/gimli-rs/gimli/deployments","created_at":"2016-06-15T00:39:04Z","updated_at":"2018-07-31T07:38:35Z","pushed_at":"2018-07-31T19:52:21Z","git_url":"git://github.com/gimli-rs/gimli.git","ssh_url":"git@github.com:gimli-rs/gimli.git","clone_url":"https://github.com/gimli-rs/gimli.git","svn_url":"https://github.com/gimli-rs/gimli","homepage":"https://docs.rs/gimli/","size":4689,"stargazers_count":184,"watchers_count":184,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":33,"mirror_url":null,"archived":false,"open_issues_count":32,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":33,"open_issues":32,"watchers":184,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/gimli-rs/gimli/pulls/316"},"html":{"href":"https://github.com/gimli-rs/gimli/pull/316"},"issue":{"href":"https://api.github.com/repos/gimli-rs/gimli/issues/316"},"comments":{"href":"https://api.github.com/repos/gimli-rs/gimli/issues/316/comments"},"review_comments":{"href":"https://api.github.com/repos/gimli-rs/gimli/pulls/316/comments"},"review_comment":{"href":"https://api.github.com/repos/gimli-rs/gimli/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/gimli-rs/gimli/pulls/316/commits"},"statuses":{"href":"https://api.github.com/repos/gimli-rs/gimli/statuses/a33221b7fc732e05739c6691c31a896f800622bf"}},"author_association":"NONE"}}
{"actor":{"display_login":"main--"}}