Skip to content

Instantly share code, notes, and snippets.

@ktemkin
Created June 13, 2017 20:51
Show Gist options
  • Save ktemkin/dea60fe224a96656057348431ebc9431 to your computer and use it in GitHub Desktop.
Save ktemkin/dea60fe224a96656057348431ebc9431 to your computer and use it in GitHub Desktop.
I spent a couple of hours spinning back up on this today, and got the VMware debug stub working (and with symbols!) for both the Linux kernel and for Bareflank. Thought I'd share, as this seems like it'll be really useful-- included below. I'll probably throw this on the Wiki once I'm sure the instructions are all sensical.
#Install homebrew, if you haven't already.
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
#Add a repository of cross compilers to your existing Homebrew installation.
brew tap sevki/homebrew-gcc_cross_compilers
#Install GDB for x86_64, which should allow us to debug Bareflank.
brew install x86_64-elf-gdb
#Turn on 64-bit debugging in your VM. While Fusion isn't open:
echo 'debugStub.listen.guest64 = "TRUE"' >> ~/path_to_bareflank.vmwarevm/your_vm_name.vmx
#Copy the linux debug symbols out of your Bareflank VM.
#For example, on Ubuntu 15.10, that might look like:
scp [email protected]:/usr/lib/debug/boot/vmlinux-4.2.0-21-generic ~/Bareflank/vmlinux
#And copy the Linux entry-point kernel module's raw object -- not the .ko:
scp [email protected]:~/hypervisor/driver_entry/src/arch/linux/bareflank.o ~/Bareflank/bareflank.o
#In the guest, load the entry point module.
make debian_load
#Locate the virtual address of the module.
#Note that if you don't run this as superuser, you'll get an invalid address of 0x0000000000000000.
sudo cat /sys/module/bareflank/sections/.text
#From the host, start your new GDB, targeting the Linux kernel...
x86_64-pc-linux-gdb ~/Bareflank/vmlinux
# In GDB, connect to vmware...
target remote localhost:8864
#... and load the symbols from the entry point module:
add-symbol-file ~/Bareflank/bareflank.o <text-address-you-located>
#Add breakpoints, if you want:
break execute_symbol
#If you want to see or interact with the source of a file, add to the directories:
dir <path-to-directory-containing-the-source-file-you-want>
#When you're ready to run the VM, use GDB's continue.
continue
#Finally, you'll likely want to add debug information for the Bareflank modules.
#This could be made a lot easier with just a /little/ bit of intervention from
#the BF elf loader, but that's likely code for another day.
#
# 1. Find the location into which the given Bareflank module was loaded.
# For now, the best way to do this is to turn on debug printing (define
# BAREFLANK_PRINTF to be printk when compiling the entry point driver),
# and watch the locations to which the modules are loaded.
# 2. Using nm or objdump, determine the offset of the .text section. Add this
# to the virtual address of the module to determine the virtual address of
# the module's .text section.
# 3. Load the symbol file into memory, like so:
add-symbol-file libentry.so <addr-of-text-section>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment