mescc: Refactor debug and stub printing.

* lib/libc.c (__mes_debug): New function.  Use it for debug printing
  and in stubs throughout.
This commit is contained in:
Jan Nieuwenhuizen 2018-06-10 14:07:19 +02:00
parent 18194b1ae4
commit c2c3554884
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273
8 changed files with 186 additions and 106 deletions

View file

@ -33,7 +33,10 @@ abs (int x)
int
chown (char const *file_name, uid_t owner, gid_t group)
{
eputs ("chown stub\n");
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("chown stub\n");
stub = 1;
errno = 0;
return 0;
}
@ -41,9 +44,10 @@ chown (char const *file_name, uid_t owner, gid_t group)
int
ctime (int x)
{
#if NOISY_TIMES
eputs ("ctime stub\n");
#endif
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("ctime stub\n");
stub = 1;
errno = 0;
return 0;
}
@ -84,7 +88,10 @@ fgets (char *s, int count, FILE *stream)
int
frexp (int x)
{
eputs ("frexp stub\n");
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("frexp stub\n");
stub = 1;
return 0;
}
@ -97,7 +104,10 @@ perror (char const *message)
int
sigsetmask (int x)
{
eputs ("sigsetmask stub\n");
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("sigsetmask stub\n");
stub = 1;
errno = 0;
return 0;
}
@ -153,7 +163,10 @@ strspn (char const *string, char const *skipset)
int
sys_siglist (int x)
{
eputs ("sys_siglist stub\n");
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("sys_siglist stub\n");
stub = 1;
errno = 0;
return 0;
}
@ -161,7 +174,10 @@ sys_siglist (int x)
int
umask (int x)
{
eputs ("umask stub\n");
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("umask stub\n");
stub = 1;
errno = 0;
return 0;
}
@ -169,9 +185,9 @@ umask (int x)
int
utime (int x)
{
#if NOISY_TIMES
eputs ("utime stub\n");
#endif
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("utime stub\n");
errno = 0;
return 0;
}
@ -180,7 +196,10 @@ utime (int x)
int
fscanf (FILE *stream, char const *template, ...)
{
eputs ("fscan stub\n");
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("fscan stub\n");
stub = 1;
return 0;
}
@ -197,16 +216,20 @@ bsearch (void const *key, void const *array, size_t count, size_t size, void (*c
bsearch (void const *key, void const *array, size_t count, size_t size, comparison_fn_t compare)
#endif
{
eputs ("bsearch stub\n");
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("bsearch stub\n");
stub = 1;
return 0;
}
struct tm *
gmtime (time_t const *time)
{
#if NOISY_TIMES
eputs ("gmtime stub\n");
#endif
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("gmtime stub\n");
stub = 1;
errno = 0;
return localtime (time);
}
@ -245,8 +268,11 @@ size_t
strftime (char *s, size_t size, char const *template,
struct tm const *brokentime)
{
eputs ("strftime stub\n");
return template;
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("strftime stub\n");
stub = 1;
return template;
}
#if !__MESC__
@ -256,7 +282,10 @@ size_t
mbstowcs (wchar_t *wstring, char const *string,
size_t size)
{
eputs ("mbstowcs stub\n");
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("mbstowcs stub\n");
stub = 1;
strcpy (wstring, string);
return strlen (string);
}

View file

@ -34,9 +34,10 @@ freopen (char const *file_name, char const *opentype, FILE *stream)
clock_t
times (struct tms *buffer)
{
#if NOISY_TIMES
eputs ("times stub\n");
#endif
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("times stub\n");
stub = 1;
return 0;
}
@ -54,14 +55,20 @@ sleep (unsigned int seconds)
double
__divdi3 (double a, double b)
{
eputs ("__divdi3 stub\n");
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("__divdi3 stub\n");
stub = 1;
return ((int)a / (int)b);
}
double
__moddi3 (double a, double b)
{
eputs ("__moddi3 stub\n");
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("__moddi3 stub\n");
stub = 1;
return ((int) a %(int)b);
}
@ -112,7 +119,10 @@ alarm (unsigned int seconds)
struct passwd *
getpwnam (const char *NAME)
{
eputs ("getpwnam stub\n");
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("getpwnam stub\n");
stub = 1;
errno = 0;
return 0;
}

View file

@ -21,7 +21,10 @@
int
__cleanup ()
{
eputs ("__cleanup stub\n");
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("__cleanup stub\n");
stub = 1;
return 0;
}

View file

@ -112,44 +112,49 @@ __ashrdi3 (long long a, int b)
long double
__floatundixf (unsigned long long a)
{
#if NOISY_FLOATS
eputs ("__floatundix stub\n");
#endif
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("__floatundix stub\n");
stub = 1;
return 0;
}
unsigned long long
__fixunsxfdi (double a1)
{
#if NOISY_FLOATS
eputs ("__fixunsxfdi stub\n");
#endif
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("__fixunsxfdi stub\n");
stub = 1;
return 0;
}
unsigned long long
__fixdfdi (double a1)
{
#if NOISY_FLOATS
eputs ("__fixdfdi stub\n");
#endif
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("__fixdfdi stub\n");
stub = 1;
return 0;
}
unsigned long long
__fixxfdi (double a1)
{
#if NOISY_FLOATS
eputs ("__fixxfdi stub\n");
#endif
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("__fixxfdi stub\n");
stub = 1;
return 0;
}
unsigned long long
__fixsfdi (double a1)
{
#if NOISY_FLOATS
eputs ("__fixsfdi stub\n");
#endif
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("__fixsfdi stub\n");
stub = 1;
return 0;
}

View file

@ -64,7 +64,7 @@ search_path (char const *file_name)
{
static char buf[256];
char *path = getenv ("PATH");
if (getenv ("MESC_DEBUG"))
if (__mes_debug ())
{
eputs ("\n search-path: "); eputs (file_name); eputs ("\n");
}
@ -75,7 +75,7 @@ search_path (char const *file_name)
end = strchr (path, '\0');
strncpy (buf, path, end - path);
buf[end - path] = 0;
if (getenv ("MESC_DEBUG"))
if (__mes_debug ())
{
eputs (" dir: "); eputs (buf); eputs ("\n");
}
@ -84,7 +84,7 @@ search_path (char const *file_name)
strcat (buf, file_name);
if (!access (buf, X_OK))
{
if (getenv ("MESC_DEBUG"))
if (__mes_debug ())
{
eputs (" found: "); eputs (buf); eputs ("\n");
}
@ -105,7 +105,7 @@ execvp (char const *file_name, char *const argv[])
errno = ENOENT;
return -1;
}
if (getenv ("MESC_DEBUG"))
if (__mes_debug ())
{
eputs (" EXEC: "); eputs (file_name); eputs ("\n");
int i = 0;
@ -170,7 +170,7 @@ fread (void *data, size_t size, size_t count, FILE *stream)
size_t
fwrite (void const *data, size_t size, size_t count, FILE *stream)
{
if (getenv ("MESC_DEBUG"))
if (__mes_debug ())
{
eputs ("fwrite "); eputs (itoa ((int)stream));
eputs (" "); eputs (itoa (size)); eputs ("\n");
@ -180,7 +180,7 @@ fwrite (void const *data, size_t size, size_t count, FILE *stream)
return 0;
int bytes = write ((int)stream, data, size * count);
if (getenv ("MESC_DEBUG"))
if (__mes_debug ())
{
eputs (" => "); eputs (itoa (bytes)); eputs ("\n");
}
@ -199,7 +199,7 @@ ftell (FILE *stream)
FILE*
fopen (char const *file_name, char const *opentype)
{
if (getenv ("MESC_DEBUG"))
if (__mes_debug ())
{
eputs ("fopen "); eputs (file_name);
eputs (" "); eputs (opentype); eputs ("\n");
@ -224,7 +224,7 @@ fopen (char const *file_name, char const *opentype)
else
fd = open (file_name, 0, 0);
if (getenv ("MESC_DEBUG"))
if (__mes_debug ())
{
eputs (" => fd="); eputs (itoa (fd)); eputs ("\n");
}
@ -244,9 +244,10 @@ fseek (FILE *stream, long offset, int whence)
int
gettimeofday (struct timeval *tv, struct timezone *tz)
{
#if NOISY_TIMES
eputs ("gettimeofday stub\n");
#endif
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("gettimeofday stub\n");
stub = 1;
errno = 0;
return 0;
}
@ -254,16 +255,20 @@ gettimeofday (struct timeval *tv, struct timezone *tz)
double
ldexp (double x, int exp)
{
eputs ("ldexp stub\n");
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("ldexp stub\n");
stub = 1;
return 0;
}
struct tm *
localtime (time_t const *timep)
{
#if NOISY_TIMES
eputs ("localtime stub\n");
#endif
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("localtime stub\n");
stub = 1;
errno = 0;
return 0;
}
@ -485,9 +490,10 @@ strstr (char const *haystack, char const *needle)
double
strtod (char const *string, char **tailptr)
{
#if NOISY_FLOATS
eputs ("strtod stub\n");
#endif
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("strtod stub\n");
stub = 1;
return 0;
}
@ -520,8 +526,6 @@ strtol (char const *string, char **tailptr, int base)
return abtoi (p, base);
}
#if 1
long long int
strtoll (char const *string, char **tailptr, int base)
{
@ -540,39 +544,13 @@ strtoull (char const *string, char **tailptr, int base)
return strtol (string, tailptr, base);
}
#else
long long int
strtoll (char const *string, char **tailptr, int base)
{
eputs ("strtoll stub\n");
return 0;
}
unsigned long
strtoul (char const *string, char **tailptr, int base)
{
eputs ("strtoul stub\n");
return 0;
}
unsigned long long
strtoull (char const *string, char **tailptr, int base)
{
// *endptr = p;
// return abtoi (endptr, base);
eputs ("strtoull stub\n");
return 0;
}
#endif
time_t
time (time_t *tloc)
{
#if NOISY_TIMES
eputs ("time stub\n");
#endif
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("time stub\n");
stub = 1;
errno = 0;
return 0;
}

View file

@ -49,6 +49,20 @@ int g_stdin = 0;
void _env ();
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
int
__mes_debug ()
{
static int __mes_debug = -1;
if (__mes_debug == -1)
{
char *p = getenv ("MES_DEBUG");
__mes_debug = p ? MAX (itoa (p), 1) : 0;
}
return __mes_debug;
}
int
getchar ()
{

View file

@ -45,27 +45,39 @@
int
__cleanup ()
{
eputs ("__cleanup stub\n");
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("__cleanup stub\n");
stub = 1;
return 0;
}
int
__libc_subinit ()
{
eputs ("__libc_subinit stub\n");
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("__libc_subinit stub\n");
stub = 1;
return 0;
}
int
__syscall_error ()
{
eputs ("__syscall_error stub\n");
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("__syscall_error stub\n");
stub = 1;
return 0;
}
int
__fpu_control ()
{
eputs ("__fpu_control stub\n");
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("__fpu_control stub\n");
stub = 1;
return 0;
}

View file

@ -21,14 +21,20 @@
int
abort ()
{
eputs ("abort stub\n");
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("abort stub\n");
stub = 1;
return 0;
}
int
atof (int x)
{
eputs ("atof stub\n");
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("atof stub\n");
stub = 1;
return 0;
}
@ -65,7 +71,10 @@ fileno (FILE *stream)
int
fpurge (FILE *stream)
{
eputs ("fpurge stub\n");
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("fpurge stub\n");
stub = 1;
errno = 0;
return 0;
}
@ -73,7 +82,10 @@ fpurge (FILE *stream)
size_t
freadahead (FILE *fp)
{
eputs ("freadahead stub\n");
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("freadahead stub\n");
stub = 1;
errno = 0;
return 0;
}
@ -131,7 +143,10 @@ mktemp (char *template)
int
pclose (int x)
{
eputs ("pclose stub\n");
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("pclose stub\n");
stub = 1;
errno = 0;
return 0;
}
@ -139,7 +154,10 @@ pclose (int x)
int
popen (int x)
{
eputs ("popen stub\n");
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("popen stub\n");
stub = 1;
errno = 0;
return 0;
}
@ -153,7 +171,10 @@ rindex (char const *s, int c)
int
rewind (int x)
{
eputs ("rewind stub\n");
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("rewind stub\n");
stub = 1;
errno = 0;
return 0;
}
@ -161,7 +182,10 @@ rewind (int x)
int
setbuf (int x)
{
eputs ("setbuf stub\n");
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("setbuf stub\n");
stub = 1;
errno = 0;
return 0;
}
@ -169,12 +193,14 @@ setbuf (int x)
int
system (int x)
{
eputs ("system stub\n");
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("system stub\n");
stub = 1;
errno = 0;
return 0;
}
//char const *const sys_errlist[40] = {
char *sys_errlist[] = {
"error 00",
"error 01",
@ -223,7 +249,10 @@ int sys_nerr = 39;
char *
strerror (int errnum)
{
eputs ("strerror errnum="); eputs (itoa (errnum)); eputs ("\n");
if (__mes_debug ())
{
eputs ("strerror errnum="); eputs (itoa (errnum)); eputs ("\n");
}
if (errnum > 0 && errnum <= sys_nerr)
return sys_errlist[errnum];
return "sterror: unknown error";