X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fprogspace.c;h=ce3d0f8185a075a4b1216b29e6bb7943825e7e23;hb=112e8700a6fd2fed65ca70132c9cbed4132e8bd4;hp=db8c5a3b09610a806c329a0b14345b4674ff13a6;hpb=6b81941e358ef95a24d90b971dd05f6c30dfa9a7;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/progspace.c b/gdb/progspace.c index db8c5a3b09..ce3d0f8185 100644 --- a/gdb/progspace.c +++ b/gdb/progspace.c @@ -1,6 +1,6 @@ /* Program and address space management, for GDB, the GNU debugger. - Copyright (C) 2009-2012 Free Software Foundation, Inc. + Copyright (C) 2009-2016 Free Software Foundation, Inc. This file is part of GDB. @@ -44,17 +44,25 @@ static int highest_address_space_num; DEFINE_REGISTRY (program_space, REGISTRY_ACCESS_FIELD) - - -/* An address space. Currently this is not used for much other than - for comparing if pspaces/inferior/threads see the same address +/* An address space. It is used for comparing if pspaces/inferior/threads + see the same address space and for associating caches to each address space. */ struct address_space { int num; + + /* Per aspace data-pointers required by other GDB modules. */ + REGISTRY_FIELDS; }; +/* Keep a registry of per-address_space data-pointers required by other GDB + modules. */ + +DEFINE_REGISTRY (address_space, REGISTRY_ACCESS_FIELD) + + + /* Create a new address space object, and add it to the list. */ struct address_space * @@ -62,8 +70,9 @@ new_address_space (void) { struct address_space *aspace; - aspace = XZALLOC (struct address_space); + aspace = XCNEW (struct address_space); aspace->num = ++highest_address_space_num; + address_space_alloc_data (aspace); return aspace; } @@ -75,7 +84,7 @@ new_address_space (void) struct address_space * maybe_new_address_space (void) { - int shared_aspace = gdbarch_has_shared_address_space (target_gdbarch); + int shared_aspace = gdbarch_has_shared_address_space (target_gdbarch ()); if (shared_aspace) { @@ -89,6 +98,7 @@ maybe_new_address_space (void) static void free_address_space (struct address_space *aspace) { + address_space_free_data (aspace); xfree (aspace); } @@ -116,15 +126,23 @@ add_program_space (struct address_space *aspace) { struct program_space *pspace; - pspace = XZALLOC (struct program_space); + pspace = XCNEW (struct program_space); pspace->num = ++last_program_space_num; pspace->aspace = aspace; program_space_alloc_data (pspace); - pspace->next = program_spaces; - program_spaces = pspace; + if (program_spaces == NULL) + program_spaces = pspace; + else + { + struct program_space *last; + + for (last = program_spaces; last->next != NULL; last = last->next) + ; + last->next = pspace; + } return pspace; } @@ -148,10 +166,9 @@ release_program_space (struct program_space *pspace) no_shared_libraries (NULL, 0); exec_close (); free_all_objfiles (); - if (!gdbarch_has_shared_address_space (target_gdbarch)) + if (!gdbarch_has_shared_address_space (target_gdbarch ())) free_address_space (pspace->aspace); - resize_section_table (&pspace->target_sections, - -resize_section_table (&pspace->target_sections, 0)); + clear_section_table (&pspace->target_sections); clear_program_space_solib_cache (pspace); /* Discard any data modules have associated with the PSPACE. */ program_space_free_data (pspace); @@ -160,30 +177,6 @@ release_program_space (struct program_space *pspace) do_cleanups (old_chain); } -/* Unlinks PSPACE from the pspace list, and releases it. */ - -void -remove_program_space (struct program_space *pspace) -{ - struct program_space *ss, **ss_link; - - ss = program_spaces; - ss_link = &program_spaces; - while (ss) - { - if (ss != pspace) - { - ss_link = &ss->next; - ss = *ss_link; - continue; - } - - *ss_link = ss->next; - release_program_space (ss); - ss = *ss_link; - } -} - /* Copies program space SRC to DEST. Copies the main executable file, and the main symbol file. Returns DEST. */ @@ -196,11 +189,11 @@ clone_program_space (struct program_space *dest, struct program_space *src) set_current_program_space (dest); - if (src->ebfd != NULL) - exec_file_attach (bfd_get_filename (src->ebfd), 0); + if (src->pspace_exec_filename != NULL) + exec_file_attach (src->pspace_exec_filename, 0); if (src->symfile_object_file != NULL) - symbol_file_add_main (src->symfile_object_file->name, 0); + symbol_file_add_main (objfile_name (src->symfile_object_file), 0); do_cleanups (old_chain); return dest; @@ -230,7 +223,7 @@ set_current_program_space (struct program_space *pspace) static void restore_program_space (void *arg) { - struct program_space *saved_pspace = arg; + struct program_space *saved_pspace = (struct program_space *) arg; set_current_program_space (saved_pspace); } @@ -250,8 +243,8 @@ save_current_program_space (void) /* Returns true iff there's no inferior bound to PSPACE. */ -static int -pspace_empty_p (struct program_space *pspace) +int +program_space_empty_p (struct program_space *pspace) { if (find_inferior_for_program_space (pspace) != NULL) return 0; @@ -259,30 +252,31 @@ pspace_empty_p (struct program_space *pspace) return 1; } -/* Prune away automatically added program spaces that aren't required - anymore. */ +/* Remove a program space from the program spaces list and release it. It is + an error to call this function while PSPACE is the current program space. */ void -prune_program_spaces (void) +delete_program_space (struct program_space *pspace) { struct program_space *ss, **ss_link; - struct program_space *current = current_program_space; + gdb_assert (pspace != NULL); + gdb_assert (pspace != current_program_space); ss = program_spaces; ss_link = &program_spaces; - while (ss) + while (ss != NULL) { - if (ss == current || !pspace_empty_p (ss)) + if (ss == pspace) { - ss_link = &ss->next; - ss = *ss_link; - continue; + *ss_link = ss->next; + break; } - *ss_link = ss->next; - release_program_space (ss); + ss_link = &ss->next; ss = *ss_link; } + + release_program_space (pspace); } /* Prints the list of program spaces and their details on UIOUT. If @@ -296,10 +290,6 @@ print_program_space (struct ui_out *uiout, int requested) int count = 0; struct cleanup *old_chain; - /* Might as well prune away unneeded ones, so the user doesn't even - seem them. */ - prune_program_spaces (); - /* Compute number of pspaces we will print. */ ALL_PSPACES (pspace) { @@ -313,10 +303,10 @@ print_program_space (struct ui_out *uiout, int requested) gdb_assert (count > 0); old_chain = make_cleanup_ui_out_table_begin_end (uiout, 3, count, "pspaces"); - ui_out_table_header (uiout, 1, ui_left, "current", ""); - ui_out_table_header (uiout, 4, ui_left, "id", "Id"); - ui_out_table_header (uiout, 17, ui_left, "exec", "Executable"); - ui_out_table_body (uiout); + uiout->table_header (1, ui_left, "current", ""); + uiout->table_header (4, ui_left, "id", "Id"); + uiout->table_header (17, ui_left, "exec", "Executable"); + uiout->table_body (); ALL_PSPACES (pspace) { @@ -330,17 +320,16 @@ print_program_space (struct ui_out *uiout, int requested) chain2 = make_cleanup_ui_out_tuple_begin_end (uiout, NULL); if (pspace == current_program_space) - ui_out_field_string (uiout, "current", "*"); + uiout->field_string ("current", "*"); else - ui_out_field_skip (uiout, "current"); + uiout->field_skip ("current"); - ui_out_field_int (uiout, "id", pspace->num); + uiout->field_int ("id", pspace->num); - if (pspace->ebfd) - ui_out_field_string (uiout, "exec", - bfd_get_filename (pspace->ebfd)); + if (pspace->pspace_exec_filename) + uiout->field_string ("exec", pspace->pspace_exec_filename); else - ui_out_field_skip (uiout, "exec"); + uiout->field_skip ("exec"); /* Print extra info that doesn't really fit in tabular form. Currently, we print the list of inferiors bound to a pspace. @@ -364,7 +353,7 @@ print_program_space (struct ui_out *uiout, int requested) target_pid_to_str (pid_to_ptid (inf->pid))); } - ui_out_text (uiout, "\n"); + uiout->text ("\n"); do_cleanups (chain2); } @@ -432,7 +421,7 @@ number_of_program_spaces (void) void update_address_spaces (void) { - int shared_aspace = gdbarch_has_shared_address_space (target_gdbarch); + int shared_aspace = gdbarch_has_shared_address_space (target_gdbarch ()); struct program_space *pspace; struct inferior *inf; @@ -454,7 +443,7 @@ update_address_spaces (void) } for (inf = inferior_list; inf; inf = inf->next) - if (gdbarch_has_global_solist (target_gdbarch)) + if (gdbarch_has_global_solist (target_gdbarch ())) inf->aspace = maybe_new_address_space (); else inf->aspace = inf->pspace->aspace; @@ -472,14 +461,14 @@ save_current_space_and_thread (void) /* If restoring to null thread, we need to restore the pspace as well, hence, we need to save the current program space first. */ old_chain = save_current_program_space (); - save_current_inferior (); + /* There's no need to save the current inferior here. + That is handled by make_cleanup_restore_current_thread. */ make_cleanup_restore_current_thread (); return old_chain; } -/* Switches full context to program space PSPACE. Switches to the - first thread found bound to PSPACE. */ +/* See progspace.h */ void switch_to_program_space_and_thread (struct program_space *pspace) @@ -487,7 +476,7 @@ switch_to_program_space_and_thread (struct program_space *pspace) struct inferior *inf; inf = find_inferior_for_program_space (pspace); - if (inf != NULL) + if (inf != NULL && inf->pid != 0) { struct thread_info *tp;