* ptid from core section
@ 2009-06-01 15:56 Aleksandar Ristovski
2009-06-03 14:41 ` Pedro Alves
0 siblings, 1 reply; 13+ messages in thread
From: Aleksandar Ristovski @ 2009-06-01 15:56 UTC (permalink / raw)
To: gdb-patches; +Cc: Pedro Alves
Hello,
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.
Thanks,
Aleksandar Ristovski
QNX Software Systems
Change log:
* 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.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: ptid from core section
2009-06-01 15:56 ptid from core section Aleksandar Ristovski
@ 2009-06-03 14:41 ` Pedro Alves
2009-06-03 16:59 ` Aleksandar Ristovski
0 siblings, 1 reply; 13+ messages in thread
From: Pedro Alves @ 2009-06-03 14:41 UTC (permalink / raw)
To: gdb-patches; +Cc: Aleksandar Ristovski
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.
--
Pedro Alves
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: ptid from core section
2009-06-03 14:41 ` Pedro Alves
@ 2009-06-03 16:59 ` Aleksandar Ristovski
2009-06-03 18:41 ` Pedro Alves
0 siblings, 1 reply; 13+ messages in thread
From: Aleksandar Ristovski @ 2009-06-03 16:59 UTC (permalink / raw)
To: gdb-patches
[-- 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);
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: ptid from core section
2009-06-03 16:59 ` Aleksandar Ristovski
@ 2009-06-03 18:41 ` Pedro Alves
2009-06-04 18:32 ` Aleksandar Ristovski
0 siblings, 1 reply; 13+ messages in thread
From: Pedro Alves @ 2009-06-03 18:41 UTC (permalink / raw)
To: gdb-patches; +Cc: Aleksandar Ristovski
On Wednesday 03 June 2009 17:59:21, Aleksandar Ristovski wrote:
> > 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
The rumours that I'm clairvoyant are really just rumours. :-)
> * sol2-tdep.h (sol2_ptid_from_core_section,
> sol2_core_section_name_from_ptid): New declarations.
Please line wrap these cases like:
* sol2-tdep.h (sol2_ptid_from_core_section)
(sol2_core_section_name_from_ptid): New declarations.
Thanks. Don't forget to add something like this to the changelog:
* gdbarch.h, gdbarch.c: Regenerate.
This is mostly OK as far as I'm concerned. One question though:
> (ptid_from_core_section, core_section_name_from_ptid): New
> functions.
Is there still a reason the former takes bfd and bfd section pointers,
instead of being a mirror of the latter (say, ptid_from_core_section_name)?
--
Pedro Alves
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: ptid from core section
2009-06-03 18:41 ` Pedro Alves
@ 2009-06-04 18:32 ` Aleksandar Ristovski
2009-06-05 13:43 ` Pedro Alves
0 siblings, 1 reply; 13+ messages in thread
From: Aleksandar Ristovski @ 2009-06-04 18:32 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 1509 bytes --]
Pedro Alves wrote:
> This is mostly OK as far as I'm concerned. One question though:
>
>> (ptid_from_core_section, core_section_name_from_ptid): New
>> functions.
>
> Is there still a reason the former takes bfd and bfd section pointers,
> instead of being a mirror of the latter (say, ptid_from_core_section_name)?
>
Not a good reason. I just used what was available at the
calling site. The attached patch makes arguments of the two
new callbacks symmetrical (as much as was possible) as well
as makes their names symmetrical.
This time, gdbarch.[ch] included.
ChangeLog:
* corelow.c (add_to_thread_list): Use new
gdbarch_ptid_from_core_section_name.
(get_core_register_section): Use new
gdbarch_core_section_name_from_ptid.
* gdbarch.sh (core_reg_section_encodes_pid): Deleted.
(ptid_from_core_section_name)
(core_section_name_from_ptid): New gdbarch callbacks.
(default_ptid_from_core_section_name)
(default_core_section_name_from_ptid): New functions.
* gdbarch.h, gdbarch.c: Regenerate.
* sol2-tdep.h (sol2_ptid_from_core_section_name)
(sol2_core_section_name_from_ptid): New declarations.
* sol2-tdep.c (sol2_ptid_from_core_section_name)
(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.
Thanks,
Aleksandar Ristovski
QNX Software Systems
[-- Attachment #2: corelow.c-pid-from-section-20090604.diff --]
[-- Type: text/x-patch, Size: 17638 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 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);
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: ptid from core section
2009-06-04 18:32 ` Aleksandar Ristovski
@ 2009-06-05 13:43 ` Pedro Alves
2009-06-05 14:04 ` Aleksandar Ristovski
0 siblings, 1 reply; 13+ messages in thread
From: Pedro Alves @ 2009-06-05 13:43 UTC (permalink / raw)
To: gdb-patches; +Cc: Aleksandar Ristovski
On Thursday 04 June 2009 19:31:58, Aleksandar Ristovski wrote:
> Pedro Alves wrote:
> > This is mostly OK as far as I'm concerned. One question though:
> >
> >> (ptid_from_core_section, core_section_name_from_ptid): New
> >> functions.
> >
> > Is there still a reason the former takes bfd and bfd section pointers,
> > instead of being a mirror of the latter (say, ptid_from_core_section_name)?
> >
>
> Not a good reason. I just used what was available at the
> calling site. The attached patch makes arguments of the two
> new callbacks symmetrical (as much as was possible) as well
> as makes their names symmetrical.
>
> This time, gdbarch.[ch] included.
>
>
Hmm, sorry I missed something before...
AFAICS, core_gdbarch can end up being left NULL. Most code
that accesses it in corelow.c handles it's NULL-ness, while your
change adds some unconditional accesses. The path of
least resistence to fix this, is to move the callback defaults
to corelow.c, make the new callbacks optional, and check
for 'core_gdbarch && gdbarch_foo_p (core_gdbarch)' predicates
before calling the optional callbacks.
( This does raise the question of which gdbarch is the best in these
case: core_gdbarch; the executable's gdbarch; the more refined
target_gdbarch, which in turn is refined from current_gdbarch
through core_read_description. Yuk. )
--
Pedro Alves
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: ptid from core section
2009-06-05 13:43 ` Pedro Alves
@ 2009-06-05 14:04 ` Aleksandar Ristovski
2009-06-05 14:39 ` Pedro Alves
0 siblings, 1 reply; 13+ messages in thread
From: Aleksandar Ristovski @ 2009-06-05 14:04 UTC (permalink / raw)
To: gdb-patches
Pedro Alves wrote:
> On Thursday 04 June 2009 19:31:58, Aleksandar Ristovski wrote:
>> Pedro Alves wrote:
>>> This is mostly OK as far as I'm concerned. One question though:
>>>
>>>> (ptid_from_core_section, core_section_name_from_ptid): New
>>>> functions.
>>> Is there still a reason the former takes bfd and bfd section pointers,
>>> instead of being a mirror of the latter (say, ptid_from_core_section_name)?
>>>
>> Not a good reason. I just used what was available at the
>> calling site. The attached patch makes arguments of the two
>> new callbacks symmetrical (as much as was possible) as well
>> as makes their names symmetrical.
>>
>> This time, gdbarch.[ch] included.
>>
>>
>
> Hmm, sorry I missed something before...
>
> AFAICS, core_gdbarch can end up being left NULL. Most code
> that accesses it in corelow.c handles it's NULL-ness, while your
In core_open, there is already a gdbarch callback which
doesn't check for its NULL-ness (piece added by me), namely
gdbarch_target_signal_from_host.
What are the circumstances under which core_gdbarch would
not be found? If we are opening a core from a system gdb was
not configured for?
> change adds some unconditional accesses. The path of
> least resistence to fix this, is to move the callback defaults
> to corelow.c, make the new callbacks optional, and check
> for 'core_gdbarch && gdbarch_foo_p (core_gdbarch)' predicates
> before calling the optional callbacks.
>
> ( This does raise the question of which gdbarch is the best in these
> case: core_gdbarch; the executable's gdbarch; the more refined
> target_gdbarch, which in turn is refined from current_gdbarch
> through core_read_description. Yuk. )
>
--
Aleksandar Ristovski
QNX Software Systems
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: ptid from core section
2009-06-05 14:04 ` Aleksandar Ristovski
@ 2009-06-05 14:39 ` Pedro Alves
2009-06-05 14:53 ` Aleksandar Ristovski
0 siblings, 1 reply; 13+ messages in thread
From: Pedro Alves @ 2009-06-05 14:39 UTC (permalink / raw)
To: gdb-patches; +Cc: Aleksandar Ristovski
On Friday 05 June 2009 15:04:19, Aleksandar Ristovski wrote:
> What are the circumstances under which core_gdbarch would
> not be found? If we are opening a core from a system gdb was
> not configured for?
E.g., we still have targets using the deprecated_add_core_fns
mechanism, and AFAICS, usually those don't usually install
gdbarch sniffers for the core bfd's they handle. E.g.,
gdb/alpha-nat.c:
/* Register that we are able to handle alpha core file formats. */
static struct core_fns alpha_osf_core_fns =
{
/* This really is bfd_target_unknown_flavour. */
bfd_target_unknown_flavour, /* core_flavour */
default_check_format, /* check_format */
default_core_sniffer, /* core_sniffer */
fetch_osf_core_registers, /* core_read_registers */
NULL /* next */
};
gdb/alpha-nat.c is pulled in by:
src/gdb/config/alpha/alpha-osf3.mh
while src/gdb/configure.tgt, indicates that alpha*-*-osf*
pulls in:
alpha*-*-osf*)
# Target: Little-endian Alpha running OSF/1
gdb_target_obs="alpha-tdep.o alpha-osf1-tdep.o alpha-mdebug-tdep.o"
;;
and, I don't see any sniffer for osf core's in alpha-osf1-tdep.c.
There may be other cores supported by bfd that end
up with similar situations, on some not-so-common configurations.
>cd bfd/
>ls *core*
aix386-core.c corefile.c elf32-score7.c hppabsd-core.c netbsd-core.c ptrace-core.c
aix5ppc-core.c cpu-mcore.c elf32-score.c hpux-core.c osf-core.c rs6000-core.c
cisco-core.c cpu-score.c elf32-score.h irix-core.c pei-mcore.c sco5-core.c
coff-mcore.c elf32-mcore.c elfcore.h lynx-core.c pe-mcore.c trad-core.c
--
Pedro Alves
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: ptid from core section
2009-06-05 14:39 ` Pedro Alves
@ 2009-06-05 14:53 ` Aleksandar Ristovski
2009-06-05 16:26 ` Pedro Alves
0 siblings, 1 reply; 13+ messages in thread
From: Aleksandar Ristovski @ 2009-06-05 14:53 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 1660 bytes --]
Pedro Alves wrote:
> On Friday 05 June 2009 15:04:19, Aleksandar Ristovski wrote:
>
>> What are the circumstances under which core_gdbarch would
>> not be found? If we are opening a core from a system gdb was
>> not configured for?
>
> E.g., we still have targets using the deprecated_add_core_fns
> mechanism, and AFAICS, usually those don't usually install
> gdbarch sniffers for the core bfd's they handle. E.g.,
Understood and agreed.
Here is a new patch. I made sure it works even if
core_gdbarch is NULL. I also fixed my previous patch for
target signal by checking if there is a core_gdbarch.
Thanks,
--
Aleksandar Ristovski
QNX Software Systems
Change log remained the same, but repeated for reference:
2009-06-05 Aleksandar Ristovski <aristovski@qnx.com>
* corelow.c (add_to_thread_list): Use new
gdbarch_ptid_from_core_section_name.
(get_core_register_section): Use new
gdbarch_core_section_name_from_ptid.
* gdbarch.sh (core_reg_section_encodes_pid): Deleted.
(ptid_from_core_section_name)
(core_section_name_from_ptid): New gdbarch callbacks.
(default_ptid_from_core_section_name)
(default_core_section_name_from_ptid): New functions.
* gdbarch.h, gdbarch.c: Regenerate.
* sol2-tdep.h (sol2_ptid_from_core_section_name)
(sol2_core_section_name_from_ptid): New declarations.
* sol2-tdep.c (sol2_ptid_from_core_section_name)
(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.
[-- Attachment #2: corelow.c-pid-from-section-20090605.diff --]
[-- Type: text/x-patch, Size: 21185 bytes --]
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 <<EOF
/* 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. */
@@ -1663,6 +1674,35 @@ done
# All the trailing guff
cat <<EOF
+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/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 5 Jun 2009 14:49:28 -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 5 Jun 2009 14:49:28 -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 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);
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: ptid from core section
2009-06-05 14:53 ` Aleksandar Ristovski
@ 2009-06-05 16:26 ` Pedro Alves
2009-06-05 17:54 ` Aleksandar Ristovski
0 siblings, 1 reply; 13+ messages in thread
From: Pedro Alves @ 2009-06-05 16:26 UTC (permalink / raw)
To: gdb-patches; +Cc: Aleksandar Ristovski
On Friday 05 June 2009 15:53:00, Aleksandar Ristovski wrote:
> Here is a new patch. I made sure it works even if
> core_gdbarch is NULL.
Sorry, we're going a bit in circles. The way you've now
implemented it, there are three ways to get a ptid
from a core reg section, but two of them are mostly
the same --- the default gdbarch fallbacks, and the
case of core_gdbarch being NULL handled in corelow.c itself.
On Friday 05 June 2009 14:44:37, Pedro Alves wrote:
> change adds some unconditional accesses. The path of
> least resistence to fix this, is to move the callback defaults
> to corelow.c, make the new callbacks optional, and check
> for 'core_gdbarch && gdbarch_foo_p (core_gdbarch)' predicates
> before calling the optional callbacks.
This meant:
On Friday 05 June 2009 15:53:00, Aleksandar Ristovski wrote:
> +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);
> +}
Moving these functions to corelow.c, and making the gdbarch callbacks
optional. Wouldn't that look cleaner? Something like the patch below.
But, at this point, I'm now confused, and I have to re-ask:
What is it that gets confused on nto when core files store
the thread id in the lwp field of ptids instead of on the tid
field? Your original patch only took care to adjust to
read tids from the tid field in default_core_section_from_ptid,
but didn't do anything to make ptids that stored the tid
in the tid field in default_ptid_from_core_section? While
your latest patch didn't even do that in
default_ptid_from_core_section_name? I can't see how you
avoid adding gdbarch callbacks for nto.
> I also fixed my previous patch for
> target signal by checking if there is a core_gdbarch.
Could you go ahead, and check in just that bit
split out from the rest please? Thanks.
--
Pedro Alves
---
gdb/amd64-sol2-tdep.c | 5 ++
gdb/corelow.c | 84 ++++++++++++++++++++++++++++++------------------
gdb/gdbarch.c | 70 ++++++++++++++++++++++++++++++++--------
gdb/gdbarch.h | 23 ++++++++++---
gdb/gdbarch.sh | 13 ++++---
gdb/i386-sol2-tdep.c | 5 ++
gdb/sol2-tdep.c | 31 +++++++++++++++++
gdb/sol2-tdep.h | 7 ++++
gdb/sparc-sol2-tdep.c | 5 ++
gdb/sparc64-sol2-tdep.c | 5 ++
10 files changed, 190 insertions(+), 58 deletions(-)
Index: src/gdb/corelow.c
===================================================================
--- src.orig/gdb/corelow.c 2009-06-05 16:16:28.000000000 +0100
+++ src/gdb/corelow.c 2009-06-05 16:56:32.000000000 +0100
@@ -232,6 +232,37 @@ core_close_cleanup (void *ignore)
core_close (0/*ignored*/);
}
+static ptid_t
+default_ptid_from_core_section_name (const bfd *abfd, const char *name)
+{
+ int lwpid;
+ const char *pos;
+
+ pos = strchr (name, '/');
+
+ /* Our caller filters sections whose name starts with ".reg/". */
+ gdb_assert (pos != NULL);
+
+ pos++;
+
+ /* Note that this returns a legitimate 0, in case the section name
+ didn't really have a lwp/tid specifier (e.g., it was just
+ ".reg". */
+ lwpid = atoi (pos);
+
+ return ptid_build (ptid_get_pid (inferior_ptid), lwpid, 0);
+}
+
+static char *
+default_core_section_name_from_ptid (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);
+}
+
/* Look for sections whose names start with `.reg/' so that we can extract the
list of threads in a core file. */
@@ -241,23 +272,20 @@ add_to_thread_list (bfd *abfd, asection
ptid_t ptid;
int thread_id;
asection *reg_sect = (asection *) reg_sect_arg;
+ const char *section_name = bfd_section_name (abfd, asect);
- if (strncmp (bfd_section_name (abfd, asect), ".reg/", 5) != 0)
+ if (strncmp (section_name, ".reg/", 5) != 0)
return;
- thread_id = atoi (bfd_section_name (abfd, asect) + 5);
-
- 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);
- }
+ if (core_gdbarch != NULL
+ && gdbarch_ptid_from_core_section_name_p (core_gdbarch))
+ ptid = gdbarch_ptid_from_core_section_name (core_gdbarch,
+ abfd, section_name);
else
- ptid = ptid_build (ptid_get_pid (inferior_ptid), thread_id, 0);
+ ptid = default_ptid_from_core_section_name (abfd, section_name);
- if (ptid_get_lwp (inferior_ptid) == 0)
+ if (ptid_get_lwp (inferior_ptid) == 0
+ && ptid_get_tid (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. */
@@ -464,11 +492,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,20 +518,16 @@ 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));
+ if (core_gdbarch != NULL
+ && gdbarch_core_section_name_from_ptid_p (core_gdbarch))
+ section_name = gdbarch_core_section_name_from_ptid (core_gdbarch,
+ core_bfd,
+ name,
+ inferior_ptid);
else
- section_name = xstrdup (name);
+ section_name = default_core_section_name_from_ptid (core_bfd,
+ name,
+ inferior_ptid);
section = bfd_get_section_by_name (core_bfd, section_name);
if (! section)
Index: src/gdb/gdbarch.h
===================================================================
--- src.orig/gdb/gdbarch.h 2009-06-05 16:16:28.000000000 +0100
+++ src/gdb/gdbarch.h 2009-06-05 16:29:05.000000000 +0100
@@ -651,12 +651,25 @@ 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. */
+ "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. */
-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);
+extern int gdbarch_ptid_from_core_section_name_p (struct gdbarch *gdbarch);
+
+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]. */
+
+extern int gdbarch_core_section_name_from_ptid_p (struct gdbarch *gdbarch);
+
+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: src/gdb/gdbarch.c
===================================================================
--- src.orig/gdb/gdbarch.c 2009-06-05 16:16:27.000000000 +0100
+++ src/gdb/gdbarch.c 2009-06-05 16:29:11.000000000 +0100
@@ -223,7 +223,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 +361,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 */
+ 0, /* ptid_from_core_section_name */
+ 0, /* core_section_name_from_ptid */
0, /* core_regset_sections */
0, /* core_xfer_shared_libraries */
0, /* core_pid_to_str */
@@ -617,7 +619,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, has predicate */
+ /* Skip verify of core_section_name_from_ptid, has predicate */
/* 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 +757,15 @@ 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: gdbarch_core_section_name_from_ptid_p() = %d\n",
+ gdbarch_core_section_name_from_ptid_p (gdbarch));
+ 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 +982,12 @@ 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: gdbarch_ptid_from_core_section_name_p() = %d\n",
+ gdbarch_ptid_from_core_section_name_p (gdbarch));
+ 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,
@@ -2930,20 +2942,51 @@ set_gdbarch_regset_from_core_section (st
}
int
-gdbarch_core_reg_section_encodes_pid (struct gdbarch *gdbarch)
+gdbarch_ptid_from_core_section_name_p (struct gdbarch *gdbarch)
{
gdb_assert (gdbarch != NULL);
- /* Skip verify of core_reg_section_encodes_pid, invalid_p == 0 */
+ return gdbarch->ptid_from_core_section_name != NULL;
+}
+
+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_core_reg_section_encodes_pid called\n");
- return gdbarch->core_reg_section_encodes_pid;
+ 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_core_reg_section_encodes_pid (struct gdbarch *gdbarch,
- int core_reg_section_encodes_pid)
+set_gdbarch_ptid_from_core_section_name (struct gdbarch *gdbarch,
+ gdbarch_ptid_from_core_section_name_ftype ptid_from_core_section_name)
{
- gdbarch->core_reg_section_encodes_pid = core_reg_section_encodes_pid;
+ gdbarch->ptid_from_core_section_name = ptid_from_core_section_name;
+}
+
+int
+gdbarch_core_section_name_from_ptid_p (struct gdbarch *gdbarch)
+{
+ gdb_assert (gdbarch != NULL);
+ return gdbarch->core_section_name_from_ptid != NULL;
+}
+
+char *
+gdbarch_core_section_name_from_ptid (struct gdbarch *gdbarch, const bfd *abfd, const char *name, ptid_t ptid)
+{
+ gdb_assert (gdbarch != NULL);
+ gdb_assert (gdbarch->core_section_name_from_ptid != NULL);
+ if (gdbarch_debug >= 2)
+ 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_section_name_from_ptid (struct gdbarch *gdbarch,
+ gdbarch_core_section_name_from_ptid_ftype core_section_name_from_ptid)
+{
+ gdbarch->core_section_name_from_ptid = core_section_name_from_ptid;
}
struct core_regset_section *
@@ -3405,7 +3448,6 @@ set_gdbarch_has_global_breakpoints (stru
gdbarch->has_global_breakpoints = has_global_breakpoints;
}
-
/* Keep a registry of per-architecture data-pointers required by GDB
modules. */
Index: src/gdb/sol2-tdep.h
===================================================================
--- src.orig/gdb/sol2-tdep.h 2009-06-05 16:16:28.000000000 +0100
+++ src/gdb/sol2-tdep.h 2009-06-05 16:18:32.000000000 +0100
@@ -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: src/gdb/sol2-tdep.c
===================================================================
--- src.orig/gdb/sol2-tdep.c 2009-06-05 16:16:28.000000000 +0100
+++ src/gdb/sol2-tdep.c 2009-06-05 17:05:09.000000000 +0100
@@ -47,3 +47,34 @@ 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)
+{
+ uint32_t merged_pid;
+ const char *pos;
+
+ gdb_assert (name != NULL);
+ pos = strchr (name, '/');
+
+ /* Our caller only passes us sections whose name starts with ".reg/". */
+ gdb_assert (pos != NULL);
+
+ pos++;
+
+ merged_pid = strtoul (pos, NULL, 10);
+ return ptid_build (merged_pid & 0xffff, 0, merged_pid >> 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: src/gdb/amd64-sol2-tdep.c
===================================================================
--- src.orig/gdb/amd64-sol2-tdep.c 2009-06-05 16:16:28.000000000 +0100
+++ src/gdb/amd64-sol2-tdep.c 2009-06-05 16:18:32.000000000 +0100
@@ -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: src/gdb/sparc-sol2-tdep.c
===================================================================
--- src.orig/gdb/sparc-sol2-tdep.c 2009-06-05 16:16:27.000000000 +0100
+++ src/gdb/sparc-sol2-tdep.c 2009-06-05 16:18:32.000000000 +0100
@@ -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: src/gdb/sparc64-sol2-tdep.c
===================================================================
--- src.orig/gdb/sparc64-sol2-tdep.c 2009-06-05 16:16:27.000000000 +0100
+++ src/gdb/sparc64-sol2-tdep.c 2009-06-05 16:18:32.000000000 +0100
@@ -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: src/gdb/i386-sol2-tdep.c
===================================================================
--- src.orig/gdb/i386-sol2-tdep.c 2009-06-05 16:16:28.000000000 +0100
+++ src/gdb/i386-sol2-tdep.c 2009-06-05 16:18:32.000000000 +0100
@@ -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);
Index: src/gdb/gdbarch.sh
===================================================================
--- src.orig/gdb/gdbarch.sh 2009-05-25 13:45:58.000000000 +0100
+++ src/gdb/gdbarch.sh 2009-06-05 16:28:57.000000000 +0100
@@ -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
+# 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
# 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)
@@ -1663,7 +1667,6 @@ done
# All the trailing guff
cat <<EOF
-
/* Keep a registry of per-architecture data-pointers required by GDB
modules. */
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: ptid from core section
2009-06-05 16:26 ` Pedro Alves
@ 2009-06-05 17:54 ` Aleksandar Ristovski
2009-06-05 19:00 ` Pedro Alves
0 siblings, 1 reply; 13+ messages in thread
From: Aleksandar Ristovski @ 2009-06-05 17:54 UTC (permalink / raw)
To: gdb-patches
Pedro Alves wrote:
> On Friday 05 June 2009 15:53:00, Aleksandar Ristovski wrote:
>
>> Here is a new patch. I made sure it works even if
>> core_gdbarch is NULL.
>
> Sorry, we're going a bit in circles. The way you've now
> implemented it, there are three ways to get a ptid
> from a core reg section, but two of them are mostly
> the same --- the default gdbarch fallbacks, and the
> case of core_gdbarch being NULL handled in corelow.c itself.
On nto, we are not using lwp field at all. We use thread id.
In nto, I override core_open to add thread private data
once core_open has finished it's work. To identify threads,
I need to build ptid the way core does. I can do that, but
then I will have two functions for adding thread private
data (one for core ops, one for live target). Also, I would
have to either figure out which field is being used in
*_ptid_to_str or again provide two functions.
In summary: the motivation for this patch is to avoid having
to patch corelow.c. I am working on a larger nto patch that
I would like to have in before next official gdb release.
>
> On Friday 05 June 2009 14:44:37, Pedro Alves wrote:
>> change adds some unconditional accesses. The path of
>> least resistence to fix this, is to move the callback defaults
>> to corelow.c, make the new callbacks optional, and check
>> for 'core_gdbarch && gdbarch_foo_p (core_gdbarch)' predicates
>> before calling the optional callbacks.
>
> This meant:
>
> On Friday 05 June 2009 15:53:00, Aleksandar Ristovski wrote:
>> +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);
>> +}
>
> Moving these functions to corelow.c, and making the gdbarch callbacks
> optional. Wouldn't that look cleaner? Something like the patch below.
Looking at core handling I think the whole thing is not
clean. I see your point, but I see no particular advantage
of your approach - we moved the default code to corelow but
now introduced check for gdbarch_..._p.
But don't get me wrong - I am not against your approach - as
long as I don't have to patch corelow in order to get gdb
working for neutrino.
>
> But, at this point, I'm now confused, and I have to re-ask:
> What is it that gets confused on nto when core files store
> the thread id in the lwp field of ptids instead of on the tid
> field? Your original patch only took care to adjust to
> read tids from the tid field in default_core_section_from_ptid,
> but didn't do anything to make ptids that stored the tid
> in the tid field in default_ptid_from_core_section? While
> your latest patch didn't even do that in
> default_ptid_from_core_section_name? I can't see how you
> avoid adding gdbarch callbacks for nto.
I don't, I provide my own callbacks similar to sol2-tdep.c,
only they build ptid something like this:
ptid_build (ptid_get_pid (ptid), 0, atoi (core_section_name
+ 5));
I reworked the latest patch to have exactly the same
behaviour as without the patch, except for one bit where I
check if both lwp and tid are 0 to set inferior_ptid.
>
>> I also fixed my previous patch for
>> target signal by checking if there is a core_gdbarch.
>
> Could you go ahead, and check in just that bit
> split out from the rest please? Thanks.
>
Sure.
--
Aleksandar Ristovski
QNX Software Systems
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: ptid from core section
2009-06-05 17:54 ` Aleksandar Ristovski
@ 2009-06-05 19:00 ` Pedro Alves
2009-06-05 19:03 ` Aleksandar Ristovski
0 siblings, 1 reply; 13+ messages in thread
From: Pedro Alves @ 2009-06-05 19:00 UTC (permalink / raw)
To: gdb-patches; +Cc: Aleksandar Ristovski
On Friday 05 June 2009 18:54:08, Aleksandar Ristovski wrote:
> On nto, we are not using lwp field at all. We use thread id.
> In nto, I override core_open to add thread private data
> once core_open has finished it's work.
It's hard to guess without seeing the code, but, by overriding
you mean: you have a function that replaces core_open itself, then
that goes against the direction we want to go with corelow.c. We
want this file to work the same for both native and cross debugging,
and overriding target_ops methods like that doesn't work well in
that case. :-( That's why all new core support customising
methods are done through gdbarch.
Hmmm, I don't have the details on how you're storing or
extracting that info, and if it is a different mechanism from
when doing live debugging, but, there's a call to
target_find_new_threads at the bottom of core_open:
/* Now go through the target stack looking for threads since there
may be a thread_stratum target loaded on top of target core by
now. The layer above should claim threads found in the BFD
sections. */
target_find_new_threads ();
it may work for you to attach thread private data from
within that callback.
> In summary: the motivation for this patch is to avoid having
> to patch corelow.c.
I understand that. I was just asking/suggesting ( since the
beggining of the thread, actually :-) ) that the nto overrides
be included in the patch, so we'd understand if we're doing
the right decisions, that's all. I didn't know about that
core_open override or the intention to add private data to
threads.
On Friday 05 June 2009 18:54:08, Aleksandar Ristovski wrote:
> Looking at core handling I think the whole thing is not
> clean.
Cleaning up patches welcome. We never have enough of those :-)
The other option I see, is to revamp, cleanup and and normalize
how bfd exports core process or threads ids to GDB. But, what,
exactly, are you refering to as not clean? corelow.c would
be leaner and cleaner if we didn't have all those legacy targets
using the deprecated mechanisms around in the tree, but we do.
Alternatively, I suppose it wouldn't be such a bad idea to
officially declare that the lwp field of ptid is for kernel
threads, and that the tid field is for user/thread library
threads (thread_stratum targets) (which itself would mostly
be useful to M:N configurations, where details of
user thread registers are found somewhere in memory data
structures). Then, it would be clearer that the .reg sections
map to kernel processes/lwps/threads. This would mean that
it wouldn't be such a stretch to make nto-procfs.c use the
lwp field of ptids at all.
> I see your point, but I see no particular advantage
> of your approach - we moved the default code to corelow but
> now introduced check for gdbarch_..._p.
The advantage is that we only implement the default
case *once* (core_gdbarch == NULL; not-NULL, but the arch
doesn't implement the callbacks).
> But don't get me wrong - I am not against your approach - as
> long as I don't have to patch corelow in order to get gdb
> working for neutrino.
Ok, assuming it works, I'll check it in.
--
Pedro Alves
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: ptid from core section
2009-06-05 19:00 ` Pedro Alves
@ 2009-06-05 19:03 ` Aleksandar Ristovski
0 siblings, 0 replies; 13+ messages in thread
From: Aleksandar Ristovski @ 2009-06-05 19:03 UTC (permalink / raw)
To: gdb-patches
Pedro Alves wrote:
> On Friday 05 June 2009 18:54:08, Aleksandar Ristovski wrote:
>> On nto, we are not using lwp field at all. We use thread id.
>> In nto, I override core_open to add thread private data
>> once core_open has finished it's work.
>
> It's hard to guess without seeing the code, but, by overriding
> you mean: you have a function that replaces core_open itself, then
> that goes against the direction we want to go with corelow.c. We
> want this file to work the same for both native and cross debugging,
> and overriding target_ops methods like that doesn't work well in
> that case. :-( That's why all new core support customising
> methods are done through gdbarch.
>
> Hmmm, I don't have the details on how you're storing or
> extracting that info, and if it is a different mechanism from
> when doing live debugging, but, there's a call to
> target_find_new_threads at the bottom of core_open:
>
> /* Now go through the target stack looking for threads since there
> may be a thread_stratum target loaded on top of target core by
> now. The layer above should claim threads found in the BFD
> sections. */
> target_find_new_threads ();
>
> it may work for you to attach thread private data from
> within that callback.
>
>> In summary: the motivation for this patch is to avoid having
>> to patch corelow.c.
>
> I understand that. I was just asking/suggesting ( since the
> beggining of the thread, actually :-) ) that the nto overrides
> be included in the patch, so we'd understand if we're doing
> the right decisions, that's all. I didn't know about that
> core_open override or the intention to add private data to
> threads.
>
> On Friday 05 June 2009 18:54:08, Aleksandar Ristovski wrote:
>> Looking at core handling I think the whole thing is not
>> clean.
>
> Cleaning up patches welcome. We never have enough of those :-)
> The other option I see, is to revamp, cleanup and and normalize
> how bfd exports core process or threads ids to GDB. But, what,
> exactly, are you refering to as not clean? corelow.c would
> be leaner and cleaner if we didn't have all those legacy targets
> using the deprecated mechanisms around in the tree, but we do.
>
> Alternatively, I suppose it wouldn't be such a bad idea to
> officially declare that the lwp field of ptid is for kernel
> threads, and that the tid field is for user/thread library
> threads (thread_stratum targets) (which itself would mostly
> be useful to M:N configurations, where details of
> user thread registers are found somewhere in memory data
> structures). Then, it would be clearer that the .reg sections
> map to kernel processes/lwps/threads. This would mean that
> it wouldn't be such a stretch to make nto-procfs.c use the
> lwp field of ptids at all.
>
>> I see your point, but I see no particular advantage
>> of your approach - we moved the default code to corelow but
>> now introduced check for gdbarch_..._p.
>
> The advantage is that we only implement the default
> case *once* (core_gdbarch == NULL; not-NULL, but the arch
> doesn't implement the callbacks).
>
>> But don't get me wrong - I am not against your approach - as
>> long as I don't have to patch corelow in order to get gdb
>> working for neutrino.
>
> Ok, assuming it works, I'll check it in.
>
Wait :-)
I have opened another thread in
http://sourceware.org/ml/gdb/2009-06/msg00051.html
Maybe we don't need to customize it this way...
--
Aleksandar Ristovski
QNX Software Systems
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2009-06-05 19:03 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-01 15:56 ptid from core section Aleksandar Ristovski
2009-06-03 14:41 ` Pedro Alves
2009-06-03 16:59 ` Aleksandar Ristovski
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox