This is the mail archive of the gdb-prs@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]

[Bug gdb/16363] New: GDB crashes after canceling symbol completion


https://sourceware.org/bugzilla/show_bug.cgi?id=16363

            Bug ID: 16363
           Summary: GDB crashes after canceling symbol completion
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: cole945 at gmail dot com

GDB crashes after canceling symbol completion.
The process of symbols/debug info loading are not exception-safe.

The tested program must has a lot of debug information,
so I can not give a simple program, but it's very easy
to reproduce it by debugging cc1 (from gcc) or llc (from llvm)
compiled with -g3 -O0.

The steps to reproduce it
1. $ gdb /path/to/gcc/cc1
2. (gdb) break <TAB>
3. Just wait 2 second and press ^C to cancel symbol completion
4. (gdb) break main
5. (gdb) run
   Starting program: /patth/to/gcc/cc1
   Segmentation fault (core dumped)

If it doesn't crash, just try this one more step

6. (gdb) call puts ("hello")
   Segmentation fault (core dumped)


I've checked why it crashed.

1. When press <TAB> for symbol completion,
   the symbols and dwarf are read (Some frames are omitted.)

   psymtab_to_symtab_1
   -> process_full_comp_unit
      -> process_die
         -> allocate_symtab

   When allocate_symtab() is called, the symtab is inserted in
   current_program_space->objfiles->symtabs

2. Press ^C to cancel completion,
   set_quit_flags() is called

3. Depends on the timing, the QUIT macro in c_type_print_* will be call

   psymtab_to_symtab_1
   -> process_full_comp_unit
      -> process_die
         -> allocate_symtab
      -> compute_delayed_physnames
         -> dwarf2_physname
            -> dwarf2_compute_name
               ...
               -> c_type_print_base
                  -> QUIT

  When quit, the value of symtab->blockvector is leaving NULL.

4. symtab->blockvector should be set here


   psymtab_to_symtab_1
   -> process_full_comp_unit
      -> process_die
         -> allocate_symtab
      -> compute_delayed_physnames
         -> dwarf2_physname
            -> dwarf2_compute_name
               ...
               -> c_type_print_base
                  -> QUIT
      -> end_symtab_from_static_block
         -> symtab->blockvector = make_blockvector ()

5. Crash in lookup_objfile_from_block, because BLOCKVECTOR (s) is NULL

  /* Go through SYMTABS.  */
  ALL_SYMTABS (obj, s)
    if (block == BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK))  <---
      {
        if (obj->separate_debug_objfile_backlink)
          obj = obj->separate_debug_objfile_backlink;

        return obj;
      }

6. I think either QUIT in (ada|c|f|m2|p|)-typeprint.c should be removed,
   because we may in the middle of building symtabs, and it seems
   those function should not take a long time.

   Or if users cancel symbol completion, those symbol inserted in objfiles
   which blockvector are set yet should be removed, because they are not
   finishing their initialization (pst->readin is also not set yet when QUIT)

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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