Easy c debugging question

Dennis Melentyev dmelentyev at fm.com.ua
Tue Mar 29 06:38:14 PST 2005


Hi,

walt wrote:
I wrote this trivial c program to practice using libkinfo:

#include <sys/param.h>
#include <kinfo.h>
int main()
{
struct kinfo_cputime *k;
kinfo_get_sched_cputime(k);
printf("user=%16d\n", k->cp_user);
printf("nice=%16d\n", k->cp_nice);
printf("sys=%16d\n", k->cp_sys);
printf("intr=%16d\n", k->cp_intr);
printf("idle=%16d\n", k->cp_idle);
}
It works as I expected when compiled with dynamic linking,
but it dumps core when statically linked.  gdb tells me
it exits at the first printf with 'code 026', which means
nothing to me.
Any hints what I'm doing wrong?
The hint:

Just use -Wformat or even -Wall, -pedantic and -Werror in gcc command 
line and _*READ*_ the warnings.

The problem description:

As of http://fxr.watson.org/fxr/source/sys/kinfo.h?v=DFBSD:
 54 struct kinfo_cputime {
 55         uint64_t        cp_user;
 56         uint64_t        cp_nice;
 57         uint64_t        cp_sys;
 58         uint64_t        cp_intr;
 59         uint64_t        cp_idle;
 60 };
So, you're trying to spoil the stack putting there 64bit values but 
extracting the 32bit ones...

--
Dennis Melentyev
http://www.melentyev.kiev.ua/dennis




More information about the Users mailing list