[1/2,gdbserver] Rename supports_conditional_breakpoints to supports_hardware_single_step

Message ID 1441096915-23615-2-git-send-email-yao.qi@linaro.org
State New, archived
Headers

Commit Message

Yao Qi Sept. 1, 2015, 8:41 a.m. UTC
  In my patch https://sourceware.org/ml/gdb-patches/2015-04/msg01110.html
a new target_ops hook supports_conditional_breakpoints was added to
disable conditional breakpoints if target doesn't have hardware single
step.  This patch is to generalize this hook from
supports_conditional_breakpoints to supports_hardware_single_step,
so that the following patch can use it.

gdb/gdbserver:

2015-09-01  Yao Qi  <yao.qi@linaro.org>

	* linux-low.c (linux_supports_conditional_breakpoints): Rename
	it to ...
	(linux_supports_hardware_single_step): ... New function.
	(linux_target_ops): Update.
	* lynx-low.c (lynx_target_ops): Set field
	supports_hardware_single_step to target_can_do_hardware_single_step.
	* nto-low.c (nto_target_ops): Likewise.
	* spu-low.c (spu_target_ops): Likewise.
	* win32-low.c (win32_target_ops): Likewise.
	* target.c (target_can_do_hardware_single_step): New function.
	* target.h (struct target_ops) <supports_conditional_breakpoints>:
	Remove.  <supports_hardware_single_step>: New field.
	(target_supports_conditional_breakpoints): Remove.
	(target_supports_hardware_single_step): New macro.
	(target_can_do_hardware_single_step): Declare.
	* server.c (handle_query): Use target_supports_hardware_single_step
	instead of target_supports_conditional_breakpoints.
---
 gdb/gdbserver/linux-low.c | 11 +++--------
 gdb/gdbserver/lynx-low.c  |  5 +----
 gdb/gdbserver/nto-low.c   |  5 +----
 gdb/gdbserver/server.c    | 12 +++++++++---
 gdb/gdbserver/spu-low.c   |  2 +-
 gdb/gdbserver/target.c    |  8 ++++++++
 gdb/gdbserver/target.h    | 13 +++++++------
 gdb/gdbserver/win32-low.c |  5 +----
 8 files changed, 31 insertions(+), 30 deletions(-)
  

Comments

Antoine Tremblay Sept. 2, 2015, 7:22 p.m. UTC | #1
On 09/01/2015 04:41 AM, Yao Qi wrote:
> In my patch https://sourceware.org/ml/gdb-patches/2015-04/msg01110.html
> a new target_ops hook supports_conditional_breakpoints was added to
> disable conditional breakpoints if target doesn't have hardware single
> step.  This patch is to generalize this hook from
> supports_conditional_breakpoints to supports_hardware_single_step,
> so that the following patch can use it.
>

Could we generalize this even more to supports_single_step like your 
next patch ?

Since I'm working on software single stepping for ARM, if this patch 
goes in I'll need to implement a supports_software_single_step and 
enable ConditionalBreakpoints for this case too...

Is there a need to know that it's really hardware or just knowing that 
it can single step would be ok ?

Regards,
Antoine
  
Antoine Tremblay Sept. 3, 2015, 3:13 p.m. UTC | #2
On 09/02/2015 03:22 PM, Antoine Tremblay wrote:
>
> On 09/01/2015 04:41 AM, Yao Qi wrote:
>> In my patch https://sourceware.org/ml/gdb-patches/2015-04/msg01110.html
>> a new target_ops hook supports_conditional_breakpoints was added to
>> disable conditional breakpoints if target doesn't have hardware single
>> step.  This patch is to generalize this hook from
>> supports_conditional_breakpoints to supports_hardware_single_step,
>> so that the following patch can use it.
>>
>
> Could we generalize this even more to supports_single_step like your
> next patch ?
>
> Since I'm working on software single stepping for ARM, if this patch
> goes in I'll need to implement a supports_software_single_step and
> enable ConditionalBreakpoints for this case too...
>
> Is there a need to know that it's really hardware or just knowing that
> it can single step would be ok ?
>

