28 #include "filenames.h"
102 file_ptr nbytes, file_ptr
offset)
108 if (offset + nbytes > buffer->
size)
129 memset (sb, 0,
sizeof (
struct stat));
130 sb->st_size = buffer->
size;
161 static const char *reader_init_fn_sym =
"gdb_init_reader";
180 init_fn =
gdb_dlsym (so, reader_init_fn_sym);
182 error (
_(
"Could not locate initialization function: %s."),
185 if (
gdb_dlsym (so,
"plugin_is_GPL_compatible") == NULL)
186 error (
_(
"Reader not GPL compatible."));
190 error (
_(
"Reader version does not match GDB version."));
209 error (
_(
"No reader name provided."));
212 error (
_(
"JIT reader already loaded. Run jit-reader-unload first."));
214 if (IS_ABSOLUTE_PATH (args))
215 so_name = xstrdup (args);
230 error (
_(
"No JIT reader loaded."));
242 struct jit_program_space_data
267 struct jit_objfile_data
283 static struct jit_objfile_data *
286 struct jit_objfile_data *objf_data;
288 objf_data = objfile_data (objf, jit_objfile_data);
289 if (objf_data == NULL)
291 objf_data = XCNEW (
struct jit_objfile_data);
292 set_objfile_data (objf, jit_objfile_data, objf_data);
304 struct jit_objfile_data *objf_data;
307 objf_data->
addr = entry;
313 static struct jit_program_space_data *
316 struct jit_program_space_data *ps_data;
321 ps_data = XCNEW (
struct jit_program_space_data);
341 struct jit_program_space_data *ps_data)
344 struct type *ptr_type;
349 struct jit_objfile_data *objf_data;
359 "jit_read_descriptor, descriptor_addr = %s\n",
366 desc_size = 8 + 2 * ptr_size;
367 desc_buf = alloca (desc_size);
372 desc_buf, desc_size);
398 struct type *ptr_type;
412 off = (off + (align_bytes - 1)) & ~(align_bytes - 1);
414 entry_size = off + 8;
415 entry_buf = alloca (entry_size);
420 error (
_(
"Unable to read JIT code entry from remote memory!"));
525 ret->
file_name = file_name ? xstrdup (file_name) : xstrdup (
"");
526 ret->
next =
object->symtabs;
527 object->symtabs = ret;
544 if (old->
end > newobj->
end)
567 block->
name = name ? xstrdup (name) : NULL;
613 for (i = 0; i < nlines; i++)
638 struct gdb_block *gdb_block_iter, *gdb_block_iter_tmp;
639 struct block *block_iter;
640 int actual_nblocks, i;
641 size_t blockvector_size;
667 + (actual_nblocks - 1) *
sizeof (
struct block *));
681 for (i = (actual_nblocks - 1), gdb_block_iter = stab->
blocks;
683 i--, gdb_block_iter = gdb_block_iter->
next)
706 gdb_block_iter->
name,
707 strlen (gdb_block_iter->
name));
745 for (gdb_block_iter = stab->
blocks;
747 gdb_block_iter = gdb_block_iter->
next)
749 if (gdb_block_iter->
parent != NULL)
765 gdb_block_iter = stab->
blocks;
767 for (gdb_block_iter = stab->
blocks, gdb_block_iter_tmp = gdb_block_iter->
next;
769 gdb_block_iter = gdb_block_iter_tmp)
772 xfree (gdb_block_iter);
788 jit_dbg_reader_data *priv_data;
799 for (i = obj->
symtabs; i; i = j)
818 jit_dbg_reader_data priv_data;
834 priv_data = entry_addr;
863 if (jit_debug && status == 0)
865 "Could not read symtab using the loaded JIT reader.\n");
879 struct bfd_section *sec;
883 const struct bfd_arch_info *b;
887 "jit_register_code, symfile_addr = %s, "
888 "symfile_size = %s\n",
902 if (!bfd_check_format (nbfd, bfd_object))
905 JITed symbol file is not an object file, ignoring it.\n"));
912 if (b->compatible (b, bfd_get_arch_info (nbfd)) != b)
913 warning (
_(
"JITed object file architecture %s is not compatible "
914 "with target architecture %s."), bfd_get_arch_info
915 (nbfd)->printable_name, b->printable_name);
923 for (sec = nbfd->sections; sec != NULL; sec = sec->next)
924 if ((bfd_get_section_flags (nbfd, sec) & (SEC_ALLOC|SEC_LOAD)) != 0)
928 sai->
other[i].
addr = bfd_get_section_vma (nbfd, sec);
929 sai->
other[i].
name = xstrdup (bfd_get_section_name (nbfd, sec));
957 "jit_register_code, symfile_addr = %s, "
958 "symfile_size = %s\n",
986 struct jit_objfile_data *objf_data;
988 objf_data = objfile_data (objf, jit_objfile_data);
989 if (objf_data != NULL && objf_data->
addr == entry_addr)
1006 for (iter = b->
loc; iter != NULL; iter = iter->
next)
1008 struct jit_program_space_data *ps_data;
1010 ps_data = program_space_data (iter->
pspace, jit_program_space_data);
1024 struct jit_program_space_data *ps_data)
1028 struct jit_objfile_data *objf_data;
1036 if (reg_symbol.
minsym == NULL
1042 if (desc_symbol.
minsym == NULL
1059 "jit_breakpoint_re_set_internal, "
1060 "breakpoint_addr = %s\n",
1107 _(
"Could not recognize DWARF regnum %d"),
1253 static struct value *
1316 struct jit_program_space_data *ps_data;
1337 "in descriptor (expected 1)\n"),
1345 cur_entry_addr != 0;
1389 struct jit_objfile_data *objf_data = objfile_data (objf,
1392 if (objf_data != NULL && objf_data->
addr != 0)
1424 "entry at address: %s\n"),
1431 error (
_(
"Unknown action_flag value in JIT descriptor!"));
1441 struct jit_objfile_data *objf_data = data;
1445 struct jit_program_space_data *ps_data;
1447 ps_data = program_space_data (objfile->
pspace, jit_program_space_data);
1448 if (ps_data != NULL && ps_data->
objfile == objfile)
1478 _(
"Set JIT debugging."),
1479 _(
"Show JIT debugging."),
1480 _(
"When non-zero, JIT debugging is enabled."),
1490 jit_program_space_data =
1491 register_program_space_data_with_cleanup (NULL,
1497 Load FILE as debug info reader and unwinder for JIT compiled code.\n\
1498 Usage: jit-reader-load FILE\n\
1499 Try to load file FILE as a debug info reader (and unwinder) for\n\
1500 JIT compiled code. The file is loaded from " JIT_READER_DIR ",\n\
1501 relocated relative to the GDB executable if required."));
1503 Unload the currently loaded JIT debug info reader.\n\
1504 Usage: jit-reader-unload FILE\n\n\
1505 Do \"help jit-reader-load\" for info on loading debug info readers."));
struct gdbarch * target_gdbarch(void)
struct linetable * linetable
ULONGEST extract_unsigned_integer(const gdb_byte *, int, enum bfd_endian)
struct breakpoint * create_jit_event_breakpoint(struct gdbarch *gdbarch, CORE_ADDR address)
struct gdb_reader_funcs * functions
static void free_objfile_data(struct objfile *objfile, void *data)
struct observer * observer_attach_breakpoint_deleted(observer_breakpoint_deleted_ftype *f)
struct frame_id frame_id_build(CORE_ADDR stack_addr, CORE_ADDR code_addr)
CORE_ADDR extract_typed_address(const gdb_byte *buf, struct type *type)
struct value * frame_unwind_got_bytes(struct frame_info *frame, int regnum, gdb_byte *buf)
#define GDB_READER_INTERFACE_VERSION
int gdb_dlclose(void *handle)
static file_ptr mem_bfd_iovec_pread(struct bfd *abfd, void *stream, void *buf, file_ptr nbytes, file_ptr offset)
static struct jit_reader * jit_reader_load(const char *file_name)
void add_setshow_zuinteger_cmd(const char *name, enum command_class theclass, unsigned int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
void _initialize_jit(void)
void symbol_set_symtab(struct symbol *symbol, struct symtab *symtab)
struct linetable_entry item[1]
static int mem_bfd_iovec_stat(struct bfd *abfd, void *stream, struct stat *sb)
static struct gdb_reg_value * jit_unwind_reg_get_impl(struct gdb_unwind_callbacks *cb, int regnum)
static const char *const jit_break_name
static const char *const jit_descriptor_name
static int jit_read_descriptor(struct gdbarch *gdbarch, struct jit_descriptor *descriptor, struct jit_program_space_data *ps_data)
struct block * real_block
gdb_unwind_reg_get * reg_get
#define JIT_READER_DIR_RELOCATABLE
struct objfile * symbol_file_add_from_bfd(bfd *abfd, const char *name, int add_flags, struct section_addr_info *addrs, int flags, struct objfile *parent)
#define BMSYMBOL_VALUE_ADDRESS(symbol)
static struct jit_reader * loaded_jit_reader
void warning(const char *fmt,...)
void jit_breakpoint_re_set(void)
struct program_space * pspace
void * gdb_dlopen(const char *filename)
static void jit_breakpoint_deleted(struct breakpoint *b)
static struct bfd * bfd_open_from_target_memory(CORE_ADDR addr, ULONGEST size, char *target)
struct gdb_block * blocks
void * gdbarch_data(struct gdbarch *gdbarch, struct gdbarch_data *data)
struct compunit_symtab * allocate_compunit_symtab(struct objfile *objfile, const char *name)
const struct builtin_type * builtin_type(struct gdbarch *gdbarch)
static void jit_reader_unload_command(char *args, int from_tty)
static void jit_register_code(struct gdbarch *gdbarch, CORE_ADDR entry_addr, struct jit_code_entry *code_entry)
gdb_destroy_reader * destroy
gdb_target_read * target_read
gdb_reg_value_free * free
struct observer * observer_attach_inferior_exit(observer_inferior_exit_ftype *f)
#define BLOCKVECTOR_BLOCK(blocklist, n)
#define OBJF_NOT_FILENAME
struct gdbarch_data * gdbarch_data_register_pre_init(gdbarch_data_pre_init_ftype *pre_init)
int gdbarch_num_regs(struct gdbarch *gdbarch)
static void show_jit_debug(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static void * jit_gdbarch_data_init(struct obstack *obstack)
#define COMPUNIT_DIRNAME(cust)
static struct objfile * jit_find_objf_with_entry_addr(CORE_ADDR entry_addr)
int is_dl_available(void)
void frame_unwind_prepend_unwinder(struct gdbarch *gdbarch, const struct frame_unwind *unwinder)
struct objfile_per_bfd_storage * per_bfd
int gdbarch_long_long_align_bit(struct gdbarch *gdbarch)
static int mem_bfd_iovec_close(struct bfd *abfd, void *stream)
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
static void jit_dealloc_cache(struct frame_info *this_frame, void *cache)
static int jit_frame_sniffer(const struct frame_unwind *self, struct frame_info *this_frame, void **cache)
#define BLOCK_FUNCTION(bl)
static void jit_frame_this_id(struct frame_info *this_frame, void **cache, struct frame_id *this_id)
static void jit_read_code_entry(struct gdbarch *gdbarch, CORE_ADDR code_addr, struct jit_code_entry *code_entry)
struct obstack objfile_obstack
static void add_objfile_entry(struct objfile *objfile, CORE_ADDR entry)
#define ALL_OBJFILES(obj)
gdb_get_frame_id * get_frame_id
struct bp_location * next
#define SYMBOL_ACLASS_INDEX(symbol)
void * gdb_dlsym(void *handle, const char *symbol)
#define CATCH(EXCEPTION, MASK)
struct cleanup * make_cleanup_dlclose(void *handle)
static void reg_value_free_impl(struct gdb_reg_value *value)
unsigned long GDB_CORE_ADDR
void free_objfile(struct objfile *objfile)
static struct gdb_symtab * jit_symtab_open_impl(struct gdb_symbol_callbacks *cb, struct gdb_object *object, const char *file_name)
void gdb_bfd_unref(struct bfd *abfd)
#define SYMBOL_DOMAIN(symbol)
struct program_space * pspace
static struct gdb_block * jit_block_open_impl(struct gdb_symbol_callbacks *cb, struct gdb_symtab *symtab, struct gdb_block *parent, GDB_CORE_ADDR begin, GDB_CORE_ADDR end, const char *name)
void fprintf_filtered(struct ui_file *stream, const char *format,...)
CORE_ADDR cached_code_address
void jit_inferior_created_hook(void)
gdb_read_debug_info * read
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t err
struct bound_minimal_symbol lookup_minimal_symbol_and_objfile(const char *name)
void fprintf_unfiltered(struct ui_file *stream, const char *format,...)
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t int status
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
struct gdbarch * get_objfile_arch(const struct objfile *objfile)
char * pulongest(ULONGEST u)
void add_compunit_symtab_to_objfile(struct compunit_symtab *cu)
gdb_unwind_reg_set * reg_set
static void jit_unwind_reg_set_impl(struct gdb_unwind_callbacks *cb, int dwarf_regnum, struct gdb_reg_value *value)
struct dictionary * dict_create_linear(struct obstack *obstack, const struct pending *symbol_list)
#define BLOCK_SUPERBLOCK(bl)
bfd * gdb_bfd_openr_iovec(const char *filename, const char *target, void *(*open_func)(struct bfd *nbfd, void *open_closure), void *open_closure, file_ptr(*pread_func)(struct bfd *nbfd, void *stream, void *buf, file_ptr nbytes, file_ptr offset), int(*close_func)(struct bfd *nbfd, void *stream), int(*stat_func)(struct bfd *abfd, void *stream, struct stat *sb))
CORE_ADDR jit_dbg_reader_data
struct frame_info * this_frame
static void jit_symtab_close_impl(struct gdb_symbol_callbacks *cb, struct gdb_symtab *stab)
static enum gdb_status jit_target_read_impl(GDB_CORE_ADDR target_mem, void *gdb_buf, int len)
struct gdb_reader_funcs *( reader_init_fn_type)(void)
static void jit_bfd_try_read_symtab(struct jit_code_entry *code_entry, CORE_ADDR entry_addr, struct gdbarch *gdbarch)
static struct jit_program_space_data * get_jit_program_space_data(void)
struct block * allocate_block(struct obstack *obstack)
char * xstrprintf(const char *format,...)
static void * mem_bfd_iovec_open(struct bfd *abfd, void *open_closure)
void printf_unfiltered(const char *format,...)
struct cmd_list_element * setdebuglist
static void jit_inferior_exit_hook(struct inferior *inf)
struct cleanup * make_cleanup_bfd_unref(bfd *abfd)
struct ui_file * gdb_stdlog
static void jit_program_space_data_cleanup(struct program_space *ps, void *arg)
struct gdb_reg_value ** registers
int gdbarch_dwarf2_reg_to_regnum(struct gdbarch *gdbarch, int dwarf2_regnr)
struct value * frame_unwind_got_optimized(struct frame_info *frame, int regnum)
#define COMPUNIT_BLOCKVECTOR(cust)
static struct gdbarch_data * jit_gdbarch_data
struct minimal_symbol * register_code
GDB_CORE_ADDR stack_address
void discard_cleanups(struct cleanup *old_chain)
static void jit_prepend_unwinder(struct gdbarch *gdbarch)
void puts_unfiltered(const char *string)
struct symbol * allocate_symbol(struct objfile *objfile)
gdb_unwind_frame * unwind
static struct jit_objfile_data * get_jit_objfile_data(struct objfile *objf)
int deprecated_frame_register_read(struct frame_info *frame, int regnum, gdb_byte *myaddr)
#define SYMBOL_BLOCK_VALUE(symbol)
static unsigned int jit_debug
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
static void jit_symtab_line_mapping_add_impl(struct gdb_symbol_callbacks *cb, struct gdb_symtab *stab, int nlines, struct gdb_line_mapping *map)
struct type * builtin_data_ptr
struct minimal_symbol * minsym
static struct value * jit_frame_prev_register(struct frame_info *this_frame, void **cache, int reg)
static void jit_inferior_init(struct gdbarch *gdbarch)
struct symtab * allocate_symtab(struct compunit_symtab *cust, const char *filename)
struct general_symbol_info ginfo
struct minimal_symbol * descriptor
#define COMPUNIT_FILETABS(cust)
#define ALL_OBJFILES_SAFE(obj, nxt)
static void finalize_symtab(struct gdb_symtab *stab, struct objfile *objfile)
#define BLOCKVECTOR_NBLOCKS(blocklist)
struct objfile * allocate_objfile(bfd *abfd, const char *name, int flags)
struct other_sections other[1]
void set_block_compunit_symtab(struct block *block, struct compunit_symtab *cu)
struct program_space * current_program_space
unsigned long long ULONGEST
enum unwind_stop_reason default_frame_unwind_stop_reason(struct frame_info *this_frame, void **this_cache)
int register_size(struct gdbarch *gdbarch, int regnum)
static int compare_block(const struct gdb_block *const old, const struct gdb_block *const newobj)
static void jit_object_close_impl(struct gdb_symbol_callbacks *cb, struct gdb_object *obj)
static void jit_reader_load_command(char *args, int from_tty)
#define SYMBOL_TYPE(symbol)
const struct bfd_arch_info * gdbarch_bfd_arch_info(struct gdbarch *gdbarch)
char * relocate_gdb_directory(const char *initial, int flag)
struct cmd_list_element * showdebuglist
struct breakpoint * jit_breakpoint
static void jit_unregister_code(struct objfile *objfile)
#define BLOCKVECTOR_MAP(blocklist)
struct gdb_block * parent
#define TYPE_LENGTH(thistype)
static int jit_reader_try_read_symtab(struct jit_code_entry *code_entry, CORE_ADDR entry_addr)
static const struct objfile_data * jit_objfile_data
struct block * allocate_global_block(struct obstack *obstack)
struct type * arch_type(struct gdbarch *gdbarch, enum type_code code, int length, char *name)
struct cleanup * make_cleanup_free_section_addr_info(struct section_addr_info *addrs)
void terminate_minimal_symbol_table(struct objfile *objfile)
struct gdb_symtab * symtabs
struct bound_minimal_symbol lookup_minimal_symbol(const char *name, const char *sfile, struct objfile *objf)
static struct gdb_object * jit_object_open_impl(struct gdb_symbol_callbacks *cb)
static const char * jit_reader_dir
struct breakpoint * owner
#define SYMTAB_LINETABLE(symtab)
void delete_breakpoint(struct breakpoint *bpt)
void error(const char *fmt,...)
void jit_event_handler(struct gdbarch *gdbarch)
struct cmd_list_element * add_com(const char *name, enum command_class theclass, cmd_cfunc_ftype *fun, const char *doc)
struct gdbarch * get_frame_arch(struct frame_info *this_frame)
static int jit_breakpoint_re_set_internal(struct gdbarch *gdbarch, struct jit_program_space_data *ps_data)
void do_cleanups(struct cleanup *old_chain)
#define MSYMBOL_VALUE_ADDRESS(objfile, symbol)
static struct block * new_block(enum block_type)
struct type * lookup_function_type(struct type *type)
struct section_addr_info * alloc_section_addr_info(size_t num_sections)
GDB_CORE_ADDR code_address
const ULONGEST const LONGEST len