Class: Dtrace::Dof::File

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/dtrace/dof/file.rb,
ext/dof/dof_api.c

Overview

Ruby-Dtrace © 2008 Chris Andrews <[email protected]>

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFile

Returns a new instance of File.



10
11
12
# File 'lib/dtrace/dof/file.rb', line 10

def initialize
  @sections = []
end

Instance Attribute Details

#sectionsObject

Returns the value of attribute sections.



8
9
10
# File 'lib/dtrace/dof/file.rb', line 8

def sections
  @sections
end

Instance Method Details

#<<(data) ⇒ Object

Appends the given string to the DOF file.



32
33
34
35
36
37
38
39
# File 'ext/dof/file.c', line 32

VALUE dof_file_append(VALUE self, VALUE data)
{
  dof_file_t *file;
  Data_Get_Struct(self, dof_file_t, file);
  
  memcpy((file->dof + file->offset), RSTRING(data)->ptr, RSTRING(data)->len);
  file->offset += RSTRING(data)->len;
}

#addrObject

Returns the memory address of the DOF file.



42
43
44
45
46
47
# File 'ext/dof/file.c', line 42

VALUE dof_file_addr(VALUE self)
{
  dof_file_t *file;
  Data_Get_Struct(self, dof_file_t, file);
  return INT2FIX(file->dof);
}

#dataObject

Returns the DOF itself.



50
51
52
53
54
55
# File 'ext/dof/file.c', line 50

VALUE dof_file_data(VALUE self)
{
  dof_file_t *file;
  Data_Get_Struct(self, dof_file_t, file);
  return rb_str_new(file->dof, file->offset);
}

#generateObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/dtrace/dof/file.rb', line 14

def generate
  hdr = Dtrace::Dof::Header.new
  hdr.secnum = @sections.length
  filesz = hdr.hdrlen
  loadsz = filesz
  dof_version = 1

  @sections.each do |s|
    # Presence of is_enabled probes forces DOF version 2.
    if s.section_type == DOF_SECT_PRENOFFS
      dof_version = 2
    end
    
    length = s.generate
    s.offset = filesz

    pad = 0
    if s.align > 1
      i = s.offset.to_f % s.align
      if i > 0
        pad = (s.align - i).to_i
        s.offset = pad + s.offset
        s.pad = "\000" * pad
      end
    end

    s.size = length + pad

    loadsz += s.size if (s.flags & 1) == 1 # DOF_SECF_LOAD
    filesz += s.size

  end
  
  hdr.loadsz = loadsz
  hdr.filesz = filesz
  hdr.dof_version = dof_version

  self << hdr.generate
  
  @sections.each do |s|
    self << s.generate_header
  end
    
  @sections.each do |s|
    self << s.pad if s.pad
    self << s.dof
  end
end