Note also that this way would force supports_conditional_breakpoints to 
check for more than can_hardware_single_step and require a target 
function set manually to 1 on targets that we know have a proper 
software or hardware single step like :

static int
linux_supports_conditional_breakpoints (void)
{
   return the_low_target.supports_conditional_breakpoints ();
}

I had initially added that in my set but we could change it for 
the_low_target_.can_single_step () ?

This way targets that have proper software single step can be handled.
Otherwise every software single step implementation is deemed too simple 
to be used...

Would that seem ok ?
  
Antoine Tremblay Sept. 4, 2015, 2:40 p.m. UTC | #3
On 09/03/2015 11:13 AM, Antoine Tremblay wrote:
>
>
> On 09/02/2015 03:22 PM, Antoine Tremblay wrote:
>>
>> On 09/01/2015 04:41 AM, Yao Qi wrote:
>>> In my patch https://sourceware.org/ml/gdb-patches/2015-04/msg01110.html
>>> a new target_ops hook supports_conditional_breakpoints was added to
>>> disable conditional breakpoints if target doesn't have hardware single
>>> step.  This patch is to generalize this hook from
>>> supports_conditional_breakpoints to supports_hardware_single_step,
>>> so that the following patch can use it.
>>>
>>
>> Could we generalize this even more to supports_single_step like your
>> next patch ?
>>
>> Since I'm working on software single stepping for ARM, if this patch
>> goes in I'll need to implement a supports_software_single_step and
>> enable ConditionalBreakpoints for this case too...
>>
>> Is there a need to know that it's really hardware or just knowing that
>> it can single step would be ok ?
>>
>
> Note also that this way would force supports_conditional_breakpoints to
> check for more than can_hardware_single_step and require a target
> function set manually to 1 on targets that we know have a proper
> software or hardware single step like :
>
> static int
> linux_supports_conditional_breakpoints (void)
> {
>    return the_low_target.supports_conditional_breakpoints ();
> }
>
> I had initially added that in my set but we could change it for
> the_low_target_.can_single_step () ?
>
> This way targets that have proper software single step can be handled.
> Otherwise every software single step implementation is deemed too simple
> to be used...
>
> Would that seem ok ?
>
>

After more analysis, I think ConditionalBreakpoints should be enabled 
for software/hardware single step.

But for the vCont s:S I don't think we can assume that gdbserver's 
software single step is better then GDB's, it should be the opposite. 
So it should only be enabled when hardware single step is present so we 
can't do away with supports_hardware_single_step.

So to support all features I suggest we have in GDBServer :

supports_hardware_single_step
supports_software_single_step

Enable ConditionalBreakpoints for supports_hardware_single_step || 
supports_software_single_step

And enable vCont s:s only for supports_hardware_single_step

I can add the supports_software_single_step in my patchset..

Does that sounds right ? So your current patch would be fine..
  
Antoine Tremblay Sept. 4, 2015, 3:04 p.m. UTC | #4
On 09/04/2015 10:40 AM, Antoine Tremblay wrote:
>
>
> On 09/03/2015 11:13 AM, Antoine Tremblay wrote:
>>
>>
>> On 09/02/2015 03:22 PM, Antoine Tremblay wrote:
>>>
>>> On 09/01/2015 04:41 AM, Yao Qi wrote:
>>>> In my patch https://sourceware.org/ml/gdb-patches/2015-04/msg01110.html
>>>> a new target_ops hook supports_conditional_breakpoints was added to
>>>> disable conditional breakpoints if target doesn't have hardware single
>>>> step.  This patch is to generalize this hook from
>>>> supports_conditional_breakpoints to supports_hardware_single_step,
>>>> so that the following patch can use it.
>>>>
>>>
>>> Could we generalize this even more to supports_single_step like your
>>> next patch ?
>>>
>>> Since I'm working on software single stepping for ARM, if this patch
>>> goes in I'll need to implement a supports_software_single_step and
>>> enable ConditionalBreakpoints for this case too...
>>>
>>> Is there a need to know that it's really hardware or just knowing that
>>> it can single step would be ok ?
>>>
>>
>> Note also that this way would force supports_conditional_breakpoints to
>> check for more than can_hardware_single_step and require a target
>> function set manually to 1 on targets that we know have a proper
>> software or hardware single step like :
>>
>> static int
>> linux_supports_conditional_breakpoints (void)
>> {
>>    return the_low_target.supports_conditional_breakpoints ();
>> }
>>
>> I had initially added that in my set but we could change it for
>> the_low_target_.can_single_step () ?
>>
>> This way targets that have proper software single step can be handled.
>> Otherwise every software single step implementation is deemed too simple
>> to be used...
>>
>> Would that seem ok ?
>>
>>
>
> After more analysis, I think ConditionalBreakpoints should be enabled
> for software/hardware single step.
>
> But for the vCont s:S I don't think we can assume that gdbserver's
> software single step is better then GDB's, it should be the opposite. So
> it should only be enabled when hardware single step is present so we
> can't do away with supports_hardware_single_step.
>
> So to support all features I suggest we have in GDBServer :
>
> supports_hardware_single_step
> supports_software_single_step
>
> Enable ConditionalBreakpoints for supports_hardware_single_step ||
> supports_software_single_step
>
> And enable vCont s:s only for supports_hardware_single_step
>
> I can add the supports_software_single_step in my patchset..
>
> Does that sounds right ? So your current patch would be fine..
>

Another option would also be to remove the reinsert_addr implementations 
and have can_hardware_single_step still check if that implementation 
exists. Thus removing the need for a manual 
supports_software_single_step ...

If the implementations were disabled for Conditional Breakpoints, I 
don't see why they should be kept ?

I would prefer that option but maybe there's a scenario I"m not seeing?
  
Yao Qi Sept. 8, 2015, 2:31 p.m. UTC | #5
Antoine Tremblay <antoine.tremblay@ericsson.com> writes:

Hi Antoine,

> Could we generalize this even more to supports_single_step like your
> next patch ?
>

I am not sure.

> Since I'm working on software single stepping for ARM, if this patch
> goes in I'll need to implement a supports_software_single_step and
> enable ConditionalBreakpoints for this case too...

Nowadays, GDBserver only support conditional breakpoint for HW single
step target.  Whether GDBserver support conditional breakpoint for SW
single step target is a separate issue, and we can decide this once we
have SW single step in GDBserver.

I believe GDBserver can compute the next instruction of $PC for SW
single step, but GDBserver execution control (target independent part)
will be more complicated if SW single step is involved in.
  
Antoine Tremblay Sept. 8, 2015, 7:01 p.m. UTC | #6
On 09/08/2015 10:31 AM, Yao Qi wrote:
> Antoine Tremblay <antoine.tremblay@ericsson.com> writes:
>
> Hi Antoine,
>
>> Could we generalize this even more to supports_single_step like your
>> next patch ?
>>
>
> I am not sure.
>
>> Since I'm working on software single stepping for ARM, if this patch
>> goes in I'll need to implement a supports_software_single_step and
>> enable ConditionalBreakpoints for this case too...
>
> Nowadays, GDBserver only support conditional breakpoint for HW single
> step target.  Whether GDBserver support conditional breakpoint for SW
> single step target is a separate issue, and we can decide this once we
> have SW single step in GDBserver.
>

Alright then, I'll base my patchset based on your patch and most likely 
add a supports_software_single_step, if it's in by the time I post most 
likely later this week...

> I believe GDBserver can compute the next instruction of $PC for SW
> single step, but GDBserver execution control (target independent part)
> will be more complicated if SW single step is involved in.
>

Execution control for software single step is already present in 
GDBServer and working fine as far as I know...?
  
