Page MenuHomeFreeBSD

[PPC] Fix kgdb symbol resolution
AbandonedPublic

Authored by luporl on Oct 8 2019, 8:02 PM.
Referenced Files
Unknown Object (File)
Jan 31 2024, 10:09 AM
Unknown Object (File)
Jan 14 2024, 3:50 PM
Unknown Object (File)
Dec 20 2023, 7:54 AM
Unknown Object (File)
Dec 5 2023, 1:00 PM
Unknown Object (File)
Nov 19 2023, 11:02 AM
Unknown Object (File)
Sep 29 2023, 2:10 AM
Unknown Object (File)
Aug 7 2023, 3:32 AM
Unknown Object (File)
Jul 12 2023, 2:37 AM
Subscribers

Details

Summary

PowerPC kernels are fully relocatable and may be loaded at any memory address.
In order to resolve symbols properly, GDB must load the kernel symbol file relative to the base offset where it was loaded in memory.

Diff Detail

Repository
rP FreeBSD ports repository
Lint
No Lint Coverage
Unit
No Test Coverage
Build Status
Buildable 28078
Build 26223: arc lint + arc unit

Event Timeline

The relocation needs to be done a different way to support, e.g. remote debugging (e.g. attaching gdb to qemu's debug stub). Also, kgdb_main.c is just a simpler wrapper, and 'target vmcore /path/to/vmcore' in plain gdb should also work. I'll have to think about how this might be doable, but this approach is rather hacky. It also won't work for cross-debugging (examining a ppc vmcore on a non-ppc host which kgdb generally supports for other architectures). For PIE executables gdb relies on using the ELF auxv values to find the relocated binary.

luporl retitled this revision from [PPC] Fix kgdb symbol resolution and backtrace to [PPC] Fix kgdb symbol resolution.
luporl edited the summary of this revision. (Show Details)
luporl edited the test plan for this revision. (Show Details)

Removed the backtrace fix part, that was moved to D22761.

In D21946#479486, @jhb wrote:

The relocation needs to be done a different way to support, e.g. remote debugging (e.g. attaching gdb to qemu's debug stub). Also, kgdb_main.c is just a simpler wrapper, and 'target vmcore /path/to/vmcore' in plain gdb should also work. I'll have to think about how this might be doable, but this approach is rather hacky. It also won't work for cross-debugging (examining a ppc vmcore on a non-ppc host which kgdb generally supports for other architectures). For PIE executables gdb relies on using the ELF auxv values to find the relocated binary.

Ok, I'm currently investigating how something similar to how gdb handles PIE files could be done.
So far I've found out that for both PIE and PPC kernel svr4_solib_create_inferior_hook() is called.
By forcing svr4_exec_displacement() to return the correct displacement of the kernel I was debugging, I've noticed that symbol resolution worked correctly.

So, it seems there are 2 main points to consider here:

  1. Find the most appropriate way to insert code that would make svr4_relocate_main_executable() work with FreeBSD PPC kernels
  2. Find a way to discover the load address of the kernel being debugged, even for remote targets

For remote targets, symbol resolution can be fixed by implementing qOffsets packet handling (D22767).