From patchwork Tue Sep 8 21:34:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 8603 Received: (qmail 25513 invoked by alias); 8 Sep 2015 21:34:33 -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 25499 invoked by uid 89); 8 Sep 2015 21:34:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mail-pd0-f201.google.com Received: from mail-pd0-f201.google.com (HELO mail-pd0-f201.google.com) (209.85.192.201) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 08 Sep 2015 21:34:31 +0000 Received: by pdrk8 with SMTP id k8so8018551pdr.1 for ; Tue, 08 Sep 2015 14:34:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:message-id:date:subject:from:to :content-type; bh=jyP2PktOZelkw3Ror9KJGqP8hBt8MDyu27WVCr50ytw=; b=HqiDUtNHMqk7KaNQHQ0VrUvROlsQzexdJBBNQxMPFJHGqaLuobcFY81HCb6JsIqPKS l1Jh87pCQXWoGARCx50CyJ4/kP68jHdmk624qXAmCYVlysTEpMHvKqqJzPHPuB7SX/KM G3bRAcKd2VzbTZntRZX9cEC32hNPzdvUpDGg3mc1wy3VvGI93GLRv4MN46GiCG3k+619 KQ31klsYBogA7mMXICKh6yttP6VaKo5F/85Xz+QbZOd12YBgntWK79PpZxqC9hdL8LzX nz/125rLtOuwrXQqtVvrt7g7azu3zFYfNSgeHRPR4SoojaE+S++s3uWQx9pw0pdOT3T5 goIg== X-Gm-Message-State: ALoCoQlG9LQqOcuiYjbxZcZPHKo5eSXrW4vr9B35kFNG4A8Hrdkja5kQhuQwKYkRe4NjQoopx3729U4rmgW4erZslC8+2pzjj4V4FZDgJ/9/B0xxxAkl1R+fHoZZU4Ow0cnJriDP4hw6qo+j11O/DwHzQT/MvUz+UMm3w9nwA+BpAg8vlGrEoAY= MIME-Version: 1.0 X-Received: by 10.66.55.70 with SMTP id q6mr1685676pap.22.1441748069471; Tue, 08 Sep 2015 14:34:29 -0700 (PDT) Message-ID: <001a1136b5ce89b092051f432146@google.com> Date: Tue, 08 Sep 2015 21:34:29 +0000 Subject: [PATCH] [PR python/18938] source -s foo.py with foo.py a symlink to foo.notpy fails From: Doug Evans To: gdb-patches@sourceware.org X-IsSubscribed: yes Hi. This patch fixes 18938. If one has foo.py as a symlink to foo.notpy, then "source -s foo.py" will fail because gdb will try to interpret the extension language from the realpath'd form of the file. 2015-09-08 Doug Evans PR python/18938 * cli/cli-cmds (source_script_fron_sctream): New arg file_to_open. All callers updated. gdb_test "python print (gdb.objfiles())" "\\\[\\\]" diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index bcd7802..909a376 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -538,10 +538,16 @@ find_and_open_script (const char *script_file, int search_path, return 1; } -/* Load script FILE, which has already been opened as STREAM. */ +/* Load script FILE, which has already been opened as STREAM. + FILE_TO_OPEN is the form of FILE to use if one needs to open the file. + This is provided as FILE may have been found via the source search path. + An important thing to note here is that FILE may be a symlink to a file + with a different or non-existing suffix, and thus one cannot infer the + extension language from FILE_TO_OPEN. */ static void -source_script_from_stream (FILE *stream, const char *file) +source_script_from_stream (FILE *stream, const char *file, + const char *file_to_open) { if (script_ext_mode != script_ext_off) { @@ -556,7 +562,7 @@ source_script_from_stream (FILE *stream, const char *file) = ext_lang_script_sourcer (extlang); gdb_assert (sourcer != NULL); - sourcer (extlang, stream, file); + sourcer (extlang, stream, file_to_open); return; } else if (script_ext_mode == script_ext_soft) @@ -609,7 +615,7 @@ source_script_with_search (const char *file, int from_tty, int search_path) anyway so that error messages show the actual file used. But only do 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 (stream, search_path ? full_path : file); + source_script_from_stream (stream, file, search_path ? full_path : file); do_cleanups (old_cleanups); } diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp index a0b80e0..19b8322 100644 --- a/gdb/testsuite/gdb.python/python.exp +++ b/gdb/testsuite/gdb.python/python.exp @@ -96,6 +96,19 @@ gdb_test "source $remote_source2_py" "yes" "source source2.py" gdb_test "source -s source2.py" "yes" "source -s source2.py" +set remote_source2_symlink_notpy \ + [gdb_remote_download host ${srcdir}/${subdir}/source2.py \ + [standard_output_file "source2-symlink.notpy"]] +set remote_source2_symlink_py [standard_output_file "source2-symlink.py"] +remote_file host delete $remote_source2_symlink_py +set status [remote_exec host "ln -sf $remote_source2_symlink_notpy $remote_source2_symlink_py"] +set test "source -s source2-symlink.py" +if {[lindex $status 0] == 0} { + gdb_test "source -s $remote_source2_symlink_py" "yes" $test +} else { + unsupported "$test (host does not support symbolic links)" +} + gdb_test "python print (gdb.current_objfile())" "None"