[1/8] Disallow using --attach and --wrapper together.

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

Commit Message

Yao Qi July 20, 2015, 11:35 a.m. UTC
  gdb/gdbserver:

2015-07-15  Yao Qi  <yao.qi@linaro.org>

	* server.c (captured_main): Call gdbserver_usage and exit if
	attach is true and wrapper_argv isn't NULL.
---
 gdb/gdbserver/server.c | 9 +++++++++
 1 file changed, 9 insertions(+)
  

Comments

Pedro Alves July 23, 2015, 10:29 p.m. UTC | #1
On 07/20/2015 12:35 PM, Yao Qi wrote:
> gdb/gdbserver:
> 
> 2015-07-15  Yao Qi  <yao.qi@linaro.org>
> 
> 	* server.c (captured_main): Call gdbserver_usage and exit if
> 	attach is true and wrapper_argv isn't NULL.

Really not sure about this.  It's reasonable to do e.g.,
alias gs="gdbserver --wrapper=/whatever/wrapper --"
(or the equivalent wrapper shell script that execs gdbserver)
and then always start that instead of gdbserver:

sometimes:

 $ gs :9999 PROGRAM

othertimes:

 $ gs --attach :9999 $pid

but after the patch, the latter errors out.

Plus, one can combine --attach and --multi, which means
that the wrapper would still apply to processes spawned
after connecting.

Thanks,
Pedro Alves
  
Yao Qi July 24, 2015, 8:44 a.m. UTC | #2
Pedro Alves <palves@redhat.com> writes:

> Really not sure about this.  It's reasonable to do e.g.,
> alias gs="gdbserver --wrapper=/whatever/wrapper --"
> (or the equivalent wrapper shell script that execs gdbserver)
> and then always start that instead of gdbserver:
>
> sometimes:
>
>  $ gs :9999 PROGRAM
>
> othertimes:
>
>  $ gs --attach :9999 $pid
>
> but after the patch, the latter errors out.

IMO, it makes sense to error out in the latter case, because --wrapper
is useless if GDBserver attaches to a process.

>
> Plus, one can combine --attach and --multi, which means
> that the wrapper would still apply to processes spawned
> after connecting.

I agree on this case.  I withdraw this patch.
  
Pedro Alves July 24, 2015, 8:51 a.m. UTC | #3
On 07/24/2015 09:44 AM, Yao Qi wrote:
> Pedro Alves <palves@redhat.com> writes:
> 
>> Really not sure about this.  It's reasonable to do e.g.,
>> alias gs="gdbserver --wrapper=/whatever/wrapper --"
>> (or the equivalent wrapper shell script that execs gdbserver)
>> and then always start that instead of gdbserver:
>>
>> sometimes:
>>
>>  $ gs :9999 PROGRAM
>>
>> othertimes:
>>
>>  $ gs --attach :9999 $pid
>>
>> but after the patch, the latter errors out.
> 
> IMO, it makes sense to error out in the latter case, because --wrapper
> is useless if GDBserver attaches to a process.

The point was that before you could just forget about --wrapper,
set it once for your target/environment, having it hidden in the
script|alias-that-wraps-gdbserver.  I see it the same as putting
this in ~/.gdbinit:

 set exec-wrapper /whatever/wrapper

and then doing "$ gdb -p PID", and having GDB complain
about "set exec-wrapper" and "-p" being incompatible.

> 
>>
>> Plus, one can combine --attach and --multi, which means
>> that the wrapper would still apply to processes spawned
>> after connecting.
> 
> I agree on this case.  I withdraw this patch.
> 


Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index 7e388dd..ce3ffb5 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -3481,6 +3481,15 @@  captured_main (int argc, char *argv[])
       exit (1);
     }
 
+  if (attach && wrapper_argv != NULL)
+    {
+      /* Option --wrapper is used to start a new program, while option
+	 --attach is used to attach to an existing process.  Emit error
+	 and quit when they are used together.  */
+      gdbserver_usage (stderr);
+      exit (1);
+    }
+
   initialize_async_io ();
   initialize_low ();
   initialize_event_loop ();