Antoine Tremblay Sept. 9, 2015, 3:37 p.m. UTC | #7
> -  /* Although lynx has hardware single step, still disable this
> -     feature for lynx, because it is implemented in linux-low.c instead
> -     of in generic code.  */
> -  NULL,  /* supports_conditional_breakpoints */
> +  target_can_do_hardware_single_step,
>     NULL,  /* stopped_by_watchpoint */
>     NULL,  /* stopped_data_address */
>     NULL,  /* read_offsets */
...
> +
> +/* Target can do hardware single step.  */
> +
> +int
> +target_can_do_hardware_single_step (void)
> +{
> +  return 1;
> +}

Why would we enable conditional breakpoints on lynx,win32 etc.. since I 
think it's still valid that it's implemented in linux-low ?

Should we not default to return 0 in target_can_do_hardware_single_step ?
  

Patch

diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index f4c6029..9ae0522 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -5524,16 +5524,11 @@  linux_supports_stopped_by_hw_breakpoint (void)
   return USE_SIGTRAP_SIGINFO;
 }
 
-/* Implement the supports_conditional_breakpoints target_ops
-   method.  */
+/* Implement the supports_hardware_single_step target_ops method.  */
 
 static int
-linux_supports_conditional_breakpoints (void)
+linux_supports_hardware_single_step (void)
 {
-  /* GDBserver needs to step over the breakpoint if the condition is
-     false.  GDBserver software single step is too simple, so disable
-     conditional breakpoints if the target doesn't have hardware single
-     step.  */
   return can_hardware_single_step ();
 }
 
