From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24611 invoked by alias); 3 Aug 2012 03:51:54 -0000 Received: (qmail 24591 invoked by uid 22791); 3 Aug 2012 03:51:51 -0000 X-SWARE-Spam-Status: No, hits=-8.5 required=5.0 tests=AWL,BAYES_00,KHOP_PGP_SIGNED,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,TW_CP,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp.gentoo.org (HELO smtp.gentoo.org) (140.211.166.183) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 03 Aug 2012 03:51:36 +0000 Received: from vapier.localnet (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with ESMTP id 1B0251B4030 for ; Fri, 3 Aug 2012 03:51:35 +0000 (UTC) From: Mike Frysinger To: gdb-patches@sourceware.org Subject: [patch v3] gdb: add completion handler for "handle" Date: Fri, 03 Aug 2012 03:51:00 -0000 User-Agent: KMail/1.13.7 (Linux/3.5.0; KDE/4.6.5; x86_64; ; ) References: <201208012353.56496.vapier@gentoo.org> In-Reply-To: <201208012353.56496.vapier@gentoo.org> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart1396019.PziE6H43Pd"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit Message-Id: <201208022351.18624.vapier@gentoo.org> X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-08/txt/msg00096.txt.bz2 --nextPart1396019.PziE6H43Pd Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-length: 10889 The command line completion has spoiled me. Thus the lack of completion wi= th the "handle" command annoys me. Patch! This does a few things: - adds a VEC_merge helper - adds a generic signal completer - adds a completion handler for the "handle" command - sets the completion handler for the "signal" command Signed-off-by: Mike Frysinger v3 - replace new array completer with existing enum completer - add a new VEC_merge helper - improve the handle completer to match existing behavior - drop handle/signal docstring changes 2012-08-01 Mike Frysinger * vec.h (VEC_merge): Define. (DEF_VEC_ALLOC_FUNC_I): Add a merge helper. (DEF_VEC_ALLOC_FUNC_P): Likewise. (DEF_VEC_ALLOC_FUNC_O): Likewise. * completer.c: Include gdb_signals.h. (signal_completer): Define. * completer.h (signal_completer): Add prototype. * infcmd.c (_initialize_infcmd): Assign the command completer for "signal" to handle_completer. * infrun.c: Include completer.h. (handle_completer): Define. (_initialize_infrun): Declare a new local variable c. Store the result of add_com("handle") to it. Assign the command completer for "handle" to handle_completer. 2012-08-01 Mike Frysinger * gdb.base/completion.exp: Add tests for handle completion. gdb/common/vec.h | 72 +++++++++++++++++++++++++++++= ++++ gdb/completer.c | 32 +++++++++++++++ gdb/completer.h | 3 ++ gdb/infcmd.c | 3 +- gdb/infrun.c | 35 +++++++++++++++- gdb/testsuite/gdb.base/completion.exp | 18 +++++++++ 6 files changed, 161 insertions(+), 2 deletions(-) diff --git a/gdb/common/vec.h b/gdb/common/vec.h index fa15370..d16b604 100644 --- a/gdb/common/vec.h +++ b/gdb/common/vec.h @@ -212,6 +212,13 @@ =20 #define VEC_copy(T,V) (VEC_OP(T,copy)(V)) =20 +/* Merge two vectors. + VEC(T,A) *VEC_T_merge(VEC(T) *, VEC(T) *); + + Copy the live elements of both vectors into a new vector. The new + and old vectors need not be allocated by the same mechanism. */ +#define VEC_merge(T,V1,V2) (VEC_OP(T,merge)(V1, V2)) + /* Determine if a vector has additional capacity. =20 int VEC_T_space (VEC(T) *v,int reserve) @@ -463,6 +470,28 @@ static inline VEC(T) *VEC_OP (T,copy) (VEC(T) *vec_) = \ return new_vec_; \ } \ \ +static inline VEC(T) *VEC_OP (T,merge) (VEC(T) *vec1_, VEC(T) *vec2_) \ +{ \ + if (vec1_ && vec2_) \ + { \ + size_t len_ =3D vec1_->num + vec2_->num; \ + VEC (T) *new_vec_ =3D NULL; \ + \ + /* We must request exact size allocation, hence the negation. */ \ + new_vec_ =3D (VEC (T) *) \ + vec_o_reserve (NULL, -len_, offsetof (VEC(T),vec), sizeof (T)); \ + \ + new_vec_->num =3D len_; \ + memcpy (new_vec_->vec, vec1_->vec, sizeof (T) * vec1_->num); \ + memcpy (new_vec_->vec + vec1_->num, vec2_->vec, \ + sizeof (T) * vec2_->num); \ + \ + return new_vec_; \ + } \ + else \ + return VEC_copy (T, vec1_ ? vec1_ : vec2_); \ +} \ + \ static inline void VEC_OP (T,free) \ (VEC(T) **vec_) \ { \ @@ -743,6 +772,27 @@ static inline VEC(T) *VEC_OP (T,copy) (VEC(T) *vec_) = \ return new_vec_; \ } \ \ +static inline VEC(T) *VEC_OP (T,merge) (VEC(T) *vec1_, VEC(T) *vec2_) \ +{ \ + if (vec1_ && vec2_) \ + { \ + size_t len_ =3D vec1_->num + vec2_->num; \ + VEC (T) *new_vec_ =3D NULL; \ + \ + /* We must request exact size allocation, hence the negation. */ \ + new_vec_ =3D (VEC (T) *)(vec_p_reserve (NULL, -len_)); \ + \ + new_vec_->num =3D len_; \ + memcpy (new_vec_->vec, vec1_->vec, sizeof (T) * vec1_->num); \ + memcpy (new_vec_->vec + vec1_->num, vec2_->vec, \ + sizeof (T) * vec2_->num); \ + \ + return new_vec_; \ + } \ + else \ + return VEC_copy (T, vec1_ ? vec1_ : vec2_); \ +} \ + \ static inline int VEC_OP (T,reserve) \ (VEC(T) **vec_, int alloc_ VEC_ASSERT_DECL) \ { \ @@ -977,6 +1027,28 @@ static inline VEC(T) *VEC_OP (T,copy) (VEC(T) *vec_) = \ return new_vec_; \ } \ \ +static inline VEC(T) *VEC_OP (T,merge) (VEC(T) *vec1_, VEC(T) *vec2_) \ +{ \ + if (vec1_ && vec2_) \ + { \ + size_t len_ =3D vec1_->num + vec2_->num; \ + VEC (T) *new_vec_ =3D NULL; \ + \ + /* We must request exact size allocation, hence the negation. */ \ + new_vec_ =3D (VEC (T) *) \ + vec_o_reserve (NULL, -len_, offsetof (VEC(T),vec), sizeof (T)); \ + \ + new_vec_->num =3D len_; \ + memcpy (new_vec_->vec, vec1_->vec, sizeof (T) * vec1_->num); \ + memcpy (new_vec_->vec + vec1_->num, vec2_->vec, \ + sizeof (T) * vec2_->num); \ + \ + return new_vec_; \ + } \ + else \ + return VEC_copy (T, vec1_ ? vec1_ : vec2_); \ +} \ + \ static inline void VEC_OP (T,free) \ (VEC(T) **vec_) \ { \ diff --git a/gdb/completer.c b/gdb/completer.c index b9f0699..2002578 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -24,6 +24,7 @@ #include "language.h" #include "gdb_assert.h" #include "exceptions.h" +#include "gdb_signals.h" =20 #include "cli/cli-decode.h" =20 @@ -797,6 +798,37 @@ command_completer (struct cmd_list_element *ignore, strlen (text), handle_help); } =20 +/* Complete on signals. */ + +VEC (char_ptr) * +signal_completer (struct cmd_list_element *ignore, + char *text, char *word) +{ + int i; + VEC (char_ptr) *return_val =3D NULL; + size_t len =3D strlen (word); + enum gdb_signal signum; + const char *signame; + + for (signum =3D GDB_SIGNAL_FIRST; signum !=3D GDB_SIGNAL_LAST; ++signum) + { + /* Can't handle this, so skip it. */ + if (signum =3D=3D GDB_SIGNAL_0) + continue; + + signame =3D gdb_signal_to_name (signum); + + /* Ignore the unknown signal case. */ + if (!signame || strcmp (signame, "?") =3D=3D 0) + continue; + + if (strncasecmp (signame, word, len) =3D=3D 0) + VEC_safe_push (char_ptr, return_val, xstrdup (signame)); + } + + return return_val; +} + /* Get the list of chars that are considered as word breaks for the current command. */ =20 diff --git a/gdb/completer.h b/gdb/completer.h index 680bc2d..fddfa42 100644 --- a/gdb/completer.h +++ b/gdb/completer.h @@ -41,6 +41,9 @@ extern VEC (char_ptr) *location_completer (struct cmd_lis= t_element *, extern VEC (char_ptr) *command_completer (struct cmd_list_element *, char *, char *); =20 +extern VEC (char_ptr) *signal_completer (struct cmd_list_element *, + char *, char *); + extern char *get_gdb_completer_quote_characters (void); =20 extern char *gdb_completion_word_break_characters (void); diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 635e577..d56503c 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -3016,9 +3016,10 @@ Disconnect from a target.\n\ The target will wait for another debugger to connect. Not available for\n\ all targets.")); =20 - add_com ("signal", class_run, signal_command, _("\ + c =3D add_com ("signal", class_run, signal_command, _("\ Continue program giving it signal specified by the argument.\n\ An argument of \"0\" means continue program without giving it a signal.")); + set_cmd_completer (c, signal_completer); =20 add_com ("stepi", class_run, stepi_command, _("\ Step one instruction exactly.\n\ diff --git a/gdb/infrun.c b/gdb/infrun.c index cf6c062..4f59a92 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -57,6 +57,7 @@ #include "skip.h" #include "probe.h" #include "objfiles.h" +#include "completer.h" =20 /* Prototypes for local functions */ =20 @@ -6416,6 +6417,36 @@ Are you sure you want to change it? "), do_cleanups (old_chain); } =20 +/* Complete the "handle" command. */ + +static VEC (char_ptr) * +handle_completer (struct cmd_list_element *ignore, + char *text, char *word) +{ + VEC (char_ptr) *vec_signals, *vec_keywords, *return_val; + static const char * const keywords[] =3D + { + "all", + "stop", + "ignore", + "print", + "pass", + "nostop", + "noignore", + "noprint", + "nopass", + NULL, + }; + + vec_signals =3D signal_completer (ignore, text, word); + vec_keywords =3D complete_on_enum (keywords, word, word); + + return_val =3D VEC_merge (char_ptr, vec_signals, vec_keywords); + VEC_free (char_ptr, vec_signals); + VEC_free (char_ptr, vec_keywords); + return return_val; +} + static void xdb_handle_command (char *args, int from_tty) { @@ -7059,13 +7090,14 @@ _initialize_infrun (void) { int i; int numsigs; + struct cmd_list_element *c; =20 add_info ("signals", signals_info, _("\ What debugger does when program gets various signals.\n\ Specify a signal as argument to print info on that signal only.")); add_info_alias ("handle", "signals", 0); =20 - add_com ("handle", class_run, handle_command, _("\ + c =3D add_com ("handle", class_run, handle_command, _("\ Specify how to handle a signal.\n\ Args are signals and actions to apply to those signals.\n\ Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ @@ -7080,6 +7112,7 @@ Print means print a message if this signal happens.\n\ Pass means let program see this signal; otherwise program doesn't know.\n\ Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ Pass and Stop may be combined.")); + set_cmd_completer (c, handle_completer); if (xdb_commands) { add_com ("lz", class_info, signals_info, _("\ diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base= /completion.exp index 9b9459c..71b9227 100644 --- a/gdb/testsuite/gdb.base/completion.exp +++ b/gdb/testsuite/gdb.base/completion.exp @@ -363,6 +363,24 @@ gdb_test_multiple "" "$test" { } } =20 +set test "complete 'handle signal'" +send_gdb "handle sigq\t" +gdb_test_multiple "" "$test" { + -re "^handle SIGQUIT $" { + send_gdb "\n" + pass "$test" + } +} + +set test "complete 'handle keyword'" +send_gdb "handle nos\t" +gdb_test_multiple "" "$test" { + -re "^handle nostop $" { + send_gdb "\n" + pass "$test" + } +} + =20 # These tests used to try completing the shorter "p b-a". # Unfortunately, on some systems, there are .o files in system --nextPart1396019.PziE6H43Pd Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. Content-length: 836 -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (GNU/Linux) iQIcBAABAgAGBQJQG0q2AAoJEEFjO5/oN/WBTR8P/jcLpruA3LGbMd4biSSVYqCI omXOepsO08mHBZj8W5OPWBdDuxU49RWFyFO2bQHE1E4bUbebOuW6KJe41VRkPBAx mdgGhDyWaIJRw5tOQFTVFNwkT+gRF7BqplwPwgNHjCM2zidVlWiYaHRDlODZzfrt GWfimJMpDLbryuqF226ccDjHd2l/WJOXzSngS+BRnJ9tPWVh89kuq0tv7R43rC96 OLgNVzUozwzVueozudYvrMteiSaKf7auEN+8QQYKg0Qbfl1v3mAWDpN4wz2bJ3KS A3w7HCgH813/89NlgQEqqVBW/wnJ40MQosvexlII4+RPlaeYYmnhfbdZDsPHCSri 2HYmF/Wo4OPmmLsFXzxUF811ndNBCM9/rBD8wiAlXzMnGdTkS/OqoSE5m1+WiJdl uJ8PcdEXD1r81Z+dvouj5QvRx8Torn8omcQrdBKLKyuRJ6cSYB+qLbKTZ2LtydkZ r2BDsaXyq24GSg159ta4QUG23C8ESQOje7v88RTxAwER0rqI0nuJPgVZcNmiJgIr KwpzAC6eBk9/7fGLloDnXpqp7HzZm7DwoyaxpWMarRFADYC0iyDKxUGGuIqF85Ue XO2NnyKyymfclNVazVYH2g/6L/Rle/IOBQnvQ3Kg0/dyfO+D2+4kb//lqd1rJlCD UJo8yQ8UZpt39RSUky1Q =vPuN -----END PGP SIGNATURE----- --nextPart1396019.PziE6H43Pd--