From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 5/9] Constify main.c:get_init_files.
Date: Thu, 27 Jun 2013 18:52:00 -0000 [thread overview]
Message-ID: <20130627185236.6625.4979.stgit@brno.lan> (raw)
In-Reply-To: <20130627185200.6625.10526.stgit@brno.lan>
A following patch will want to make the "gdbinit" global array const.
As usual, that forces in a cascading series of const additions. This
patch preemptively does those. I went all the way up to constifying
catch_command_errors, but then that would require constifying
execute_command as well (which is a much more significant effort). So
as stop point, I found the cleanest would be to add a variant of
catch_command_errors that takes const args, and use that in the few
spots that needed it due to the the get_init_files constification.
gdb/
2013-06-27 Pedro Alves <palves@redhat.com>
* cli/cli-cmds.c (source_script): Make 'file' parameter const.
* cli/cli-cmds.h (source_script): Likewise.
* exceptions.c (catch_command_errors_const): New function.
* exceptions.h (catch_command_errors_const): Declare.
* main.c (get_init_files): Make parameters const, and adjust.
(captured_main): Make 'system_gdbinit', 'home_gdbinit' and
'local_gdbinit' locals const. Adjust to use
catch_command_errors_const.
(print_gdb_help): Make 'system_gdbinit', 'home_gdbinit' and
'local_gdbinit' locals const.
---
gdb/cli/cli-cmds.c | 2 +-
gdb/cli/cli-cmds.h | 2 +-
gdb/exceptions.c | 16 ++++++++++++++++
gdb/exceptions.h | 6 ++++++
gdb/main.c | 40 +++++++++++++++++++++-------------------
5 files changed, 45 insertions(+), 21 deletions(-)
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 6ee7673..bd2ca2d 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -597,7 +597,7 @@ source_script_with_search (const char *file, int from_tty, int search_path)
for use in loading .gdbinit scripts. */
void
-source_script (char *file, int from_tty)
+source_script (const char *file, int from_tty)
{
source_script_with_search (file, from_tty, 0);
}
diff --git a/gdb/cli/cli-cmds.h b/gdb/cli/cli-cmds.h
index 9f6977c..34fe445 100644
--- a/gdb/cli/cli-cmds.h
+++ b/gdb/cli/cli-cmds.h
@@ -117,7 +117,7 @@ extern void cd_command (char *, int);
extern void quit_command (char *, int);
-extern void source_script (char *, int);
+extern void source_script (const char *, int);
/* Exported to objfiles.c. */
diff --git a/gdb/exceptions.c b/gdb/exceptions.c
index 0cdd16b..416d81d 100644
--- a/gdb/exceptions.c
+++ b/gdb/exceptions.c
@@ -577,3 +577,19 @@ catch_command_errors (catch_command_errors_ftype *command,
return 0;
return 1;
}
+
+int
+catch_command_errors_const (catch_command_errors_const_ftype *command,
+ const char *arg, int from_tty, return_mask mask)
+{
+ volatile struct gdb_exception e;
+
+ TRY_CATCH (e, mask)
+ {
+ command (arg, from_tty);
+ }
+ print_any_exception (gdb_stderr, NULL, e);
+ if (e.reason < 0)
+ return 0;
+ return 1;
+}
diff --git a/gdb/exceptions.h b/gdb/exceptions.h
index 7e3be95..19eacd3 100644
--- a/gdb/exceptions.h
+++ b/gdb/exceptions.h
@@ -257,4 +257,10 @@ typedef void (catch_command_errors_ftype) (char *, int);
extern int catch_command_errors (catch_command_errors_ftype *func,
char *arg, int from_tty, return_mask);
+/* Like catch_command_errors, but works with const command and args. */
+
+typedef void (catch_command_errors_const_ftype) (const char *, int);
+extern int catch_command_errors_const (catch_command_errors_const_ftype *func,
+ const char *arg, int from_tty, return_mask);
+
#endif
diff --git a/gdb/main.c b/gdb/main.c
index 3c1ef75..a0930ee 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -160,13 +160,13 @@ relocate_gdb_directory (const char *initial, int flag)
to be loaded, then SYSTEM_GDBINIT (resp. HOME_GDBINIT and
LOCAL_GDBINIT) is set to NULL. */
static void
-get_init_files (char **system_gdbinit,
- char **home_gdbinit,
- char **local_gdbinit)
+get_init_files (const char **system_gdbinit,
+ const char **home_gdbinit,
+ const char **local_gdbinit)
{
- static char *sysgdbinit = NULL;
+ static const char *sysgdbinit = NULL;
static char *homeinit = NULL;
- static char *localinit = NULL;
+ static const char *localinit = NULL;
static int initialized = 0;
if (!initialized)
@@ -336,9 +336,9 @@ captured_main (void *data)
int ndir;
/* gdb init files. */
- char *system_gdbinit;
- char *home_gdbinit;
- char *local_gdbinit;
+ const char *system_gdbinit;
+ const char *home_gdbinit;
+ const char *local_gdbinit;
int i;
int save_auto_load;
@@ -894,7 +894,8 @@ captured_main (void *data)
processed; it sets global parameters, which are independent of
what file you are debugging or what directory you are in. */
if (system_gdbinit && !inhibit_gdbinit)
- catch_command_errors (source_script, system_gdbinit, 0, RETURN_MASK_ALL);
+ catch_command_errors_const (source_script, system_gdbinit,
+ 0, RETURN_MASK_ALL);
/* Read and execute $HOME/.gdbinit file, if it exists. This is done
*before* all the command line arguments are processed; it sets
@@ -902,15 +903,16 @@ captured_main (void *data)
debugging or what directory you are in. */
if (home_gdbinit && !inhibit_gdbinit && !inhibit_home_gdbinit)
- catch_command_errors (source_script, home_gdbinit, 0, RETURN_MASK_ALL);
+ catch_command_errors_const (source_script,
+ home_gdbinit, 0, RETURN_MASK_ALL);
/* Process '-ix' and '-iex' options early. */
for (i = 0; VEC_iterate (cmdarg_s, cmdarg_vec, i, cmdarg_p); i++)
switch (cmdarg_p->type)
{
case CMDARG_INIT_FILE:
- catch_command_errors (source_script, cmdarg_p->string,
- !batch_flag, RETURN_MASK_ALL);
+ catch_command_errors_const (source_script, cmdarg_p->string,
+ !batch_flag, RETURN_MASK_ALL);
break;
case CMDARG_INIT_COMMAND:
catch_command_errors (execute_command, cmdarg_p->string,
@@ -1006,8 +1008,8 @@ captured_main (void *data)
{
auto_load_local_gdbinit_loaded = 1;
- catch_command_errors (source_script, local_gdbinit, 0,
- RETURN_MASK_ALL);
+ catch_command_errors_const (source_script, local_gdbinit, 0,
+ RETURN_MASK_ALL);
}
}
@@ -1024,8 +1026,8 @@ captured_main (void *data)
switch (cmdarg_p->type)
{
case CMDARG_FILE:
- catch_command_errors (source_script, cmdarg_p->string,
- !batch_flag, RETURN_MASK_ALL);
+ catch_command_errors_const (source_script, cmdarg_p->string,
+ !batch_flag, RETURN_MASK_ALL);
break;
case CMDARG_COMMAND:
catch_command_errors (execute_command, cmdarg_p->string,
@@ -1075,9 +1077,9 @@ gdb_main (struct captured_main_args *args)
static void
print_gdb_help (struct ui_file *stream)
{
- char *system_gdbinit;
- char *home_gdbinit;
- char *local_gdbinit;
+ const char *system_gdbinit;
+ const char *home_gdbinit;
+ const char *local_gdbinit;
get_init_files (&system_gdbinit, &home_gdbinit, &local_gdbinit);
next prev parent reply other threads:[~2013-06-27 18:52 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-27 18:52 [PATCH 00/09] Import unistd and pathmax gnulib modules Pedro Alves
2013-06-27 18:52 ` [PATCH 6/9] Reimplement DJGPP's .gdbinit -> gdb.ini renaming Pedro Alves
2013-06-27 18:52 ` [PATCH 3/9] Import the "unistd" gnulib module Pedro Alves
2013-06-27 18:52 ` Pedro Alves [this message]
2013-06-27 18:52 ` [PATCH 1/9] Reimport gnulib from scratch Pedro Alves
2013-06-28 8:49 ` Yao Qi
2013-06-28 9:55 ` Pedro Alves
2013-06-28 12:10 ` Yao Qi
2013-06-28 12:28 ` Pedro Alves
2013-06-27 18:52 ` [PATCH 2/9] utils.c: pathconf call, check for _PC_PATH_MAX instead of HAVE_UNISTD_H Pedro Alves
2013-06-27 18:52 ` [PATCH 4/9] Rely on gnulib's unistd.h replacement Pedro Alves
2013-06-28 9:05 ` Yao Qi
2013-06-28 17:44 ` Pedro Alves
2013-06-28 18:11 ` Pedro Alves
2013-06-27 18:53 ` [PATCH 7/9] Import the "pathmax" gnulib module Pedro Alves
2013-06-27 18:53 ` [PATCH 8/9] Normalize on PATH_MAX instead of MAXPATHLEN throughout Pedro Alves
2013-06-28 15:21 ` Tom Tromey
2013-06-28 18:06 ` Pedro Alves
2013-06-28 19:08 ` Tom Tromey
2013-06-27 18:59 ` [PATCH 9/9] [GDBserver] hostio.c: Fallback to packet buffer size if PATH_MAX is not available Pedro Alves
2013-06-28 15:43 ` [PATCH 00/09] Import unistd and pathmax gnulib modules Tom Tromey
2013-07-01 11:31 ` Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130627185236.6625.4979.stgit@brno.lan \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox