Page MenuHomeFreeBSD

Add support for cross-arch vmcores.

Authored by jhb on Aug 8 2015, 6:39 PM.


  • Add a kvaddr_type for to represent kernel virtual addresses instead of unsigned long.
  • Add a struct kvm_nlist which is a stripped down version of struct nlist that uses kvaddr_t for n_value.
  • Add a kvm_native() routine that returns true if an open kvm descriptor is for a native kernel and memory image.
  • Add a kvm_open2() function similar to kvm_openfiles(). It drops the unused 'swapfile' argument and adds a new function pointer argument for a symbol resolving function. Native kernels still use _fdnlist() from libc to resolve symbols, but cross kernels use the supplied function.
  • Add a kvm_nlist2() function similar to kvm_nlist() except that it uses struct kvm_nlist instead of struct nlist.
  • Add a kvm_read2() function similar to kvm_read() except that it uses kvaddr_t instead of unsigned long for the kernel virtual address.
  • Add a new kvm_arch switch of routines needed by a vmcore backend. Each backend is responsible for implementing kvm_read2() for a given vmcore format.
  • Use libelf to read headers from ELF kernels and cores (except for powerpc cores).
  • Add internal helper routines for the common page offset hash table used by the minidump backends.
  • Port all of the existing kvm backends to implement a kvm_arch switch and to be cross-friendly by using private constants instead of ones that vary by platform (e.g. PAGE_SIZE). Static assertions are present when a given backend is compiled natively to ensure the private constants match the real ones.
Test Plan
  • Test that native vmcores still work with the in-tree kgdb and ps. (Done for amd64 and i386)
  • Test that the newer kgdb port can use the new kvm interface to debug both native and cross vmcores. (amd64 has tested amd64 and i386) (i386 has tested amd64 and i386)

Diff Detail

rS FreeBSD src repository - subversion
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

jhb retitled this revision from to Add support for cross-arch vmcores..
jhb updated this object.
jhb edited the test plan for this revision. (Show Details)
  • Drop uvatop. It was only present in the unused kvm_sparc.c.
  • Add the KVM_ARCH() for sparc64 and a native hook.
  • The conditional does need fixing, so fix it.
  • Fixes from make universe.
  • Fix rescue build.
  • Note that libkvm now depends on libelf.
  • Manually add libelf as a dependency.
  • Fail operations that try to read kernel structures from non-native cores.
  • Compile.
12 ↗(On Diff #7908)

arm64 WIP is in D3319

17 ↗(On Diff #7908)


12 ↗(On Diff #7908)

Yes, I've reviewed it. In the new world order, only the kvm_minidump_aarch64.c file will be used and not kvm_aarch64.c since only minidumps are supported on aarch64. (MIPS is in the same boat)

17 ↗(On Diff #7908)

It's just a copy of kvm_amd64.c. Probably a license sweep in libkvm is in order, but I think that is orthogonal to this.

  • Update licenses on new MD headers.
  • Rebase to pick up upstream aarch64.
  • Port the aarch64 minidump reader.
  • Trim some trailing whitespace.
192 ↗(On Diff #8373)

git apply complained that there's a space before the tab here (and a few instances of trailing whitespace)

jhb marked an inline comment as done.
  • Whitespace fix.
192 ↗(On Diff #8374)

There shouldn't be any trailing whitespace in new changes (I removed some prior to the last update that git had highlighted:

There is some existing trailing whitespace in libkvm, but I left that alone to avoid further muddying the diff. Do you which lines git apply complained about specifically?

  • Sort.
  • First pass at updating manpages. kvm_native.3 still needs to be written.
  • Add manage for kvm_native(3).
jhb edited edge metadata.
  • Fix MLINKS.
jhb edited edge metadata.


One open question I have that I think I want to change is to make the internal kvm_nlist always use the resolver function if it is provided and only fallback to libc's __fdnlist if there is no resolver function (and then only for native kernels). However, aside from that I have grown tired of waiting for testing and would like to get this reviewed so I can commit it.

Please remember to update .Dd on all the changed man pages. Thanks!

74 ↗(On Diff #9926)

Needs a comma:

For live kernels, the

Or to avoid a sentence with a pause in it, reorganize:

.Xr kldsym 2
is used to locate the symbol for live kernels.
84 ↗(On Diff #9926)

The \& should not be needed here.

jhb marked 2 inline comments as done.Nov 4 2015, 12:27 AM
jhb added inline comments.
84 ↗(On Diff #9926)

Fixed. This page uses the escape earlier in the description of kvm_nlist() as well (I just copied it from there).

jhb marked an inline comment as done.
jhb edited edge metadata.
  • Always use the resolver function when it is present.
  • Manpage fixes from Warren.
jhb edited edge metadata.
  • Fix warnings on 32-bit platforms.
  • Fix build race reported by marius@.
jhb edited edge metadata.


jhb edited edge metadata.
  • Rebase
  • Trim trailing whitespace.
This revision was automatically updated to reflect the committed changes.