12
12
#ifdef _WIN32
13
13
typedef uint64_t traceoff_t ;
14
14
#define SEEKNAME _fseeki64
15
- #define SEEK (f,x ) { if (SEEKNAME (f, x, SEEK_SET) != 0 ) { throw (TraceException (" Unable to seek in trace to offset " + x )); } }
15
+ #define SEEK (f,x ) { if (SEEKNAME (f, x, SEEK_SET) != 0 ) { throw (TraceException (" Unable to seek in trace to offset " + std::to_string (x) )); } }
16
16
#define TELL (f ) _ftelli64(f)
17
17
#else
18
18
typedef off_t traceoff_t ;
19
19
#define SEEKNAME fseeko
20
- #define SEEK (f,x ) { if (SEEKNAME (f, x, SEEK_SET) != 0 ) { throw (TraceException (" Unable to seek in trace to offset " + x )); } }
20
+ #define SEEK (f,x ) { if (SEEKNAME (f, x, SEEK_SET) != 0 ) { throw (TraceException (" Unable to seek in trace to offset " + std::to_string (x) )); } }
21
21
#define TELL (f ) ftello(f)
22
22
#endif
23
23
@@ -46,7 +46,6 @@ namespace SerializedTrace {
46
46
frame_architecture arch,
47
47
uint64_t machine,
48
48
uint64_t frames_per_toc_entry_in)
49
- throw (TraceException)
50
49
: num_frames (0 )
51
50
, frames_per_toc_entry (frames_per_toc_entry_in)
52
51
, ofs(open_trace(filename,arch,machine,1LL )) {}
@@ -56,7 +55,6 @@ namespace SerializedTrace {
56
55
frame_architecture arch,
57
56
uint64_t machine,
58
57
uint64_t frames_per_toc_entry_in)
59
- throw (TraceException)
60
58
: num_frames (0 )
61
59
, frames_per_toc_entry (frames_per_toc_entry_in)
62
60
, ofs(open_trace(filename,arch,machine,2LL )) {
@@ -72,7 +70,7 @@ namespace SerializedTrace {
72
70
}
73
71
}
74
72
75
- void TraceContainerWriter::add (const frame &f) throw (TraceException) {
73
+ void TraceContainerWriter::add (const frame &f) {
76
74
if (num_frames > 0 && (num_frames % frames_per_toc_entry) == 0 ) {
77
75
toc.push_back (TELL (ofs));
78
76
}
@@ -111,7 +109,7 @@ namespace SerializedTrace {
111
109
ofs = NULL ;
112
110
}
113
111
114
- TraceContainerReader::TraceContainerReader (std::string filename) throw (TraceException)
112
+ TraceContainerReader::TraceContainerReader (std::string filename)
115
113
{
116
114
ifs = fopen (filename.c_str (), " rb" );
117
115
if (!ifs) { throw (TraceException (" Unable to open trace for reading" )); }
@@ -142,6 +140,18 @@ namespace SerializedTrace {
142
140
uint64_t toc_offset;
143
141
READ (toc_offset);
144
142
143
+ uint64_t meta_size;
144
+ READ (meta_size);
145
+ first_frame_offset = meta_offset + meta_size;
146
+
147
+ std::vector<uint8_t > meta_buf (meta_size);
148
+ if (fread (meta_buf.data (), 1 , meta_buf.size (), ifs) != meta_buf.size ()) {
149
+ throw (TraceException (" Unable to read meta frame" ));
150
+ }
151
+ if (!meta.ParseFromArray (meta_buf.data (), meta_buf.size ())) {
152
+ throw (TraceException (" Unable to parse meta frame" ));
153
+ }
154
+
145
155
/* Find the toc. */
146
156
SEEK (ifs, toc_offset);
147
157
@@ -166,31 +176,31 @@ namespace SerializedTrace {
166
176
seek (0 );
167
177
}
168
178
169
- TraceContainerReader::~TraceContainerReader (void ) throw () {
179
+ TraceContainerReader::~TraceContainerReader (void ) noexcept {
170
180
/* Nothing yet. */
171
181
}
172
182
173
- uint64_t TraceContainerReader::get_num_frames (void ) throw () {
183
+ uint64_t TraceContainerReader::get_num_frames (void ) noexcept {
174
184
return num_frames;
175
185
}
176
186
177
- uint64_t TraceContainerReader::get_frames_per_toc_entry (void ) throw () {
187
+ uint64_t TraceContainerReader::get_frames_per_toc_entry (void ) noexcept {
178
188
return frames_per_toc_entry;
179
189
}
180
190
181
- frame_architecture TraceContainerReader::get_arch (void ) throw () {
191
+ frame_architecture TraceContainerReader::get_arch (void ) noexcept {
182
192
return arch;
183
193
}
184
194
185
- uint64_t TraceContainerReader::get_machine (void ) throw () {
195
+ uint64_t TraceContainerReader::get_machine (void ) noexcept {
186
196
return mach;
187
197
}
188
198
189
- uint64_t TraceContainerReader::get_trace_version (void ) throw () {
199
+ uint64_t TraceContainerReader::get_trace_version (void ) noexcept {
190
200
return trace_version;
191
201
}
192
202
193
- void TraceContainerReader::seek (uint64_t frame_number) throw (TraceException) {
203
+ void TraceContainerReader::seek (uint64_t frame_number) {
194
204
/* First, make sure the frame is in range. */
195
205
check_end_of_trace_num (frame_number, " seek() to non-existant frame" );
196
206
@@ -215,68 +225,62 @@ namespace SerializedTrace {
215
225
}
216
226
}
217
227
218
- std::auto_ptr <frame> TraceContainerReader::get_frame (void ) throw (TraceException ) {
228
+ std::unique_ptr <frame> TraceContainerReader::get_frame (void ) {
219
229
/* Make sure we are in bounds. */
220
230
check_end_of_trace (" get_frame() on non-existant frame" );
221
231
222
232
uint64_t frame_len;
223
233
READ (frame_len);
224
234
if (frame_len == 0 ) {
225
- throw (TraceException (" Read zero-length frame at offset " + TELL (ifs)));
235
+ throw (TraceException (" Read zero-length frame at offset " + std::to_string ( TELL (ifs) )));
226
236
}
227
237
228
- /* We really just want a variable sized array, but MS VC++ doesn't support C99 yet.
229
- *
230
- * http://stackoverflow.com/questions/5246900/enabling-vlasvariable-length-arrays-in-ms-visual-c
231
- */
232
- auto_vec<char > buf ( new char [frame_len] );
238
+ std::vector<uint8_t > buf (frame_len);
233
239
234
240
/* Read the frame into buf. */
235
- if (fread (buf.get (), 1 , frame_len, ifs) != frame_len) {
241
+ if (fread (buf.data (), 1 , frame_len, ifs) != frame_len) {
236
242
throw (TraceException (" Unable to read frame from trace" ));
237
243
}
238
244
239
- std::string sbuf (buf.get (), frame_len);
240
-
241
- std::auto_ptr<frame> f (new frame);
242
- if (!(f->ParseFromString (sbuf))) {
245
+ std::unique_ptr<frame> f (new frame);
246
+ if (!(f->ParseFromArray (buf.data (), buf.size ()))) {
243
247
throw (TraceException (" Unable to parse from string" ));
244
248
}
245
249
current_frame++;
246
250
247
251
return f;
248
252
}
249
253
250
- std::auto_ptr <std::vector<frame> > TraceContainerReader::get_frames (uint64_t requested_frames) throw (TraceException ) {
254
+ std::unique_ptr <std::vector<frame> > TraceContainerReader::get_frames (uint64_t requested_frames) {
251
255
check_end_of_trace (" get_frames() on non-existant frame" );
252
256
253
- std::auto_ptr <std::vector<frame> > frames (new std::vector<frame>);
257
+ std::unique_ptr <std::vector<frame> > frames (new std::vector<frame>);
254
258
for (uint64_t i = 0 ; i < requested_frames && current_frame < num_frames; i++) {
255
259
frames->push_back (*(get_frame ()));
256
260
}
257
261
258
262
return frames;
259
263
}
260
264
261
- bool TraceContainerReader::end_of_trace (void ) throw () {
265
+ bool TraceContainerReader::end_of_trace (void ) noexcept {
262
266
return end_of_trace_num (current_frame);
263
267
}
264
268
265
- bool TraceContainerReader::end_of_trace_num (uint64_t frame_num) throw () {
269
+ bool TraceContainerReader::end_of_trace_num (uint64_t frame_num) noexcept {
266
270
if (frame_num + 1 > num_frames) {
267
271
return true ;
268
272
} else {
269
273
return false ;
270
274
}
271
275
}
272
276
273
- void TraceContainerReader::check_end_of_trace_num (uint64_t frame_num, std::string msg) throw (TraceException) {
277
+ void TraceContainerReader::check_end_of_trace_num (uint64_t frame_num, std::string msg) {
274
278
if (end_of_trace_num (frame_num)) {
275
279
throw (TraceException (msg));
276
280
}
277
281
}
278
282
279
- void TraceContainerReader::check_end_of_trace (std::string msg) throw (TraceException) {
283
+ void TraceContainerReader::check_end_of_trace (std::string msg) {
280
284
return check_end_of_trace_num (current_frame, msg);
281
285
}
282
286
};
0 commit comments