1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940
|
# debugedit.at: Tests for the debugedit tool
#
# Copyright (C) 2019, 2024, 2025 Mark J. Wielaard <mark@klomp.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see see <http://www.gnu.org/licenses/>.
# Tests for the tools/debugedit program.
AT_BANNER([debugedit])
# Show which debugedit binary we are testing.
AT_TESTED([debugedit])
# Helper to create some test binaries.
# Optional fist parameter can specify additional gcc parameters.
# e.g. -gdwarf-4 or -gdwarf-5 for explicit DWARF version.
# -g3 is always given. Second parameter can be a compression flag
# like $GZ_ZLIB_FLAG (if it exists), when not given $GZ_NONE_FLAG
# is used.
m4_define([DEBUGEDIT_SETUP],[[
# Create some test binaries. Create and build them in different subdirs
# to make sure they produce different relative/absolute paths.
export HOME=${PWD}
mkdir subdir_foo
cp "${abs_srcdir}"/data/SOURCES/foo.c subdir_foo
mkdir subdir_bar
cp "${abs_srcdir}"/data/SOURCES/bar.c subdir_bar
mkdir subdir_headers
cp "${abs_srcdir}"/data/SOURCES/foobar.h subdir_headers
cp "${abs_srcdir}"/data/SOURCES/baz.c .
# Check second param, if given use compression
if test -z "$2"; then
GZ_FLAG=$GZ_NONE_FLAG
else
GZ_FLAG=$2
fi
# First three object files (foo.o subdir_bar/bar.o and baz.o)
$CC $CFLAGS -g3 $GZ_FLAG -Isubdir_headers $1 -c subdir_foo/foo.c
cd subdir_bar
$CC $CFLAGS -g3 $GZ_FLAG -I../subdir_headers $1 -c bar.c
cd ..
$CC $CFLAGS -g3 $GZ_FLAG -I$(pwd)/subdir_headers $1 -c $(pwd)/baz.c
# Then a partially linked object file (somewhat like a kernel module).
# This will still have relocations between the debug sections.
$LD $LDFLAGS -r -o foobarbaz.part.o foo.o subdir_bar/bar.o baz.o
# Create an executable. Relocations between debug sections will
# have been resolved.
$CC $CFLAGS -g3 $GZ_FLAG $1 -o foobarbaz.exe foo.o subdir_bar/bar.o baz.o
]])
# ===
# Check debugedit --help doesn't crash and burn.
# ===
AT_SETUP([debugedit help])
AT_KEYWORDS([debuginfo] [debugedit])
AT_CHECK([debugedit --help],[0],[ignore],[ignore])
AT_CLEANUP
# ===
# Check debugedit usage.
# ===
AT_SETUP([debugedit usage])
AT_KEYWORDS([debuginfo] [debugedit])
AT_CHECK([debugedit --usage],[0],[ignore],[])
AT_CHECK([debugedit],[1],[],[ignore])
AT_CHECK([debugedit . ..],[1],[],[ignore])
AT_CLEANUP
# ===
# Make sure that an executable still runs after debugedit munged it.
# ===
AT_SETUP([debugedit executable])
AT_KEYWORDS([debuginfo] [debugedit])
DEBUGEDIT_SETUP
AT_CHECK([[./foobarbaz.exe]])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.exe]])
AT_CHECK([[./foobarbaz.exe]])
AT_CLEANUP
AT_SETUP([debugedit executable (compressed)])
AT_KEYWORDS([debuginfo] [debugedit])
AT_SKIP_IF([test -z "$GZ_ZLIB_FLAG"])
AT_SKIP_IF([test "$READELF_VERSION_OK" = "no"])
DEBUGEDIT_SETUP([], [$GZ_ZLIB_FLAG])
AT_CHECK([[./foobarbaz.exe]])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.exe]])
AT_CHECK([[./foobarbaz.exe]])
AT_CLEANUP
# ===
# debugedit should at least replace the .debug_str directory paths
# in the objects.
# ===
AT_SETUP([debugedit .debug_str objects DWARF4])
AT_KEYWORDS([debuginfo] [debugedit])
DEBUGEDIT_SETUP([-gdwarf-4])
# Capture strings that start with the testdir (pwd) directory path
# (and replace that textually with /foo/bar/baz)
($READELF -zp.debug_str foo.o; \
$READELF -zp.debug_str subdir_bar/bar.o; \
$READELF -zp.debug_str baz.o) \
| cut -c13- \
| grep ^$(pwd) | sort \
| sed -e "s@$(pwd)@/foo/bar/baz@" > expout
# Make sure there is at least some output
expout_lines=$(wc --lines expout | cut -f1 -d\ )
if test $expout_lines -lt 3; then
echo "Expecting at least 3 debug strings starting with ${testdir}" >> expout
fi
# Check the replaced strings are all there.
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foo.o]])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./subdir_bar/bar.o]])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./baz.o]])
AT_CHECK([[
($READELF -zp.debug_str foo.o; \
$READELF -zp.debug_str subdir_bar/bar.o; \
$READELF -zp.debug_str baz.o) \
| cut -c13- \
| grep ^/foo/bar/baz | sort
]],[0],[expout])
AT_CLEANUP
# ===
# debugedit should at least replace the .debug_str/line_str directory paths
# in the objects.
# ===
AT_SETUP([debugedit .debug_str/line_str objects DWARF5])
AT_KEYWORDS([debuginfo] [debugedit])
AT_SKIP_IF([test "$GDWARF_5_FLAG" = "no"])
DEBUGEDIT_SETUP([-gdwarf-5])
# Capture strings that start with the testdir (pwd) directory path
# (and replace that textually with /foo/bar/baz)
($READELF -zp.debug_str -zp.debug_line_str foo.o; \
$READELF -zp.debug_str -zp.debug_line_str subdir_bar/bar.o; \
$READELF -zp.debug_str -zp.debug_line_str baz.o) \
| cut -c13- \
| grep ^$(pwd) | sort | uniq \
| sed -e "s@$(pwd)@/foo/bar/baz@" > expout
# Make sure there is at least some output
expout_lines=$(wc --lines expout | cut -f1 -d\ )
if test $expout_lines -lt 3; then
echo "Expecting at least 3 debug strings starting with ${testdir}" >> expout
fi
# Check the replaced strings are all there.
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foo.o]])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./subdir_bar/bar.o]])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./baz.o]])
AT_CHECK([[
($READELF -zp.debug_str -zp.debug_line_str foo.o; \
$READELF -zp.debug_str -zp.debug_line_str subdir_bar/bar.o; \
$READELF -zp.debug_str -zp.debug_line_str baz.o) \
| cut -c13- \
| grep ^/foo/bar/baz | sort | uniq
]],[0],[expout],[ignore])
AT_CLEANUP
# ===
# debugedit should at least replace the .debug_str directory paths
# also in partially linked files.
# ===
AT_SETUP([debugedit .debug_str partial DWARF4])
AT_KEYWORDS([debuginfo] [debugedit])
DEBUGEDIT_SETUP([-gdwarf-4])
# Capture strings that start with the testdir (pwd) directory path
# (and replace that textually with /foo/bar/baz)
# Note that partially linked files, might have multiple duplicate
# strings, but debugedit will merge them. So use sort -u.
$READELF -zp.debug_str ./foobarbaz.part.o | cut -c13- \
| grep ^$(pwd) | sort -u \
| sed -e "s@$(pwd)@/foo/bar/baz@" > expout
# Make sure there is at least some output
expout_lines=$(wc --lines expout | cut -f1 -d\ )
if test $expout_lines -lt 3; then
echo "Expecting at least 3 debug strings starting with ${testdir}" >> expout
fi
# Check the replaced strings are all there.
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.part.o]])
AT_CHECK([[
$READELF -zp.debug_str ./foobarbaz.part.o | cut -c13- \
| grep ^/foo/bar/baz | sort
]],[0],[expout])
AT_CLEANUP
# ===
# debugedit should at least replace the .debug_str/line_str directory paths
# also in partially linked files.
# ===
AT_SETUP([debugedit .debug_str/line_str partial DWARF5])
AT_KEYWORDS([debuginfo] [debugedit])
AT_SKIP_IF([test "$GDWARF_5_FLAG" = "no"])
DEBUGEDIT_SETUP([-gdwarf-5])
# Capture strings that start with the testdir (pwd) directory path
# (and replace that textually with /foo/bar/baz)
# Note that partially linked files, might have multiple duplicate
# strings, but debugedit will merge them. So use sort -u.
$READELF -zp.debug_str -zp.debug_line_str ./foobarbaz.part.o | cut -c13- \
| grep ^$(pwd) | sort -u | uniq \
| sed -e "s@$(pwd)@/foo/bar/baz@" > expout
# Make sure there is at least some output
expout_lines=$(wc --lines expout | cut -f1 -d\ )
if test $expout_lines -lt 3; then
echo "Expecting at least 3 debug strings starting with ${testdir}" >> expout
fi
# Check the replaced strings are all there.
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.part.o]])
AT_CHECK([[
$READELF -zp.debug_str -zp.debug_line_str ./foobarbaz.part.o | cut -c13- \
| grep ^/foo/bar/baz | sort | uniq
]],[0],[expout],[ignore])
AT_CLEANUP
# ===
# debugedit should at least replace the .debug_str directory paths
# and in the executable.
# ===
AT_SETUP([debugedit .debug_str exe DWARF4])
AT_KEYWORDS([debuginfo] [debugedit])
DEBUGEDIT_SETUP([-gdwarf-4])
# Capture strings that start with the testdir (pwd) directory path
# (and replace that textually with /foo/bar/baz)
$READELF -zp.debug_str foobarbaz.exe | cut -c13- \
| grep ^$(pwd) | sort \
| sed -e "s@$(pwd)@/foo/bar/baz@" > expout
# Make sure there is at least some output
# The linker will have merged unique strings, so no need for sort -u.
expout_lines=$(wc --lines expout | cut -f1 -d\ )
if test $expout_lines -lt 3; then
echo "Expecting at least 3 debug strings starting with ${testdir}" >> expout
fi
# Check the replaced strings are all there.
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.exe]])
AT_CHECK([[
$READELF -zp.debug_str foobarbaz.exe | cut -c13- \
| grep ^/foo/bar/baz | sort
]],[0],[expout])
AT_CLEANUP
# ===
# debugedit should at least replace the .debug_str/line_str directory paths
# and in the executable.
# ===
AT_SETUP([debugedit .debug_str/line_str exe DWARF5])
AT_KEYWORDS([debuginfo] [debugedit])
AT_SKIP_IF([test "$GDWARF_5_FLAG" = "no"])
DEBUGEDIT_SETUP([-gdwarf-5])
# Capture strings that start with the testdir (pwd) directory path
# (and replace that textually with /foo/bar/baz)
$READELF -zp.debug_str -zp.debug_line_str foobarbaz.exe | cut -c13- \
| grep ^$(pwd) | sort | uniq \
| sed -e "s@$(pwd)@/foo/bar/baz@" > expout
# Make sure there is at least some output
# The linker will have merged unique strings, so no need for sort -u.
expout_lines=$(wc --lines expout | cut -f1 -d\ )
if test $expout_lines -lt 3; then
echo "Expecting at least 3 debug strings starting with ${testdir}" >> expout
fi
# Check the replaced strings are all there.
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.exe]])
AT_CHECK([[
$READELF -zp.debug_str -zp.debug_line_str foobarbaz.exe | cut -c13- \
| grep ^/foo/bar/baz | sort | uniq
]],[0],[expout],[ignore])
AT_CLEANUP
# For .debug_info we expect the following DW_AT_name and DW_AT_comp_dir
# strings for the DW_TAG_compile_unit:
# - foo.o
# DW_AT_name: subdir_foo/foo.c
# DW_AT_comp_dir: /foo/baz/baz
# - bar.o
# DW_AT_name: bar.c
# DW_AT_comp_dir: /foo/bar/baz/subdir_bar
# - baz.o
# DW_AT_name: /foo/bar/baz/baz.c
# DW_AT_comp_dir: /foo/baz/baz
#
# Older gcc (before 7) don't emit the DW_AT_comp_dir for baz.o.
# But because it is similar to the comp_dir of foo.o, just sort -u.
# ===
# Make sure DW_AT_name and DW_AT_comp_dir strings are replaced
# in objects.
# ===
AT_SETUP([debugedit .debug_info objects])
AT_KEYWORDS([debuginfo] [debugedit])
DEBUGEDIT_SETUP
AT_DATA([expout],
[/foo/bar/baz
/foo/bar/baz/baz.c
/foo/bar/baz/subdir_bar
])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foo.o]])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./subdir_bar/bar.o]])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./baz.o]])
AT_CHECK([[
($READELF --debug-dump=info foo.o; \
$READELF --debug-dump=info subdir_bar/bar.o; \
$READELF --debug-dump=info baz.o) \
| grep -E 'DW_AT_(name|comp_dir)' \
| rev | cut -d: -f1 | rev | cut -c2- | grep ^/foo/bar/baz | sort -u
]],[0],[expout],[ignore])
AT_CLEANUP
AT_SETUP([debugedit .debug_info objects (compressed)])
AT_KEYWORDS([debuginfo] [debugedit])
AT_SKIP_IF([test -z "$GZ_ZLIB_FLAG"])
AT_SKIP_IF([test "$READELF_VERSION_OK" = "no"])
DEBUGEDIT_SETUP([], [$GZ_ZLIB_FLAG])
AT_DATA([expout],
[/foo/bar/baz
/foo/bar/baz/baz.c
/foo/bar/baz/subdir_bar
])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foo.o]])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./subdir_bar/bar.o]])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./baz.o]])
AT_CHECK([[
($READELF --debug-dump=info foo.o; \
$READELF --debug-dump=info subdir_bar/bar.o; \
$READELF --debug-dump=info baz.o) \
| grep -E 'DW_AT_(name|comp_dir)' \
| rev | cut -d: -f1 | rev | cut -c2- | grep ^/foo/bar/baz | sort -u
]],[0],[expout],[ignore])
AT_CLEANUP
# ===
# Make sure DW_AT_name and DW_AT_comp_dir strings are replaced
# in partial linked object.
# ===
AT_SETUP([debugedit .debug_info partial])
AT_KEYWORDS([debuginfo] [debugedit])
DEBUGEDIT_SETUP
AT_DATA([expout],
[/foo/bar/baz
/foo/bar/baz/baz.c
/foo/bar/baz/subdir_bar
])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.part.o]])
AT_CHECK([[
$READELF --debug-dump=info ./foobarbaz.part.o \
| grep -E 'DW_AT_(name|comp_dir)' \
| rev | cut -d: -f1 | rev | cut -c2- | grep ^/foo/bar/baz | sort -u
]],[0],[expout],[ignore])
AT_CLEANUP
AT_SETUP([debugedit .debug_info partial (compressed)])
AT_KEYWORDS([debuginfo] [debugedit])
AT_SKIP_IF([test -z "$GZ_ZLIB_FLAG"])
AT_SKIP_IF([test "$READELF_VERSION_OK" = "no"])
DEBUGEDIT_SETUP([], [$GZ_ZLIB_FLAG])
AT_DATA([expout],
[/foo/bar/baz
/foo/bar/baz/baz.c
/foo/bar/baz/subdir_bar
])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.part.o]])
AT_CHECK([[
$READELF --debug-dump=info ./foobarbaz.part.o \
| grep -E 'DW_AT_(name|comp_dir)' \
| rev | cut -d: -f1 | rev | cut -c2- | grep ^/foo/bar/baz | sort -u
]],[0],[expout],[ignore])
AT_CLEANUP
# ===
# Make sure DW_AT_name and DW_AT_comp_dir strings are replaced
# in executable.
# ===
AT_SETUP([debugedit .debug_info exe])
AT_KEYWORDS([debuginfo] [debugedit])
DEBUGEDIT_SETUP
AT_DATA([expout],
[/foo/bar/baz
/foo/bar/baz/baz.c
/foo/bar/baz/subdir_bar
])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.exe]])
AT_CHECK([[
$READELF --debug-dump=info ./foobarbaz.exe | grep -E 'DW_AT_(name|comp_dir)' \
| rev | cut -d: -f1 | rev | cut -c2- | grep ^/foo/bar/baz | sort -u
]],[0],[expout],[ignore])
AT_CLEANUP
AT_SETUP([debugedit .debug_info exe (compressed)])
AT_KEYWORDS([debuginfo] [debugedit])
AT_SKIP_IF([test -z "$GZ_ZLIB_FLAG"])
AT_SKIP_IF([test "$READELF_VERSION_OK" = "no"])
DEBUGEDIT_SETUP([], [$GZ_ZLIB_FLAG])
AT_DATA([expout],
[/foo/bar/baz
/foo/bar/baz/baz.c
/foo/bar/baz/subdir_bar
])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.exe]])
AT_CHECK([[
$READELF --debug-dump=info ./foobarbaz.exe | grep -E 'DW_AT_(name|comp_dir)' \
| rev | cut -d: -f1 | rev | cut -c2- | grep ^/foo/bar/baz | sort -u
]],[0],[expout],[ignore])
AT_CLEANUP
# ===
# Make sure -fdebug-types-section has updated strings in objects.
# Currently only works with DWARF4
# ===
AT_SETUP([debugedit .debug_types objects])
AT_KEYWORDS([debugtypes] [debugedit])
DEBUGEDIT_SETUP([-fdebug-types-section -gdwarf-4])
AT_SKIP_IF([! $READELF -S ./foo.o ./subdir_bar/bar.o ./baz.o | grep -F -q '.debug_types'])
AT_DATA([expout],
[st1
stf
stringp1
stringp_foo
st1
stb
stringp1
stringp_bar
st1
stringp1
stringp_baz
stz
])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foo.o]])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./subdir_bar/bar.o]])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./baz.o]])
AT_CHECK([[
for i in ./foo.o ./subdir_bar/bar.o ./baz.o;do \
$READELF --debug-dump=info $i \
| awk '/Abbrev Number:.*DW_TAG_type_unit/{p=1}{if(p)print}/^$/{p=0}' \
| sed -n 's/^.*> *DW_AT_name *:.* \(stringp[^ ]*\|st.\)$/\1/p' \
| sort;
done
]],[0],[expout],[ignore])
AT_CLEANUP
# ===
# Make sure -fdebug-types-section has updated strings in partial linked object.
# Currently only works with DWARF4
# ===
AT_SETUP([debugedit .debug_types partial])
AT_KEYWORDS([debugtypes] [debugedit])
DEBUGEDIT_SETUP([-fdebug-types-section -gdwarf-4])
AT_SKIP_IF([! $READELF -S ./foobarbaz.part.o | grep -F -q '.debug_types'])
AT_DATA([expout],
[st1
stb
stf
stringp1
stringp_bar
stringp_baz
stringp_foo
stz
])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.part.o]])
AT_CHECK([[
$READELF --debug-dump=info ./foobarbaz.part.o \
| awk '/Abbrev Number:.*DW_TAG_type_unit/{p=1}{if(p)print}/^$/{p=0}' \
| sed -n 's/^.*> *DW_AT_name *:.* \(stringp[^ ]*\|st.\)$/\1/p' \
| sort
]],[0],[expout],[ignore])
AT_CLEANUP
# ===
# Make sure -fdebug-types-section has updated strings in executable.
# DWARF4
# ===
AT_SETUP([debugedit .debug_types exe DWARF4])
AT_KEYWORDS([debugtypes] [debugedit])
DEBUGEDIT_SETUP([-fdebug-types-section -gdwarf-4])
AT_SKIP_IF([! $READELF -S ./foobarbaz.exe | grep -F -q '.debug_types'])
AT_DATA([expout],
[st1
stb
stf
stringp1
stringp_bar
stringp_baz
stringp_foo
stz
])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.exe]])
AT_CHECK([[
$READELF --debug-dump=info ./foobarbaz.exe \
| awk '/Abbrev Number:.*DW_TAG_type_unit/{p=1}{if(p)print}/^$/{p=0}' \
| sed -n 's/^.*> *DW_AT_name *:.* \(stringp[^ ]*\|st.\)$/\1/p' \
| sort
]],[0],[expout],[ignore])
AT_CLEANUP
# ===
# Make sure -fdebug-types-section has updated strings in executable.
# DWARF5
# ===
AT_SETUP([debugedit .debug_types exe DWARF5])
AT_KEYWORDS([debugtypes] [debugedit])
DEBUGEDIT_SETUP([-fdebug-types-section -gdwarf-5])
AT_SKIP_IF([test "$GDWARF_5_FLAG" = "no"])
AT_SKIP_IF([! $READELF --debug-dump=info ./foobarbaz.exe | grep -F -q 'DW_TAG_type_unit'])
AT_DATA([expout],
[st1
stb
stf
stringp1
stringp_bar
stringp_baz
stringp_foo
stz
])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.exe]])
AT_CHECK([[
$READELF --debug-dump=info ./foobarbaz.exe \
| awk '/Abbrev Number:.*DW_TAG_type_unit/{p=1}{if(p)print}/^$/{p=0}' \
| sed -n 's/^.*> *DW_AT_name *:.* \(stringp[^ ]*\|st.\)$/\1/p' \
| sort
]],[0],[expout],[ignore])
AT_CLEANUP
# foo.o and bar.o are build with relative paths and so will use the
# comp_dir (from .debug_info). But bar.o is build from sources with
# an absolute path, so the .debug_line Directory Table should contain
# /foo/bar/baz and /foo/bar/baz/subdir_headers.
# ===
# Make sure .debug_line Directory Table entries are replaced
# in objects.
# ===
AT_SETUP([debugedit .debug_line objects DWARF4])
AT_KEYWORDS([debuginfo] [debugedit])
DEBUGEDIT_SETUP([-gdwarf-4])
($READELF --debug-dump=line foo.o; \
$READELF --debug-dump=line subdir_bar/bar.o; \
$READELF --debug-dump=line baz.o) \
| grep -E -A5 "The (Directory|File Name) Table" \
| grep "^ [[1234]]" \
| sed -e "s@$(pwd)@/foo/bar/baz@" | tee expout
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foo.o]])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./subdir_bar/bar.o]])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./baz.o]])
AT_CHECK([[
($READELF --debug-dump=line foo.o; \
$READELF --debug-dump=line subdir_bar/bar.o; \
$READELF --debug-dump=line baz.o) \
| grep -E -A5 "The (Directory|File Name) Table" | grep "^ [1234]"
]],[0],[expout],[ignore])
AT_CLEANUP
# ===
# Make sure .debug_line Directory Table entries are replaced
# in objects.
# ===
AT_SETUP([debugedit .debug_line objects DWARF5])
AT_KEYWORDS([debuginfo] [debugedit])
AT_SKIP_IF([test "$GDWARF_5_FLAG" = "no"])
AT_SKIP_IF([test "$DWARF_5_DEBUGLINE" = "no"])
DEBUGEDIT_SETUP([-gdwarf-5])
($READELF --debug-dump=line foo.o; \
$READELF --debug-dump=line subdir_bar/bar.o; \
$READELF --debug-dump=line baz.o) \
| grep -E -A5 "The (Directory|File Name) Table" \
| grep "^ [[01234]]" | cut -f3 -d: \
| sed -e "s@$(pwd)@/foo/bar/baz@" | tee expout
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foo.o]])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./subdir_bar/bar.o]])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./baz.o]])
AT_CHECK([[
($READELF --debug-dump=line foo.o; \
$READELF --debug-dump=line subdir_bar/bar.o; \
$READELF --debug-dump=line baz.o) \
| grep -E -A5 "The (Directory|File Name) Table" \
| grep "^ [01234]" | cut -f3 -d:
]],[0],[expout],[ignore])
AT_CLEANUP
# ===
# Make sure .debug_line Directory Table entries are replaced
# in partial linked object.
# ===
AT_SETUP([debugedit .debug_line partial DWARF4])
AT_KEYWORDS([debuginfo] [debugedit])
DEBUGEDIT_SETUP([-gdwarf-4])
$READELF --debug-dump=line ./foobarbaz.part.o \
| grep -E -A5 "The (Directory|File Name) Table" \
| grep "^ [[1234]]" \
| sed -e "s@$(pwd)@/foo/bar/baz@" | tee expout
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.part.o]])
AT_CHECK([[
$READELF --debug-dump=line ./foobarbaz.part.o \
| grep -E -A5 "The (Directory|File Name) Table" \
| grep "^ [1234]"
]],[0],[expout],[ignore])
AT_CLEANUP
# ===
# Make sure .debug_line Directory Table entries are replaced
# in partial linked object.
# ===
AT_SETUP([debugedit .debug_line partial DWARF5])
AT_KEYWORDS([debuginfo] [debugedit])
AT_SKIP_IF([test "$GDWARF_5_FLAG" = "no"])
AT_SKIP_IF([test "$DWARF_5_DEBUGLINE" = "no"])
DEBUGEDIT_SETUP([-gdwarf-5])
$READELF --debug-dump=line ./foobarbaz.part.o \
| grep -E -A5 "The (Directory|File Name) Table" \
| grep "^ [[01234]]" | cut -f3 -d: \
| sed -e "s@$(pwd)@/foo/bar/baz@" | tee expout
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.part.o]])
AT_CHECK([[
$READELF --debug-dump=line ./foobarbaz.part.o \
| grep -E -A5 "The (Directory|File Name) Table" \
| grep "^ [01234]" | cut -f3 -d:
]],[0],[expout],[ignore])
AT_CLEANUP
# ===
# Make sure .debug_line Directory Table entries are replaced
# in executable.
# ===
AT_SETUP([debugedit .debug_line exe DWARF4])
AT_KEYWORDS([debuginfo] [debugedit])
DEBUGEDIT_SETUP([-gdwarf-4])
$READELF --debug-dump=line ./foobarbaz.exe \
| grep -E -A5 "The (Directory|File Name) Table" \
| grep "^ [[1234]]" \
| sed -e "s@$(pwd)@/foo/bar/baz@" | tee expout
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.exe]])
AT_CHECK([[
$READELF --debug-dump=line ./foobarbaz.exe \
| grep -E -A5 "The (Directory|File Name) Table" \
| grep "^ [1234]"
]],[0],[expout],[ignore])
AT_CLEANUP
# ===
# Make sure .debug_line Directory Table entries are replaced
# in executable.
# ===
AT_SETUP([debugedit .debug_line exe DWARF5])
AT_KEYWORDS([debuginfo] [debugedit])
AT_SKIP_IF([test "$GDWARF_5_FLAG" = "no"])
AT_SKIP_IF([test "$DWARF_5_DEBUGLINE" = "no"])
DEBUGEDIT_SETUP([-gdwarf-5])
$READELF --debug-dump=line ./foobarbaz.exe \
| grep -E -A5 "The (Directory|File Name) Table" \
| grep "^ [[01234]]" | cut -f3 -d: \
| sed -e "s@$(pwd)@/foo/bar/baz@" | tee expout
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.exe]])
AT_CHECK([[
$READELF --debug-dump=line ./foobarbaz.exe \
| grep -E -A5 "The (Directory|File Name) Table" \
| grep "^ [01234]" | cut -f3 -d:
]],[0],[expout],[ignore])
AT_CLEANUP
# ===
# Make sure .debug_macro strings are still there
# in objects.
# ===
AT_SETUP([debugedit .debug_macro objects])
AT_KEYWORDS([debuginfo] [debugedit])
DEBUGEDIT_SETUP([$DEBUG_MACRO_FLAG])
# We expect 3 for each compile unit.
AT_DATA([expout],
[NUMBER 42
NUMBER 42
NUMBER 42
])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foo.o]])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./subdir_bar/bar.o]])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./baz.o]])
AT_CHECK([[
($READELF --debug-dump=macro foo.o; \
$READELF --debug-dump=macro subdir_bar/bar.o; \
$READELF --debug-dump=macro baz.o) \
| grep NUMBER | rev | cut -d: -f1 | rev | cut -c2-
]],[0],[expout],[ignore])
AT_CLEANUP
# ===
# Make sure .debug_macro strings are still there
# in partial linked object.
# ===
AT_SETUP([debugedit .debug_macro partial])
AT_KEYWORDS([debuginfo] [debugedit])
DEBUGEDIT_SETUP([$DEBUG_MACRO_FLAG])
# We expect 3 for each compile unit.
AT_DATA([expout],
[NUMBER 42
NUMBER 42
NUMBER 42
])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.part.o]])
AT_CHECK([[
$READELF --debug-dump=macro ./foobarbaz.part.o \
| grep NUMBER | rev | cut -d: -f1 | rev | cut -c2-
]],[0],[expout],[ignore])
AT_CLEANUP
# ===
# Make sure .debug_macro strings are still there
# in executable.
# ===
AT_SETUP([debugedit .debug_macro exe])
AT_KEYWORDS([debuginfo] [debugedit])
DEBUGEDIT_SETUP([$DEBUG_MACRO_FLAG])
# We expect 3 for each compile unit.
AT_DATA([expout],
[NUMBER 42
NUMBER 42
NUMBER 42
])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.exe]])
AT_CHECK([[
$READELF --debug-dump=macro ./foobarbaz.exe \
| grep NUMBER | rev | cut -d: -f1 | rev | cut -c2-
]],[0],[expout],[ignore])
AT_CLEANUP
AT_SETUP([debugedit .debug_macro exe (compressed)])
AT_KEYWORDS([debuginfo] [debugedit])
AT_SKIP_IF([test -z "$GZ_ZLIB_FLAG"])
AT_SKIP_IF([test "$READELF_VERSION_OK" = "no"])
DEBUGEDIT_SETUP([$DEBUG_MACRO_FLAG], [$GZ_ZLIB_FLAG])
# We expect 3 for each compile unit.
AT_DATA([expout],
[NUMBER 42
NUMBER 42
NUMBER 42
])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.exe]])
AT_CHECK([[
$READELF --debug-dump=macro ./foobarbaz.exe \
| grep NUMBER | rev | cut -d: -f1 | rev | cut -c2-
]],[0],[expout],[ignore])
AT_CLEANUP
# ===
# source list mode dwarf-4
# ===
AT_SETUP([debugedit --list-file DWARF4])
AT_KEYWORDS([debuginfo] [debugedit])
echo "int main () { }" > main.c
$CC $CFLAGS -gdwarf-4 -o main main.c
AT_CHECK([[debugedit -l sources.list main]])
AT_CHECK([[grep -q main.c sources.list]])
cat sources.list
AT_CLEANUP
# ===
# source list mode dwarf-5
# ===
AT_SETUP([debugedit --list-file DWARF5])
AT_KEYWORDS([debuginfo] [debugedit])
AT_SKIP_IF([test "$GDWARF_5_FLAG" = "no"])
echo "int main () { }" > main.c
$CC $CFLAGS -gdwarf-5 -o main main.c
AT_CHECK([[debugedit -l sources.list main]])
AT_CHECK([[grep -q main.c sources.list]])
AT_CLEANUP
# ===
# source list with compression dwarf-4
# ===
AT_SETUP([debugedit --list-file compressed DWARF4])
AT_KEYWORDS([debuginfo] [debugedit])
echo "int main () { }" > main.c
$CC $CFLAGS $GZ_ZLIB_FLAG -gdwarf-4 -o main main.c
AT_CHECK([[debugedit -l sources.list main]])
AT_CHECK([[grep -q main.c sources.list]])
AT_CLEANUP
# ===
# source list with compression dwarf-5
# ===
AT_SETUP([debugedit --list-file compressed DWARF5])
AT_KEYWORDS([debuginfo] [debugedit])
AT_SKIP_IF([test "$GDWARF_5_FLAG" = "no"])
echo "int main () { }" > main.c
$CC $CFLAGS $GZ_ZLIB_FLAG -gdwarf-5 -o main main.c
AT_CHECK([[debugedit -l sources.list main]])
AT_CHECK([[grep -q main.c sources.list]])
AT_CLEANUP
# ===
# build-id recomputation
# ===
AT_SETUP([debugedit build-id recompute])
AT_KEYWORDS([debuginfo] [debugedit] [build-id])
# compile a test program and extract its linker-assigned build-id
echo "int main () { }" > main.c
$CC $CFLAGS -Wl,--build-id -o main main.c
AT_CHECK([[$READELF -n main | grep -o "Build.ID:.*" | awk '{print $3}']], [0], [stdout], [ignore])
bid="`cat stdout`"
AT_CHECK([[expr "$bid" : '[0-9a-f]*']], [0], [ignore])
# run debugedit to recompute build-id
AT_CHECK([[debugedit -i -s deadbeef main]], [0], [stdout])
bid2a="`cat stdout`"
AT_CHECK([[expr "$bid2a" : '[0-9a-f]*']], [0], [ignore])
AT_CHECK([[test "$bid" != "$bid2a"]])
# check that debugedit's stdout matches readelf -n note
AT_CHECK([[$READELF -n main | grep -o "Build.ID:.*" | awk '{print $3}']], [0], [stdout], [ignore])
bid2b="`cat stdout`"
AT_CHECK([[expr "$bid2b" : '[0-9a-f]*']], [0], [ignore])
AT_CHECK([[test "$bid2a" = "$bid2b"]])
# run debugedit to recompute build-id, check for idempotence
AT_CHECK([[debugedit -i -s deadbeef main]], [0], [stdout])
bid2c="`cat stdout`"
AT_CHECK([[expr "$bid2c" : '[0-9a-f]*']], [0], [ignore])
AT_CHECK([[test "$bid2a" = "$bid2c"]])
# check that debugedit -i with different -s seed results in different valid build-id
AT_CHECK([[debugedit -i -s zoofoo main]], [0], [stdout])
bid3="`cat stdout`"
AT_CHECK([[expr "$bid3" : '[0-9a-f]*']], [0], [ignore])
AT_CHECK([[test "$bid3" != "$bid2a"]])
AT_CLEANUP
# Preserving time stamps
AT_SETUP([debugedit preserve timestamps])
AT_KEYWORDS([debugedit] [timestamp])
# compile a test program and record the timestamps
echo "int main () { }" > main.c
$CC $CFLAGS -g -o main main.c
AT_CHECK([[stat -c "%x %y" main]], [0], [stdout], [])
mv stdout expout
# process it with debugedit, using -p
AT_CHECK([[debugedit -p -b $(pwd) -d /foo/bar/baz ./main]])
# check timestamps were preserved
AT_CHECK([[stat -c "%x %y" main]], [0], [expout], [])
AT_CLEANUP
|