Index: gdb/corelow.c =================================================================== RCS file: /cvs/src/src/gdb/corelow.c,v retrieving revision 1.84 diff -u -p -r1.84 corelow.c --- gdb/corelow.c 18 May 2009 12:12:16 -0000 1.84 +++ gdb/corelow.c 4 Jun 2009 13:29:54 -0000 @@ -239,19 +239,11 @@ add_to_thread_list (bfd *abfd, asection if (strncmp (bfd_section_name (abfd, asect), ".reg/", 5) != 0) return; - thread_id = atoi (bfd_section_name (abfd, asect) + 5); + ptid = gdbarch_ptid_from_core_section_name (core_gdbarch, abfd, + bfd_section_name (abfd, asect)); - if (core_gdbarch - && gdbarch_core_reg_section_encodes_pid (core_gdbarch)) - { - uint32_t merged_pid = thread_id; - ptid = ptid_build (merged_pid & 0xffff, - merged_pid >> 16, 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. */ @@ -439,11 +431,11 @@ core_detach (struct target_ops *ops, cha 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. @@ -465,20 +457,10 @@ 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)); - } - else if (ptid_get_lwp (inferior_ptid)) - section_name = xstrprintf ("%s/%ld", name, ptid_get_lwp (inferior_ptid)); - else - section_name = xstrdup (name); + section_name = gdbarch_core_section_name_from_ptid (core_gdbarch, + core_bfd, + name, + inferior_ptid); section = bfd_get_section_by_name (core_bfd, section_name); if (! section) Index: gdb/gdbarch.h =================================================================== RCS file: /cvs/src/src/gdb/gdbarch.h,v retrieving revision 1.397 diff -u -p -r1.397 gdbarch.h --- gdb/gdbarch.h 19 May 2009 00:23:49 -0000 1.397 +++ gdb/gdbarch.h 4 Jun 2009 13:29:55 -0000 @@ -651,12 +651,21 @@ extern void set_gdbarch_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. */ - -extern int gdbarch_core_reg_section_encodes_pid (struct gdbarch *gdbarch); -extern void set_gdbarch_core_reg_section_encodes_pid (struct gdbarch *gdbarch, int core_reg_section_encodes_pid); + "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. */ + +typedef ptid_t (gdbarch_ptid_from_core_section_name_ftype) (struct gdbarch *gdbarch, const bfd *abfd, const char *name); +extern ptid_t gdbarch_ptid_from_core_section_name (struct gdbarch *gdbarch, const bfd *abfd, const char *name); +extern void set_gdbarch_ptid_from_core_section_name (struct gdbarch *gdbarch, gdbarch_ptid_from_core_section_name_ftype *ptid_from_core_section_name); + +/* 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]. */ + +typedef char * (gdbarch_core_section_name_from_ptid_ftype) (struct gdbarch *gdbarch, const bfd *abfd, const char *name, ptid_t ptid); +extern char * gdbarch_core_section_name_from_ptid (struct gdbarch *gdbarch, const bfd *abfd, const char *name, ptid_t ptid); +extern void set_gdbarch_core_section_name_from_ptid (struct gdbarch *gdbarch, gdbarch_core_section_name_from_ptid_ftype *core_section_name_from_ptid); /* Supported register notes in a core file. */ Index: gdb/gdbarch.c =================================================================== RCS file: /cvs/src/src/gdb/gdbarch.c,v retrieving revision 1.446 diff -u -p -r1.446 gdbarch.c --- gdb/gdbarch.c 19 May 2009 00:23:49 -0000 1.446 +++ gdb/gdbarch.c 4 Jun 2009 13:29:55 -0000 @@ -53,6 +53,13 @@ /* Static function declarations */ static void alloc_gdbarch_data (struct gdbarch *); +static ptid_t default_ptid_from_core_section_name (struct gdbarch *, + const bfd *, + const char *); +static char *default_core_section_name_from_ptid (struct gdbarch *, + const bfd *, + const char *name, + ptid_t); /* Non-zero if we want to trace architecture code. */ @@ -223,7 +230,8 @@ struct gdbarch gdbarch_register_reggroup_p_ftype *register_reggroup_p; gdbarch_fetch_pointer_argument_ftype *fetch_pointer_argument; gdbarch_regset_from_core_section_ftype *regset_from_core_section; - int core_reg_section_encodes_pid; + gdbarch_ptid_from_core_section_name_ftype *ptid_from_core_section_name; + gdbarch_core_section_name_from_ptid_ftype *core_section_name_from_ptid; struct core_regset_section * core_regset_sections; gdbarch_core_xfer_shared_libraries_ftype *core_xfer_shared_libraries; gdbarch_core_pid_to_str_ftype *core_pid_to_str; @@ -360,7 +368,8 @@ struct gdbarch startup_gdbarch = default_register_reggroup_p, /* register_reggroup_p */ 0, /* fetch_pointer_argument */ 0, /* regset_from_core_section */ - 0, /* core_reg_section_encodes_pid */ + default_ptid_from_core_section_name, /* ptid_from_core_section_name */ + default_core_section_name_from_ptid, /* core_section_name_from_ptid */ 0, /* core_regset_sections */ 0, /* core_xfer_shared_libraries */ 0, /* core_pid_to_str */ @@ -462,6 +471,8 @@ gdbarch_alloc (const struct gdbarch_info gdbarch->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 4 Jun 2009 13:29:55 -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 4 Jun 2009 13:29:55 -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 4 Jun 2009 13:29:55 -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 4 Jun 2009 13:29:55 -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 4 Jun 2009 13:29:55 -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 4 Jun 2009 13:29:55 -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);