DragonFly BSD
DragonFly users List (threaded) for 2005-03
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: Easy c debugging question


From: Dennis Melentyev <dmelentyev@xxxxxxxxx>
Date: Tue, 29 Mar 2005 17:32:23 +0300

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



[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]