Giter VIP home page Giter VIP logo

current-time's Introduction

A sample Linux kernel module that saves the current time to /tmp/current_time every minute in the hh:mm format, e.g., 11:58 or 22:07.

Debugging with VMware Fusion

The following is partly based on this post, which also describes how to configure lldb: http://ddeville.me/2015/08/using-the-vmware-fusion-gdb-stub-for-kernel-debugging-with-lldb

I was able to attach with lldb as described in the post, but decided to configure gdb instead. lldb seems to be poorly suited for debugging the Linux kernel.

Two Linux VMs are required: a debugger and a debuggee. gdbserver won't work with gdb configured as something like "x86_64-apple-darwin16.6.0", even if it's built for multiple targets (the file command in gdb will work on vmlinux, but debugging won't be possible). gdb --version should return, e.g., "x86_64-redhat-linux-gnu".

Quit VMware and add these lines to the debuggee's .vmx file, e.g., ~/Documents/Virtual\ Machines.localized/Fedora\ 64-bit.vmwarevm/Fedora\ 64-bit.vmx:

debugStub.listen.guest64 = "TRUE"                          # for 64-bit guests
debugStub.listen.guest64.remote = "TRUE"                   # allows remote connection
debugStub.port.guest64 = "8086"                            # port to listen on
debugStub.listen.guest32 = "TRUE"                          # same for 32-bit guests
debugStub.listen.guest32.remote = "TRUE"
debugStub.port.guest32 = "8032"
# debugStub.hideBreakpoints= "TRUE"                        # for hardware breakpoints

There might be an error when starting the debuggee VM. If so, stop all VMware-related services and try again, or just reboot.

The debugger VM will connect to the host on port 8086, so set the Network Adapter option to NAT or similar. The debuggee can be connected to the Host-only network.

Build the kernel with debugging options, for example (there's more):

CONFIG_DEBUG_INFO=y
CONFIG_READABLE_ASM=y

Modify the module:

  • add __attribute__((optimize("O0"))) to the relevant module functions
  • remove __init and __exit for setting breakpoints on the module entry and cleanup functions.

Start debugging:

debuggee$ make
debugger$ gdb -q -x cmd.gdb
debuggee1$ dmesg --follow
debuggee2$ sudo insmod current_time.ko

current-time's People

Contributors

nkaretnikov avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.