7 our $dir = Cwd
::realpath
("./.debuginfod");
10 # Kill the server and remove temporary files.
11 sub cleanup_and_exit
($) {
12 my $exit_code = $_[0];
13 mysystem
("rm -rf $dir");
20 # Propagate Ctrl-C and exit if command results in an error.
23 my $exit_code = system($_[0]);
24 ($exit_code == 2) and cleanup_and_exit
(1); # Exit if SIGINT
25 if ($exit_code != 0) {
26 #warn "Error while executing: $_[0]";
32 # Check that debuginfod and debuginfod-find can be found
33 mysystem
("debuginfod --help > /dev/null");
34 mysystem
("debuginfod-find --help > /dev/null");
36 $SIG{'INT'} = sub { cleanup_and_exit
(1) };
38 my $testname = "debuginfod-check";
39 my $tmp = "$dir/debuginfod_test.tmp";
41 mysystem
("rm -rf $dir");
42 mysystem
("mkdir -p $dbg");
44 # Compile the test executable, strip its debuginfo and store it so
45 # that valgrind cannot find it without debuginfod.
46 mysystem
("gcc -O0 -g -o $testname $testname.c");
47 mysystem
("objcopy --only-keep-debug $testname $testname.debug");
48 mysystem
("objcopy --strip-unneeded $testname");
49 mysystem
("objcopy --add-gnu-debuglink=$testname.debug $testname");
50 mysystem
("mv $testname.debug $dbg");
51 mysystem
("readelf -n $testname > $tmp 2>&1");
55 while (my $out = <TMP
>) {
56 if ($out =~ /Build ID: ([0-9a-f]*)/) {
62 warn "can't find $testname build-id";
70 while ($found_port == 0 and $port < 65536) {
72 $pid = open3
(undef, "TMP", undef,
73 "debuginfod", "-d", "$dir/db", '-F', "$dbg", "--port=$port");
74 for (my $i = 0; $i < 5 and $found_port == 0; $i++) {
75 while (my $got = <TMP
>) {
76 if ($got =~ /Failed to bind/) {
78 } elsif ($got =~ /started http server/) {
87 warn "No available ports";
93 # Confirm that the server is ready to be queried
94 for (my $i = 0; $i < 10 and $server_ready == 0; $i++) {
96 my $got = `curl -s http://localhost:$port/metrics`;
98 and $got =~ /thread_work_total\{role=\"traverse\"\} 1/
99 and $got =~ /thread_work_pending\{role=\"scan\"\} 0/
100 and $got =~ /thread_busy\{role=\"scan\"\} 0/) {
105 if ($server_ready == 0) {
106 warn "Can't start debuginfod server";
110 # Query the server and store the debuginfo in the client cache for valgrind to find.
111 my $myres = mysystem
("DEBUGINFOD_CACHE_PATH=$dir DEBUGINFOD_URLS=http://localhost:$port debuginfod-find debuginfo $buildid > /dev/null 2>&1");