44 gdb_puts (
"GDB has no preprocessor macro information for that code.\n");
56 error (_(
"You must follow the `macro expand' command with the"
64 gdb::unique_xmalloc_ptr<char> expanded =
macro_expand (exp, *ms);
84 error (_(
"You must follow the `macro expand-once' command with"
86 "you want to expand."));
117 while (file->included_by)
120 gdb_puts (_(
" included at "), stream);
122 gdb_printf (stream,
":%d\n", file->included_at_line);
123 file = file->included_by;
153 for (i = 0; i < d->
argc; i++)
172 gdb::unique_xmalloc_ptr<struct macro_scope> ms;
174 int show_all_macros_named = 0;
175 const char *arg_start = args;
176 int processing_args = 1;
178 while (processing_args
179 && arg_start && *arg_start ==
'-' && *arg_start !=
'\0')
181 const char *p = skip_to_space (arg_start);
183 if (strncmp (arg_start,
"-a", p - arg_start) == 0
184 || strncmp (arg_start,
"-all", p - arg_start) == 0)
185 show_all_macros_named = 1;
186 else if (strncmp (arg_start,
"--", p - arg_start) == 0)
194 arg_start = skip_spaces (p);
200 error (_(
"You must follow the `info macro' command with the name"
202 "whose definition you want to see."));
208 else if (show_all_macros_named)
214 if (strcmp (name, macro_name) == 0)
215 print_macro_definition (name, macro, source, line);
232 gdb_printf (
"The symbol `%s' has no definition as a C/C++"
233 " preprocessor macro\n"
244 gdb::unique_xmalloc_ptr<struct macro_scope> ms;
250 std::vector<symtab_and_line> sals
257 if (! ms || ! ms->file || ! ms->file->table)
280static gdb::unique_xmalloc_ptr<char>
284 const char *p = *expp;
287 if (is_parameter && startswith (p,
"..."))
301 if (is_parameter && startswith (p,
"..."))
305 result = (
char *)
xmalloc (len + 1);
306 memcpy (result, *expp, len);
309 return gdb::unique_xmalloc_ptr<char> (result);
327 for (i = 0; i <
argc; ++i)
340 error (_(
"usage: macro define NAME[(ARGUMENT-LIST)] [REPLACEMENT-LIST]"));
345 error (_(
"Invalid macro name."));
350 char **argv = XNEWVEC (
char *, alloced);
354 new_macro.
argv = (
const char *
const *) argv;
364 if (new_macro.
argc == alloced)
367 argv = (
char **)
xrealloc (argv, alloced *
sizeof (
char *));
369 new_macro.
argv = (
const char *
const *) argv;
372 if (! argv[new_macro.
argc])
373 error (_(
"Macro is missing an argument."));
376 for (i = new_macro.
argc - 2; i >= 0; --i)
378 if (! strcmp (argv[i], argv[new_macro.
argc - 1]))
379 error (_(
"Two macro arguments with identical names."));
388 else if (*exp !=
')')
389 error (_(
"',' or ')' expected at end of macro arguments."));
396 new_macro.
argc, (
const char **) new_macro.
argv,
412 error (_(
"usage: macro undef NAME"));
417 error (_(
"Invalid macro name."));
432 for (i = 0; i < macro->
argc; ++i)
456 _(
"Prefix for commands dealing with C preprocessor macros."),
461Fully expand any C/C++ preprocessor macro invocations in EXPRESSION.\n\
462Show the expanded expression."),
468Expand C/C++ preprocessor macro invocations appearing directly in EXPRESSION.\n\
469Show the expanded expression.\n\
471This command differs from `macro expand' in that it only expands macro\n\
472invocations that appear directly in EXPRESSION; if expanding a macro\n\
473introduces further macro invocations, those are left unexpanded.\n\
475`macro expand-once' helps you see how a particular macro expands,\n\
476whereas `macro expand' shows you how all the macros involved in an\n\
477expression work together to yield a pre-processed expression."),
482 _(
"Show the definition of MACRO, and it's source location.\n\
483Usage: info macro [-a|-all] [--] MACRO\n\
485 -a, --all Output all definitions of MACRO in the current compilation\
487 -- Specify the end of arguments and the beginning of the MACRO."));
490 _(
"Show the definitions of all macros at LINESPEC, or the current \
492Usage: info macros [LINESPEC]"));
495Define a new C/C++ preprocessor macro.\n\
496The GDB command `macro define DEFINITION' is equivalent to placing a\n\
497preprocessor directive of the form `#define DEFINITION' such that the\n\
498definition is visible in all the inferior's source files.\n\
500 (gdb) macro define PI (3.1415926)\n\
501 (gdb) macro define MIN(x,y) ((x) < (y) ? (x) : (y))"),
505Remove the definition of the C/C++ preprocessor macro with the given name."),
509 _(
"List all the macros defined using the `macro define' command."),
void * xrealloc(void *ptr, size_t size)
ui_file_style style() const
struct cmd_list_element * cmdlist
struct cmd_list_element * add_alias_cmd(const char *name, cmd_list_element *target, enum command_class theclass, int abbrev_flag, struct cmd_list_element **list)
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
struct cmd_list_element * add_basic_prefix_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **subcommands, int allow_unknown, struct cmd_list_element **list)
struct cmd_list_element * add_info(const char *name, cmd_simple_func_ftype *fun, const char *doc)
cli_style_option file_name_style
void report_unrecognized_option_error(const char *command, const char *args)
std::vector< symtab_and_line > decode_line_with_current_source(const char *string, int flags)
void _initialize_macrocmd()
static void info_macros_command(const char *args, int from_tty)
static gdb::unique_xmalloc_ptr< char > extract_identifier(const char **expp, int is_parameter)
static void print_macro_definition(const char *name, const struct macro_definition *d, struct macro_source_file *file, int line)
static void macro_define_command(const char *exp, int from_tty)
static void macro_expand_command(const char *exp, int from_tty)
static void show_pp_source_pos(struct ui_file *stream, struct macro_source_file *file, int line)
static void macro_expand_once_command(const char *exp, int from_tty)
static void macro_list_command(const char *exp, int from_tty)
static struct cmd_list_element * macrolist
static void macro_inform_no_debuginfo(void)
static void print_one_macro(const char *name, const struct macro_definition *macro, struct macro_source_file *source, int line)
static void macro_undef_command(const char *exp, int from_tty)
static void info_macro_command(const char *args, int from_tty)
static void skip_ws(const char **expp)
int macro_is_identifier_nondigit(int c)
gdb::unique_xmalloc_ptr< char > macro_expand(const char *source, const macro_scope &scope)
int macro_is_digit(int c)
gdb::unique_xmalloc_ptr< char > macro_expand_once(const char *source, const macro_scope &scope)
int macro_is_whitespace(int c)
gdb::unique_xmalloc_ptr< struct macro_scope > sal_macro_scope(struct symtab_and_line sal)
gdb::unique_xmalloc_ptr< struct macro_scope > default_macro_scope(void)
struct macro_table * macro_user_macros
void macro_for_each(struct macro_table *table, gdb::function_view< macro_callback_fn > fn)
struct macro_definition * macro_lookup_definition(struct macro_source_file *source, int line, const char *name)
void macro_define_object(struct macro_source_file *source, int line, const char *name, const char *replacement)
struct macro_source_file * macro_main(struct macro_table *t)
struct macro_source_file * macro_definition_location(struct macro_source_file *source, int line, const char *name, int *definition_line)
std::string macro_source_fullname(struct macro_source_file *file)
void macro_for_each_in_scope(struct macro_source_file *file, int line, gdb::function_view< macro_callback_fn > fn)
void macro_define_function(struct macro_source_file *source, int line, const char *name, int argc, const char **argv, const char *replacement)
void macro_undef(struct macro_source_file *source, int line, const char *name)
struct macro_table * table
__extension__ enum macro_kind kind
temporary_macro_definition()
~temporary_macro_definition()
static styled_string_s * styled_string(const ui_file_style &style, const char *str, styled_string_s &&tmp={})
void gdb_printf(struct ui_file *stream, const char *format,...)
void fputs_styled(const char *linebuffer, const ui_file_style &style, struct ui_file *stream)
void gdb_puts(const char *linebuffer, struct ui_file *stream)