Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 04 Aug 2001 01:24:59 +0100
From:      Ian Dowse <iedowse@maths.tcd.ie>
To:        Tabor Kelly <pdxmax@dsl-only.net>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: problems with kvm_nlist() 
Message-ID:   <200108040124.aa31753@salmon.maths.tcd.ie>
In-Reply-To: Your message of "Fri, 03 Aug 2001 15:23:22 PDT." <137268305.20010803152322@dsl-only.net> 

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi? <200108040124.aa31753>