diff options
author | Tom Tromey <tromey@redhat.com> | 2008-07-18 20:55:33 +0000 |
---|---|---|
committer | Tom Tromey <tromey@redhat.com> | 2008-07-18 20:55:33 +0000 |
commit | d7d9f01ea18f14a9a1574042bd65dd73f9b6b2b8 (patch) | |
tree | 350b57eb105730c6e52b961f7c55b0821f6b222e /gdb/macroscope.c | |
parent | a9dc948127c2cb5127cec5ca87dbc19f17dd16cf (diff) | |
download | gdb-d7d9f01ea18f14a9a1574042bd65dd73f9b6b2b8.zip gdb-d7d9f01ea18f14a9a1574042bd65dd73f9b6b2b8.tar.gz gdb-d7d9f01ea18f14a9a1574042bd65dd73f9b6b2b8.tar.bz2 |
gdb
PR gdb/855:
* NEWS: Add entry for macro commands.
* Makefile.in (macrocmd.o): Add gdb_string.h.
* macroscope.h (user_macro_scope): Declare.
(default_macro_scope): Update documentation.
(macro_user_macros): Declare.
* c-lang.c (c_preprocess_and_parse): Always attempt macro lookup.
Use user_macro_scope.
(null_macro_lookup): Remove.
* macrotab.h (macro_callback_fn): Declare.
(macro_for_each): Likewise.
(macro_allow_redefinitions): Likewise.
* macrotab.c (foreach_macro): New function
(macro_for_each): Likewise.
(struct macro_table) <redef_ok>: New field.
(macro_allow_redefinitions): New function.
(new_macro_table): Update.
(macro_define_function): Likewise.
(macro_define_object): Likewise.
* macroscope.c (user_macro_scope): New function.
(default_macro_scope): Use it.
(macro_user_macros): New global.
(standard_macro_lookup): Look in macro_user_macros.
(_initialize_macroscope): New function.
* macroexp.h (macro_is_whitespace, macro_is_digit,
macro_is_identifier_nondigit): Declare.
* macroexp.c (macro_is_whitespace): Rename. No longer static.
(macro_is_digit): Likewise.
(macro_is_identifier_nondigit): Likewise.
(get_identifier): Update.
(get_pp_number): Likewise.
(get_token): Likewise.
* macrocmd.c (skip_ws): New function.
(extract_identifier): Likewise.
(free_macro_definition_ptr): Likewise.
(user_macros): Remove.
(macro_define_command): Implement.
(_initialize_macrocmd): Update.
(macro_undef_command): Implement.
(print_one_macro): New function.
(macro_list_command): Implement.
gdb/doc
* gdb.texinfo (Macros): Update. Use @code rather than @command.
gdb/testsuite
* gdb.base/macscp.exp: Add macro tests.
Diffstat (limited to 'gdb/macroscope.c')
-rw-r--r-- | gdb/macroscope.c | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/gdb/macroscope.c b/gdb/macroscope.c index 7383986..ef334b7 100644 --- a/gdb/macroscope.c +++ b/gdb/macroscope.c @@ -27,6 +27,13 @@ #include "inferior.h" #include "complaints.h" +/* A table of user-defined macros. Unlike the macro tables used for + symtabs, this one uses xmalloc for all its allocation, not an + obstack, and it doesn't bcache anything; it just xmallocs things. So + it's perfectly possible to remove things from this, or redefine + things. */ +struct macro_table *macro_user_macros; + struct macro_scope * sal_macro_scope (struct symtab_and_line sal) @@ -78,6 +85,16 @@ sal_macro_scope (struct symtab_and_line sal) struct macro_scope * +user_macro_scope (void) +{ + struct macro_scope *ms; + ms = XNEW (struct macro_scope); + ms->file = macro_main (macro_user_macros); + ms->line = -1; + return ms; +} + +struct macro_scope * default_macro_scope (void) { struct symtab_and_line sal; @@ -110,7 +127,11 @@ default_macro_scope (void) sal.line = cursal.line; } - return sal_macro_scope (sal); + ms = sal_macro_scope (sal); + if (! ms) + ms = user_macro_scope (); + + return ms; } @@ -121,6 +142,20 @@ struct macro_definition * standard_macro_lookup (const char *name, void *baton) { struct macro_scope *ms = (struct macro_scope *) baton; + struct macro_definition *result; + + /* Give user-defined macros priority over all others. */ + result = macro_lookup_definition (macro_main (macro_user_macros), -1, name); + if (! result) + result = macro_lookup_definition (ms->file, ms->line, name); + return result; +} + - return macro_lookup_definition (ms->file, ms->line, name); +void +_initialize_macroscope (void) +{ + macro_user_macros = new_macro_table (0, 0); + macro_set_main (macro_user_macros, "<user-defined>"); + macro_allow_redefinitions (macro_user_macros); } |