1
1
module ObjFileBase
2
2
3
- export ObjectHandle, SectionRef, SymbolRef
3
+ export ObjectHandle, SectionRef, SymbolRef, debugsections
4
+
5
+ export printfield, printentry, printfield_with_color, deref,
6
+ sectionaddress, sectionoffset, sectionsize, sectionname
4
7
5
8
import Base: read, seek, readbytes, position, show
6
9
@@ -97,6 +100,12 @@ abstract Section{T<:ObjectHandle}
97
100
# The offset of the section in the file
98
101
@mustimplement sectionoffset (section:: Section )
99
102
103
+ # The address of the section in virtual memory
104
+ @mustimplement sectionaddress (section:: Section )
105
+
106
+ # The name of the section
107
+ @mustimplement sectionname (section:: SectionRef )
108
+
100
109
# Retrieving the actual section datastructure
101
110
@mustimplement deref (section:: SectionRef )
102
111
@@ -106,9 +115,17 @@ abstract Section{T<:ObjectHandle}
106
115
abstract SymbolRef{T<: ObjectHandle }
107
116
abstract SymtabEntry{T<: ObjectHandle }
108
117
118
+ sectionsize (x:: SectionRef ) = sectionsize (deref (x))
119
+ sectionaddress (x:: SectionRef ) = sectionaddress (deref (x))
120
+ sectionoffset (x:: SectionRef ) = sectionoffset (deref (x))
121
+
109
122
handleT {T} (:: Union (Type{SectionRef{T}}, Type{Section{T}}, Type{SymbolRef{T}},
110
123
Type{SymtabEntry{T}})) = T
111
124
125
+ abstract StrTab
126
+
127
+ @mustimplement strtab_lookup (s:: StrTab , offset)
128
+
112
129
# ################################ Utilities ####################################
113
130
114
131
typealias SectionOrRef{T} Union (Section{T},SectionRef{T})
@@ -217,7 +234,7 @@ function DebugSections{T}(oh::T; debug_abbrev = nothing, debug_aranges = nothing
217
234
debug_ranges = nothing , debug_str = nothing , debug_types = nothing )
218
235
DebugSections (oh, debug_abbrev, debug_aranges, debug_frame, debug_info,
219
236
debug_line, debug_loc, debug_macinfo, debug_pubnames, debug_ranges,
220
- debug_pubnames, debug_ranges )
237
+ debug_str, debug_types )
221
238
end
222
239
223
240
function DebugSections {T<:ObjectHandle} (oh:: T , sections:: Dict )
@@ -299,15 +316,50 @@ function finddietreebyname(x::DebugSections, name;
299
316
cu,DWARF. DIETree)
300
317
end
301
318
319
+ function read (x:: DebugSections , :: Type{DWARF.ARTableSet} )
320
+ read (x. oh, deref (x. debug_aranges), DWARF. ARTableSet)
321
+ end
322
+
323
+ # Utils
324
+ # JIT Utils
325
+
326
+ function is_jit_section (s:: Section )
327
+ sectionaddress (s) > 0x100000
328
+ end
329
+ is_jit_section (s:: SectionRef ) = is_jit_section (deref (s))
330
+
331
+ @mustimplement replace_sections_from_memory (h:: ObjectHandle , buffer)
332
+
333
+ # Printing utils
334
+ function printfield (io:: IO ,string,fieldlength; align = :right )
335
+ (align == :right ) && print (io," " ^ max (fieldlength- length (string),0 ))
336
+ print (io,string)
337
+ (align == :left ) && print (io," " ^ max (fieldlength- length (string),0 ))
338
+ end
339
+ function printfield_with_color (color,io:: IO ,string,fieldlength; align = :right )
340
+ (align == :right ) && print (io," " ^ max (fieldlength- length (string),0 ))
341
+ print_with_color (color,io,string)
342
+ (align == :left ) && print (io," " ^ max (fieldlength- length (string),0 ))
343
+ end
344
+ printentry (io:: IO ,header,values... ) = (printfield (io,header,21 );println (io," " ,values... ))
302
345
303
346
# User facing interfaces
304
347
348
+ immutable MagicMismatch;
349
+ message
350
+ end
351
+
305
352
function readmeta (io:: IO )
306
353
ts = subtypes (ObjFileBase. ObjectHandle)
354
+ pos = position (io)
307
355
for T in ts
356
+ seek (io,pos)
308
357
try
309
358
return readmeta (io, T)
310
- catch
359
+ catch e
360
+ if ! isa (e,MagicMismatch)
361
+ rethrow (e)
362
+ end
311
363
end
312
364
end
313
365
error ("""
321
373
322
374
readmeta (file:: String ) = readmeta (open (file," r" ))
323
375
376
+ # Others
377
+
378
+ function getSectionLoadAddress
379
+ end
380
+
324
381
end # module
0 commit comments