From owner-freebsd-hackers@freebsd.org Tue Apr 4 06:50:51 2017 Return-Path: Delivered-To: freebsd-hackers@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 1C759D2D587 for ; Tue, 4 Apr 2017 06:50:51 +0000 (UTC) (envelope-from aijazbaig1@gmail.com) Received: from mail-vk0-x232.google.com (mail-vk0-x232.google.com [IPv6:2607:f8b0:400c:c05::232]) (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 CC9A621F for ; Tue, 4 Apr 2017 06:50:50 +0000 (UTC) (envelope-from aijazbaig1@gmail.com) Received: by mail-vk0-x232.google.com with SMTP id z204so164828219vkd.1 for ; Mon, 03 Apr 2017 23:50:50 -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=E75Xm5VA55zPKFsU61m7NuXTc2rBqf+Z3Dv2Zof+yt0=; b=R1TkJmMfUVR72Ay96qdW2sbapZnDjQYU0wyQJY0L/DGgarVGc8+BJ5+ekzRv61bPz3 +wVKpGZUwKqJ7eAyLqnmWesNJifvN89pZvdBbioASBX/6iJKlSeKmKygJfkJt51dtpLi GtujBnlw4NBYb/iSe/3KOpouHWlZchR5fUKKnz+3hKX1NBH2WU3u5/wcZ+MvMinBlFNa co1EtZ38SkB/J9MpwlaAEDzMHFDBo6ndlpYiyx5O5UeN3IoL3zBsd11ohYzqh7WX0Tbc YemLx3Z71f1FhsgnA/nNC+JdEFsjBkkLJcKuq9VrlTh3sMSXfwlkIiWVZd2UGME7VmQp GykQ== 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=E75Xm5VA55zPKFsU61m7NuXTc2rBqf+Z3Dv2Zof+yt0=; b=aiVnK4B0B32Lsv9ncAbZQmddJn64sprAcwskfTUNauSKoCep0vMSODuc8rbmSNcgM+ eQQmsRDu2ZYXtw0AfnEGnXjz5hGOVoN63kT+VXQXAVew9hnTT+kCyEzYXqD482OCWxEU vzZo0DZxiRyk1dWbhkCH0nGQ3+71oo6CINERXgM451ghbdFOLcp2+Mk3tc0iTRI06aLh PGyZVicm+2I1hcOUJDvHlkoGQil3MR6Hizy5M9ERIv95jZgRLQT807pvu5W7uhk+AAQE AdUmgvPM6Ic2n1leZJKqLY+Lfu936O57Qtcp8MFyCn/BYehlhpYhEDiNqcyitKtGbmqc 6giA== X-Gm-Message-State: AFeK/H0b5I6GtpP4GBkK+sgVnPtZeWg312EfH36X80uFiIr7D+0JycPwP+M/Wfb5v2eh4Hd/Vl9/upsiytpiGg== X-Received: by 10.159.40.135 with SMTP id d7mr11232499uad.122.1491288649438; Mon, 03 Apr 2017 23:50:49 -0700 (PDT) MIME-Version: 1.0 Received: by 10.31.50.138 with HTTP; Mon, 3 Apr 2017 23:50:49 -0700 (PDT) From: Aijaz Baig Date: Tue, 4 Apr 2017 12:20:49 +0530 Message-ID: Subject: Debugging KLD -- cannot access memory at 'address' To: FreeBSD Hackers Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Apr 2017 06:50:51 -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