X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fjit.c;h=42ef8efb5cad4ecb01f0c3eb06fb178ec2891688;hb=3c853d931322f71b01a217f05bb8302f32a263d2;hp=0c500608e213d7127a59279b022038e9ab2679fe;hpb=4efc6507960ac76505ebb1be9886f207ceb46c3a;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/jit.c b/gdb/jit.c index 0c500608e2..42ef8efb5c 100644 --- a/gdb/jit.c +++ b/gdb/jit.c @@ -1,7 +1,6 @@ /* Handle JIT code generation in the inferior for GDB, the GNU Debugger. - Copyright (C) 2009 - Free Software Foundation, Inc. + Copyright (C) 2009, 2010 Free Software Foundation, Inc. This file is part of GDB. @@ -137,17 +136,18 @@ bfd_open_from_target_memory (CORE_ADDR addr, size_t size, char *target) /* Helper function for reading the global JIT descriptor from remote memory. */ static void -jit_read_descriptor (struct jit_descriptor *descriptor) +jit_read_descriptor (struct gdbarch *gdbarch, + struct jit_descriptor *descriptor) { int err; struct type *ptr_type; int ptr_size; int desc_size; gdb_byte *desc_buf; - enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch); + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); /* Figure out how big the descriptor is on the remote and how to read it. */ - ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr; + ptr_type = builtin_type (gdbarch)->builtin_data_ptr; ptr_size = TYPE_LENGTH (ptr_type); desc_size = 8 + 2 * ptr_size; /* Two 32-bit ints and two pointers. */ desc_buf = alloca (desc_size); @@ -169,17 +169,18 @@ jit_read_descriptor (struct jit_descriptor *descriptor) /* Helper function for reading a JITed code entry from remote memory. */ static void -jit_read_code_entry (CORE_ADDR code_addr, struct jit_code_entry *code_entry) +jit_read_code_entry (struct gdbarch *gdbarch, + CORE_ADDR code_addr, struct jit_code_entry *code_entry) { int err; struct type *ptr_type; int ptr_size; int entry_size; gdb_byte *entry_buf; - enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch); + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); /* Figure out how big the entry is on the remote and how to read it. */ - ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr; + ptr_type = builtin_type (gdbarch)->builtin_data_ptr; ptr_size = TYPE_LENGTH (ptr_type); entry_size = 3 * ptr_size + 8; /* Three pointers and one 64-bit int. */ entry_buf = alloca (entry_size); @@ -190,7 +191,7 @@ jit_read_code_entry (CORE_ADDR code_addr, struct jit_code_entry *code_entry) error (_("Unable to read JIT code entry from remote memory!")); /* Fix the endianness to match the host. */ - ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr; + ptr_type = builtin_type (gdbarch)->builtin_data_ptr; code_entry->next_entry = extract_typed_address (&entry_buf[0], ptr_type); code_entry->prev_entry = extract_typed_address (&entry_buf[ptr_size], ptr_type); @@ -206,7 +207,8 @@ jit_read_code_entry (CORE_ADDR code_addr, struct jit_code_entry *code_entry) a symbol file added by the user. */ static void -jit_register_code (CORE_ADDR entry_addr, struct jit_code_entry *code_entry) +jit_register_code (struct gdbarch *gdbarch, + CORE_ADDR entry_addr, struct jit_code_entry *code_entry) { bfd *nbfd; struct section_addr_info *sai; @@ -232,7 +234,7 @@ JITed symbol file is not an object file, ignoring it.\n")); } /* Check bfd arch. */ - b = gdbarch_bfd_arch_info (target_gdbarch); + b = gdbarch_bfd_arch_info (gdbarch); if (b->compatible (b, bfd_get_arch_info (nbfd)) != b) warning (_("JITed object file architecture %s is not compatible " "with target architecture %s."), bfd_get_arch_info @@ -250,7 +252,7 @@ JITed symbol file is not an object file, ignoring it.\n")); /* We assume that these virtual addresses are absolute, and do not treat them as offsets. */ sai->other[i].addr = bfd_get_section_vma (nbfd, sec); - sai->other[i].name = (char *) bfd_get_section_name (nbfd, sec); + sai->other[i].name = xstrdup (bfd_get_section_name (nbfd, sec)); sai->other[i].sectindex = sec->index; ++i; } @@ -299,8 +301,11 @@ jit_find_objf_with_entry_addr (CORE_ADDR entry_addr) return NULL; } -void -jit_inferior_created_hook (void) +/* (Re-)Initialize the jit breakpoint handler, and register any already + created translations. */ + +static void +jit_inferior_init (struct gdbarch *gdbarch) { struct minimal_symbol *reg_symbol; struct minimal_symbol *desc_symbol; @@ -308,7 +313,6 @@ jit_inferior_created_hook (void) struct jit_descriptor descriptor; struct jit_code_entry cur_entry; CORE_ADDR cur_entry_addr; - struct cleanup *old_cleanups; /* When we register code, GDB resets its breakpoints in case symbols have changed. That in turn calls this handler, which makes us look for new @@ -336,14 +340,14 @@ jit_inferior_created_hook (void) /* Read the descriptor so we can check the version number and load any already JITed functions. */ - jit_read_descriptor (&descriptor); + jit_read_descriptor (gdbarch, &descriptor); /* Check that the version number agrees with that we support. */ if (descriptor.version != 1) error (_("Unsupported JIT protocol version in descriptor!")); /* Put a breakpoint in the registration symbol. */ - create_jit_event_breakpoint (target_gdbarch, reg_addr); + create_jit_event_breakpoint (gdbarch, reg_addr); /* If we've attached to a running program, we need to check the descriptor to register any functions that were already generated. */ @@ -351,23 +355,40 @@ jit_inferior_created_hook (void) cur_entry_addr != 0; cur_entry_addr = cur_entry.next_entry) { - jit_read_code_entry (cur_entry_addr, &cur_entry); + jit_read_code_entry (gdbarch, cur_entry_addr, &cur_entry); /* This hook may be called many times during setup, so make sure we don't add the same symbol file twice. */ if (jit_find_objf_with_entry_addr (cur_entry_addr) != NULL) continue; - jit_register_code (cur_entry_addr, &cur_entry); + jit_register_code (gdbarch, cur_entry_addr, &cur_entry); } } +/* Exported routine to call when an inferior has been created. */ + +void +jit_inferior_created_hook (void) +{ + jit_inferior_init (target_gdbarch); +} + +/* Exported routine to call to re-set the jit breakpoints, + e.g. when a program is rerun. */ + +void +jit_breakpoint_re_set (void) +{ + jit_inferior_init (target_gdbarch); +} + /* Wrapper to match the observer function pointer prototype. */ static void -jit_inferior_created_hook1 (struct target_ops *objfile, int from_tty) +jit_inferior_created_observer (struct target_ops *objfile, int from_tty) { - jit_inferior_created_hook (); + jit_inferior_init (target_gdbarch); } /* This function cleans up any code entries left over when the inferior exits. @@ -375,7 +396,7 @@ jit_inferior_created_hook1 (struct target_ops *objfile, int from_tty) for example when it crashes. */ static void -jit_inferior_exit_hook (int pid) +jit_inferior_exit_hook (struct inferior *inf) { struct objfile *objf; struct objfile *temp; @@ -390,7 +411,7 @@ jit_inferior_exit_hook (int pid) } void -jit_event_handler (void) +jit_event_handler (struct gdbarch *gdbarch) { struct jit_descriptor descriptor; struct jit_code_entry code_entry; @@ -398,7 +419,7 @@ jit_event_handler (void) struct objfile *objf; /* Read the descriptor from remote memory. */ - jit_read_descriptor (&descriptor); + jit_read_descriptor (gdbarch, &descriptor); entry_addr = descriptor.relevant_entry; /* Do the corresponding action. */ @@ -407,14 +428,14 @@ jit_event_handler (void) case JIT_NOACTION: break; case JIT_REGISTER: - jit_read_code_entry (entry_addr, &code_entry); - jit_register_code (entry_addr, &code_entry); + jit_read_code_entry (gdbarch, entry_addr, &code_entry); + jit_register_code (gdbarch, entry_addr, &code_entry); break; case JIT_UNREGISTER: objf = jit_find_objf_with_entry_addr (entry_addr); if (objf == NULL) - printf_unfiltered ("Unable to find JITed code entry at address: %p\n", - (void *) entry_addr); + printf_unfiltered (_("Unable to find JITed code entry at address: %s\n"), + paddress (gdbarch, entry_addr)); else jit_unregister_code (objf); @@ -432,7 +453,7 @@ extern void _initialize_jit (void); void _initialize_jit (void) { - observer_attach_inferior_created (jit_inferior_created_hook1); + observer_attach_inferior_created (jit_inferior_created_observer); observer_attach_inferior_exit (jit_inferior_exit_hook); jit_objfile_data = register_objfile_data (); }