From owner-freebsd-hackers Fri Aug 3 17:25: 4 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from salmon.maths.tcd.ie (salmon.maths.tcd.ie [134.226.81.11]) by hub.freebsd.org (Postfix) with SMTP id 41F1B37B401 for ; Fri, 3 Aug 2001 17:25:00 -0700 (PDT) (envelope-from iedowse@maths.tcd.ie) Received: from walton.maths.tcd.ie by salmon.maths.tcd.ie with SMTP id ; 4 Aug 2001 01:24:59 +0100 (BST) To: Tabor Kelly Cc: freebsd-hackers@freebsd.org Subject: Re: problems with kvm_nlist() In-Reply-To: Your message of "Fri, 03 Aug 2001 15:23:22 PDT." <137268305.20010803152322@dsl-only.net> Date: Sat, 04 Aug 2001 01:24:59 +0100 From: Ian Dowse Message-ID: <200108040124.aa31753@salmon.maths.tcd.ie> Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG In message <137268305.20010803152322@dsl-only.net>, Tabor Kelly writes: >Now that that is taken care of, would somebody mind explaining to me >what n_value represents? Is it an offset in kernel memory to retrieve >the actual data? It is the kernel virtual address of the symbol that you specified in n_name, which will be the same as an in-kernel pointer value (e.g. something like 0xc0123456). This address has no meaning in userland, but libkvm provides a kvm_read() function that does all the magic necessary to read from the kernel memory at this address. There are lots of examples of code using the libkvm interface in the FreeBSD source tree (fstat, ps, vmstat, pstat etc.) although many of these now use sysctl to retrieve values instead. Briefly, you just kvm_read the value of the variable whose symbol address you have found, e.g. something like the code below, but you'll want to add code to deal with any errors that the kvm_* calls might return. struct nlist nl[] = { {"nextpid"}, {NULL}, }; int nextpid; kd = kvm_openfiles(...); kvm_nlist(kd, nl); kvm_read(kd, nl[0].n_value, &nextpid, sizeof(nextpid)); printf("nextpid is %d\n", nextpid); Ian To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message