@@ -6886,7 +6881,7 @@  static struct target_ops linux_target_ops = {
   linux_supports_stopped_by_sw_breakpoint,
   linux_stopped_by_hw_breakpoint,
   linux_supports_stopped_by_hw_breakpoint,
-  linux_supports_conditional_breakpoints,
+  linux_supports_hardware_single_step,
   linux_stopped_by_watchpoint,
   linux_stopped_data_address,
 #if defined(__UCLIBC__) && defined(HAS_NOMMU)	      \
diff --git a/gdb/gdbserver/lynx-low.c b/gdb/gdbserver/lynx-low.c
index 1a187c8..c5eb8fd 100644
--- a/gdb/gdbserver/lynx-low.c
+++ b/gdb/gdbserver/lynx-low.c
@@ -747,10 +747,7 @@  static struct target_ops lynx_target_ops = {
   NULL,  /* supports_stopped_by_sw_breakpoint */
   NULL,  /* stopped_by_hw_breakpoint */
   NULL,  /* supports_stopped_by_hw_breakpoint */
-  /* Although lynx has hardware single step, still disable this
-     feature for lynx, because it is implemented in linux-low.c instead
-     of in generic code.  */
-  NULL,  /* supports_conditional_breakpoints */
+  target_can_do_hardware_single_step,
   NULL,  /* stopped_by_watchpoint */
   NULL,  /* stopped_data_address */
   NULL,  /* read_offsets */
diff --git a/gdb/gdbserver/nto-low.c b/gdb/gdbserver/nto-low.c
index 19f492f..fa216a9 100644
--- a/gdb/gdbserver/nto-low.c
+++ b/gdb/gdbserver/nto-low.c
@@ -950,10 +950,7 @@  static struct target_ops nto_target_ops = {
   NULL, /* supports_stopped_by_sw_breakpoint */
   NULL, /* stopped_by_hw_breakpoint */
   NULL, /* supports_stopped_by_hw_breakpoint */
-  /* Although nto has hardware single step, still disable this
-     feature for not, because it is implemented in linux-low.c instead
-     of in generic code.  */
-  NULL, /* supports_conditional_breakpoints */
+  target_can_do_hardware_single_step,
   nto_stopped_by_watchpoint,
   nto_stopped_data_address,
   NULL, /* nto_read_offsets */
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index c52cf16..5c0d83d 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -2192,9 +2192,15 @@  handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
 	  strcat (own_buf, ";tracenz+");
 	}
 
-      /* Support target-side breakpoint conditions and commands.  */
-      if (target_supports_conditional_breakpoints ())
-	strcat (own_buf, ";ConditionalBreakpoints+");
+      if (target_supports_hardware_single_step ())
+	{
+	  /* Support target-side breakpoint conditions and commands.
+	     GDBserver needs to step over the breakpoint if the condition
+	     is false.  GDBserver software single step is too simple, so
+	     disable conditional breakpoints if the target doesn't have
+	     hardware single step.  */
+	  strcat (own_buf, ";ConditionalBreakpoints+");
+	}
       strcat (own_buf, ";BreakpointCommands+");
 
       if (target_supports_agent ())
diff --git a/gdb/gdbserver/spu-low.c b/gdb/gdbserver/spu-low.c
index 878ed82..074417a 100644
--- a/gdb/gdbserver/spu-low.c
+++ b/gdb/gdbserver/spu-low.c
@@ -666,7 +666,7 @@  static struct target_ops spu_target_ops = {
   NULL, /* supports_stopped_by_sw_breakpoint */
   NULL, /* stopped_by_hw_breakpoint */
   NULL, /* supports_stopped_by_hw_breakpoint */
-  NULL, /* supports_conditional_breakpoints */
+  NULL, /* supports_hardware_single_step */
   NULL,
   NULL,
   NULL,
diff --git a/gdb/gdbserver/target.c b/gdb/gdbserver/target.c
index 7540f2f..17ff7a6 100644
--- a/gdb/gdbserver/target.c
+++ b/gdb/gdbserver/target.c
@@ -216,3 +216,11 @@  kill_inferior (int pid)
 
   return (*the_target->kill) (pid);
 }
+
+/* Target can do hardware single step.  */
+
+int
+target_can_do_hardware_single_step (void)
+{
+  return 1;
+}
diff --git a/gdb/gdbserver/target.h b/gdb/gdbserver/target.h
index 3e3b80f..7df8df3 100644
--- a/gdb/gdbserver/target.h
+++ b/gdb/gdbserver/target.h
@@ -225,9 +225,8 @@  struct target_ops
      HW breakpoint triggering.  */
   int (*supports_stopped_by_hw_breakpoint) (void);
 
-  /* Returns true if the target can evaluate conditions of
-     breakpoints.  */
-  int (*supports_conditional_breakpoints) (void);
+  /* Returns true if the target can do hardware single step.  */
+  int (*supports_hardware_single_step) (void);
 
   /* Returns 1 if target was stopped due to a watchpoint hit, 0 otherwise.  */
 
@@ -609,9 +608,9 @@  int kill_inferior (int);
   (the_target->supports_stopped_by_hw_breakpoint ? \
    (*the_target->supports_stopped_by_hw_breakpoint) () : 0)
 
-#define target_supports_conditional_breakpoints() \
-  (the_target->supports_conditional_breakpoints ? \
-   (*the_target->supports_conditional_breakpoints) () : 0)
+#define target_supports_hardware_single_step() \
+  (the_target->supports_hardware_single_step ? \
+   (*the_target->supports_hardware_single_step) () : 0)
 
 #define target_stopped_by_hw_breakpoint() \
   (the_target->stopped_by_hw_breakpoint ? \
@@ -649,4 +648,6 @@  int set_desired_thread (int id);
 
 const char *target_pid_to_str (ptid_t);
 
+int target_can_do_hardware_single_step (void);
+
 #endif /* TARGET_H */
diff --git a/gdb/gdbserver/win32-low.c b/gdb/gdbserver/win32-low.c
index 86386ce..212c3c2 100644
--- a/gdb/gdbserver/win32-low.c
+++ b/gdb/gdbserver/win32-low.c
@@ -1810,10 +1810,7 @@  static struct target_ops win32_target_ops = {
   NULL, /* supports_stopped_by_sw_breakpoint */
   NULL, /* stopped_by_hw_breakpoint */
   NULL, /* supports_stopped_by_hw_breakpoint */
-  /* Although win32-i386 has hardware single step, still disable this
-     feature for win32, because it is implemented in linux-low.c instead
-     of in generic code.  */
-  NULL, /* supports_conditional_breakpoints */
+  target_can_do_hardware_single_step,
   win32_stopped_by_watchpoint,
   win32_stopped_data_address,
   NULL, /* read_offsets */