* Rename "info definitions"?
@ 2011-09-21 19:34 Doug Evans
2011-09-21 20:28 ` Matt Rice
0 siblings, 1 reply; 17+ messages in thread
From: Doug Evans @ 2011-09-21 19:34 UTC (permalink / raw)
To: ratmice; +Cc: gdb-patches
Hi.
I was wondering if it's not too late to rename "info definitions",
or better delete it and enhance "info macros" to replace it.
I look at "info definitions" and think "Definitions of what? That could be
anything." and then I find out what it refers to, look at both
"info macros" and "info definitions", and wish I didn't have to
think about when to use which one.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Rename "info definitions"?
2011-09-21 19:34 Rename "info definitions"? Doug Evans
@ 2011-09-21 20:28 ` Matt Rice
2011-09-23 17:38 ` Doug Evans
0 siblings, 1 reply; 17+ messages in thread
From: Matt Rice @ 2011-09-21 20:28 UTC (permalink / raw)
To: Doug Evans; +Cc: gdb-patches
On Wed, Sep 21, 2011 at 12:04 PM, Doug Evans <dje@google.com> wrote:
> Hi.
>
> I was wondering if it's not too late to rename "info definitions",
> or better delete it and enhance "info macros" to replace it.
> I look at "info definitions" and think "Definitions of what? That could be
> anything." and then I find out what it refers to, look at both
> "info macros" and "info definitions", and wish I didn't have to
> think about when to use which one.
>
IMO not too late since its never hit a tar ball
in fact I'd tried to merge info macros/info definitions but the
resulting command would have 2 optional arguments, and be fairly
difficult to comprehend.
now that I think about it maybe add an optional arg to 'info macro'
replace `info definitions MACRO' with 'info macro -all MACRO' ?
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Rename "info definitions"?
2011-09-21 20:28 ` Matt Rice
@ 2011-09-23 17:38 ` Doug Evans
2011-09-29 2:16 ` Matt Rice
0 siblings, 1 reply; 17+ messages in thread
From: Doug Evans @ 2011-09-23 17:38 UTC (permalink / raw)
To: Matt Rice; +Cc: gdb-patches
On Wed, Sep 21, 2011 at 12:33 PM, Matt Rice <ratmice@gmail.com> wrote:
> On Wed, Sep 21, 2011 at 12:04 PM, Doug Evans <dje@google.com> wrote:
>> Hi.
>>
>> I was wondering if it's not too late to rename "info definitions",
>> or better delete it and enhance "info macros" to replace it.
>> I look at "info definitions" and think "Definitions of what? That could be
>> anything." and then I find out what it refers to, look at both
>> "info macros" and "info definitions", and wish I didn't have to
>> think about when to use which one.
>>
>
> IMO not too late since its never hit a tar ball
>
> in fact I'd tried to merge info macros/info definitions but the
> resulting command would have 2 optional arguments, and be fairly
> difficult to comprehend.
>
> now that I think about it maybe add an optional arg to 'info macro'
> replace `info definitions MACRO' with 'info macro -all MACRO' ?
That would be better alright.
Also, I see calls to error() when there are no macros.
I think this shouldn't be an error.
For example, if it were done in a script it shouldn't break the script
if no macro info was found.
An informational message would be better IMO.
"info var foo" doesn't print an error on stripped binaries, for example.
E.g. here:
if (! ms || ! ms->file || ! ms->file->table)
error (_("GDB has no preprocessor macro information for that code."));
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Rename "info definitions"?
2011-09-23 17:38 ` Doug Evans
@ 2011-09-29 2:16 ` Matt Rice
2011-09-29 7:20 ` Eli Zaretskii
` (2 more replies)
0 siblings, 3 replies; 17+ messages in thread
From: Matt Rice @ 2011-09-29 2:16 UTC (permalink / raw)
To: Doug Evans; +Cc: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 2246 bytes --]
On Fri, Sep 23, 2011 at 10:20 AM, Doug Evans <dje@google.com> wrote:
> On Wed, Sep 21, 2011 at 12:33 PM, Matt Rice <ratmice@gmail.com> wrote:
>> now that I think about it maybe add an optional arg to 'info macro'
>> replace `info definitions MACRO' with 'info macro -all MACRO' ?
>
> That would be better alright.
>
> Also, I see calls to error() when there are no macros.
> I think this shouldn't be an error.
> For example, if it were done in a script it shouldn't break the script
> if no macro info was found.
> An informational message would be better IMO.
> "info var foo" doesn't print an error on stripped binaries, for example.
>
> E.g. here:
>
> if (! ms || ! ms->file || ! ms->file->table)
> error (_("GDB has no preprocessor macro information for that code."));
sorry for the delay,
this file was internally inconsistent in this case sometimes using
fputs_filtered, sometimes error,
apparently i flipped the coin wrong.
the attached patch changes the errors mentioned to informational messages...
adds -all, and a -- argument for reasons commented.
I'm not really opposed to removing the latter if it is unwanted,
but pedantic hat on, these come from dwarf which strives for language
independence
though the macro printing functions, and the macro expansion are all
currently c specific.
I wasn't really planning on doing anything more to make these less
c-specific but
didn't want to add any more hurdles...
Thanks.
2011-09-28 Matt Rice <ratmice@gmail.com>
* macrocmd.c (macro_no_macro_info): New function.
(macro_expand_command): Use macro_no_macro_info.
(macro_expand_once_command): Ditto.
(info_macro_command): Add argument processing,
move info_definitions_command here.
(_initialize_macrocmd): Remove info definitions command.
Add arguments to info macro help text.
* NEWS: Replace info definitions command with new info macro options.
2011-09-28 Matt Rice <ratmice@gmail.com>
gdb.texinfo (C Preprocessor Macros): Remove info definitions.
Add arguments to info macro.
2011-09-28 Matt Rice <ratmice@gmail.com>
gdb.base/info-macros.exp: Make tests for info definitions
test info macro. Add tests for info macro argument processing.
[-- Attachment #2: foo.diff --]
[-- Type: text/x-patch, Size: 11328 bytes --]
diff --git a/gdb/NEWS b/gdb/NEWS
index 20e58a0..3c5f4cb 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -73,7 +73,7 @@
the first connection is made. The listening port used by GDBserver will
become available after that.
-* New commands "info macros", and "info definitions" have been added.
+* New command "info macros" for listing all of the macros at a source location.
* Changed commands
@@ -85,6 +85,11 @@ info auto-load-scripts [REGEXP]
This command was formerly named "maintenance print section-scripts".
It is now generally useful and is no longer a maintenance-only command.
+info macro [-all] [--] MACRO
+ The info macro command has new options -all and --. The first or printing
+ all definitions of a macro. The second for explicitly specifying the end
+ of arguments and the beginning of the macro name.
+
* Tracepoints can now be enabled and disabled at any time after a trace
experiment has been started using the standard "enable" and "disable"
commands. It is now possible to start a trace experiment with no enabled
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index c8bb006..7f95196 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -9610,9 +9610,12 @@ can be any string of tokens.
@cindex macro definition, showing
@cindex definition of a macro, showing
@cindex macros, from debug info
-@item info macro @var{macro}
-Show the current definition of the named @var{macro}, and describe the
-source location or compiler command-line where that definition was established.
+@item info macro @r{[}-a@r{|}-all@r{]} @r{[}--@r{]} @var{macro}
+Show the current definition or all definitions of the named @var{macro},
+and describe the source location or compiler command-line where that
+definition was established. The optional double dash is to signify the end of
+argument processing and the beginning of @var{macro} for non C-like macros where
+the macro may begin with a dash.
@kindex info macros
@item info macros @var{linespec}
@@ -9620,12 +9623,6 @@ Show all macro definitions that are in effect at the location specified
by @var{linespec}, and describe the source location or compiler
command-line where those definitions were established.
-@kindex info definitions
-@item info definitions @var{macro}
-Show all definitions of the named @var{macro} that are defined in the current
-compilation unit, and describe the source location or compiler command-line
-where those definitions were established.
-
@kindex macro define
@cindex user-defined macros
@cindex defining macros interactively
diff --git a/gdb/macrocmd.c b/gdb/macrocmd.c
index d1ac7fa..9a003b3 100644
--- a/gdb/macrocmd.c
+++ b/gdb/macrocmd.c
@@ -45,6 +45,14 @@ macro_command (char *arg, int from_tty)
/* Macro expansion commands. */
+/* Prints an informational message regarding the lack of macro information. */
+static void macro_inform_no_debuginfo()
+{
+ fputs_filtered ("GDB has no preprocessor macro information for "
+ "that code.",
+ gdb_stdout);
+}
+
static void
macro_expand_command (char *exp, int from_tty)
{
@@ -73,9 +81,7 @@ macro_expand_command (char *exp, int from_tty)
fputs_filtered ("\n", gdb_stdout);
}
else
- fputs_filtered ("GDB has no preprocessor macro information for "
- "that code.\n",
- gdb_stdout);
+ macro_inform_no_debuginfo ();
do_cleanups (cleanup_chain);
return;
@@ -109,9 +115,7 @@ macro_expand_once_command (char *exp, int from_tty)
fputs_filtered ("\n", gdb_stdout);
}
else
- fputs_filtered ("GDB has no preprocessor macro information for "
- "that code.\n",
- gdb_stdout);
+ macro_inform_no_debuginfo ();
do_cleanups (cleanup_chain);
return;
@@ -178,43 +182,6 @@ print_macro_definition (const char *name,
fprintf_filtered (gdb_stdout, "=%s\n", d->replacement);
}
-static void
-info_macro_command (char *name, int from_tty)
-{
- struct macro_scope *ms = NULL;
- struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &ms);
- struct macro_definition *d;
-
- if (! name || ! *name)
- error (_("You must follow the `info macro' command with the name"
- " of the macro\n"
- "whose definition you want to see."));
-
- ms = default_macro_scope ();
- if (! ms)
- error (_("GDB has no preprocessor macro information for that code."));
-
- d = macro_lookup_definition (ms->file, ms->line, name);
- if (d)
- {
- int line;
- struct macro_source_file *file
- = macro_definition_location (ms->file, ms->line, name, &line);
-
- print_macro_definition (name, d, file, line);
- }
- else
- {
- fprintf_filtered (gdb_stdout,
- "The symbol `%s' has no definition as a C/C++"
- " preprocessor macro\n"
- "at ", name);
- show_pp_source_pos (gdb_stdout, ms->file, ms->line);
- }
-
- do_cleanups (cleanup_chain);
-}
-
/* A callback function for usage with macro_for_each and friends.
If USER_DATA is null all macros will be printed.
Otherwise USER_DATA is considered to be a string, printing
@@ -229,23 +196,79 @@ print_macro_callback (const char *name, const struct macro_definition *macro,
print_macro_definition (name, macro, source, line);
}
-/* Implementation of the "info definitions" command. */
+/* The implementation of the `info macro' command. */
static void
-info_definitions_command (char *name, int from_tty)
+info_macro_command (char *args, int from_tty)
{
struct macro_scope *ms = NULL;
- struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &ms);
+ struct cleanup *cleanup_chain;
+ char *name;
+ int show_all_macros_named = 0;
+ char *arg_start = args;
+ char *p = args;
+ int processing_args = 1;
+
+ while (processing_args
+ && arg_start && *arg_start == '-' && *arg_start != '\0')
+ {
+ p = strchrnul (p, ' ');
+
+ if (strncmp (arg_start, "-a", p - arg_start) == 0
+ || strncmp (arg_start, "-all", p - arg_start) == 0)
+ show_all_macros_named = 1;
+ else if (strncmp (arg_start, "--", p - arg_start) == 0)
+ /* Our macro support seems rather C specific but this would
+ seem necessary for languages allow - in macro names.
+ e.g. Scheme's (defmacro ->foo () "bar\n") */
+ processing_args = 0;
+ else
+ {
+ *p = '\0';
+ error (_("Unrecognized option '%s' to info macro command. "
+ "Try \"help info macro\"."), arg_start);
+ }
+
+ if (*p)
+ p++;
+ arg_start = p;
+ }
+ name = arg_start;
if (! name || ! *name)
- error (_("The `info definitions' command requires a macro name as an \
-argument."));
+ error (_("You must follow the `info macro' command with the name"
+ " of the macro\n"
+ "whose definition you want to see."));
ms = default_macro_scope ();
+ cleanup_chain = make_cleanup (free_current_contents, &ms);
- if (! ms || ! ms->file || ! ms->file->table)
- error (_("GDB has no preprocessor macro information for that code."));
+ if (! ms)
+ macro_inform_no_debuginfo ();
+ else if (show_all_macros_named)
+ macro_for_each (ms->file->table, print_macro_callback, name);
+ else
+ {
+ struct macro_definition *d;
+
+ d = macro_lookup_definition (ms->file, ms->line, name);
+ if (d)
+ {
+ int line;
+ struct macro_source_file *file
+ = macro_definition_location (ms->file, ms->line, name, &line);
+
+ print_macro_definition (name, d, file, line);
+ }
+ else
+ {
+ fprintf_filtered (gdb_stdout,
+ "The symbol `%s' has no definition as a C/C++"
+ " preprocessor macro\n"
+ "at ", name);
+ show_pp_source_pos (gdb_stdout, ms->file, ms->line);
+ }
+ }
- macro_for_each (ms->file->table, print_macro_callback, name);
do_cleanups (cleanup_chain);
}
@@ -267,9 +290,10 @@ info_macros_command (char *args, int from_tty)
}
if (! ms || ! ms->file || ! ms->file->table)
- error (_("GDB has no preprocessor macro information for that code."));
+ macro_inform_no_debuginfo ();
+ else
+ macro_for_each_in_scope (ms->file, ms->line, print_macro_callback, NULL);
- macro_for_each_in_scope (ms->file, ms->line, print_macro_callback, NULL);
do_cleanups (cleanup_chain);
}
@@ -495,7 +519,13 @@ expression work together to yield a pre-processed expression."),
add_alias_cmd ("exp1", "expand-once", no_class, 1, ¯olist);
add_cmd ("macro", no_class, info_macro_command,
- _("Show the definition of MACRO, and its source location."),
+ _("Show the definition of MACRO, and it's source location.\n\
+Usage: info macro [-a|-all] [--] MACRO\n\
+Options: \n\
+ -a, --all Output all definitions of MACRO in the current compilation\
+ unit.\n\
+ -- Specify the end of arguments and the beginning of the MACRO."),
+
&infolist);
add_cmd ("macros", no_class, info_macros_command,
@@ -504,11 +534,6 @@ source location.\n\
Usage: info macros [LINESPEC]"),
&infolist);
- add_cmd ("definitions", no_class, info_definitions_command,
- _("Show all definitions of MACRO in the current compilation unit.\n\
-Usage: info definitions MACRO"),
- &infolist);
-
add_cmd ("define", no_class, macro_define_command, _("\
Define a new C/C++ preprocessor macro.\n\
The GDB command `macro define DEFINITION' is equivalent to placing a\n\
diff --git a/gdb/testsuite/gdb.base/info-macros.exp b/gdb/testsuite/gdb.base/info-macros.exp
index bd5a870..8437f94 100644
--- a/gdb/testsuite/gdb.base/info-macros.exp
+++ b/gdb/testsuite/gdb.base/info-macros.exp
@@ -34,7 +34,39 @@ if ![runto_main] {
return -1
}
-set test "info definitions FOO"
+# Test various error messages.
+# "The symbol `-all' has no definition .*\r\nat.*\r\n" \
+gdb_test "info macro -- -all" \
+ "The symbol `-all' has no definition .*\[^\r\n\]at *\[\r\n\]" \
+ "info macro -- -all"
+
+gdb_test "info macro -all --" \
+ "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]" \
+ "info macro -all --"
+
+gdb_test "info macro --" \
+ "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]" \
+ "info macro --"
+
+gdb_test "info macro -invalid-option" \
+ "Unrecognized option.*Try \"help info macro\"\." \
+ "info macro -invalid-option 1"
+
+gdb_test "info macro -invalid-option FOO" \
+ "Unrecognized option.*Try \"help info macro\"\." \
+ "info macro -invalid-option 2"
+
+# Single macro lookups.
+gdb_test "info macro -- FOO" \
+ ".*#define FOO \"hello\"" \
+ "info macro -- FOO"
+
+gdb_test "info macro FOO" \
+ ".*#define FOO \"hello\"" \
+ "info macro FOO"
+
+# Multiple macro lookups.
+set test "info macro -a FOO"
set r1 ".*#define FOO \"hello\""
set r2 ".*#define FOO \" \""
set r3 ".*#define FOO \"world\""
@@ -42,6 +74,14 @@ set r4 ".*#define FOO\\(a\\) foo = a"
set testname "$test 1"
gdb_test "$test" "$r1$r2$r3$r4" "$testname"
+set test "info macro -a -- FOO"
+set testname "$test 1"
+gdb_test "$test" "$r1$r2$r3$r4" "$testname"
+
+set test "info macro -all -- FOO"
+set testname "$test 1"
+gdb_test "$test" "$r1$r2$r3$r4" "$testname"
+
set test "info macros"
set r1 ".*#define FOO \"hello\""
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Rename "info definitions"?
2011-09-29 2:16 ` Matt Rice
@ 2011-09-29 7:20 ` Eli Zaretskii
2011-09-29 10:55 ` Pedro Alves
2011-10-03 21:18 ` Matt Rice
2 siblings, 0 replies; 17+ messages in thread
From: Eli Zaretskii @ 2011-09-29 7:20 UTC (permalink / raw)
To: Matt Rice; +Cc: dje, gdb-patches
> Date: Wed, 28 Sep 2011 19:13:58 -0700
> From: Matt Rice <ratmice@gmail.com>
> Cc: gdb-patches@sourceware.org
>
> +info macro [-all] [--] MACRO
> + The info macro command has new options -all and --.
Please quote the options with `..'. Also, please have 2 spaces after
the period.
> The first or printing
^^
"for", I guess.
> + all definitions of a macro. The second for explicitly specifying the end
> + of arguments and the beginning of the macro name.
I would add "in case the macro name starts with a hyphen".
> +@item info macro @r{[}-a@r{|}-all@r{]} @r{[}--@r{]} @var{macro}
You don't need the @r{} markup here. It is only needed in the @def*
lines, because those cause the rest of the line automatically typeset
as in @var{}, which produces a slanted typeface in print. Since we
want the square brackets typeset in the normal Roman typeface, we
countermand the slanted face with @r{}. But @item does not have that
effect, so @r{} is not needed.
OK with those changes.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Rename "info definitions"?
2011-09-29 2:16 ` Matt Rice
2011-09-29 7:20 ` Eli Zaretskii
@ 2011-09-29 10:55 ` Pedro Alves
2011-09-29 12:41 ` Matt Rice
2011-10-03 21:18 ` Matt Rice
2 siblings, 1 reply; 17+ messages in thread
From: Pedro Alves @ 2011-09-29 10:55 UTC (permalink / raw)
To: gdb-patches; +Cc: Matt Rice, Doug Evans
On Thursday 29 September 2011 03:13:58, Matt Rice wrote:
> +info macro [-all] [--] MACRO
> + The info macro command has new options -all and --. The first or printing
> + all definitions of a macro. The second for explicitly specifying the end
> + of arguments and the beginning of the macro name.
Why do we need [--]? MACROS can't start with `-', can they?
--
Pedro Alves
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Rename "info definitions"?
2011-09-29 10:55 ` Pedro Alves
@ 2011-09-29 12:41 ` Matt Rice
2011-09-29 13:28 ` Pedro Alves
0 siblings, 1 reply; 17+ messages in thread
From: Matt Rice @ 2011-09-29 12:41 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches, Doug Evans
On Thu, Sep 29, 2011 at 3:54 AM, Pedro Alves <pedro@codesourcery.com> wrote:
> On Thursday 29 September 2011 03:13:58, Matt Rice wrote:
>> +info macro [-all] [--] MACRO
>> + The info macro command has new options -all and --. The first or printing
>> + all definitions of a macro. The second for explicitly specifying the end
>> + of arguments and the beginning of the macro name.
>
> Why do we need [--]? MACROS can't start with `-', can they?
not in cpp macros or m4 at least,
lisp/scheme macros allow them i'm not sure what else may,
I don't think any of the languages gdb currently supports allow it,
but not positive
I figured someone would complain but at least there'd be a patch in
the archives...
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Rename "info definitions"?
2011-09-29 12:41 ` Matt Rice
@ 2011-09-29 13:28 ` Pedro Alves
2011-09-29 13:37 ` Pedro Alves
0 siblings, 1 reply; 17+ messages in thread
From: Pedro Alves @ 2011-09-29 13:28 UTC (permalink / raw)
To: Matt Rice; +Cc: gdb-patches, Doug Evans
On Thursday 29 September 2011 13:33:37, Matt Rice wrote:
> On Thu, Sep 29, 2011 at 3:54 AM, Pedro Alves <pedro@codesourcery.com> wrote:
> > On Thursday 29 September 2011 03:13:58, Matt Rice wrote:
> >> +info macro [-all] [--] MACRO
> >> + The info macro command has new options -all and --. The first or printing
> >> + all definitions of a macro. The second for explicitly specifying the end
> >> + of arguments and the beginning of the macro name.
> >
> > Why do we need [--]? MACROS can't start with `-', can they?
>
> not in cpp macros or m4 at least,
> lisp/scheme macros allow them i'm not sure what else may,
Ah, I now see you've put comments in that direction in the code.
Sorry I missed them before.
> I don't think any of the languages gdb currently supports allow it,
> but not positive
I'm not sure scheme macros would be a good fit for gdb's
(C/preprocessor) macros infrastructure.
> I figured someone would complain but at least there'd be a patch in
> the archives...
:-) Given that it's optional, I don't care that much. Fine with
me to put it in.
We could just add it back if we ever find a need though.
If a language needing it for macros would require adding more
such switches to other commands.
--
Pedro Alves
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Rename "info definitions"?
2011-09-29 13:28 ` Pedro Alves
@ 2011-09-29 13:37 ` Pedro Alves
2011-09-29 13:56 ` Matt Rice
0 siblings, 1 reply; 17+ messages in thread
From: Pedro Alves @ 2011-09-29 13:37 UTC (permalink / raw)
To: gdb-patches; +Cc: Matt Rice, Doug Evans
On Thursday 29 September 2011 14:26:19, Pedro Alves wrote:
> We could just add it back if we ever find a need though.
> If a language needing it for macros would require adding more
> such switches to other commands.
Err, I meant, "I suspect a language needing it for macros would
require adding more such switches to other commands."
--
Pedro Alves
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Rename "info definitions"?
2011-09-29 13:37 ` Pedro Alves
@ 2011-09-29 13:56 ` Matt Rice
2011-09-29 14:01 ` Pedro Alves
0 siblings, 1 reply; 17+ messages in thread
From: Matt Rice @ 2011-09-29 13:56 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches, Doug Evans
On Thu, Sep 29, 2011 at 6:28 AM, Pedro Alves <pedro@codesourcery.com> wrote:
> On Thursday 29 September 2011 14:26:19, Pedro Alves wrote:
>> We could just add it back if we ever find a need though.
>> If a language needing it for macros would require adding more
>> such switches to other commands.
>
> Err, I meant, "I suspect a language needing it for macros would
> require adding more such switches to other commands."
None of the other macro commands accept options, they just interpret
the entire string as a
name currently, so this is a new form of c-ism
I think all that would be required is just turning the macro printing
formatters into language based callbacks, and the macro expansion
parser into language based callbacks.
but who knows what you would run into if you actually tried.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Rename "info definitions"?
2011-09-29 13:56 ` Matt Rice
@ 2011-09-29 14:01 ` Pedro Alves
0 siblings, 0 replies; 17+ messages in thread
From: Pedro Alves @ 2011-09-29 14:01 UTC (permalink / raw)
To: Matt Rice; +Cc: gdb-patches, Doug Evans
On Thursday 29 September 2011 14:42:42, Matt Rice wrote:
> On Thu, Sep 29, 2011 at 6:28 AM, Pedro Alves <pedro@codesourcery.com> wrote:
> > On Thursday 29 September 2011 14:26:19, Pedro Alves wrote:
> >> We could just add it back if we ever find a need though.
> >> If a language needing it for macros would require adding more
> >> such switches to other commands.
> >
> > Err, I meant, "I suspect a language needing it for macros would
> > require adding more such switches to other commands."
>
> None of the other macro commands accept options, they just interpret
> the entire string as a
> name currently, so this is a new form of c-ism
>
> I think all that would be required is just turning the macro printing
> formatters into language based callbacks, and the macro expansion
> parser into language based callbacks.
Still, I'm really not sure doing just that would be a good idea. You
can always run a C preprocessor on some non-C sources. If it's a
compiled language, the compiler should be able to output c preprocessor
macro debug info in that case too. I think that "info macros" and friends
(possibly renamed to c-macros?) should would still operate on the C
preprocessor macros / text expansion level in that case, instead of on
whatever the target language calls macros, and a new command specific
for the language's macros would be added.
> but who knows what you would run into if you actually tried.
Exactly. :-)
--
Pedro Alves
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Rename "info definitions"?
2011-09-29 2:16 ` Matt Rice
2011-09-29 7:20 ` Eli Zaretskii
2011-09-29 10:55 ` Pedro Alves
@ 2011-10-03 21:18 ` Matt Rice
2011-10-04 16:51 ` Tom Tromey
2 siblings, 1 reply; 17+ messages in thread
From: Matt Rice @ 2011-10-03 21:18 UTC (permalink / raw)
To: Doug Evans; +Cc: gdb-patches
On Wed, Sep 28, 2011 at 7:13 PM, Matt Rice <ratmice@gmail.com> wrote:
> (info_macro_command): Add argument processing,
sorry I realized in this argument processing I used strchrnul, but
forgot to check if its OK
since nothing else in gdb calls it except autoconf macros, and there
is no libiberty replacement
I doubt that it is... i'll come up with another patch unless someone
feels like blessing strchrnul.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Rename "info definitions"?
2011-10-03 21:18 ` Matt Rice
@ 2011-10-04 16:51 ` Tom Tromey
2011-10-05 0:31 ` Matt Rice
0 siblings, 1 reply; 17+ messages in thread
From: Tom Tromey @ 2011-10-04 16:51 UTC (permalink / raw)
To: Matt Rice; +Cc: Doug Evans, gdb-patches
>>>>> "Matt" == Matt Rice <ratmice@gmail.com> writes:
Matt> sorry I realized in this argument processing I used strchrnul, but
Matt> forgot to check if its OK
Matt> since nothing else in gdb calls it except autoconf macros, and there
Matt> is no libiberty replacement
Matt> I doubt that it is... i'll come up with another patch unless someone
Matt> feels like blessing strchrnul.
Use skip_to_space, see cli-utils.h.
This has the advantage of also recognizing \t.
Tom
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Rename "info definitions"?
2011-10-04 16:51 ` Tom Tromey
@ 2011-10-05 0:31 ` Matt Rice
2011-10-14 20:23 ` Tom Tromey
0 siblings, 1 reply; 17+ messages in thread
From: Matt Rice @ 2011-10-05 0:31 UTC (permalink / raw)
To: Tom Tromey; +Cc: Doug Evans, gdb-patches
[-- Attachment #1: Type: text/plain, Size: 1642 bytes --]
On Tue, Oct 4, 2011 at 9:51 AM, Tom Tromey <tromey@redhat.com> wrote:
>>>>>> "Matt" == Matt Rice <ratmice@gmail.com> writes:
>
> Matt> sorry I realized in this argument processing I used strchrnul, but
> Matt> forgot to check if its OK
> Matt> since nothing else in gdb calls it except autoconf macros, and there
> Matt> is no libiberty replacement
> Matt> I doubt that it is... i'll come up with another patch unless someone
> Matt> feels like blessing strchrnul.
>
> Use skip_to_space, see cli-utils.h.
> This has the advantage of also recognizing \t.
Thanks,
attached patch uses skip_to_space, and skip_spaces (to handle
extraneous whitespace)
updates docs with Eli's wanted changes, and fixes a test case which
would have failed if it would run, but wasn't
because of a silly # \ style commented out line.
2011-10-04 Matt Rice <ratmice@gmail.com>
* macrocmd.c (macro_no_macro_info): New function.
(macro_expand_command): Use macro_no_macro_info.
(macro_expand_once_command): Ditto.
(info_macro_command): Add argument processing,
move info_definitions_command here.
(_initialize_macrocmd): Remove info definitions command.
Add arguments to info macro help text.
* NEWS: Replace info definitions command with new info macro options.
2011-10-04 Matt Rice <ratmice@gmail.com>
gdb.texinfo (C Preprocessor Macros): Remove info definitions.
Add arguments to info macro.
2011-10-04 Matt Rice <ratmice@gmail.com>
gdb.base/info-macros.exp: Make tests for info definitions
test info macro. Add tests for info macro argument processing.
[-- Attachment #2: foo.diff --]
[-- Type: text/x-patch, Size: 12937 bytes --]
diff --git a/gdb/NEWS b/gdb/NEWS
index 20e58a0..2efda2a 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -73,7 +73,7 @@
the first connection is made. The listening port used by GDBserver will
become available after that.
-* New commands "info macros", and "info definitions" have been added.
+* New command "info macros" for listing all of the macros at a source location.
* Changed commands
@@ -85,6 +85,12 @@ info auto-load-scripts [REGEXP]
This command was formerly named "maintenance print section-scripts".
It is now generally useful and is no longer a maintenance-only command.
+info macro [-all] [--] MACRO
+ The info macro command has new options -all and --. The first for printing
+ all definitions of a macro. The second for explicitly specifying the end
+ of arguments and the beginning of the macro name in case the macro name
+ starts with a hyphen.
+
* Tracepoints can now be enabled and disabled at any time after a trace
experiment has been started using the standard "enable" and "disable"
commands. It is now possible to start a trace experiment with no enabled
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index aa7cdca..d3faf87 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -9610,9 +9610,12 @@ can be any string of tokens.
@cindex macro definition, showing
@cindex definition of a macro, showing
@cindex macros, from debug info
-@item info macro @var{macro}
-Show the current definition of the named @var{macro}, and describe the
-source location or compiler command-line where that definition was established.
+@item info macro [-a|-all] [--] @var{macro}
+Show the current definition or all definitions of the named @var{macro},
+and describe the source location or compiler command-line where that
+definition was established. The optional double dash is to signify the end of
+argument processing and the beginning of @var{macro} for non C-like macros where
+the macro may begin with a hyphen.
@kindex info macros
@item info macros @var{linespec}
@@ -9620,12 +9623,6 @@ Show all macro definitions that are in effect at the location specified
by @var{linespec}, and describe the source location or compiler
command-line where those definitions were established.
-@kindex info definitions
-@item info definitions @var{macro}
-Show all definitions of the named @var{macro} that are defined in the current
-compilation unit, and describe the source location or compiler command-line
-where those definitions were established.
-
@kindex macro define
@cindex user-defined macros
@cindex defining macros interactively
diff --git a/gdb/macrocmd.c b/gdb/macrocmd.c
index d1ac7fa..f5fd80e 100644
--- a/gdb/macrocmd.c
+++ b/gdb/macrocmd.c
@@ -23,6 +23,7 @@
#include "macrotab.h"
#include "macroexp.h"
#include "macroscope.h"
+#include "cli/cli-utils.h"
#include "command.h"
#include "gdbcmd.h"
#include "gdb_string.h"
@@ -45,6 +46,14 @@ macro_command (char *arg, int from_tty)
/* Macro expansion commands. */
+/* Prints an informational message regarding the lack of macro information. */
+static void macro_inform_no_debuginfo()
+{
+ fputs_filtered ("GDB has no preprocessor macro information for "
+ "that code.",
+ gdb_stdout);
+}
+
static void
macro_expand_command (char *exp, int from_tty)
{
@@ -73,9 +82,7 @@ macro_expand_command (char *exp, int from_tty)
fputs_filtered ("\n", gdb_stdout);
}
else
- fputs_filtered ("GDB has no preprocessor macro information for "
- "that code.\n",
- gdb_stdout);
+ macro_inform_no_debuginfo ();
do_cleanups (cleanup_chain);
return;
@@ -109,9 +116,7 @@ macro_expand_once_command (char *exp, int from_tty)
fputs_filtered ("\n", gdb_stdout);
}
else
- fputs_filtered ("GDB has no preprocessor macro information for "
- "that code.\n",
- gdb_stdout);
+ macro_inform_no_debuginfo ();
do_cleanups (cleanup_chain);
return;
@@ -178,43 +183,6 @@ print_macro_definition (const char *name,
fprintf_filtered (gdb_stdout, "=%s\n", d->replacement);
}
-static void
-info_macro_command (char *name, int from_tty)
-{
- struct macro_scope *ms = NULL;
- struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &ms);
- struct macro_definition *d;
-
- if (! name || ! *name)
- error (_("You must follow the `info macro' command with the name"
- " of the macro\n"
- "whose definition you want to see."));
-
- ms = default_macro_scope ();
- if (! ms)
- error (_("GDB has no preprocessor macro information for that code."));
-
- d = macro_lookup_definition (ms->file, ms->line, name);
- if (d)
- {
- int line;
- struct macro_source_file *file
- = macro_definition_location (ms->file, ms->line, name, &line);
-
- print_macro_definition (name, d, file, line);
- }
- else
- {
- fprintf_filtered (gdb_stdout,
- "The symbol `%s' has no definition as a C/C++"
- " preprocessor macro\n"
- "at ", name);
- show_pp_source_pos (gdb_stdout, ms->file, ms->line);
- }
-
- do_cleanups (cleanup_chain);
-}
-
/* A callback function for usage with macro_for_each and friends.
If USER_DATA is null all macros will be printed.
Otherwise USER_DATA is considered to be a string, printing
@@ -229,23 +197,78 @@ print_macro_callback (const char *name, const struct macro_definition *macro,
print_macro_definition (name, macro, source, line);
}
-/* Implementation of the "info definitions" command. */
+/* The implementation of the `info macro' command. */
static void
-info_definitions_command (char *name, int from_tty)
+info_macro_command (char *args, int from_tty)
{
struct macro_scope *ms = NULL;
- struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &ms);
+ struct cleanup *cleanup_chain;
+ char *name;
+ int show_all_macros_named = 0;
+ char *arg_start = args;
+ int processing_args = 1;
+
+ while (processing_args
+ && arg_start && *arg_start == '-' && *arg_start != '\0')
+ {
+ char *p = skip_to_space (arg_start);
+
+ if (strncmp (arg_start, "-a", p - arg_start) == 0
+ || strncmp (arg_start, "-all", p - arg_start) == 0)
+ show_all_macros_named = 1;
+ else if (strncmp (arg_start, "--", p - arg_start) == 0)
+ /* Our macro support seems rather C specific but this would
+ seem necessary for languages allowing - in macro names.
+ e.g. Scheme's (defmacro ->foo () "bar\n") */
+ processing_args = 0;
+ else
+ {
+ /* Relies on modified 'args' not making it in to history */
+ *p = '\0';
+ error (_("Unrecognized option '%s' to info macro command. "
+ "Try \"help info macro\"."), arg_start);
+ }
+
+ arg_start = skip_spaces (p);
+ }
+
+ name = arg_start;
if (! name || ! *name)
- error (_("The `info definitions' command requires a macro name as an \
-argument."));
+ error (_("You must follow the `info macro' command with the name"
+ " of the macro\n"
+ "whose definition you want to see."));
ms = default_macro_scope ();
+ cleanup_chain = make_cleanup (free_current_contents, &ms);
- if (! ms || ! ms->file || ! ms->file->table)
- error (_("GDB has no preprocessor macro information for that code."));
+ if (! ms)
+ macro_inform_no_debuginfo ();
+ else if (show_all_macros_named)
+ macro_for_each (ms->file->table, print_macro_callback, name);
+ else
+ {
+ struct macro_definition *d;
+
+ d = macro_lookup_definition (ms->file, ms->line, name);
+ if (d)
+ {
+ int line;
+ struct macro_source_file *file
+ = macro_definition_location (ms->file, ms->line, name, &line);
+
+ print_macro_definition (name, d, file, line);
+ }
+ else
+ {
+ fprintf_filtered (gdb_stdout,
+ "The symbol `%s' has no definition as a C/C++"
+ " preprocessor macro\n"
+ "at ", name);
+ show_pp_source_pos (gdb_stdout, ms->file, ms->line);
+ }
+ }
- macro_for_each (ms->file->table, print_macro_callback, name);
do_cleanups (cleanup_chain);
}
@@ -267,9 +290,10 @@ info_macros_command (char *args, int from_tty)
}
if (! ms || ! ms->file || ! ms->file->table)
- error (_("GDB has no preprocessor macro information for that code."));
+ macro_inform_no_debuginfo ();
+ else
+ macro_for_each_in_scope (ms->file, ms->line, print_macro_callback, NULL);
- macro_for_each_in_scope (ms->file, ms->line, print_macro_callback, NULL);
do_cleanups (cleanup_chain);
}
@@ -495,7 +519,13 @@ expression work together to yield a pre-processed expression."),
add_alias_cmd ("exp1", "expand-once", no_class, 1, ¯olist);
add_cmd ("macro", no_class, info_macro_command,
- _("Show the definition of MACRO, and its source location."),
+ _("Show the definition of MACRO, and it's source location.\n\
+Usage: info macro [-a|-all] [--] MACRO\n\
+Options: \n\
+ -a, --all Output all definitions of MACRO in the current compilation\
+ unit.\n\
+ -- Specify the end of arguments and the beginning of the MACRO."),
+
&infolist);
add_cmd ("macros", no_class, info_macros_command,
@@ -504,11 +534,6 @@ source location.\n\
Usage: info macros [LINESPEC]"),
&infolist);
- add_cmd ("definitions", no_class, info_definitions_command,
- _("Show all definitions of MACRO in the current compilation unit.\n\
-Usage: info definitions MACRO"),
- &infolist);
-
add_cmd ("define", no_class, macro_define_command, _("\
Define a new C/C++ preprocessor macro.\n\
The GDB command `macro define DEFINITION' is equivalent to placing a\n\
diff --git a/gdb/testsuite/gdb.base/info-macros.exp b/gdb/testsuite/gdb.base/info-macros.exp
index bd5a870..0481e55 100644
--- a/gdb/testsuite/gdb.base/info-macros.exp
+++ b/gdb/testsuite/gdb.base/info-macros.exp
@@ -34,7 +34,75 @@ if ![runto_main] {
return -1
}
-set test "info definitions FOO"
+# Test various error messages.
+gdb_test "info macro -- -all" \
+ "The symbol `-all' has no definition .*\r\nat .*$srcfile:\[0-9\]+" \
+ "info macro -- -all"
+gdb_test "info macro -- -all" \
+ "The symbol `-all' has no definition .*\r\nat .*$srcfile:\[0-9\]+" \
+ "info macro -- -all"
+
+gdb_test "info macro -all --" \
+ "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]" \
+ "info macro -all --"
+
+gdb_test "info macro -all --" \
+ "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]" \
+ "info macro -all --"
+
+gdb_test "info macro -all --" \
+ "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]" \
+ "info macro -all --"
+
+gdb_test "info macro --" \
+ "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]" \
+ "info macro --"
+
+gdb_test "info macro -- " \
+ "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]" \
+ "'info macro -- '"
+gdb_test "info macro -- " \
+ "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]" \
+ "'info macro -- '"
+
+gdb_test "info macro -invalid-option" \
+ "Unrecognized option.*Try \"help info macro\"\." \
+ "info macro -invalid-option 1"
+
+gdb_test "info macro -invalid-option" \
+ "Unrecognized option.*Try \"help info macro\"\." \
+ "info macro -invalid-option"
+
+gdb_test "info macro -invalid-option FOO" \
+ "Unrecognized option.*Try \"help info macro\"\." \
+ "info macro -invalid-option 2"
+gdb_test "info macro -invalid-option FOO" \
+ "Unrecognized option.*Try \"help info macro\"\." \
+ "info macro -invalid-option 2"
+
+# Single macro lookups.
+gdb_test "info macro -- FOO" \
+ ".*#define FOO \"hello\"" \
+ "info macro -- FOO"
+
+gdb_test "info macro -- FOO" \
+ ".*#define FOO \"hello\"" \
+ "info macro -- FOO"
+
+gdb_test "info macro -- FOO" \
+ ".*#define FOO \"hello\"" \
+ "info macro -- FOO"
+
+gdb_test "info macro FOO" \
+ ".*#define FOO \"hello\"" \
+ "info macro FOO"
+
+gdb_test "info macro FOO" \
+ ".*#define FOO \"hello\"" \
+ "info macro FOO"
+
+# Multiple macro lookups.
+set test "info macro -a FOO"
set r1 ".*#define FOO \"hello\""
set r2 ".*#define FOO \" \""
set r3 ".*#define FOO \"world\""
@@ -42,6 +110,21 @@ set r4 ".*#define FOO\\(a\\) foo = a"
set testname "$test 1"
gdb_test "$test" "$r1$r2$r3$r4" "$testname"
+set test "info macro -a -- FOO"
+set testname "$test 1"
+gdb_test "$test" "$r1$r2$r3$r4" "$testname"
+
+set test "info macro -all -- FOO"
+set testname "$test 1"
+gdb_test "$test" "$r1$r2$r3$r4" "$testname"
+
+set test "info macro -a -- FOO"
+set testname "$test"
+gdb_test "$test" "$r1$r2$r3$r4" "$testname"
+
+set test "info macro -a -- FOO"
+set testname "$test"
+gdb_test "$test" "$r1$r2$r3$r4" "$testname"
set test "info macros"
set r1 ".*#define FOO \"hello\""
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Rename "info definitions"?
2011-10-05 0:31 ` Matt Rice
@ 2011-10-14 20:23 ` Tom Tromey
2011-11-12 17:03 ` Matt Rice
0 siblings, 1 reply; 17+ messages in thread
From: Tom Tromey @ 2011-10-14 20:23 UTC (permalink / raw)
To: Matt Rice; +Cc: Doug Evans, gdb-patches
>>>>> "Matt" == Matt Rice <ratmice@gmail.com> writes:
Matt> 2011-10-04 Matt Rice <ratmice@gmail.com>
Matt> * macrocmd.c (macro_no_macro_info): New function.
Matt> (macro_expand_command): Use macro_no_macro_info.
Matt> (macro_expand_once_command): Ditto.
Matt> (info_macro_command): Add argument processing,
Matt> move info_definitions_command here.
Matt> (_initialize_macrocmd): Remove info definitions command.
Matt> Add arguments to info macro help text.
Matt> * NEWS: Replace info definitions command with new info macro options.
Matt> 2011-10-04 Matt Rice <ratmice@gmail.com>
Matt> gdb.texinfo (C Preprocessor Macros): Remove info definitions.
Matt> Add arguments to info macro.
Matt> 2011-10-04 Matt Rice <ratmice@gmail.com>
Matt> gdb.base/info-macros.exp: Make tests for info definitions
Matt> test info macro. Add tests for info macro argument processing.
The code bits are ok. Thanks.
Tom
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Rename "info definitions"?
2011-10-14 20:23 ` Tom Tromey
@ 2011-11-12 17:03 ` Matt Rice
2011-11-12 17:09 ` Matt Rice
0 siblings, 1 reply; 17+ messages in thread
From: Matt Rice @ 2011-11-12 17:03 UTC (permalink / raw)
To: Tom Tromey; +Cc: Doug Evans, gdb-patches
[-- Attachment #1: Type: text/plain, Size: 258 bytes --]
On Fri, Oct 14, 2011 at 1:23 PM, Tom Tromey <tromey@redhat.com> wrote:
> The code bits are ok. Thanks.
sorry for the delay, attached is what I commited,
(I missed a change from Eli's requested changes),
and noticed a duplicate and a misnamed test.
[-- Attachment #2: foo.diff --]
[-- Type: text/x-patch, Size: 15586 bytes --]
? foo.diff
Index: gdb/ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/ChangeLog,v
retrieving revision 1.13508
diff -u -r1.13508 ChangeLog
--- gdb/ChangeLog 11 Nov 2011 19:52:45 -0000 1.13508
+++ gdb/ChangeLog 12 Nov 2011 16:59:19 -0000
@@ -1,3 +1,14 @@
+2011-11-12 Matt Rice <ratmice@gmail.com>
+
+ * macrocmd.c (macro_no_macro_info): New function.
+ (macro_expand_command): Use macro_no_macro_info.
+ (macro_expand_once_command): Ditto.
+ (info_macro_command): Add argument processing,
+ move info_definitions_command here.
+ (_initialize_macrocmd): Remove info definitions command.
+ Add arguments to info macro help text.
+ * NEWS: Replace info definitions command with new info macro options.
+
2011-11-11 Keith Seitz <keiths@redhat.com>
PR gdb/12843
Index: gdb/NEWS
===================================================================
RCS file: /cvs/src/src/gdb/NEWS,v
retrieving revision 1.464
diff -u -r1.464 NEWS
--- gdb/NEWS 2 Nov 2011 23:44:19 -0000 1.464
+++ gdb/NEWS 12 Nov 2011 16:59:19 -0000
@@ -97,8 +97,7 @@
the first connection is made. The listening port used by GDBserver will
become available after that.
-* New commands "info macros", "info definitions",
- and "alias" have been added.
+* New commands "info macros" and "alias" have been added.
* New function parameters suffix @entry specifies value of function parameter
at the time the function got called. Entry values are available only since
@@ -114,6 +113,12 @@
This command was formerly named "maintenance print section-scripts".
It is now generally useful and is no longer a maintenance-only command.
+info macro [-all] [--] MACRO
+ The info macro command has new options `-all' and `--'. The first for
+ printing all definitions of a macro. The second for explicitly specifying
+ the end of arguments and the beginning of the macro name in case the macro
+ name starts with a hyphen.
+
collect[/s] EXPRESSIONS
The tracepoint collect command now takes an optional modifier "/s"
that directs it to dereference pointer-to-character types and
Index: gdb/macrocmd.c
===================================================================
RCS file: /cvs/src/src/gdb/macrocmd.c,v
retrieving revision 1.26
diff -u -r1.26 macrocmd.c
--- gdb/macrocmd.c 21 Jul 2011 15:13:28 -0000 1.26
+++ gdb/macrocmd.c 12 Nov 2011 16:59:19 -0000
@@ -23,6 +23,7 @@
#include "macrotab.h"
#include "macroexp.h"
#include "macroscope.h"
+#include "cli/cli-utils.h"
#include "command.h"
#include "gdbcmd.h"
#include "gdb_string.h"
@@ -45,6 +46,14 @@
/* Macro expansion commands. */
+/* Prints an informational message regarding the lack of macro information. */
+static void macro_inform_no_debuginfo()
+{
+ fputs_filtered ("GDB has no preprocessor macro information for "
+ "that code.",
+ gdb_stdout);
+}
+
static void
macro_expand_command (char *exp, int from_tty)
{
@@ -73,9 +82,7 @@
fputs_filtered ("\n", gdb_stdout);
}
else
- fputs_filtered ("GDB has no preprocessor macro information for "
- "that code.\n",
- gdb_stdout);
+ macro_inform_no_debuginfo ();
do_cleanups (cleanup_chain);
return;
@@ -109,9 +116,7 @@
fputs_filtered ("\n", gdb_stdout);
}
else
- fputs_filtered ("GDB has no preprocessor macro information for "
- "that code.\n",
- gdb_stdout);
+ macro_inform_no_debuginfo ();
do_cleanups (cleanup_chain);
return;
@@ -178,43 +183,6 @@
fprintf_filtered (gdb_stdout, "=%s\n", d->replacement);
}
-static void
-info_macro_command (char *name, int from_tty)
-{
- struct macro_scope *ms = NULL;
- struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &ms);
- struct macro_definition *d;
-
- if (! name || ! *name)
- error (_("You must follow the `info macro' command with the name"
- " of the macro\n"
- "whose definition you want to see."));
-
- ms = default_macro_scope ();
- if (! ms)
- error (_("GDB has no preprocessor macro information for that code."));
-
- d = macro_lookup_definition (ms->file, ms->line, name);
- if (d)
- {
- int line;
- struct macro_source_file *file
- = macro_definition_location (ms->file, ms->line, name, &line);
-
- print_macro_definition (name, d, file, line);
- }
- else
- {
- fprintf_filtered (gdb_stdout,
- "The symbol `%s' has no definition as a C/C++"
- " preprocessor macro\n"
- "at ", name);
- show_pp_source_pos (gdb_stdout, ms->file, ms->line);
- }
-
- do_cleanups (cleanup_chain);
-}
-
/* A callback function for usage with macro_for_each and friends.
If USER_DATA is null all macros will be printed.
Otherwise USER_DATA is considered to be a string, printing
@@ -229,23 +197,78 @@
print_macro_definition (name, macro, source, line);
}
-/* Implementation of the "info definitions" command. */
+/* The implementation of the `info macro' command. */
static void
-info_definitions_command (char *name, int from_tty)
+info_macro_command (char *args, int from_tty)
{
struct macro_scope *ms = NULL;
- struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &ms);
+ struct cleanup *cleanup_chain;
+ char *name;
+ int show_all_macros_named = 0;
+ char *arg_start = args;
+ int processing_args = 1;
+
+ while (processing_args
+ && arg_start && *arg_start == '-' && *arg_start != '\0')
+ {
+ char *p = skip_to_space (arg_start);
+
+ if (strncmp (arg_start, "-a", p - arg_start) == 0
+ || strncmp (arg_start, "-all", p - arg_start) == 0)
+ show_all_macros_named = 1;
+ else if (strncmp (arg_start, "--", p - arg_start) == 0)
+ /* Our macro support seems rather C specific but this would
+ seem necessary for languages allowing - in macro names.
+ e.g. Scheme's (defmacro ->foo () "bar\n") */
+ processing_args = 0;
+ else
+ {
+ /* Relies on modified 'args' not making it in to history */
+ *p = '\0';
+ error (_("Unrecognized option '%s' to info macro command. "
+ "Try \"help info macro\"."), arg_start);
+ }
+
+ arg_start = skip_spaces (p);
+ }
+
+ name = arg_start;
if (! name || ! *name)
- error (_("The `info definitions' command requires a macro name as an \
-argument."));
+ error (_("You must follow the `info macro' command with the name"
+ " of the macro\n"
+ "whose definition you want to see."));
ms = default_macro_scope ();
+ cleanup_chain = make_cleanup (free_current_contents, &ms);
- if (! ms || ! ms->file || ! ms->file->table)
- error (_("GDB has no preprocessor macro information for that code."));
+ if (! ms)
+ macro_inform_no_debuginfo ();
+ else if (show_all_macros_named)
+ macro_for_each (ms->file->table, print_macro_callback, name);
+ else
+ {
+ struct macro_definition *d;
+
+ d = macro_lookup_definition (ms->file, ms->line, name);
+ if (d)
+ {
+ int line;
+ struct macro_source_file *file
+ = macro_definition_location (ms->file, ms->line, name, &line);
+
+ print_macro_definition (name, d, file, line);
+ }
+ else
+ {
+ fprintf_filtered (gdb_stdout,
+ "The symbol `%s' has no definition as a C/C++"
+ " preprocessor macro\n"
+ "at ", name);
+ show_pp_source_pos (gdb_stdout, ms->file, ms->line);
+ }
+ }
- macro_for_each (ms->file->table, print_macro_callback, name);
do_cleanups (cleanup_chain);
}
@@ -267,9 +290,10 @@
}
if (! ms || ! ms->file || ! ms->file->table)
- error (_("GDB has no preprocessor macro information for that code."));
+ macro_inform_no_debuginfo ();
+ else
+ macro_for_each_in_scope (ms->file, ms->line, print_macro_callback, NULL);
- macro_for_each_in_scope (ms->file, ms->line, print_macro_callback, NULL);
do_cleanups (cleanup_chain);
}
@@ -495,7 +519,13 @@
add_alias_cmd ("exp1", "expand-once", no_class, 1, ¯olist);
add_cmd ("macro", no_class, info_macro_command,
- _("Show the definition of MACRO, and its source location."),
+ _("Show the definition of MACRO, and it's source location.\n\
+Usage: info macro [-a|-all] [--] MACRO\n\
+Options: \n\
+ -a, --all Output all definitions of MACRO in the current compilation\
+ unit.\n\
+ -- Specify the end of arguments and the beginning of the MACRO."),
+
&infolist);
add_cmd ("macros", no_class, info_macros_command,
@@ -504,11 +534,6 @@
Usage: info macros [LINESPEC]"),
&infolist);
- add_cmd ("definitions", no_class, info_definitions_command,
- _("Show all definitions of MACRO in the current compilation unit.\n\
-Usage: info definitions MACRO"),
- &infolist);
-
add_cmd ("define", no_class, macro_define_command, _("\
Define a new C/C++ preprocessor macro.\n\
The GDB command `macro define DEFINITION' is equivalent to placing a\n\
Index: gdb/doc/ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/doc/ChangeLog,v
retrieving revision 1.1242
diff -u -r1.1242 ChangeLog
--- gdb/doc/ChangeLog 11 Nov 2011 16:56:47 -0000 1.1242
+++ gdb/doc/ChangeLog 12 Nov 2011 16:59:20 -0000
@@ -1,3 +1,8 @@
+2011-11-12 Matt Rice <ratmice@gmail.com>
+
+ * gdb.texinfo (C Preprocessor Macros): Remove info definitions.
+ Add arguments to info macro.
+
2011-11-10 Tom Tromey <tromey@redhat.com>
* gdb.texinfo (Compilation): Don't mention -gdwarf-2. Link to GCC
Index: gdb/doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.892
diff -u -r1.892 gdb.texinfo
--- gdb/doc/gdb.texinfo 11 Nov 2011 16:56:47 -0000 1.892
+++ gdb/doc/gdb.texinfo 12 Nov 2011 16:59:23 -0000
@@ -10011,9 +10011,12 @@
@cindex macro definition, showing
@cindex definition of a macro, showing
@cindex macros, from debug info
-@item info macro @var{macro}
-Show the current definition of the named @var{macro}, and describe the
-source location or compiler command-line where that definition was established.
+@item info macro [-a|-all] [--] @var{macro}
+Show the current definition or all definitions of the named @var{macro},
+and describe the source location or compiler command-line where that
+definition was established. The optional double dash is to signify the end of
+argument processing and the beginning of @var{macro} for non C-like macros where
+the macro may begin with a hyphen.
@kindex info macros
@item info macros @var{linespec}
@@ -10021,12 +10024,6 @@
by @var{linespec}, and describe the source location or compiler
command-line where those definitions were established.
-@kindex info definitions
-@item info definitions @var{macro}
-Show all definitions of the named @var{macro} that are defined in the current
-compilation unit, and describe the source location or compiler command-line
-where those definitions were established.
-
@kindex macro define
@cindex user-defined macros
@cindex defining macros interactively
Index: gdb/testsuite/ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/ChangeLog,v
retrieving revision 1.2934
diff -u -r1.2934 ChangeLog
--- gdb/testsuite/ChangeLog 11 Nov 2011 19:53:12 -0000 1.2934
+++ gdb/testsuite/ChangeLog 12 Nov 2011 16:59:25 -0000
@@ -1,3 +1,9 @@
+2011-11-12 Matt Rice <ratmice@gmail.com>
+
+ * gdb.base/info-macros.exp: Make tests for info definitions
+ test info macro. Add tests for info macro argument processing.
+ Rename a few tests.
+
2011-11-11 Keith Seitz <keiths@redhat.com>
PR gdb/12843
Index: gdb/testsuite/gdb.base/info-macros.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/info-macros.exp,v
retrieving revision 1.1
diff -u -r1.1 info-macros.exp
--- gdb/testsuite/gdb.base/info-macros.exp 21 Jul 2011 15:13:30 -0000 1.1
+++ gdb/testsuite/gdb.base/info-macros.exp 12 Nov 2011 16:59:25 -0000
@@ -34,7 +34,75 @@
return -1
}
-set test "info definitions FOO"
+# Test various error messages.
+gdb_test "info macro -- -all" \
+ "The symbol `-all' has no definition .*\r\nat .*$srcfile:\[0-9\]+" \
+ "info macro -- -all"
+gdb_test "info macro -- -all" \
+ "The symbol `-all' has no definition .*\r\nat .*$srcfile:\[0-9\]+" \
+ "info macro -- -all"
+
+gdb_test "info macro -all --" \
+ "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]" \
+ "info macro -all --"
+
+gdb_test "info macro -all --" \
+ "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]" \
+ "info macro -all --"
+
+gdb_test "info macro -all --" \
+ "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]" \
+ "info macro -all --"
+
+gdb_test "info macro --" \
+ "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]" \
+ "info macro --"
+
+gdb_test "info macro -- " \
+ "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]" \
+ "'info macro -- '"
+gdb_test "info macro -- " \
+ "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]" \
+ "'info macro -- '"
+
+gdb_test "info macro -invalid-option" \
+ "Unrecognized option.*Try \"help info macro\"\." \
+ "info macro -invalid-option 1"
+
+gdb_test "info macro -invalid-option" \
+ "Unrecognized option.*Try \"help info macro\"\." \
+ "info macro -invalid-option"
+
+gdb_test "info macro -invalid-option FOO" \
+ "Unrecognized option.*Try \"help info macro\"\." \
+ "info macro -invalid-option FOO"
+gdb_test "info macro -invalid-option FOO" \
+ "Unrecognized option.*Try \"help info macro\"\." \
+ "info macro -invalid-option FOO"
+
+# Single macro lookups.
+gdb_test "info macro -- FOO" \
+ ".*#define FOO \"hello\"" \
+ "info macro -- FOO"
+
+gdb_test "info macro -- FOO" \
+ ".*#define FOO \"hello\"" \
+ "info macro -- FOO"
+
+gdb_test "info macro -- FOO" \
+ ".*#define FOO \"hello\"" \
+ "info macro -- FOO"
+
+gdb_test "info macro FOO" \
+ ".*#define FOO \"hello\"" \
+ "info macro FOO"
+
+gdb_test "info macro FOO" \
+ ".*#define FOO \"hello\"" \
+ "info macro FOO"
+
+# Multiple macro lookups.
+set test "info macro -a FOO"
set r1 ".*#define FOO \"hello\""
set r2 ".*#define FOO \" \""
set r3 ".*#define FOO \"world\""
@@ -42,6 +110,21 @@
set testname "$test 1"
gdb_test "$test" "$r1$r2$r3$r4" "$testname"
+set test "info macro -a -- FOO"
+set testname "$test 1"
+gdb_test "$test" "$r1$r2$r3$r4" "$testname"
+
+set test "info macro -all -- FOO"
+set testname "$test 1"
+gdb_test "$test" "$r1$r2$r3$r4" "$testname"
+
+set test "info macro -a -- FOO"
+set testname "$test"
+gdb_test "$test" "$r1$r2$r3$r4" "$testname"
+
+set test "info macro -a -- FOO"
+set testname "$test"
+gdb_test "$test" "$r1$r2$r3$r4" "$testname"
set test "info macros"
set r1 ".*#define FOO \"hello\""
@@ -68,7 +151,7 @@
set r2 ".*#define ONE"
set r3 ".*#define TWO"
set r4 ".*\r\n$gdb_prompt"
-set testname "$test 4"
+set testname "$test 3"
gdb_test_multiple "$test" $testname {
-re ".*#define THREE.*\r\n$gdb_prompt" {
fail $testname
@@ -113,8 +196,8 @@
set r2 ".*#define ONE"
set r3 ".*#define TWO."
set r4 ".*\r\n$gdb_prompt"
-set testname "$test 5"
set test "info macros"
+set testname "$test 5"
gdb_test_multiple "$test" $test {
-re ".*#define THREE.*\r\n$gdb_prompt" {
fail $testname
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Rename "info definitions"?
2011-11-12 17:03 ` Matt Rice
@ 2011-11-12 17:09 ` Matt Rice
0 siblings, 0 replies; 17+ messages in thread
From: Matt Rice @ 2011-11-12 17:09 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches
On Sat, Nov 12, 2011 at 9:03 AM, Matt Rice <ratmice@gmail.com> wrote:
> On Fri, Oct 14, 2011 at 1:23 PM, Tom Tromey <tromey@redhat.com> wrote:
>
>> The code bits are ok. Thanks.
>
> sorry for the delay, attached is what I commited,
> (I missed a change from Eli's requested changes),
> and noticed a duplicate and a misnamed test.
>
Forgot to mention... The NEWS file text i had written didn't really
work well with changes since. (explaining one new command while not
explaining others). So I removed the explaination. Hopefully that is
alright.
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2011-11-12 17:09 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-21 19:34 Rename "info definitions"? Doug Evans
2011-09-21 20:28 ` Matt Rice
2011-09-23 17:38 ` Doug Evans
2011-09-29 2:16 ` Matt Rice
2011-09-29 7:20 ` Eli Zaretskii
2011-09-29 10:55 ` Pedro Alves
2011-09-29 12:41 ` Matt Rice
2011-09-29 13:28 ` Pedro Alves
2011-09-29 13:37 ` Pedro Alves
2011-09-29 13:56 ` Matt Rice
2011-09-29 14:01 ` Pedro Alves
2011-10-03 21:18 ` Matt Rice
2011-10-04 16:51 ` Tom Tromey
2011-10-05 0:31 ` Matt Rice
2011-10-14 20:23 ` Tom Tromey
2011-11-12 17:03 ` Matt Rice
2011-11-12 17:09 ` Matt Rice
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox