/* Parse expressions for GDB.
Copyright (C) 1986, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
- 1998, 1999, 2000, 2001, 2004, 2005, 2007 Free Software Foundation, Inc.
+ 1998, 1999, 2000, 2001, 2004, 2005, 2007, 2008
+ Free Software Foundation, Inc.
Modified from expread.y by the Department of Computer Science at the
State University of New York at Buffalo, 1991.
struct type *text_symbol_type,
struct type *data_symbol_type)
{
- struct gdbarch *gdbarch = current_gdbarch;
- CORE_ADDR addr;
+ struct objfile *objfile = msymbol_objfile (msymbol);
+ struct gdbarch *gdbarch = get_objfile_arch (objfile);
+
+ CORE_ADDR addr = SYMBOL_VALUE_ADDRESS (msymbol);
+ asection *bfd_section = SYMBOL_BFD_SECTION (msymbol);
+ enum minimal_symbol_type type = msymbol->type;
+ CORE_ADDR pc;
+
+ /* The minimal symbol might point to a function descriptor;
+ resolve it to the actual code address instead. */
+ pc = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, ¤t_target);
+ if (pc != addr)
+ {
+ /* In this case, assume we have a code symbol instead of
+ a data symbol. */
+ type = mst_text;
+ bfd_section = NULL;
+ addr = pc;
+ }
+
+ if (overlay_debugging)
+ addr = symbol_overlayed_address (addr, bfd_section);
write_exp_elt_opcode (OP_LONG);
/* Let's make the type big enough to hold a 64-bit address. */
write_exp_elt_type (builtin_type_CORE_ADDR);
-
- addr = SYMBOL_VALUE_ADDRESS (msymbol);
- if (overlay_debugging)
- addr = symbol_overlayed_address (addr, SYMBOL_BFD_SECTION (msymbol));
write_exp_elt_longcst ((LONGEST) addr);
-
write_exp_elt_opcode (OP_LONG);
- if (SYMBOL_BFD_SECTION (msymbol)
- && SYMBOL_BFD_SECTION (msymbol)->flags & SEC_THREAD_LOCAL)
+ if (bfd_section && bfd_section->flags & SEC_THREAD_LOCAL)
{
- bfd *bfd = SYMBOL_BFD_SECTION (msymbol)->owner;
- struct objfile *ofp;
-
- ALL_OBJFILES (ofp)
- if (ofp->obfd == bfd)
- break;
-
write_exp_elt_opcode (UNOP_MEMVAL_TLS);
- write_exp_elt_objfile (ofp);
+ write_exp_elt_objfile (objfile);
write_exp_elt_type (builtin_type (gdbarch)->nodebug_tls_symbol);
write_exp_elt_opcode (UNOP_MEMVAL_TLS);
return;
}
write_exp_elt_opcode (UNOP_MEMVAL);
- switch (msymbol->type)
+ switch (type)
{
case mst_text:
case mst_file_text:
static void
prefixify_expression (struct expression *expr)
{
- int len =
- sizeof (struct expression) + EXP_ELEM_TO_BYTES (expr->nelts);
+ int len = sizeof (struct expression) + EXP_ELEM_TO_BYTES (expr->nelts);
struct expression *temp;
int inpos = expr->nelts, outpos = 0;
old_chain = make_cleanup (free_funcalls, 0 /*ignore*/);
funcall_chain = 0;
- /* If no context specified, try using the current frame, if any. */
+ expression_context_block = block;
- if (!block)
- block = get_selected_block (&expression_context_pc);
+ /* If no context specified, try using the current frame, if any. */
+ if (!expression_context_block)
+ expression_context_block = get_selected_block (&expression_context_pc);
+ else
+ expression_context_pc = BLOCK_START (expression_context_block);
- /* Fall back to using the current source static context, if any. */
+ /* Fall back to using the current source static context, if any. */
- if (!block)
+ if (!expression_context_block)
{
struct symtab_and_line cursal = get_current_source_symtab_and_line ();
if (cursal.symtab)
- block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (cursal.symtab), STATIC_BLOCK);
- }
-
- /* Save the context, if specified by caller, or found above. */
-
- if (block)
- {
- expression_context_block = block;
- expression_context_pc = BLOCK_START (block);
+ expression_context_block
+ = BLOCKVECTOR_BLOCK (BLOCKVECTOR (cursal.symtab), STATIC_BLOCK);
+ if (expression_context_block)
+ expression_context_pc = BLOCK_START (expression_context_block);
}
expout_size = 10;
return exp;
}
-
-/* As for parse_expression, except that if VOID_CONTEXT_P, then
- no value is expected from the expression. */
-
-struct expression *
-parse_expression_in_context (char *string, int void_context_p)
-{
- struct expression *exp;
- exp = parse_exp_in_context (&string, 0, 0, void_context_p);
- if (*string != '\000')
- error (_("Junk after end of expression."));
- return exp;
-}
-
/* A post-parser that does nothing */
void