Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH v2][CRISv32] Add support for threaded debugging
@ 2013-09-03 14:18 Ricard Wanderlof
  2013-09-03 14:57 ` Pedro Alves
  0 siblings, 1 reply; 4+ messages in thread
From: Ricard Wanderlof @ 2013-09-03 14:18 UTC (permalink / raw)
  To: gdb-patches

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


This patch adds support for threaded debugging on the CRISv32
architecture. In its original form it's been floating around for several
years now in our local repository so it's way overdue pushing upstream.

Tested by debugging a small program on a CRISv32 target which uses
multiple threads, and verify that the __thread variables can be properly
accessed for every thread.

Patch included inline for review and as attachement for use.


Suggested-by: Edgar Iglesias <edgar.iglesias@gmail.com>
Signed-off-by: Ricard Wanderlof <ricardw@axis.com>


2013-09-03  Ricard Wanderlof  <ricardw@axis.com>

  	* cris-tdep.c:
  	(cris_gdbarch_init): Add call to
  	get_gdbarch_fetch_tls_load_module_address.

gdbserver

  	* linux-crisv32-low.c: PTRACE_GET_THREAD_AREA: New macro.
  	(ps_get_thread_area): New function.


diff --git a/gdb/cris-tdep.c b/gdb/cris-tdep.c
index 1b0e3cd..ef2746d 100644
--- a/gdb/cris-tdep.c
+++ b/gdb/cris-tdep.c
@@ -4137,6 +4137,11 @@ cris_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
         set_gdbarch_single_step_through_delay
   	(gdbarch, crisv32_single_step_through_delay);

+      /* FIXME: Ricard W/2013-09-03: Linux-specific stuff like this
+         should really go in (a new) cris-linux-tdep.c. */
+      set_gdbarch_fetch_tls_load_module_address (gdbarch,
+                                                 svr4_fetch_objfile_link_map);
+
         break;

       default:
diff --git a/gdb/gdbserver/linux-crisv32-low.c b/gdb/gdbserver/linux-crisv32-low.c
index 2849d02..84cb7ff 100644
--- a/gdb/gdbserver/linux-crisv32-low.c
+++ b/gdb/gdbserver/linux-crisv32-low.c
@@ -27,6 +27,10 @@ extern const struct target_desc *tdesc_crisv32;
   /* CRISv32 */
   #define cris_num_regs 49

+#ifndef PTRACE_GET_THREAD_AREA
+#define PTRACE_GET_THREAD_AREA 25
+#endif
+
   /* Note: Ignoring USP (having the stack pointer in two locations causes trouble
      without any significant gain).  */

@@ -339,6 +343,20 @@ cris_stopped_data_address (void)
     return eda;
   }

+ps_err_e
+ps_get_thread_area (const struct ps_prochandle *ph,
+                    lwpid_t lwpid, int idx, void **base)
+{
+  if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
+    return PS_ERR;
+
+  /* IDX is the bias from the thread pointer to the beginning of the
+     thread descriptor.  It has to be subtracted due to implementation
+     quirks in libthread_db.  */
+  *base = (void *) ((char *) *base - idx);
+  return PS_OK;
+}
+
   static void
   cris_fill_gregset (struct regcache *regcache, void *buf)
   {


/Ricard
-- 
Ricard Wolf Wanderlöf                           ricardw(at)axis.com
Axis Communications AB, Lund, Sweden            www.axis.com
Phone +46 46 272 2016                           Fax +46 46 13 61 30

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch file.patch --]
[-- Type: text/x-diff; name="cris-head-thread.patch", Size: 1768 bytes --]

diff --git a/gdb/cris-tdep.c b/gdb/cris-tdep.c
index 1b0e3cd..ef2746d 100644
--- a/gdb/cris-tdep.c
+++ b/gdb/cris-tdep.c
@@ -4137,6 +4137,11 @@ cris_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
       set_gdbarch_single_step_through_delay 
 	(gdbarch, crisv32_single_step_through_delay);
 
+      /* FIXME: Ricard W/2013-09-03: Linux-specific stuff like this
+         should really go in (a new) cris-linux-tdep.c. */
+      set_gdbarch_fetch_tls_load_module_address (gdbarch,
+                                                 svr4_fetch_objfile_link_map);
+
       break;
 
     default:
diff --git a/gdb/gdbserver/linux-crisv32-low.c b/gdb/gdbserver/linux-crisv32-low.c
index 2849d02..84cb7ff 100644
--- a/gdb/gdbserver/linux-crisv32-low.c
+++ b/gdb/gdbserver/linux-crisv32-low.c
@@ -27,6 +27,10 @@ extern const struct target_desc *tdesc_crisv32;
 /* CRISv32 */
 #define cris_num_regs 49
 
+#ifndef PTRACE_GET_THREAD_AREA
+#define PTRACE_GET_THREAD_AREA 25
+#endif
+
 /* Note: Ignoring USP (having the stack pointer in two locations causes trouble
    without any significant gain).  */
 
@@ -339,6 +343,20 @@ cris_stopped_data_address (void)
   return eda;
 }
 
+ps_err_e
+ps_get_thread_area (const struct ps_prochandle *ph,
+                    lwpid_t lwpid, int idx, void **base)
+{
+  if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
+    return PS_ERR;
+
+  /* IDX is the bias from the thread pointer to the beginning of the
+     thread descriptor.  It has to be subtracted due to implementation
+     quirks in libthread_db.  */
+  *base = (void *) ((char *) *base - idx);
+  return PS_OK;
+}
+
 static void
 cris_fill_gregset (struct regcache *regcache, void *buf)
 {

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2][CRISv32] Add support for threaded debugging
  2013-09-03 14:18 [PATCH v2][CRISv32] Add support for threaded debugging Ricard Wanderlof
@ 2013-09-03 14:57 ` Pedro Alves
  2013-09-03 15:11   ` Ricard Wanderlof
  2013-09-06  8:40   ` Ricard Wanderlof
  0 siblings, 2 replies; 4+ messages in thread
