remote: Return NULL extra_info/name if they are empty

Message ID 1513016513-26428-1-git-send-email-simon.marchi@ericsson.com
State New, archived
Headers

Commit Message

Simon Marchi Dec. 11, 2017, 6:21 p.m. UTC
  Commit

  remote: C++ify thread_item and threads_listing_context
  21fe1c752e254167d953fa8c846280f63a3a5290

broke the test gdb.threads/names.exp.  The problem is that since we now
use an std::string to hold the extra_info, an empty string is returned
by target_extra_thread_info to print_thread_info_1 when the remote stub
didn't send any extra info, instead of NULL before.  Because of that,
print_thread_info_1 prints the extra info between parentheses, which
results in some spurious empty parentheses.

  Expected: * 1    Thread 22752.22752 "main" all_threads_ready () at ...
  Actual  : * 1    Thread 22752.22752 "main" () all_threads_ready () a ...

Since the bug was introduced by a behavior change in the remote target,
I chose to fix it on the remote target side by making it return NULL
when the extra string is empty.  This will avoid possibly changing the
behavior of the common code and affecting other targets.

The name field has the same problem.  If a remote stub returns no thread
names, remote_thread_name will return an empty string instead of NULL,
so print_thread_info_1 will show empty quotes ("") instead of nothing.

gdb/ChangeLog:

	PR gdb/22556
	* remote.c (remote_thread_name): Return NULL if name is empty.
	(remote_threads_extra_info): Return NULL if extra info is empty.
---
 gdb/remote.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
  

Comments

Pedro Alves Dec. 12, 2017, 12:24 a.m. UTC | #1
On 12/11/2017 06:21 PM, Simon Marchi wrote:
> Commit
> 
>   remote: C++ify thread_item and threads_listing_context
>   21fe1c752e254167d953fa8c846280f63a3a5290
> 
> broke the test gdb.threads/names.exp.  The problem is that since we now
> use an std::string to hold the extra_info, an empty string is returned
> by target_extra_thread_info to print_thread_info_1 when the remote stub
> didn't send any extra info, instead of NULL before.  Because of that,
> print_thread_info_1 prints the extra info between parentheses, which
> results in some spurious empty parentheses.
> 
>   Expected: * 1    Thread 22752.22752 "main" all_threads_ready () at ...
>   Actual  : * 1    Thread 22752.22752 "main" () all_threads_ready () a ...
> 
> Since the bug was introduced by a behavior change in the remote target,
> I chose to fix it on the remote target side by making it return NULL
> when the extra string is empty.  This will avoid possibly changing the
> behavior of the common code and affecting other targets.
> 
> The name field has the same problem.  If a remote stub returns no thread
> names, remote_thread_name will return an empty string instead of NULL,
> so print_thread_info_1 will show empty quotes ("") instead of nothing.
> 
> gdb/ChangeLog:
> 
> 	PR gdb/22556
> 	* remote.c (remote_thread_name): Return NULL if name is empty.
> 	(remote_threads_extra_info): Return NULL if extra info is empty.

Looks good, thanks.

Pedro Alves
  
Simon Marchi Dec. 12, 2017, 2:06 a.m. UTC | #2
On 2017-12-11 19:24, Pedro Alves wrote:
> On 12/11/2017 06:21 PM, Simon Marchi wrote:
>> Commit
>> 
>>   remote: C++ify thread_item and threads_listing_context
>>   21fe1c752e254167d953fa8c846280f63a3a5290
>> 
>> broke the test gdb.threads/names.exp.  The problem is that since we 
>> now
>> use an std::string to hold the extra_info, an empty string is returned
>> by target_extra_thread_info to print_thread_info_1 when the remote 
>> stub
>> didn't send any extra info, instead of NULL before.  Because of that,
>> print_thread_info_1 prints the extra info between parentheses, which
>> results in some spurious empty parentheses.
>> 
>>   Expected: * 1    Thread 22752.22752 "main" all_threads_ready () at 
>> ...
>>   Actual  : * 1    Thread 22752.22752 "main" () all_threads_ready () a 
>> ...
>> 
>> Since the bug was introduced by a behavior change in the remote 
>> target,
>> I chose to fix it on the remote target side by making it return NULL
>> when the extra string is empty.  This will avoid possibly changing the
>> behavior of the common code and affecting other targets.
>> 
>> The name field has the same problem.  If a remote stub returns no 
>> thread
>> names, remote_thread_name will return an empty string instead of NULL,
>> so print_thread_info_1 will show empty quotes ("") instead of nothing.
>> 
>> gdb/ChangeLog:
>> 
>> 	PR gdb/22556
>> 	* remote.c (remote_thread_name): Return NULL if name is empty.
>> 	(remote_threads_extra_info): Return NULL if extra info is empty.
> 
> Looks good, thanks.
> 
> Pedro Alves

Thanks, pushed.

Simon
  

Patch

diff --git a/gdb/remote.c b/gdb/remote.c
index fe27713..852fdef 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -2268,7 +2268,10 @@  static const char *
 remote_thread_name (struct target_ops *ops, struct thread_info *info)
 {
   if (info->priv != NULL)
-    return get_remote_thread_info (info)->name.c_str ();
+    {
+      const std::string &name = get_remote_thread_info (info)->name;
+      return !name.empty () ? name.c_str () : NULL;
+    }
 
   return NULL;
 }
@@ -3319,7 +3322,10 @@  remote_threads_extra_info (struct target_ops *self, struct thread_info *tp)
       struct thread_info *info = find_thread_ptid (tp->ptid);
 
       if (info != NULL && info->priv != NULL)
-	return get_remote_thread_info (info)->extra.c_str ();
+	{
+	  const std::string &extra = get_remote_thread_info (info)->extra;
+	  return !extra.empty () ? extra.c_str () : NULL;
+	}
       else
 	return NULL;
     }