Fix the remote-sim.c build
[binutils-gdb.git] / gdb / jit.c
index 296b436c7964ac6b84e261f2a68f061acf165617..42776b956832fb149c4997ca685be4ec460b9520 100644 (file)
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -1,6 +1,6 @@
 /* Handle JIT code generation in the inferior for GDB, the GNU Debugger.
 
-   Copyright (C) 2009-2021 Free Software Foundation, Inc.
+   Copyright (C) 2009-2022 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -74,6 +74,30 @@ show_jit_debug (struct ui_file *file, int from_tty,
   fprintf_filtered (file, _("JIT debugging is %s.\n"), value);
 }
 
+/* Implementation of the "maintenance info jit" command.  */
+
+static void
+maint_info_jit_cmd (const char *args, int from_tty)
+{
+  inferior *inf = current_inferior ();
+  bool printed_header = false;
+
+  /* Print a line for each JIT-ed objfile.  */
+  for (objfile *obj : inf->pspace->objfiles ())
+    {
+      if (obj->jited_data == nullptr)
+       continue;
+
+      if (!printed_header)
+       {
+         printf_filtered ("Base address of known JIT-ed objfiles:\n");
+         printed_header = true;
+       }
+
+      printf_filtered ("  %s\n", paddress (obj->arch (), obj->jited_data->addr));
+    }
+}
+
 struct jit_reader
 {
   jit_reader (struct gdb_reader_funcs *f, gdb_dlhandle_up &&h)
@@ -140,8 +164,8 @@ jit_reader_load_command (const char *args, int from_tty)
     error (_("JIT reader already loaded.  Run jit-reader-unload first."));
 
   if (!IS_ABSOLUTE_PATH (file.get ()))
-    file.reset (xstrprintf ("%s%s%s", jit_reader_dir.c_str (), SLASH_STRING,
-                           file.get ()));
+    file = xstrprintf ("%s%s%s", jit_reader_dir.c_str (),
+                      SLASH_STRING, file.get ());
 
   loaded_jit_reader = jit_reader_load (file.get ());
   reinit_frame_cache ();
@@ -227,8 +251,8 @@ jit_read_descriptor (gdbarch *gdbarch,
   err = target_read_memory (addr, desc_buf, desc_size);
   if (err)
     {
-      printf_unfiltered (_("Unable to read JIT descriptor from "
-                          "remote memory\n"));
+      fprintf_unfiltered (gdb_stderr, _("Unable to read JIT descriptor from "
+                                       "remote memory\n"));
       return false;
     }
 
@@ -695,7 +719,8 @@ jit_bfd_try_read_symtab (struct jit_code_entry *code_entry,
       (code_entry->symfile_addr, code_entry->symfile_size, gnutarget));
   if (nbfd == NULL)
     {
-      puts_unfiltered (_("Error opening JITed symbol file, ignoring it.\n"));
+      fputs_unfiltered (_("Error opening JITed symbol file, ignoring it.\n"),
+                       gdb_stderr);
       return;
     }
 
@@ -703,7 +728,7 @@ jit_bfd_try_read_symtab (struct jit_code_entry *code_entry,
      We would segfault later without this line.  */
   if (!bfd_check_format (nbfd.get (), bfd_object))
     {
-      printf_unfiltered (_("\
+      fprintf_unfiltered (gdb_stderr, _("\
 JITed symbol file is not an object file, ignoring it.\n"));
       return;
     }
@@ -783,7 +808,7 @@ jit_breakpoint_deleted (struct breakpoint *b)
   if (b->type != bp_jit_event)
     return;
 
-  for (bp_location *iter = b->loc; iter != nullptr; iter = iter->next)
+  for (bp_location *iter : b->locations ())
     {
       for (objfile *objf : iter->pspace->objfiles ())
        {
@@ -807,6 +832,10 @@ jit_breakpoint_re_set_internal (struct gdbarch *gdbarch, program_space *pspace)
 {
   for (objfile *the_objfile : pspace->objfiles ())
     {
+      /* Skip separate debug objects.  */
+      if (the_objfile->separate_debug_objfile_backlink != nullptr)
+       continue;
+
       if (the_objfile->skip_jit_symbol_lookup)
        continue;
 
@@ -833,7 +862,7 @@ jit_breakpoint_re_set_internal (struct gdbarch *gdbarch, program_space *pspace)
        }
 
       jiter_objfile_data *objf_data
-       = get_jiter_objfile_data (reg_symbol.objfile);
+       = get_jiter_objfile_data (the_objfile);
       objf_data->register_code = reg_symbol.minsym;
       objf_data->descriptor = desc_symbol.minsym;
 
@@ -1044,6 +1073,7 @@ jit_frame_prev_register (struct frame_info *this_frame, void **cache, int reg)
 
 static const struct frame_unwind jit_frame_unwind =
 {
+  "jit",
   NORMAL_FRAME,
   default_frame_unwind_stop_reason,
   jit_frame_this_id,
@@ -1109,9 +1139,10 @@ jit_inferior_init (inferior *inf)
       /* Check that the version number agrees with that we support.  */
       if (descriptor.version != 1)
        {
-         printf_unfiltered (_("Unsupported JIT protocol version %ld "
-                              "in descriptor (expected 1)\n"),
-                            (long) descriptor.version);
+         fprintf_unfiltered (gdb_stderr,
+                             _("Unsupported JIT protocol version %ld "
+                               "in descriptor (expected 1)\n"),
+                             (long) descriptor.version);
          continue;
        }
 
@@ -1200,9 +1231,10 @@ jit_event_handler (gdbarch *gdbarch, objfile *jiter)
       {
        objfile *jited = jit_find_objf_with_entry_addr (entry_addr);
        if (jited == nullptr)
-         printf_unfiltered (_("Unable to find JITed code "
-                              "entry at address: %s\n"),
-                            paddress (gdbarch, entry_addr));
+         fprintf_unfiltered (gdb_stderr,
+                             _("Unable to find JITed code "
+                               "entry at address: %s\n"),
+                             paddress (gdbarch, entry_addr));
        else
          jited->unlink ();
 
@@ -1243,6 +1275,10 @@ _initialize_jit ()
                           show_jit_debug,
                           &setdebuglist, &showdebuglist);
 
+  add_cmd ("jit", class_maintenance, maint_info_jit_cmd,
+          _("Print information about JIT-ed code objects."),
+          &maintenanceinfolist);
+
   gdb::observers::inferior_created.attach (jit_inferior_created_hook, "jit");
   gdb::observers::inferior_execd.attach (jit_inferior_created_hook, "jit");
   gdb::observers::inferior_exit.attach (jit_inferior_exit_hook, "jit");