mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-01-23 08:23:50 +08:00
Move info definitions command to an info macro option.
This commit is contained in:
parent
30fc0b956b
commit
71eba9c25e
@ -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
|
||||
|
9
gdb/NEWS
9
gdb/NEWS
@ -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 @@ 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.
|
||||
|
||||
collect[/s] EXPRESSIONS
|
||||
The tracepoint collect command now takes an optional modifier "/s"
|
||||
that directs it to dereference pointer-to-character types and
|
||||
|
@ -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
|
||||
|
@ -10011,9 +10011,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}
|
||||
@ -10021,12 +10024,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
|
||||
|
143
gdb/macrocmd.c
143
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\
|
||||
|
@ -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
|
||||
|
@ -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 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 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\""
|
||||
@ -68,7 +151,7 @@ set r1 ".*#define FOO \" \""
|
||||
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 r1 ".*#define FOO \" \""
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user