Re: [RFA] 12266 (typedef'd parameters) revisited again

Jan Kratochvil
2011-06-05T13:28:44Z

[-- Attachment #1: Type: text/plain, Size: 5517 bytes --]

On Sat, 04 Jun 2011 01:33:26 +0200, Keith Seitz wrote:
> Of course, it is still possible that I've neglected something along
> the line.

This patch crashes for me on:
./gdb -nx -ex "b '__gnu_cxx::__detail::__mini_vector<std::pair<__gnu_cxx::bitmap_allocator<char>::_Alloc_block*, __gnu_cxx::bitmap_allocator<char>::_Alloc_block*> >::deallocate(std::pair<__gnu_cxx::bitmap_allocator<char>::_Alloc_block*, __gnu_cxx::bitmap_allocator<char>::_Alloc_block*>*, unsigned long)'" ~/t/libstdc++.so.6.0.16 -ex q

where libstdc++.so.6.0.16 has build-id 3b4e74185daae5c573056df66b5807908029eac8
, it is associated by its .debug file and comes from gcc-4.6.0-7.fc15.x86_64.

valgring first problematic crash is below.

Attaching scripts/patches I use to reach at the pre-physname functionality
without regressions, that is to be able to at least:
(gdb) break 'function name as seen in nm -C'

gdb-breakpoint.pl
- run by: for i in variant-to-run;do time ~/t/gdb-breakpoint.pl 0 ~/t/gdb-$i ~/redhat/binutils-clean/binutils/nm-new-{clean,retdrop} ~/t/libstdc++.so.6.0.16 >~/t/gdb-breakpoint-out-libstdcxx-$i; time ~/t/gdb-breakpoint.pl 0 ~/t/gdb-$i ~/redhat/binutils-clean/binutils/nm-new-{clean,retdrop} ~/t/libwebkitgtk-1.0.so.0.5.2 >~/t/gdb-breakpoint-out-libwebkit-$i;done
- nm-new-retdrop is nm patched for DMGL_RET_DROP
gdb-breakpoint-fix.pl
- some postprocessing of the output from gdb-breakpoint.pl
gdb-breakpoint-diff.pl
- comparison of two files to reach 0 regressions against pre-physname GDB
gdb-breakpoint-O2g.patch
- workaround GDB PR 12822 - Assertion `found' failed.
gdb-breakpoint-hack_count-old.patch
gdb-breakpoint-hack_count-new.patch
- workaround GDB PR 12828 - Too slow break on -O2 -g code
- two variants for pre-physname and recent GDB sources

Some stats out of gdb-breakpoint-diff.pl:

pre-phys -> jan
prev bad: 1324
now bad: 53
both bad: 53
regression: 0
improvement: 1271
both good: 47619
pre-phys -> master
prev bad: 1324
now bad: 3243
both bad: 813
regression: 2430
improvement: 511
both good: 45189
master -> jan
prev bad: 3243
now bad: 53
both bad: 53
regression: 0
improvement: 3190
both good: 45700

Thanks,
Jan

Invalid read of size 8
at 0x5E8B2B6: __memcpy_ssse3_back (memcpy-ssse3-back.S:1624)
by 0x41A5D0: mem_file_write (ui-file.c:457)
by 0x419DF9: ui_file_write (ui-file.c:214)
by 0x4223B3: replace_typedefs_qualified_name (cp-support.c:224)
by 0x422585: replace_typedefs (cp-support.c:294)
by 0x4225BF: replace_typedefs (cp-support.c:309)
by 0x422538: replace_typedefs (cp-support.c:285)
by 0x4225A2: replace_typedefs (cp-support.c:304)
by 0x422493: replace_typedefs_qualified_name (cp-support.c:254)
by 0x422585: replace_typedefs (cp-support.c:294)
by 0x4225BF: replace_typedefs (cp-support.c:309)
by 0x422538: replace_typedefs (cp-support.c:285)
by 0x4225A2: replace_typedefs (cp-support.c:304)
by 0x4225A2: replace_typedefs (cp-support.c:304)
by 0x42264D: cp_canonicalize_string_no_typedefs (cp-support.c:338)
by 0x61FD06: find_methods (linespec.c:252)
by 0x6232B3: find_method (linespec.c:1747)
by 0x622CAA: decode_compound (linespec.c:1599)
by 0x621779: decode_line_1 (linespec.c:939)
by 0x5CF964: parse_breakpoint_sals (breakpoint.c:7739)
by 0x5D0341: create_breakpoint (breakpoint.c:7971)
by 0x5D0AEC: break_command_1 (breakpoint.c:8203)
by 0x5D0CA4: break_command (breakpoint.c:8276)
by 0x58D724: do_cfunc (cli-decode.c:67)
by 0x5908A9: cmd_func (cli-decode.c:1777)
by 0x411BF1: execute_command (top.c:435)
by 0x644FDF: catch_command_errors (exceptions.c:522)
by 0x407E70: captured_main (main.c:913)
by 0x644F44: catch_errors (exceptions.c:506)
by 0x407F05: gdb_main (main.c:946)
by 0x406BA2: main (gdb.c:35)
Address 0xda91035 is 11 bytes before a block of size 227,731,995 alloc'd
at 0x4C284F2: realloc (vg_replace_malloc.c:525)
by 0x415552: xrealloc (utils.c:1270)
by 0x41A59B: mem_file_write (ui-file.c:455)
by 0x419DF9: ui_file_write (ui-file.c:214)
by 0x4223B3: replace_typedefs_qualified_name (cp-support.c:224)
by 0x422585: replace_typedefs (cp-support.c:294)
by 0x4225BF: replace_typedefs (cp-support.c:309)
by 0x422538: replace_typedefs (cp-support.c:285)
by 0x4225A2: replace_typedefs (cp-support.c:304)
by 0x422493: replace_typedefs_qualified_name (cp-support.c:254)
by 0x422585: replace_typedefs (cp-support.c:294)
by 0x4225BF: replace_typedefs (cp-support.c:309)
by 0x422538: replace_typedefs (cp-support.c:285)
by 0x4225A2: replace_typedefs (cp-support.c:304)
by 0x4225A2: replace_typedefs (cp-support.c:304)
by 0x42264D: cp_canonicalize_string_no_typedefs (cp-support.c:338)
by 0x61FD06: find_methods (linespec.c:252)
by 0x6232B3: find_method (linespec.c:1747)
by 0x622CAA: decode_compound (linespec.c:1599)
by 0x621779: decode_line_1 (linespec.c:939)
by 0x5CF964: parse_breakpoint_sals (breakpoint.c:7739)
by 0x5D0341: create_breakpoint (breakpoint.c:7971)
by 0x5D0AEC: break_command_1 (breakpoint.c:8203)
by 0x5D0CA4: break_command (breakpoint.c:8276)
by 0x58D724: do_cfunc (cli-decode.c:67)
by 0x5908A9: cmd_func (cli-decode.c:1777)
by 0x411BF1: execute_command (top.c:435)
by 0x644FDF: catch_command_errors (exceptions.c:522)
by 0x407E70: captured_main (main.c:913)
by 0x644F44: catch_errors (exceptions.c:506)
by 0x407F05: gdb_main (main.c:946)
by 0x406BA2: main (gdb.c:35)

[-- Attachment #2: gdb-breakpoint.pl --]
[-- Type: text/plain, Size: 2490 bytes --]

#! /usr/bin/perl
# perl -i -p -e 's/^(Breakpoint )(?:\d+ )?(?:at 0x[0-9a-f]+ )?/$1/'

use strict;
use warnings;
use Data::Dumper;
use List::Util qw(&shuffle);

my $BATCH=500;

my $die;
@ARGV>=5 or die "$0 <limit> <gdb> <nm> <nm-retdrop> <files>...";
my $limit=shift;
my $gdb=shift;
my $nm=shift;
my $nm_retdrop=shift;
$limit=~/^\d+$/ or die "limit is not numeric: $limit";
$limit or undef $limit;
-x $gdb or die "-x $gdb";
-x $nm or die "-x $nm";
-x $nm_retdrop or die "-x $nm_retdrop";

#system "cgclassify -g '*':hammock $$ &>/dev/null";
system "renice +19 -p $$ &>/dev/null";
system "ionice -c3 -p $$ &>/dev/null";
srand 0;

while (@ARGV) {

my $file=shift;
my $debug="${file}.debug";
warn "$file\n";

-r $file or die "-r $file";
-r $debug or die "-r $debug";

my %break;

sub nm($)
{
my($nm_kind)=@_;

my $f="$nm_kind -C $debug|";
local *F;
open F,$f or die $f;
my @retval;
while (<F>) {
chomp;
next if !(my $break=(/^.{16} [tT] (.*)$/)[0]);
# $break=~s/@.*//;
next if $break=~/[.]clone[.]\d+$/;
push @retval,$break;
die "' in: $break" if $break=~/'/;
$break{$break}++;
}
close F or die $f;
return @retval;
}
my @nm=nm $nm;
my @nm_retdrop=nm $nm_retdrop;

@nm==@nm_retdrop or die '@nm!=@nm_retdrop';
@nm>0 or die '@nm==0';
warn "minsyms ".scalar(@nm)."\n";

my @break=shuffle(sort(keys(%break)));
warn "breaks ".scalar(@break)."\n";

my %h;
for my $i (0..$#nm) {
my $a=$nm[$i];
my $b=$nm_retdrop[$i];
next if $a eq $b;
length($a) > length ($b) or die "$a length $b";
$h{$b}{$a}=1;
}
warn "function templates ".scalar(keys(%h))."\n";
for my $b (keys(%h)) {
my @a=keys(%{$h{$b}});
next if @a==1;
print Dumper([$b,\@a]);
$die++;
}

my $break_done=0;
while (@break) {
local *GDB;
my $GDB="|$gdb -nx $file 2>&1";
open GDB,$GDB or die "open $GDB";
print GDB <<"EOH" or die "print $GDB";
set prompt
set breakpoint pending off
set confirm no
set width 0
set height 0
set pagination off
set language c++
EOH

my $batch_done=0;
while (@break && $batch_done < $BATCH) {
my $break=shift @break;
print GDB <<"EOH" or die "print $GDB";
echo BREAK @{[ sprintf "%6d",$break_done ]} $break\\n
b '$break'
delete
EOH
$batch_done++;
$break_done++;
last if defined $limit && --$limit<=0;
}

print GDB <<"EOH" or die "print $GDB";
quit
EOH
close GDB or die "close $GDB";
$? and die "error $? on close $GDB";
last if defined $limit && $limit<=0;
} # while (@break);

} # while (@ARGV);
die $die if $die;

[-- Attachment #3: gdb-breakpoint-fix.pl --]
[-- Type: text/plain, Size: 143 bytes --]

#! /usr/bin/perl -i -n
next if $_ eq "BREAKSTUB\n";
print "BREAKSTUB\n" if /^BREAK/;
s/^(Breakpoint )(?:\d+ )?(?:at 0x[0-9a-f]+ )?/$1/;
print;

[-- Attachment #4: gdb-breakpoint-diff.pl --]
[-- Type: text/plain, Size: 1312 bytes --]

#! /usr/bin/perl
use strict;
use warnings;

my $v=0;
$v++,shift if ($ARGV[0]||"") eq "-v";
$v++,shift if ($ARGV[0]||"") eq "-v";
@ARGV and @ARGV%1==0 or die "$0: [-v] {<gdb-breakpoint-out1> <gdb-breakpoint-out2>}...";
my @s=([0,0],[0,0]);
while (@ARGV) {
local *F;
my $f="(diff -U999999 '".shift."' '".shift."';:)|";
open F,$f or die $f;
my($a,$b,$text);
while (<F>) {
my $line=$.-3;
chomp;
warn "$line:$_\n" if $v;
next if $_ eq " BREAKSTUB";
die $_ if /^.BREAKSTUB/;
if (/^ BREAK/) {
if (!defined $text) {}
elsif (!$a && !$b) {
print "both bad:$line\n$text";
}
elsif ($a && !$b) {
print "regression:$line\n$text";
}
elsif (!$a && $b && $v>=2) {
print "improvement:$line\n$text";
}
$s[$a||0][$b||0]++ if defined $text;
$a=$b=0;
$text="$_\n";
next;
}
$text.="$_\n" if defined $text;
die $_ if /^.BREAK/;
my $re=qr/Breakpoint at |\d+ hack_count/o;
$a=1 if /^[-]$re/o;
$b=1 if /^[+]$re/o;
$a=$b=1 if /^ $re/o;
}
close F or die $f;
}
printf "prev bad: %5d\n",$s[0][0]+$s[0][1];
printf "now bad: %5d\n",$s[0][0]+$s[1][0];
printf "both bad: %5d\n",$s[0][0];
printf "regression: %5d\n",$s[1][0];
printf "improvement: %5d\n",$s[0][1];
printf "both good: %5d\n",$s[1][1];

[-- Attachment #5: gdb-breakpoint-O2g.patch --]
[-- Type: text/plain, Size: 356 bytes --]

--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -6608,6 +6608,7 @@ expand_line_sal_maybe (struct symtab_and_line sal)
return expanded;
}

+#if 0
if (original_pc)
{
found = 0;
@@ -6619,6 +6620,7 @@ expand_line_sal_maybe (struct symtab_and_line sal)
}
gdb_assert (found);
}
+#endif

return expanded;
}

[-- Attachment #6: gdb-breakpoint-hack_count-old.patch --]
[-- Type: text/plain, Size: 597 bytes --]

--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -4771,6 +4771,16 @@ expand_line_sal (struct symtab_and_line sal)
lineno = sal.line;
match_filename = sal.symtab->filename;

+{ int hack_count = 0;
+ ALL_PSPACES (pspace)
+ ALL_PSPACE_PSYMTABS (pspace, objfile, psymtab)
+ {
+ if (FILENAME_CMP (match_filename, psymtab->filename) == 0)
+ hack_count++;
+ }
+if (hack_count > 10) error ("%d hack_count", hack_count);
+}
+
/* We need to find all symtabs for a file which name
is described by sal. We cannot just directly
iterate over symtabs, since a symtab might not be

[-- Attachment #7: gdb-breakpoint-hack_count-new.patch --]
[-- Type: text/plain, Size: 570 bytes --]

diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index ea690ef..38b0ca3 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -1073,6 +1073,15 @@ read_psymtabs_with_filename (struct objfile *objfile, const char *filename)
{
struct partial_symtab *p;

+{ int hack_count = 0;
+ ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
+ {
+ if (filename_cmp (filename, p->filename) == 0)
+ hack_count++;
+ }
+if (hack_count > 10) error ("%d hack_count", hack_count);
+}
+
ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
{
if (filename_cmp (filename, p->filename) == 0)