New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std: Render large exit codes as hex on Windows #57473

Merged
merged 1 commit into from Jan 13, 2019

Conversation

Projects
None yet
9 participants
@alexcrichton
Copy link
Member

alexcrichton commented Jan 9, 2019

On Windows process exit codes are never signals but rather always 32-bit
integers. Most faults like segfaults and such end up having large
integers used to represent them, like STATUS_ACCESS_VIOLATION being
0xC0000005. Currently, however, when an ExitStatus is printed this
ends up getting rendered as 3221225477 which is somewhat more difficult
to debug.

This commit adds a branch in Display for ExitStatus on Windows which
handles exit statuses where the high bit is set and prints those exit
statuses as hex instead of with decimals. This will hopefully preserve
the current display for small exit statuses (like exit code: 22), but
assist in quickly debugging segfaults/access violations/etc. I've
found at least that the hex codes are easier to search for than decimal.

I wasn't able to find any official documentation saying that all system
exit codes have the high bit set, but I figure it's a good enough
heuristic for now.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Jan 9, 2019

r? @Kimundi

(rust_highfive has picked a reviewer for you, use r? to override)

@nagisa

This comment has been minimized.

Copy link
Contributor

nagisa commented Jan 9, 2019

I think it is a good heuristic.

cc @retep998

@retep998

This comment has been minimized.

Copy link
Member

retep998 commented Jan 9, 2019

Generally the system exit codes are due to an unhandled exception, and unhandled exceptions have an NTSTATUS code, which is the code that is returned when the program is terminated due to the unhandled exception. An NTSTATUS with the high bit set indicates a warning or an error. Since it's unlikely that the program would be crashing due to an NTSTATUS that indicates success, checking for the high bit is a very valid heuristic.

@Kimundi

This comment has been minimized.

Copy link
Member

Kimundi commented Jan 10, 2019

Seems sensible, and @retep998 approves, so...

@bors: r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jan 10, 2019

📌 Commit 415f514 has been approved by Kimundi

