source: svn/trunk/zas_dstar/hal/os/src/v2lin/v2ldebug.c @ 2

Last change on this file since 2 was 2, checked in by phkim, 11 years ago

1.phkim

  1. revision copy newcon3sk r27
File size: 2.4 KB
Line 
1/****************************************************************************
2 * This file is part of the v2lin Library.
3 * VxWorks is a registered trademark of Wind River Systems, Inc.
4 *
5 * Copyright (C) 2006 Constantine Shulyupin, conan.sh@gmail.com
6 *
7 * The v2lin library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * The v2lin Library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * Lesser General Public License for more details.
16 *
17 ****************************************************************************/
18
19#include <stdio.h>
20#include <unistd.h>
21#include <signal.h>
22#include "v2lpthread.h"
23#include <stdlib.h>
24#include "v2ldebug.h"
25#include <sys/wait.h>
26
27//_syscall0(pid_t,gettid)
28
29int tid;
30extern char * _argv[];
31char trace_fn[100];
32struct timeval start_tv={0,0};
33int trace = 1;
34struct timeval prev_tv={0,0};
35
36void gdb()
37{
38        static int gdb_pid;
39        char spid[20];
40        snprintf(spid, 19, "%i", getpid());
41        spid[19] = 0;
42        if (gdb_pid) {
43                TRACEF("gdb already started");
44                exit(1);
45        }
46        gdb_pid = fork();
47        if (gdb_pid == 0) {
48                // define _argv and open comment
49                // execlp("gdb", "gdb", "-q",_argv[0], spid, NULL);
50        } else {
51                waitpid(gdb_pid, NULL, 0);
52        }
53
54}
55
56void sighandler(int x)
57{
58        gdb();
59}
60
61void signal_init()
62{
63        signal(SIGSEGV,sighandler);
64}
65
66void trace_time()
67{
68        time_t time_cur;
69        time(&time_cur);
70        struct timeval now_tv,uptime={0,0},passed_tv={0,0};
71
72        struct timezone tz;
73
74        gettimeofday(&now_tv, &tz);
75        if (!start_tv.tv_sec) { 
76                start_tv = now_tv;
77                struct tm* now_tm;
78                now_tm = localtime(&time_cur);
79                fprintf(stderr,"time=%04d-%02d-%02d %02d:%02d:%02d.%06d\n",
80                                now_tm->tm_year+1900, now_tm->tm_mon+1, now_tm->tm_mday,
81                                now_tm->tm_hour,now_tm->tm_min,now_tm->tm_sec, (int)now_tv.tv_usec);
82        }
83        time_cur = now_tv.tv_sec;
84        timersub(&now_tv,&start_tv,&uptime);
85        if (timerisset(&prev_tv)) timersub(&now_tv,&prev_tv,&passed_tv);
86
87        //if ( passed > 0.01 )
88        if ( !timerisset(&passed_tv) || passed_tv.tv_usec > 10000)
89        {
90                fprintf(stderr,"uptime=%d.%06d s ",(int)uptime.tv_sec,(int)uptime.tv_usec);
91                fprintf(stderr,"+%d.%06d ",(int)passed_tv.tv_sec,(int)passed_tv.tv_usec);
92                fprintf(stderr,"\n");
93                prev_tv = now_tv;
94        }
95}
Note: See TracBrowser for help on using the repository browser.