MXVM 1.8.1
Virtual Machine, Compiler, and Pascal Frontend
Loading...
Searching...
No Matches
exception.cpp
Go to the documentation of this file.
1
7#include <csignal>
8#include <cstdint>
9#include <iomanip>
10#include <iostream>
11#include <sstream>
12
13namespace mx {
14 std::string format_hex64(uint64_t value) {
15 std::ostringstream oss;
16 oss << "0x" << std::setfill('0') << std::setw(16) << std::hex << std::uppercase << value;
17 return oss.str();
18 }
19
20 std::string format_hex32(uint32_t value) {
21 std::ostringstream oss;
22 oss << "0x" << std::setfill('0') << std::setw(8) << std::hex << std::uppercase << value;
23 return oss.str();
24 }
25
26 std::string format_hex16(uint16_t value) {
27 std::ostringstream oss;
28 oss << "0x" << std::setfill('0') << std::setw(4) << std::hex << std::uppercase << value;
29 return oss.str();
30 }
31
32 std::string format_hex8(uint8_t value) {
33 std::ostringstream oss;
34 oss << "0x" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << static_cast<unsigned>(value);
35 return oss.str();
36 }
37
38 std::string format_hex_no_prefix(uint64_t value) {
39 std::ostringstream stream;
40 stream << std::hex << std::uppercase << value;
41 return stream.str();
42 }
43
44 std::string format_signal(uint32_t sig) {
45 switch (sig) {
46 case SIGHUP:
47 return "SIGHUP (Hangup)";
48 case SIGINT:
49 return "SIGINT (Interrupt)";
50 case SIGQUIT:
51 return "SIGQUIT (Quit)";
52 case SIGILL:
53 return "SIGILL (Illegal instruction)";
54 case SIGTRAP:
55 return "SIGTRAP (Trace/breakpoint trap)";
56 case SIGABRT:
57 return "SIGABRT (Aborted)";
58 case SIGBUS:
59 return "SIGBUS (Bus error)";
60 case SIGFPE:
61 return "SIGFPE (Floating point exception)";
62 case SIGKILL:
63 return "SIGKILL (Killed)";
64 case SIGUSR1:
65 return "SIGUSR1 (User defined signal 1)";
66 case SIGSEGV:
67 return "SIGSEGV (Segmentation fault)";
68 case SIGUSR2:
69 return "SIGUSR2 (User defined signal 2)";
70 case SIGPIPE:
71 return "SIGPIPE (Broken pipe)";
72 case SIGALRM:
73 return "SIGALRM (Alarm clock)";
74 case SIGTERM:
75 return "SIGTERM (Terminated)";
76 case SIGCHLD:
77 return "SIGCHLD (Child exited)";
78 case SIGCONT:
79 return "SIGCONT (Continued)";
80 case SIGSTOP:
81 return "SIGSTOP (Stopped)";
82 case SIGTSTP:
83 return "SIGTSTP (Stopped (tty input))";
84 case SIGTTIN:
85 return "SIGTTIN (Stopped (tty input))";
86 case SIGTTOU:
87 return "SIGTTOU (Stopped (tty output))";
88 case SIGURG:
89 return "SIGURG (Urgent I/O condition)";
90 case SIGXCPU:
91 return "SIGXCPU (CPU time limit exceeded)";
92 case SIGXFSZ:
93 return "SIGXFSZ (File size limit exceeded)";
94 case SIGVTALRM:
95 return "SIGVTALRM (Virtual timer expired)";
96 case SIGPROF:
97 return "SIGPROF (Profiling timer expired)";
98 case SIGWINCH:
99 return "SIGWINCH (Window size changed)";
100 case SIGIO:
101 return "SIGIO (I/O possible)";
102 case SIGPWR:
103 return "SIGPWR (Power failure)";
104 case SIGSYS:
105 return "SIGSYS (Bad system call)";
106
107 default:
108 if (sig >= SIGRTMIN && sig <= SIGRTMAX) {
109 std::ostringstream oss;
110 oss << "SIGRTMIN+" << (sig - SIGRTMIN) << " (Real-time signal)";
111 return oss.str();
112 }
113
114 std::ostringstream oss;
115 oss << "Unknown signal (" << sig << ")";
116 return oss.str();
117 }
118 }
119} // namespace mx
Exception class, hex formatting utilities, and terminal color definitions.
std::string format_hex8(uint8_t value)
Format an 8-bit value as a hex string with 0x prefix.
Definition exception.cpp:32
std::string format_signal(uint32_t sig)
Format a signal number as a descriptive string.
Definition exception.cpp:44
std::string format_hex64(uint64_t value)
Format a 64-bit value as a hex string with 0x prefix.
Definition exception.cpp:14
std::string format_hex32(uint32_t value)
Format a 32-bit value as a hex string with 0x prefix.
Definition exception.cpp:20
std::string format_hex_no_prefix(uint64_t value)
Format a 64-bit value as a hex string without 0x prefix.
Definition exception.cpp:38
std::string format_hex16(uint16_t value)
Format a 16-bit value as a hex string with 0x prefix.
Definition exception.cpp:26