This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Avoid most open and stat syscalls when setting a breakpoint


Hi all,

I want to present a patch that helps avoiding many unneccessary filesystem 
accesses when setting breakpoints. This leads to a remarkable perfomance 
improvement when sources are on network shares.

The effect that gdb opens a lot of unneccessary files when setting a 
breakpoint via its absulute source path was already discussed here 
http://sourceware.org/ml/gdb/2010-03/msg00195.html.
gdb iterates over all source files mentioned in all object file's symtabs 
(== all source and header files used during the build). For each of these 
source files, gdb tries to find the file in the filesystem by applying the 
source path. The source path is used to debug in different locations than 
the build was done or to find the sources at all if the compiler does not 
include the compile dir in the debug infos.  If there is a hit, e,g, the 
source file from the debug info with one of the entries in soure path 
applied is there ( stat and open succeed ), then gdb checks if that is the 
file mentioned in the break command and if so, takes the code address from 
the symtab to set the breakpoint.

I think that most of these checks are not neccessary, e.g. to compare if

/home/me/project/source/main.cpp

becomes the same file as  <iostream>  when trying all source paths on 
main.cpp. The patch below leaves the described search loop when the 
basename from the symtab and the basename from the break command do not 
match, as they wont match by appliing different paths either.


diff -Naur gdb-7.1.orig/gdb/symtab.c gdb-7.1.mod/gdb/symtab.c
--- gdb-7.1.orig/gdb/symtab.c   2010-01-26 16:48:25.000000000 +0100
+++ gdb-7.1.mod/gdb/symtab.c    2010-03-24 16:54:37.000000000 +0100
@@ -280,7 +280,7 @@
 
    /* If the user gave us an absolute path, try to find the file in
       this symtab and use its absolute path.  */
-   if (full_path != NULL)
+   if (full_path != NULL && FILENAME_CMP( lbasename(full_path), 
lbasename(pst->filename)) == 0)
    {
        psymtab_to_fullname (pst);
        if (pst->fullname != NULL
@@ -290,7 +290,7 @@
        }
    }

-   if (real_path != NULL)
+   if (real_path != NULL && FILENAME_CMP( lbasename(real_path), 
lbasename(pst->filename)) == 0)
    { 
        char *rp = NULL;
        psymtab_to_fullname (pst);


please let me know what you think and if this is relevant for inclusion in 
future gdb releases.

best regards
Martin
 



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]