Class: Dtrace::Dof::Parser
- Inherits:
-
Object
- Object
- Dtrace::Dof::Parser
- Defined in:
- ext/dof/dof_api.c
Class Method Summary collapse
-
.parse(rdof) ⇒ Object
Parse the given DOF.
Class Method Details
.parse(rdof) ⇒ Object
Parse the given DOF
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
# File 'ext/dof/parser.c', line 333
VALUE dof_parse(VALUE self, VALUE rdof)
{
VALUE dof_data;
VALUE sec_data;
VALUE ctx;
VALUE sec;
char *dof;
char *pos;
dof_hdr_t dof_hdr;
dof_sec_t dof_sec;
int i;
ctx = rb_hash_new();
rb_cv_set(self, "@@ctx", ctx);
dof = STR2CSTR(rdof);
pos = dof;
memcpy(&dof_hdr, pos, sizeof(dof_hdr));
/* Check magic */
if (!(dof_hdr.dofh_ident[0] == DOF_MAG_MAG0 &&
dof_hdr.dofh_ident[1] == DOF_MAG_MAG1 &&
dof_hdr.dofh_ident[2] == DOF_MAG_MAG2 &&
dof_hdr.dofh_ident[3] == DOF_MAG_MAG3)) {
rb_raise(eDtraceDofException, "bad DOF header magic");
return Qnil;
}
pos += dof_hdr.dofh_hdrsize;
dof_data = rb_ary_new();
/* Walk section headers, parsing sections */
for (i = 0; i < dof_hdr.dofh_secnum; i++) {
memcpy(&dof_sec, pos, sizeof(struct dof_sec));
sec_data = rb_hash_new();
rb_hash_aset(sec_data, ID2SYM(rb_intern("index")), INT2FIX(i));
rb_hash_aset(sec_data, ID2SYM(rb_intern("type")), rb_str_new2(_dof_sec_type(dof_sec.dofs_type)));
rb_hash_aset(sec_data, ID2SYM(rb_intern("flags")), INT2FIX(dof_sec.dofs_flags));
sec = Qnil;
switch(dof_sec.dofs_type) {
case DOF_SECT_STRTAB:
sec = _dof_parse_string_table(self, dof, &dof_sec);
break;
case DOF_SECT_PROBES:
sec = _dof_parse_dof_probe_t_array(self, dof, &dof_sec);
break;
case DOF_SECT_PROVIDER:
sec = _dof_parse_dof_provider_t(self, dof, &dof_sec);
break;
case DOF_SECT_PRARGS:
sec = _dof_parse_uint8_t_array(self, dof, &dof_sec);
break;
case DOF_SECT_PRENOFFS:
case DOF_SECT_PROFFS:
sec = _dof_parse_uint32_t_array(self, dof, &dof_sec);
break;
case DOF_SECT_RELTAB:
sec = _dof_parse_dof_relodesc_t_array(self, dof, &dof_sec);
break;
case DOF_SECT_URELHDR:
sec = _dof_parse_dof_relohdr_t(self, dof, &dof_sec);
break;
case DOF_SECT_UTSNAME:
sec = _dof_parse_utsname(self, dof, &dof_sec);
break;
case DOF_SECT_COMMENTS:
sec = _dof_parse_comments(self, dof, &dof_sec);
break;
default:
sec = _dof_parse_unknown(self, dof, &dof_sec);
break;
}
rb_hash_aset(sec_data, ID2SYM(rb_intern("data")), sec);
rb_ary_push(dof_data, sec_data);
pos += dof_hdr.dofh_secsize;
}
return dof_data;
}
|