From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25591 invoked by alias); 15 Apr 2014 23:35:35 -0000 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 Received: (qmail 25580 invoked by uid 89); 15 Apr 2014 23:35:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-ob0-f202.google.com Received: from mail-ob0-f202.google.com (HELO mail-ob0-f202.google.com) (209.85.214.202) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 15 Apr 2014 23:35:33 +0000 Received: by mail-ob0-f202.google.com with SMTP id gq1so639566obb.5 for ; Tue, 15 Apr 2014 16:35:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:mime-version:content-type :content-transfer-encoding:message-id:date:to:subject:in-reply-to :references; bh=hWWQLPKLuyqLod43cJJFPcTzQicz8uvPVMIqZTiiTsg=; b=WXo5k6ZMcH09bBQ5n0HcJh5G9iAmaMDPeRY6Q2uGHVwCcZD2WaW1+XVY893InJHvJU BHk8DhOmdbKhztLDpdVGC19gVEpF4NZpKiNeAHLXATPaEOZrUXzaglkh7OEM6o2wM0Ub 8OflPGFag4tGspyg70VFrVpf1hgVUmsAEgb0ddHBOOgxfYFB1LJTh53zqIAGVEh8fZ/i oV/KcsHc7xJmM5b1lJWg3NYrpoCF9l5kDJ5+2ZWy/ff8fr1bGb1hbMbTylUOfMpwNdpO zvDb4y3ZlIuJQW+vEeM5tsrIeKNTGuRfcLsh8NL4be7kiJJ+eJY+xTyDJlNFzjluX5Sf 5agw== X-Gm-Message-State: ALoCoQnTEVIOdhLOJbla4+cSykBm6sgQzYWzNdev271zsBNrDwPgmJI4Ss7oMYSMrPfFvoY+GeGXFYihkTJdH7U4B0ZGHfZhXo4dK0ex4o5Fh3jNbTl0ENWSzkOzLiP3A0gOedmBT3knc1tDMqgafyNfW14ZyecEpKMzDQy2CgeuPqjn69vz1yqKw0WwPTdCsA2+0PW8T0ARwa/WK0tMIxbwMs1RaZ2XEH1BslI1fCIiXjJ5kYAkq7Y= X-Received: by 10.43.78.135 with SMTP id zm7mr595026icb.27.1397604931087; Tue, 15 Apr 2014 16:35:31 -0700 (PDT) Received: from corp2gmr1-2.hot.corp.google.com (corp2gmr1-2.hot.corp.google.com [172.24.189.93]) by gmr-mx.google.com with ESMTPS id r61si2913103yhf.1.2014.04.15.16.35.31 for (version=TLSv1.1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 15 Apr 2014 16:35:31 -0700 (PDT) Received: from ruffy.mtv.corp.google.com (ruffy.mtv.corp.google.com [172.17.128.44]) by corp2gmr1-2.hot.corp.google.com (Postfix) with ESMTP id B3CAB5A4260 for ; Tue, 15 Apr 2014 16:35:30 -0700 (PDT) From: Doug Evans MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <21325.49730.150496.454220@ruffy.mtv.corp.google.com> Date: Tue, 15 Apr 2014 23:35:00 -0000 To: gdb-patches@sourceware.org Subject: Re: [PATCH] Pass --data-directory through gdb_realpath. In-Reply-To: References: X-IsSubscribed: yes X-SW-Source: 2014-04/txt/msg00307.txt.bz2 Doug Evans writes: > Hi. > > gdb currently records the supplied --data-directory as is, > which if a relative path will be wrong if the user cd's > to a different directory. > > 2014-04-15 Doug Evans > > * main.c (captured_main): Pass --data-directory through gdb_realpath. This patch supercedes the previous one. It adds similar processing for "set data-directory foo". 2014-04-15 Doug Evans * main.c (set_gdb_data_directory): New function. (captured_main): Flag error for --data-directory "". Call set_gdb_data_directory. * main.h (set_gdb_data_directory): Declare. * top.c (staged_gdb_datadir): New static local. (set_gdb_datadir): Call set_gdb_data_directory (show_gdb_datadir): New function. (init_main): Update init of data-directory parameter. testsuite/ * gdb.base/catch-syscall.exp (test_catch_syscall_fail_nodatadir): Update. (do_syscall_tests_without_xml): Update. diff --git a/gdb/main.c b/gdb/main.c index 59015f5..2be9bbc 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -106,6 +106,41 @@ get_gdb_program_name (void) static void print_gdb_help (struct ui_file *); +/* Set the data-directory parameter to NEW_DATADIR. + If NEW_DATADIR is not a directory then a warning is printed. + We don't signal an error for backward compatibility. */ + +void +set_gdb_data_directory (const char *new_datadir) +{ + struct stat st; + + if (stat (new_datadir, &st) < 0) + { + int save_errno = errno; + + fprintf_unfiltered (gdb_stderr, "Warning: "); + print_sys_errmsg (new_datadir, save_errno); + } + else if (!S_ISDIR (st.st_mode)) + warning (_("%s is not a directory."), new_datadir); + + xfree (gdb_datadir); + gdb_datadir = gdb_realpath (new_datadir); + + /* gdb_realpath won't return an absolute path if the path doesn't exist, + but we still want to record an absolute path here. If the user entered + "../foo" and "../foo" doesn't exist then we'll record $(pwd)/../foo which + isn't canonical, but that's ok. */ + if (!IS_ABSOLUTE_PATH (gdb_datadir)) + { + char *abs_datadir = gdb_abspath (gdb_datadir); + + xfree (gdb_datadir); + gdb_datadir = abs_datadir; + } +} + /* Relocate a file or directory. PROGNAME is the name by which gdb was invoked (i.e., argv[0]). INITIAL is the default value for the file or directory. FLAG is true if the value is relocatable, false @@ -641,8 +676,15 @@ captured_main (void *data) gdb_stdout = ui_file_new(); break; case 'D': - xfree (gdb_datadir); - gdb_datadir = xstrdup (optarg); + if (optarg[0] == '\0') + { + fprintf_unfiltered (gdb_stderr, + _("%s: empty path for" + " `--data-directory'\n"), + argv[0]); + exit (1); + } + set_gdb_data_directory (optarg); gdb_datadir_provided = 1; break; #ifdef GDBTK diff --git a/gdb/main.h b/gdb/main.h index 089e1c8..502ca30 100644 --- a/gdb/main.h +++ b/gdb/main.h @@ -47,4 +47,6 @@ extern char *windows_get_absolute_argv0 (const char *argv0); parse the argv array. */ extern const char *get_gdb_program_name (void); +extern void set_gdb_data_directory (const char *new_data_dir); + #endif diff --git a/gdb/testsuite/gdb.base/catch-syscall.exp b/gdb/testsuite/gdb.base/catch-syscall.exp index da838f7..a70534c 100644 --- a/gdb/testsuite/gdb.base/catch-syscall.exp +++ b/gdb/testsuite/gdb.base/catch-syscall.exp @@ -256,7 +256,8 @@ proc test_catch_syscall_fail_nodatadir {} { # Make sure GDB doesn't load the syscalls xml from the system # data directory. - gdb_test_no_output "set data-directory /the/path/to/nowhere" + gdb_test "set data-directory /the/path/to/nowhere" \ + "Warning: /the/path/to/nowhere: .*" # Testing to see if we receive a warning when calling "catch # syscall" without XML support (without datadir). @@ -374,7 +375,8 @@ proc test_catch_syscall_with_wrong_args_noxml {} { proc do_syscall_tests_without_xml {} { # Make sure GDB doesn't load the syscalls xml from the system data # directory. - gdb_test_no_output "set data-directory /the/path/to/nowhere" + gdb_test "set data-directory /the/path/to/nowhere" \ + "Warning: /the/path/to/nowhere: .*" # Let's test if we can catch syscalls without XML support. # We should succeed, but GDB is not supposed to print syscall names. diff --git a/gdb/top.c b/gdb/top.c index fa20025..186b05f 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -1668,14 +1668,28 @@ show_exec_done_display_p (struct ui_file *file, int from_tty, value); } +/* New values of the "data-directory" parameter are staged here. */ +static char *staged_gdb_datadir; + /* "set" command for the gdb_datadir configuration variable. */ static void set_gdb_datadir (char *args, int from_tty, struct cmd_list_element *c) { + set_gdb_data_directory (staged_gdb_datadir); observer_notify_gdb_datadir_changed (); } +/* "show" command for the gdb_datadir configuration variable. */ + +static void +show_gdb_datadir (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char *value) +{ + fprintf_filtered (file, _("GDB's data directory is \"%s\".\n"), + gdb_datadir); +} + static void set_history_filename (char *args, int from_tty, struct cmd_list_element *c) { @@ -1793,11 +1807,11 @@ Use \"on\" to enable the notification, and \"off\" to disable it."), &setlist, &showlist); add_setshow_filename_cmd ("data-directory", class_maintenance, - &gdb_datadir, _("Set GDB's data directory."), + &staged_gdb_datadir, _("Set GDB's data directory."), _("Show GDB's data directory."), _("\ When set, GDB uses the specified path to search for data files."), - set_gdb_datadir, NULL, + set_gdb_datadir, show_gdb_datadir, &setlist, &showlist); }