From owner-freebsd-drivers@freebsd.org Sun Apr 2 03:49:56 2017 Return-Path: Delivered-To: freebsd-drivers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A750FD1E8E8 for ; Sun, 2 Apr 2017 03:49:56 +0000 (UTC) (envelope-from aijazbaig1@gmail.com) Received: from mail-ua0-x235.google.com (mail-ua0-x235.google.com [IPv6:2607:f8b0:400c:c08::235]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 57683F57 for ; Sun, 2 Apr 2017 03:49:56 +0000 (UTC) (envelope-from aijazbaig1@gmail.com) Received: by mail-ua0-x235.google.com with SMTP id 97so13120439uaz.3 for ; Sat, 01 Apr 2017 20:49:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=dJMOJlqqB9M9Ebq6xcY/GlL3mg440u9fGpBqVV1zpao=; b=IaNN4aiDnGVJJh6ddWRa+VZEd/64uHF6w7l/4rBM4GME/sZCZCettelaPbXtBqmf7U ZF49IkegaIDWxsgY3bdUwt0mvxkALCIDC9hIh051fqTZhkLMxODRbHRwpagZ3i9jXrYZ Cz5OHXo2pemL86vNi8bfFDBWwfANIBCz26AmgaBRYlQJFf1e1qWAFIvpe8YR9ZLaGzQG Rfo0pqmAjjipt8wZlZi1jUOM5qj2M0EMxz9vNAAHhNg0wwvaeOE1QjCkIgRTblT0fAf8 WXvNLnfx+soY/Um19cmuLiwA2A0FjHXvPGyGjRGhL991/9vRJBlwgBYqyx5cwA01YJve HaGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=dJMOJlqqB9M9Ebq6xcY/GlL3mg440u9fGpBqVV1zpao=; b=np/Huy6praoW9BDFoaIOd2ayJ6wbwfE+avdlDBBE7rohlrRoL0tYpuDnBpB7nVNkKy xnj1KOGPc786abc5dDtsMXqNju/H9vvMyxkrJbpPYI7zaV7CCCKLmEN9q3SapVe+sw2U PsrU3r01B7P/amjOW7yru6YFU7gEu+sXEgs6VlSZoh5QLltQvHKCQHOw48odLz8kiqh5 c8+L5E4d0LKw7P0lIw05nAVPL4fsVzXtV5KLkBzeyOgHC6oTny+jq6bRp4LUfZnK9XXj 05Za+pcQFPGR74cZC+GLWafFVCY/jZla+APki1edYMUQ4uP4TWKgyVnQbW46bMAsNKNW gFqA== X-Gm-Message-State: AFeK/H3Ucys5k5ddwixvChvahqAmBrcvobM8t/P17XIMlUC/F+JJObg1S8xpo8fLCeEsx8PzQ/3w7F1f4wfQyg== X-Received: by 10.176.7.2 with SMTP id h2mr5535322uah.103.1491104994088; Sat, 01 Apr 2017 20:49:54 -0700 (PDT) MIME-Version: 1.0 Received: by 10.31.50.138 with HTTP; Sat, 1 Apr 2017 20:49:53 -0700 (PDT) From: Aijaz Baig Date: Sun, 2 Apr 2017 09:19:53 +0530 Message-ID: Subject: Debugging KLD -- cannot access memory at 'address' To: freebsd-drivers@freebsd.org Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 Apr 2017 03:49:56 -0000 Hello. I am unable to get quite a 'handle' on debugging KLDs. I have compiled my modules with the DEBUG_FLAGS set to -g3 and have also installed it using the same flags so that /boot/kernel/ contains not only the module binary (kernel object) but also the symbol file. So I do a make DEBUG_FLAGS=-g3 make install DEBUG_FLAGS=-g3 under the directory containing the KLD which ultimately copies the binary as well as the symbol file. After connecting kgdb to the remote (debugged) machine, I load my module which automatically asks me if I need to load the symbols from the symbol file, to which I click yes sudo kgdb kernel.debug (kgdb) set remotebaud 9600 (kgdb) target remote /dev/cuau0 Remote debugging using /dev/cuau0 kdb_sysctl_enter (oidp=, arg1=, arg2=0xfffffe001e3397f0, req=) at /usr/src/sys/kern/subr_kdb.c:446 446 kdb_why = KDB_WHY_UNSET; Current language: auto; currently minimal (kgdb) kldstat Id Refs Address Size Name 1 8 0x80200000 17e10c8 kernel 2 1 0x819e2000 4cf0 vmxnet.ko 3 1 0x81c11000 23dc vmmemctl.ko 4 1 0x81c14000 47a echo.ko (kgdb) add-kld /boot/kernel/echo.ko add symbol table from file "/boot/kernel/echo.ko.symbols" at .text_addr = 0xffffffff81c14000 set_modmetadata_set_addr = 0xffffffff81c14228 set_sysinit_set_addr = 0xffffffff81c14238 .rodata.str1.1_addr = 0xffffffff81c14240 .data_addr = 0xffffffff81c142f8 .bss_addr = 0xffffffff81c14420 (y or n) y Reading symbols from /boot/kernel/echo.ko.symbols... location expression too complex...done. (kgdb) b echo_write Breakpoint 1 at 0xffffffff81c14161: file echo.c, line 89. (kgdb) getsyms Id Refs Address Size Name 1 8 0x80200000 17e10c8 kernel 2 1 0x819e2000 4cf0 vmxnet.ko 3 1 0x81c11000 23dc vmmemctl.ko 4 1 0x81c14000 47a echo.ko Select the list above with the mouse, paste into the screen and then press ^D. Yes, this is annoying. 1 8 0x80200000 17e10c8 kernel 2 1 0x819e2000 4cf0 vmxnet.ko 3 1 0x81c11000 23dc vmmemctl.ko 4 1 0x81c14000 47a echo.ko (kgdb) n 95 strlen += MIN(uio->uio_iov->iov_len, bufferspace-1); (kgdb) x/d strlen Cannot access memory at address 0x0 (kgdb) info locals strlen = Cannot access memory at address 0x0 I am unable to fathom what am I missing. Keen to hear -- Best Regards, Aijaz Baig