From patchwork Tue Oct 22 08:51:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 35218 Received: (qmail 45634 invoked by alias); 22 Oct 2019 08:52:01 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 45383 invoked by uid 89); 22 Oct 2019 08:52:01 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=HOME, Files, recognition X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 22 Oct 2019 08:51:59 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id 8B20D204BC; Tue, 22 Oct 2019 04:51:57 -0400 (EDT) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [IPv6:2620:52:3:1:5054:ff:fe06:16ca]) by mx1.osci.io (Postfix) with ESMTP id AFC1120176; Tue, 22 Oct 2019 04:51:54 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id 712372192E; Tue, 22 Oct 2019 04:51:54 -0400 (EDT) X-Gerrit-PatchSet: 2 Date: Tue, 22 Oct 2019 04:51:54 -0400 From: "Tom de Vries (Code Review)" To: gdb-patches@sourceware.org Cc: Christian Biesinger Auto-Submitted: auto-generated X-Gerrit-MessageType: newpatchset Subject: [review v2] [RFC][gdb] Make script-extension strict reject unknown extensions X-Gerrit-Change-Id: Ia357a4b0b1042808401578266da80919035ad576 X-Gerrit-Change-Number: 40 X-Gerrit-ChangeURL: X-Gerrit-Commit: 15ebbb078ea84b2c0443ebb993abcb8e09cd770a In-Reply-To: References: Reply-To: tdevries@suse.de, cbiesinger@google.com, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3 Message-Id: <20191022085154.712372192E@gnutoolchain-gerrit.osci.io> Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/40 ...................................................................... [RFC][gdb] Make script-extension strict reject unknown extensions At https://sourceware.org/gdb/onlinedocs/gdb.html#index-set-script_002dextension we have: ... Files with an unrecognized filename extension are always treated as a GDB Command Files. ... So, we have this behaviour: ... $ gdb -q -batch a.out \ -ex "set trace-commands on" \ -ex "set script-extension strict" \ -ex "show script-extension" \ -ex "source bla.bla" +set script-extension strict +show script-extension Script filename extension recognition is "strict". +source bla.bla +start Temporary breakpoint 1 at 0x40050b: file /home/vries/hello.c, line 6. Temporary breakpoint 1, main () at /home/vries/hello.c:6 6 printf ("hello\n"); +bt ... Change this behaviour to allow only recognized extensions when using strict: ... $ gdb -q -batch a.out \ -ex "set trace-commands on" \ -ex "set script-extension strict" \ -ex "show script-extension" \ -ex "source bla.bla" +set script-extension strict +show script-extension Script filename extension recognition is "strict". +source bla.bla Scripting in the "" language is not supported in this copy of GDB. ... This does not change the default behaviour of gdb, which uses the 'script-extension soft' setting. Setting script-extension to force doesn't inhibit reading: - system gdbinit (/etc/gdbinit) - home gdbinit (~/.gdbinit) - local gdbinit (./.gdbinit) Tested on x86_64-linux. No docs update yet. gdb/ChangeLog: 2019-10-22 Tom de Vries * cli/cli-cmds.c (source_script_from_stream) (source_script_with_search): Add and handle force parameter. (source_script_force): New function. * cli/cli-cmds.h (source_script_force): Declare. * extension.c (extension_language_none): New var. (get_ext_lang_of_file): Handle extension_language_gdb.suffix. * extension.h (extension_language_none): Declare. * main.c (captured_main_1): Use source_script_force for gdbinit files. gdb/testsuite/ChangeLog: 2019-10-22 Tom de Vries * gdb.base/source-execution.exp: Test rejection of gdb.bla when script-extension is set to strict. * gdb.base/gdb.bla: New empty command file. Change-Id: Ia357a4b0b1042808401578266da80919035ad576 --- M gdb/cli/cli-cmds.c M gdb/cli/cli-cmds.h M gdb/extension.c M gdb/extension.h M gdb/main.c A gdb/testsuite/gdb.base/gdb.bla M gdb/testsuite/gdb.base/source-execution.exp 7 files changed, 43 insertions(+), 6 deletions(-) diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index a39ea22..24c0bcb 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -630,7 +630,7 @@ static void source_script_from_stream (FILE *stream, const char *file, - const char *file_to_open) + const char *file_to_open, bool force) { if (script_ext_mode != script_ext_off) { @@ -656,6 +656,10 @@ else throw_ext_lang_unsupported (extlang); } + else if (!force && script_ext_mode == script_ext_strict) + { + throw_ext_lang_unsupported (&extension_language_none); + } } script_from_file (stream, file); @@ -667,7 +671,8 @@ search for it in the source search path. */ static void -source_script_with_search (const char *file, int from_tty, int search_path) +source_script_with_search (const char *file, int from_tty, int search_path, + bool force = false) { if (file == NULL || *file == 0) @@ -695,7 +700,8 @@ this if we (may have) used search_path, as printing the full path in errors for the non-search case can be more noise than signal. */ source_script_from_stream (opened->stream.get (), file, - search_path ? opened->full_path.get () : file); + search_path ? opened->full_path.get () : file, + force); } /* Wrapper around source_script_with_search to export it to main.c @@ -707,6 +713,12 @@ source_script_with_search (file, from_tty, 0); } +void +source_script_force (const char *file, int from_tty) +{ + source_script_with_search (file, from_tty, 0, true); +} + static void source_command (const char *args, int from_tty) { diff --git a/gdb/cli/cli-cmds.h b/gdb/cli/cli-cmds.h index 94ae814..16f6147 100644 --- a/gdb/cli/cli-cmds.h +++ b/gdb/cli/cli-cmds.h @@ -120,6 +120,7 @@ extern void quit_command (const char *, int); extern void source_script (const char *, int); +extern void source_script_force (const char *, int); /* Exported to objfiles.c. */ diff --git a/gdb/extension.c b/gdb/extension.c index 8637bc5..8a7bea5 100644 --- a/gdb/extension.c +++ b/gdb/extension.c @@ -66,6 +66,18 @@ auto_load_gdb_scripts_enabled }; +const struct extension_language_defn extension_language_none = +{ + EXT_LANG_NONE, + "", + "", + NULL, + NULL, + invalid_control, + NULL, + NULL +}; + const struct extension_language_defn extension_language_gdb = { EXT_LANG_GDB, @@ -154,6 +166,9 @@ int i; const struct extension_language_defn *extlang; + if (has_extension (file, extension_language_gdb.suffix)) + return &extension_language_gdb; + ALL_EXTENSION_LANGUAGES (i, extlang) { if (has_extension (file, extlang->suffix)) diff --git a/gdb/extension.h b/gdb/extension.h index fc8e3e2..a59d15a 100644 --- a/gdb/extension.h +++ b/gdb/extension.h @@ -230,6 +230,8 @@ /* The interface for gdb's own extension(/scripting) language. */ extern const struct extension_language_defn extension_language_gdb; +extern const struct extension_language_defn extension_language_none; + extern const struct extension_language_defn *get_ext_lang_defn (enum extension_language lang); diff --git a/gdb/main.c b/gdb/main.c index a77d6ec..c56005a 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -993,7 +993,8 @@ processed; it sets global parameters, which are independent of what file you are debugging or what directory you are in. */ if (!system_gdbinit.empty () && !inhibit_gdbinit) - ret = catch_command_errors (source_script, system_gdbinit.c_str (), 0); + ret = catch_command_errors (source_script_force, system_gdbinit.c_str (), + 0); /* Read and execute $HOME/.gdbinit file, if it exists. This is done *before* all the command line arguments are processed; it sets @@ -1001,7 +1002,7 @@ debugging or what directory you are in. */ if (!home_gdbinit.empty () && !inhibit_gdbinit && !inhibit_home_gdbinit) - ret = catch_command_errors (source_script, home_gdbinit.c_str (), 0); + ret = catch_command_errors (source_script_force, home_gdbinit.c_str (), 0); /* Process '-ix' and '-iex' options early. */ for (i = 0; i < cmdarg_vec.size (); i++) @@ -1117,7 +1118,8 @@ { auto_load_local_gdbinit_loaded = 1; - ret = catch_command_errors (source_script, local_gdbinit.c_str (), 0); + ret = catch_command_errors (source_script_force, + local_gdbinit.c_str (), 0); } } diff --git a/gdb/testsuite/gdb.base/gdb.bla b/gdb/testsuite/gdb.base/gdb.bla new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/gdb/testsuite/gdb.base/gdb.bla diff --git a/gdb/testsuite/gdb.base/source-execution.exp b/gdb/testsuite/gdb.base/source-execution.exp index 25e7e37..4fa76b3 100644 --- a/gdb/testsuite/gdb.base/source-execution.exp +++ b/gdb/testsuite/gdb.base/source-execution.exp @@ -31,3 +31,8 @@ gdb_test "source ${srcdir}/${subdir}/source-execution.gdb" \ "func2.*func3.*" \ "source source-execution.gdb" + +gdb_test_no_output "set script-extension strict" + +gdb_test "source gdb.bla" \ + "Scripting in the \"\" language is not supported in this copy of GDB."