public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Avoid harmful fall throughs in core_target::xfer_partial.
@ 2022-03-16 19:36 John Baldwin
  2022-03-17 16:06 ` Pedro Alves
  0 siblings, 1 reply; 4+ messages in thread
From: John Baldwin @ 2022-03-16 19:36 UTC (permalink / raw)
  To: gdb-patches

The cases for TARGET_OBJECT_LIBRARIES and TARGET_OBJECT_LIBRARIES_AIX
can try to fetch different data objects (such as
TARGET_OBJECT_SIGNAL_INFO) if gdbarch methods for the requested data
aren't present.  Replace case fallthroughs with an explicit goto to
the default case.
---
 gdb/corelow.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gdb/corelow.c b/gdb/corelow.c
index 1579e6bc2b8..f7f2bd3f318 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -943,7 +943,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
 		return TARGET_XFER_OK;
 	    }
 	}
-      /* FALL THROUGH */
+      goto fallthrough;
 
     case TARGET_OBJECT_LIBRARIES_AIX:
       if (m_core_gdbarch != nullptr
@@ -964,7 +964,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
 		return TARGET_XFER_OK;
 	    }
 	}
-      /* FALL THROUGH */
+      goto fallthrough;
 
     case TARGET_OBJECT_SIGNAL_INFO:
       if (readbuf)
@@ -988,6 +988,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
       return TARGET_XFER_E_IO;
 
     default:
+    fallthrough:
       return this->beneath ()->xfer_partial (object, annex, readbuf,
 					     writebuf, offset, len,
 					     xfered_len);
-- 
2.34.1


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

* Re: [PATCH] Avoid harmful fall throughs in core_target::xfer_partial.
  2022-03-16 19:36 [PATCH] Avoid harmful fall throughs in core_target::xfer_partial John Baldwin
@ 2022-03-17 16:06 ` Pedro Alves
  2022-03-17 16:23   ` John Baldwin
  0 siblings, 1 reply; 4+ messages in thread
From: Pedro Alves @ 2022-03-17 16:06 UTC (permalink / raw)
  To: John Baldwin, gdb-patches

On 2022-03-16 19:36, John Baldwin wrote:
> The cases for TARGET_OBJECT_LIBRARIES and TARGET_OBJECT_LIBRARIES_AIX
> can try to fetch different data objects (such as
> TARGET_OBJECT_SIGNAL_INFO) if gdbarch methods for the requested data
> aren't present.  Replace case fallthroughs with an explicit goto to
> the default case.

This is OK.  I mean, I think it would be reasonable to instead return
TARGET_XFER_E_IO -- it's what the other cases do (notice even TARGET_OBJECT_SIGNAL_INFO
doesn't fallback to the beneath target if there's no gdbarch method installed), and the targets
beneath (file and dummy) won't be returning any library anyhow.  OTOH, maybe some day we will
teach GDB to read the list of libraries the program is linked with and load those before
the program starts, and it's conceivable that we would do that at the file_stratum layer.

Pedro Alves

> ---
>  gdb/corelow.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/gdb/corelow.c b/gdb/corelow.c
> index 1579e6bc2b8..f7f2bd3f318 100644
> --- a/gdb/corelow.c
> +++ b/gdb/corelow.c
> @@ -943,7 +943,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
>  		return TARGET_XFER_OK;
>  	    }
>  	}
> -      /* FALL THROUGH */
> +      goto fallthrough;
>  
>      case TARGET_OBJECT_LIBRARIES_AIX:
>        if (m_core_gdbarch != nullptr
> @@ -964,7 +964,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
>  		return TARGET_XFER_OK;
>  	    }
>  	}
> -      /* FALL THROUGH */
> +      goto fallthrough;
>  
>      case TARGET_OBJECT_SIGNAL_INFO:
>        if (readbuf)
> @@ -988,6 +988,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
>        return TARGET_XFER_E_IO;
>  
>      default:
> +    fallthrough:
>        return this->beneath ()->xfer_partial (object, annex, readbuf,
>  					     writebuf, offset, len,
>  					     xfered_len);


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

* Re: [PATCH] Avoid harmful fall throughs in core_target::xfer_partial.
  2022-03-17 16:06 ` Pedro Alves
@ 2022-03-17 16:23   ` John Baldwin
  2022-03-17 16:26     ` Pedro Alves
  0 siblings, 1 reply; 4+ messages in thread
From: John Baldwin @ 2022-03-17 16:23 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches

