annotate packages/language/cxx/ustl/current/src/uexception.cpp @ 3292:7f8e529b4d82 default tip

Fix FREESCALE_EDMA_NBYTES_MLOFFYES_MLOFF() so it works with negative offsets.
author vae
date Wed, 29 Apr 2015 23:31:48 +0000
parents 4885e0722884
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2904
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
1 // This file is part of the uSTL library, an STL implementation.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
2 //
3152
4885e0722884 * include/*:
sergeig
parents: 2910
diff changeset
3 // Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
2904
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
4 // This file is free software, distributed under the MIT License.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
5
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
6 #include "uexception.h"
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
7 #include "ustring.h"
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
8 #include "mistream.h"
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
9 #include "sostream.h"
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
10 #include "strmsize.h"
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
11 #include "uspecial.h"
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
12 #include <errno.h>
3152
4885e0722884 * include/*:
sergeig
parents: 2910
diff changeset
13
2904
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
14 #if HAVE_CXXABI_H && WANT_NAME_DEMANGLING
3152
4885e0722884 * include/*:
sergeig
parents: 2910
diff changeset
15 extern "C" char* __cxa_demangle (const char* mangled_name, char* output_buffer, size_t* length, int* status);
2904
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
16 #endif
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
17
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
18 namespace ustl {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
19
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
20 //----------------------------------------------------------------------
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
21
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
22 /// \brief Returns a descriptive error message. fmt="%s"
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
23 /// Overloads of this functions must set NULL as the default fmt
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
24 /// argument and handle that case to provide a default format string
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
25 /// in case the user does not have a localized one. The format
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
26 /// string should be shown in the documentation to not require
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
27 /// translators to look through code. Also, this function must
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
28 /// not throw anything, so you must wrap memory allocation routines
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
29 /// (like string::format, for instance) in a try{}catch(...){} block.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
30 ///
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
31 void exception::info (string& msgbuf, const char*) const throw()
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
32 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
33 USTL_TRY { msgbuf.format ("%s", what()); } USTL_CATCH_ALL;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
34 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
35
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
36 /// Reads the exception from stream \p is.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
37 void exception::read (istream& is)
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
38 {
2910
9e1cb7863bef * src/bktrace.cpp: prevent inclusion of host header <execinfo.h> (eCos builds
jld
parents: 2904
diff changeset
39 uint32_t stmSize = 0;
2904
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
40 xfmt_t fmt = xfmt_Exception;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
41 is >> fmt >> stmSize >> m_Backtrace;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
42 assert (fmt == m_Format && "The saved exception is of a different type.");
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
43 assert ((stmSize + 8) - exception::stream_size() <= is.remaining() && "The saved exception data is corrupt.");
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
44 m_Format = fmt;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
45 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
46
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
47 /// Writes the exception into stream \p os as an IFF chunk.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
48 void exception::write (ostream& os) const
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
49 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
50 os << m_Format << uint32_t(stream_size() - 8) << m_Backtrace;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
51 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
52
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
53 /// Writes the exception as text into stream \p os.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
54 void exception::text_write (ostringstream& os) const
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
55 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
56 USTL_TRY {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
57 string buf;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
58 info (buf);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
59 os << buf;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
60 } USTL_CATCH_ALL
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
61 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
62
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
63 //----------------------------------------------------------------------
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
64
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
65 /// Initializes the empty object. \p nBytes is the size of the attempted allocation.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
66 bad_alloc::bad_alloc (size_t nBytes) throw()
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
67 : ustl::exception(),
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
68 m_nBytesRequested (nBytes)
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
69 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
70 set_format (xfmt_BadAlloc);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
71 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
72
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
73 /// Returns a descriptive error message. fmt="failed to allocate %d bytes"
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
74 void bad_alloc::info (string& msgbuf, const char* fmt) const throw()
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
75 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
76 if (!fmt) fmt = "failed to allocate %d bytes";
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
77 USTL_TRY { msgbuf.format (fmt, m_nBytesRequested); } USTL_CATCH_ALL
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
78 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
79
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
80 /// Reads the exception from stream \p is.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
81 void bad_alloc::read (istream& is)
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
82 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
83 ustl::exception::read (is);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
84 is >> m_nBytesRequested;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
85 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
86
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
87 /// Writes the exception into stream \p os.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
88 void bad_alloc::write (ostream& os) const
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
89 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
90 ustl::exception::write (os);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
91 os << m_nBytesRequested;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
92 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
93
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
94 /// Returns the size of the written exception.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
95 size_t bad_alloc::stream_size (void) const
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
96 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
97 return (ustl::exception::stream_size() + stream_size_of(m_nBytesRequested));
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
98 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
99
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
100 //----------------------------------------------------------------------
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
101
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
102 /// Initializes the empty object. \p operation is the function that returned the error code.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
103 libc_exception::libc_exception (const char* operation) throw()
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
104 : exception(),
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
105 m_Errno (errno),
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
106 m_Operation (operation)
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
107 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
108 set_format (xfmt_LibcException);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
109 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
110
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
111 /// Copies object \p v.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
112 libc_exception::libc_exception (const libc_exception& v) throw()
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
113 : exception (v),
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
114 m_Errno (v.m_Errno),
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
115 m_Operation (v.m_Operation)
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
116 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
117 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
118
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
119 /// Copies object \p v.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
120 const libc_exception& libc_exception::operator= (const libc_exception& v)
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
121 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
122 m_Errno = v.m_Errno;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
123 m_Operation = v.m_Operation;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
124 return (*this);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
125 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
126
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
127 /// Returns a descriptive error message. fmt="%s: %m"
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
128 void libc_exception::info (string& msgbuf, const char* fmt) const throw()
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
129 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
130 if (!fmt) fmt = "%s: %d %s";
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
131 USTL_TRY { msgbuf.format (fmt, m_Operation, m_Errno, strerror(m_Errno)); } USTL_CATCH_ALL
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
132 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
133
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
134 /// Reads the exception from stream \p is.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
135 void libc_exception::read (istream& is)
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
136 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
137 exception::read (is);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
138 is >> m_Errno >> m_Operation;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
139 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
140
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
141 /// Writes the exception into stream \p os.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
142 void libc_exception::write (ostream& os) const
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
143 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
144 exception::write (os);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
145 os << m_Errno << m_Operation;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
146 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
147
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
148 /// Returns the size of the written exception.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
149 size_t libc_exception::stream_size (void) const
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
150 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
151 return (exception::stream_size() +
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
152 stream_size_of(m_Errno) +
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
153 stream_size_of(m_Operation));
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
154 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
155
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
156 //----------------------------------------------------------------------
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
157
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
158 /// Initializes the empty object. \p operation is the function that returned the error code.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
159 file_exception::file_exception (const char* operation, const char* filename) throw()
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
160 : libc_exception (operation)
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
161 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
162 memset (m_Filename, 0, VectorSize(m_Filename));
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
163 set_format (xfmt_FileException);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
164 if (filename) {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
165 strncpy (m_Filename, filename, VectorSize(m_Filename));
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
166 m_Filename [VectorSize(m_Filename) - 1] = 0;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
167 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
168 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
169
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
170 /// Returns a descriptive error message. fmt="%s %s: %m"
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
171 void file_exception::info (string& msgbuf, const char* fmt) const throw()
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
172 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
173 if (!fmt) fmt = "%s %s: %d %s";
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
174 USTL_TRY { msgbuf.format (fmt, m_Operation, m_Filename, m_Errno, strerror(m_Errno)); } USTL_CATCH_ALL
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
175 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
176
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
177 /// Reads the exception from stream \p is.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
178 void file_exception::read (istream& is)
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
179 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
180 libc_exception::read (is);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
181 string filename;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
182 is >> filename;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
183 is.align (8);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
184 filename.copyto (filename, VectorSize(m_Filename));
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
185 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
186
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
187 /// Writes the exception into stream \p os.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
188 void file_exception::write (ostream& os) const
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
189 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
190 libc_exception::write (os);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
191 os << string (m_Filename);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
192 os.align (8);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
193 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
194
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
195 /// Returns the size of the written exception.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
196 size_t file_exception::stream_size (void) const
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
197 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
198 return (libc_exception::stream_size() +
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
199 Align (stream_size_of (string (m_Filename)), 8));
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
200 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
201
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
202 //----------------------------------------------------------------------
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
203
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
204 /// \brief Uses C++ ABI call, if available to demangle the contents of \p buf.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
205 ///
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
206 /// The result is written to \p buf, with the maximum size of \p bufSize, and
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
207 /// is zero-terminated. The return value is \p buf.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
208 ///
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
209 const char* demangle_type_name (char* buf, size_t bufSize, size_t* pdmSize)
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
210 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
211 size_t bl = strlen (buf);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
212 #if HAVE_CXXABI_H && WANT_NAME_DEMANGLING
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
213 char dmname [256];
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
214 size_t sz = VectorSize(dmname);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
215 int bFailed;
3152
4885e0722884 * include/*:
sergeig
parents: 2910
diff changeset
216 __cxa_demangle (buf, dmname, &sz, &bFailed);
2904
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
217 if (!bFailed) {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
218 bl = min (strlen (dmname), bufSize - 1);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
219 memcpy (buf, dmname, bl);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
220 buf[bl] = 0;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
221 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
222 #else
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
223 bl = min (bl, bufSize);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
224 #endif
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
225 if (pdmSize)
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
226 *pdmSize = bl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
227 return (buf);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
228 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
229
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
230 //----------------------------------------------------------------------
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
231
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
232 /// Initializes the empty object. \p operation is the function that returned the error code.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
233 stream_bounds_exception::stream_bounds_exception (const char* operation, const char* type, uoff_t offset, size_t expected, size_t remaining) throw()
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
234 : libc_exception (operation),
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
235 m_TypeName (type),
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
236 m_Offset (offset),
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
237 m_Expected (expected),
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
238 m_Remaining (remaining)
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
239 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
240 set_format (xfmt_StreamBoundsException);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
241 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
242
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
243 /// Returns a descriptive error message. fmt="%s stream %s: @%u: expected %u, available %u";
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
244 void stream_bounds_exception::info (string& msgbuf, const char* fmt) const throw()
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
245 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
246 char typeName [256];
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
247 strncpy (typeName, m_TypeName, VectorSize(typeName));
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
248 typeName[VectorSize(typeName)-1] = 0;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
249 if (!fmt) fmt = "%s stream %s: @0x%X: need %u bytes, have %u";
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
250 USTL_TRY { msgbuf.format (fmt, demangle_type_name (VectorBlock(typeName)), m_Operation, m_Offset, m_Expected, m_Remaining); } USTL_CATCH_ALL
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
251 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
252
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
253 /// Reads the exception from stream \p is.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
254 void stream_bounds_exception::read (istream& is)
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
255 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
256 libc_exception::read (is);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
257 is >> m_TypeName >> m_Offset >> m_Expected >> m_Remaining;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
258 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
259
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
260 /// Writes the exception into stream \p os.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
261 void stream_bounds_exception::write (ostream& os) const
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
262 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
263 libc_exception::write (os);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
264 os << m_TypeName << m_Offset << m_Expected << m_Remaining;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
265 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
266
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
267 /// Returns the size of the written exception.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
268 size_t stream_bounds_exception::stream_size (void) const
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
269 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
270 return (libc_exception::stream_size() +
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
271 stream_size_of(m_TypeName) +
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
272 stream_size_of(m_Offset) +
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
273 stream_size_of(m_Expected) +
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
274 stream_size_of(m_Remaining));
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
275 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
276
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
277 } // namespace ustl