21#include "gdbsupport/gdb_obstack.h"
22#include "gdbsupport/pathstuff.h"
23#include "splay-tree.h"
122 memcpy (copy, addr, len);
134 return (
const char *)
macro_bcache (t, s, strlen (s) + 1);
193 for (depth = 0; file->included_by; depth++)
194 file = file->included_by;
253 while (depth1 > depth2)
260 while (depth2 > depth1)
270 while (file1 != file2)
286 gdb_assert (file1 && file2);
295 gdb_assert (! included1 || ! included2);
307 return line1 - line2;
324 int names = strcmp (key->
name,
name);
338 splay_tree_key untyped_key2)
358 memset (k, 0,
sizeof (*k));
392 memset (
f, 0,
sizeof (*
f));
408 for (child = src->
includes; child; child = next_child)
453 const char *included)
461 for (link = &source->includes;
480 complaint (_(
"both `%s' and `%s' allegedly #included at %s:%d"),
481 included, link_fullname.c_str (), source_fullname.c_str (),
511 if (filename_cmp (
name, source->filename) == 0)
520 for (child = source->includes; child; child = child->
next_included)
529 if (! best || result_depth < best_depth)
532 best_depth = result_depth;
557 memset (d, 0,
sizeof (*d));
566 const char **cached_argv;
567 int cached_argv_size =
argc *
sizeof (*cached_argv);
570 cached_argv = (
const char **) alloca (cached_argv_size);
571 for (i = 0; i <
argc; i++)
575 d->
argv = ((
const char *
const *)
611 for (i = 0; i < d->
argc; i++)
623static splay_tree_node
635 query.start_file = file;
636 query.start_line = line;
637 query.end_file = NULL;
648 splay_tree_node pred = splay_tree_predecessor (t->
definitions,
649 (splay_tree_key) &
query);
657 if (strcmp (found->
name,
name) == 0)
687 int argc,
const char **argv,
688 const char *replacement)
718 for (i = 0; i <
argc; i++)
719 if (strcmp (
argv[i], found_def->
argv[i]))
727 std::string found_key_fullname
729 complaint (_(
"macro `%s' redefined at %s:%d; "
730 "original definition at %s:%d"),
731 name, source_fullname.c_str (), line,
732 found_key_fullname.c_str (),
779 splay_tree_insert (t->
definitions, (splay_tree_key) k, (splay_tree_value) d);
841 splay_tree_remove (source->table->definitions, n->key);
855 complaint (_(
"macro '%s' is #undefined twice,"
856 " at %s:%d and %s:%d"),
857 name, source_fullname.c_str (), line,
858 key_fullname.c_str (),
874 complaint (_(
"no definition for macro `%s' in scope to #undef at %s:%d"),
875 name, source->filename, line);
886 static gdb::unique_xmalloc_ptr<char> saved_expansion;
897 saved_expansion = xstrprintf (
"%d", line);
907 int line,
const char *
name)
926 int *definition_line)
947 gdb::function_view<macro_callback_fn>
fn;
971 gdb::function_view<macro_callback_fn> fn)
1006 gdb::function_view<macro_callback_fn> fn)
1034 memset (t, 0,
sizeof (*t));
1067 const char *comp_dir = NULL;
1069 if (file->table->compunit_symtab != NULL)
1070 comp_dir = file->table->compunit_symtab->dirname ();
1072 if (comp_dir == NULL || IS_ABSOLUTE_PATH (file->filename))
1073 return file->filename;
1075 return path_join (comp_dir, file->filename);
#define complaint(FMT,...)
gdb::unique_xmalloc_ptr< char > macro_stringify(const char *str)
void macro_for_each(struct macro_table *table, gdb::function_view< macro_callback_fn > fn)
static const char * macro_bcache_str(struct macro_table *t, const char *s)
static void macro_tree_delete_value(void *untyped_definition)
struct macro_definition * macro_lookup_definition(struct macro_source_file *source, int line, const char *name)
struct macro_source_file * macro_lookup_inclusion(struct macro_source_file *source, const char *name)
void macro_define_object(struct macro_source_file *source, int line, const char *name, const char *replacement)
static struct macro_key * new_macro_key(struct macro_table *t, const char *name, struct macro_source_file *file, int line)
static int foreach_macro_in_scope(splay_tree_node node, void *info)
static void * macro_alloc(int size, struct macro_table *t)
static void macro_define_object_internal(struct macro_source_file *source, int line, const char *name, const char *replacement, enum macro_special_kind special_kind)
struct macro_source_file * macro_set_main(struct macro_table *t, const char *filename)
static int inclusion_depth(struct macro_source_file *file)
struct macro_table * new_macro_table(struct obstack *obstack, gdb::bcache *b, struct compunit_symtab *cust)
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)
static void macro_define_internal(struct macro_source_file *source, int line, const char *name, enum macro_kind kind, int argc, const char **argv, const char *replacement)
static struct macro_source_file * new_source_file(struct macro_table *t, const char *filename)
static struct macro_key * check_for_redefinition(struct macro_source_file *source, int line, const char *name, enum macro_kind kind, int argc, const char **argv, const char *replacement)
struct macro_source_file * macro_include(struct macro_source_file *source, int line, const char *included)
static int foreach_macro(splay_tree_node node, void *arg)
static struct macro_definition * fixup_definition(const char *filename, int line, struct macro_definition *def)
static splay_tree_node find_definition(const char *name, struct macro_source_file *file, int line)
void free_macro_table(struct macro_table *table)
static struct macro_definition * new_macro_definition(struct macro_table *t, enum macro_kind kind, int argc, const char **argv, const char *replacement)
static int compare_locations(struct macro_source_file *file1, int line1, struct macro_source_file *file2, int line2)
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_define_special(struct macro_table *table)
static const void * macro_bcache(struct macro_table *t, const void *addr, int len)
static int key_compare(struct macro_key *key, const char *name, struct macro_source_file *file, int line)
static void macro_tree_delete_key(void *untyped_key)
static void free_macro_source_file(struct macro_source_file *src)
static void macro_bcache_free(struct macro_table *t, void *obj)
void macro_allow_redefinitions(struct macro_table *t)
static int macro_tree_compare(splay_tree_key untyped_key1, splay_tree_key untyped_key2)
static void macro_free(void *object, struct macro_table *t)
void macro_undef(struct macro_source_file *source, int line, const char *name)
const void * insert(const void *addr, int length, bool *added=nullptr)
struct macro_table * table
__extension__ enum macro_kind kind
struct macro_source_file * file
gdb::function_view< macro_callback_fn > fn
struct macro_source_file * end_file
struct macro_source_file * start_file
struct macro_table * table
struct macro_source_file * includes
struct macro_source_file * included_by
struct macro_table * table
struct macro_source_file * next_included
struct compunit_symtab * compunit_symtab
struct macro_source_file * main_source
int query(const char *ctlstr,...)