This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC] rx sim: Print load statistics


The patch below updates the rx sim to print load statistics.  I.e.
instead of printing nothing when the gdb "load" command is invoked,
it'll now do something like this:

(gdb) target sim 
Connected to the simulator.
(gdb) load
Loading section .text, size 0x7358 lma 01000000 vma 01000000
Loading section .vectors, size 0x30 lma ffffffd0 vma ffffffd0

Comments?


sim/rx/ChangeLog:

	* load.h (rx_load): Add `callback' parameter to function prototype.
	(gdb/callback.h): Include.
	* load.c (load.h): Include.
	(xprintf, find_section_name_by_offset): New functions.
	(rx_load): Add `callback' parameter.  Add code for printing
	section loaded using GDB's printf facilities.
	* gdb-if.c (sim_load, sim_create_inferior): Update calls to
	rx_load().
	* main.c (main): Likewise.
	* syscalls.c, syscalls.h (get_callbacks): New function.

Index: sim/rx/gdb-if.c
===================================================================
RCS file: /cvs/src/src/sim/rx/gdb-if.c,v
retrieving revision 1.13
diff -u -p -r1.13 gdb-if.c
--- sim/rx/gdb-if.c	4 Jan 2012 08:28:24 -0000	1.13
+++ sim/rx/gdb-if.c	2 Mar 2012 00:30:36 -0000
@@ -201,7 +201,7 @@ sim_load (SIM_DESC sd, char *prog, struc
   if (!abfd)
     return SIM_RC_FAIL;
 
-  rx_load (abfd);
+  rx_load (abfd, get_callbacks ());
   build_swap_list (abfd);
 
   return SIM_RC_OK;
@@ -214,7 +214,7 @@ sim_create_inferior (SIM_DESC sd, struct
 
   if (abfd)
     {
-      rx_load (abfd);
+      rx_load (abfd, 0);
       build_swap_list (abfd);
     }
 
Index: sim/rx/load.c
===================================================================
RCS file: /cvs/src/src/sim/rx/load.c,v
retrieving revision 1.6
diff -u -p -r1.6 load.c
--- sim/rx/load.c	4 Jan 2012 08:28:24 -0000	1.6
+++ sim/rx/load.c	2 Mar 2012 00:30:36 -0000
@@ -28,9 +28,36 @@ along with this program.  If not, see <h
 #include "libbfd.h"
 #include "cpu.h"
 #include "mem.h"
+#include "load.h"
 #include "elf/internal.h"
 #include "elf/common.h"
 
+/* Helper function for invoking a GDB-specified printf.  */
+static void
+xprintf (host_callback *callback, const char *fmt, ...)
+{
+  va_list ap;
+
+  va_start (ap, fmt);
+
+  (*callback->vprintf_filtered) (callback, fmt, ap);
+
+  va_end (ap);
+}
+
+/* Given a file offset, look up the section name.  */
+static char *
+find_section_name_by_offset (bfd *abfd, file_ptr filepos)
+{
+  asection *s;
+
+  for (s = abfd->sections; s; s = s->next)
+    if (s->filepos == filepos)
+      return bfd_get_section_name (abfd, s);
+
+  return "(unknown)";
+}
+
 /* A note about endianness and swapping...
 
    The RX chip is CISC-like in that the opcodes are variable length
@@ -56,7 +83,7 @@ along with this program.  If not, see <h
    encoded in little-endian format.  */
 
 void
-rx_load (bfd *prog)
+rx_load (bfd *prog, host_callback *callback)
 {
   unsigned long highest_addr_loaded = 0;
   Elf_Internal_Phdr * phdrs;
@@ -105,6 +132,11 @@ rx_load (bfd *prog)
       if (verbose > 1)
 	fprintf (stderr, "[load segment: lma=%08x vma=%08x size=%08x]\n",
 		 (int) base, (int) p->p_vaddr, (int) size);
+      if (callback)
+	xprintf (callback,
+	         "Loading section %s, size %#lx lma %08lx vma %08lx\n",
+	         find_section_name_by_offset (prog, p->p_offset),
+		 size, base, p->p_vaddr);
 
       buf = malloc (size);
       if (buf == NULL)
Index: sim/rx/load.h
===================================================================
RCS file: /cvs/src/src/sim/rx/load.h,v
retrieving revision 1.4
diff -u -p -r1.4 load.h
--- sim/rx/load.h	4 Jan 2012 08:28:24 -0000	1.4
+++ sim/rx/load.h	2 Mar 2012 00:30:36 -0000
@@ -20,8 +20,9 @@ along with this program.  If not, see <h
 
 
 #include "bfd.h"
+#include "gdb/callback.h"
 
 extern int default_machine;
 
 void rx_set_mach (int mach);
-void rx_load (bfd *);
+void rx_load (bfd *, host_callback *callback);
Index: sim/rx/main.c
===================================================================
RCS file: /cvs/src/src/sim/rx/main.c,v
retrieving revision 1.7
diff -u -p -r1.7 main.c
--- sim/rx/main.c	4 Jan 2012 08:28:24 -0000	1.7
+++ sim/rx/main.c	2 Mar 2012 00:30:36 -0000
@@ -174,7 +174,7 @@ main (int argc, char **argv)
   rx_in_gdb = 0;
   save_trace = trace;
   trace = 0;
-  rx_load (prog);
+  rx_load (prog, 0);
   trace = save_trace;
 
   sim_disasm_init (prog);
Index: sim/rx/syscalls.c
===================================================================
RCS file: /cvs/src/src/sim/rx/syscalls.c,v
retrieving revision 1.5
diff -u -p -r1.5 syscalls.c
--- sim/rx/syscalls.c	4 Jan 2012 08:28:24 -0000	1.5
+++ sim/rx/syscalls.c	2 Mar 2012 00:30:36 -0000
@@ -43,6 +43,12 @@ set_callbacks (struct host_callback_stru
   callbacks = cb;
 }
 
+struct host_callback_struct *
+get_callbacks (void)
+{
+  return callbacks;
+}
+
 
 /* Arguments 1..4 are in R1..R4, remainder on stack.
 
Index: sim/rx/syscalls.h
===================================================================
RCS file: /cvs/src/src/sim/rx/syscalls.h,v
retrieving revision 1.4
diff -u -p -r1.4 syscalls.h
--- sim/rx/syscalls.h	4 Jan 2012 08:28:24 -0000	1.4
+++ sim/rx/syscalls.h	2 Mar 2012 00:30:36 -0000
@@ -21,4 +21,5 @@ along with this program.  If not, see <h
 
 struct host_callback_struct;
 extern void set_callbacks (struct host_callback_struct *);
+extern struct host_callback_struct * get_callbacks (void);
 extern int rx_syscall (int id);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]