Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Aleksandar Ristovski <aristovski@qnx.com>
To: gdb-patches@sources.redhat.com
Subject: Re: ptid from core section
Date: Wed, 03 Jun 2009 16:59:00 -0000	[thread overview]
Message-ID: <h06a59$v55$1@ger.gmane.org> (raw)
In-Reply-To: <200906031541.49256.pedro@codesourcery.com>

[-- Attachment #1: Type: text/plain, Size: 2177 bytes --]

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

[-- Attachment #2: corelow.c-pid-from-section-20090601.diff --]
[-- Type: text/x-patch, Size: 9323 bytes --]

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 <<EOF
 /* Static function declarations */
 
 static void alloc_gdbarch_data (struct gdbarch *);
+static ptid_t default_ptid_from_core_section (struct gdbarch *, const bfd *,
+					      const asection *);
+static char *default_core_section_name_from_ptid (struct gdbarch *,
+						  const char *, ptid_t);
 
 /* Non-zero if we want to trace architecture code.  */
 
@@ -1663,6 +1668,30 @@ done
 # All the trailing guff
 cat <<EOF
 
+static ptid_t
+default_ptid_from_core_section (struct gdbarch *gdbarch, const bfd *abfd,
+			        const asection *asect)
+{
+  int thread_id;
+  ptid_t ptid;
+
+  thread_id = atoi (bfd_section_name (abfd, asect) + 5);
+  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 char *name,
+				     ptid_t ptid)
+{
+  if (ptid_get_lwp (ptid))
+    return xstrprintf ("%s/%ld", name, ptid_get_lwp (ptid));
+  else if (ptid_get_tid (ptid))
+    return xstrprintf ("%s/%ld", name, ptid_get_tid (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	1 Jun 2009 15:05:39 -0000
@@ -26,4 +26,10 @@ 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 (struct gdbarch *, const bfd *,
+				    const asection *);
+
+char *sol2_core_section_name_from_ptid (struct gdbarch *, 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	1 Jun 2009 15:05:39 -0000
@@ -47,3 +47,29 @@ 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 (struct gdbarch *gdbarch, const bfd *abfd,
+			     const asection *asect)
+{
+  int thread_id;
+
+  gdb_assert (asect != NULL);
+  thread_id = atoi (bfd_section_name (abfd, asect) + 5);
+
+  return ptid_build (thread_id & 0xffff, 0,
+		     thread_id >> 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);

  reply	other threads:[~2009-06-03 16:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-01 15:56 Aleksandar Ristovski
2009-06-03 14:41 ` Pedro Alves
2009-06-03 16:59   ` Aleksandar Ristovski [this message]
2009-06-03 18:41     ` Pedro Alves
2009-06-04 18:32       ` Aleksandar Ristovski
2009-06-05 13:43         ` Pedro Alves
2009-06-05 14:04           ` Aleksandar Ristovski
2009-06-05 14:39             ` Pedro Alves
2009-06-05 14:53               ` Aleksandar Ristovski
2009-06-05 16:26                 ` Pedro Alves
2009-06-05 17:54                   ` Aleksandar Ristovski
2009-06-05 19:00                     ` Pedro Alves
2009-06-05 19:03                       ` Aleksandar Ristovski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='h06a59$v55$1@ger.gmane.org' \
    --to=aristovski@qnx.com \
    --cc=gdb-patches@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox