@@ -199,6 +199,64 @@ public void TestDebugLineSmall()
199199 var cppName = "small" ;
200200 var cppObj = $ "{ cppName } _debug.o";
201201 LinuxUtil . RunLinuxExe ( "gcc" , $ "{ cppName } .cpp -g -c -o { cppObj } ") ;
202+ ElfObjectFile elf ;
203+ using ( var inStream = File . OpenRead ( cppObj ) )
204+ {
205+ Console . WriteLine ( $ "ReadBack from { cppObj } ") ;
206+ elf = ElfObjectFile . Read ( inStream ) ;
207+ elf . Print ( Console . Out ) ;
208+ }
209+
210+ var elfContext = new DwarfElfContext ( elf ) ;
211+ var inputContext = new DwarfReaderContext ( elfContext ) ;
212+ inputContext . DebugLinePrinter = Console . Out ;
213+ var dwarf = DwarfFile . Read ( inputContext ) ;
214+
215+ inputContext . DebugLineStream . Position = 0 ;
216+ var copyInputDebugLineStream = new MemoryStream ( ) ;
217+ inputContext . DebugLineStream . CopyTo ( copyInputDebugLineStream ) ;
218+ inputContext . DebugLineStream . Position = 0 ;
219+
220+ var outputContext = new DwarfWriterContext
221+ {
222+ IsLittleEndian = inputContext . IsLittleEndian ,
223+ AddressSize = inputContext . AddressSize ,
224+ DebugLineStream = new MemoryStream ( )
225+ } ;
226+ dwarf . Write ( outputContext ) ;
227+
228+ Console . WriteLine ( ) ;
229+ Console . WriteLine ( "=====================================================" ) ;
230+ Console . WriteLine ( "Readback" ) ;
231+ Console . WriteLine ( "=====================================================" ) ;
232+ Console . WriteLine ( ) ;
233+
234+ var reloadContext = new DwarfReaderContext ( )
235+ {
236+ IsLittleEndian = outputContext . IsLittleEndian ,
237+ AddressSize = outputContext . AddressSize ,
238+ DebugLineStream = outputContext . DebugLineStream
239+ } ;
240+
241+ reloadContext . DebugLineStream . Position = 0 ;
242+ reloadContext . DebugLineStream = outputContext . DebugLineStream ;
243+ reloadContext . DebugLinePrinter = Console . Out ;
244+
245+ var dwarf2 = DwarfFile . Read ( reloadContext ) ;
246+
247+ var inputDebugLineBuffer = copyInputDebugLineStream . ToArray ( ) ;
248+ var outputDebugLineBuffer = ( ( MemoryStream ) reloadContext . DebugLineStream ) . ToArray ( ) ;
249+ Assert . AreEqual ( inputDebugLineBuffer , outputDebugLineBuffer ) ;
250+ }
251+
252+
253+
254+ [ Test ]
255+ public void TestDebugLineMultipleFunctions ( )
256+ {
257+ var cppName = "multiple_functions" ;
258+ var cppObj = $ "{ cppName } _debug.o";
259+ LinuxUtil . RunLinuxExe ( "gcc" , $ "{ cppName } .cpp -g -c -o { cppObj } ") ;
202260
203261 ElfObjectFile elf ;
204262 using ( var inStream = File . OpenRead ( cppObj ) )
@@ -370,6 +428,8 @@ public void CreateDwarf()
370428 }
371429 }
372430 ) ;
431+ // NOTE: doesn't seem to be generated by regular GCC
432+ // (it seems that only one line sequence is usually used)
373433 lineTable . AddLineSequence ( new DwarfLineSequence ( )
374434 {
375435
0 commit comments