diff options
author | Mark Harmstone <mark@harmstone.com> | 2022-12-09 01:52:31 +0000 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2022-12-23 19:37:44 +1030 |
commit | f559276dc5f1ac25ca5c310135287dc20c2925e8 (patch) | |
tree | 4ffa7a6c7fe5966f78ad2aa0972a63ad75a43ede /ld/testsuite/ld-pe | |
parent | f27d07a1c208701de6f2c11d43b4a7d89a44180f (diff) | |
download | gdb-f559276dc5f1ac25ca5c310135287dc20c2925e8.zip gdb-f559276dc5f1ac25ca5c310135287dc20c2925e8.tar.gz gdb-f559276dc5f1ac25ca5c310135287dc20c2925e8.tar.bz2 |
ld: Generate PDB string table
Diffstat (limited to 'ld/testsuite/ld-pe')
-rw-r--r-- | ld/testsuite/ld-pe/pdb-strings.d | 10 | ||||
-rw-r--r-- | ld/testsuite/ld-pe/pdb-strings1.s | 19 | ||||
-rw-r--r-- | ld/testsuite/ld-pe/pdb-strings2.s | 19 | ||||
-rw-r--r-- | ld/testsuite/ld-pe/pdb.exp | 122 |
4 files changed, 170 insertions, 0 deletions
diff --git a/ld/testsuite/ld-pe/pdb-strings.d b/ld/testsuite/ld-pe/pdb-strings.d new file mode 100644 index 0000000..8be853e --- /dev/null +++ b/ld/testsuite/ld-pe/pdb-strings.d @@ -0,0 +1,10 @@ + +*: file format binary + +Contents of section .data: + 0000 feeffeef 01000000 17000000 0000666f ..............fo + 0010 6f006261 72006261 7a007175 78007175 o.bar.baz.qux.qu + 0020 7578000c 00000001 0000000a 00000000 ux.............. + 0030 00000000 00000000 00000012 00000000 ................ + 0040 00000000 00000002 00000006 00000000 ................ + 0050 0000000e 00000006 000000 ...........
\ No newline at end of file diff --git a/ld/testsuite/ld-pe/pdb-strings1.s b/ld/testsuite/ld-pe/pdb-strings1.s new file mode 100644 index 0000000..09eedd9 --- /dev/null +++ b/ld/testsuite/ld-pe/pdb-strings1.s @@ -0,0 +1,19 @@ +.equ CV_SIGNATURE_C13, 4 +.equ DEBUG_S_STRINGTABLE, 0xf3 + +.section ".debug$S", "rn" +.long CV_SIGNATURE_C13 +.long DEBUG_S_STRINGTABLE +.long .strings_end - .strings_start + +.strings_start: + +.asciz "" +.asciz "foo" +.asciz "bar" +.asciz "baz" +.asciz "qux" + +.strings_end: + +.balign 4 diff --git a/ld/testsuite/ld-pe/pdb-strings2.s b/ld/testsuite/ld-pe/pdb-strings2.s new file mode 100644 index 0000000..33d9215 --- /dev/null +++ b/ld/testsuite/ld-pe/pdb-strings2.s @@ -0,0 +1,19 @@ +.equ CV_SIGNATURE_C13, 4 +.equ DEBUG_S_STRINGTABLE, 0xf3 + +.section ".debug$S", "rn" +.long CV_SIGNATURE_C13 +.long DEBUG_S_STRINGTABLE +.long .strings_end - .strings_start + +.strings_start: + +.asciz "" +.asciz "bar" +.asciz "baz" +.asciz "qux" +.asciz "quux" + +.strings_end: + +.balign 4 diff --git a/ld/testsuite/ld-pe/pdb.exp b/ld/testsuite/ld-pe/pdb.exp index 0be65e2..09e9b4a 100644 --- a/ld/testsuite/ld-pe/pdb.exp +++ b/ld/testsuite/ld-pe/pdb.exp @@ -703,5 +703,127 @@ proc test2 { } { test_section_contrib $section_contrib } +proc find_named_stream { pdb name } { + global ar + + set exec_output [run_host_cmd "$ar" "x --output tmpdir $pdb 0001"] + + if ![string match "" $exec_output] { + return 0 + } + + set fi [open tmpdir/0001] + fconfigure $fi -translation binary + + seek $fi 0x1c + + set data [read $fi 4] + binary scan $data i string_len + + set strings [read $fi $string_len] + + set string_off 0 + + while {[string first \000 $strings $string_off] != -1 } { + set str [string range $strings $string_off [expr [string first \000 $strings $string_off] - 1]] + + if { $str eq $name } { + break + } + + incr string_off [expr [string length $str] + 1] + } + + if { [string length $strings] == $string_off } { # string not found + close $fi + return 0 + } + + set data [read $fi 4] + binary scan $data i num_entries + + seek $fi 4 current + + set data [read $fi 4] + binary scan $data i present_bitmap_len + + seek $fi [expr $present_bitmap_len * 4] current + + set data [read $fi 4] + binary scan $data i deleted_bitmap_len + + seek $fi [expr $deleted_bitmap_len * 4] current + + for {set i 0} {$i < $num_entries} {incr i} { + set data [read $fi 4] + binary scan $data i offset + + if { $offset == $string_off } { + set data [read $fi 4] + binary scan $data i value + close $fi + + return $value + } + + seek $fi 4 current + } + + close $fi + + return 0 +} + +proc test3 { } { + global as + global ar + global ld + global objdump + global srcdir + global subdir + + if ![ld_assemble $as $srcdir/$subdir/pdb-strings1.s tmpdir/pdb-strings1.o] { + unsupported "Build pdb-strings1.o" + return + } + + if ![ld_assemble $as $srcdir/$subdir/pdb-strings2.s tmpdir/pdb-strings2.o] { + unsupported "Build pdb-strings2.o" + return + } + + if ![ld_link $ld "tmpdir/pdb-strings.exe" "--pdb=tmpdir/pdb-strings.pdb tmpdir/pdb-strings1.o tmpdir/pdb-strings2.o"] { + unsupported "Create PE image with PDB file" + return + } + + set index [find_named_stream "tmpdir/pdb-strings.pdb" "/names"] + + if { $index == 0 } { + fail "Could not find /names stream" + return + } else { + pass "Found /names stream" + } + + set index_str [format "%04x" $index] + + set exec_output [run_host_cmd "$ar" "x --output tmpdir tmpdir/pdb-strings.pdb $index_str"] + + if ![string match "" $exec_output] { + return 0 + } + + set exp [file_contents "$srcdir/$subdir/pdb-strings.d"] + set got [run_host_cmd "$objdump" "-s --target=binary tmpdir/$index_str"] + + if ![string match $exp $got] { + fail "Strings table was not as expected" + } else { + pass "Strings table was as expected" + } +} + test1 test2 +test3 |