@@ -393,7 +393,11 @@ impl From<c::DWORD> for ExitStatus {

impl fmt::Display for ExitStatus {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "exit code: {}", self.0)
if self.0 & 0x80000000 != 0 {

This comment has been minimized.

@varkor

varkor Jan 10, 2019

Member

It would be nice to have a comment explaining this heuristic briefly.

This comment has been minimized.

@pravic

pravic Jan 17, 2019

Contributor

@varkor Apparently, ExitProcess is a newtype for u32 on Windows. And Windows uses sometimes system error codes, sometimes NTSTATUS.

The self.0 & 0x80000000 != 0 for u32 acts like self.0 < 0 for i32, but I'd render informational status codes (the ones within 0x40000000 − 0x7FFFFFFF range) as hexadecimal as well.

This comment has been minimized.

@petrochenkov

petrochenkov Jan 17, 2019

Contributor

I'm not sure why only large codes are printed in hexadecimal. What's the problem with printing all codes in hexadecimal? We wouldn't need any heuristics and comments then.
(Small codes are documented and searchable in both hexadecimal and decimal forms.)

This comment has been minimized.

@retep998

retep998 Jan 17, 2019

Member

Are there any examples of exceptions crashing the process that have an informational status codes though?

This comment has been minimized.

@pravic

pravic Jan 17, 2019

Contributor

@petrochenkov Because system error codes are decimal. For example, 12000 - 12175 is reserved for Internet Error codes. So, displaying it in hexadecimal would be the opposite of this PR.

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jan 10, 2019

💡 This pull request was already approved, no need to approve it again.

  • There's another pull request that is currently being tested, blocking this pull request: #57355
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jan 10, 2019

📌 Commit 415f514 has been approved by Kimundi

std: Render large exit codes as hex on Windows
On Windows process exit codes are never signals but rather always 32-bit
integers. Most faults like segfaults and such end up having large
integers used to represent them, like STATUS_ACCESS_VIOLATION being
0xC0000005. Currently, however, when an `ExitStatus` is printed this
ends up getting rendered as 3221225477 which is somewhat more difficult
to debug.

This commit adds a branch in `Display for ExitStatus` on Windows which
handles exit statuses where the high bit is set and prints those exit
statuses as hex instead of with decimals. This will hopefully preserve
the current display for small exit statuses (like `exit code: 22`), but
assist in quickly debugging segfaults/access violations/etc. I've
found at least that the hex codes are easier to search for than decimal.

I wasn't able to find any official documentation saying that all system
exit codes have the high bit set, but I figure it's a good enough
heuristic for now.

@alexcrichton alexcrichton force-pushed the alexcrichton:hex-display-on-windows branch from 415f514 to bbb5448 Jan 10, 2019

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Jan 10, 2019

@bors: r=Kimundi

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jan 10, 2019

📌 Commit bbb5448 has been approved by Kimundi

pietroalbini added a commit to pietroalbini/rust that referenced this pull request Jan 12, 2019

Rollup merge of rust-lang#57473 - alexcrichton:hex-display-on-windows…
…, r=Kimundi

std: Render large exit codes as hex on Windows

On Windows process exit codes are never signals but rather always 32-bit
integers. Most faults like segfaults and such end up having large
integers used to represent them, like STATUS_ACCESS_VIOLATION being
0xC0000005. Currently, however, when an `ExitStatus` is printed this
ends up getting rendered as 3221225477 which is somewhat more difficult
to debug.

This commit adds a branch in `Display for ExitStatus` on Windows which
handles exit statuses where the high bit is set and prints those exit
statuses as hex instead of with decimals. This will hopefully preserve
the current display for small exit statuses (like `exit code: 22`), but
assist in quickly debugging segfaults/access violations/etc. I've
found at least that the hex codes are easier to search for than decimal.

I wasn't able to find any official documentation saying that all system
exit codes have the high bit set, but I figure it's a good enough
heuristic for now.

bors added a commit that referenced this pull request Jan 12, 2019

Auto merge of #57554 - pietroalbini:rollup, r=pietroalbini
Rollup of 15 pull requests

Successful merges:

 - #57351 (Don't actually create a full MIR stack frame when not needed)
 - #57353 (Optimise floating point `is_finite` (2x) and `is_infinite` (1.6x).)
 - #57392 (Always calculate glob map but only for glob uses)
 - #57412 (Improve the wording)
 - #57436 (save-analysis: use a fallback when access levels couldn't be computed)
 - #57442 (Simplify `ConstValue::ScalarPair`)
 - #57453 (lldb_batchmode.py: try `import _thread` for Python 3)
 - #57454 (Some cleanups for core::fmt)
 - #57461 (Change `String` to `&'static str` in `ParseResult::Failure`.)
 - #57473 (std: Render large exit codes as hex on Windows)
 - #57474 (save-analysis: Get path def from parent in case there's no def for the path itself.)
 - #57494 (Speed up item_bodies for large match statements involving regions)
 - #57496 (re-do docs for core::cmp)
 - #57508 (rustdoc: Allow inlining of reexported crates and crate items)
 - #57547 (Use `ptr::eq` where applicable)

Failed merges:

r? @ghost

Centril added a commit to Centril/rust that referenced this pull request Jan 13, 2019

Rollup merge of rust-lang#57473 - alexcrichton:hex-display-on-windows…
…, r=Kimundi

std: Render large exit codes as hex on Windows

On Windows process exit codes are never signals but rather always 32-bit
integers. Most faults like segfaults and such end up having large
integers used to represent them, like STATUS_ACCESS_VIOLATION being
0xC0000005. Currently, however, when an `ExitStatus` is printed this
ends up getting rendered as 3221225477 which is somewhat more difficult
to debug.

This commit adds a branch in `Display for ExitStatus` on Windows which
handles exit statuses where the high bit is set and prints those exit
statuses as hex instead of with decimals. This will hopefully preserve
the current display for small exit statuses (like `exit code: 22`), but
assist in quickly debugging segfaults/access violations/etc. I've
found at least that the hex codes are easier to search for than decimal.

I wasn't able to find any official documentation saying that all system
exit codes have the high bit set, but I figure it's a good enough
heuristic for now.

bors added a commit that referenced this pull request Jan 13, 2019

Auto merge of #57561 - Centril:rollup, r=Centril
Rollup of 15 pull requests

Successful merges:

 - #57351 (Don't actually create a full MIR stack frame when not needed)
 - #57353 (Optimise floating point `is_finite` (2x) and `is_infinite` (1.6x).)
 - #57392 (Always calculate glob map but only for glob uses)
 - #57412 (Improve the wording)
 - #57436 (save-analysis: use a fallback when access levels couldn't be computed)
 - #57453 (lldb_batchmode.py: try `import _thread` for Python 3)
 - #57454 (Some cleanups for core::fmt)
 - #57461 (Change `String` to `&'static str` in `ParseResult::Failure`.)
 - #57473 (std: Render large exit codes as hex on Windows)
 - #57474 (save-analysis: Get path def from parent in case there's no def for the path itself.)
 - #57494 (Speed up item_bodies for large match statements involving regions)
 - #57496 (re-do docs for core::cmp)
 - #57508 (rustdoc: Allow inlining of reexported crates and crate items)
 - #57547 (Use `ptr::eq` where applicable)
 - #57560 (hygiene: Do not treat `Self` ctor as a local variable)

Failed merges:

r? @ghost

Centril added a commit to Centril/rust that referenced this pull request Jan 13, 2019

Rollup merge of rust-lang#57473 - alexcrichton:hex-display-on-windows…
…, r=Kimundi

std: Render large exit codes as hex on Windows

On Windows process exit codes are never signals but rather always 32-bit
integers. Most faults like segfaults and such end up having large
integers used to represent them, like STATUS_ACCESS_VIOLATION being
0xC0000005. Currently, however, when an `ExitStatus` is printed this
ends up getting rendered as 3221225477 which is somewhat more difficult
to debug.

This commit adds a branch in `Display for ExitStatus` on Windows which
handles exit statuses where the high bit is set and prints those exit
statuses as hex instead of with decimals. This will hopefully preserve
the current display for small exit statuses (like `exit code: 22`), but
assist in quickly debugging segfaults/access violations/etc. I've
found at least that the hex codes are easier to search for than decimal.

I wasn't able to find any official documentation saying that all system
exit codes have the high bit set, but I figure it's a good enough
heuristic for now.

bors added a commit that referenced this pull request Jan 13, 2019

Auto merge of #57568 - Centril:rollup, r=Centril
Rollup of 16 pull requests

Successful merges:

 - #57351 (Don't actually create a full MIR stack frame when not needed)
 - #57353 (Optimise floating point `is_finite` (2x) and `is_infinite` (1.6x).)
 - #57412 (Improve the wording)
 - #57436 (save-analysis: use a fallback when access levels couldn't be computed)
 - #57453 (lldb_batchmode.py: try `import _thread` for Python 3)
 - #57454 (Some cleanups for core::fmt)
 - #57461 (Change `String` to `&'static str` in `ParseResult::Failure`.)
 - #57473 (std: Render large exit codes as hex on Windows)
 - #57474 (save-analysis: Get path def from parent in case there's no def for the path itself.)
 - #57494 (Speed up item_bodies for large match statements involving regions)
 - #57496 (re-do docs for core::cmp)
 - #57508 (rustdoc: Allow inlining of reexported crates and crate items)
 - #57547 (Use `ptr::eq` where applicable)
 - #57557 (resolve: Mark extern crate items as used in more cases)
 - #57560 (hygiene: Do not treat `Self` ctor as a local variable)
 - #57564 (Update the const fn tracking issue to the new metabug)

Failed merges:

r? @ghost

bors added a commit that referenced this pull request Jan 13, 2019

Auto merge of #57568 - Centril:rollup, r=Centril
Rollup of 16 pull requests

Successful merges:

 - #57351 (Don't actually create a full MIR stack frame when not needed)
 - #57353 (Optimise floating point `is_finite` (2x) and `is_infinite` (1.6x).)
 - #57412 (Improve the wording)
 - #57436 (save-analysis: use a fallback when access levels couldn't be computed)
 - #57453 (lldb_batchmode.py: try `import _thread` for Python 3)
 - #57454 (Some cleanups for core::fmt)
 - #57461 (Change `String` to `&'static str` in `ParseResult::Failure`.)
 - #57473 (std: Render large exit codes as hex on Windows)
 - #57474 (save-analysis: Get path def from parent in case there's no def for the path itself.)
 - #57494 (Speed up item_bodies for large match statements involving regions)
 - #57496 (re-do docs for core::cmp)
 - #57508 (rustdoc: Allow inlining of reexported crates and crate items)
 - #57547 (Use `ptr::eq` where applicable)
 - #57557 (resolve: Mark extern crate items as used in more cases)
 - #57560 (hygiene: Do not treat `Self` ctor as a local variable)
 - #57564 (Update the const fn tracking issue to the new metabug)

Failed merges:

r? @ghost

@bors bors merged commit bbb5448 into rust-lang:master Jan 13, 2019

@alexcrichton alexcrichton deleted the alexcrichton:hex-display-on-windows branch Jan 17, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment