Skip to content

Commit 0e09ebc

Browse files
committed
Add multiple_functions DWARF tests
1 parent 6a89355 commit 0e09ebc

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

src/LibObjectFile.Tests/Dwarf/DwarfTests.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/LibObjectFile.Tests/LibObjectFile.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111
<None Remove="helloworld.cpp" />
1212
<None Remove="lib_a.cpp" />
1313
<None Remove="lib_b.cpp" />
14+
<None Remove="multiple_functions.cpp" />
1415
<None Remove="small.cpp" />
1516
</ItemGroup>
1617

1718
<ItemGroup>
19+
<Content Include="multiple_functions.cpp">
20+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
21+
</Content>
1822
<Content Include="lib_b.cpp">
1923
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2024
</Content>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
int process_add(int a, int b)
2+
{
3+
return a + b;
4+
}
5+
6+
float process_add2(float a, float b)
7+
{
8+
return a + b;
9+
}
10+
11+
float process_both(int a, float b)
12+
{
13+
return (float)process_add(a, (int)b) + process_add2((float)a, b);
14+
}

0 commit comments

Comments
 (0)