From: Pedro Alves @ 2013-09-03 14:57 UTC (permalink / raw)
  To: Ricard Wanderlof; +Cc: gdb-patches

On 09/03/2013 03:18 PM, Ricard Wanderlof wrote:

> 
> 2013-09-03  Ricard Wanderlof  <ricardw@axis.com>
> 
>   	* cris-tdep.c:
>   	(cris_gdbarch_init): Add call to
>   	get_gdbarch_fetch_tls_load_module_address.

Spurious ':' / wrong formatting:

   	* cris-tdep.c (cris_gdbarch_init): Add call to
   	get_gdbarch_fetch_tls_load_module_address.

> 
> gdbserver
> 
>   	* linux-crisv32-low.c: PTRACE_GET_THREAD_AREA: New macro.
>   	(ps_get_thread_area): New function.

Wrong formatting:

   	* linux-crisv32-low.c (PTRACE_GET_THREAD_AREA): New macro.
   	(ps_get_thread_area): New function.

OK with those changes.

Thanks,
-- 
Pedro Alves


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2][CRISv32] Add support for threaded debugging
  2013-09-03 14:57 ` Pedro Alves
@ 2013-09-03 15:11   ` Ricard Wanderlof
  2013-09-06  8:40   ` Ricard Wanderlof
  1 sibling, 0 replies; 4+ messages in thread
From: Ricard Wanderlof @ 2013-09-03 15:11 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches


On Tue, 3 Sep 2013, Pedro Alves wrote:

> Spurious ':' / wrong formatting:
>
>   	* cris-tdep.c (cris_gdbarch_init): Add call to
>   	get_gdbarch_fetch_tls_load_module_address.
>
>>
>> gdbserver
>>
>>   	* linux-crisv32-low.c: PTRACE_GET_THREAD_AREA: New macro.
>>   	(ps_get_thread_area): New function.
>
> Wrong formatting:
>
>   	* linux-crisv32-low.c (PTRACE_GET_THREAD_AREA): New macro.
>   	(ps_get_thread_area): New function.
>
> OK with those changes.

I see I should start using mklog to at least get the initial formatting 
right here.

/Ricard
-- 
Ricard Wolf Wanderlöf                           ricardw(at)axis.com
Axis Communications AB, Lund, Sweden            www.axis.com
Phone +46 46 272 2016                           Fax +46 46 13 61 30


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2][CRISv32] Add support for threaded debugging
  2013-09-03 14:57 ` Pedro Alves
  2013-09-03 15:11   ` Ricard Wanderlof
@ 2013-09-06  8:40   ` Ricard Wanderlof
  1 sibling, 0 replies; 4+ messages in thread
