From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26459 invoked by alias); 3 Jun 2009 16:59:51 -0000 Received: (qmail 26429 invoked by uid 22791); 3 Jun 2009 16:59:45 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,HK_OBFDOM,J_CHICKENPOX_15,J_CHICKENPOX_16,J_CHICKENPOX_44,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from main.gmane.org (HELO ciao.gmane.org) (80.91.229.2) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 03 Jun 2009 16:59:35 +0000 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1MBtoK-0007DJ-Fk for gdb-patches@sources.redhat.com; Wed, 03 Jun 2009 16:59:32 +0000 Received: from entropy.qnx.com ([209.226.137.107]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 03 Jun 2009 16:59:32 +0000 Received: from aristovski by entropy.qnx.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 03 Jun 2009 16:59:32 +0000 To: gdb-patches@sources.redhat.com From: Aleksandar Ristovski Subject: Re: ptid from core section Date: Wed, 03 Jun 2009 16:59:00 -0000 Message-ID: References: <4A23F9FF.8040708@qnx.com> <200906031541.49256.pedro@codesourcery.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------030106090509030101070703" User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) In-Reply-To: <200906031541.49256.pedro@codesourcery.com> X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-06/txt/msg00041.txt.bz2 This is a multi-part message in MIME format. --------------030106090509030101070703 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 2177 Pedro Alves wrote: > On Monday 01 June 2009 16:55:43, Aleksandar Ristovski wrote: > >> In corelow.c we have several architecture specific lines for >> determining ptid from core section. The same for getting >> section name given inferior_ptid. >> >> This patch moves architecture specific parts into two new >> functions: gdbarch_ptid_from_core_section and >> gdbarch_core_section_name_from_ptid. >> >> They replace Pedro's gdbarch_core_reg_section_encodes_pid >> since predicate is now redundant. >> >> I haven't added diffs for generated gdbarch.h/c, I would >> like to get your thoughts about this first. > > As we talked about on IRC the other day, a better solution > could require a redesign and normalization of how bfd exposes these > thread/lwp/process ids. In principle, this change is fine > with me, but it seems you forgot to attach the patch. :-) > > It would be nice if you included the nto bits in the > patch, so we can see how this helps in your case, so > that people can check upfront if this change is > sufficient and good. > oops... and you couldn't guess??? :-D Sorry about that. nto bits are actually included since otherwise gdb wouldn't properly add threads. We add threads like this: ptid_build(pid, 0, thread_id) as opposed to default ptid_build(pid, lwp, 0); Changelog again: * corelow.c (add_to_thread_list): Use new gdbarch_ptid_from_core_section. (get_core_register_section): Use new gdbarch_core_section_name_from_ptid. * gdbarch.sh (core_reg_section_encodes_pid): Deleted. (ptid_from_core_section, core_section_name_from_ptid): New functions. (default_ptid_from_core_section, default_core_section_name_from_ptid): New functions. * sol2-tdep.h (sol2_ptid_from_core_section, sol2_core_section_name_from_ptid): New declarations. * sol2-tdep.c (sol2_ptid_from_core_section, sol2_core_section_name_from_ptid): New functions. * amd64-sol2-tdep.c (amd64_sol2_init_abi): Register the two functions. * sparc-sol2-tdep.c (sparc32_sol2_init_abi): Likewise. * sparc64-sol2-tdep.c (sparc64_sol2_init_abi): Likewise. * i386-sol2-tdep.c (i386_sol2_init_abi): Likewise. -- Aleksandar Ristovski QNX Software Systems --------------030106090509030101070703 Content-Type: text/x-patch; name="corelow.c-pid-from-section-20090601.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="corelow.c-pid-from-section-20090601.diff" Content-length: 9323 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 1 Jun 2009 15:05:39 -0000 @@ -239,19 +239,10 @@ 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 (core_gdbarch, 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. */ @@ -465,20 +456,9 @@ 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, + name, + inferior_ptid); section = bfd_get_section_by_name (core_bfd, section_name); if (! section) 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 1 Jun 2009 15:05:39 -0000 @@ -602,10 +602,11 @@ 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:const bfd *abfd, const asection *asect:abfd, asect::default_ptid_from_core_section::0 +m:char *:core_section_name_from_ptid:const char *name, ptid_t ptid: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 +1189,10 @@ cat <> 16); +} + +char * +sol2_core_section_name_from_ptid (struct gdbarch *gdbarch, 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 1 Jun 2009 15:05:39 -0000 @@ -116,7 +116,8 @@ 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 (sol2_ptid_from_core_section); + set_gdbarch_core_section_name_from_ptid (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 1 Jun 2009 15:05:39 -0000 @@ -234,7 +234,9 @@ 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 (gdbarch, sol2_ptid_from_core_section); + 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 1 Jun 2009 15:05:39 -0000 @@ -183,7 +183,9 @@ 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 (gdbarch, sol2_ptid_from_core_section); + 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 1 Jun 2009 15:05:39 -0000 @@ -138,7 +138,9 @@ 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 (gdbarch, sol2_ptid_from_core_section); + 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); --------------030106090509030101070703--