On 3/17/22 9:06 AM, Pedro Alves wrote:
> On 2022-03-16 19:36, John Baldwin wrote:
>> The cases for TARGET_OBJECT_LIBRARIES and TARGET_OBJECT_LIBRARIES_AIX
>> can try to fetch different data objects (such as
>> TARGET_OBJECT_SIGNAL_INFO) if gdbarch methods for the requested data
>> aren't present.  Replace case fallthroughs with an explicit goto to
>> the default case.
> 
> This is OK.  I mean, I think it would be reasonable to instead return
> TARGET_XFER_E_IO -- it's what the other cases do (notice even TARGET_OBJECT_SIGNAL_INFO
> doesn't fallback to the beneath target if there's no gdbarch method installed), and the targets
> beneath (file and dummy) won't be returning any library anyhow.  OTOH, maybe some day we will
> teach GDB to read the list of libraries the program is linked with and load those before
> the program starts, and it's conceivable that we would do that at the file_stratum layer.

I'm happy to do whichever.  I was trying to preserve the intent from when
TARGET_OBJECT_LIBRARIES was first added.  If there are no beneath targets that
handle these objects, then I think it probably is cleaner to just fail with
TARGET_XFER_E_IO for now and let explicit fall through logic be added in the
future when it is needed.

> Pedro Alves
> 
>> ---
>>   gdb/corelow.c | 5 +++--
>>   1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/gdb/corelow.c b/gdb/corelow.c
>> index 1579e6bc2b8..f7f2bd3f318 100644
>> --- a/gdb/corelow.c
>> +++ b/gdb/corelow.c
>> @@ -943,7 +943,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
>>   		return TARGET_XFER_OK;
>>   	    }
>>   	}
>> -      /* FALL THROUGH */
>> +      goto fallthrough;
>>   
>>       case TARGET_OBJECT_LIBRARIES_AIX:
>>         if (m_core_gdbarch != nullptr
>> @@ -964,7 +964,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
>>   		return TARGET_XFER_OK;
>>   	    }
>>   	}
>> -      /* FALL THROUGH */
>> +      goto fallthrough;
>>   
>>       case TARGET_OBJECT_SIGNAL_INFO:
>>         if (readbuf)
>> @@ -988,6 +988,7 @@ core_target::xfer_partial (enum target_object object, const char *annex,
>>         return TARGET_XFER_E_IO;
>>   
>>       default:
>> +    fallthrough:
>>         return this->beneath ()->xfer_partial (object, annex, readbuf,
>>   					     writebuf, offset, len,
>>   					     xfered_len);
> 


-- 
John Baldwin

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

* Re: [PATCH] Avoid harmful fall throughs in core_target::xfer_partial.
  2022-03-17 16:23   ` John Baldwin
@ 2022-03-17 16:26     ` Pedro Alves
  0 siblings, 0 replies; 4+ messages in thread
From: Pedro Alves @ 2022-03-17 16:26 UTC (permalink / raw)
  To: John Baldwin, gdb-patches

On 2022-03-17 16:23, John Baldwin wrote:
> On 3/17/22 9:06 AM, Pedro Alves wrote:
>> On 2022-03-16 19:36, John Baldwin wrote:
>>> The cases for TARGET_OBJECT_LIBRARIES and TARGET_OBJECT_LIBRARIES_AIX
>>> can try to fetch different data objects (such as
>>> TARGET_OBJECT_SIGNAL_INFO) if gdbarch methods for the requested data
>>> aren't present.  Replace case fallthroughs with an explicit goto to
>>> the default case.
>>
>> This is OK.  I mean, I think it would be reasonable to instead return
>> TARGET_XFER_E_IO -- it's what the other cases do (notice even TARGET_OBJECT_SIGNAL_INFO
>> doesn't fallback to the beneath target if there's no gdbarch method installed), and the targets
>> beneath (file and dummy) won't be returning any library anyhow.  OTOH, maybe some day we will
>> teach GDB to read the list of libraries the program is linked with and load those before
>> the program starts, and it's conceivable that we would do that at the file_stratum layer.
> 
> I'm happy to do whichever.  I was trying to preserve the intent from when
> TARGET_OBJECT_LIBRARIES was first added.  If there are no beneath targets that
> handle these objects, then I think it probably is cleaner to just fail with
> TARGET_XFER_E_IO for now and let explicit fall through logic be added in the
> future when it is needed.

Fine with me.  Consider it pre-approved.

Thanks.

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

end of thread, other threads:[~2022-03-17 16:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-16 19:36 [PATCH] Avoid harmful fall throughs in core_target::xfer_partial John Baldwin
2022-03-17 16:06 ` Pedro Alves
2022-03-17 16:23   ` John Baldwin
2022-03-17 16:26     ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).