Index: gdb/corelow.c =================================================================== RCS file: /cvs/src/src/gdb/corelow.c,v retrieving revision 1.85 diff -u -p -r1.85 corelow.c --- gdb/corelow.c 3 Jun 2009 18:50:36 -0000 1.85 +++ gdb/corelow.c 5 Jun 2009 14:49:27 -0000 @@ -239,25 +239,23 @@ static void add_to_thread_list (bfd *abfd, asection *asect, void *reg_sect_arg) { ptid_t ptid; - int thread_id; asection *reg_sect = (asection *) reg_sect_arg; if (strncmp (bfd_section_name (abfd, asect), ".reg/", 5) != 0) return; - thread_id = atoi (bfd_section_name (abfd, asect) + 5); - - if (core_gdbarch - && gdbarch_core_reg_section_encodes_pid (core_gdbarch)) + if (core_gdbarch != NULL) + ptid = gdbarch_ptid_from_core_section_name (core_gdbarch, abfd, + bfd_section_name (abfd, asect)); + else { - uint32_t merged_pid = thread_id; - ptid = ptid_build (merged_pid & 0xffff, - merged_pid >> 16, 0); + int thread_id = atoi (bfd_section_name (abfd, asect) + 5); + + ptid = ptid_build (ptid_get_pid (inferior_ptid), thread_id, 0); } - else - ptid = ptid_build (ptid_get_pid (inferior_ptid), thread_id, 0); - if (ptid_get_lwp (inferior_ptid) == 0) + if (ptid_get_tid (inferior_ptid) == 0 + && ptid_get_lwp (inferior_ptid) == 0) /* The main thread has already been added before getting here, and this is the first time we hear about a thread id. Assume this is the main thread. */ @@ -421,7 +419,9 @@ core_open (char *filename, int from_tty) name ..._from_host(). */ printf_filtered (_("Program terminated with signal %d, %s.\n"), siggy, target_signal_to_string ( - gdbarch_target_signal_from_host (core_gdbarch, siggy))); + core_gdbarch ? + gdbarch_target_signal_from_host (core_gdbarch, siggy) + : siggy)); /* Fetch all registers from core file. */ target_fetch_registers (get_current_regcache (), -1); @@ -464,11 +464,11 @@ deprecated_core_resize_section_table (in them to core_vec->core_read_registers, as the register set numbered WHICH. - If inferior_ptid's lwp member is zero, do the single-threaded - thing: look for a section named NAME. If inferior_ptid's lwp - member is non-zero, do the multi-threaded thing: look for a section - named "NAME/LWP", where LWP is the shortest ASCII decimal - representation of inferior_ptid's lwp member. + Architecture supplied function determines if NAME needs to be encoded + with process/thread information. Many architectures will, depending + on inferior_ptid, append "/LWP" or "/TID" where LWP and TID are the shortest + ASCII decimal representation of inferior_ptid's lwp/tid member. Some + architectures however, encode both process id and lwp/tid. HUMAN_NAME is a human-readable name for the kind of registers the NAME section contains, for use in error messages. @@ -490,16 +490,11 @@ get_core_register_section (struct regcac xfree (section_name); - if (core_gdbarch - && gdbarch_core_reg_section_encodes_pid (core_gdbarch)) - { - uint32_t merged_pid; - - merged_pid = ptid_get_lwp (inferior_ptid); - merged_pid = merged_pid << 16 | ptid_get_pid (inferior_ptid); - - section_name = xstrprintf ("%s/%s", name, plongest (merged_pid)); - } + if (core_gdbarch != NULL) + section_name = gdbarch_core_section_name_from_ptid (core_gdbarch, + core_bfd, + name, + inferior_ptid); else if (ptid_get_lwp (inferior_ptid)) section_name = xstrprintf ("%s/%ld", name, ptid_get_lwp (inferior_ptid)); else Index: gdb/gdbarch.sh =================================================================== RCS file: /cvs/src/src/gdb/gdbarch.sh,v retrieving revision 1.489 diff -u -p -r1.489 gdbarch.sh --- gdb/gdbarch.sh 19 May 2009 00:23:49 -0000 1.489 +++ gdb/gdbarch.sh 5 Jun 2009 14:49:27 -0000 @@ -602,10 +602,14 @@ M:const struct regset *:regset_from_core # When creating core dumps, some systems encode the PID in addition # to the LWP id in core file register section names. In those cases, the -# "XXX" in ".reg/XXX" is encoded as [LWPID << 16 | PID]. This setting -# is set to true for such architectures; false if "XXX" represents an LWP -# or thread id with no special encoding. -v:int:core_reg_section_encodes_pid:::0:0::0 +# "XXX" in ".reg/XXX" is encoded as [LWPID << 16 | PID]. Others have thread_id +# but no LWP. This let's different architectures provide their own +# ptid for a given section. +m:ptid_t:ptid_from_core_section_name:const bfd *abfd, const char *name:abfd, name::default_ptid_from_core_section_name::0 +# Mirror function of ptid_from_core_section_name, returns architecture-specific +# section name given NAME base. For example if NAME is ".reg" resulting +# name may be ".reg/42" where 42 is thread ID, or LWP or [LWPID << 16 | PID]. +m:char *:core_section_name_from_ptid:const bfd *abfd, const char *name, ptid_t ptid:abfd, name, ptid::default_core_section_name_from_ptid::0 # Supported register notes in a core file. v:struct core_regset_section *:core_regset_sections:const char *name, int len::::::host_address_to_string (gdbarch->core_regset_sections) @@ -1188,6 +1192,13 @@ cat <elf_make_msymbol_special = default_elf_make_msymbol_special; gdbarch->coff_make_msymbol_special = default_coff_make_msymbol_special; gdbarch->register_reggroup_p = default_register_reggroup_p; + gdbarch->ptid_from_core_section_name = default_ptid_from_core_section_name; + gdbarch->core_section_name_from_ptid = default_core_section_name_from_ptid; gdbarch->displaced_step_fixup = NULL; gdbarch->displaced_step_free_closure = NULL; gdbarch->displaced_step_location = NULL; @@ -617,7 +628,8 @@ verify_gdbarch (struct gdbarch *gdbarch) /* Skip verify of register_reggroup_p, invalid_p == 0 */ /* Skip verify of fetch_pointer_argument, has predicate */ /* Skip verify of regset_from_core_section, has predicate */ - /* Skip verify of core_reg_section_encodes_pid, invalid_p == 0 */ + /* Skip verify of ptid_from_core_section_name, invalid_p == 0 */ + /* Skip verify of core_section_name_from_ptid, invalid_p == 0 */ /* Skip verify of core_xfer_shared_libraries, has predicate */ /* Skip verify of core_pid_to_str, has predicate */ /* Skip verify of vtable_function_descriptors, invalid_p == 0 */ @@ -754,12 +766,12 @@ gdbarch_dump (struct gdbarch *gdbarch, s "gdbarch_dump: core_read_description = <%s>\n", host_address_to_string (gdbarch->core_read_description)); fprintf_unfiltered (file, - "gdbarch_dump: core_reg_section_encodes_pid = %s\n", - plongest (gdbarch->core_reg_section_encodes_pid)); - fprintf_unfiltered (file, "gdbarch_dump: core_regset_sections = %s\n", host_address_to_string (gdbarch->core_regset_sections)); fprintf_unfiltered (file, + "gdbarch_dump: core_section_name_from_ptid = <%s>\n", + host_address_to_string (gdbarch->core_section_name_from_ptid)); + fprintf_unfiltered (file, "gdbarch_dump: gdbarch_core_xfer_shared_libraries_p() = %d\n", gdbarch_core_xfer_shared_libraries_p (gdbarch)); fprintf_unfiltered (file, @@ -976,6 +988,9 @@ gdbarch_dump (struct gdbarch *gdbarch, s "gdbarch_dump: pseudo_register_write = <%s>\n", host_address_to_string (gdbarch->pseudo_register_write)); fprintf_unfiltered (file, + "gdbarch_dump: ptid_from_core_section_name = <%s>\n", + host_address_to_string (gdbarch->ptid_from_core_section_name)); + fprintf_unfiltered (file, "gdbarch_dump: ptr_bit = %s\n", plongest (gdbarch->ptr_bit)); fprintf_unfiltered (file, @@ -2929,21 +2944,38 @@ set_gdbarch_regset_from_core_section (st gdbarch->regset_from_core_section = regset_from_core_section; } -int -gdbarch_core_reg_section_encodes_pid (struct gdbarch *gdbarch) +ptid_t +gdbarch_ptid_from_core_section_name (struct gdbarch *gdbarch, const bfd *abfd, const char *name) +{ + gdb_assert (gdbarch != NULL); + gdb_assert (gdbarch->ptid_from_core_section_name != NULL); + if (gdbarch_debug >= 2) + fprintf_unfiltered (gdb_stdlog, "gdbarch_ptid_from_core_section_name called\n"); + return gdbarch->ptid_from_core_section_name (gdbarch, abfd, name); +} + +void +set_gdbarch_ptid_from_core_section_name (struct gdbarch *gdbarch, + gdbarch_ptid_from_core_section_name_ftype ptid_from_core_section_name) +{ + gdbarch->ptid_from_core_section_name = ptid_from_core_section_name; +} + +char * +gdbarch_core_section_name_from_ptid (struct gdbarch *gdbarch, const bfd *abfd, const char *name, ptid_t ptid) { gdb_assert (gdbarch != NULL); - /* Skip verify of core_reg_section_encodes_pid, invalid_p == 0 */ + gdb_assert (gdbarch->core_section_name_from_ptid != NULL); if (gdbarch_debug >= 2) - fprintf_unfiltered (gdb_stdlog, "gdbarch_core_reg_section_encodes_pid called\n"); - return gdbarch->core_reg_section_encodes_pid; + fprintf_unfiltered (gdb_stdlog, "gdbarch_core_section_name_from_ptid called\n"); + return gdbarch->core_section_name_from_ptid (gdbarch, abfd, name, ptid); } void -set_gdbarch_core_reg_section_encodes_pid (struct gdbarch *gdbarch, - int core_reg_section_encodes_pid) +set_gdbarch_core_section_name_from_ptid (struct gdbarch *gdbarch, + gdbarch_core_section_name_from_ptid_ftype core_section_name_from_ptid) { - gdbarch->core_reg_section_encodes_pid = core_reg_section_encodes_pid; + gdbarch->core_section_name_from_ptid = core_section_name_from_ptid; } struct core_regset_section * @@ -3405,6 +3437,35 @@ set_gdbarch_has_global_breakpoints (stru gdbarch->has_global_breakpoints = has_global_breakpoints; } +static ptid_t +default_ptid_from_core_section_name (struct gdbarch *gdbarch, const bfd *abfd, + const char *name) +{ + int thread_id; + ptid_t ptid; + const char *pos; + + pos = strchr (name, '/'); + if (pos == NULL) + pos = name + strlen (name); + else + pos++; + thread_id = atoi (pos); + ptid = ptid_build (ptid_get_pid (inferior_ptid), thread_id, 0); + return ptid; +} + +static char * +default_core_section_name_from_ptid (struct gdbarch *gdbarch, + const bfd *abfd, + const char *name, + ptid_t ptid) +{ + if (ptid_get_lwp (ptid)) + return xstrprintf ("%s/%ld", name, ptid_get_lwp (ptid)); + else + return xstrdup (name); +} /* Keep a registry of per-architecture data-pointers required by GDB modules. */ Index: gdb/sol2-tdep.h =================================================================== RCS file: /cvs/src/src/gdb/sol2-tdep.h,v retrieving revision 1.6 diff -u -p -r1.6 sol2-tdep.h --- gdb/sol2-tdep.h 23 Feb 2009 00:03:50 -0000 1.6 +++ gdb/sol2-tdep.h 5 Jun 2009 14:49:28 -0000 @@ -26,4 +26,11 @@ CORE_ADDR sol2_skip_solib_resolver (stru char *sol2_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid); +ptid_t sol2_ptid_from_core_section_name (struct gdbarch *, const bfd *, + const char *); + +char *sol2_core_section_name_from_ptid (struct gdbarch *, const bfd *, + const char *, + ptid_t); + #endif /* sol2-tdep.h */ Index: gdb/sol2-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/sol2-tdep.c,v retrieving revision 1.8 diff -u -p -r1.8 sol2-tdep.c --- gdb/sol2-tdep.c 23 Feb 2009 00:03:50 -0000 1.8 +++ gdb/sol2-tdep.c 5 Jun 2009 14:49:28 -0000 @@ -47,3 +47,35 @@ sol2_core_pid_to_str (struct gdbarch *gd xsnprintf (buf, sizeof buf, "LWP %ld", ptid_get_lwp (ptid)); return buf; } + + +ptid_t +sol2_ptid_from_core_section_name (struct gdbarch *gdbarch, const bfd *abfd, + const char *name) +{ + int thread_id; + const char *pos; + + gdb_assert (name != NULL); + pos = strchr (name, '/'); + if (pos == NULL) + pos = name + strlen (name); + else + pos++; + thread_id = (*pos) ? atoi (pos) : 0; + return ptid_build (thread_id & 0xffff, 0, + thread_id >> 16); +} + +char * +sol2_core_section_name_from_ptid (struct gdbarch *gdbarch, const bfd *abfd, + const char *name, + ptid_t ptid) +{ + uint32_t merged_pid; + + merged_pid = ptid_get_lwp (ptid); + merged_pid = merged_pid << 16 | ptid_get_pid (ptid); + return xstrprintf ("%s/%s", name, plongest (merged_pid)); +} + Index: gdb/amd64-sol2-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/amd64-sol2-tdep.c,v retrieving revision 1.10 diff -u -p -r1.10 amd64-sol2-tdep.c --- gdb/amd64-sol2-tdep.c 23 Feb 2009 00:03:48 -0000 1.10 +++ gdb/amd64-sol2-tdep.c 5 Jun 2009 14:49:28 -0000 @@ -116,7 +116,10 @@ amd64_sol2_init_abi (struct gdbarch_info /* Solaris encodes the pid of the inferior in regset section names. */ - set_gdbarch_core_reg_section_encodes_pid (gdbarch, 1); + set_gdbarch_ptid_from_core_section_name (gdbarch, + sol2_ptid_from_core_section_name); + set_gdbarch_core_section_name_from_ptid (gdbarch, + sol2_core_section_name_from_ptid); /* How to print LWP PTIDs from core files. */ set_gdbarch_core_pid_to_str (gdbarch, sol2_core_pid_to_str); Index: gdb/sparc-sol2-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/sparc-sol2-tdep.c,v retrieving revision 1.20 diff -u -p -r1.20 sparc-sol2-tdep.c --- gdb/sparc-sol2-tdep.c 23 Feb 2009 00:03:50 -0000 1.20 +++ gdb/sparc-sol2-tdep.c 5 Jun 2009 14:49:28 -0000 @@ -234,7 +234,10 @@ sparc32_sol2_init_abi (struct gdbarch_in /* Solaris encodes the pid of the inferior in regset section names. */ - set_gdbarch_core_reg_section_encodes_pid (gdbarch, 1); + set_gdbarch_ptid_from_core_section_name (gdbarch, + sol2_ptid_from_core_section_name); + set_gdbarch_core_section_name_from_ptid (gdbarch, + sol2_core_section_name_from_ptid); /* How to print LWP PTIDs from core files. */ set_gdbarch_core_pid_to_str (gdbarch, sol2_core_pid_to_str); Index: gdb/sparc64-sol2-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/sparc64-sol2-tdep.c,v retrieving revision 1.19 diff -u -p -r1.19 sparc64-sol2-tdep.c --- gdb/sparc64-sol2-tdep.c 23 Feb 2009 00:03:50 -0000 1.19 +++ gdb/sparc64-sol2-tdep.c 5 Jun 2009 14:49:28 -0000 @@ -183,7 +183,10 @@ sparc64_sol2_init_abi (struct gdbarch_in /* Solaris encodes the pid of the inferior in regset section names. */ - set_gdbarch_core_reg_section_encodes_pid (gdbarch, 1); + set_gdbarch_ptid_from_core_section_name (gdbarch, + sol2_ptid_from_core_section_name); + set_gdbarch_core_section_name_from_ptid (gdbarch, + sol2_core_section_name_from_ptid); /* How to print LWP PTIDs from core files. */ set_gdbarch_core_pid_to_str (gdbarch, sol2_core_pid_to_str); Index: gdb/i386-sol2-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/i386-sol2-tdep.c,v retrieving revision 1.28 diff -u -p -r1.28 i386-sol2-tdep.c --- gdb/i386-sol2-tdep.c 23 Feb 2009 00:03:49 -0000 1.28 +++ gdb/i386-sol2-tdep.c 5 Jun 2009 14:49:28 -0000 @@ -138,7 +138,10 @@ i386_sol2_init_abi (struct gdbarch_info /* Solaris encodes the pid of the inferior in regset section names. */ - set_gdbarch_core_reg_section_encodes_pid (gdbarch, 1); + set_gdbarch_ptid_from_core_section_name (gdbarch, + sol2_ptid_from_core_section_name); + set_gdbarch_core_section_name_from_ptid (gdbarch, + sol2_core_section_name_from_ptid); /* How to print LWP PTIDs from core files. */ set_gdbarch_core_pid_to_str (gdbarch, sol2_core_pid_to_str);