[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
This commit is contained in:
Leandro Lupori 2019-12-16 13:17:39 +00:00
parent 174ae28247
commit fa76c6f9ba
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=355801
3 changed files with 32 additions and 0 deletions

View File

@ -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;

View File

@ -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_ */

View File

@ -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)
{
@ -101,3 +103,28 @@ gdb_cpu_signal(int vector, int dummy __unused)
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();
}