Author: luporl
Date: Mon Dec 16 13:17:39 2019
New Revision: 355801
URL: https://svnweb.freebsd.org/changeset/base/355801

Log:
  [PPC] Handle qOffsets packet
  
  On PowerPC, this is needed in order for the debugger to find out
  the memory offset where the kernel image was loaded on the remote
  target.
  
  This fixes symbol resolution when remote debugging a PowerPC kernel.
  
  Reviewed by:  cem
  Differential Revision:        https://reviews.freebsd.org/D22767

Modified:
  head/sys/gdb/gdb_main.c
  head/sys/powerpc/include/gdb_machdep.h
  head/sys/powerpc/powerpc/gdb_machdep.c

Modified: head/sys/gdb/gdb_main.c
==============================================================================
--- head/sys/gdb/gdb_main.c     Mon Dec 16 09:11:38 2019        (r355800)
+++ head/sys/gdb/gdb_main.c     Mon Dec 16 13:17:39 2019        (r355801)
@@ -769,6 +769,10 @@ gdb_trap(int type, int code)
                                do_qXfer();
                        } else if (gdb_rx_equal("Search:memory:")) {
                                gdb_do_mem_search();
+#ifdef __powerpc__
+                       } else if (gdb_rx_equal("Offsets")) {
+                               gdb_cpu_do_offsets();
+#endif
                        } else if (!gdb_cpu_query())
                                gdb_tx_empty();
                        break;

Modified: head/sys/powerpc/include/gdb_machdep.h
==============================================================================
--- head/sys/powerpc/include/gdb_machdep.h      Mon Dec 16 09:11:38 2019        
(r355800)
+++ head/sys/powerpc/include/gdb_machdep.h      Mon Dec 16 13:17:39 2019        
(r355801)
@@ -131,5 +131,6 @@ gdb_end_write(void *arg __unused)
 void *gdb_cpu_getreg(int, size_t *);
 void gdb_cpu_setreg(int, void *);
 int gdb_cpu_signal(int, int);
+void gdb_cpu_do_offsets(void);
 
 #endif /* !_MACHINE_GDB_MACHDEP_H_ */

Modified: head/sys/powerpc/powerpc/gdb_machdep.c
==============================================================================
--- head/sys/powerpc/powerpc/gdb_machdep.c      Mon Dec 16 09:11:38 2019        
(r355800)
+++ head/sys/powerpc/powerpc/gdb_machdep.c      Mon Dec 16 13:17:39 2019        
(r355801)
@@ -48,6 +48,8 @@ __FBSDID("$FreeBSD$");
 #include <gdb/gdb.h>
 #include <gdb/gdb_int.h>
 
+extern vm_offset_t __startkernel;
+
 void *
 gdb_cpu_getreg(int regnum, size_t *regsz)
 {
@@ -100,4 +102,29 @@ gdb_cpu_signal(int vector, int dummy __unused)
                return (vector);
        else
                return (SIGEMT);
+}
+
+void
+gdb_cpu_do_offsets(void)
+{
+       /*
+        * On PowerPC, .text starts at KERNBASE + SIZEOF_HEADERS and
+        * text segment at KERNBASE - SIZEOF_HEADERS.
+        * On PowerPC64, .text starts at KERNBASE and text segment at
+        * KERNBASE - 0x100.
+        * In both cases, the text segment offset is aligned to 64KB.
+        *
+        * The __startkernel variable holds the relocated KERNBASE offset.
+        * Thus, as long as SIZEOF_HEADERS doesn't get bigger than 0x100
+        * (which would lead to other issues), aligning __startkernel to
+        * 64KB gives the text segment offset.
+        *
+        * TODO: Add DataSeg to response. On PowerPC64 all sections reside
+        * in a single LOAD segment, but on PowerPC modifiable data reside
+        * in a separate segment, that GDB should also relocate.
+        */
+       gdb_tx_begin(0);
+       gdb_tx_str("TextSeg=");
+       gdb_tx_varhex(__startkernel & ~0xffff);
+       gdb_tx_end();
 }
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to