From nobody Mon Jul 29 05:10:53 2024 X-Original-To: freebsd-drivers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4WXRK20fsnz5RCJP for ; Mon, 29 Jul 2024 05:11:02 +0000 (UTC) (envelope-from quail5101os@use.startmail.com) Received: from mx-out2.startmail.com (mx-out2.startmail.com [145.131.90.155]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4WXRK10vjqz57Kd for ; Mon, 29 Jul 2024 05:11:01 +0000 (UTC) (envelope-from quail5101os@use.startmail.com) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=startmail.com header.s=2020-07 header.b=fWqZwewz; dmarc=pass (policy=quarantine) header.from=use.startmail.com; spf=pass (mx1.freebsd.org: domain of quail5101os@use.startmail.com designates 145.131.90.155 as permitted sender) smtp.mailfrom=quail5101os@use.startmail.com Content-Type: multipart/alternative; boundary="===============4209039786258324174==" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=startmail.com; s=2020-07; t=1722229853; bh=EXHGH5vkQa102dKXl/7BzgGNzujQ5+kN2VgUBI4TQ3E=; h=Content-Type:Subject:Message-ID:Date:From:To:Mime-Version:From: Subject:To:Date:Sender:Content-Type:Content-Transfer-Encoding: Content-Disposition:Mime-Version:Reply-To:In-Reply-To:References: Message-Id:Autocrypt; b=fWqZwewzJBvy7Su5WgtZue62yI/3OgWNsRpfjgYuu43wPNNbjw19he1qW2dfHgqlL qxPVa+dT+DN35kf7k5E/BVw0JdzKJhWS6kojqVMWyz6fUtynamGYRfLebYVKOhoDod GYB61sLi2dWOYliWgWizaJxj9LvNnFopSzXtzR7MU+/lm0KCNroTNkh/pFPu73j0La iYyIE2LmloSEcm0PDevO1WOQhdklFFs8ReeRmcoj3Cbs6ywlHnEK817PdECK9pvar0 oNAWYTXW//3jOcSufPxcDIlsDmhK9R3QjdtpZSYVkG6sLpafLUgwMvOTs+o5N12/28 +cC2zGmrnLRIg== Subject: How to live debug a FreeBSD kernel module? Message-ID: <172222985287.138720.11163516792060957897@startmail.com> Date: Mon, 29 Jul 2024 05:10:53 -0000 From: quail5101os@use.startmail.com To: freebsd-drivers@freebsd.org List-Id: Writing device drivers for FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-drivers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-drivers@FreeBSD.org Mime-Version: 1.0 X-Spamd-Bar: -- X-Spamd-Result: default: False [-2.50 / 15.00]; SUBJECT_ENDS_QUESTION(1.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-1.000]; MV_CASE(0.50)[]; DMARC_POLICY_ALLOW(-0.50)[use.startmail.com,quarantine]; R_SPF_ALLOW(-0.20)[+ip4:145.131.90.128/27]; R_DKIM_ALLOW(-0.20)[startmail.com:s=2020-07]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; MIME_TRACE(0.00)[0:+,1:+,2:~]; ASN(0.00)[asn:28685, ipnet:145.131.64.0/18, country:NL]; MISSING_XM_UA(0.00)[]; FROM_NO_DN(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; RCVD_COUNT_ZERO(0.00)[0]; ARC_NA(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; MID_RHS_MATCH_FROMTLD(0.00)[]; TO_DN_NONE(0.00)[]; MLMMJ_DEST(0.00)[freebsd-drivers@freebsd.org]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_TRACE(0.00)[startmail.com:+] X-Rspamd-Queue-Id: 4WXRK10vjqz57Kd --===============4209039786258324174== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Estimated FreeBSD mailing list, =20 =20 I am following Joseph Kong's FreeBSD device driver's: A guide for the intrepid. Now I am at the chapter 4, where rather than copy the example= from the bug I wrote a examples the day later which follows the same ioctl c= alls as those which the books gives, except that they are named differently, bu= t every time that I try to run the command line utility that interacts with my = ioctl calls I get a broken ssh connection to my development Virtual Machine. Therefore, how can I debug my kernel module? =20 =20 Note, that I had tried to consult the manpage ddb, kgdb, and also have = tried to run ``sysctl debug.kdb.enter=3D1`` from , a= nd nothing have worked in my ssh session. This last may be because it is n= ot enabled, but the handbook page is not clear in how to compile a kernel. =20 =20 For I cannot imagine the pain= of setting from the virtual machine to the Linux Host and back to another = virtual machine, it certainly could be done with the FreeBSD guest doing nested virtualization with bhyve, and doing the procedure with that, but no id= ea of how to setup it, likewise not idea of how to setup with bhyve. =20 =20 Cordially, Quail5101. =20 --===============4209039786258324174== Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable
Esti= mated FreeBSD mailing list,


I am following Jo= seph Kong's FreeBSD device driver's: A guide for the intrepid. Now I am= at the chapter 4, where rather than copy the example from the bug I wr= ote a examples the day later which follows the same ioctl calls as thos= e which the books gives, except that they are named differently, but ev= ery time that I try to run the command line utility that interacts with= my ioctl calls I get a broken ssh connection to my development Virtual= Machine. Therefore, how can I debug my kernel module?

=


Note, = that I had tried to consult the manpage ddb, kgdb, and also have tried = to run `sysctl debug.kdb.enter=3D1` from https://docs.freebsd.org/en/b= ooks/developers-handbook/kerneldebug/, and nothing have worked in m= y ssh session. This last may be because it is not enabled, but the hand= book page https://docs.freebsd.org/en/books/handboo= k/kernelconfig/#kernelconfig-building is not clear in how to compil= e a kernel.


For https://docs.freebsd.org/en/books/developers-handbook/ker= neldebug/#kerneldebug-online-gdb I cannot imagine the pain of setti= ng from the virtual machine to the Linux Host and back to another virtu= al machine, it certainly could be done with the FreeBSD guest doing nes= ted virtualization with bhyve, and doing the procedure with that, but n= o idea of how to setup it, likewise not idea of how to setup https://docs.freebsd.org/en/books/developers-handbook/k= erneldebug/#kerneldebug-dcons with bhyve.


Cordially, Quail5101.

--===============4209039786258324174==-- From nobody Wed Jul 31 20:39:43 2024 X-Original-To: freebsd-drivers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4WZ3qh6D7xz5RJtD for ; Wed, 31 Jul 2024 20:39:44 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WZ3qh4wg2z4hLg; Wed, 31 Jul 2024 20:39:44 +0000 (UTC) (envelope-from jhb@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722458384; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tHt+coTuqC0QTrRz1AzFCsdVd2SuuWbPWXv33LkIxmI=; b=LZjJf6HLH10wzeeKUrHZmK2ptiKc1dJvHCM8j3OtSZYxemZ62MOhGaha1RXXVjDgXH+NfB H0CKAwJ9G/6dAYAlvVo+TkMJPqgqBAg09a7mQEuvW3AQ6//SH+AksZzsV87Nnbu27vbP49 WUNvraHuK96yqGmKSyTWeNdIzVOQq5+MCbJpXp+Wc0DdtMhycirxPsYLwqcT2jHd6Oe19J KwRmHeYkitg/Q/ggkDkj1ctiNp+2hDv0Vwv/wzvzTiPpRqU/kxKa+Uiqvy+8EfH6iDMwhD GoVq4mfwnmuNl+VuamvyF75VVJ6lgfV8n3rC25DMeMKlj7No5YoeI/1CkWkYcw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1722458384; a=rsa-sha256; cv=none; b=I6h0octIPpGVK4IfymqRWPP9aBdo4HX5mxek6/VnZWFdHdC7pDJGbaImoFoUdIJqqZOqJr EoB7rSfQSKn6FcCf6cyWm+WVy4X3I0bfjzyZ2BMF88nGRpFycYk9Swv7ZpN+T8QQQHXUHc N5iJvPD3f1kpax1BpV93wd70TlBXkWvpK8PmKQREA5L6+AoU4S+3y9VX8quDkzE9xPeuMt IwF+X4S527sHj4zkrHrGrX9XlgmCRavZDmZsbbn1g62hY0JAmjIfnt5IVpidBe8g/klUjT quk7kPkC0FGTfl6RVqVzWKb5B2VZ4C67fnNvweUA0C1ZZd4lLb6QRL3zB/ZT2w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722458384; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tHt+coTuqC0QTrRz1AzFCsdVd2SuuWbPWXv33LkIxmI=; b=eDDSElkqzljJQveTERKqRJFfVKZyv0/bgTBK/bt8IfhNtbf/E+juhhoJvvCcLh5GYHsVek Tc06aFP2kD5g1Vv/yRYG88LkVYJSb9CCWaH0YNP85HRAJxqvXtU6EvEn+0MAdG6kqy7fjH e2YN6s0kgbvTEYN8IXqBvbh2M6MnEap5vcP0Iv4acOZwqocb0mzZalBJOuIMGav1yRl2av 5s3wGgq+8yUsAxndYZfmqN9gdGMVuKKFX18hvUbes77OjTxLSDuzC06e56CYuxa7tIdnU7 ufFBNKFCs20etI3VaKPIOdj2omSAuIpj1RNCcgbbhUDZAmMJpVI6sGmpaVkaYQ== Received: from [IPV6:2601:5c0:4200:b830:a527:982d:44f2:7b0b] (unknown [IPv6:2601:5c0:4200:b830:a527:982d:44f2:7b0b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: jhb) by smtp.freebsd.org (Postfix) with ESMTPSA id 4WZ3qh3Trqz1Hhl; Wed, 31 Jul 2024 20:39:44 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Message-ID: <1116740a-8f7c-4adf-afdf-cc12d854ea84@FreeBSD.org> Date: Wed, 31 Jul 2024 16:39:43 -0400 List-Id: Writing device drivers for FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-drivers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-drivers@FreeBSD.org MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Asistence with sysctl proc's handle in kernel space Content-Language: en-US To: Nimbly2329 , freebsd-drivers@freebsd.org References: <172064548937.305907.8627778909077618453@startmail.com> From: John Baldwin In-Reply-To: <172064548937.305907.8627778909077618453@startmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 7/10/24 17:04, Nimbly2329 wrote: > I am following FreeBSD drivers: A guide for the intrepid by Joseph Kong to > learn to write FreeBSD device drivers. > > > > I got to the sysctl subchapter where is more or less this code > > > > #include > > #include > > > > .... > > > > static int sysctl_set_buffer_size(SYSCTL_HANDLER_ARGS) { > > int error = 0; > > int size = echo_message->buffer_size; > > error = sysctl_handle_int(oidp, &size, 0, req); > > if (error || !req->newptr || echo_message->buffer_size == size) return > (error); > > if (size >= 128 && size <= 512) { > > echo_message->buffer = realloc(echo_message->buffer, size, M_ECHO, M_WAITOK); > > echo_message->buffer_size = size; > > if (echo_message->length >= size) { > > echo_message->length = size - 1; > > echo_message->buffer[size - 1] = '\0'; > > } > > } else { > > error = EINVAL; > > } > > return (error); > > } > > > > but when compiling I got the error: > > > > error: call to undeclared function 'sysctl_int_handle'; ISO C99 and later do > not support implicit function declarations [-Werror,-Wimplicit-function- > declaration] > > 167 | error = sysctl_int_handle(oidp, &size, 0, req); > Your error here shows 'sysctl_int_handle' instead of 'sysctl_handle_int' -- John Baldwin From nobody Wed Jul 31 21:23:39 2024 X-Original-To: freebsd-drivers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4WZ4pX0Jvzz5RNNr for ; Wed, 31 Jul 2024 21:23:48 +0000 (UTC) (envelope-from hjlftdygaqf@use.startmail.com) Received: from mx-out1.startmail.com (mx-out1.startmail.com [145.131.90.139]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4WZ4pW4kLTz4lGc; Wed, 31 Jul 2024 21:23:47 +0000 (UTC) (envelope-from hjlftdygaqf@use.startmail.com) Authentication-Results: mx1.freebsd.org; none Content-Type: multipart/alternative; boundary="===============3317729185132738339==" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=startmail.com; s=2020-07; t=1722461020; bh=44wbtEyVqrFHPn+ni2GTH4z7vcBW86y6ERl57BSt06A=; h=Content-Type:Subject:Message-ID:Date:In-Reply-To:References:From: To:Mime-Version:From:Subject:To:Date:Sender:Content-Type: Content-Transfer-Encoding:Content-Disposition:Mime-Version: Reply-To:In-Reply-To:References:Message-Id:Autocrypt; b=fgMcmDphpHutNi0wd91UTDbRm8GaCkBpdIne9hxyX2WILskTagbD6TKRjuNDK3TUA 3imQwlOHSN+8tsw9JWULSaxYLpGvaMAjXkSsFwSOmYkoPDS8brXW3pSJt29MG8ltup ttDBrgFfIQnM6lHAL1wSkgY6hYQg2wummw8TFZ3vtnbqF/LB9qtF5/Y5/g60YBtxZj 1p3mF71sSNyJVAwSvMu9pX80DKGJ6G85jja9B7TGhuAR/quLDED8G/ovb9tW6qYBMI NOnJ/NWls5Qg//it15cw8VPRea45ozUV/Ua0eZ9hW9VRMZjzE8tKNtFMSqp1P4lJ7N MwKyIs1vAh70A== Subject: Re: Asistence with sysctl proc's handle in kernel space Message-ID: <172246101946.45.14456548573975496958@startmail.com> Date: Wed, 31 Jul 2024 21:23:39 -0000 In-Reply-To: <1116740a-8f7c-4adf-afdf-cc12d854ea84@FreeBSD.org> References: <172064548937.305907.8627778909077618453@startmail.com> <1116740a-8f7c-4adf-afdf-cc12d854ea84@FreeBSD.org> From: Nimbly2329 To: John Baldwin Cc: freebsd-drivers@freebsd.org List-Id: Writing device drivers for FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-drivers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-drivers@FreeBSD.org Mime-Version: 1.0 X-Spamd-Bar: ---- X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:28685, ipnet:145.131.64.0/18, country:NL] X-Rspamd-Queue-Id: 4WZ4pW4kLTz4lGc --===============3317729185132738339== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable I realized just after sending, still I have not found documentation in = the FreeBSD site: =20 > > On 7/10/24 17:04, Nimbly2329 wrote: > > I am following FreeBSD drivers: A guide for the intrepid by Jos= eph > Kong to > > learn to write FreeBSD device drivers. > > > > =20 > > > > I got to the sysctl subchapter where is more or less this code > > > > =20 > > > > #include > > > > #include > > > > =20 > > > > .... > > > > =20 > > > > static int sysctl_set_buffer_size(SYSCTL_HANDLER_ARGS) { > > > > int error =3D 0; > > > > int size =3D echo_message->buffer_size; > > > > error =3D sysctl_handle_int(oidp, &size, 0, req); > > > > if (error || !req->newptr || echo_message->buffer_size =3D=3D s= ize) return > > (error); > > > > if (size >=3D 128 && size <=3D 512) { > > > > echo_message->buffer =3D realloc(echo_message->buffer, size, M_= ECHO, > M_WAITOK); > > > > echo_message->buffer_size =3D size; > > > > if (echo_message->length >=3D size) { > > > > echo_message->length =3D size - 1; > > > > echo_message->buffer[size - 1] =3D '\0'; > > > > } > > > > } else { > > > > error =3D EINVAL; > > > > } > > > > return (error); > > > > } > > > > =20 > > > > but when compiling I got the error: > > > > =20 > > > > error: call to undeclared function 'sysctl_int_handle'; ISO C99= and > later do > > not support implicit function declarations [-Werror,-Wimplicit- > function- > > declaration] > > > > 167 | error =3D sysctl_int_handle(oidp, &size, 0, req); > > > =20 > Your error here shows 'sysctl_int_handle' instead of 'sysctl_hand= le_int' > =20 > -- > John Baldwin > =20 > =20 > =20 > =20 > > =20 --===============3317729185132738339== Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable
I re= alized just after sending, still I have not found documentation in the = FreeBSD site:
On 7/10/24 17:04, Nimbly2329 wrote:
> I am following FreeBSD drivers: A guide for the intrepid by Joseph=
 Kong to
> learn to write FreeBSD device drivers.
>=20
>   =20
>=20
> I got to the sysctl subchapter where is more or less this code
>=20
>   =20
>=20
> #include <sys/param.h>
>=20
> #include <sys/sysctl.h>
>=20
>   =20
>=20
> ....
>=20
>   =20
>=20
> static int sysctl_set_buffer_size(SYSCTL_HANDLER_ARGS) {
>=20
> int error =3D 0;
>=20
> int size =3D echo_message->buffer_size;
>=20
> error =3D sysctl_handle_int(oidp, &size, 0, req);
>=20
> if (error || !req->newptr || echo_message->buffer_size =3D=
=3D size) return
> (error);
>=20
> if (size >=3D 128 && size <=3D 512) {
>=20
> echo_message->buffer =3D realloc(echo_message->buffer, size,=
 M_ECHO, M_WAITOK);
>=20
> echo_message->buffer_size =3D size;
>=20
> if (echo_message->length >=3D size) {
>=20
> echo_message->length =3D size - 1;
>=20
> echo_message->buffer[size - 1] =3D '\0';
>=20
> }
>=20
> } else {
>=20
> error =3D EINVAL;
>=20
> }
>=20
> return (error);
>=20
> }
>=20
>   =20
>=20
> but when compiling I got the error:
>=20
>   =20
>=20
> error: call to undeclared function 'sysctl_int_handle'; ISO C99 an=
d later do
> not support implicit function declarations [-Werror,-Wimplicit-fun=
ction-
> declaration]
>=20
> 167 | error =3D sysctl_int_handle(oidp, &size, 0, req);
>=20

Your error here shows 'sysctl_int_handle' instead of 'sysctl_handle_int'

--=20
John Baldwin




<= br />

--===============3317729185132738339==--