static struct symbol * iter_name_first_hashed (const struct dictionary *dict, const char *name, struct dict_iterator *iterator) { unsigned int hash_index = msymbol_hash_iw (name) % DICT_HASHED_NBUCKETS (dict); struct symbol *sym; DICT_ITERATOR_DICT (iterator) = dict; /* Loop through the symbols in the given bucket, breaking when SYM first matches. If SYM never matches, it will be set to NULL; either way, we have the right return value. */ for (sym = DICT_HASHED_BUCKET (dict, hash_index); sym != NULL; sym = sym->hash_next) { /* Warning: the order of arguments to strcmp_iw matters! */ if (strcmp_iw (SYMBOL_NATURAL_NAME (sym), name) == 0) { break; } } DICT_ITERATOR_CURRENT (iterator) = sym; return sym; }
/* Using the frame specified in BATON, find the location expression describing the frame base. Return a pointer to it in START and its length in LENGTH. */ static void dwarf_expr_frame_base (void *baton, unsigned char **start, size_t * length) { /* FIXME: cagney/2003-03-26: This code should be using get_frame_base_address(), and then implement a dwarf2 specific this_base method. */ struct symbol *framefunc; struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton; framefunc = get_frame_function (debaton->frame); if (SYMBOL_OPS (framefunc) == &dwarf2_loclist_funcs) { struct dwarf2_loclist_baton *symbaton; symbaton = SYMBOL_LOCATION_BATON (framefunc); *start = find_location_expression (symbaton, length, get_frame_pc (debaton->frame)); } else { struct dwarf2_locexpr_baton *symbaton; symbaton = SYMBOL_LOCATION_BATON (framefunc); *length = symbaton->size; *start = symbaton->data; } if (*start == NULL) error ("Could not find the frame base for \"%s\".", SYMBOL_NATURAL_NAME (framefunc)); }
static void dwarf_expr_frame_base_1 (struct symbol *framefunc, CORE_ADDR pc, gdb_byte **start, size_t *length) { if (SYMBOL_LOCATION_BATON (framefunc) == NULL) *start = NULL; else if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_loclist_funcs) { struct dwarf2_loclist_baton *symbaton; symbaton = SYMBOL_LOCATION_BATON (framefunc); *start = find_location_expression (symbaton, length, pc); } else { struct dwarf2_locexpr_baton *symbaton; symbaton = SYMBOL_LOCATION_BATON (framefunc); if (symbaton != NULL) { *length = symbaton->size; *start = symbaton->data; } else *start = NULL; } if (*start == NULL) error (_("Could not find the frame base for \"%s\"."), SYMBOL_NATURAL_NAME (framefunc)); }
static PyObject * sympy_get_name (PyObject *self, void *closure) { struct symbol *symbol = NULL; SYMPY_REQUIRE_VALID (self, symbol); return PyString_FromString (SYMBOL_NATURAL_NAME (symbol)); }
static SCM gdbscm_symbol_name (SCM self) { symbol_smob *s_smob = syscm_get_valid_symbol_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); const struct symbol *symbol = s_smob->symbol; return gdbscm_scm_from_c_string (SYMBOL_NATURAL_NAME (symbol)); }
debug_print_scope (const compile_scope &scope) { for (const auto &comp: scope) { const char *symbol = (comp.bsymbol.symbol != nullptr ? SYMBOL_NATURAL_NAME (comp.bsymbol.symbol) : "<none>"); printf_unfiltered ("\tname = %s, symbol = %s\n", comp.name.c_str (), symbol); } }
static void insert_symbol_hashed (struct dictionary *dict, struct symbol *sym) { unsigned int hash_index; struct symbol **buckets = DICT_HASHED_BUCKETS (dict); hash_index = (msymbol_hash_iw (SYMBOL_NATURAL_NAME (sym)) % DICT_HASHED_NBUCKETS (dict)); sym->hash_next = buckets[hash_index]; buckets[hash_index] = sym; }
/* Describe the location of SYMBOL as an agent value in VALUE, generating any necessary bytecode in AX. */ static void loclist_tracepoint_var_ref (struct symbol * symbol, struct agent_expr * ax, struct axs_value * value) { struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol); gdb_byte *data; size_t size; data = find_location_expression (dlbaton, &size, ax->scope); if (data == NULL) error (_("Variable \"%s\" is not available."), SYMBOL_NATURAL_NAME (symbol)); dwarf2_tracepoint_var_ref (symbol, ax, value, data, size); }
static struct symbol * search_symbol_list (const char *name, int num, struct symbol **syms) { int i; /* Maybe we should store a dictionary in here instead. */ for (i = 0; i < num; ++i) { if (strcmp (name, SYMBOL_NATURAL_NAME (syms[i])) == 0) return syms[i]; } return NULL; }
/* Using the frame specified in BATON, find the location expression describing the frame base. Return a pointer to it in START and its length in LENGTH. */ static void dwarf_expr_frame_base (void *baton, gdb_byte **start, size_t * length) { /* FIXME: cagney/2003-03-26: This code should be using get_frame_base_address(), and then implement a dwarf2 specific this_base method. */ struct symbol *framefunc; struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton; /* Use block_linkage_function, which returns a real (not inlined) function, instead of get_frame_function, which may return an inlined function. */ framefunc = block_linkage_function (get_frame_block (debaton->frame, NULL)); /* If we found a frame-relative symbol then it was certainly within some function associated with a frame. If we can't find the frame, something has gone wrong. */ gdb_assert (framefunc != NULL); if (SYMBOL_LOCATION_BATON (framefunc) == NULL) *start = NULL; else if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_loclist_funcs) { struct dwarf2_loclist_baton *symbaton; struct frame_info *frame = debaton->frame; symbaton = SYMBOL_LOCATION_BATON (framefunc); *start = find_location_expression (symbaton, length, get_frame_address_in_block (frame)); } else { struct dwarf2_locexpr_baton *symbaton; symbaton = SYMBOL_LOCATION_BATON (framefunc); if (symbaton != NULL) { *length = symbaton->size; *start = symbaton->data; } else *start = NULL; } if (*start == NULL) error (_("Could not find the frame base for \"%s\"."), SYMBOL_NATURAL_NAME (framefunc)); }
/* Return the value of SYMBOL in FRAME using the DWARF-2 expression evaluator to calculate the location. */ static struct value * loclist_read_variable (struct symbol *symbol, struct frame_info *frame) { struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol); struct value *val; unsigned char *data; size_t size; data = find_location_expression (dlbaton, &size, frame ? get_frame_pc (frame) : 0); if (data == NULL) error ("Variable \"%s\" is not available.", SYMBOL_NATURAL_NAME (symbol)); val = dwarf2_evaluate_loc_desc (symbol, frame, data, size, dlbaton->objfile); return val; }
static struct symbol * iter_name_next_hashed (const char *name, struct dict_iterator *iterator) { struct symbol *next; for (next = DICT_ITERATOR_CURRENT (iterator)->hash_next; next != NULL; next = next->hash_next) { if (strcmp_iw (SYMBOL_NATURAL_NAME (next), name) == 0) break; } DICT_ITERATOR_CURRENT (iterator) = next; return next; }
static void overload_list_add_symbol (struct symbol *sym, const char *oload_name) { int newsize; int i; char *sym_name; /* If there is no type information, we can't do anything, so skip */ if (SYMBOL_TYPE (sym) == NULL) return; /* skip any symbols that we've already considered. */ for (i = 0; i < sym_return_val_index; ++i) if (strcmp (SYMBOL_LINKAGE_NAME (sym), SYMBOL_LINKAGE_NAME (sym_return_val[i])) == 0) return; /* Get the demangled name without parameters */ sym_name = cp_remove_params (SYMBOL_NATURAL_NAME (sym)); if (!sym_name) return; /* skip symbols that cannot match */ if (strcmp (sym_name, oload_name) != 0) { xfree (sym_name); return; } xfree (sym_name); /* We have a match for an overload instance, so add SYM to the current list * of overload instances */ if (sym_return_val_index + 3 > sym_return_val_size) { newsize = (sym_return_val_size *= 2) * sizeof (struct symbol *); sym_return_val = (struct symbol **) xrealloc ((char *) sym_return_val, newsize); } sym_return_val[sym_return_val_index++] = sym; sym_return_val[sym_return_val_index] = NULL; }
static struct symbol * iter_name_next_linear (const char *name, struct dict_iterator *iterator) { const struct dictionary *dict = DICT_ITERATOR_DICT (iterator); int i, nsyms = DICT_LINEAR_NSYMS (dict); struct symbol *sym, *retval = NULL; for (i = DICT_ITERATOR_INDEX (iterator) + 1; i < nsyms; ++i) { sym = DICT_LINEAR_SYM (dict, i); if (strcmp_iw (SYMBOL_NATURAL_NAME (sym), name) == 0) { retval = sym; break; } } DICT_ITERATOR_INDEX (iterator) = i; return retval; }
static void convert_one_symbol (struct compile_c_instance *context, struct symbol *sym, int is_global, int is_local) { gcc_type sym_type; const char *filename = symbol_symtab (sym)->filename; unsigned short line = SYMBOL_LINE (sym); error_symbol_once (context, sym); if (SYMBOL_CLASS (sym) == LOC_LABEL) sym_type = 0; else sym_type = convert_type (context, SYMBOL_TYPE (sym)); if (SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN) { /* Binding a tag, so we don't need to build a decl. */ C_CTX (context)->c_ops->tagbind (C_CTX (context), SYMBOL_NATURAL_NAME (sym), sym_type, filename, line); } else { gcc_decl decl; enum gcc_c_symbol_kind kind; CORE_ADDR addr = 0; char *symbol_name = NULL; switch (SYMBOL_CLASS (sym)) { case LOC_TYPEDEF: kind = GCC_C_SYMBOL_TYPEDEF; break; case LOC_LABEL: kind = GCC_C_SYMBOL_LABEL; addr = SYMBOL_VALUE_ADDRESS (sym); break; case LOC_BLOCK: kind = GCC_C_SYMBOL_FUNCTION; addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)); if (is_global && TYPE_GNU_IFUNC (SYMBOL_TYPE (sym))) addr = gnu_ifunc_resolve_addr (target_gdbarch (), addr); break; case LOC_CONST: if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_ENUM) { /* Already handled by convert_enum. */ return; } C_CTX (context)->c_ops->build_constant (C_CTX (context), sym_type, SYMBOL_NATURAL_NAME (sym), SYMBOL_VALUE (sym), filename, line); return; case LOC_CONST_BYTES: error (_("Unsupported LOC_CONST_BYTES for symbol \"%s\"."), SYMBOL_PRINT_NAME (sym)); case LOC_UNDEF: internal_error (__FILE__, __LINE__, _("LOC_UNDEF found for \"%s\"."), SYMBOL_PRINT_NAME (sym)); case LOC_COMMON_BLOCK: error (_("Fortran common block is unsupported for compilation " "evaluaton of symbol \"%s\"."), SYMBOL_PRINT_NAME (sym)); case LOC_OPTIMIZED_OUT: error (_("Symbol \"%s\" cannot be used for compilation evaluation " "as it is optimized out."), SYMBOL_PRINT_NAME (sym)); case LOC_COMPUTED: if (is_local) goto substitution; /* Probably TLS here. */ warning (_("Symbol \"%s\" is thread-local and currently can only " "be referenced from the current thread in " "compiled code."), SYMBOL_PRINT_NAME (sym)); /* FALLTHROUGH */ case LOC_UNRESOLVED: /* 'symbol_name' cannot be used here as that one is used only for local variables from compile_dwarf_expr_to_c. Global variables can be accessed by GCC only by their address, not by their name. */ { struct value *val; struct frame_info *frame = NULL; if (symbol_read_needs_frame (sym)) { frame = get_selected_frame (NULL); if (frame == NULL) error (_("Symbol \"%s\" cannot be used because " "there is no selected frame"), SYMBOL_PRINT_NAME (sym)); } val = read_var_value (sym, frame); if (VALUE_LVAL (val) != lval_memory) error (_("Symbol \"%s\" cannot be used for compilation " "evaluation as its address has not been found."), SYMBOL_PRINT_NAME (sym)); kind = GCC_C_SYMBOL_VARIABLE; addr = value_address (val); } break; case LOC_REGISTER: case LOC_ARG: case LOC_REF_ARG: case LOC_REGPARM_ADDR: case LOC_LOCAL: substitution: kind = GCC_C_SYMBOL_VARIABLE; symbol_name = symbol_substitution_name (sym); break; case LOC_STATIC: kind = GCC_C_SYMBOL_VARIABLE; addr = SYMBOL_VALUE_ADDRESS (sym); break; case LOC_FINAL_VALUE: default: gdb_assert_not_reached ("Unreachable case in convert_one_symbol."); } /* Don't emit local variable decls for a raw expression. */ if (context->base.scope != COMPILE_I_RAW_SCOPE || symbol_name == NULL) { decl = C_CTX (context)->c_ops->build_decl (C_CTX (context), SYMBOL_NATURAL_NAME (sym), kind, sym_type, symbol_name, addr, filename, line); C_CTX (context)->c_ops->bind (C_CTX (context), decl, is_global); } xfree (symbol_name); } }
static char * symbol_substitution_name (struct symbol *sym) { return concat ("__", SYMBOL_NATURAL_NAME (sym), "_ptr", (char *) NULL); }
struct block_symbol cp_lookup_symbol_imports_or_template (const char *scope, const char *name, const struct block *block, const domain_enum domain) { struct symbol *function = BLOCK_FUNCTION (block); struct block_symbol result; if (symbol_lookup_debug) { fprintf_unfiltered (gdb_stdlog, "cp_lookup_symbol_imports_or_template" " (%s, %s, %s, %s)\n", scope, name, host_address_to_string (block), domain_name (domain)); } if (function != NULL && SYMBOL_LANGUAGE (function) == language_cplus) { /* Search the function's template parameters. */ if (SYMBOL_IS_CPLUS_TEMPLATE_FUNCTION (function)) { struct template_symbol *templ = (struct template_symbol *) function; struct symbol *sym = search_symbol_list (name, templ->n_template_arguments, templ->template_arguments); if (sym != NULL) { if (symbol_lookup_debug) { fprintf_unfiltered (gdb_stdlog, "cp_lookup_symbol_imports_or_template" " (...) = %s\n", host_address_to_string (sym)); } return (struct block_symbol) {sym, block}; } } /* Search the template parameters of the function's defining context. */ if (SYMBOL_NATURAL_NAME (function)) { struct type *context; char *name_copy = xstrdup (SYMBOL_NATURAL_NAME (function)); struct cleanup *cleanups = make_cleanup (xfree, name_copy); const struct language_defn *lang = language_def (language_cplus); struct gdbarch *arch = symbol_arch (function); const struct block *parent = BLOCK_SUPERBLOCK (block); struct symbol *sym; while (1) { unsigned int prefix_len = cp_entire_prefix_len (name_copy); if (prefix_len == 0) context = NULL; else { name_copy[prefix_len] = '\0'; context = lookup_typename (lang, arch, name_copy, parent, 1); } if (context == NULL) break; sym = search_symbol_list (name, TYPE_N_TEMPLATE_ARGUMENTS (context), TYPE_TEMPLATE_ARGUMENTS (context)); if (sym != NULL) { do_cleanups (cleanups); if (symbol_lookup_debug) { fprintf_unfiltered (gdb_stdlog, "cp_lookup_symbol_imports_or_template (...) = %s\n", host_address_to_string (sym)); } return (struct block_symbol) {sym, parent}; } } do_cleanups (cleanups); } }
/* Print a list of the locals or the arguments for the currently selected frame. If the argument passed is 0, printonly the names of the variables, if an argument of 1 is passed, print the values as well. */ static void list_args_or_locals (int locals, int values, struct frame_info *fi) { struct block *block; struct symbol *sym; struct dict_iterator iter; int nsyms; struct cleanup *cleanup_list; static struct ui_stream *stb = NULL; struct type *type; stb = ui_out_stream_new (uiout); block = get_frame_block (fi, 0); cleanup_list = make_cleanup_ui_out_list_begin_end (uiout, locals ? "locals" : "args"); while (block != 0) { ALL_BLOCK_SYMBOLS (block, iter, sym) { int print_me = 0; switch (SYMBOL_CLASS (sym)) { default: case LOC_UNDEF: /* catches errors */ case LOC_CONST: /* constant */ case LOC_TYPEDEF: /* local typedef */ case LOC_LABEL: /* local label */ case LOC_BLOCK: /* local function */ case LOC_CONST_BYTES: /* loc. byte seq. */ case LOC_UNRESOLVED: /* unresolved static */ case LOC_OPTIMIZED_OUT: /* optimized out */ print_me = 0; break; case LOC_ARG: /* argument */ case LOC_REF_ARG: /* reference arg */ case LOC_REGPARM: /* register arg */ case LOC_REGPARM_ADDR: /* indirect register arg */ case LOC_LOCAL_ARG: /* stack arg */ case LOC_BASEREG_ARG: /* basereg arg */ case LOC_COMPUTED_ARG: /* arg with computed location */ if (!locals) print_me = 1; break; case LOC_LOCAL: /* stack local */ case LOC_BASEREG: /* basereg local */ case LOC_STATIC: /* static */ case LOC_REGISTER: /* register */ case LOC_COMPUTED: /* computed location */ if (locals) print_me = 1; break; } if (print_me) { struct cleanup *cleanup_tuple = NULL; struct symbol *sym2; if (values != PRINT_NO_VALUES) cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (uiout, NULL); ui_out_field_string (uiout, "name", SYMBOL_PRINT_NAME (sym)); if (!locals) sym2 = lookup_symbol (SYMBOL_NATURAL_NAME (sym), block, VAR_DOMAIN, (int *) NULL, (struct symtab **) NULL); else sym2 = sym; switch (values) { case PRINT_SIMPLE_VALUES: type = check_typedef (sym2->type); type_print (sym2->type, "", stb->stream, -1); ui_out_field_stream (uiout, "type", stb); if (TYPE_CODE (type) != TYPE_CODE_ARRAY && TYPE_CODE (type) != TYPE_CODE_STRUCT && TYPE_CODE (type) != TYPE_CODE_UNION) { print_variable_value (sym2, fi, stb->stream); ui_out_field_stream (uiout, "value", stb); } do_cleanups (cleanup_tuple); break; case PRINT_ALL_VALUES: print_variable_value (sym2, fi, stb->stream); ui_out_field_stream (uiout, "value", stb); do_cleanups (cleanup_tuple); break; } } } if (BLOCK_FUNCTION (block)) break; else block = BLOCK_SUPERBLOCK (block); }