This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[03/15] Revert find_function_in_inferior gdbarch changes
- From: "Ulrich Weigand" <uweigand at de dot ibm dot com>
- To: gdb-patches at sourceware dot org
- Date: Tue, 9 Jun 2009 17:16:01 +0200 (CEST)
- Subject: [03/15] Revert find_function_in_inferior gdbarch changes
Hello,
this patch reverts the changes introduced here:
http://sourceware.org/ml/gdb-patches/2008-08/msg00708.html
As we'll associate an architecture with every value, find_function_in_inferior
will need an GDBARCH argument anyway, like all value allocator routines,
to define the architecture the returned function value object should have.
This means we no longer need to (ab-)use the objfile architecture of the
file where the function symbol is found.
There's some amount of circular dependency between this patch and the
patch to introduce per-value architecture. To break this, this patch
re-introduces a number of references to current_gdbarch, which will
be removed again by the follow-on patch.
Bye,
Ulrich
ChangeLog:
* value.h (find_function_in_inferior): Add GDBARCH, remove OBJF_P parameter.
(value_allocate_space_in_inferior): Add GDBARCH parameter.
* valops.c (allocate_space_in_inferior): Remove.
(find_function_in_inferior): Add GDBARCH parameter; remove OBJF_P parameter.
(value_allocate_space_in_inferior): Add GDBARCH parameter.
(value_coerce_to_target): Call value_allocate_space_in_inferior
instead of allocate_space_in_inferior.
* scm-lang.h (scm_evaluate_string): Add GDBARCH parameter.
* scm-lang.c (scm_evaluate_string): Likewise.
(evaluate_exp): Update call.
* scm-exp.c (scm_lreadr): Likewise.
Update calls to find_function_in_inferior:
* scm-valprint.c (scm_inferior_print): Update.
* eval.c (evaluate_subexp_standard): Update.
* gcore.c (derive_heap_segment): Update.
* linux-fork.c (checkpoint_command): Update.
* objc-lang.c (lookup_objc_class, lookup_child_selector, value_nsstring,
print_object_command): Update.
* scm-lang.c (scm_lookup_name): Update.
(scm_evaluate_string): Update.
* valops.c (value_allocate_space_in_inferior): Update.
Update calls to value_allocate_space_in_inferior:
* frv-tdep.c (find_func_descr): Update.
* scm-lang.c (scm_lookup_name): Update.
(scm_evaluate_string): Update.
* linux-fork.c: Include "arch-utils.h".
(checkpoint_command): Use get_current_arch ().
* objc-lang.c: Include "arch-utils.h".
(print_object_command): Use get_current_arch ().
Index: gdb-head/gdb/frv-tdep.c
===================================================================
--- gdb-head.orig/gdb/frv-tdep.c
+++ gdb-head/gdb/frv-tdep.c
@@ -1154,7 +1154,7 @@ find_func_descr (struct gdbarch *gdbarch
/* Construct a non-canonical descriptor from space allocated on
the stack. */
- descr = value_as_long (value_allocate_space_in_inferior (8));
+ descr = value_as_long (value_allocate_space_in_inferior (gdbarch, 8));
store_unsigned_integer (valbuf, 4, entry_point);
write_memory (descr, valbuf, 4);
store_unsigned_integer (valbuf, 4,
Index: gdb-head/gdb/scm-exp.c
===================================================================
--- gdb-head.orig/gdb/scm-exp.c
+++ gdb-head/gdb/scm-exp.c
@@ -308,7 +308,8 @@ tryagain:
scm_lreadr (skipping);
if (!skipping)
{
- struct value *val = scm_evaluate_string (str.ptr, lexptr - str.ptr);
+ struct value *val = scm_evaluate_string (parse_gdbarch,
+ str.ptr, lexptr - str.ptr);
if (!is_scmvalue_type (value_type (val)))
error ("quoted scm form yields non-SCM value");
svalue = extract_signed_integer (value_contents (val),
Index: gdb-head/gdb/scm-lang.c
===================================================================
--- gdb-head.orig/gdb/scm-lang.c
+++ gdb-head/gdb/scm-lang.c
@@ -152,9 +152,9 @@ scm_lookup_name (struct gdbarch *gdbarch
struct value *val;
struct symbol *sym;
- func = find_function_in_inferior ("scm_lookup_cstr", NULL);
+ func = find_function_in_inferior (gdbarch, "scm_lookup_cstr");
- args[0] = value_allocate_space_in_inferior (len);
+ args[0] = value_allocate_space_in_inferior (gdbarch, len);
args[1] = value_from_longest (builtin_type (gdbarch)->builtin_int, len);
write_memory (value_as_long (args[0]), (gdb_byte *) str, len);
@@ -181,15 +181,15 @@ scm_lookup_name (struct gdbarch *gdbarch
}
struct value *
-scm_evaluate_string (char *str, int len)
+scm_evaluate_string (struct gdbarch *gdbarch, char *str, int len)
{
struct value *func;
- struct value *addr = value_allocate_space_in_inferior (len + 1);
+ struct value *addr = value_allocate_space_in_inferior (gdbarch, len + 1);
LONGEST iaddr = value_as_long (addr);
write_memory (iaddr, (gdb_byte *) str, len);
/* FIXME - should find and pass env */
write_memory (iaddr + len, (gdb_byte *) "", 1);
- func = find_function_in_inferior ("scm_evstr", NULL);
+ func = find_function_in_inferior (gdbarch, "scm_evstr");
return call_function_by_hand (func, 1, &addr);
}
@@ -217,7 +217,7 @@ evaluate_exp (struct type *expect_type,
if (noside == EVAL_SKIP)
goto nosideret;
str = &exp->elts[pc + 2].string;
- return scm_evaluate_string (str, len);
+ return scm_evaluate_string (exp->gdbarch, str, len);
default:;
}
return evaluate_subexp_standard (expect_type, exp, pos, noside);
Index: gdb-head/gdb/scm-lang.h
===================================================================
--- gdb-head.orig/gdb/scm-lang.h
+++ gdb-head/gdb/scm-lang.h
@@ -58,7 +58,7 @@ extern int is_scmvalue_type (struct type
extern void scm_printchar (int, struct type *, struct ui_file *);
-extern struct value *scm_evaluate_string (char *, int);
+extern struct value *scm_evaluate_string (struct gdbarch *, char *, int);
extern int scm_parse (void);
Index: gdb-head/gdb/value.h
===================================================================
--- gdb-head.orig/gdb/value.h
+++ gdb-head/gdb/value.h
@@ -655,10 +655,10 @@ extern struct value *value_slice (struct
extern struct value *value_literal_complex (struct value *, struct value *,
struct type *);
-extern struct value *find_function_in_inferior (const char *,
- struct objfile **);
+extern struct value *find_function_in_inferior (struct gdbarch *,
+ const char *);
-extern struct value *value_allocate_space_in_inferior (int);
+extern struct value *value_allocate_space_in_inferior (struct gdbarch *, int);
extern struct value *value_of_local (const char *name, int complain);
Index: gdb-head/gdb/valops.c
===================================================================
--- gdb-head.orig/gdb/valops.c
+++ gdb-head/gdb/valops.c
@@ -96,8 +96,6 @@ static struct value *value_maybe_namespa
char *, int,
enum noside);
-static CORE_ADDR allocate_space_in_inferior (int);
-
static struct value *cast_into_complex (struct type *, struct value *);
static struct fn_field *find_method_list (struct value **, char *,
@@ -124,12 +122,10 @@ Overload resolution in evaluating C++ fu
value);
}
-/* Find the address of function name NAME in the inferior. If OBJF_P
- is non-NULL, *OBJF_P will be set to the OBJFILE where the function
- is defined. */
+/* Find the address of function name NAME in the inferior. */
struct value *
-find_function_in_inferior (const char *name, struct objfile **objf_p)
+find_function_in_inferior (struct gdbarch *gdbarch, const char *name)
{
struct symbol *sym;
sym = lookup_symbol (name, 0, VAR_DOMAIN, 0);
@@ -141,9 +137,6 @@ find_function_in_inferior (const char *n
name);
}
- if (objf_p)
- *objf_p = SYMBOL_SYMTAB (sym)->objfile;
-
return value_of_variable (sym, NULL);
}
else
@@ -152,9 +145,6 @@ find_function_in_inferior (const char *n
lookup_minimal_symbol (name, NULL, NULL);
if (msymbol != NULL)
{
- struct objfile *objfile = msymbol_objfile (msymbol);
- struct gdbarch *gdbarch = get_objfile_arch (objfile);
-
struct type *type;
CORE_ADDR maddr;
type = lookup_pointer_type (builtin_type (gdbarch)->builtin_char);
@@ -162,9 +152,6 @@ find_function_in_inferior (const char *n
type = lookup_pointer_type (type);
maddr = SYMBOL_VALUE_ADDRESS (msymbol);
- if (objf_p)
- *objf_p = objfile;
-
return value_from_pointer (type, maddr);
}
else
@@ -182,11 +169,9 @@ find_function_in_inferior (const char *n
space. */
struct value *
-value_allocate_space_in_inferior (int len)
+value_allocate_space_in_inferior (struct gdbarch *gdbarch, int len)
{
- struct objfile *objf;
- struct value *val = find_function_in_inferior ("malloc", &objf);
- struct gdbarch *gdbarch = get_objfile_arch (objf);
+ struct value *val = find_function_in_inferior (gdbarch, "malloc");
struct value *blocklen;
blocklen = value_from_longest (builtin_type (gdbarch)->builtin_int, len);
@@ -201,12 +186,6 @@ value_allocate_space_in_inferior (int le
return val;
}
-static CORE_ADDR
-allocate_space_in_inferior (int len)
-{
- return value_as_long (value_allocate_space_in_inferior (len));
-}
-
/* Cast struct value VAL to type TYPE and return as a value.
Both type and val must be of TYPE_CODE_STRUCT or TYPE_CODE_UNION
for this to work. Typedef to one of the codes is permitted.
@@ -1102,6 +1081,7 @@ value_must_coerce_to_target (struct valu
struct value *
value_coerce_to_target (struct value *val)
{
+ struct gdbarch *gdbarch = current_gdbarch;
LONGEST length;
CORE_ADDR addr;
@@ -1109,7 +1089,7 @@ value_coerce_to_target (struct value *va
return val;
length = TYPE_LENGTH (check_typedef (value_type (val)));
- addr = allocate_space_in_inferior (length);
+ addr = value_as_address (value_allocate_space_in_inferior (gdbarch, length));
write_memory (addr, value_contents (val), length);
return value_at_lazy (value_type (val), addr);
}
Index: gdb-head/gdb/eval.c
===================================================================
--- gdb-head.orig/gdb/eval.c
+++ gdb-head/gdb/eval.c
@@ -1079,9 +1079,10 @@ evaluate_subexp_standard (struct type *e
type = lookup_function_type (type);
type = lookup_pointer_type (type);
- msg_send = find_function_in_inferior ("objc_msg_lookup", NULL);
+ msg_send
+ = find_function_in_inferior (exp->gdbarch, "objc_msg_lookup");
msg_send_stret
- = find_function_in_inferior ("objc_msg_lookup", NULL);
+ = find_function_in_inferior (exp->gdbarch, "objc_msg_lookup");
msg_send = value_from_pointer (type, value_as_address (msg_send));
msg_send_stret = value_from_pointer (type,
@@ -1089,10 +1090,11 @@ evaluate_subexp_standard (struct type *e
}
else
{
- msg_send = find_function_in_inferior ("objc_msgSend", NULL);
+ msg_send
+ = find_function_in_inferior (exp->gdbarch, "objc_msgSend");
/* Special dispatcher for methods returning structs */
msg_send_stret
- = find_function_in_inferior ("objc_msgSend_stret", NULL);
+ = find_function_in_inferior (exp->gdbarch, "objc_msgSend_stret");
}
/* Verify the target object responds to this method. The
Index: gdb-head/gdb/gcore.c
===================================================================
--- gdb-head.orig/gdb/gcore.c
+++ gdb-head/gdb/gcore.c
@@ -219,8 +219,7 @@ derive_stack_segment (bfd_vma *bottom, b
static int
derive_heap_segment (bfd *abfd, bfd_vma *bottom, bfd_vma *top)
{
- struct objfile *sbrk_objf;
- struct gdbarch *gdbarch;
+ struct gdbarch *gdbarch = target_gdbarch;
bfd_vma top_of_data_memory = 0;
bfd_vma top_of_heap = 0;
bfd_size_type sec_size;
@@ -262,20 +261,19 @@ derive_heap_segment (bfd *abfd, bfd_vma
/* Now get the top-of-heap by calling sbrk in the inferior. */
if (lookup_minimal_symbol ("sbrk", NULL, NULL) != NULL)
{
- sbrk = find_function_in_inferior ("sbrk", &sbrk_objf);
+ sbrk = find_function_in_inferior (gdbarch, "sbrk");
if (sbrk == NULL)
return 0;
}
else if (lookup_minimal_symbol ("_sbrk", NULL, NULL) != NULL)
{
- sbrk = find_function_in_inferior ("_sbrk", &sbrk_objf);
+ sbrk = find_function_in_inferior (gdbarch, "_sbrk");
if (sbrk == NULL)
return 0;
}
else
return 0;
- gdbarch = get_objfile_arch (sbrk_objf);
zero = value_from_longest (builtin_type (gdbarch)->builtin_int, 0);
gdb_assert (zero);
sbrk = call_function_by_hand (sbrk, 1, &zero);
Index: gdb-head/gdb/linux-fork.c
===================================================================
--- gdb-head.orig/gdb/linux-fork.c
+++ gdb-head/gdb/linux-fork.c
@@ -18,6 +18,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
+#include "arch-utils.h"
#include "inferior.h"
#include "regcache.h"
#include "gdbcmd.h"
@@ -570,8 +571,7 @@ save_detach_fork (int *saved_val)
static void
checkpoint_command (char *args, int from_tty)
{
- struct objfile *fork_objf;
- struct gdbarch *gdbarch;
+ struct gdbarch *gdbarch = get_current_arch ();
struct target_waitstatus last_target_waitstatus;
ptid_t last_target_ptid;
struct value *fork_fn = NULL, *ret;
@@ -589,14 +589,13 @@ checkpoint_command (char *args, int from
/* Make the inferior fork, record its (and gdb's) state. */
if (lookup_minimal_symbol ("fork", NULL, NULL) != NULL)
- fork_fn = find_function_in_inferior ("fork", &fork_objf);
+ fork_fn = find_function_in_inferior (gdbarch, "fork");
if (!fork_fn)
if (lookup_minimal_symbol ("_fork", NULL, NULL) != NULL)
- fork_fn = find_function_in_inferior ("fork", &fork_objf);
+ fork_fn = find_function_in_inferior (gdbarch, "fork");
if (!fork_fn)
error (_("checkpoint: can't find fork function in inferior."));
- gdbarch = get_objfile_arch (fork_objf);
ret = value_from_longest (builtin_type (gdbarch)->builtin_int, 0);
old_chain = save_detach_fork (&temp_detach_fork);
detach_fork = 0;
Index: gdb-head/gdb/objc-lang.c
===================================================================
--- gdb-head.orig/gdb/objc-lang.c
+++ gdb-head/gdb/objc-lang.c
@@ -22,6 +22,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
+#include "arch-utils.h"
#include "symtab.h"
#include "gdbtypes.h"
#include "expression.h"
@@ -119,10 +120,10 @@ lookup_objc_class (struct gdbarch *gdbar
return 0;
}
- if (lookup_minimal_symbol("objc_lookUpClass", 0, 0))
- function = find_function_in_inferior("objc_lookUpClass", NULL);
+ if (lookup_minimal_symbol ("objc_lookUpClass", 0, 0))
+ function = find_function_in_inferior (gdbarch, "objc_lookUpClass");
else if (lookup_minimal_symbol ("objc_lookup_class", 0, 0))
- function = find_function_in_inferior("objc_lookup_class", NULL);
+ function = find_function_in_inferior (gdbarch, "objc_lookup_class");
else
{
complaint (&symfile_complaints, _("no way to lookup Objective-C classes"));
@@ -147,10 +148,10 @@ lookup_child_selector (struct gdbarch *g
return 0;
}
- if (lookup_minimal_symbol("sel_getUid", 0, 0))
- function = find_function_in_inferior("sel_getUid", NULL);
+ if (lookup_minimal_symbol ("sel_getUid", 0, 0))
+ function = find_function_in_inferior (gdbarch, "sel_getUid");
else if (lookup_minimal_symbol ("sel_get_any_uid", 0, 0))
- function = find_function_in_inferior("sel_get_any_uid", NULL);
+ function = find_function_in_inferior (gdbarch, "sel_get_any_uid");
else
{
complaint (&symfile_complaints, _("no way to lookup Objective-C selectors"));
@@ -179,18 +180,18 @@ value_nsstring (struct gdbarch *gdbarch,
/* _NSNewStringFromCString replaces "istr" after Lantern2A. */
if (lookup_minimal_symbol("_NSNewStringFromCString", 0, 0))
{
- function = find_function_in_inferior("_NSNewStringFromCString", NULL);
+ function = find_function_in_inferior(gdbarch, "_NSNewStringFromCString");
nsstringValue = call_function_by_hand(function, 1, &stringValue[2]);
}
else if (lookup_minimal_symbol("istr", 0, 0))
{
- function = find_function_in_inferior("istr", NULL);
+ function = find_function_in_inferior(gdbarch, "istr");
nsstringValue = call_function_by_hand(function, 1, &stringValue[2]);
}
else if (lookup_minimal_symbol("+[NSString stringWithCString:]", 0, 0))
{
function
- = find_function_in_inferior("+[NSString stringWithCString:]", NULL);
+ = find_function_in_inferior(gdbarch, "+[NSString stringWithCString:]");
type = builtin_type (gdbarch)->builtin_long;
stringValue[0] = value_from_longest
@@ -1406,6 +1407,7 @@ char *find_imps (struct symtab *symtab,
static void
print_object_command (char *args, int from_tty)
{
+ struct gdbarch *gdbarch = get_current_arch ();
struct value *object, *function, *description;
CORE_ADDR string_addr, object_addr;
int i = 0;
@@ -1430,7 +1432,7 @@ print_object_command (char *args, int fr
object_addr = value_as_long (object);
read_memory (object_addr, &c, 1);
- function = find_function_in_inferior ("_NSPrintForDebugger", NULL);
+ function = find_function_in_inferior (gdbarch, "_NSPrintForDebugger");
if (function == NULL)
error (_("Unable to locate _NSPrintForDebugger in child process"));
Index: gdb-head/gdb/scm-valprint.c
===================================================================
--- gdb-head.orig/gdb/scm-valprint.c
+++ gdb-head/gdb/scm-valprint.c
@@ -53,7 +53,7 @@ scm_inferior_print (struct type *type, L
char *output;
int ret, output_len;
- func = find_function_in_inferior ("gdb_print", NULL);
+ func = find_function_in_inferior (current_gdbarch, "gdb_print");
arg = value_from_longest (type, value);
result = call_function_by_hand (func, 1, &arg);
--
Dr. Ulrich Weigand
GNU Toolchain for Linux on System z and Cell BE
Ulrich.Weigand@de.ibm.com