39#include "gdbsupport/gdb-dlfcn.h"
42#include "readline/tilde.h"
44#include <forward_list>
61#define jit_debug_printf(fmt, ...) \
62 debug_prefixed_printf_cond (jit_debug, "jit", fmt, ##__VA_ARGS__)
77 bool printed_header =
false;
79 gdb::optional<ui_out_emit_table> table_emitter;
84 if (obj->jited_data ==
nullptr)
89 table_emitter.emplace (
current_uiout, 3, -1,
"jit-created-objfiles");
98 "jit_code_entry-address",
99 "jit_code_entry address");
101 "symfile-address",
"symfile address");
103 "symfile-size",
"symfile size");
106 printed_header =
true;
111 current_uiout->field_core_addr (
"jit_code_entry-address", obj->arch (),
112 obj->jited_data->addr);
113 current_uiout->field_core_addr (
"symfile-address", obj->arch (),
114 obj->jited_data->symfile_addr);
116 obj->jited_data->symfile_size);
157 gdb_dlhandle_up so = gdb_dlopen (file_name);
161 error (_(
"Could not locate initialization function: %s."),
164 if (gdb_dlsym (so,
"plugin_is_GPL_compatible") == NULL)
165 error (_(
"Reader not GPL compatible."));
169 error (_(
"Reader version does not match GDB version."));
171 return new jit_reader (funcs, std::move (so));
180 error (_(
"No reader name provided."));
181 gdb::unique_xmalloc_ptr<char> file (tilde_expand (args));
184 error (_(
"JIT reader already loaded. Run jit-reader-unload first."));
186 if (!IS_ABSOLUTE_PATH (file.get ()))
188 SLASH_STRING, file.get ());
201 error (_(
"No JIT reader loaded."));
235 CORE_ADDR symfile_addr, ULONGEST symfile_size)
252 struct type *ptr_type;
258 gdb_assert (jiter !=
nullptr);
260 gdb_assert (objf_data !=
nullptr);
268 ptr_size = ptr_type->
length ();
269 desc_size = 8 + 2 * ptr_size;
270 desc_buf = (gdb_byte *) alloca (desc_size);
299 struct type *ptr_type;
308 ptr_size = ptr_type->
length ();
313 off = (off + (align_bytes - 1)) & ~(align_bytes - 1);
315 entry_size = off + 8;
316 entry_buf = (gdb_byte *) alloca (entry_size);
321 error (_(
"Unable to read JIT code entry from remote memory!"));
359 gdb::unique_xmalloc_ptr<char>
name;
423 (gdb_byte *) gdb_buf, len);
453 object->symtabs.emplace_front (
file_name);
454 return &
object->symtabs.front ();
471 return &
symtab->blocks.front ();
492 for (i = 0; i < nlines; i++)
494 stab->
linetable->item[i].set_unrelocated_pc
495 (unrelocated_addr (map[i].
pc));
519 size_t blockvector_size;
520 CORE_ADDR begin, end;
555 + (actual_nblocks - 1) *
sizeof (
struct block *));
563 begin = stab->
blocks.front ().begin;
564 end = stab->
blocks.front ().end;
591 gdb_block_iter.name.get ());
598 if (end < new_block->end ())
607 struct block *block_iter = NULL;
634 if (gdb_block_iter.parent != NULL)
638 gdb_block_iter.real_block->set_superblock
639 (gdb_block_iter.parent->real_block);
645 gdb_block_iter.real_block->set_superblock (bv->
static_block ());
659 = string_printf (
"<< JIT compiled code at %s >>",
683 CORE_ADDR entry_addr)
719 catch (
const gdb_exception_error &e)
727 if (funcs->
read (funcs, &callbacks, gdb_mem.data (),
744 CORE_ADDR entry_addr,
747 struct bfd_section *sec;
749 const struct bfd_arch_info *b;
759 gdb_puts (_(
"Error opening JITed symbol file, ignoring it.\n"),
766 if (!bfd_check_format (nbfd.get (), bfd_object))
769JITed symbol file is not an object file, ignoring it.\n"));
775 if (b->compatible (b, bfd_get_arch_info (nbfd.get ())) != b)
776 warning (_(
"JITed object file architecture %s is not compatible "
777 "with target architecture %s."),
778 bfd_get_arch_info (nbfd.get ())->printable_name,
785 for (sec = nbfd->sections; sec != NULL; sec = sec->next)
786 if ((bfd_section_flags (sec) & (SEC_ALLOC|SEC_LOAD)) != 0)
790 sai.emplace_back (bfd_section_vma (sec),
791 bfd_section_name (sec),
797 bfd_get_filename (nbfd.get ()), 0,
833 if (objf->jited_data !=
nullptr && objf->jited_data->addr == entry_addr)
851 for (
objfile *objf : iter.pspace->objfiles ())
874 if (the_objfile->separate_debug_objfile_backlink !=
nullptr)
877 if (the_objfile->skip_jit_symbol_lookup)
884 if (reg_symbol.
minsym == NULL
888 the_objfile->skip_jit_symbol_lookup =
true;
894 if (desc_symbol.
minsym == NULL
898 the_objfile->skip_jit_symbol_lookup =
true;
1026 gdb_assert (!*cache);
1085static struct value *
1096 enum register_status
status = priv->
regcache->cooked_read (reg, buf);
1141 if (data ==
nullptr)
1144 if (!data->unwinder_registered)
1147 data->unwinder_registered = 1;
1161 CORE_ADDR cur_entry_addr;
1173 if (jiter->jiter_data ==
nullptr)
1185 _(
"Unsupported JIT protocol version %ld "
1186 "in descriptor (expected 1)\n"),
1195 cur_entry_addr != 0;
1244 if (objf->jited_data !=
nullptr && objf->jited_data->addr != 0)
1280 if (jited ==
nullptr)
1282 _(
"Unable to find JITed code "
1283 "entry at address: %s\n"),
1292 error (_(
"Unknown action_flag value in JIT descriptor!"));
1304 _(
"Set JIT debugging."),
1305 _(
"Show JIT debugging."),
1306 _(
"When set, JIT debugging is enabled."),
1312 _(
"Print information about JIT-ed code objects."),
1320 if (is_dl_available ())
1325Load FILE as debug info reader and unwinder for JIT compiled code.\n\
1326Usage: jit-reader-load FILE\n\
1327Try to load file FILE as a debug info reader (and unwinder) for\n\
1329relocated relative to the GDB executable if required."));
1334Unload the currently loaded JIT debug info reader.\n\
1335Usage: jit-reader-unload\n\n\
1336Do \"help jit-reader-load\" for info on loading debug info readers."));
struct gdbarch * target_gdbarch(void)
void delete_breakpoint(struct breakpoint *bpt)
struct breakpoint * create_jit_event_breakpoint(struct gdbarch *gdbarch, CORE_ADDR address)
struct cmd_list_element * showdebuglist
struct cmd_list_element * maintenanceinfolist
struct cmd_list_element * setdebuglist
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
void set_cmd_completer(struct cmd_list_element *cmd, completer_ftype *completer)
struct cmd_list_element * add_com(const char *name, enum command_class theclass, cmd_simple_func_ftype *fun, const char *doc)
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
void noop_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *prefix)
void filename_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
#define JIT_READER_DIR_RELOCATABLE
std::string relocate_gdb_directory(const char *initial, bool relocatable)
CORE_ADDR extract_typed_address(const gdb_byte *buf, struct type *type)
static ULONGEST extract_unsigned_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
struct multidictionary * mdict_create_linear(struct obstack *obstack, const struct pending *symbol_list)
struct value * frame_unwind_got_optimized(frame_info_ptr frame, int regnum)
void frame_unwind_prepend_unwinder(struct gdbarch *gdbarch, const struct frame_unwind *unwinder)
enum unwind_stop_reason default_frame_unwind_stop_reason(frame_info_ptr this_frame, void **this_cache)
struct value * frame_unwind_got_bytes(frame_info_ptr frame, int regnum, const gdb_byte *buf)
void reinit_frame_cache(void)
struct frame_id frame_id_build(CORE_ADDR stack_addr, CORE_ADDR code_addr)
struct gdbarch * get_frame_arch(frame_info_ptr this_frame)
bool deprecated_frame_register_read(frame_info_ptr frame, int regnum, gdb_byte *myaddr)
gdb_bfd_ref_ptr gdb_bfd_open_from_target_memory(CORE_ADDR addr, ULONGEST size, const char *target)
gdb::ref_ptr< struct bfd, gdb_bfd_ref_policy > gdb_bfd_ref_ptr
int gdbarch_dwarf2_reg_to_regnum(struct gdbarch *gdbarch, int dwarf2_regnr)
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
const struct bfd_arch_info * gdbarch_bfd_arch_info(struct gdbarch *gdbarch)
int gdbarch_ptr_bit(struct gdbarch *gdbarch)
struct type * lookup_function_type(struct type *type)
const struct builtin_type * builtin_type(struct gdbarch *gdbarch)
unsigned type_align(struct type *type)
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t err
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int status
struct inferior * current_inferior(void)
unsigned long GDB_CORE_ADDR
#define GDB_READER_INTERFACE_VERSION
static const char jit_descriptor_name[]
static void jit_inferior_created_hook(inferior *inf)
static void add_objfile_entry(struct objfile *objfile, CORE_ADDR entry, CORE_ADDR symfile_addr, ULONGEST symfile_size)
static void jit_breakpoint_re_set_internal(struct gdbarch *gdbarch, 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)
static int jit_frame_sniffer(const struct frame_unwind *self, frame_info_ptr this_frame, void **cache)
static const registry< gdbarch >::key< jit_gdbarch_data_type > jit_gdbarch_data
static void reg_value_free_impl(struct gdb_reg_value *value)
static struct gdb_reg_value * jit_unwind_reg_get_impl(struct gdb_unwind_callbacks *cb, int regnum)
static void jit_inferior_init(inferior *inf)
static void jit_bfd_try_read_symtab(struct jit_code_entry *code_entry, CORE_ADDR entry_addr, struct gdbarch *gdbarch)
static struct gdb_symtab * jit_symtab_open_impl(struct gdb_symbol_callbacks *cb, struct gdb_object *object, const char *file_name)
static const struct frame_unwind jit_frame_unwind
void jit_event_handler(gdbarch *gdbarch, objfile *jiter)
static std::string jit_reader_dir
static struct jit_reader * loaded_jit_reader
static void jit_breakpoint_deleted(struct breakpoint *b)
static void jit_read_code_entry(struct gdbarch *gdbarch, CORE_ADDR code_addr, struct jit_code_entry *code_entry)
static void jit_reader_load_command(const char *args, int from_tty)
void jit_breakpoint_re_set(void)
static void jit_symtab_close_impl(struct gdb_symbol_callbacks *cb, struct gdb_symtab *stab)
static void jit_register_code(struct gdbarch *gdbarch, CORE_ADDR entry_addr, struct jit_code_entry *code_entry)
static void jit_prepend_unwinder(struct gdbarch *gdbarch)
static void jit_inferior_execd_hook(inferior *exec_inf, inferior *follow_inf)
static const char jit_break_name[]
static jiter_objfile_data * get_jiter_objfile_data(objfile *objf)
static struct jit_reader * jit_reader_load(const char *file_name)
static void jit_frame_this_id(frame_info_ptr this_frame, void **cache, struct frame_id *this_id)
static struct gdb_object * jit_object_open_impl(struct gdb_symbol_callbacks *cb)
static void jit_reader_unload_command(const char *args, int from_tty)
static void jit_inferior_exit_hook(struct inferior *inf)
static void jit_unwind_reg_set_impl(struct gdb_unwind_callbacks *cb, int dwarf_regnum, struct gdb_reg_value *value)
struct gdb_reader_funcs * reader_init_fn_type(void)
#define jit_debug_printf(fmt,...)
static struct value * jit_frame_prev_register(frame_info_ptr this_frame, void **cache, int reg)
static void jit_dealloc_cache(frame_info *this_frame, void *cache)
static int jit_reader_try_read_symtab(gdbarch *gdbarch, jit_code_entry *code_entry, CORE_ADDR entry_addr)
static const char reader_init_fn_sym[]
static enum gdb_status jit_target_read_impl(GDB_CORE_ADDR target_mem, void *gdb_buf, int 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)
static void finalize_symtab(struct gdb_symtab *stab, struct objfile *objfile)
static bool jit_read_descriptor(gdbarch *gdbarch, jit_descriptor *descriptor, objfile *jiter)
static void jit_object_close_impl(struct gdb_symbol_callbacks *cb, struct gdb_object *obj)
static void show_jit_debug(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static struct objfile * jit_find_objf_with_entry_addr(CORE_ADDR entry_addr)
static void maint_info_jit_cmd(const char *args, int from_tty)
static struct block * new_block(struct objfile *objfile, enum block_type, enum language)
struct bound_minimal_symbol lookup_minimal_symbol(const char *name, const char *sfile, struct objfile *objf)
observable< struct inferior * > inferior_exit
observable< struct breakpoint * > breakpoint_deleted
observable< inferior *, inferior * > inferior_execd
observable< inferior * > inferior_created
const char * objfile_name(const struct objfile *objfile)
struct program_space * current_program_space
int register_size(struct gdbarch *gdbarch, int regnum)
void set_start(CORE_ADDR start)
void set_multidict(multidictionary *multidict)
void set_compunit_symtab(struct compunit_symtab *)
void set_end(CORE_ADDR end)
void set_superblock(const block *superblock)
void set_function(symbol *function)
struct block * static_block()
void set_map(addrmap *map)
void set_block(int i, struct block *block)
void set_num_blocks(int num_blocks)
CORE_ADDR value_address() const
struct minimal_symbol * minsym
bp_location_range locations() const
struct type * builtin_data_ptr
struct type * builtin_void
void set_blockvector(struct blockvector *blockvector)
void set_dirname(const char *dirname)
struct gdb_block * parent
struct block * real_block
gdb_block(gdb_block *parent, CORE_ADDR begin, CORE_ADDR end, const char *name)
gdb::unique_xmalloc_ptr< char > name
std::forward_list< gdb_symtab > symtabs
gdb_read_debug_info * read
gdb_destroy_reader * destroy
gdb_unwind_frame * unwind
gdb_get_frame_id * get_frame_id
gdb::unique_xmalloc_ptr< struct linetable > linetable
std::forward_list< gdb_block > blocks
gdb_symtab(const char *file_name)
gdb_unwind_reg_set * reg_set
gdb_target_read * target_read
gdb_unwind_reg_get * reg_get
const jit_code_entry & entry
DISABLE_COPY_AND_ASSIGN(jit_reader)
struct gdb_reader_funcs * functions
jit_reader(struct gdb_reader_funcs *f, gdb_dlhandle_up &&h)
frame_info_ptr this_frame
std::unique_ptr< detached_regcache > regcache
breakpoint * jit_breakpoint
CORE_ADDR cached_code_address
minimal_symbol * register_code
minimal_symbol * descriptor
CORE_ADDR pc(const struct objfile *objfile) const
CORE_ADDR value_address(objfile *objfile) const
std::unique_ptr< jiter_objfile_data > jiter_data
struct program_space * pspace
struct gdbarch * arch() const
struct objfile_per_bfd_storage * per_bfd
static objfile * make(gdb_bfd_ref_ptr bfd_, const char *name_, objfile_flags flags_, objfile *parent=nullptr)
objfile(gdb_bfd_ref_ptr, const char *, objfile_flags)
std::unique_ptr< jited_objfile_data > jited_data
auto_obstack objfile_obstack
objfiles_safe_range objfiles_safe()
objfiles_range objfiles()
void set_value_block(const block *block)
void set_aclass_index(unsigned int aclass_index)
void set_type(struct type *type)
void set_domain(domain_enum domain)
void set_symtab(struct symtab *symtab)
void set_linetable(const struct linetable *linetable)
value(struct type *type_)
struct value::@203::@204 reg
void add_compunit_symtab_to_objfile(struct compunit_symtab *cu)
struct symtab * allocate_symtab(struct compunit_symtab *cust, const char *filename, const char *filename_for_id)
struct compunit_symtab * allocate_compunit_symtab(struct objfile *objfile, const char *name)
struct objfile * symbol_file_add_from_bfd(const gdb_bfd_ref_ptr &abfd, const char *name, symfile_add_flags add_flags, section_addr_info *addrs, objfile_flags flags, struct objfile *parent)
std::vector< other_sections > section_addr_info
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
void gdb_printf(struct ui_file *stream, const char *format,...)
void gdb_puts(const char *linebuffer, struct ui_file *stream)