Page MenuHomeFreeBSD

[PPC] Handle qOffsets packet
ClosedPublic

Authored by luporl on Dec 11 2019, 7:11 PM.
Referenced Files
Unknown Object (File)
Wed, Dec 18, 7:06 PM
Unknown Object (File)
Tue, Dec 3, 12:22 PM
Unknown Object (File)
Oct 22 2024, 12:20 AM
Unknown Object (File)
Oct 22 2024, 12:20 AM
Unknown Object (File)
Oct 22 2024, 12:19 AM
Unknown Object (File)
Oct 22 2024, 12:19 AM
Unknown Object (File)
Oct 22 2024, 12:19 AM
Unknown Object (File)
Oct 21 2024, 10:43 PM

Details

Reviewers
cem
Group Reviewers
PowerPC
Commits
rS355801: [PPC] Handle qOffsets packet
Summary

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.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

It’s kind of ugly, but because it only impacts ppc I don’t think it’s risky for other arch. Mechanically the change looks fine; I didn’t verify the qOffsets response packet syntax but if it works, it works. Thanks!

This revision is now accepted and ready to land.Dec 11 2019, 9:00 PM
jhibbits added inline comments.
sys/gdb/gdb_main.c
143 ↗(On Diff #65504)

Don't you really want to align to the base of the load segment? Shouldn't you be subtracting KERNBASE instead? I don't know what's at play here, so I may be completely wrong.

sys/gdb/gdb_main.c
143 ↗(On Diff #65504)

I guess I've wrongly assumed that powerpc/powerpcspe .text section also started at KERNBASE (0x100100), as powerpc64 does, and just subtracting 0x100 would give the correct segment offset. But SIZEOF_HEADERS is added to KERNBASE before their .text section.

This code must return the offset of the first/text segment, as loaded in memory, after being relocated (see https://sourceware.org/gdb/onlinedocs/gdb/General-Query-Packets.html#General-Query-Packets). GDB then relocates the segment and all its sections.

Now, I'm not sure how to do it for powerpc/powerpcspe. Would truncating __startkernel to 64K (segment alignment) do it?
In any case, powerpc/powerpcspe kernel images use more than one LOAD segment, which would require at least the "DataSeg" part of the response to also be implemented, in order to properly relocate data symbols too.
But this would probably need the introduction of a new symbol, to mark the start of .data.

Another option is to change the #ifdef to powerpc64 for now, and then handle 32-bit properly later.

What do you think?

-Fix qOffsets for 32-bit PowerPC

This revision now requires review to proceed.Dec 12 2019, 8:16 PM
luporl added inline comments.
sys/gdb/gdb_main.c
143 ↗(On Diff #65504)

As discussed with @jhibbits, the best option here, to handle PPC and PPC64 correctly, seems to be the following:
align __startkernel value to 64KB, to get the segment offset.

Obtaining the data segment offset, used on 32-bit PPC only, needed to inform GDB about the relocation of modifiable data symbols, is left as a TODO for later.

There is some precedent for putting MD gdb code paths in, e.g., sys/powerpc/powerpc/gdb_machdep.c. The naming convention appears to be something like, gdb_cpu_do_offsets(). If you want to put the current gdb_do_offses code there, that would be cool. I would be fine leaving #ifdef __powerpc__ around the qOffsets handler and not implementing it everywhere, given it doesn't seem to be needed on other platforms. It is also fine with me to gdb_do_offset here, until/unless a second arch shows up needing to provide another implementation.

This revision is now accepted and ready to land.Dec 12 2019, 8:48 PM

Move implementation of qOffsets to gdb_machdep.c

This revision now requires review to proceed.Dec 13 2019, 1:35 PM
In D22767#498741, @cem wrote:

There is some precedent for putting MD gdb code paths in, e.g., sys/powerpc/powerpc/gdb_machdep.c. The naming convention appears to be something like, gdb_cpu_do_offsets(). If you want to put the current gdb_do_offses code there, that would be cool. I would be fine leaving #ifdef __powerpc__ around the qOffsets handler and not implementing it everywhere, given it doesn't seem to be needed on other platforms. It is also fine with me to gdb_do_offset here, until/unless a second arch shows up needing to provide another implementation.

Right, thanks for the feedback. Moving gdb_do_offsets() to powerpc/gdb_machdep.c really seems a better option.
Now there is only one #ifdef __powerpc__ in gdb_main.c, that can be removed if/when other archs need to implement qOffsets handling.

This revision is now accepted and ready to land.Dec 13 2019, 5:19 PM
This revision was automatically updated to reflect the committed changes.