From: Ricard Wanderlof @ 2013-09-06  8:40 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches


On Tue, 3 Sep 2013, Pedro Alves wrote:

> On 09/03/2013 03:18 PM, Ricard Wanderlof wrote:
>
>>
>> 2013-09-03  Ricard Wanderlof  <ricardw@axis.com>
>>
>>   	* cris-tdep.c:
>>   	(cris_gdbarch_init): Add call to
>>   	get_gdbarch_fetch_tls_load_module_address.
>
> Spurious ':' / wrong formatting:
>
>   	* cris-tdep.c (cris_gdbarch_init): Add call to
>   	get_gdbarch_fetch_tls_load_module_address.
>
>>
>> gdbserver
>>
>>   	* linux-crisv32-low.c: PTRACE_GET_THREAD_AREA: New macro.
>>   	(ps_get_thread_area): New function.
>
> Wrong formatting:
>
>   	* linux-crisv32-low.c (PTRACE_GET_THREAD_AREA): New macro.
>   	(ps_get_thread_area): New function.
>
> OK with those changes.

Committed now.

/Ricard


Add support for threaded debugging for CRISv32.

2013-09-06  Ricard Wanderlof  <ricardw@axis.com>

 	* cris-tdep.c (cris_gdbarch_init): Add call to
 	get_gdbarch_fetch_tls_load_module_address.

gdbserver

 	* linux-crisv32-low.c (PTRACE_GET_THREAD_AREA): New macro.
 	(ps_get_thread_area): New function.


diff --git a/gdb/cris-tdep.c b/gdb/cris-tdep.c
index 1b0e3cd..ef2746d 100644
--- a/gdb/cris-tdep.c
+++ b/gdb/cris-tdep.c
@@ -4137,6 +4137,11 @@ cris_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        set_gdbarch_single_step_through_delay
  	(gdbarch, crisv32_single_step_through_delay);

+      /* FIXME: Ricard W/2013-09-03: Linux-specific stuff like this
+         should really go in (a new) cris-linux-tdep.c. */
+      set_gdbarch_fetch_tls_load_module_address (gdbarch,
+                                                 svr4_fetch_objfile_link_map);
+
        break;

      default:
diff --git a/gdb/gdbserver/linux-crisv32-low.c b/gdb/gdbserver/linux-crisv32-low.c
index 2849d02..84cb7ff 100644
--- a/gdb/gdbserver/linux-crisv32-low.c
+++ b/gdb/gdbserver/linux-crisv32-low.c
@@ -27,6 +27,10 @@ extern const struct target_desc *tdesc_crisv32;
  /* CRISv32 */
  #define cris_num_regs 49

+#ifndef PTRACE_GET_THREAD_AREA
+#define PTRACE_GET_THREAD_AREA 25
+#endif
+
  /* Note: Ignoring USP (having the stack pointer in two locations causes trouble
     without any significant gain).  */

@@ -339,6 +343,20 @@ cris_stopped_data_address (void)
    return eda;
  }

+ps_err_e
+ps_get_thread_area (const struct ps_prochandle *ph,
+                    lwpid_t lwpid, int idx, void **base)
+{
+  if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
+    return PS_ERR;
+
+  /* IDX is the bias from the thread pointer to the beginning of the
+     thread descriptor.  It has to be subtracted due to implementation
+     quirks in libthread_db.  */
+  *base = (void *) ((char *) *base - idx);
+  return PS_OK;
+}
+
  static void
  cris_fill_gregset (struct regcache *regcache, void *buf)
  {


-- 
Ricard Wolf Wanderlöf                           ricardw(at)axis.com
Axis Communications AB, Lund, Sweden            www.axis.com
Phone +46 46 272 2016                           Fax +46 46 13 61 30


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-09-06  8:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-03 14:18 [PATCH v2][CRISv32] Add support for threaded debugging Ricard Wanderlof
2013-09-03 14:57 ` Pedro Alves
2013-09-03 15:11   ` Ricard Wanderlof
2013-09-06  8:40   ` Ricard Wanderlof

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox