Skip to content

Commit

Permalink
Add tests for dwo and dwp.
Browse files Browse the repository at this point in the history
The dwp tests are currently skipped because I haven't implemented dwp handling yet.
  • Loading branch information
mstange committed Apr 1, 2024
1 parent 63579bf commit 1339468
Show file tree
Hide file tree
Showing 29 changed files with 352 additions and 22 deletions.
46 changes: 46 additions & 0 deletions fixtures/other/simple-example/build-dwp-debuglink.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

mkdir -p out/dwp-debuglink

# Compile source files into object files
g++ -c -g -Os -Wall -Wextra -gsplit-dwarf src/main.cpp -o out/dwp-debuglink/main.o
g++ -c -g -Os -Wall -Wextra -gsplit-dwarf src/file1.cpp -o out/dwp-debuglink/file1.o
g++ -c -g -Os -Wall -Wextra -gsplit-dwarf src/file2.cpp -o out/dwp-debuglink/file2.o
g++ -c -g -Os -Wall -Wextra -gsplit-dwarf src/file3.cpp -o out/dwp-debuglink/file3.o

# Create libfile23.a from file2.o and file3.o
ar rcs out/dwp-debuglink/libfile23.a out/dwp-debuglink/file2.o out/dwp-debuglink/file3.o

# Link libraries into executable
g++ out/dwp-debuglink/main.o out/dwp-debuglink/file1.o out/dwp-debuglink/libfile23.a -o out/dwp-debuglink/main

# Make dwp file
dwp -e out/dwp-debuglink/main

# Extract dwp sections into individual files
objcopy --dump-section .debug_abbrev.dwo=out/dwp-debuglink/dwp-debug_abbrev.dwo.bin \
--dump-section .debug_line.dwo=out/dwp-debuglink/dwp-debug_line.dwo.bin \
--dump-section .debug_loc.dwo=out/dwp-debuglink/dwp-debug_loc.dwo.bin \
--dump-section .debug_str_offsets.dwo=out/dwp-debuglink/dwp-debug_str_offsets.dwo.bin \
--dump-section .debug_info.dwo=out/dwp-debuglink/dwp-debug_info.dwo.bin \
--dump-section .debug_str.dwo=out/dwp-debuglink/dwp-debug_str.dwo.bin \
--dump-section .debug_cu_index=out/dwp-debuglink/dwp-debug_cu_index.bin \
--dump-section .debug_tu_index=out/dwp-debuglink/dwp-debug_tu_index.bin \
out/dwp-debuglink/main.dwp

# Create main.dbg with debug sections from main and from dwp
objcopy --only-keep-debug \
--add-section .debug_abbrev.dwo=out/dwp-debuglink/dwp-debug_abbrev.dwo.bin \
--add-section .debug_line.dwo=out/dwp-debuglink/dwp-debug_line.dwo.bin \
--add-section .debug_loc.dwo=out/dwp-debuglink/dwp-debug_loc.dwo.bin \
--add-section .debug_str_offsets.dwo=out/dwp-debuglink/dwp-debug_str_offsets.dwo.bin \
--add-section .debug_info.dwo=out/dwp-debuglink/dwp-debug_info.dwo.bin \
--add-section .debug_str.dwo=out/dwp-debuglink/dwp-debug_str.dwo.bin \
--add-section .debug_cu_index=out/dwp-debuglink/dwp-debug_cu_index.bin \
--add-section .debug_tu_index=out/dwp-debuglink/dwp-debug_tu_index.bin \
out/dwp-debuglink/main out/dwp-debuglink/main.dbg
strip -g out/dwp-debuglink/main
objcopy --add-gnu-debuglink=out/dwp-debuglink/main.dbg out/dwp-debuglink/main

# Remove .dwo, .dwp, .bin, .o, .a files
rm out/dwp-debuglink/*.dwo out/dwp-debuglink/*.dwp out/dwp-debuglink/*.bin out/dwp-debuglink/*.o out/dwp-debuglink/*.a
23 changes: 23 additions & 0 deletions fixtures/other/simple-example/build-regular-debuglink.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

mkdir -p out/regular-debuglink

# Compile source files into object files
g++ -c -g -Os -Wall -Wextra src/main.cpp -o out/regular-debuglink/main.o
g++ -c -g -Os -Wall -Wextra src/file1.cpp -o out/regular-debuglink/file1.o
g++ -c -g -Os -Wall -Wextra src/file2.cpp -o out/regular-debuglink/file2.o
g++ -c -g -Os -Wall -Wextra src/file3.cpp -o out/regular-debuglink/file3.o

# Create libfile23.a from file2.o and file3.o
ar rcs out/regular-debuglink/libfile23.a out/regular-debuglink/file2.o out/regular-debuglink/file3.o

# Link libraries into executable
g++ out/regular-debuglink/main.o out/regular-debuglink/file1.o out/regular-debuglink/libfile23.a -o out/regular-debuglink/main

# Create main.dbg with debug sections
objcopy --only-keep-debug out/regular-debuglink/main out/regular-debuglink/main.dbg
strip -g out/regular-debuglink/main
objcopy --add-gnu-debuglink=out/regular-debuglink/main.dbg out/regular-debuglink/main

# Remove .o, .a files
rm out/regular-debuglink/*.o out/regular-debuglink/*.a
15 changes: 15 additions & 0 deletions fixtures/other/simple-example/build-with-dwo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

mkdir -p out/with-dwo

# Compile source files into object files
g++ -c -g -Os -Wall -Wextra -gsplit-dwarf src/main.cpp -o out/with-dwo/main.o
g++ -c -g -Os -Wall -Wextra -gsplit-dwarf src/file1.cpp -o out/with-dwo/file1.o
g++ -c -g -Os -Wall -Wextra -gsplit-dwarf src/file2.cpp -o out/with-dwo/file2.o
g++ -c -g -Os -Wall -Wextra -gsplit-dwarf src/file3.cpp -o out/with-dwo/file3.o

# Create libfile23.a from file2.o and file3.o
ar rcs out/with-dwo/libfile23.a out/with-dwo/file2.o out/with-dwo/file3.o

# Link libraries into executable
g++ out/with-dwo/main.o out/with-dwo/file1.o out/with-dwo/libfile23.a -o out/with-dwo/main
21 changes: 21 additions & 0 deletions fixtures/other/simple-example/build-with-dwp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

mkdir -p out/with-dwp

# Compile source files into object files
g++ -c -g -Os -Wall -Wextra -gsplit-dwarf src/main.cpp -o out/with-dwp/main.o
g++ -c -g -Os -Wall -Wextra -gsplit-dwarf src/file1.cpp -o out/with-dwp/file1.o
g++ -c -g -Os -Wall -Wextra -gsplit-dwarf src/file2.cpp -o out/with-dwp/file2.o
g++ -c -g -Os -Wall -Wextra -gsplit-dwarf src/file3.cpp -o out/with-dwp/file3.o

# Create libfile23.a from file2.o and file3.o
ar rcs out/with-dwp/libfile23.a out/with-dwp/file2.o out/with-dwp/file3.o

# Link libraries into executable
g++ out/with-dwp/main.o out/with-dwp/file1.o out/with-dwp/libfile23.a -o out/with-dwp/main

# Make dwp file
dwp -e out/with-dwp/main

# Remove .dwo, .o, .a files
rm out/with-dwp/*.dwo out/with-dwp/*.o out/with-dwp/*.a
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added fixtures/other/simple-example/out/with-dwo/main
Binary file not shown.
Binary file not shown.
Binary file added fixtures/other/simple-example/out/with-dwo/main.o
Binary file not shown.
Binary file added fixtures/other/simple-example/out/with-dwp/main
Binary file not shown.
Binary file not shown.
14 changes: 14 additions & 0 deletions fixtures/other/simple-example/src/file1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <iostream>

#include "file1.h"
#include "file2.h"
#include "file3.h"

int file1_func1(int x) {
std::cout << "Hello from file1.cpp file1_func1().\n";
return (file1_func2(x + 2) + file2_func1(x + 4)) << 2;
}

int file1_func2(int y) {
return file1_func3(y, file3_func1(y + 3)) + 5;
}
6 changes: 6 additions & 0 deletions fixtures/other/simple-example/src/file1.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
int file1_func1(int x);
int file1_func2(int y);

inline int file1_func3(int z, int w) {
return z * w + 5;
}
12 changes: 12 additions & 0 deletions fixtures/other/simple-example/src/file2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <iostream>

#include "file2.h"

int file2_func1(int x) {
std::cout << "Hello from file2.cpp file2_func1().\n";
return file2_func2(x + 2);
}

int file2_func2(int y) {
return file2_func3(y, 4) + 5;
}
6 changes: 6 additions & 0 deletions fixtures/other/simple-example/src/file2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
int file2_func1(int x);
int file2_func2(int y);

inline int file2_func3(int z, int w) {
return z * w + 5;
}
12 changes: 12 additions & 0 deletions fixtures/other/simple-example/src/file3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <iostream>

#include "file3.h"

int file3_func1(int x) {
std::cout << "Hello from file3.cpp file3_func1().\n";
return file3_func2(x + 2);
}

int file3_func2(int y) {
return file3_func3(y, 4) + 5;
}
6 changes: 6 additions & 0 deletions fixtures/other/simple-example/src/file3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
int file3_func1(int x);
int file3_func2(int y);

inline int file3_func3(int z, int w) {
return z * w + 5;
}
10 changes: 10 additions & 0 deletions fixtures/other/simple-example/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <iostream>

#include "file1.h"

int main() {
std::cout << "Hello from main()\n";
int r = file1_func1(15);
std::cout << "Number: " << r << "\n";
return 0;
}
1 change: 1 addition & 0 deletions wholesym/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ core-foundation = "0.9.1"

[dev-dependencies]
futures = "0.3.5"
tokio = { version = "1.17.0", features = ["macros"] } # Feature "macros" for #[tokio::test]
Loading

0 comments on commit 1339468

Please sign in to comment.