From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31744 invoked by alias); 20 Apr 2009 23:29:12 -0000 Received: (qmail 31734 invoked by uid 22791); 20 Apr 2009 23:29:11 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.33.17) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 20 Apr 2009 23:29:06 +0000 Received: from spaceape23.eur.corp.google.com (spaceape23.eur.corp.google.com [172.28.16.75]) by smtp-out.google.com with ESMTP id n3KNT3DJ031015 for ; Tue, 21 Apr 2009 00:29:03 +0100 Received: from localhost (elbrus.mtv.corp.google.com [172.18.118.100]) by spaceape23.eur.corp.google.com with ESMTP id n3KNT0vt007214; Mon, 20 Apr 2009 16:29:01 -0700 Received: by localhost (Postfix, from userid 74925) id 2456B19C4F6; Mon, 20 Apr 2009 16:29:00 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [rfc][patch] Eliminate quadratic slow-down on number of solibs. Message-Id: <20090420232900.2456B19C4F6@localhost> Date: Mon, 20 Apr 2009 23:29:00 -0000 From: ppluzhnikov@google.com (Paul Pluzhnikov) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-04/txt/msg00548.txt.bz2 Greetings, We have a test case which uses ~2800 shared libraries. Running this test with '--version' (i.e. run to main and exit) takes about 40 seconds. Running it under GDB (CVS Head) with a breakpoint set on main takes 15 minutes, with significant CPU usage by GDB itself. Profiling GDB, I see that the 2 top contributors are: time seconds seconds calls s/call s/call name 61.66 728.26 728.26 2794 0.26 0.26 find_methods 24.21 1014.18 285.91 3904625 0.00 0.00 lookup_minimal_symbol_text The former call comes from breakpoin_re_set(), as GDB scans all libraries loaded so far, looking to see if any of them define Objective-C methods which match "main" as a selector. The latter call comes from repeaded calls to create_overlay_event_breakpoint, which again scans all libraries loaded so far for "_ovly_debug_event". AFAICT, both of the above scans are quadratic in number of solibs; and we don't use either overlays or Objective-C, so this is "pure waste" for us. To address the repeated scanning for objective-c, I propose adding n_objc_syms to the struct objstats, initializing that field to ~0, and counting them in find_methods the first time we encounter a given objfile. If we see that objfile again, and n_objc_syms == 0, find_methods could return immediately. To address the overlay_event_breakpoint, I propose attached patch. [Tested on Linux/x86_64 with no regressions.] Comments? Thanks, -- Paul Pluzhnikov ChangeLog: 2009-04-20 Paul Pluzhnikov * breakpoint.h: Add breakpoint_re_set_objfile prototype. * breakpoint.c (breakpoint_re_set_objfile): Don't rescan all objfiles unnecessarily. (breakpoint_re_set): New function. * symfile.c (new_symfile_objfile): Call breakpoint_re_set_objfile instead of breakpoint_re_set. * objfiles.c (objfile_relocate): Likewise. Index: breakpoint.h =================================================================== RCS file: /cvs/src/src/gdb/breakpoint.h,v retrieving revision 1.90 diff -u -p -u -r1.90 breakpoint.h --- breakpoint.h 31 Mar 2009 16:44:17 -0000 1.90 +++ breakpoint.h 20 Apr 2009 23:02:11 -0000 @@ -687,7 +687,7 @@ extern int breakpoint_thread_match (CORE extern void until_break_command (char *, int, int); extern void breakpoint_re_set (void); - +extern void breakpoint_re_set_objfile (struct objfile *); extern void breakpoint_re_set_thread (struct breakpoint *); extern struct breakpoint *set_momentary_breakpoint Index: breakpoint.c =================================================================== RCS file: /cvs/src/src/gdb/breakpoint.c,v retrieving revision 1.390 diff -u -p -u -r1.390 breakpoint.c --- breakpoint.c 31 Mar 2009 16:44:17 -0000 1.390 +++ breakpoint.c 20 Apr 2009 23:02:11 -0000 @@ -7711,7 +7711,7 @@ breakpoint_re_set_one (void *bint) /* Re-set all breakpoints after symbols have been re-loaded. */ void -breakpoint_re_set (void) +breakpoint_re_set_objfile (struct objfile *objfile) { struct breakpoint *b, *temp; enum language save_language; @@ -7730,8 +7730,17 @@ breakpoint_re_set (void) } set_language (save_language); input_radix = save_input_radix; - - create_overlay_event_breakpoint ("_ovly_debug_event"); + + if (objfile != NULL) + create_overlay_event_breakpoint_1 ("_ovly_debug_event", objfile); + else + create_overlay_event_breakpoint ("_ovly_debug_event"); +} + +void +breakpoint_re_set (void) +{ + breakpoint_re_set_objfile (NULL); } /* Reset the thread number of this breakpoint: Index: symfile.c =================================================================== RCS file: /cvs/src/src/gdb/symfile.c,v retrieving revision 1.224 diff -u -p -u -r1.224 symfile.c --- symfile.c 7 Apr 2009 20:43:51 -0000 1.224 +++ symfile.c 20 Apr 2009 23:02:11 -0000 @@ -922,7 +922,7 @@ new_symfile_objfile (struct objfile *obj } else { - breakpoint_re_set (); + breakpoint_re_set_objfile (objfile); } /* We're done reading the symbol file; finish off complaints. */ Index: objfiles.c =================================================================== RCS file: /cvs/src/src/gdb/objfiles.c,v retrieving revision 1.82 diff -u -p -u -r1.82 objfiles.c --- objfiles.c 11 Mar 2009 20:26:02 -0000 1.82 +++ objfiles.c 20 Apr 2009 23:02:11 -0000 @@ -674,7 +674,7 @@ objfile_relocate (struct objfile *objfil } /* Relocate breakpoints as necessary, after things are relocated. */ - breakpoint_re_set (); + breakpoint_re_set_objfile (objfile); } /* Many places in gdb want to test just to see if we have any partial